Ensuring that views with two properties will quick find
This commit is contained in:
parent
5d7fa3c198
commit
d0f8b0be68
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
2
spec/fixtures/more/course.rb
vendored
2
spec/fixtures/more/course.rb
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue