So I'm making an web app here using Rails 4, and if it helps I'm on a Mac using Mountain Lion, developing using Aptana Studio 3.
I'm trying to make a page that will list and paginate my application's users. I'm using will_paginate and bootstrap-will_paginate to do that. It works perfectly when I run rails server using sample users on my database, but when I run my tests using RSpec and FactoryGirl all my tests for pages requiring user authorization aren't working. So that's why I think the problem is FactoryGirl.
Previously, my factories.rb looked like this, since it only needed to create one user:
FactoryGirl.define do
factory :user do
username "example_user"
password "foobar"
password_confirmation "foobar"
end
end
Now I changed it to do this:
FactoryGirl.define do
factory :user do
sequence(:username) { |n| "Person_#{n}" }
password "foobar"
password_confirmation "foobar"
end
end
And here are the changes to my user_pages_spec file. It's the only thing I have changed aside from the factories file before the tests stopped passing. This is the diff for it:
describe "index" do
- before do
- sign_in FactoryGirl.create(:user)
- FactoryGirl.create(:user, username: "bananarama")
- FactoryGirl.create(:user, username: "appleface")
+ let(:user) { FactoryGirl.create(:user) }
+ before(:each) do
+ sign_in user
visit users_path
end
it { should have_title('All users') }
it { should have_content('All users') }
- it "should list each user" do
- User.all.each do |user|
- expect(page).to have_selector('li', text: user.username)
+ describe "pagination" do
+
+ before(:all) { 30.times { FactoryGirl.create(:user) } }
+ after(:all) { User.delete_all }
+
+ it { should have_selector('div.pagination') }
+
+ it "should list each user" do
+ User.paginate(page: 1).each do |user|
+ expect(page).to have_selector('li', text: user.username)
+ end
end
end
end
Is something missing? Anything else I should be looking at? Again, the tests that are failing are the ones on pages about authorization. These include some in my authorization_pages_spec.rb
Thanks a lot!