Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete the secondary skip for a branch route if the branching question is deleted #648

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Page < ApplicationRecord

belongs_to :form
has_many :routing_conditions, class_name: "Condition", foreign_key: "routing_page_id", dependent: :destroy
has_many :check_conditions, class_name: "Condition", foreign_key: "check_page_id", dependent: :nullify
has_many :check_conditions, class_name: "Condition", foreign_key: "check_page_id", dependent: :destroy
has_many :goto_conditions, class_name: "Condition", foreign_key: "goto_page_id", dependent: :nullify
acts_as_list scope: :form

Expand Down
53 changes: 53 additions & 0 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,59 @@
expect(page).to be_valid
end

describe "associations" do
let(:form) { create :form }
let(:page) { create :page, form: }

context "when it has a routing condition" do
let!(:condition) { page.routing_conditions.create! }

it "deletes the condition if it is deleted" do
page.destroy!

expect(condition).to be_destroyed
end
end

context "when it has a check condition" do
let(:routing_page) { create :page, form: }
let!(:condition) { page.check_conditions.create! routing_page: }

it "deletes the condition if it is deleted" do
page.destroy!

expect(condition).to be_destroyed
end
end

context "when it has a go to condition" do
let(:routing_page) { create :page, form: }
let!(:condition) { page.goto_conditions.create! routing_page: }

it "removes association from the condition if it is deleted" do
page.destroy!

expect(condition).not_to be_destroyed
expect(condition.goto_page).to be_nil
end
end

context "when it has a branch route with skip and secondary skip" do
let(:first_branch) { create :page, form: }
let(:second_branch) { create :page, form: }

let!(:skip_condition) { page.routing_conditions.create! goto_page: second_branch }
let!(:secondary_skip_condition) { page.check_conditions.create! routing_page: first_branch, skip_to_end: true }

it "deletes all the conditions if it is deleted" do
page.destroy!

expect(skip_condition).to be_destroyed
expect(secondary_skip_condition).to be_destroyed
end
end
end

describe "versioning", :versioning do
it "enables paper trail" do
expect(page).to be_versioned
Expand Down
Loading