Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
add .merge to HashBasedStore
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenchanin committed Sep 28, 2010
1 parent e0ffa94 commit 78e8207
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/strava/hash_based_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def to_s
alias_method :original_inspect, :inspect
alias_method :inspect, :to_s

def merge(other)
@valid_attributes.each do |json_key, ruby_key|
@values[ruby_key] = other[ruby_key] if other[ruby_key]
end
end

def method_missing(symbol, *args)
if @valid_attributes.values.include?(symbol)
@values[symbol]
Expand Down
2 changes: 2 additions & 0 deletions strava.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |s|
"test/helper.rb",
"test/test_base.rb",
"test/test_clubs.rb",
"test/test_hash_based_store.rb",
"test/test_rides.rb",
"test/test_segments.rb",
"test/test_strava.rb"
Expand All @@ -50,6 +51,7 @@ Gem::Specification.new do |s|
"test/helper.rb",
"test/test_base.rb",
"test/test_clubs.rb",
"test/test_hash_based_store.rb",
"test/test_rides.rb",
"test/test_segments.rb",
"test/test_strava.rb"
Expand Down
21 changes: 21 additions & 0 deletions test/test_hash_based_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,25 @@ def test_create_with_nested_object_via_methods
assert obj.bike.id == @complex_initial_values['bike']['id']
assert obj.bike.name == @complex_initial_values['bike']['name']
end

def test_merge
@big_attribute_map = {'name' => :name, 'id' => :id, "extra1" => :extra1, "extra2" => :extra2 }

obj1 = Strava::HashBasedStore.new(@connection, @big_attribute_map, {}, {'id' => 13, 'name' => 'Fred'})
assert obj1.name == 'Fred'
assert obj1.id == 13

obj2 = Strava::HashBasedStore.new(@connection, @big_attribute_map, {},
{'id' => 13, 'name' => 'Fred', 'extra1' => 'red', 'extra2' => 'sneaker'})
assert obj2.name == 'Fred'
assert obj2.id == 13
assert obj2.extra1 == 'red'
assert obj2.extra2 == 'sneaker'

obj1.merge(obj2)
assert obj1.name == 'Fred'
assert obj1.id == 13
assert obj1.extra1 == 'red'
assert obj1.extra2 == 'sneaker'
end
end

0 comments on commit 78e8207

Please sign in to comment.