spec/cases/api_spec.rb in koala-2.0.0 vs spec/cases/api_spec.rb in koala-2.2.0rc1
- old
+ new
@@ -73,24 +73,52 @@
response = double('Mock KoalaResponse', :body => '', :status => 200)
allow(Koala).to receive(:make_request).and_return(response)
expect(@service.api('anything', {}, 'get', :http_component => http_component)).to eq(response)
end
- it "turns arrays of non-enumerables into comma-separated arguments" do
+ it "turns arrays of non-enumerables into comma-separated arguments by default" do
args = [12345, {:foo => [1, 2, "3", :four]}]
expected = ["/12345", {:foo => "1,2,3,four"}, "get", {}]
response = double('Mock KoalaResponse', :body => '', :status => 200)
expect(Koala).to receive(:make_request).with(*expected).and_return(response)
@service.api(*args)
end
+ it "can be configured to leave arrays of non-enumerables as is" do
+ Koala.configure do |config|
+ config.preserve_form_arguments = true
+ end
+
+ args = [12345, {:foo => [1, 2, "3", :four]}]
+ expected = ["/12345", {:foo => [1, 2, "3", :four]}, "get", {}]
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
+ expect(Koala).to receive(:make_request).with(*expected).and_return(response)
+ @service.api(*args)
+ end
+
+ it "can be configured on a per-request basis to leave arrays as is" do
+ args = [12345, {foo: [1, 2, "3", :four]}, "get", preserve_form_arguments: true]
+ expected = ["/12345", {foo: [1, 2, "3", :four]}, "get", preserve_form_arguments: true]
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
+ expect(Koala).to receive(:make_request).with(*expected).and_return(response)
+ @service.api(*args)
+ end
+
it "doesn't turn arrays containing enumerables into comma-separated strings" do
params = {:foo => [1, 2, ["3"], :four]}
args = [12345, params]
# we leave this as is -- the HTTP layer can either handle it appropriately
# (if appropriate behavior is defined)
# or raise an exception
expected = ["/12345", params, "get", {}]
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
+ expect(Koala).to receive(:make_request).with(*expected).and_return(response)
+ @service.api(*args)
+ end
+
+ it "doesn't modify any data if the option format of :json is provided" do
+ args = [12345, {:foo => [1, 2, "3", :four]}, 'get', format: :json]
+ expected = ["/12345", {:foo => [1, 2, "3", :four]}, 'get', format: :json]
response = double('Mock KoalaResponse', :body => '', :status => 200)
expect(Koala).to receive(:make_request).with(*expected).and_return(response)
@service.api(*args)
end