spec/unit/braintree/util_spec.rb in braintree-3.3.0 vs spec/unit/braintree/util_spec.rb in braintree-3.4.0

- old
+ new

@@ -9,16 +9,16 @@ original["a"].should == "b" new[:a].should == "b" end it "symbolizes nested keys" do - hash = {"a" => {"b" => {"c" => "d" }}} + hash = {"a" => {"b" => {"c" => "d"}}} Braintree::Util.symbolize_keys(hash).should == {:a => {:b => {:c => "d"}}} end it "symbolizes nested keys in arrays" do - hash = {"a" => ["b" => {"c" => "d" }]} + hash = {"a" => ["b" => {"c" => "d"}]} Braintree::Util.symbolize_keys(hash).should == {:a => [:b => {:c => "d"}]} end end describe "self.verify_keys" do @@ -42,11 +42,11 @@ :top_level_invalid => "bad", :nested => { :nested_allowed => "ok", :nested_allowed2 => "also ok", :nested_invalid => "bad" - } + }, ) end.to raise_error(ArgumentError, "invalid keys: nested[nested_invalid], top_level_invalid") end it "does not raise an exception for wildcards" do @@ -55,11 +55,11 @@ [:allowed, {:custom_fields => :_any_key_}], :allowed => "ok", :custom_fields => { :custom_allowed => "ok", :custom_allowed2 => "also ok", - } + }, ) end.to_not raise_error end it "raise an exception for wildcards at different nesting" do @@ -68,11 +68,11 @@ [:allowed, {:custom_fields => :_any_key_}], :allowed => { :custom_fields => { :bad_nesting => "very bad" } - } + }, ) end.to raise_error(ArgumentError, "invalid keys: allowed[custom_fields][bad_nesting]") end it "raises an exception if a deeply nested hash contains an invalid key" do @@ -87,11 +87,11 @@ :nested_invalid => "bad", :deeply_allowed => { :super_deep_allowed => "yep", :real_deep_invalid => "nope" } - } + }, ) end.to raise_error(ArgumentError, "invalid keys: nested[deeply_allowed][real_deep_invalid], nested[nested_invalid], top_level_invalid") end it "does not raise an error for array values" do @@ -99,11 +99,11 @@ Braintree::Util.verify_keys( [{:add_ons => [{:update => [:amount]}, {:add => [:amount]}]}], :add_ons => { :update => [{:amount => 10}], :add => [{:amount => 5}] - } + }, ) end.to_not raise_error end it "raises an error for invalid key inside of array" do @@ -111,11 +111,11 @@ Braintree::Util.verify_keys( [{:add_ons => [{:update => [:amount]}, {:add => [:amount]}]}], :add_ons => { :update => [{:foo => 10}], :add => [{:bar => 5}] - } + }, ) end.to raise_error(ArgumentError, /invalid keys: add_ons\[add\]\[bar\], add_ons\[update\]\[foo\]/) end end @@ -125,11 +125,11 @@ [:allowed, {:custom_fields => :_any_key_}], :allowed => "ok", :custom_fields => { :custom_allowed => "ok", :custom_allowed2 => "also ok", - } + }, ) expect(response).to eq(true) end it "raises an exception if the hash contains an invalid key" do response = Braintree::Util.keys_valid?([:allowed], :allowed => "ok", :disallowed => "bad") @@ -145,11 +145,11 @@ response = Braintree::Util.keys_valid?( [{:add_ons => [{:update => [:amount]}, {:add => [:amount]}]}], :add_ons => { :update => [{:foo => 10}], :add => [{:bar => 5}] - } + }, ) expect(response).to eq(false) end it "returns false if a deeply nested hash contains an invalid key" do @@ -163,11 +163,11 @@ :nested_invalid => "bad", :deeply_allowed => { :super_deep_allowed => "yep", :real_deep_invalid => "nope" } - } + }, ) expect(response).to eq(false) end end @@ -198,17 +198,17 @@ end describe "self._flatten_valid_keys" do it "flattens hash keys" do Braintree::Util._flatten_valid_keys( - [:top_level, {:nested => [:nested_allowed, :nested_allowed2]}] + [:top_level, {:nested => [:nested_allowed, :nested_allowed2]}], ).should == ["nested[nested_allowed2]", "nested[nested_allowed]", "top_level"] end it "allows wildcards with the :_any_key_ symbol" do Braintree::Util._flatten_valid_keys( - [:top_level, {:nested => :_any_key_}] + [:top_level, {:nested => :_any_key_}], ).should == ["nested[_any_key_]", "top_level"] end end describe "self.extract_attribute_as_array" do @@ -234,14 +234,14 @@ hash = {:foo => ["one", "two"], :bar => :baz} result = Braintree::Util.extract_attribute_as_array(hash, :quz) result.should == [] end - it "raises an UnexpectedError if nil data is provided" do - expect do - Braintree::Util.extract_attribute_as_array(nil, :abc) - end.to raise_error(Braintree::UnexpectedError, /Unprocessable entity due to an invalid request/) - end + it "raises an UnexpectedError if nil data is provided" do + expect do + Braintree::Util.extract_attribute_as_array(nil, :abc) + end.to raise_error(Braintree::UnexpectedError, /Unprocessable entity due to an invalid request/) + end end describe "self.hash_to_query_string" do it "generates a query string from the hash" do hash = {:foo => {:key_one => "value_one", :key_two => "value_two"}}