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

@@ -51,7 +51,7 @@ class NotesController < ApplicationController
def destroy def destroy
@note = Note.find(params[:id]) @note = Note.find(params[:id])
@note.update_attributes(:is_active => false) @note.update(is_active: false)
respond_with(@note) respond_with(@note)
end end

View File

@@ -68,7 +68,7 @@ class WikiPagesController < ApplicationController
def destroy def destroy
@wiki_page = WikiPage.find(params[:id]) @wiki_page = WikiPage.find(params[:id])
@wiki_page.update_attributes(:is_deleted => true) @wiki_page.update(is_deleted: true)
respond_with(@wiki_page) respond_with(@wiki_page)
end end

View File

@@ -279,14 +279,7 @@ class Artist < ApplicationRecord
def merge_version def merge_version
prev = versions.last prev = versions.last
prev.update_attributes( prev.update(name: name, urls: url_array, is_active: is_active, is_banned: is_banned, other_names: other_names, group_name: group_name)
:name => name,
:urls => url_array,
:is_active => is_active,
:is_banned => is_banned,
:other_names => other_names,
:group_name => group_name
)
end end
def merge_version? def merge_version?
@@ -427,7 +420,7 @@ class Artist < ApplicationRecord
Post.tag_match(name).where("true /* Artist.unban */").each do |post| Post.tag_match(name).where("true /* Artist.unban */").each do |post|
post.unban! post.unban!
fixed_tags = post.tag_string.sub(/(?:\A| )banned_artist(?:\Z| )/, " ").strip 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 end
rescue Post::SearchError rescue Post::SearchError
# swallow # swallow

View File

@@ -174,7 +174,7 @@ class FavoriteGroup < ApplicationRecord
return if contains?(post_id) return if contains?(post_id)
clear_post_id_array 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
end end
@@ -184,7 +184,7 @@ class FavoriteGroup < ApplicationRecord
return unless contains?(post_id) return unless contains?(post_id)
clear_post_id_array 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
end end

View File

@@ -193,7 +193,7 @@ class ForumTopic < ApplicationRecord
def merge(topic) def merge(topic)
ForumPost.where(:id => self.posts.map(&:id)).update_all(:topic_id => topic.id) 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) self.update_columns(:response_count => 0, :is_deleted => true, :updater_id => CurrentUser.id)
end end

View File

@@ -139,14 +139,7 @@ class Note < ApplicationRecord
def merge_version def merge_version
prev = versions.last prev = versions.last
prev.update_attributes( prev.update(x: x, y: y, width: width, height: height, is_active: is_active, body: body)
:x => x,
:y => y,
:width => width,
:height => height,
:is_active => is_active,
:body => body
)
end end
def merge_version?(updater_id) def merge_version?(updater_id)

View File

@@ -142,9 +142,7 @@ class TagAlias < TagRelationship
escaped_antecedent_name = Regexp.escape(antecedent_name) escaped_antecedent_name = Regexp.escape(antecedent_name)
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
CurrentUser.scoped(creator, creator_ip_addr) do CurrentUser.scoped(creator, creator_ip_addr) do
post.update_attributes( post.update(tag_string: fixed_tags)
:tag_string => fixed_tags
)
end end
end end

View File

@@ -154,9 +154,7 @@ class TagImplication < TagRelationship
Post.raw_tag_match(antecedent_name).where("true /* TagImplication#update_posts */").find_each do |post| Post.raw_tag_match(antecedent_name).where("true /* TagImplication#update_posts */").find_each do |post|
fixed_tags = "#{post.tag_string} #{descendant_names_string}".strip fixed_tags = "#{post.tag_string} #{descendant_names_string}".strip
CurrentUser.scoped(creator, creator_ip_addr) do CurrentUser.scoped(creator, creator_ip_addr) do
post.update_attributes( post.update(tag_string: fixed_tags)
:tag_string => fixed_tags
)
end end
end end
end end

View File

@@ -47,7 +47,7 @@ class UserNameChangeRequest < ApplicationRecord
end end
def approve! 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) user.update_attribute(:name, desired_name)
body = "Your name change request has been approved. Be sure to log in with your new user 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) Dmail.create_automated(:title => "Name change request approved", :body => body, :to_id => user_id)
@@ -56,7 +56,7 @@ class UserNameChangeRequest < ApplicationRecord
end end
def reject!(reason) 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}" 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) Dmail.create_automated(:title => "Name change request rejected", :body => body, :to_id => user_id)
end end

