Skip to content

Commit

Permalink
Delegate OpenStructWithHashAccess#key? to the underlying hash
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Apr 8, 2015
1 parent e687376 commit 282c996
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blacklight/utils.rb
Expand Up @@ -26,7 +26,7 @@ def self.protected_attributes_enabled?
##
# An OpenStruct that responds to common Hash methods
class OpenStructWithHashAccess < OpenStruct
delegate :keys, :each, :map, :has_key?, :include?, :empty?, :length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!, :replace, :fetch, :to_json, :as_json, to: :to_h
delegate :keys, :each, :map, :has_key?, :key?, :include?, :empty?, :length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!, :replace, :fetch, :to_json, :as_json, to: :to_h

if ::RUBY_VERSION < '2.0'
def []=(key, value)
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/utils_spec.rb
Expand Up @@ -48,6 +48,23 @@

end

describe "#key?" do
subject do
h = Blacklight::OpenStructWithHashAccess.new
h[:a] = 1
h[:b] = 2
h
end

it "is true if the key exists" do
expect(subject.key? :a).to eq true
end

it "is false if the key does not exist" do
expect(subject.key? :c).to eq false
end
end

describe "#replace" do
subject { Blacklight::OpenStructWithHashAccess.new a: 1 }

Expand Down

0 comments on commit 282c996

Please sign in to comment.