|
9 | 9 | end |
10 | 10 |
|
11 | 11 | describe "#new" do |
12 | | - context "when the json_submission_enabled feature flag is off" do |
13 | | - before do |
14 | | - allow(Settings.features).to receive(:json_submission_enabled).and_return(false) |
15 | | - |
16 | | - get submission_attachments_path(form_id: form.id) |
17 | | - end |
18 | | - |
19 | | - it "returns a 404 page" do |
20 | | - expect(response).to redirect_to :error_404 |
21 | | - end |
| 12 | + before do |
| 13 | + get submission_attachments_path(form_id: form.id) |
22 | 14 | end |
23 | 15 |
|
24 | | - context "when the json_submission_enabled feature flag is on" do |
25 | | - before do |
26 | | - allow(Settings.features).to receive(:json_submission_enabled).and_return(true) |
27 | | - |
28 | | - get submission_attachments_path(form_id: form.id) |
29 | | - end |
30 | | - |
31 | | - it "renders the submission attachments view" do |
32 | | - expect(response).to have_rendered :new |
33 | | - end |
| 16 | + it "renders the submission attachments view" do |
| 17 | + expect(response).to have_rendered :new |
| 18 | + end |
34 | 19 |
|
35 | | - it "uses the form submission attachments input" do |
36 | | - expect(assigns).to include submission_attachments_input: an_instance_of(Forms::SubmissionAttachmentsInput) |
37 | | - end |
| 20 | + it "uses the form submission attachments input" do |
| 21 | + expect(assigns).to include submission_attachments_input: an_instance_of(Forms::SubmissionAttachmentsInput) |
| 22 | + end |
38 | 23 |
|
39 | | - context "when the submission_type is s3" do |
40 | | - let(:form) { create(:form, submission_type: "s3") } |
| 24 | + context "when the submission_type is s3" do |
| 25 | + let(:form) { create(:form, submission_type: "s3") } |
41 | 26 |
|
42 | | - it "returns a 404 page" do |
43 | | - expect(response).to redirect_to :error_404 |
44 | | - end |
| 27 | + it "returns a 404 page" do |
| 28 | + expect(response).to redirect_to :error_404 |
45 | 29 | end |
46 | 30 | end |
47 | 31 | end |
48 | 32 |
|
49 | 33 | describe "#create" do |
50 | 34 | let(:params) { { forms_submission_attachments_input: { submission_format: } } } |
51 | 35 |
|
52 | | - context "when the json_submission_enabled feature flag is off" do |
53 | | - before do |
54 | | - allow(Settings.features).to receive(:json_submission_enabled).and_return(false) |
55 | | - end |
| 36 | + context "when params are valid" do |
| 37 | + let(:submission_format) { %w[csv json] } |
56 | 38 |
|
57 | | - it "returns a 404 page" do |
58 | | - post submission_attachments_path(form_id: form.id) |
59 | | - expect(response).to redirect_to :error_404 |
| 39 | + it "updates the form submission format" do |
| 40 | + expect { |
| 41 | + post(submission_attachments_path(form_id: form.id), params:) |
| 42 | + }.to change { form.reload.submission_format }.to(submission_format) |
60 | 43 | end |
61 | | - end |
62 | 44 |
|
63 | | - context "when the json_submission_enabled feature flag is on" do |
64 | | - before do |
65 | | - allow(Settings.features).to receive(:json_submission_enabled).and_return(true) |
| 45 | + it "redirects you to the form overview page" do |
| 46 | + post(submission_attachments_path(form_id: form.id), params:) |
| 47 | + expect(response).to redirect_to(form_path(form.id)) |
66 | 48 | end |
67 | 49 |
|
68 | | - context "when params are valid" do |
69 | | - let(:submission_format) { %w[csv json] } |
70 | | - |
71 | | - it "updates the form submission format" do |
72 | | - expect { |
73 | | - post(submission_attachments_path(form_id: form.id), params:) |
74 | | - }.to change { form.reload.submission_format }.to(submission_format) |
75 | | - end |
| 50 | + context "when submission format has changed to 'csv'" do |
| 51 | + let(:submission_format) { %w[csv] } |
76 | 52 |
|
77 | | - it "redirects you to the form overview page" do |
| 53 | + it "displays a success flash message" do |
78 | 54 | post(submission_attachments_path(form_id: form.id), params:) |
79 | | - expect(response).to redirect_to(form_path(form.id)) |
| 55 | + expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_csv_enabled")) |
80 | 56 | end |
| 57 | + end |
81 | 58 |
|
82 | | - context "when submission format has changed to 'csv'" do |
83 | | - let(:submission_format) { %w[csv] } |
| 59 | + context "when submission format has changed to 'json'" do |
| 60 | + let(:submission_format) { %w[json] } |
84 | 61 |
|
85 | | - it "displays a success flash message" do |
86 | | - post(submission_attachments_path(form_id: form.id), params:) |
87 | | - expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_csv_enabled")) |
88 | | - end |
| 62 | + it "displays a success flash message" do |
| 63 | + post(submission_attachments_path(form_id: form.id), params:) |
| 64 | + expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_json_enabled")) |
89 | 65 | end |
| 66 | + end |
90 | 67 |
|
91 | | - context "when submission format has changed to 'json'" do |
92 | | - let(:submission_format) { %w[json] } |
| 68 | + context "when submission format has changed to 'csv json'" do |
| 69 | + let(:submission_format) { %w[csv json] } |
93 | 70 |
|
94 | | - it "displays a success flash message" do |
95 | | - post(submission_attachments_path(form_id: form.id), params:) |
96 | | - expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_json_enabled")) |
97 | | - end |
| 71 | + it "displays a success flash message" do |
| 72 | + post(submission_attachments_path(form_id: form.id), params:) |
| 73 | + expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_csv_and_json_enabled")) |
98 | 74 | end |
| 75 | + end |
99 | 76 |
|
100 | | - context "when submission format has changed to 'csv json'" do |
101 | | - let(:submission_format) { %w[csv json] } |
| 77 | + context "when submission format has changed to blank" do |
| 78 | + let(:original_submission_format) { %w[csv json] } |
| 79 | + let(:submission_format) { %w[] } |
102 | 80 |
|
103 | | - it "displays a success flash message" do |
104 | | - post(submission_attachments_path(form_id: form.id), params:) |
105 | | - expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_csv_and_json_enabled")) |
106 | | - end |
| 81 | + it "displays a success flash message" do |
| 82 | + post(submission_attachments_path(form_id: form.id), params:) |
| 83 | + expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_no_attachments")) |
107 | 84 | end |
| 85 | + end |
108 | 86 |
|
109 | | - context "when submission format has changed to blank" do |
110 | | - let(:original_submission_format) { %w[csv json] } |
111 | | - let(:submission_format) { %w[] } |
| 87 | + context "when submission format has not changed" do |
| 88 | + let(:submission_format) { %w[] } |
112 | 89 |
|
113 | | - it "displays a success flash message" do |
114 | | - post(submission_attachments_path(form_id: form.id), params:) |
115 | | - expect(flash[:success]).to eq(I18n.t("banner.success.form.receive_no_attachments")) |
116 | | - end |
| 90 | + it "does not display a flash message" do |
| 91 | + post(submission_attachments_path(form_id: form.id), params:) |
| 92 | + expect(flash[:success]).to be_nil |
117 | 93 | end |
| 94 | + end |
| 95 | + end |
118 | 96 |
|
119 | | - context "when submission format has not changed" do |
120 | | - let(:submission_format) { %w[] } |
| 97 | + context "when params are invalid" do |
| 98 | + let(:submission_format) { %w[apple] } |
121 | 99 |
|
122 | | - it "does not display a flash message" do |
123 | | - post(submission_attachments_path(form_id: form.id), params:) |
124 | | - expect(flash[:success]).to be_nil |
125 | | - end |
126 | | - end |
| 100 | + it "returns 422" do |
| 101 | + post(submission_attachments_path(form_id: form.id), params:) |
| 102 | + expect(response).to have_http_status(:unprocessable_content) |
127 | 103 | end |
128 | 104 |
|
129 | | - context "when params are invalid" do |
130 | | - let(:submission_format) { %w[apple] } |
131 | | - |
132 | | - it "returns 422" do |
| 105 | + it "does not update the form" do |
| 106 | + expect { |
133 | 107 | post(submission_attachments_path(form_id: form.id), params:) |
134 | | - expect(response).to have_http_status(:unprocessable_content) |
135 | | - end |
136 | | - |
137 | | - it "does not update the form" do |
138 | | - expect { |
139 | | - post(submission_attachments_path(form_id: form.id), params:) |
140 | | - }.not_to(change { form.reload.submission_format }) |
141 | | - end |
| 108 | + }.not_to(change { form.reload.submission_format }) |
| 109 | + end |
142 | 110 |
|
143 | | - it "re-renders the page with an error" do |
144 | | - post(submission_attachments_path(form_id: form.id), params:) |
145 | | - expect(response).to render_template("new") |
146 | | - expect(response.body).to include(I18n.t("activemodel.errors.models.forms/submission_attachments_input.invalid_submission_format")) |
147 | | - end |
| 111 | + it "re-renders the page with an error" do |
| 112 | + post(submission_attachments_path(form_id: form.id), params:) |
| 113 | + expect(response).to render_template("new") |
| 114 | + expect(response.body).to include(I18n.t("activemodel.errors.models.forms/submission_attachments_input.invalid_submission_format")) |
148 | 115 | end |
| 116 | + end |
149 | 117 |
|
150 | | - context "when the submission_type is s3" do |
151 | | - let(:form) { create(:form, submission_type: "s3") } |
152 | | - let(:submission_format) { %w[csv] } |
| 118 | + context "when the submission_type is s3" do |
| 119 | + let(:form) { create(:form, submission_type: "s3") } |
| 120 | + let(:submission_format) { %w[csv] } |
153 | 121 |
|
154 | | - it "returns a 404 page" do |
155 | | - post(submission_attachments_path(form_id: form.id), params:) |
156 | | - expect(response).to redirect_to :error_404 |
157 | | - end |
| 122 | + it "returns a 404 page" do |
| 123 | + post(submission_attachments_path(form_id: form.id), params:) |
| 124 | + expect(response).to redirect_to :error_404 |
158 | 125 | end |
159 | 126 | end |
160 | 127 | end |
|
0 commit comments