Skip to content

Commit

Permalink
[AR, DM, Mongoid, MongoMapper].each {|orm| run orm specs only if orm …
Browse files Browse the repository at this point in the history
…is loaded }
  • Loading branch information
amatsuda committed May 23, 2012
1 parent 53bae06 commit 854d04a
Show file tree
Hide file tree
Showing 6 changed files with 554 additions and 540 deletions.
42 changes: 22 additions & 20 deletions spec/models/active_record/active_record_relation_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
require 'spec_helper'

describe Kaminari::ActiveRecordRelationMethods do
describe '#total_count' do
before do
@author = User.create! :name => 'author'
@author2 = User.create! :name => 'author2'
@author3 = User.create! :name => 'author3'
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
@readers = 4.times.map { User.create! :name => 'reader' }
@books.each {|book| book.readers << @readers }
end
if defined? ActiveRecord
describe Kaminari::ActiveRecordRelationMethods do
describe '#total_count' do
before do
@author = User.create! :name => 'author'
@author2 = User.create! :name => 'author2'
@author3 = User.create! :name => 'author3'
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
@readers = 4.times.map { User.create! :name => 'reader' }
@books.each {|book| book.readers << @readers }
end

context "when the scope includes an order which references a generated column" do
it "should successfully count the results" do
@author.readers.by_read_count.page(1).total_count.should == @readers.size
context "when the scope includes an order which references a generated column" do
it "should successfully count the results" do
@author.readers.by_read_count.page(1).total_count.should == @readers.size
end
end
end
context "when the scope use conditions on includes" do
it "should keep includes and successfully count the results" do
# Only @author and @author2 have books titled with the title00x partern
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
context "when the scope use conditions on includes" do
it "should keep includes and successfully count the results" do
# Only @author and @author2 have books titled with the title00x partern
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
end
end
end
end
Expand Down
39 changes: 21 additions & 18 deletions spec/models/active_record/default_per_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
require 'spec_helper'

describe 'default per_page' do
describe 'AR::Base' do
subject { ActiveRecord::Base }
it { should_not respond_to :paginates_per }
end
if defined? ActiveRecord

subject { User.page 0 }
describe 'default per_page' do
describe 'AR::Base' do
subject { ActiveRecord::Base }
it { should_not respond_to :paginates_per }
end

context 'by default' do
its(:limit_value) { should == 25 }
end
subject { User.page 0 }

context 'when explicitly set via paginates_per' do
before { User.paginates_per 1326 }
its(:limit_value) { should == 1326 }
after { User.paginates_per nil }
end
context 'by default' do
its(:limit_value) { should == 25 }
end

describe "default per_page value's independency per model" do
context "when User's default per_page was changed" do
context 'when explicitly set via paginates_per' do
before { User.paginates_per 1326 }
subject { Book.page 0 }
its(:limit_value) { should == 25 }
its(:limit_value) { should == 1326 }
after { User.paginates_per nil }
end

describe "default per_page value's independency per model" do
context "when User's default per_page was changed" do
before { User.paginates_per 1326 }
subject { Book.page 0 }
its(:limit_value) { should == 25 }
after { User.paginates_per nil }
end
end
end
end
Loading

0 comments on commit 854d04a

Please sign in to comment.