Skip to content

Commit

Permalink
Add tests for micropost navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier SCHNEIDER committed Mar 23, 2012
1 parent bac27a9 commit 98982a4
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions spec/requests/static_pages_spec.rb
Expand Up @@ -18,12 +18,14 @@


describe "for signed-in users" do describe "for signed-in users" do
let(:user) { FactoryGirl.create(:user) } let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
end


describe "with several microposts" do describe "with several microposts" do
before do before do
FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum") FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum")
FactoryGirl.create(:micropost, user: user, content: "Dolor sit amet") FactoryGirl.create(:micropost, user: user, content: "Dolor sit amet")
sign_in user
visit root_path visit root_path
end end


Expand All @@ -45,14 +47,39 @@


describe "without any micropost" do describe "without any micropost" do
before do before do
sign_in user
visit root_path visit root_path
end end

it "should not pluralize microspost" do it "should not pluralize microspost" do
page.should have_selector('span', text: "#{user.microposts.count} micropost") page.should have_selector('span', text: "#{user.microposts.count} micropost")
end end
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
end end


Expand Down

0 comments on commit 98982a4

Please sign in to comment.