-
Notifications
You must be signed in to change notification settings - Fork 671
AO3-5748 Split off assignments with both offer and pinch hitter #5555
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -496,4 +496,24 @@ def self.update_placeholder_assignments!(collection) | |
| end | ||
| end | ||
| end | ||
|
|
||
| # create fresh new assignments for pinch hitters assigned alongside existing offer signups | ||
| def self.split_off_write_in_giver_assignments!(collection) | ||
| collection.assignments.each do |assignment| | ||
| assignment.split if assignment.double_assigned? | ||
| end | ||
| end | ||
|
|
||
| def double_assigned? | ||
| pinch_hitter && offer_signup && pinch_hitter.user != offering_user | ||
| end | ||
|
|
||
| def split | ||
|
Comment on lines
+507
to
+511
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add tests for these methods as well? (I'm also wondering if it's worth making them |
||
| new_assignment = self.dup | ||
| new_assignment.offer_signup = nil | ||
| new_assignment.save! | ||
|
|
||
| self.pinch_hitter = nil | ||
| save! | ||
|
Comment on lines
+514
to
+517
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about these 2 saves, I'm leaning towards wrapping it in an explicit transaction. That way, we don't "lose" signup information if there's a problem with one of these writes. But it means we could still hit the case mentioned in the bug iff there's some database issue between the start and end of the assignments change. What do you think? |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,36 @@ | |
| end | ||
| end | ||
|
|
||
| context "when an assignment has both an offer and a pinch hitter" do | ||
| let(:params) do | ||
| { | ||
| collection_id: collection.name, | ||
| challenge_assignments: { | ||
| assignment.id => { | ||
| request_signup_pseud: signup1.pseud.byline, | ||
| offer_signup_pseud: signup2.pseud.byline, | ||
| pinch_hitter_byline: other_user.pseuds.first.byline | ||
| } | ||
| } | ||
| } | ||
| end | ||
|
|
||
| it "creates a new assignment for the pinch hitter" do | ||
| PotentialMatch.create(request_signup: signup1, | ||
| offer_signup: signup2, | ||
| collection: collection) | ||
|
|
||
| put :set, params: params | ||
|
|
||
| assignment.reload | ||
| expect(assignment.pinch_hitter).to be_nil | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add an assertion to make sure the offer signup is not cleared here? (Probably paranoid of me, but just in case 😅 ) |
||
|
|
||
| pinch_hitter_assignment = collection.assignments.find_by(pinch_hitter_id: other_user.pseuds.first.id) | ||
| expect(pinch_hitter_assignment).to be_present | ||
| expect(pinch_hitter_assignment.offer_signup).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context "when assignments have been sent" do | ||
| let(:gift_exchange) { create(:gift_exchange, assignments_sent_at: Faker::Time.backward) } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this should go inside
update_placeholder_assignments!, since at the moment it seems like we'll always want to do them both at the same time?