From a14d97dd3803d63846a741235715554422e41c87 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Tue, 25 Oct 2011 10:31:35 +0200 Subject: [PATCH] Clean up mongoid specs by letting criteria be MongoidModel.criteria. --- spec/finders/mongoid_spec.rb | 44 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/spec/finders/mongoid_spec.rb b/spec/finders/mongoid_spec.rb index de7543c08..a01ba2a85 100644 --- a/spec/finders/mongoid_spec.rb +++ b/spec/finders/mongoid_spec.rb @@ -8,8 +8,10 @@ class MongoidModel end describe "will paginate mongoid" do + let(:criteria) { MongoidModel.criteria } + it "should have the #paginate method" do - MongoidModel.criteria.should respond_to(:paginate) + criteria.should respond_to(:paginate) end describe "pagination" do @@ -19,62 +21,58 @@ class MongoidModel end it "should use criteria" do - MongoidModel.all.paginate.should be_instance_of(::Mongoid::Criteria) + criteria.paginate.should be_instance_of(::Mongoid::Criteria) end it "should limit according to per_page parameter" do - criteria = MongoidModel.all.paginate(:per_page => 10) - criteria.options.should include(:limit => 10) + criteria.paginate(:per_page => 10).options.should include(:limit => 10) end it "should skip according to page and per_page parameters" do - criteria = MongoidModel.all.paginate(:page => 2, :per_page => 5) - criteria.options.should include(:skip => 5) + criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5) end specify "per_page should default to value configured for WillPaginate" do - criteria = MongoidModel.all.paginate - criteria.options.should include(:limit => WillPaginate.per_page) + criteria.paginate.options.should include(:limit => WillPaginate.per_page) end specify "page should default to 1" do - MongoidModel.all.paginate.options.should include(:skip => 0) + criteria.paginate.options.should include(:skip => 0) end it "should convert strings to integers" do - MongoidModel.all.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3, :limit => 3) + criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3, :limit => 3) end describe "collection compatibility" do it "should calculate total_count" do - MongoidModel.all.paginate(:per_page => 1).total_entries.should == 4 - MongoidModel.all.paginate(:per_page => 3).total_entries.should == 4 + criteria.paginate(:per_page => 1).total_entries.should == 4 + criteria.paginate(:per_page => 3).total_entries.should == 4 end it "should calculate total_pages" do - MongoidModel.all.paginate(:per_page => 1).total_pages.should == 4 - MongoidModel.all.paginate(:per_page => 3).total_pages.should == 2 - MongoidModel.all.paginate(:per_page => 10).total_pages.should == 1 + criteria.paginate(:per_page => 1).total_pages.should == 4 + criteria.paginate(:per_page => 3).total_pages.should == 2 + criteria.paginate(:per_page => 10).total_pages.should == 1 end it "should return per_page" do - MongoidModel.all.paginate(:per_page => 1).per_page.should == 1 - MongoidModel.all.paginate(:per_page => 5).per_page.should == 5 + criteria.paginate(:per_page => 1).per_page.should == 1 + criteria.paginate(:per_page => 5).per_page.should == 5 end it "should return current_page" do - MongoidModel.all.paginate(:page => 1).current_page.should == 1 - MongoidModel.all.paginate(:page => 3).current_page.should == 3 + criteria.paginate(:page => 1).current_page.should == 1 + criteria.paginate(:page => 3).current_page.should == 3 end it "should return offset" do - MongoidModel.all.paginate(:page => 1).offset.should == 0 - MongoidModel.all.paginate(:page => 2, :per_page => 5).offset.should == 5 - MongoidModel.all.paginate(:page => 3, :per_page => 10).offset.should == 20 + criteria.paginate(:page => 1).offset.should == 0 + criteria.paginate(:page => 2, :per_page => 5).offset.should == 5 + criteria.paginate(:page => 3, :per_page => 10).offset.should == 20 end it "should not pollute plain mongoid criterias" do - criteria = MongoidModel.criteria %w(total_entries total_pages per_page current_page).each do |method| criteria.should_not respond_to(method) end