|
3 | 3 | RSpec.describe Question::Selection, type: :model do |
4 | 4 | subject(:question) { build :selection, only_one_option:, selection_options:, is_optional:, question_text: } |
5 | 5 |
|
6 | | - # We use different values for name and value to make it clear which is which in the tests. |
7 | | - # Name would be the text in current locale and value doesn't change between locales. |
8 | | - # For English forms they would be the same, but for Welsh forms they would be different. |
9 | | - let(:selection_options) { [OpenStruct.new({ name: "display option 1", value: "option 1" }), OpenStruct.new({ name: "display option 2", value: "option 2" })] } |
| 6 | + let(:selection_options) { [OpenStruct.new({ name: "option 1" }), OpenStruct.new({ name: "option 2" })] } |
10 | 7 | let(:is_optional) { false } |
11 | 8 | let(:only_one_option) { "false" } |
12 | 9 | let(:question_text) { Faker::Lorem.question } |
|
67 | 64 |
|
68 | 65 | context "when selection has a value" do |
69 | 66 | before do |
70 | | - question.selection = ["option 1"] |
| 67 | + question.selection = %w[something] |
71 | 68 | end |
72 | 69 |
|
73 | 70 | it "shows the answer" do |
74 | | - expect(question.show_answer).to eq("display option 1") |
| 71 | + expect(question.show_answer).to eq("something") |
75 | 72 | end |
76 | 73 |
|
77 | 74 | it "shows the answer in show_answer_in_csv" do |
78 | | - expect(question.show_answer_in_csv).to eq(Hash[question_text, "display option 1"]) |
| 75 | + expect(question.show_answer_in_csv).to eq(Hash[question_text, "something"]) |
79 | 76 | end |
80 | 77 |
|
81 | 78 | it "returns a hash for show_answer_in_json" do |
82 | 79 | expect(question.show_answer_in_json).to eq({ |
83 | | - selections: ["option 1"], |
84 | | - answer_text: "display option 1", |
| 80 | + selections: %w[something], |
| 81 | + answer_text: "something", |
85 | 82 | }) |
86 | 83 | end |
87 | 84 | end |
|
155 | 152 |
|
156 | 153 | context "when selection has a value" do |
157 | 154 | before do |
158 | | - question.selection = ["option 1"] |
| 155 | + question.selection = %w[something] |
159 | 156 | end |
160 | 157 |
|
161 | 158 | it "shows the answer" do |
162 | | - expect(question.show_answer).to eq("display option 1") |
| 159 | + expect(question.show_answer).to eq("something") |
163 | 160 | end |
164 | 161 |
|
165 | 162 | it "shows the answer in show_answer_in_csv" do |
166 | | - expect(question.show_answer_in_csv).to eq(Hash[question_text, "display option 1"]) |
| 163 | + expect(question.show_answer_in_csv).to eq(Hash[question_text, "something"]) |
167 | 164 | end |
168 | 165 |
|
169 | 166 | it "returns a hash for show_answer_in_json" do |
170 | 167 | expect(question.show_answer_in_json).to eq({ |
171 | | - selections: ["option 1"], |
172 | | - answer_text: "display option 1", |
| 168 | + selections: %w[something], |
| 169 | + answer_text: "something", |
173 | 170 | }) |
174 | 171 | end |
175 | 172 | end |
|
213 | 210 |
|
214 | 211 | context "when selection has a value" do |
215 | 212 | before do |
216 | | - question.selection = "option 1" |
| 213 | + question.selection = "something" |
217 | 214 | end |
218 | 215 |
|
219 | 216 | it "shows the answer" do |
220 | | - expect(question.show_answer).to eq("display option 1") |
| 217 | + expect(question.show_answer).to eq("something") |
221 | 218 | end |
222 | 219 |
|
223 | 220 | it "shows the answer in show_answer_in_csv" do |
224 | | - expect(question.show_answer_in_csv).to eq(Hash[question_text, "display option 1"]) |
| 221 | + expect(question.show_answer_in_csv).to eq(Hash[question_text, "something"]) |
225 | 222 | end |
226 | 223 |
|
227 | 224 | it "returns a hash for show_answer_in_json" do |
228 | 225 | expect(question.show_answer_in_json).to eq({ |
229 | | - answer_text: "display option 1", |
| 226 | + answer_text: "something", |
230 | 227 | }) |
231 | 228 | end |
232 | 229 | end |
|
283 | 280 |
|
284 | 281 | context "when selection has a value" do |
285 | 282 | before do |
286 | | - question.selection = "option 1" |
| 283 | + question.selection = "something" |
287 | 284 | end |
288 | 285 |
|
289 | 286 | it "shows the answer" do |
290 | | - expect(question.show_answer).to eq("display option 1") |
| 287 | + expect(question.show_answer).to eq("something") |
291 | 288 | end |
292 | 289 |
|
293 | 290 | it "shows the answer in show_answer_in_csv" do |
294 | | - expect(question.show_answer_in_csv).to eq(Hash[question_text, "display option 1"]) |
| 291 | + expect(question.show_answer_in_csv).to eq(Hash[question_text, "something"]) |
295 | 292 | end |
296 | 293 |
|
297 | 294 | it "returns a hash for show_answer_in_json" do |
298 | 295 | expect(question.show_answer_in_json).to eq({ |
299 | | - answer_text: "display option 1", |
| 296 | + answer_text: "something", |
300 | 297 | }) |
301 | 298 | end |
302 | 299 | end |
|
433 | 430 |
|
434 | 431 | describe "#selection_options_with_none_of_the_above" do |
435 | 432 | let(:only_one_option) { "true" } |
436 | | - let(:none_of_the_above_option) { OpenStruct.new(name: I18n.t("page.none_of_the_above"), value: I18n.t("page.none_of_the_above")) } |
| 433 | + let(:none_of_the_above_option) { OpenStruct.new(name: I18n.t("page.none_of_the_above")) } |
437 | 434 |
|
438 | 435 | context "when the user can select 'None of the above'" do |
439 | 436 | let(:is_optional) { true } |
|
466 | 463 |
|
467 | 464 | describe "#autocomplete_component?" do |
468 | 465 | context "when there are 30 selection options" do |
469 | | - let(:selection_options) { Array.new(30).map { |_index| OpenStruct.new(name: Faker::Lorem.sentence, value: Faker::Lorem.sentence) } } |
| 466 | + let(:selection_options) { Array.new(30).map { |_index| OpenStruct.new(name: Faker::Lorem.sentence) } } |
470 | 467 |
|
471 | 468 | it "returns false" do |
472 | 469 | expect(question.autocomplete_component?).to be false |
473 | 470 | end |
474 | 471 | end |
475 | 472 |
|
476 | 473 | context "when there are more than 30 selection options" do |
477 | | - let(:selection_options) { Array.new(31).map { |_index| OpenStruct.new(name: Faker::Lorem.sentence, value: Faker::Lorem.sentence) } } |
| 474 | + let(:selection_options) { Array.new(31).map { |_index| OpenStruct.new(name: Faker::Lorem.sentence) } } |
478 | 475 |
|
479 | 476 | it "returns true" do |
480 | 477 | expect(question.autocomplete_component?).to be true |
|
0 commit comments