post replacements: rename <attr>_was to old_<attr>

Rename the following post replacement attributes:

* file_size_was -> old_file_size
* file_ext_was -> old_file_ext
* image_width_was -> old_image_width
* image_height_was -> old_image_height
* md5_was -> old_md5

In Rails 6.1, having attributes named `file_size` and `file_size_was` on
the same model breaks things because it conflicts with Rails' dirty
attribute tracking.
This commit is contained in:
evazion
2020-12-19 14:18:05 -06:00
parent 09e3146819
commit 4cb39422b2
7 changed files with 36 additions and 26 deletions

View File

@@ -11,17 +11,17 @@ class PostReplacement < ApplicationRecord
self.original_url = post.source
self.tags = post.tag_string + " " + self.tags.to_s
self.file_ext_was = post.file_ext
self.file_size_was = post.file_size
self.image_width_was = post.image_width
self.image_height_was = post.image_height
self.md5_was = post.md5
self.old_file_ext = post.file_ext
self.old_file_size = post.file_size
self.old_image_width = post.image_width
self.old_image_height = post.image_height
self.old_md5 = post.md5
end
concerning :Search do
class_methods do
def search(params = {})
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :md5_was, :file_ext, :file_ext_was, :original_url, :replacement_url, :creator, :post)
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :old_md5, :file_ext, :old_file_ext, :original_url, :replacement_url, :creator, :post)
q.apply_default_order(params)
end
end

View File

@@ -12,8 +12,8 @@ class PostReplacementPolicy < ApplicationPolicy
end
def permitted_attributes_for_update
[:file_ext_was, :file_size_was, :image_width_was, :image_height_was,
:md5_was, :file_ext, :file_size, :image_width, :image_height, :md5,
[:old_file_ext, :old_file_size, :old_image_width, :old_image_height,
:old_md5, :file_ext, :file_size, :image_width, :image_height, :md5,
:original_url, :replacement_url]
end
end

View File

@@ -29,10 +29,10 @@
</dl>
<% end %>
<% t.column "MD5" do |post_replacement| %>
<% if post_replacement.md5_was.present? && post_replacement.md5.present? %>
<% if post_replacement.old_md5.present? && post_replacement.md5.present? %>
<dl>
<dt>Original MD5</dt>
<dd><%= post_replacement.md5_was %></dd>
<dd><%= post_replacement.old_md5 %></dd>
<dt>Replacement MD5</dt>
<dd><%= post_replacement.md5 %></dd>
@@ -40,12 +40,12 @@
<% end %>
<% end %>
<% t.column "Size" do |post_replacement| %>
<% if %i[image_width_was image_height_was file_size_was file_ext_was image_width image_height file_size file_ext].all? { |k| post_replacement[k].present? } %>
<% if %i[old_image_width old_image_height old_file_size old_file_ext image_width image_height file_size file_ext].all? { |k| post_replacement[k].present? } %>
<dl>
<dt>Original Size</dt>
<dd>
<%= post_replacement.image_width_was %>x<%= post_replacement.image_height_was %>
(<%= post_replacement.file_size_was.to_s(:human_size, precision: 4) %>, <%= post_replacement.file_ext_was %>)
<%= post_replacement.old_image_width %>x<%= post_replacement.old_image_height %>
(<%= post_replacement.old_file_size.to_s(:human_size, precision: 4) %>, <%= post_replacement.old_file_ext %>)
</dd>
<dt>Replacement Size</dt>