diff --git a/lib/couchrest/extended_document.rb b/lib/couchrest/extended_document.rb index 4c824c1..0e03e1a 100644 --- a/lib/couchrest/extended_document.rb +++ b/lib/couchrest/extended_document.rb @@ -130,7 +130,7 @@ module CouchRest if has_view?(m) query = args.shift || {} return view(m, query, *args, &block) - elsif m.to_s =~ /^find_(.+)/ + elsif m.to_s =~ /^find_(by_.+)/ view_name = $1 if has_view?(view_name) query = {:key => args.first, :limit => 1} diff --git a/spec/couchrest/extended_doc_view_spec.rb b/spec/couchrest/extended_doc_view_spec.rb index d429c0f..16ffec0 100644 --- a/spec/couchrest/extended_doc_view_spec.rb +++ b/spec/couchrest/extended_doc_view_spec.rb @@ -101,7 +101,7 @@ describe "ExtendedDocument views" do before(:all) do reset_test_db! %w{aaa bbb ddd eee}.each do |title| - Course.new(:title => title).save + Course.new(:title => title, :active => (title == 'bbb')).save end end @@ -116,6 +116,17 @@ describe "ExtendedDocument views" do course.should be_nil end + it "should peform search on view with two properties" do + course = Course.find_by_title_and_active(['bbb', true]) + course.should_not be_nil + course.title.should eql('bbb') # Ensure really is a Course! + end + + it "should return nil if not found" do + course = Course.find_by_title_and_active(['bbb', false]) + course.should be_nil + end + it "should raise exception if view not present" do lambda { Course.find_by_foobar('123') }.should raise_error(NoMethodError) end diff --git a/spec/fixtures/more/course.rb b/spec/fixtures/more/course.rb index 72b295e..8146065 100644 --- a/spec/fixtures/more/course.rb +++ b/spec/fixtures/more/course.rb @@ -19,5 +19,7 @@ class Course < CouchRest::ExtendedDocument property :klass, :type => 'Class' view_by :title + view_by :title, :active view_by :dept, :ducktype => true + end