-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement revisions to creating support claims flow
This should fix the issue where a support user edits a draft claim and with every edit, the draft claim is updated for everyone. This will only `update` the draft claim when the support user actually clicks `Update claim`. They way this works is by using the `internal_draft` status. A generated revision starts with `internal_draft` as its status and is changed to draft when the support user finishes editing the draft claim. The previous revision is then set to `internal_draft`, to not show more than 1 claim per reference.
- Loading branch information
1 parent
413bb01
commit c9b9315
Showing
10 changed files
with
234 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Claims::Claim::UpdateDraft < Claims::Claim::CreateDraft | ||
include ServicePattern | ||
|
||
def call | ||
ActiveRecord::Base.transaction do | ||
updated_claim.save! | ||
update_previous_revisions_to_internal_draft | ||
end | ||
end | ||
|
||
private | ||
|
||
def update_previous_revisions_to_internal_draft | ||
claim_record = updated_claim.previous_revision | ||
|
||
while claim_record.present? | ||
claim_record.update!(status: :internal_draft) if claim_record.draft? | ||
claim_record = claim_record.previous_revision | ||
end | ||
end | ||
|
||
def updated_claim | ||
@updated_claim ||= begin | ||
claim.status = :draft | ||
claim | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "rails_helper" | ||
|
||
describe Claims::Claim::UpdateDraft do | ||
subject(:draft_service) { described_class.call(claim:) } | ||
|
||
let!(:previous_revision) { create(:claim, :draft) } | ||
let!(:claim) { create(:claim, :internal_draft, previous_revision:) } | ||
|
||
it_behaves_like "a service object" do | ||
let(:params) { { claim: } } | ||
end | ||
|
||
describe "#call" do | ||
it "updates draft claim and sets the previous revisions to internal_draft status" do | ||
expect { draft_service }.to change(claim, :status).from("internal_draft").to("draft") | ||
expect(claim.previous_revision.status).to eq("internal_draft") | ||
end | ||
end | ||
end |
Oops, something went wrong.