Skip to content

Commit

Permalink
add env variable feature flag for early years emails
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-coggin committed Jul 12, 2023
1 parent 96498b0 commit 26c6474
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 11 deletions.
10 changes: 7 additions & 3 deletions app/controllers/registration/training_emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ def update
@user_form = Users::TrainingEmailsForm.new(user_params.merge(user: current_user))

if @user_form.save
if current_user.registration_complete?
redirect_to my_modules_path, notice: t('.complete_update')
if ENV['EARLY_YEARS_EMAILS']
redirect_to edit_registration_early_years_emails_path
else
complete_registration
if current_user.registration_complete?
redirect_to my_modules_path, notice: t('.complete_update')
else
complete_registration
end
end
else
render :edit, status: :unprocessable_entity
Expand Down
19 changes: 19 additions & 0 deletions app/forms/users/early_years_emails_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Users
class EarlyYearsEmailsForm < BaseForm
attr_accessor :early_years_emails

validates :early_years_emails, presence: true

def name
'early_years_emails'
end

def save
if valid?
user.update!(
early_years_emails: early_years_emails,
)
end
end
end
end
14 changes: 14 additions & 0 deletions app/views/registration/early_years_emails/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
= govuk_back_link= govuk_back_link href: edit_registration_training_emails_path
.govuk-grid-row
.govuk-grid-column-full
= form_for @user_form, url: registration_early_years_emails_path, method: :patch do |f|
= f.govuk_error_summary
= f.govuk_collection_radio_buttons :early_years_emails,
[OpenStruct.new(id: true, name: t('.opt_in')),OpenStruct.new(id: false, name: t('.opt_out'))],
:id,
:name,
legend: { text: t('.heading') },
hint: { text: translate_markdown(t('.body')) }

div class='govuk-!-margin-top-4'
= f.govuk_submit t('.button')
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
resource :role_type, only: %i[edit update], path: 'role-type'
resource :role_type_other, only: %i[edit update], path: 'role-type-other'
resource :training_emails, only: %i[edit update], path: 'training-emails'
resource :early_years_emails, only: %i[edit update], path: 'early-years-emails'
end

resource :user, controller: :user, only: %i[show], path: 'my-account' do
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
describe 'POST #update' do
it 'succeeds' do
post :update, params: { user: { training_emails: 'true' } }
expect(response).to redirect_to my_modules_path
if ENV['EARLY_YEARS_EMAILS']
expect(response).to redirect_to edit_registration_early_years_emails_path
else
expect(response).to redirect_to my_modules_path
end
expect(confirmed_user.reload.training_emails).to eq true
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

trait :emails_opt_out do
training_emails { false }
if ENV['EARLY_YEARS_EMAILS']
early_years_emails { false }
end
end
end
end
6 changes: 5 additions & 1 deletion spec/requests/registration/training_emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

it 'redirects to my training email preference' do
update_user
expect(response).to redirect_to(my_modules_path)
if ENV['EARLY_YEARS_EMAILS']
expect(response).to redirect_to(edit_registration_early_years_emails_path)
else
expect(response).to redirect_to(my_modules_path)
end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/system/confirmed_user/completing_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@

click_button 'Continue'

if ENV['EARLY_YEARS_EMAILS']

expect(page).to have_text('Do you want to get early years email updates from the Department for Education?')

click_button 'Continue'

expect(page).to have_text('There is a problem')
.and have_text('Choose an option.')

choose 'Send me early years email updates'

click_button 'Continue'

end

expect(page).to have_text('Thank you for creating an Early years child development training account. You can now start the first module.')
end
end

0 comments on commit 26c6474

Please sign in to comment.