Прежде всего, при разработке, вам, возможно, придется «подтвердить» пользователя.
вы можете сделать что-то вроде этого:
user = User.make!
user.confirmed_at = Time.now
user.save!
Вот пример без Machinist (но вам просто нужно заменить часть кода создания пользователя на часть выше):
в test_integration_helper:
require "test_helper"
require "capybara/rails"
module ActionController
class IntegrationTest
include Capybara
def sign_in_as(user, password)
user = User.create(:password => password, :password_confirmation => password, :email => user)
user.confirmed_at = Time.now
user.save!
visit '/'
click_link_or_button('Log in')
fill_in 'Email', :with => user.email
fill_in 'Password', :with => password
click_link_or_button('Sign in')
user
end
def sign_out
click_link_or_button('Log Out')
end
end
end
И в ваш интеграционный тест:
require 'test_integration_helper'
class UsersIntegrationTest < ActionController::IntegrationTest
test "sign in and then sign out" do
#this helper method is into the test_integration_helper file
sign_in_as("lolz@gmail.com", "monkey")
assert page.has_content?('Signed in successfully'), "Signed in successfully"
sign_out
assert page.has_content?('Signed out successfully'), "Signed out successfully"
end
end