# factories/users.rb
FactoryGirl.define do
sequence :email do |n|
"user#{n}@test.com"
end
factory :user do
first_name 'Jon'
last_name 'Snow'
email { generate :email }
password 'testing'
password_confirmation 'testing'
end
factory :admin_user, class: "AdminUser" do
first_name 'Admin'
last_name 'User'
email { generate :email }
password 'testing'
password_confirmation 'testing'
end
end
Failures:
1) Navigate index has a list of Posts
Failure/Error: expect(page).to have_content(/Some|super/)
expected to find text matching /Some|super/ in "Home Time Entries Account Log In Edit Profile Logout Posts # Date User Rationale"
# ./spec/features/post_spec.rb:26:in `block (3 levels) in <top (required)>'
# factories/posts.rb
FactoryGirl.define do
factory :post do
date Date.today
rationale 'Some Rationale'
user
end
factory :second_post, class: "Post" do
date Date.yesterday
rationale 'super Potatoes'
user
end
end
# features/post_spec.rb
require 'rails_helper'
describe 'Navigate' do
before do
@user = FactoryGirl.create(:user)
login_as(@user, :scope => :user)
end
describe 'index' do
before do
visit posts_path
end
it 'can be reached successfully' do
expect(page.status_code).to eq(200)
end
it 'has a title of Posts' do
expect(page).to have_content(/Posts/)
end
it 'has a list of Posts' do
post1 = FactoryGirl.build_stubbed(:post)
post2 = FactoryGirl.build_stubbed(:second_post)
visit posts_path
expect(page).to have_content(/Some|super/)
end
end
describe 'Creation' do
before do
visit new_post_path
end
it 'has a form that can be reached at posts/new' do
expect(page.status_code).to eq(200)
end
it 'can be created from new form page' do
fill_in 'post[date]', with: Date.today
fill_in 'post[rationale]', with: 'Some Rationale'
click_on 'Save'
expect(page).to have_content('Some Rationale')
end
it 'will have a user associated to it' do
fill_in 'post[date]', with: Date.today
fill_in 'post[rationale]', with: 'User_Association'
click_on 'Save'
expect(User.last.posts.last.rationale).to eq('User_Association')
end
end
end