View File

@@ -176,13 +176,7 @@ class WikiPage < ApplicationRecord
def merge_version def merge_version
prev = versions.last prev = versions.last
prev.update_attributes( prev.update(title: title, body: body, is_locked: is_locked, is_deleted: is_deleted, other_names: other_names)
:title => title,
:body => body,
:is_locked => is_locked,
:is_deleted => is_deleted,
:other_names => other_names
)
end end
def merge_version? def merge_version?

View File

@@ -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) 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| rand(20).times do |i|
note.update_attributes(:body => rand_sentence(6)) note.update(body: rand_sentence(6))
end end
end end
end end

View File

@@ -13,6 +13,6 @@ dead_post_ids = all_post_ids - live_post_ids
dead_post_ids.each do |post_id| 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.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
end end

View File

@@ -14,11 +14,11 @@ class NoteVersionsControllerTest < ActionDispatch::IntegrationTest
@user_2 = create(:user) @user_2 = create(:user)
CurrentUser.scoped(@user_2, "1.2.3.4") do CurrentUser.scoped(@user_2, "1.2.3.4") do
@note.update_attributes(:body => "1 2") @note.update(body: "1 2")
end end
CurrentUser.scoped(@user, "1.2.3.4") do CurrentUser.scoped(@user, "1.2.3.4") do
@note.update_attributes(:body => "1 2 3") @note.update(body: "1 2 3")
end end
end end

View File

@@ -242,7 +242,7 @@ class CommentTest < ActiveSupport::TestCase
should "create a mod action" do should "create a mod action" do
assert_difference("ModAction.count") do assert_difference("ModAction.count") do
@comment.update_attributes(:body => "nope") @comment.update(body: "nope")
end end
end end

View File

@@ -77,7 +77,7 @@ class DmailTest < ActiveSupport::TestCase
context "that is empty" do context "that is empty" do
setup do setup do
@recipient.dmail_filter.update_attributes(:words => " ") @recipient.dmail_filter.update(words: " ")
end end
should "not filter everything" do should "not filter everything" do

View File

@@ -121,7 +121,7 @@ class ForumPostTest < ActiveSupport::TestCase
end end
should "not be updateable" do should "not be updateable" do
@post.update_attributes(:body => "xxx") @post.update(body: "xxx")
@post.reload @post.reload
assert_equal("zzz", @post.body) assert_equal("zzz", @post.body)
end end
@@ -150,14 +150,14 @@ class ForumPostTest < ActiveSupport::TestCase
# updating the original post # updating the original post
travel(1.second) do travel(1.second) do
posts.first.update_attributes(:body => "xxx") posts.first.update(body: "xxx")
end end
@topic.reload @topic.reload
assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s) assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s)
# updating a non-original post # updating a non-original post
travel(2.seconds) do travel(2.seconds) do
posts.last.update_attributes(:body => "xxx") posts.last.update(body: "xxx")
end end
assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s) assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s)
end end
@@ -181,7 +181,7 @@ class ForumPostTest < ActiveSupport::TestCase
end end
should "record its updater" do should "record its updater" do
@post.update_attributes(:body => "abc") @post.update(body: "abc")
assert_equal(@second_user.id, @post.updater_id) assert_equal(@second_user.id, @post.updater_id)
end end
end end

View File

@@ -153,7 +153,7 @@ class ForumTopicTest < ActiveSupport::TestCase
end end
should "record its updater" do should "record its updater" do
@topic.update_attributes(:title => "abc") @topic.update(title: "abc")
assert_equal(@second_user.id, @topic.updater_id) assert_equal(@second_user.id, @topic.updater_id)
end end
end end

View File

