Skip to content

Commit a638485

Browse files
committed
Add spec to check that a group value is passed on update
1 parent c393f9a commit a638485

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

spec/features/group_form/move_form_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
but_i_do_not_see_the_move_link
3737
and_i_cannot_visit_the_move_form_page
3838
end
39+
40+
scenario "not choosing a form" do
41+
given_i_am_logged_in_as_an_organisation_admin
42+
and_i_see_the_move_form_page
43+
when_i_do_not_choose_a_group
44+
then_i_see_an_error_message
45+
end
3946
end
4047

4148
def given_i_am_logged_in_as_an_organisation_admin
@@ -75,6 +82,8 @@ def then_i_see_the_move_form_page
7582
expect(page).to have_content(another_group.name)
7683
end
7784

85+
alias_method :and_i_see_the_move_form_page, :then_i_see_the_move_form_page
86+
7887
def when_i_change_the_group
7988
choose(another_group.name)
8089
click_button "Continue"
@@ -92,4 +101,13 @@ def and_the_other_group_has_the_form
92101

93102
expect(page).to have_content(form.name)
94103
end
104+
105+
def when_i_do_not_choose_a_group
106+
click_button "Continue"
107+
end
108+
109+
def then_i_see_an_error_message
110+
expect(page).to have_content("There is a problem")
111+
expect(page).to have_content("Select a group")
112+
end
95113
end

spec/requests/group_forms_controller_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,20 @@
7272
describe "PATCH /update" do
7373
let(:other_group) { create(:group, organisation: organisation_admin_user.organisation) }
7474

75-
it "redirects to the group" do
76-
patch group_form_url(group, id: form.id), params: { forms_group_select: { group: other_group.id } }
75+
context "with valid parameters" do
76+
it "redirects to the group" do
77+
patch group_form_url(group, id: form.id), params: { forms_group_select: { group: other_group.id } }
7778

78-
expect(response).to redirect_to(group_url(group))
79+
expect(response).to redirect_to(group_url(group))
80+
end
81+
end
82+
83+
context "with missing form group parameter" do
84+
it "re-renders the form with an error" do
85+
patch group_form_url(group, id: form.id), params: { forms_group_select: { group: nil } }
86+
87+
expect(response).to have_http_status :see_other
88+
end
7989
end
8090
end
8191
end

0 commit comments

Comments
 (0)