spec/mongomodel/support/scope_spec.rb in mongomodel-0.4.9 vs spec/mongomodel/support/scope_spec.rb in mongomodel-0.5.0

- old
+ new

@@ -276,27 +276,37 @@ order_scope.order_values.should == [:author.asc] end end describe "#select" do - it "returns a new scope" do - subject.select(:author).should be_an_instance_of(Scope) - end + context "when no block is given" do + it "returns a new scope" do + subject.select(:author).should be_an_instance_of(Scope) + end - it "is not loaded" do - subject.to_a - subject.select(:author).should_not be_loaded - end + it "is not loaded" do + subject.to_a + subject.select(:author).should_not be_loaded + end - it "adds individual select values" do - select_scope = subject.select(:author) - select_scope.select_values.should == subject.select_values + [:author] + it "adds individual select values" do + select_scope = subject.select(:author) + select_scope.select_values.should == subject.select_values + [:author] + end + + it "adds multiple select values" do + select_scope = subject.select(:author, :published) + select_scope.select_values.should == subject.select_values + [:author, :published] + end end - it "adds multiple select values" do - select_scope = subject.select(:author, :published) - select_scope.select_values.should == subject.select_values + [:author, :published] + context "when a block given" do + it "passed block to to_a#select" do + blk = lambda { |*args| true } + subject.to_a.should_receive(:select).with(&blk) + subject.select(&blk) + end end end describe "#select!" do it "overwrites select values" do @@ -778,10 +788,10 @@ end it "loads total entries using count when auto-detection not possible" do paginator = nil - subject.stub!(:count).and_return(57) + subject.stub(:count).and_return(57) model.should_find(finder_options.merge(:offset => 0, :limit => 5), posts) { paginator = subject.paginate(:per_page => 5) } paginator.total_entries.should == 57