From 2703cad7dfa49965711a6683234eb37cc3e20da0 Mon Sep 17 00:00:00 2001
From: Lorna
N/A
" ) + section = Section.create(title: "Preview Section", journey: @journey) + task = Task.create(title: "Preview Task", section: section) contentful_entry = GetEntry.new(entry_id: entry_id).call @step = CreateJourneyStep.new( - journey: @journey, contentful_entry: contentful_entry + task: task, contentful_entry: contentful_entry ).call redirect_to journey_step_path(@journey, @step) diff --git a/app/controllers/specifications_controller.rb b/app/controllers/specifications_controller.rb index 3464f9d08..99b066a16 100644 --- a/app/controllers/specifications_controller.rb +++ b/app/controllers/specifications_controller.rb @@ -5,15 +5,7 @@ class SpecificationsController < ApplicationController def show @journey = current_journey - @visible_steps = @journey.visible_steps.includes([ - :radio_answer, - :short_text_answer, - :long_text_answer, - :single_date_answer, - :checkbox_answers, - :number_answer, - :currency_answer - ]) + @visible_steps = @journey.visible_steps @step_presenters = @visible_steps.map { |step| StepPresenter.new(step) } specification_renderer = SpecificationRenderer.new( diff --git a/app/models/journey.rb b/app/models/journey.rb index 1dea375b1..8f17cb42e 100644 --- a/app/models/journey.rb +++ b/app/models/journey.rb @@ -1,12 +1,16 @@ class Journey < ApplicationRecord self.implicit_order_column = "created_at" - has_many :steps - has_many :sections - has_many :visible_steps, -> { where(steps: {hidden: false}) }, class_name: "Step" + has_many :sections, dependent: :destroy + has_many :tasks, through: :sections, class_name: "Task" + has_many :steps, through: :tasks, class_name: "Step" belongs_to :user validates :category, :liquid_template, presence: true + def visible_steps + steps.where(hidden: false) + end + def all_steps_completed? visible_steps.all? { |step| step.answer.present? } end diff --git a/app/models/section.rb b/app/models/section.rb index a4f71545d..0ab4a8d53 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -1,7 +1,8 @@ class Section < ApplicationRecord self.implicit_order_column = "created_at" belongs_to :journey - has_many :tasks + has_many :tasks, dependent: :destroy + has_many :steps, through: :tasks, class_name: "Step" validates :title, :contentful_id, presence: true end diff --git a/app/models/step.rb b/app/models/step.rb index 2ee714bcc..d27f8e0d1 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -1,6 +1,6 @@ class Step < ApplicationRecord self.implicit_order_column = "created_at" - belongs_to :journey + belongs_to :task has_one :radio_answer has_one :short_text_answer @@ -33,4 +33,8 @@ def primary_call_to_action_text def skippable? skip_call_to_action_text.present? end + + def journey + task.section.journey + end end diff --git a/app/models/task.rb b/app/models/task.rb index 4708e9ac3..143f1cf48 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -1,6 +1,7 @@ class Task < ApplicationRecord self.implicit_order_column = "created_at" belongs_to :section + has_many :steps, dependent: :destroy validates :title, :contentful_id, presence: true end diff --git a/app/services/create_journey.rb b/app/services/create_journey.rb index 1bd3702fb..147b47d61 100644 --- a/app/services/create_journey.rb +++ b/app/services/create_journey.rb @@ -21,28 +21,36 @@ def call journey.save! contentful_sections.each do |contentful_section| - CreateSection.new(journey: journey, contentful_section: contentful_section).call + section = CreateSection.new(journey: journey, contentful_section: contentful_section).call - question_entries = GetStepsFromSection.new(section: contentful_section).call - question_entries.each do |entry| - CreateJourneyStep.new( - journey: journey, contentful_entry: entry - ).call - end + # The entire `if` block here exists to support our fixtures which do not nest steps + # within tasks. Once we update our fixtures to the "new way" of doing things, this + # entire `if` block can be discarded. + if contentful_section.respond_to?(:tasks) && !contentful_section.tasks.any? + question_entries = GetStepsFromSection.new(section: contentful_section).call + question_entries.each do |entry| + fake_contentful_task = OpenStruct.new(title: entry.title, id: entry.id) + task = CreateTask.new(section: section, contentful_task: fake_contentful_task).call - tasks = GetTasksFromSection.new(section: contentful_section).call - tasks.each do |task| - CreateTask.new(section: contentful_section, contentful_task: task) - end - end + CreateJourneyStep.new( + task: task, contentful_entry: entry + ).call + end + else + contentful_tasks = GetTasksFromSection.new(section: contentful_section).call + contentful_tasks.each do |contentful_task| + task = CreateTask.new(section: section, contentful_task: contentful_task).call - contentful_sections.each do |section| - tasks = GetTasksFromSection.new(section: section).call - tasks.each do |task| - CreateTask.new(section: section, contentful_task: task) + question_entries = GetStepsFromTask(task: contentful_task).call + question_entries.each do |entry| + CreateJourneyStep.new( + contentful_entry: entry, task: task + ).call + end + end end end - + journey end diff --git a/app/services/create_journey_step.rb b/app/services/create_journey_step.rb index b2354254d..e59308180 100644 --- a/app/services/create_journey_step.rb +++ b/app/services/create_journey_step.rb @@ -15,9 +15,9 @@ class UnexpectedContentfulStepType < StandardError; end currency ].freeze - attr_accessor :journey, :contentful_entry - def initialize(journey:, contentful_entry:) - self.journey = journey + attr_accessor :task, :contentful_entry + def initialize(task:, contentful_entry:) + self.task = task self.contentful_entry = contentful_entry end @@ -45,7 +45,7 @@ def call hidden: hidden, additional_step_rules: additional_step_rules, raw: raw, - journey: journey + task: task ) end diff --git a/app/services/create_task.rb b/app/services/create_task.rb index 5f7d543ed..44e89a74d 100644 --- a/app/services/create_task.rb +++ b/app/services/create_task.rb @@ -1,4 +1,6 @@ class CreateTask + class UnexpectedContentfulModel < StandardError; end + attr_accessor :section, :contentful_task def initialize(section:, contentful_task:) @@ -8,7 +10,11 @@ def initialize(section:, contentful_task:) def call task = Task.new(section: section, title: contentful_task.title, contentful_id: contentful_task.id) - task.save! - task + begin + task.save! + task + rescue ActiveRecord::RecordInvalid + raise UnexpectedContentfulModel + end end end diff --git a/db/migrate/20210419082411_add_task_association_to_steps.rb b/db/migrate/20210419082411_add_task_association_to_steps.rb new file mode 100644 index 000000000..4b3104675 --- /dev/null +++ b/db/migrate/20210419082411_add_task_association_to_steps.rb @@ -0,0 +1,7 @@ +class AddTaskAssociationToSteps < ActiveRecord::Migration[6.1] + def change + add_column :steps, :task_id, :uuid + add_index :steps, :task_id + remove_column :steps, :journey_id, :uuid + end +end diff --git a/db/schema.rb b/db/schema.rb index 95f44eb2b..42d48e356 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_04_07_111600) do +ActiveRecord::Schema.define(version: 2021_04_19_082411) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -42,11 +42,11 @@ t.jsonb "liquid_template", null: false t.jsonb "section_groups" t.uuid "user_id" - t.index ["user_id"], name: "index_journeys_on_user_id" t.boolean "started", default: true - t.index ["started"], name: "index_journeys_on_started" t.datetime "last_worked_on" t.index ["last_worked_on"], name: "index_journeys_on_last_worked_on" + t.index ["started"], name: "index_journeys_on_started" + t.index ["user_id"], name: "index_journeys_on_user_id" end create_table "long_text_answers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -100,7 +100,6 @@ end create_table "steps", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "journey_id" t.string "title", null: false t.string "help_text" t.string "contentful_type", null: false @@ -115,7 +114,8 @@ t.boolean "hidden", default: false t.jsonb "additional_step_rules" t.string "skip_call_to_action_text" - t.index ["journey_id"], name: "index_steps_on_journey_id" + t.uuid "task_id" + t.index ["task_id"], name: "index_steps_on_task_id" end create_table "tasks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -136,5 +136,4 @@ add_foreign_key "long_text_answers", "steps", on_delete: :cascade add_foreign_key "radio_answers", "steps", on_delete: :cascade add_foreign_key "short_text_answers", "steps", on_delete: :cascade - add_foreign_key "steps", "journeys", on_delete: :cascade end diff --git a/spec/factories/step.rb b/spec/factories/step.rb index c2d75527f..c184f47a2 100644 --- a/spec/factories/step.rb +++ b/spec/factories/step.rb @@ -9,7 +9,7 @@ primary_call_to_action_text { nil } skip_call_to_action_text { nil } - association :journey, factory: :journey + association :task, factory: :task trait :radio do options { [{"value" => "Red"}, {"value" => "Green"}, {"value" => "Blue"}] } diff --git a/spec/factories/task.rb b/spec/factories/task.rb new file mode 100644 index 000000000..fe11ca70b --- /dev/null +++ b/spec/factories/task.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :task do + title { "Task title" } + contentful_id { "5m26U35YLau4cOaJq6FXZA" } + association :section + end +end diff --git a/spec/features/visitors/anyone_can_sign_in_with_dfe_sign_in_spec.rb b/spec/features/visitors/anyone_can_sign_in_with_dfe_sign_in_spec.rb index 92f7f8f6f..ea904a744 100644 --- a/spec/features/visitors/anyone_can_sign_in_with_dfe_sign_in_spec.rb +++ b/spec/features/visitors/anyone_can_sign_in_with_dfe_sign_in_spec.rb @@ -27,8 +27,9 @@ # Undo the OmniAuth stub to check we don't require it again OmniAuth.config.mock_auth[:dfe] = OmniAuth::AuthHash.new(foo: :bar) - journey = create(:journey, user: user) - step = create(:step, :radio, journey: journey) + step = create(:step, :radio) + journey = step.journey + journey.update(user: user) visit journey_step_path(journey, step) expect(page).to have_content(step.title) end diff --git a/spec/helpers/journey_helper_spec.rb b/spec/helpers/journey_helper_spec.rb index 1d4d7df67..27ab24c60 100644 --- a/spec/helpers/journey_helper_spec.rb +++ b/spec/helpers/journey_helper_spec.rb @@ -3,10 +3,12 @@ RSpec.describe JourneyHelper, type: :helper do describe "#section_group_with_steps" do it "returns an ordered array of steps" do - journey = create(:journey, section_groups: "", steps: []) - step_1 = StepPresenter.new(create(:step, :radio, journey: journey)) - step_2 = StepPresenter.new(create(:step, :long_text, journey: journey)) - step_3 = StepPresenter.new(create(:step, :short_text, journey: journey)) + journey = create(:journey, section_groups: "") + section = create(:section, journey: journey) + task = create(:task, section: section) + step_1 = StepPresenter.new(create(:step, :radio, task: task)) + step_2 = StepPresenter.new(create(:step, :long_text, task: task)) + step_3 = StepPresenter.new(create(:step, :short_text, task: task)) section_groups = [ { @@ -47,11 +49,13 @@ context "when the ordering we want does not match the order saved in the database" do it "the ordering defined by 'order' is preserved" do - journey = create(:journey, section_groups: "", steps: []) - step_1 = StepPresenter.new(create(:step, :radio, title: "First question", journey: journey)) - step_2 = StepPresenter.new(create(:step, :long_text, title: "Second question", journey: journey)) - step_3 = StepPresenter.new(create(:step, :short_text, title: "Third question", journey: journey)) - step_4 = StepPresenter.new(create(:step, :short_text, title: "Fourth question", journey: journey)) + journey = create(:journey, section_groups: "") + section = create(:section, journey: journey) + task = create(:task, section: section) + step_1 = StepPresenter.new(create(:step, :radio, title: "First question", task: task)) + step_2 = StepPresenter.new(create(:step, :long_text, title: "Second question", task: task)) + step_3 = StepPresenter.new(create(:step, :short_text, title: "Third question", task: task)) + step_4 = StepPresenter.new(create(:step, :short_text, title: "Fourth question", task: task)) section_groups = [ { diff --git a/spec/models/journey_spec.rb b/spec/models/journey_spec.rb index b4c1d1220..6ccd8a593 100644 --- a/spec/models/journey_spec.rb +++ b/spec/models/journey_spec.rb @@ -1,7 +1,6 @@ require "rails_helper" RSpec.describe Journey, type: :model do - it { should have_many(:steps) } it { should have_many(:sections) } describe "validations" do @@ -18,11 +17,13 @@ context "when all steps have been completed" do it "returns true" do journey = create(:journey) + section = create(:section, journey: journey) + task = create(:task, section: section) - step_1 = create(:step, :radio, journey: journey) + step_1 = create(:step, :radio, task: task) create(:radio_answer, step: step_1) - step_2 = create(:step, :radio, journey: journey) + step_2 = create(:step, :radio, task: task) create(:radio_answer, step: step_2) expect(journey.all_steps_completed?).to be true @@ -32,8 +33,10 @@ context "when no steps have been completed" do it "returns false " do journey = create(:journey) + section = create(:section, journey: journey) + task = create(:task, section: section) - create_list(:step, 2, :radio, journey: journey) + create_list(:step, 2, :radio, task: task) expect(journey.all_steps_completed?).to be false end @@ -42,11 +45,13 @@ context "when only some steps have been completed" do it "returns false" do journey = create(:journey) + section = create(:section, journey: journey) + task = create(:task, section: section) - step_1 = create(:step, :radio, journey: journey) + step_1 = create(:step, :radio, task: task) create(:radio_answer, step: step_1) - create(:step, :radio, journey: journey) + create(:step, :radio, task: task) expect(journey.all_steps_completed?).to be false end @@ -55,11 +60,13 @@ context "when there are uncompleted hidden steps" do it "ignores them and returns true" do journey = create(:journey) + section = create(:section, journey: journey) + task = create(:task, section: section) - step_1 = create(:step, :radio, journey: journey) + step_1 = create(:step, :radio, task: task) create(:radio_answer, step: step_1) - _hidden_step_without_an_answer = create(:step, :radio, journey: journey, hidden: true) + _hidden_step_without_an_answer = create(:step, :radio, task: task, hidden: true) expect(journey.all_steps_completed?).to be true end diff --git a/spec/models/step_spec.rb b/spec/models/step_spec.rb index 22206faa5..ef173661e 100644 --- a/spec/models/step_spec.rb +++ b/spec/models/step_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Step, type: :model do - it { should belong_to(:journey) } + it { should belong_to(:task) } it { should have_one(:radio_answer) } it { should have_one(:short_text_answer) } it { should have_one(:long_text_answer) } diff --git a/spec/models/task_spec.rb b/spec/models/task_spec.rb index 984d007a1..bc194dc38 100644 --- a/spec/models/task_spec.rb +++ b/spec/models/task_spec.rb @@ -2,6 +2,7 @@ RSpec.describe Task, type: :model do it { should belong_to(:section) } + it { should have_many(:steps) } describe "validations" do it { is_expected.to validate_presence_of(:title) } diff --git a/spec/services/create_journey_step_spec.rb b/spec/services/create_journey_step_spec.rb index 7f8e772c7..faafd99df 100644 --- a/spec/services/create_journey_step_spec.rb +++ b/spec/services/create_journey_step_spec.rb @@ -5,11 +5,14 @@ context "when the new step is of type step" do it "creates a local copy of the new step" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/radio-question.json" ) - step = described_class.new(journey: journey, contentful_entry: fake_entry).call + step = described_class.new(task: task, contentful_entry: fake_entry).call expect(step.title).to eq("Which service do you need?") expect(step.help_text).to eq("Tell us which service you need.") @@ -64,22 +67,28 @@ context "when the question is of type 'short_text'" do it "sets help_text and options to nil" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/short-text-question.json" ) - step = described_class.new(journey: journey, contentful_entry: fake_entry).call + step = described_class.new(task: task, contentful_entry: fake_entry).call expect(step.options).to eq(nil) end it "replaces spaces with underscores" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/short-text-question.json" ) - step = described_class.new(journey: journey, contentful_entry: fake_entry).call + step = described_class.new(task: task, contentful_entry: fake_entry).call expect(step.contentful_type).to eq("short_text") end @@ -88,12 +97,15 @@ context "when the new entry has a body field" do it "updates the step with the body" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/static-content.json" ) step, _answer = described_class.new( - journey: journey, contentful_entry: fake_entry + task: task, contentful_entry: fake_entry ).call expect(step.body).to eq("Procuring a new catering contract can \ @@ -106,12 +118,15 @@ context "when the new entry has a 'primaryCallToAction' field" do it "updates the step with the body" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/primary-button.json" ) step, _answer = described_class.new( - journey: journey, contentful_entry: fake_entry + task: task, contentful_entry: fake_entry ).call expect(step.primary_call_to_action_text).to eq("Go onwards!") @@ -121,12 +136,15 @@ context "when no 'primaryCallToAction' is provided" do it "default copy is used for the button" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/no-primary-button.json" ) step, _answer = described_class.new( - journey: journey, contentful_entry: fake_entry + task: task, contentful_entry: fake_entry ).call expect(step.primary_call_to_action_text).to eq(I18n.t("generic.button.next")) @@ -136,12 +154,15 @@ context "when no 'skipCallToAction' is provided" do it "default copy is used for the button" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/skippable-checkboxes-question.json" ) step, _answer = described_class.new( - journey: journey, contentful_entry: fake_entry + task: task, contentful_entry: fake_entry ).call expect(step.skip_call_to_action_text).to eq("None of the above") @@ -151,12 +172,15 @@ context "when no 'alwaysShowTheUser' is provided" do it "default hidden to true" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/no-hidden-field.json" ) step, _answer = described_class.new( - journey: journey, contentful_entry: fake_entry + task: task, contentful_entry: fake_entry ).call expect(step.hidden).to eq(false) @@ -166,12 +190,15 @@ context "when 'showAdditionalQuestion' is provided" do it "stores the rule as JSON" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/show-one-additional-question.json" ) step, _answer = described_class.new( - journey: journey, contentful_entry: fake_entry + task: task, contentful_entry: fake_entry ).call expect(step.additional_step_rules).to eql([ @@ -186,16 +213,21 @@ context "when the new entry has an unexpected content model" do it "raises an error" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/unexpected-contentful-type.json" ) - expect { described_class.new(journey: journey, contentful_entry: fake_entry).call } + expect { described_class.new(task: task, contentful_entry: fake_entry).call } .to raise_error(CreateJourneyStep::UnexpectedContentfulModel) end it "raises a rollbar event" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/unexpected-contentful-type.json" @@ -212,7 +244,7 @@ allowed_content_models: CreateJourneyStep::ALLOWED_CONTENTFUL_MODELS.join(", "), allowed_step_types: CreateJourneyStep::ALLOWED_CONTENTFUL_ENTRY_TYPES.join(", ")) .and_call_original - expect { described_class.new(journey: journey, contentful_entry: fake_entry).call } + expect { described_class.new(task: task, contentful_entry: fake_entry).call } .to raise_error(CreateJourneyStep::UnexpectedContentfulModel) end end @@ -220,16 +252,21 @@ context "when the new step has an unexpected step type" do it "raises an error" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) + fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/unexpected-contentful-question-type.json" ) - expect { described_class.new(journey: journey, contentful_entry: fake_entry).call } + expect { described_class.new(task: task, contentful_entry: fake_entry).call } .to raise_error(CreateJourneyStep::UnexpectedContentfulStepType) end it "raises a rollbar event" do journey = create(:journey, :catering) + section = create(:section, journey: journey) + task = create(:task, section: section) fake_entry = fake_contentful_step_or_task( contentful_fixture_filename: "steps/unexpected-contentful-question-type.json" @@ -246,7 +283,7 @@ allowed_content_models: CreateJourneyStep::ALLOWED_CONTENTFUL_MODELS.join(", "), allowed_step_types: CreateJourneyStep::ALLOWED_CONTENTFUL_ENTRY_TYPES.join(", ")) .and_call_original - expect { described_class.new(journey: journey, contentful_entry: fake_entry).call } + expect { described_class.new(task: task, contentful_entry: fake_entry).call } .to raise_error(CreateJourneyStep::UnexpectedContentfulStepType) end end diff --git a/spec/services/delete_stale_journeys_spec.rb b/spec/services/delete_stale_journeys_spec.rb index aafe4cb5f..22bf8699a 100644 --- a/spec/services/delete_stale_journeys_spec.rb +++ b/spec/services/delete_stale_journeys_spec.rb @@ -6,8 +6,9 @@ describe "#call" do it "destroys a journey and all associated records" do - journey = create(:journey, started: false, last_worked_on: (1.month + 1.day).ago) - step = create(:step, :radio, journey: journey) + step = create(:step, :radio) + journey = step.journey + journey.update(started: false, last_worked_on: (1.month + 1.day).ago) _radio_answer = create(:radio_answer, step: step) _short_text_answer = create(:short_text_answer, step: step) diff --git a/spec/services/get_answers_for_steps_spec.rb b/spec/services/get_answers_for_steps_spec.rb index 57a4d2eba..f52403f17 100644 --- a/spec/services/get_answers_for_steps_spec.rb +++ b/spec/services/get_answers_for_steps_spec.rb @@ -195,9 +195,11 @@ context "when there is no answer for a step" do it "does not try to prepare that answer in the result" do journey = create(:journey) - answerable_step = create(:step, :radio, journey: journey) + section = create(:section, journey: journey) + task = create(:task, section: section) + answerable_step = create(:step, :radio, task: task) _answer = create(:radio_answer, step: answerable_step) - unanswerable_step = create(:step, :radio, journey: journey) + unanswerable_step = create(:step, :radio, task: task) result = described_class.new(visible_steps: [answerable_step]).call diff --git a/spec/services/save_answer_spec.rb b/spec/services/save_answer_spec.rb index 793912dbc..a12928a13 100644 --- a/spec/services/save_answer_spec.rb +++ b/spec/services/save_answer_spec.rb @@ -71,8 +71,9 @@ context "when the associated journey is unstarted" do it "updates the journey to be started" do - journey = create(:journey, started: false) - step = create(:step, :radio, journey: journey) + step = create(:step, :radio) + journey = step.journey + journey.update(started: false) answer = create(:short_text_answer, step: step) _result = described_class.new(answer: answer).call(params: {}) diff --git a/spec/services/toggle_additional_steps_spec.rb b/spec/services/toggle_additional_steps_spec.rb index b8af60be1..5da9827b2 100644 --- a/spec/services/toggle_additional_steps_spec.rb +++ b/spec/services/toggle_additional_steps_spec.rb @@ -3,6 +3,8 @@ RSpec.describe ToggleAdditionalSteps do describe "#call" do let(:journey) { create(:journey) } + let(:section) { create(:section, journey: journey) } + let(:task) { create(:task, section: section) } context "when the additional_step_rules field is nil" do it "returns nil" do @@ -16,13 +18,13 @@ it "only shows the additional steps within the same journey" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "Red", "question_identifiers" => ["123"]}]) create(:radio_answer, step: step, response: "Red") another_step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: true) @@ -40,7 +42,7 @@ it "shows all additional_steps within the same journey" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{ "required_answer" => "Red", "question_identifiers" => ["123", "456"] @@ -49,13 +51,13 @@ first_additional_step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: true) second_additional_step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "456", hidden: true) @@ -75,13 +77,13 @@ it "updates the referenced step's hidden field to false" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "Red", "question_identifiers" => ["123"]}]) create(:radio_answer, step: step, response: "Red") step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: true) @@ -95,13 +97,13 @@ it "returns the updated step" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "RED", "question_identifiers" => ["123"]}]) create(:radio_answer, step: step, response: "red") step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: true) @@ -115,14 +117,14 @@ it "shows both connected questions" do first_step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "Red", "question_identifiers" => ["123"]}], hidden: false) create(:radio_answer, step: first_step, response: "Red") second_step = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", additional_step_rules: [{"required_answer" => "Blue", "question_identifiers" => ["456"]}], hidden: true) @@ -130,7 +132,7 @@ third_step = create(:step, :radio, - journey: journey, + task: task, contentful_id: "456", hidden: true) @@ -146,7 +148,7 @@ it "should hide itself and all connected branches" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [ {"required_answer" => "Red", "question_identifiers" => ["123"]}, {"required_answer" => "Blue", "question_identifiers" => ["456"]} @@ -157,7 +159,7 @@ first_step_to_hide = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", additional_step_rules: [ {"required_answer" => "Yellow", "question_identifiers" => ["8"]}, @@ -167,14 +169,14 @@ second_step_to_hide = create(:step, :radio, - journey: journey, + task: task, contentful_id: "8", additional_step_rules: [], hidden: false) third_step_to_hide = create(:step, :radio, - journey: journey, + task: task, contentful_id: "9", additional_step_rules: [], hidden: false) @@ -191,7 +193,7 @@ it "continues to show the next step (rather than hiding it again when it doesn't match the second rule)" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [ {"required_answer" => "red", "question_identifiers" => ["123"]}, {"required_answer" => "blue", "question_identifiers" => ["123"]} @@ -200,7 +202,7 @@ step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: true) @@ -214,13 +216,13 @@ it "updates the referenced step's hidden field to true" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "Red", "question_identifiers" => ["123"]}]) create(:radio_answer, step: step, response: "Blue") step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: false) @@ -232,7 +234,7 @@ it "hides all additional_steps within the same journey" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{ "required_answer" => "Red", "question_identifiers" => ["123", "456"] @@ -241,13 +243,13 @@ first_additional_step_to_hide = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: false) second_additional_step_to_hide = create(:step, :radio, - journey: journey, + task: task, contentful_id: "456", hidden: false) @@ -267,13 +269,13 @@ it "does not hide the step" do step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "RED", "question_identifiers" => ["123"]}]) create(:radio_answer, step: step, response: "red") step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: false) @@ -287,14 +289,14 @@ it "hides both connected questions" do first_step = create(:step, :radio, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "Red", "question_identifiers" => ["123"]}], hidden: false) create(:radio_answer, step: first_step, response: "Changed from red") second_step = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", additional_step_rules: [{"required_answer" => "Blue", "question_identifiers" => ["456"]}], hidden: false) @@ -302,7 +304,7 @@ third_step = create(:step, :radio, - journey: journey, + task: task, contentful_id: "456", hidden: false) @@ -318,13 +320,13 @@ it "checks for a match against all answers" do step = create(:step, :checkbox_answers, - journey: journey, + task: task, additional_step_rules: [{"required_answer" => "Red", "question_identifiers" => ["123"]}]) create(:checkbox_answers, step: step, response: ["Blue", "Red"]) step_to_show = create(:step, :radio, - journey: journey, + task: task, contentful_id: "123", hidden: true) From fd18a20e7d998c4128eaf5123a17a6cc753c2f93 Mon Sep 17 00:00:00 2001 From: Laura PorterDate started | -- |
---|
<%= journey.created_at.strftime("%e %B %Y") %> | -Review and edit | +Date started | +
---|
<%= I18n.t("journey.index.existing.empty") %>
+ +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index bba9160db..8ea1dcf2a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -63,6 +63,7 @@ en: index: existing: header: "Existing specifications" + empty: "You currently have no existing specifications, return to create a new specification" specification: header: "Your specification" warning: "You have not completed all the tasks. There may be information missing from your specification." diff --git a/spec/features/school_buying_professionals/view_a_dashboard_spec.rb b/spec/features/school_buying_professionals/view_a_dashboard_spec.rb index a55be68e5..d3f8f50f4 100644 --- a/spec/features/school_buying_professionals/view_a_dashboard_spec.rb +++ b/spec/features/school_buying_professionals/view_a_dashboard_spec.rb @@ -33,6 +33,16 @@ expect(page).to have_content("15 February 2021") end + scenario "when a user has no specifications a message is shown" do + user = create(:user) + user_is_signed_in(user: user) + + visit journeys_path + + expect(page).to have_content(I18n.t("journey.index.existing.empty")) + expect(page).to have_content(I18n.t("dashboard.create.link")) + end + scenario "user can start a new specification" do stub_contentful_category(fixture_filename: "radio-question.json") From 31375f878749433b6159c04c18e780008af74c98 Mon Sep 17 00:00:00 2001 From: Lorna