Sha256: d03f4a18b88bca27e4faed62a28918b335ad081743a880db5deb88890637b7ff

Contents?: true

Size: 1.41 KB

Versions: 41

Compression:

Stored size: 1.41 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')


describe 'Blacklight::Utils' do
  describe Blacklight::OpenStructWithHashAccess do
    it "should provide hash-like accessors for OpenStruct data" do
      a = Blacklight::OpenStructWithHashAccess.new :foo => :bar, :baz => 1

      a[:foo].should == :bar
      a[:baz].should == 1
      a[:asdf].should be_nil
    end

    it "should provide hash-like writers for OpenStruct data" do
      a = Blacklight::OpenStructWithHashAccess.new :foo => :bar, :baz => 1

      a[:asdf] = 'qwerty'
      a.asdf.should == 'qwerty'

    end
    
    it "should treat symbols and strings interchangeably in hash access" do
      h = Blacklight::OpenStructWithHashAccess.new
      
      h["string"] = "value"
      h[:string].should == "value"
      h.string.should == "value"
      
      h[:symbol] = "value"
      h["symbol"].should == "value"
      h.symbol.should == "value"      
    end

    describe "internal hash table" do
      before do
        @h = Blacklight::OpenStructWithHashAccess.new

        @h[:a] = 1
        @h[:b] = 2


      end
      it "should expose the internal hash table" do
        @h.to_h.should be_a_kind_of(Hash)
        @h.to_h[:a].should == 1
      end

      it "should expose keys" do
        @h.keys.should include(:a, :b)
      end

      it "should expose merge" do
        @h.merge(:a => 'a')[:a].should == 'a'
      end

    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
blacklight-4.6.3 spec/lib/utils_spec.rb
blacklight-4.6.2 spec/lib/utils_spec.rb
blacklight-4.6.1 spec/lib/utils_spec.rb
blacklight-5.0.0.pre1 spec/lib/utils_spec.rb
blacklight-4.6.0 spec/lib/utils_spec.rb
blacklight-4.5.0 spec/lib/utils_spec.rb
blacklight-4.5.0.rc1 spec/lib/utils_spec.rb
blacklight-4.4.2 spec/lib/utils_spec.rb
blacklight-4.4.1 spec/lib/utils_spec.rb
blacklight-4.4.0 spec/lib/utils_spec.rb
blacklight-4.3.0 spec/lib/utils_spec.rb
blacklight-4.2.2 spec/lib/utils_spec.rb
blacklight-4.2.1 spec/lib/utils_spec.rb
blacklight-4.2.0 spec/lib/utils_spec.rb
blacklight-4.1.0 test_support/spec/lib/utils_spec.rb
blacklight-4.0.1 test_support/spec/lib/utils_spec.rb
blacklight-3.8.2 test_support/spec/lib/utils_spec.rb
blacklight-4.0.0 test_support/spec/lib/utils_spec.rb
blacklight-4.0.0.rc2 test_support/spec/lib/utils_spec.rb
blacklight-4.0.0.rc1 test_support/spec/lib/utils_spec.rb