Last active
October 30, 2020 15:49
-
-
Save berkes/bf1285ecf0420c58760be9224156c924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'delegate' | |
module Workflows | |
## | |
# Common workflow generics | |
class Base < SimpleDelegator | |
attr_reader :test_obj | |
def upto(final_step) | |
retval = nil | |
STEPS[0..STEPS.index(final_step)].each do |current_step| | |
retval = send(current_step) | |
test_obj.process_events # Call test-helper that runs all event Projectors and Reactors on the new events. | |
end | |
retval | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Workflows | |
class MemberRegisters < Base | |
STEPS = %i[registered confirmed subscribed].freeze | |
def registered | |
test_obj.visit '/' | |
test_obj.click_link 'Register' | |
test_obj.fill_in('Username', with: 'hpotter') | |
test_obj.fill_in('Password', with: 'caput draconis') | |
test_obj.fill_in('Email', with: 'harry@hogwards.edu.wiz') | |
test_obj.click_button('Register') | |
end | |
def confirmed | |
confirmation_url = confirmation_mail.mail.match(%r{http.*/confirmation/}) | |
test_obj.visit confirmation_url | |
end | |
def subscribed | |
test_obj.find('nav.main').click_link('Account') | |
test_obj.click_button('Choose Bronze') | |
test_obj.fill_in('Creditcard number', '5555555555554444') | |
test_obj.fill_in('CVC', '1234') | |
test_obj.click_button('Subscribe') | |
end | |
private | |
def confirmation_mail | |
Roost.mailer.deliveries.find do |email| | |
email.subject.match?(/Please confirm your email address/) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VisitorRegistersTest < Minitest::WebSpec | |
before do | |
Roost.mailer.deliveries.clear | |
end | |
describe 'with open registrations' do | |
it 'sends an email' do | |
page = Workflows::MemberRegisters.new(self).upto(:registered) | |
assert_content( | |
find('.notification'), | |
'Registration email sent. Please check your spam folder too' | |
) | |
process_events | |
assert_equal(1, Roost.mailer.deliveries.length) | |
assert_includes(email.to, 'harry@hogwards.edu.wiz') | |
assert_match( | |
/Welcome to Flockingbird. Please confirm your email address/, | |
email.subject | |
) | |
assert_match(%r{http.*/confirmation/[0-9A-Z]+}, email.body.to_s) | |
end | |
it 'confirms the email by clicking the link in the email' do | |
Workflows::MemberRegisters.new(self).upto(:confirmed) | |
assert_content( | |
find('.notification'), | |
'Email address confirmed. Welcome!' | |
) | |
asert_content(find('.header'), 'logged in as: hpotter') | |
end | |
end | |
describe 'with invite-only' do | |
before { skip 'implement setting' } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment