Permalink
Browse files

Add tests for micropost navigation

  • Loading branch information...
1 parent bac27a9 commit 98982a413eb1c42a48d5fa70d27f8a54c29efef1 Olivier SCHNEIDER committed Mar 23, 2012
Showing with 30 additions and 3 deletions.
  1. +30 −3 spec/requests/static_pages_spec.rb
@@ -18,12 +18,14 @@
describe "for signed-in users" do
let(:user) { FactoryGirl.create(:user) }
+ before do
+ sign_in user
+ end
describe "with several microposts" do
before do
FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum")
FactoryGirl.create(:micropost, user: user, content: "Dolor sit amet")
- sign_in user
visit root_path
end
@@ -45,14 +47,39 @@
describe "without any micropost" do
before do
- sign_in user
visit root_path
end
-
it "should not pluralize microspost" do
page.should have_selector('span', text: "#{user.microposts.count} micropost")
end
end
+
+ describe "pagination" do
+ before do
+ 100.times do
+ FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum")
+ end
+ visit root_path
+ end
+
+ let(:first_page) { user.microposts.paginate(page: 1) }
+ let(:second_page) { user.microposts.paginate(page: 2) }
+
+ it { should have_link('Next') }
+ it { should have_link('2') }
+
+ it "should list the first page of microposts" do
+ first_page.each do |micropost|
+ page.should have_selector("tr##{micropost.id}", text: micropost.content)
+ end
+ end
+
+ it "should not list the second page of microposts" do
+ second_page.each do |micropost|
+ page.should_not have_selector("tr##{micropost.id}", text: micropost.content)
+ end
+ end
+ end
end
end

0 comments on commit 98982a4

Please sign in to comment.