Skip to content

Commit 52f2afe

Browse files
committed
Add redirect if feature flag isn't enabled
1 parent 08f5183 commit 52f2afe

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

app/controllers/forms/welsh_translation_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ class WelshTranslationController < WebController
44

55
def new
66
authorize current_form, :can_view_form?
7+
return redirect_to form_path(current_form) unless welsh_enabled?
8+
79
@welsh_translation_input = WelshTranslationInput.new(form: current_form).assign_form_values
810
end
911

1012
def create
1113
authorize current_form, :can_view_form?
14+
return redirect_to form_path(current_form) unless welsh_enabled?
15+
1216
@welsh_translation_input = WelshTranslationInput.new(**welsh_translation_input_params)
1317

1418
if @welsh_translation_input.submit
@@ -27,5 +31,9 @@ def create
2731
def welsh_translation_input_params
2832
params.require(:forms_welsh_translation_input).permit(:mark_complete).merge(form: current_form)
2933
end
34+
35+
def welsh_enabled?
36+
FeatureService.new(group: current_form.group).enabled?(:welsh)
37+
end
3038
end
3139
end

spec/requests/forms/welsh_translation_controller_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
let(:id) { form.id }
66

77
let(:current_user) { standard_user }
8-
let(:group) { create(:group, organisation: standard_user.organisation, welsh_enabled: false) }
8+
let(:group) { create(:group, organisation: standard_user.organisation, welsh_enabled:) }
9+
10+
let(:welsh_enabled) { true }
911

1012
before do
1113
Membership.create!(group_id: group.id, user: standard_user, added_by: standard_user)
@@ -34,6 +36,14 @@
3436
expect(response).to have_http_status(:forbidden)
3537
end
3638
end
39+
40+
context "when the welsh feature is not enabled for the group" do
41+
let(:welsh_enabled) { false }
42+
43+
it "redirects to the form" do
44+
expect(response).to redirect_to(form_path(id))
45+
end
46+
end
3747
end
3848

3949
describe "#create" do
@@ -119,5 +129,20 @@
119129
expect(response).to have_http_status(:forbidden)
120130
end
121131
end
132+
133+
context "when the welsh feature is not enabled for the group" do
134+
let(:welsh_enabled) { false }
135+
136+
it "does not update the form" do
137+
expect {
138+
post(welsh_translation_create_path(id), params:)
139+
}.not_to(change { form.reload.welsh_completed })
140+
end
141+
142+
it "redirects to the form" do
143+
post(welsh_translation_create_path(id), params:)
144+
expect(response).to redirect_to(form_path(id))
145+
end
146+
end
122147
end
123148
end

0 commit comments

Comments
 (0)