diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index ae5a23174..290e54984 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -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 diff --git a/app/policies/post_replacement_policy.rb b/app/policies/post_replacement_policy.rb index 0cec75193..2a03d6bee 100644 --- a/app/policies/post_replacement_policy.rb +++ b/app/policies/post_replacement_policy.rb @@ -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 diff --git a/app/views/post_replacements/index.html.erb b/app/views/post_replacements/index.html.erb index b0dd09c87..59a766341 100644 --- a/app/views/post_replacements/index.html.erb +++ b/app/views/post_replacements/index.html.erb @@ -29,10 +29,10 @@ <% 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? %>
Original MD5
-
<%= post_replacement.md5_was %>
+
<%= post_replacement.old_md5 %>
Replacement MD5
<%= post_replacement.md5 %>
@@ -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? } %>
Original Size
- <%= 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 %>)
Replacement Size
diff --git a/db/migrate/20201219201007_rename_post_replacement_attributes.rb b/db/migrate/20201219201007_rename_post_replacement_attributes.rb new file mode 100644 index 000000000..31584c920 --- /dev/null +++ b/db/migrate/20201219201007_rename_post_replacement_attributes.rb @@ -0,0 +1,9 @@ +class RenamePostReplacementAttributes < ActiveRecord::Migration[6.1] + def change + rename_column :post_replacements, :file_ext_was, :old_file_ext + rename_column :post_replacements, :file_size_was, :old_file_size + rename_column :post_replacements, :image_width_was, :old_image_width + rename_column :post_replacements, :image_height_was, :old_image_height + rename_column :post_replacements, :md5_was, :old_md5 + end +end diff --git a/db/structure.sql b/db/structure.sql index d85f9a64c..5f8a9b7da 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2736,11 +2736,11 @@ CREATE TABLE public.post_replacements ( replacement_url text NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - file_ext_was character varying, - file_size_was integer, - image_width_was integer, - image_height_was integer, - md5_was character varying, + old_file_ext character varying, + old_file_size integer, + old_image_width integer, + old_image_height integer, + old_md5 character varying, file_ext character varying, file_size integer, image_width integer, @@ -7436,6 +7436,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200803022359'), ('20200816175151'), ('20201201211748'), -('20201213052805'); +('20201213052805'), +('20201219201007'); diff --git a/test/functional/post_replacements_controller_test.rb b/test/functional/post_replacements_controller_test.rb index e9021d1de..21525bcc1 100644 --- a/test/functional/post_replacements_controller_test.rb +++ b/test/functional/post_replacements_controller_test.rb @@ -47,14 +47,14 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest format: :json, id: @post_replacement.id, post_replacement: { - file_size_was: 23, + old_file_size: 23, file_size: 42 } } put_auth post_replacement_path(@post_replacement), @mod, params: params assert_response :success - assert_equal(23, @post_replacement.reload.file_size_was) + assert_equal(23, @post_replacement.reload.old_file_size) assert_equal(42, @post_replacement.file_size) end end diff --git a/test/unit/upload_service_test.rb b/test/unit/upload_service_test.rb index c8041ebfe..2828b30ab 100644 --- a/test/unit/upload_service_test.rb +++ b/test/unit/upload_service_test.rb @@ -287,11 +287,11 @@ class UploadServiceTest < ActiveSupport::TestCase should "preserve the old values" do as(@user) { subject.process! } - assert_equal(1500, @replacement.image_width_was) - assert_equal(1000, @replacement.image_height_was) - assert_equal(2000, @replacement.file_size_was) - assert_equal("jpg", @replacement.file_ext_was) - assert_equal(@old_md5, @replacement.md5_was) + assert_equal(1500, @replacement.old_image_width) + assert_equal(1000, @replacement.old_image_height) + assert_equal(2000, @replacement.old_file_size) + assert_equal("jpg", @replacement.old_file_ext) + assert_equal(@old_md5, @replacement.old_md5) end should "record the new values" do