demarches-normaliennes/spec/support/feature_helpers.rb

66 lines
1.7 KiB
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
module FeatureHelpers
include ActiveJob::TestHelper
2015-08-10 11:05:06 +02:00
def login_admin
user = create :user
2015-08-10 11:05:06 +02:00
login_as user, scope: :user
user
end
2015-09-22 10:15:12 +02:00
def login_gestionnaire
gestionnaire = create(:gestionnaire)
login_as gestionnaire, scope: :gestionnaire
end
2015-08-10 11:05:06 +02:00
def create_dossier
2018-01-23 17:15:42 +01:00
dossier = FactoryBot.create(:dossier)
2015-08-10 11:05:06 +02:00
dossier
end
def sign_in_with(email, password, sign_in_by_link = false)
fill_in :user_email, with: email
fill_in :user_password, with: password
perform_enqueued_jobs do
click_on 'Se connecter'
end
if sign_in_by_link
mail = ActionMailer::Base.deliveries.last
2018-12-26 17:35:28 +01:00
message = mail.html_part.body.raw_source
gestionnaire_id = message[/\".+\/connexion-par-jeton\/(.+)\?jeton=(.*)\"/, 1]
jeton = message[/\".+\/connexion-par-jeton\/(.+)\?jeton=(.*)\"/, 2]
2018-12-26 17:35:28 +01:00
visit sign_in_by_link_path(gestionnaire_id, jeton: jeton)
end
end
def sign_up_with(email, password = 'testpassword')
fill_in :user_email, with: email
fill_in :user_password, with: password
perform_enqueued_jobs do
click_button 'Créer un compte'
end
end
def click_confirmation_link_for(email)
confirmation_email = open_email(email)
token_params = confirmation_email.body.match(/confirmation_token=[^"]+/)
visit "/users/confirmation?#{token_params}"
end
def expect_page_to_have_procedure_description(procedure)
# Procedure context on the page
expect(page).to have_content(procedure.libelle)
expect(page).to have_content(procedure.description)
# Procedure contact infos in the footer
expect(page).to have_content(procedure.service.email)
end
2015-08-10 11:05:06 +02:00
end
RSpec.configure do |config|
config.include FeatureHelpers, type: :feature
2015-08-20 17:30:17 +02:00
end