Replace deprecated update_attributes with update.

https://rubyinrails.com/2019/04/09/rails-6-1-activerecord-deprecates-update-attributes-methods/

DEPRECATION WARNING: update_attributes! is deprecated and will be removed from Rails 6.1 (please, use update! instead)
This commit is contained in:
evazion
2019-08-25 20:29:32 -05:00
parent 62875eabb2
commit 0df5c0fd2b
23 changed files with 63 additions and 87 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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?)