0
@@ -148,6 +148,19 @@ describe WillPaginate::Finders::ActiveRecord do
0
ArProject.paginate_by_id(ids, :per_page => 3, :page => 2, :order => 'id')
0
+ # Is this Rails 2.0? Find out by testing find_all which was removed in [6998]
0
+ unless ActiveRecord::Base.respond_to? :find_all
0
+ it "should paginate array of IDs" do
0
+ # AR finders also accept arrays of IDs
0
+ # (this was broken in Rails before [6912])
0
+ result = Developer.paginate((1..8).to_a, :per_page => 3, :page => 2, :order => 'id')
0
+ result.map(&:id).should == (4..6).to_a
0
+ result.total_entries.should == 8
0
+ }.should run_queries(1)
0
it "doesn't mangle options" do
0
ArProject.expects(:find).returns([])
0
@@ -243,6 +256,66 @@ describe WillPaginate::Finders::ActiveRecord do
0
:include => :projects, :conditions => 'projects.id > 2'
0
+ describe "associations" do
0
+ it "should paginate with include" do
0
+ project = projects(:active_record)
0
+ result = project.topics.paginate \
0
+ :conditions => ["replies.content LIKE ?", 'Nice%'],
0
+ expected = Topic.find :all,
0
+ :include => 'replies',
0
+ :conditions => ["project_id = #{project.id} AND replies.content LIKE ?", 'Nice%'],
0
+ result.should == expected
0
+ it "should paginate" do
0
+ expected_name_ordered = projects(:action_controller, :active_record)
0
+ expected_id_ordered = projects(:active_record, :action_controller)
0
+ # with association-specified order
0
+ result = dhh.projects.paginate(:page => 1)
0
+ result.should == expected_name_ordered
0
+ result.total_entries.should == 2
0
+ }.should run_queries(2)
0
+ result = dhh.projects.paginate(:page => 1, :order => 'projects.id')
0
+ result.should == expected_id_ordered
0
+ result.total_entries.should == 2
0
+ dhh.projects.find(:all, :order => 'projects.id', :limit => 4)
0
+ }.should_not raise_error
0
+ result = dhh.projects.paginate(:page => 1, :order => 'projects.id', :per_page => 4)
0
+ result.should == expected_id_ordered
0
+ # has_many with implicit order
0
+ expected = replies(:spam, :witty_retort)
0
+ # FIXME: wow, this is ugly
0
+ topic.replies.paginate(:page => 1).map(&:id).sort.should == expected.map(&:id).sort
0
+ topic.replies.paginate(:page => 1, :order => 'replies.id ASC').should == expected.reverse
0
+ it "should paginate through association extension" do
0
+ project = Project.find(:first)
0
+ result = project.replies.paginate_recent :page => 1
0
+ result.should == [replies(:brave)]
0
+ }.should run_queries(2)
Comments
No one has commented yet.