Skip to content

Commit c388aa6

Browse files
author
John Pinto
committed
Added RSpec tests for Conditional Questions.
Changes: - added and updated tests for Conditional Questions. - Fixed a few broken RSpec tests by replacing click_link 'Write plan' --> click_link 'Write Plan'. - Updated CHANGELOG.md.
1 parent 8106636 commit c388aa6

12 files changed

+1244
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
- Fix for bug in Conditional questions functionality. In the case of a conditional question with answers that removed questions, any answers of removed questions was not removed. Nor were the removed answers deleted in the database. The Rspec tests were also updated to reflect this change.
4+
5+
36
## v5.0.0
47

58
- Updated app to Rails 7 [#3426](https://github.com/DMPRoadmap/roadmap/pull/3426), [#3496](https://github.com/DMPRoadmap/roadmap/pull/3496)

spec/controllers/answers_controller_with_conditional_questions_spec.rb

Lines changed: 540 additions & 0 deletions
Large diffs are not rendered by default.

spec/factories/answers.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@
3434
plan
3535
user
3636
question
37+
trait :question_options do
38+
question_options { [create(:question_option)] }
39+
end
40+
trait :lock_version do
41+
lock_version { 0 }
42+
end
3743
end
3844
end

spec/factories/conditions.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,22 @@
2626

2727
FactoryBot.define do
2828
factory :condition do
29-
option_list { nil }
30-
remove_data { nil }
29+
option_list { [] }
30+
remove_data { [] }
31+
action_type { nil }
32+
# the webhook_data is a Json string of form:
33+
# '{"name":"Joe Bloggs","email":"[email protected]","subject":"Large data volume","message":"A message."}'
34+
trait :webhook do
35+
action_type { 'add_webhook' }
36+
webhook_data do
37+
# Generates string from hash
38+
JSON.generate({
39+
name: Faker::Name.name,
40+
email: Faker::Internet.email,
41+
subject: Faker::Lorem.sentence(word_count: 4),
42+
message: Faker::Lorem.paragraph(sentence_count: 2)
43+
})
44+
end
45+
end
3146
end
3247
end

spec/features/questions/checkbox_questions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
visit overview_plan_path(@plan)
2222

2323
# Action
24-
click_link 'Write plan'
24+
click_link 'Write Plan'
2525

2626
# Expectations
2727
expect(current_path).to eql(edit_plan_path(@plan))

spec/features/questions/conditions_questions_spec.rb

Lines changed: 534 additions & 0 deletions
Large diffs are not rendered by default.

spec/features/questions/dropdown_questions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
visit overview_plan_path(@plan)
2222

2323
# Action
24-
click_link 'Write plan'
24+
click_link 'Write Plan'
2525

2626
# Expectations
2727
expect(current_path).to eql(edit_plan_path(@plan))

spec/features/questions/radiobuttons_questions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
visit overview_plan_path(@plan)
2222

2323
# Action
24-
click_link 'Write plan'
24+
click_link 'Write Plan'
2525

2626
# Expectations
2727
expect(current_path).to eql(edit_plan_path(@plan))

spec/features/questions/textarea_questions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
visit overview_plan_path(@plan)
2222

2323
# Action
24-
click_link 'Write plan'
24+
click_link 'Write Plan'
2525

2626
# Expectations
2727
expect(current_path).to eql(edit_plan_path(@plan))

spec/features/questions/textfield_questions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
visit overview_plan_path(@plan)
2222

2323
# Action
24-
click_link 'Write plan'
24+
click_link 'Write Plan'
2525

2626
# Expectations
2727
expect(current_path).to eql(edit_plan_path(@plan))

0 commit comments

Comments
 (0)