@@ -20,7 +20,7 @@ class NoteTest < ActiveSupport::TestCase
end end
should "not increment version" do 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.count)
assert_equal(1, @note.versions.first.version) assert_equal(1, @note.versions.first.version)
end end
@@ -121,14 +121,14 @@ class NoteTest < ActiveSupport::TestCase
should "increment the updater's note_update_count" do should "increment the updater's note_update_count" do
@user.reload @user.reload
assert_difference("@user.note_update_count", 1) do assert_difference("@user.note_update_count", 1) do
@note.update_attributes(:body => "zzz") @note.update(body: "zzz")
@user.reload @user.reload
end end
end end
should "update the post's last_noted_at field" do should "update the post's last_noted_at field" do
assert_nil(@post.last_noted_at) assert_nil(@post.last_noted_at)
@note.update_attributes(:x => 500) @note.update(x: 500)
@post.reload @post.reload
assert_equal(@post.last_noted_at.to_i, @note.updated_at.to_i) assert_equal(@post.last_noted_at.to_i, @note.updated_at.to_i)
end end
@@ -136,7 +136,7 @@ class NoteTest < ActiveSupport::TestCase
should "create a version" do should "create a version" do
assert_difference("NoteVersion.count", 1) do assert_difference("NoteVersion.count", 1) do
travel(1.day) do travel(1.day) do
@note.update_attributes(:body => "fafafa") @note.update(body: "fafafa")
end end
end end
assert_equal(2, @note.versions.count) assert_equal(2, @note.versions.count)
@@ -153,7 +153,7 @@ class NoteTest < ActiveSupport::TestCase
end end
should "fail" do should "fail" do
@note.update_attributes(:x => 500) @note.update(x: 500)
assert_equal(["Post is note locked"], @note.errors.full_messages) assert_equal(["Post is note locked"], @note.errors.full_messages)
end end
end end
@@ -172,7 +172,7 @@ class NoteTest < ActiveSupport::TestCase
@vandal = FactoryBot.create(:user) @vandal = FactoryBot.create(:user)
@note = FactoryBot.create(:note, :x => 5, :y => 5) @note = FactoryBot.create(:note, :x => 5, :y => 5)
CurrentUser.scoped(@vandal, "127.0.0.1") do CurrentUser.scoped(@vandal, "127.0.0.1") do
@note.update_attributes(:x => 10, :y => 10) @note.update(x: 10, y: 10)
end end
end end

View File

@@ -21,8 +21,8 @@ class PostArchiveTest < ActiveSupport::TestCase
setup do setup do
PostArchive.sqs_service.stubs(:merge?).returns(false) PostArchive.sqs_service.stubs(:merge?).returns(false)
@post = FactoryBot.create(:post, :tag_string => "1") @post = FactoryBot.create(:post, :tag_string => "1")
@post.update_attributes(:tag_string => "1 2") @post.update(tag_string: "1 2")
@post.update_attributes(:tag_string => "2 3") @post.update(tag_string: "2 3")
end end
subject { @post.versions.sort_by(&:id)[1] } subject { @post.versions.sort_by(&:id)[1] }
@@ -38,8 +38,8 @@ class PostArchiveTest < ActiveSupport::TestCase
setup do setup do
PostArchive.sqs_service.stubs(:merge?).returns(false) PostArchive.sqs_service.stubs(:merge?).returns(false)
@post = FactoryBot.create(:post, :tag_string => "1") @post = FactoryBot.create(:post, :tag_string => "1")
@post.update_attributes(:tag_string => "1 2") @post.update(tag_string: "1 2")
@post.update_attributes(:tag_string => "2 3") @post.update(tag_string: "2 3")
end end
context "a version record" do context "a version record" do
@@ -94,7 +94,7 @@ class PostArchiveTest < ActiveSupport::TestCase
should "delete the previous version" do should "delete the previous version" do
assert_equal(1, @post.versions.count) 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 @post.reload
assert_equal(1, @post.versions.count) assert_equal(1, @post.versions.count)
end end
@@ -104,7 +104,7 @@ class PostArchiveTest < ActiveSupport::TestCase
setup do setup do
PostArchive.sqs_service.stubs(:merge?).returns(false) PostArchive.sqs_service.stubs(:merge?).returns(false)
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz") @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 end
should "also create a version" do should "also create a version" do

View File

