diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 270edb3ba..942ae3054 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -51,7 +51,7 @@ class NotesController < ApplicationController def destroy @note = Note.find(params[:id]) - @note.update_attributes(:is_active => false) + @note.update(is_active: false) respond_with(@note) end diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 142c8deef..2c84c642f 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -68,7 +68,7 @@ class WikiPagesController < ApplicationController def destroy @wiki_page = WikiPage.find(params[:id]) - @wiki_page.update_attributes(:is_deleted => true) + @wiki_page.update(is_deleted: true) respond_with(@wiki_page) end diff --git a/app/models/artist.rb b/app/models/artist.rb index 8a90d5ef0..06c39d05f 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -279,14 +279,7 @@ class Artist < ApplicationRecord def merge_version prev = versions.last - prev.update_attributes( - :name => name, - :urls => url_array, - :is_active => is_active, - :is_banned => is_banned, - :other_names => other_names, - :group_name => group_name - ) + prev.update(name: name, urls: url_array, is_active: is_active, is_banned: is_banned, other_names: other_names, group_name: group_name) end def merge_version? @@ -427,7 +420,7 @@ class Artist < ApplicationRecord Post.tag_match(name).where("true /* Artist.unban */").each do |post| post.unban! fixed_tags = post.tag_string.sub(/(?:\A| )banned_artist(?:\Z| )/, " ").strip - post.update_attributes(:tag_string => fixed_tags) + post.update(tag_string: fixed_tags) end rescue Post::SearchError # swallow diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index cc010e62e..b7ecd17e4 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -174,7 +174,7 @@ class FavoriteGroup < ApplicationRecord return if contains?(post_id) clear_post_id_array - update_attributes(:post_ids => add_number_to_string(post_id, post_ids)) + update(post_ids: add_number_to_string(post_id, post_ids)) end end @@ -184,7 +184,7 @@ class FavoriteGroup < ApplicationRecord return unless contains?(post_id) clear_post_id_array - update_attributes(:post_ids => remove_number_from_string(post_id, post_ids)) + update(post_ids: remove_number_from_string(post_id, post_ids)) end end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 432bfabfd..442c1f8ed 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -193,7 +193,7 @@ class ForumTopic < ApplicationRecord def merge(topic) ForumPost.where(:id => self.posts.map(&:id)).update_all(:topic_id => topic.id) - topic.update_attributes(:response_count => topic.response_count + self.posts.length, :updater_id => CurrentUser.id) + topic.update(response_count: topic.response_count + self.posts.length, updater_id: CurrentUser.id) self.update_columns(:response_count => 0, :is_deleted => true, :updater_id => CurrentUser.id) end diff --git a/app/models/note.rb b/app/models/note.rb index bcc6481b2..c6281e2ea 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -139,14 +139,7 @@ class Note < ApplicationRecord def merge_version prev = versions.last - prev.update_attributes( - :x => x, - :y => y, - :width => width, - :height => height, - :is_active => is_active, - :body => body - ) + prev.update(x: x, y: y, width: width, height: height, is_active: is_active, body: body) end def merge_version?(updater_id) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 8c4740c10..5e9c29adf 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -142,9 +142,7 @@ class TagAlias < TagRelationship escaped_antecedent_name = Regexp.escape(antecedent_name) fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip CurrentUser.scoped(creator, creator_ip_addr) do - post.update_attributes( - :tag_string => fixed_tags - ) + post.update(tag_string: fixed_tags) end end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 7fb537844..4d700ee9d 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -154,9 +154,7 @@ class TagImplication < TagRelationship Post.raw_tag_match(antecedent_name).where("true /* TagImplication#update_posts */").find_each do |post| fixed_tags = "#{post.tag_string} #{descendant_names_string}".strip CurrentUser.scoped(creator, creator_ip_addr) do - post.update_attributes( - :tag_string => fixed_tags - ) + post.update(tag_string: fixed_tags) end end end diff --git a/app/models/user_name_change_request.rb b/app/models/user_name_change_request.rb index 46d9dd0b6..f4e62123d 100644 --- a/app/models/user_name_change_request.rb +++ b/app/models/user_name_change_request.rb @@ -47,7 +47,7 @@ class UserNameChangeRequest < ApplicationRecord end def approve! - update_attributes(:status => "approved", :approver_id => CurrentUser.user.id) + update(status: "approved", approver_id: CurrentUser.user.id) user.update_attribute(:name, desired_name) body = "Your name change request has been approved. Be sure to log in with your new user name." Dmail.create_automated(:title => "Name change request approved", :body => body, :to_id => user_id) @@ -56,7 +56,7 @@ class UserNameChangeRequest < ApplicationRecord end def reject!(reason) - update_attributes(:status => "rejected", :rejection_reason => reason) + update(status: "rejected", rejection_reason: reason) body = "Your name change request has been rejected for the following reason: #{rejection_reason}" Dmail.create_automated(:title => "Name change request rejected", :body => body, :to_id => user_id) end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index ccd39ebab..e6c12e684 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -176,13 +176,7 @@ class WikiPage < ApplicationRecord def merge_version prev = versions.last - prev.update_attributes( - :title => title, - :body => body, - :is_locked => is_locked, - :is_deleted => is_deleted, - :other_names => other_names - ) + prev.update(title: title, body: body, is_locked: is_locked, is_deleted: is_deleted, other_names: other_names) end def merge_version? diff --git a/db/populate.rb b/db/populate.rb index 37602c794..f7babee42 100644 --- a/db/populate.rb +++ b/db/populate.rb @@ -131,7 +131,7 @@ if Note.count == 0 note = Note.create(:post_id => post.id, :x => rand(post.image_width), :y => rand(post.image_height), :width => 100, :height => 100, :body => Time.now.to_f.to_s) rand(20).times do |i| - note.update_attributes(:body => rand_sentence(6)) + note.update(body: rand_sentence(6)) end end end diff --git a/script/fixes/023_remove_expunged_posts_from_pools.rb b/script/fixes/023_remove_expunged_posts_from_pools.rb index 9c80875b4..9c1b04217 100644 --- a/script/fixes/023_remove_expunged_posts_from_pools.rb +++ b/script/fixes/023_remove_expunged_posts_from_pools.rb @@ -13,6 +13,6 @@ dead_post_ids = all_post_ids - live_post_ids dead_post_ids.each do |post_id| Pool.where("post_ids like '? %' or post_ids like '% ? %' or post_ids like '% ?'", post_id, post_id, post_id).find_each do |pool| - pool.update_attributes(:post_ids => pool.remove_number_from_string(post_id, pool.post_ids), :post_count => pool.post_count - 1) + pool.update(post_ids: pool.remove_number_from_string(post_id, pool.post_ids), post_count: pool.post_count - 1) end end diff --git a/test/functional/note_versions_controller_test.rb b/test/functional/note_versions_controller_test.rb index 96b883c03..4ac3b8690 100644 --- a/test/functional/note_versions_controller_test.rb +++ b/test/functional/note_versions_controller_test.rb @@ -14,11 +14,11 @@ class NoteVersionsControllerTest < ActionDispatch::IntegrationTest @user_2 = create(:user) CurrentUser.scoped(@user_2, "1.2.3.4") do - @note.update_attributes(:body => "1 2") + @note.update(body: "1 2") end CurrentUser.scoped(@user, "1.2.3.4") do - @note.update_attributes(:body => "1 2 3") + @note.update(body: "1 2 3") end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index ec58c0d29..bb64db132 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -242,7 +242,7 @@ class CommentTest < ActiveSupport::TestCase should "create a mod action" do assert_difference("ModAction.count") do - @comment.update_attributes(:body => "nope") + @comment.update(body: "nope") end end diff --git a/test/unit/dmail_test.rb b/test/unit/dmail_test.rb index c6ed3ee8d..e68d25dc8 100644 --- a/test/unit/dmail_test.rb +++ b/test/unit/dmail_test.rb @@ -77,7 +77,7 @@ class DmailTest < ActiveSupport::TestCase context "that is empty" do setup do - @recipient.dmail_filter.update_attributes(:words => " ") + @recipient.dmail_filter.update(words: " ") end should "not filter everything" do diff --git a/test/unit/forum_post_test.rb b/test/unit/forum_post_test.rb index a8478b4c0..296723068 100644 --- a/test/unit/forum_post_test.rb +++ b/test/unit/forum_post_test.rb @@ -121,7 +121,7 @@ class ForumPostTest < ActiveSupport::TestCase end should "not be updateable" do - @post.update_attributes(:body => "xxx") + @post.update(body: "xxx") @post.reload assert_equal("zzz", @post.body) end @@ -150,14 +150,14 @@ class ForumPostTest < ActiveSupport::TestCase # updating the original post travel(1.second) do - posts.first.update_attributes(:body => "xxx") + posts.first.update(body: "xxx") end @topic.reload assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s) # updating a non-original post travel(2.seconds) do - posts.last.update_attributes(:body => "xxx") + posts.last.update(body: "xxx") end assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s) end @@ -181,7 +181,7 @@ class ForumPostTest < ActiveSupport::TestCase end should "record its updater" do - @post.update_attributes(:body => "abc") + @post.update(body: "abc") assert_equal(@second_user.id, @post.updater_id) end end diff --git a/test/unit/forum_topic_test.rb b/test/unit/forum_topic_test.rb index 3b211d7cd..5014eb49d 100644 --- a/test/unit/forum_topic_test.rb +++ b/test/unit/forum_topic_test.rb @@ -153,7 +153,7 @@ class ForumTopicTest < ActiveSupport::TestCase end should "record its updater" do - @topic.update_attributes(:title => "abc") + @topic.update(title: "abc") assert_equal(@second_user.id, @topic.updater_id) end end diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index 9eaa9f91e..c9235b735 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -20,7 +20,7 @@ class NoteTest < ActiveSupport::TestCase end should "not increment version" do - @note.update_attributes(:x => 100) + @note.update(x: 100) assert_equal(1, @note.versions.count) assert_equal(1, @note.versions.first.version) end @@ -121,14 +121,14 @@ class NoteTest < ActiveSupport::TestCase should "increment the updater's note_update_count" do @user.reload assert_difference("@user.note_update_count", 1) do - @note.update_attributes(:body => "zzz") + @note.update(body: "zzz") @user.reload end end should "update the post's last_noted_at field" do assert_nil(@post.last_noted_at) - @note.update_attributes(:x => 500) + @note.update(x: 500) @post.reload assert_equal(@post.last_noted_at.to_i, @note.updated_at.to_i) end @@ -136,7 +136,7 @@ class NoteTest < ActiveSupport::TestCase should "create a version" do assert_difference("NoteVersion.count", 1) do travel(1.day) do - @note.update_attributes(:body => "fafafa") + @note.update(body: "fafafa") end end assert_equal(2, @note.versions.count) @@ -153,7 +153,7 @@ class NoteTest < ActiveSupport::TestCase end should "fail" do - @note.update_attributes(:x => 500) + @note.update(x: 500) assert_equal(["Post is note locked"], @note.errors.full_messages) end end @@ -172,7 +172,7 @@ class NoteTest < ActiveSupport::TestCase @vandal = FactoryBot.create(:user) @note = FactoryBot.create(:note, :x => 5, :y => 5) CurrentUser.scoped(@vandal, "127.0.0.1") do - @note.update_attributes(:x => 10, :y => 10) + @note.update(x: 10, y: 10) end end diff --git a/test/unit/post_archive_test.rb b/test/unit/post_archive_test.rb index f171c04cf..25dc5c2b8 100644 --- a/test/unit/post_archive_test.rb +++ b/test/unit/post_archive_test.rb @@ -21,8 +21,8 @@ class PostArchiveTest < ActiveSupport::TestCase setup do PostArchive.sqs_service.stubs(:merge?).returns(false) @post = FactoryBot.create(:post, :tag_string => "1") - @post.update_attributes(:tag_string => "1 2") - @post.update_attributes(:tag_string => "2 3") + @post.update(tag_string: "1 2") + @post.update(tag_string: "2 3") end subject { @post.versions.sort_by(&:id)[1] } @@ -38,8 +38,8 @@ class PostArchiveTest < ActiveSupport::TestCase setup do PostArchive.sqs_service.stubs(:merge?).returns(false) @post = FactoryBot.create(:post, :tag_string => "1") - @post.update_attributes(:tag_string => "1 2") - @post.update_attributes(:tag_string => "2 3") + @post.update(tag_string: "1 2") + @post.update(tag_string: "2 3") end context "a version record" do @@ -94,7 +94,7 @@ class PostArchiveTest < ActiveSupport::TestCase should "delete the previous version" do assert_equal(1, @post.versions.count) - @post.update_attributes(:tag_string => "bbb ccc xxx", :source => "") + @post.update(tag_string: "bbb ccc xxx", source: "") @post.reload assert_equal(1, @post.versions.count) end @@ -104,7 +104,7 @@ class PostArchiveTest < ActiveSupport::TestCase setup do PostArchive.sqs_service.stubs(:merge?).returns(false) @post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz") - @post.update_attributes(:tag_string => "bbb ccc xxx", :source => "") + @post.update(tag_string: "bbb ccc xxx", source: "") end should "also create a version" do diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 47cf381c0..209b8e045 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -592,12 +592,12 @@ class PostTest < ActiveSupport::TestCase end should "not allow you to remove tags" do - @post.update_attributes(:tag_string => "aaa") + @post.update(tag_string: "aaa") assert_equal(["You must have an account at least 1 week old to remove tags"], @post.errors.full_messages) end should "allow you to remove request tags" do - @post.update_attributes(:tag_string => "aaa bbb ccc ddd") + @post.update(tag_string: "aaa bbb ccc ddd") @post.reload assert_equal("aaa bbb ccc ddd", @post.tag_string) end @@ -795,7 +795,7 @@ class PostTest < ActiveSupport::TestCase end should "update the parent relationships for both posts" do - @post.update_attributes(:tag_string => "aaa parent:#{@parent.id}") + @post.update(tag_string: "aaa parent:#{@parent.id}") @post.reload @parent.reload assert_equal(@parent.id, @post.parent_id) @@ -887,7 +887,7 @@ class PostTest < ActiveSupport::TestCase context "id" do setup do @pool = FactoryBot.create(:pool) - @post.update_attributes(:tag_string => "aaa pool:#{@pool.id}") + @post.update(tag_string: "aaa pool:#{@pool.id}") end should "add the post to the pool" do @@ -902,7 +902,7 @@ class PostTest < ActiveSupport::TestCase context "that exists" do setup do @pool = FactoryBot.create(:pool, :name => "abc") - @post.update_attributes(:tag_string => "aaa pool:abc") + @post.update(tag_string: "aaa pool:abc") end should "add the post to the pool" do @@ -915,7 +915,7 @@ class PostTest < ActiveSupport::TestCase context "that doesn't exist" do should "create a new pool and add the post to that pool" do - @post.update_attributes(:tag_string => "aaa newpool:abc") + @post.update(tag_string: "aaa newpool:abc") @pool = Pool.find_by_name("abc") @post.reload assert_not_nil(@pool) @@ -936,7 +936,7 @@ class PostTest < ActiveSupport::TestCase context "for a rating" do context "that is valid" do should "update the rating if the post is unlocked" do - @post.update_attributes(:tag_string => "aaa rating:e") + @post.update(tag_string: "aaa rating:e") @post.reload assert_equal("e", @post.rating) end @@ -944,7 +944,7 @@ class PostTest < ActiveSupport::TestCase context "that is invalid" do should "not update the rating" do - @post.update_attributes(:tag_string => "aaa rating:z") + @post.update(tag_string: "aaa rating:z") @post.reload assert_equal("q", @post.rating) end @@ -972,10 +972,10 @@ class PostTest < ActiveSupport::TestCase context "for a fav" do should "add/remove the current user to the post's favorite listing" do - @post.update_attributes(:tag_string => "aaa fav:self") + @post.update(tag_string: "aaa fav:self") assert_equal("fav:#{@user.id}", @post.fav_string) - @post.update_attributes(:tag_string => "aaa -fav:self") + @post.update(tag_string: "aaa -fav:self") assert_equal("", @post.fav_string) end end @@ -1148,8 +1148,8 @@ class PostTest < ActiveSupport::TestCase context "tagged with a negated tag" do should "remove the tag if present" do - @post.update_attributes(:tag_string => "aaa bbb ccc") - @post.update_attributes(:tag_string => "aaa bbb ccc -bbb") + @post.update(tag_string: "aaa bbb ccc") + @post.update(tag_string: "aaa bbb ccc -bbb") @post.reload assert_equal("aaa ccc", @post.tag_string) end @@ -1280,7 +1280,7 @@ class PostTest < ActiveSupport::TestCase post = FactoryBot.create(:post) travel(6.hours) do assert_difference("PostArchive.count", 1) do - post.update_attributes(:tag_string => "zzz") + post.update(tag_string: "zzz") end end end @@ -1288,7 +1288,7 @@ class PostTest < ActiveSupport::TestCase should "merge with the previous version if the updater is the same user and it's been less than an hour" do post = FactoryBot.create(:post) assert_difference("PostArchive.count", 0) do - post.update_attributes(:tag_string => "zzz") + post.update(tag_string: "zzz") end assert_equal("zzz", post.versions.last.tags) end @@ -1302,7 +1302,7 @@ class PostTest < ActiveSupport::TestCase # production the counter cache doesn't bump the count, because # versions are created on a separate server. assert_difference("CurrentUser.user.reload.post_update_count", 2) do - post.update_attributes(:tag_string => "zzz") + post.update(tag_string: "zzz") end end diff --git a/test/unit/post_version_test.rb b/test/unit/post_version_test.rb index 5a788dce3..5dcd9cb11 100644 --- a/test/unit/post_version_test.rb +++ b/test/unit/post_version_test.rb @@ -19,8 +19,8 @@ class PostVersionTest < ActiveSupport::TestCase setup do PostArchive.sqs_service.stubs(:merge?).returns(false) @post = FactoryBot.create(:post, :tag_string => "1") - @post.update_attributes(:tag_string => "1 2") - @post.update_attributes(:tag_string => "2 3") + @post.update(tag_string: "1 2") + @post.update(tag_string: "2 3") end context "a version record" do @@ -59,7 +59,7 @@ class PostVersionTest < ActiveSupport::TestCase should "delete the previous version" do assert_equal(1, @post.versions.count) - @post.update_attributes(:tag_string => "bbb ccc xxx", :source => "") + @post.update(tag_string: "bbb ccc xxx", source: "") @post.reload assert_equal(1, @post.versions.count) end @@ -71,7 +71,7 @@ class PostVersionTest < ActiveSupport::TestCase travel_to(1.minute.ago) do @post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz") end - @post.update_attributes(:tag_string => "bbb ccc xxx", :source => "") + @post.update(tag_string: "bbb ccc xxx", source: "") end should "also create a version" do diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 5036efdf4..f0f0f2c6e 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -239,25 +239,25 @@ class UserTest < ActiveSupport::TestCase should "not change the password if the password and old password are blank" do @user = FactoryBot.create(:user, :password => "67890") - @user.update_attributes(:password => "", :old_password => "") + @user.update(password: "", old_password: "") assert(@user.bcrypt_password == User.sha1("67890")) end should "not change the password if the old password is incorrect" do @user = FactoryBot.create(:user, :password => "67890") - @user.update_attributes(:password => "12345", :old_password => "abcdefg") + @user.update(password: "12345", old_password: "abcdefg") assert(@user.bcrypt_password == User.sha1("67890")) end should "not change the password if the old password is blank" do @user = FactoryBot.create(:user, :password => "67890") - @user.update_attributes(:password => "12345", :old_password => "") + @user.update(password: "12345", old_password: "") assert(@user.bcrypt_password == User.sha1("67890")) end should "change the password if the old password is correct" do @user = FactoryBot.create(:user, :password => "67890") - @user.update_attributes(:password => "12345", :old_password => "67890") + @user.update(password: "12345", old_password: "67890") assert(@user.bcrypt_password == User.sha1("12345")) end diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index c9dedfbe5..03738f2b9 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -16,7 +16,7 @@ class WikiPageTest < ActiveSupport::TestCase CurrentUser.user = FactoryBot.create(:moderator_user) @wiki_page = FactoryBot.create(:wiki_page, :is_locked => true) CurrentUser.user = FactoryBot.create(:user) - @wiki_page.update_attributes(:body => "hello") + @wiki_page.update(body: "hello") assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages) end @@ -24,7 +24,7 @@ class WikiPageTest < ActiveSupport::TestCase CurrentUser.user = FactoryBot.create(:moderator_user) @wiki_page = FactoryBot.create(:wiki_page, :is_locked => true) CurrentUser.user = FactoryBot.create(:moderator_user) - @wiki_page.update_attributes(:body => "hello") + @wiki_page.update(body: "hello") assert_equal([], @wiki_page.errors.full_messages) end end @@ -37,7 +37,7 @@ class WikiPageTest < ActiveSupport::TestCase end should "allow the is_locked attribute to be updated" do - @wiki_page.update_attributes(:is_locked => true) + @wiki_page.update(is_locked: true) @wiki_page.reload assert_equal(true, @wiki_page.is_locked?) end @@ -51,7 +51,7 @@ class WikiPageTest < ActiveSupport::TestCase end should "not allow the is_locked attribute to be updated" do - @wiki_page.update_attributes(:is_locked => true) + @wiki_page.update(is_locked: true) assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages) @wiki_page.reload assert_equal(false, @wiki_page.is_locked?)