summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/page.rb16
-rw-r--r--test/models/page_test.rb8
2 files changed, 6 insertions, 18 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index ab42b1c..c1498fc 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -319,22 +319,6 @@ class Page < ApplicationRecord
319 end 319 end
320 end 320 end
321 321
322 def update_assets image_ids
323 transaction do
324 previous_headline_asset_id = self.related_assets.find_by(headline: true)&.asset_id
325
326 self.related_assets.delete_all
327
328 if image_ids
329 image_ids.each_with_index do |id, index|
330 asset = Asset.find(id)
331 self.related_assets.create!(:asset_id => asset.id, :position => index+1,
332 :headline => asset.id == previous_headline_asset_id)
333 end
334 end
335 end
336 end
337
338 # Installs (or re-installs) the trigger that keeps page_translations' 322 # Installs (or re-installs) the trigger that keeps page_translations'
339 # search_vector in sync. Idempotent, safe to call on every boot. 323 # search_vector in sync. Idempotent, safe to call on every boot.
340 # search_vector is populated by a raw Postgres trigger, not anything 324 # search_vector is populated by a raw Postgres trigger, not anything
diff --git a/test/models/page_test.rb b/test/models/page_test.rb
index 1f924f9..98a00d2 100644
--- a/test/models/page_test.rb
+++ b/test/models/page_test.rb
@@ -309,11 +309,15 @@ class PageTest < ActiveSupport::TestCase
309 309
310 kept_asset = Asset.create!(:upload_file_name => "kept.png", :upload_content_type => "image/png", :upload_file_size => 1) 310 kept_asset = Asset.create!(:upload_file_name => "kept.png", :upload_content_type => "image/png", :upload_file_size => 1)
311 removed_asset = Asset.create!(:upload_file_name => "removed.pdf", :upload_content_type => "application/pdf", :upload_file_size => 1) 311 removed_asset = Asset.create!(:upload_file_name => "removed.pdf", :upload_content_type => "application/pdf", :upload_file_size => 1)
312 n.head.update_assets([kept_asset.id, removed_asset.id]) 312 n.head.related_assets.delete_all
313 n.head.related_assets.create!(:asset_id => kept_asset.id, :position => 1)
314 n.head.related_assets.create!(:asset_id => removed_asset.id, :position => 2)
313 315
314 d2 = find_or_create_draft(n, @user1) 316 d2 = find_or_create_draft(n, @user1)
315 added_asset = Asset.create!(:upload_file_name => "added.png", :upload_content_type => "image/png", :upload_file_size => 1) 317 added_asset = Asset.create!(:upload_file_name => "added.png", :upload_content_type => "image/png", :upload_file_size => 1)
316 d2.update_assets([kept_asset.id, added_asset.id]) 318 d2.related_assets.delete_all
319 d2.related_assets.create!(:asset_id => kept_asset.id, :position => 1)
320 d2.related_assets.create!(:asset_id => added_asset.id, :position => 2)
317 d2.save! 321 d2.save!
318 322
319 diff = d2.diff_against(n.head) 323 diff = d2.diff_against(n.head)