Skip to content

Commit

Permalink
Merge branch 'release-2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomelm committed Aug 12, 2014
2 parents d4b4aaa + c05c49d commit ef182d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/yelp/burst_struct.rb
Expand Up @@ -15,7 +15,7 @@ def method_missing(method_name, *arguments, &block)
end

def respond_to?(method_name, include_private = false)
@hash.keys.include?(method_name) || super
has_key?(method_name) || super
end

def self.convert_array(array)
Expand All @@ -35,6 +35,10 @@ def to_json(options = {})
JSON.generate(@hash)
end

def has_key?(method_name)
!find_key(method_name).nil?
end

private

def return_or_build_struct(method_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/yelp/version.rb
@@ -1,3 +1,3 @@
module Yelp
VERSION = "2.0.1"
VERSION = "2.0.2"
end
23 changes: 23 additions & 0 deletions spec/yelp/burst_struct_spec.rb
Expand Up @@ -8,12 +8,20 @@
it 'should return' do
expect(struct.foo).to eql 'bar'
end

it { should have_key(:foo) }
it { should have_key('foo') }

it { should respond_to(:foo) }
end

context 'when a key does not exist' do
it 'should not respond to it' do
expect(struct.respond_to? :super_foo).to eql false
end

it { should_not have_key(:super_foo) }
it { should_not have_key('super_foo') }
end
end

Expand Down Expand Up @@ -121,4 +129,19 @@
expect(struct.to_json).to eql hash.to_json
end
end

context 'struct with string keys' do
subject(:struct) { BurstStruct::Burst.new('foo' => 'bar') }

context 'when a key exists' do
it 'should return' do
expect(struct.foo).to eql 'bar'
end

it { should have_key(:foo) }
it { should have_key('foo') }

it { should respond_to(:foo) }
end
end
end

0 comments on commit ef182d2

Please sign in to comment.