Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding respond_to override to the ObjectifiedHash class ... #96

Merged
merged 1 commit into from
Dec 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/gitlab/objectified_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ def to_hash
def method_missing(key)
@data.key?(key.to_s) ? @data[key.to_s] : nil
end

def respond_to?(method_name, include_private = false)
@hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
end
end
end
20 changes: 19 additions & 1 deletion spec/gitlab/objectified_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Gitlab::ObjectifiedHash do
before do
@hash = {a: 1, b: 2}
@hash = {a: 1, b: 2, 'string' => 'string', symbol: :symbol}
@oh = Gitlab::ObjectifiedHash.new @hash
end

Expand All @@ -20,4 +20,22 @@
expect(@oh.respond_to?(:to_h)).to be_truthy
end
end

describe "#respond_to" do
it "should return true for methods this object responds to through method_missing as sym" do
expect(@oh.respond_to?(:a)).to be_truthy
end

it "should return true for methods this object responds to through method_missing as string" do
expect(@oh.respond_to?('string')).to be_truthy
end

it "should not care if you use a string or symbol to reference a method" do
expect(@oh.respond_to?(:string)).to be_truthy
end

it "should not care if you use a string or symbol to reference a method" do
expect(@oh.respond_to?('symbol')).to be_truthy
end
end
end