spec/utils_spec.rb in i18n-js-3.0.0.rc9 vs spec/utils_spec.rb in i18n-js-3.0.0.rc10
- old
+ new
@@ -64,6 +64,43 @@
result.should eql({:a => {:c => 2}})
hash.should eql({:a => {:b => 1, :c => 2}})
end
end
+
+ describe ".deep_key_sort" do
+ let(:unsorted_hash) { {:z => {:b => 1, :a => 2}, :y => 3} }
+ subject(:sorting) { described_class.deep_key_sort(unsorted_hash) }
+
+ it "performs a deep keys sort without changing the original hash" do
+ should eql({:y => 3, :z => {:a => 2, :b => 1}})
+ unsorted_hash.should eql({:z => {:b => 1, :a => 2}, :y => 3})
+ end
+
+ # Idea from gem `rails_admin`
+ context "when hash contain non-Symbol as key" do
+ let(:unsorted_hash) { {:z => {1 => 1, true => 2}, :y => 3} }
+
+ it "performs a deep keys sort without error" do
+ expect{ sorting }.to_not raise_error
+ end
+ it "converts keys to symbols" do
+ should eql({:y => 3, :z => {1 => 1, true => 2}})
+ end
+ end
+ end
+
+ describe ".scopes_match?" do
+ it "performs a comparison of literal scopes" do
+ described_class.scopes_match?([:a, :b], [:a, :b, :c]).should_not eql true
+ described_class.scopes_match?([:a, :b, :c], [:a, :b, :c]).should eql true
+ described_class.scopes_match?([:a, :b, :c], [:a, :b, :d]).should_not eql true
+ end
+
+ it "performs a comparison of wildcard scopes" do
+ described_class.scopes_match?([:a, '*'], [:a, :b, :c]).should_not eql true
+ described_class.scopes_match?([:a, '*', :c], [:a, :b, :c]).should eql true
+ described_class.scopes_match?([:a, :b, :c], [:a, '*', :c]).should eql true
+ described_class.scopes_match?([:a, :b, :c], [:a, '*', '*']).should eql true
+ end
+ end
end