Browse files

allow properties to be passed as strings to queries

  • Loading branch information...
1 parent ecdcb67 commit 5efabdb9db0e66ba8547c776f1cfbb48291c7d91 @timcowlishaw committed Apr 18, 2012
Showing with 38 additions and 1 deletion.
  1. +1 −1 lib/persistence/sequel/identity_set_repository.rb
  2. +37 −0 test/sequel_test.rb
View
2 lib/persistence/sequel/identity_set_repository.rb
@@ -167,7 +167,7 @@ def add_observer(observer)
# convenience to get a particular property mapper of this repo:
def mapper(name)
- @property_mappers[name] or raise "#{self.class}: no such property mapper #{name.inspect}"
+ @property_mappers[name.to_sym] or raise "#{self.class}: no such property mapper #{name.inspect}"
end
# if you want to avoid the need to manually pass in target_repo parameters for each property
View
37 test/sequel_test.rb
@@ -67,6 +67,43 @@ def make_id_set_repo
assert !entity.attribute_loaded?(:def)
end
+ it "should accept a property name passed as a string to get_by_property" do
+ entity = make_entity(:id => 1, :abc => 'foo', :def => 'bar')
+ @repository.store_new(entity)
+ assert_equal entity, @repository.get_by_property("abc", "foo")
+ end
+
+ it "should accept a property name passed as a symbol to get_by_property" do
+ entity = make_entity(:id => 1, :abc => 'foo', :def => 'bar')
+ @repository.store_new(entity)
+ assert_equal entity, @repository.get_by_property(:abc, "foo")
+ end
+
+ it "should accept a property name passed as a string to get_property" do
+ entity = make_entity(:id => 1, :abc => 'foo', :def => 'bar')
+ @repository.store_new(entity)
+ assert_equal "foo", @repository.get_property(entity, "abc", "foo")
+ end
+
+ it "should accept a property name passed as a symbol to get_property" do
+ entity = make_entity(:id => 1, :abc => 'foo', :def => 'bar')
+ @repository.store_new(entity)
+ assert_equal "foo", @repository.get_property(entity, :abc, "foo")
+ end
+
+ it "should accept a property name passed as a string to get_many_by_property" do
+ entity = make_entity(:id => 1, :abc => 'foo', :def => 'bar')
+ @repository.store_new(entity)
+ assert_equal [entity], @repository.get_many_by_property("abc", "foo")
+ end
+
+ it "should accept a property name passed as a symbol to get_many_by_property" do
+ entity = make_entity(:id => 1, :abc => 'foo', :def => 'bar')
+ @repository.store_new(entity)
+ assert_equal [entity], @repository.get_many_by_property(:abc, "foo")
+ end
+
+
describe "map_column", self do
it "should map a schema property to a database column of the same name" do
@db = Sequel.sqlite

0 comments on commit 5efabdb

Please sign in to comment.