Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit 12dba88

Browse files
committed
Adding nascent encoding files
1 parent c40fe06 commit 12dba88

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

lib/buff/encode.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Buff
2+
class Encode
3+
def self.encode(hash)
4+
raise ArgumentError unless hash.is_a?(Hash)
5+
6+
end
7+
end
8+
end

spec/lib/buff/encode_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require "spec_helper"
2+
3+
describe Buff::Encode do
4+
describe "#encode" do
5+
6+
let(:uri) { Addressable::URI.new }
7+
it "throws error unless input is a hash" do
8+
lambda { Buff::Encode.encode([]) }.
9+
should raise_error(ArgumentError)
10+
end
11+
12+
it "should convert {:pony => 'pony' }" do
13+
h = { pony: "pony"}
14+
uri.query_values = h
15+
uri.query.should eq("pony=pony")
16+
end
17+
18+
it "should convert {:pony => ['pony', 'horse'] }" do
19+
h = { pony: ["pony", "horse"]}
20+
uri.query_values = h
21+
uri.query.should eq("pony=pony&pony=horse")
22+
end
23+
24+
it "should convert {:days => [mon, tues], :times => [....]}" do
25+
h = { days: ["mon", "tue"], times: ["12:00", "13:00"]}
26+
uri.query_values = h
27+
uri.query.should eq("days=mon&days=tue&times=12%3A00&times=13%3A00")
28+
end
29+
xit "should convert {schedules => {:days => [mon, tues], :times => [....]}" do
30+
# h = { :days => ["mon", "tue", "wed", "thu"], :times => ["12:00", "13:00"]}
31+
h = {:a => "a", :bd => ["c", "d", "e"]}
32+
uri.query_values = h
33+
uri.query.should eq("days=mon&days=tue&times=12%3A00&times=13%3A00")
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)