mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: Don't use exceptions to catch conflicts
If a database exception is raised ActiveRecord will always rollback even if caught. Instead we build the query in manual SQL and DO NOTHING when there's a conflict. If we detect nothing was done, perform an update.
This commit is contained in:
@ -7,7 +7,7 @@ describe HasCustomFields do
|
||||
context "custom_fields" do
|
||||
before do
|
||||
DB.exec("create temporary table custom_fields_test_items(id SERIAL primary key)")
|
||||
DB.exec("create temporary table custom_fields_test_item_custom_fields(id SERIAL primary key, custom_fields_test_item_id int, name varchar(256) not null, value text)")
|
||||
DB.exec("create temporary table custom_fields_test_item_custom_fields(id SERIAL primary key, custom_fields_test_item_id int, name varchar(256) not null, value text, created_at TIMESTAMP, updated_at TIMESTAMP)")
|
||||
DB.exec(<<~SQL)
|
||||
CREATE UNIQUE INDEX ON custom_fields_test_item_custom_fields (custom_fields_test_item_id)
|
||||
WHERE NAME = 'rare'
|
||||
@ -282,6 +282,7 @@ describe HasCustomFields do
|
||||
item0 = CustomFieldsTestItem.new
|
||||
item0.custom_fields = { "rare" => "gem" }
|
||||
item0.save
|
||||
expect(item0.reload.custom_fields['rare']).to eq("gem")
|
||||
|
||||
item0.create_singular('rare', "diamond")
|
||||
expect(item0.reload.custom_fields['rare']).to eq("diamond")
|
||||
|
Reference in New Issue
Block a user