diff --git a/app/models/arbitrary_assignment_creation.rb b/app/models/arbitrary_assignment_creation.rb index 4896628f..80064918 100644 --- a/app/models/arbitrary_assignment_creation.rb +++ b/app/models/arbitrary_assignment_creation.rb @@ -73,7 +73,7 @@ def superseding? end def individual_override? - superseding? && (assignment.individually_overridden || !bulk_assignment?) + superseding? && !bulk_assignment? end def bulk_assignment? diff --git a/app/models/bulk_reassignment.rb b/app/models/bulk_reassignment.rb index a9f4277a..c1598a76 100644 --- a/app/models/bulk_reassignment.rb +++ b/app/models/bulk_reassignment.rb @@ -65,6 +65,7 @@ def update_assignments # rubocop:disable Metrics/AbcSize mixpanel_result = NULL, bulk_assignment_id = #{connection.quote(bulk_assignment.id)}, visitor_supersession_id = NULL, + individually_overridden = false, context = 'bulk_assignment', force = #{connection.quote(bulk_assignment.force)} WHERE id #{assignment_id_clause} diff --git a/db/migrate/20260504164518_clear_stale_individually_overridden_flags.rb b/db/migrate/20260504164518_clear_stale_individually_overridden_flags.rb new file mode 100644 index 00000000..5fc7b153 --- /dev/null +++ b/db/migrate/20260504164518_clear_stale_individually_overridden_flags.rb @@ -0,0 +1,14 @@ +class ClearStaleIndividuallyOverriddenFlags < ActiveRecord::Migration[7.2] + def up + execute <<~SQL + UPDATE assignments + SET individually_overridden = false + WHERE individually_overridden = true + AND context IS DISTINCT FROM 'individually_overridden' + SQL + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index 696bc047..97bf5945 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[7.0].define(version: 2019_04_13_210327) do +ActiveRecord::Schema[7.2].define(version: 2026_05_04_164518) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp" diff --git a/spec/models/arbitrary_assignment_creation_spec.rb b/spec/models/arbitrary_assignment_creation_spec.rb index 475c9fd5..2b806519 100644 --- a/spec/models/arbitrary_assignment_creation_spec.rb +++ b/spec/models/arbitrary_assignment_creation_spec.rb @@ -233,15 +233,15 @@ end end - it "remains during a bulk assignment" do + it "is cleared during a bulk assignment" do existing_assignment = FactoryBot.create(:assignment, existing_assignment_params.merge(individually_overridden: true)) bulk_assignment = FactoryBot.create(:bulk_assignment, split: existing_assignment_params[:split]) ArbitraryAssignmentCreation.create!(params.merge(bulk_assignment_id: bulk_assignment.id)) expect(existing_assignment.reload.bulk_assignment).to eq bulk_assignment - expect(existing_assignment).to be_individually_overridden - expect(existing_assignment.context).to eq "individually_overridden" + expect(existing_assignment).not_to be_individually_overridden + expect(existing_assignment.context).to eq "bulk_assignment" end it "makes a previous bulk_assignment nil" do diff --git a/spec/models/bulk_assignment_creation_spec.rb b/spec/models/bulk_assignment_creation_spec.rb index 984537e2..d689b16a 100644 --- a/spec/models/bulk_assignment_creation_spec.rb +++ b/spec/models/bulk_assignment_creation_spec.rb @@ -289,7 +289,7 @@ def subject_with_reason(reason) expect(previous_assignment.individually_overridden).to be false end - it "maintains the individually_overridden dirty flag across bulk assignments" do + it "clears the individually_overridden flag across bulk assignments" do assignment.update(individually_overridden: true, context: "individually_overridden") subject.save @@ -297,7 +297,7 @@ def subject_with_reason(reason) current_assignment = Assignment.find_by(visitor:) previous_assignment = current_assignment.previous_assignments.first - expect(current_assignment.individually_overridden).to be true + expect(current_assignment.individually_overridden).to be false expect(current_assignment.context).to eq "bulk_assignment" expect(previous_assignment.individually_overridden).to be true expect(previous_assignment.context).to eq "individually_overridden" diff --git a/spec/models/bulk_reassignment_spec.rb b/spec/models/bulk_reassignment_spec.rb index 26b35213..8e0ba307 100644 --- a/spec/models/bulk_reassignment_spec.rb +++ b/spec/models/bulk_reassignment_spec.rb @@ -75,8 +75,8 @@ expect(assignment.mixpanel_result).to be_nil end - it "preserves individually_overridden" do - expect(assignment.individually_overridden).to be true + it "clears individually_overridden" do + expect(assignment.individually_overridden).to be false end it "uses bulk_assignment's created_at as updated_at" do