@@ -592,12 +592,12 @@ class PostTest < ActiveSupport::TestCase
end end
should "not allow you to remove tags" do 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) assert_equal(["You must have an account at least 1 week old to remove tags"], @post.errors.full_messages)
end end
should "allow you to remove request tags" do 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 @post.reload
assert_equal("aaa bbb ccc ddd", @post.tag_string) assert_equal("aaa bbb ccc ddd", @post.tag_string)
end end
@@ -795,7 +795,7 @@ class PostTest < ActiveSupport::TestCase
end end
should "update the parent relationships for both posts" do 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 @post.reload
@parent.reload @parent.reload
assert_equal(@parent.id, @post.parent_id) assert_equal(@parent.id, @post.parent_id)
@@ -887,7 +887,7 @@ class PostTest < ActiveSupport::TestCase
context "id" do context "id" do
setup do setup do
@pool = FactoryBot.create(:pool) @pool = FactoryBot.create(:pool)
@post.update_attributes(:tag_string => "aaa pool:#{@pool.id}") @post.update(tag_string: "aaa pool:#{@pool.id}")
end end
should "add the post to the pool" do should "add the post to the pool" do
@@ -902,7 +902,7 @@ class PostTest < ActiveSupport::TestCase
context "that exists" do context "that exists" do
setup do setup do
@pool = FactoryBot.create(:pool, :name => "abc") @pool = FactoryBot.create(:pool, :name => "abc")
@post.update_attributes(:tag_string => "aaa pool:abc") @post.update(tag_string: "aaa pool:abc")
end end
should "add the post to the pool" do should "add the post to the pool" do
@@ -915,7 +915,7 @@ class PostTest < ActiveSupport::TestCase
context "that doesn't exist" do context "that doesn't exist" do
should "create a new pool and add the post to that pool" 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") @pool = Pool.find_by_name("abc")
@post.reload @post.reload
assert_not_nil(@pool) assert_not_nil(@pool)
@@ -936,7 +936,7 @@ class PostTest < ActiveSupport::TestCase
context "for a rating" do context "for a rating" do
context "that is valid" do context "that is valid" do
should "update the rating if the post is unlocked" 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 @post.reload
assert_equal("e", @post.rating) assert_equal("e", @post.rating)
end end
@@ -944,7 +944,7 @@ class PostTest < ActiveSupport::TestCase
context "that is invalid" do context "that is invalid" do
should "not update the rating" do should "not update the rating" do
@post.update_attributes(:tag_string => "aaa rating:z") @post.update(tag_string: "aaa rating:z")
@post.reload @post.reload
assert_equal("q", @post.rating) assert_equal("q", @post.rating)
end end
@@ -972,10 +972,10 @@ class PostTest < ActiveSupport::TestCase
context "for a fav" do context "for a fav" do
should "add/remove the current user to the post's favorite listing" 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) 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) assert_equal("", @post.fav_string)
end end
end end
@@ -1148,8 +1148,8 @@ class PostTest < ActiveSupport::TestCase
context "tagged with a negated tag" do context "tagged with a negated tag" do
should "remove the tag if present" do should "remove the tag if present" do
@post.update_attributes(:tag_string => "aaa bbb ccc") @post.update(tag_string: "aaa bbb ccc")
@post.update_attributes(:tag_string => "aaa bbb ccc -bbb") @post.update(tag_string: "aaa bbb ccc -bbb")
@post.reload @post.reload
assert_equal("aaa ccc", @post.tag_string) assert_equal("aaa ccc", @post.tag_string)
end end
@@ -1280,7 +1280,7 @@ class PostTest < ActiveSupport::TestCase
post = FactoryBot.create(:post) post = FactoryBot.create(:post)
travel(6.hours) do travel(6.hours) do
assert_difference("PostArchive.count", 1) do assert_difference("PostArchive.count", 1) do
post.update_attributes(:tag_string => "zzz") post.update(tag_string: "zzz")
end end
end 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 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) post = FactoryBot.create(:post)
assert_difference("PostArchive.count", 0) do assert_difference("PostArchive.count", 0) do
post.update_attributes(:tag_string => "zzz") post.update(tag_string: "zzz")
end end
assert_equal("zzz", post.versions.last.tags) assert_equal("zzz", post.versions.last.tags)
end end
@@ -1302,7 +1302,7 @@ class PostTest < ActiveSupport::TestCase
# production the counter cache doesn't bump the count, because # production the counter cache doesn't bump the count, because
# versions are created on a separate server. # versions are created on a separate server.
assert_difference("CurrentUser.user.reload.post_update_count", 2) do assert_difference("CurrentUser.user.reload.post_update_count", 2) do
post.update_attributes(:tag_string => "zzz") post.update(tag_string: "zzz")
end end
end end

