Skip to content

Commit

Permalink
Ensure that :new_collection behavior applies with or without type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Rowe committed May 14, 2010
1 parent 81b5755 commit 41643af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_mapper/attribute/pattern.rb
Expand Up @@ -12,7 +12,7 @@ def pattern=(value)
end

def source_value(object)
object.simple_mapper_source.inject({}) do |hash, keyval|
object.simple_mapper_source.inject(new_collection) do |hash, keyval|
hash[from_simple_key(keyval[0])] = keyval[1] if pattern.match(keyval[0].to_s)
hash
end
Expand Down
5 changes: 5 additions & 0 deletions test/unit/attribute_pattern_test.rb
Expand Up @@ -54,6 +54,11 @@ class SimpleMapperAttributePatternTest < Test::Unit::TestCase
assert_equal({}, @instance.source_value(@object))
end

should 'get its container value from :new_collection' do
@instance.expects(:new_collection).returns(container = stub('container'))
assert_equal(container, @instance.source_value(@object))
end

should 'return hash with key/value pairs for only the keys matching pattern' do
expected = {:a => 'A', :abc => 'ABC', :aarp => 'AARP'}
@source_values.merge! expected
Expand Down

0 comments on commit 41643af

Please sign in to comment.