View File

@@ -19,8 +19,8 @@ class PostVersionTest < ActiveSupport::TestCase
setup do setup do
PostArchive.sqs_service.stubs(:merge?).returns(false) PostArchive.sqs_service.stubs(:merge?).returns(false)
@post = FactoryBot.create(:post, :tag_string => "1") @post = FactoryBot.create(:post, :tag_string => "1")
@post.update_attributes(:tag_string => "1 2") @post.update(tag_string: "1 2")
@post.update_attributes(:tag_string => "2 3") @post.update(tag_string: "2 3")
end end
context "a version record" do context "a version record" do
@@ -59,7 +59,7 @@ class PostVersionTest < ActiveSupport::TestCase
should "delete the previous version" do should "delete the previous version" do
assert_equal(1, @post.versions.count) 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 @post.reload
assert_equal(1, @post.versions.count) assert_equal(1, @post.versions.count)
end end
@@ -71,7 +71,7 @@ class PostVersionTest < ActiveSupport::TestCase
travel_to(1.minute.ago) do travel_to(1.minute.ago) do
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz") @post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
end end
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "") @post.update(tag_string: "bbb ccc xxx", source: "")
end end
should "also create a version" do 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 should "not change the password if the password and old password are blank" do
@user = FactoryBot.create(:user, :password => "67890") @user = FactoryBot.create(:user, :password => "67890")
@user.update_attributes(:password => "", :old_password => "") @user.update(password: "", old_password: "")
assert(@user.bcrypt_password == User.sha1("67890")) assert(@user.bcrypt_password == User.sha1("67890"))
end end
should "not change the password if the old password is incorrect" do should "not change the password if the old password is incorrect" do
@user = FactoryBot.create(:user, :password => "67890") @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")) assert(@user.bcrypt_password == User.sha1("67890"))
end end
should "not change the password if the old password is blank" do should "not change the password if the old password is blank" do
@user = FactoryBot.create(:user, :password => "67890") @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")) assert(@user.bcrypt_password == User.sha1("67890"))
end end
should "change the password if the old password is correct" do should "change the password if the old password is correct" do
@user = FactoryBot.create(:user, :password => "67890") @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")) assert(@user.bcrypt_password == User.sha1("12345"))
end end

View File

@@ -16,7 +16,7 @@ class WikiPageTest < ActiveSupport::TestCase
CurrentUser.user = FactoryBot.create(:moderator_user) CurrentUser.user = FactoryBot.create(:moderator_user)
@wiki_page = FactoryBot.create(:wiki_page, :is_locked => true) @wiki_page = FactoryBot.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryBot.create(:user) 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) assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
end end
@@ -24,7 +24,7 @@ class WikiPageTest < ActiveSupport::TestCase
CurrentUser.user = FactoryBot.create(:moderator_user) CurrentUser.user = FactoryBot.create(:moderator_user)
@wiki_page = FactoryBot.create(:wiki_page, :is_locked => true) @wiki_page = FactoryBot.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryBot.create(:moderator_user) CurrentUser.user = FactoryBot.create(:moderator_user)
@wiki_page.update_attributes(:body => "hello") @wiki_page.update(body: "hello")
assert_equal([], @wiki_page.errors.full_messages) assert_equal([], @wiki_page.errors.full_messages)
end end
end end
@@ -37,7 +37,7 @@ class WikiPageTest < ActiveSupport::TestCase
end end
should "allow the is_locked attribute to be updated" do 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 @wiki_page.reload
assert_equal(true, @wiki_page.is_locked?) assert_equal(true, @wiki_page.is_locked?)
end end
@@ -51,7 +51,7 @@ class WikiPageTest < ActiveSupport::TestCase
end end
should "not allow the is_locked attribute to be updated" do 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) assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
@wiki_page.reload @wiki_page.reload
assert_equal(false, @wiki_page.is_locked?) assert_equal(false, @wiki_page.is_locked?)