DEV: remove update_attributes which is deprecated in Rails 6
See: https://github.com/rails/rails/pull/31998 update_attributes is a relic of the past, it should no longer be used.
This commit is contained in:
parent
3b95f34e7b
commit
45285f1477
|
@ -32,7 +32,7 @@ class Admin::ScreenedIpAddressesController < Admin::AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
if @screened_ip_address.update_attributes(allowed_params)
|
||||
if @screened_ip_address.update(allowed_params)
|
||||
render_serialized(@screened_ip_address, ScreenedIpAddressSerializer)
|
||||
else
|
||||
render_json_error(@screened_ip_address)
|
||||
|
|
|
@ -42,7 +42,7 @@ class Admin::WebHooksController < Admin::AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
if @web_hook.update_attributes(web_hook_params)
|
||||
if @web_hook.update(web_hook_params)
|
||||
StaffActionLogger.new(current_user).log_web_hook(@web_hook, UserHistory.actions[:web_hook_update], changes: @web_hook.saved_changes)
|
||||
render_serialized(@web_hook, AdminWebHookSerializer, root: 'web_hook')
|
||||
else
|
||||
|
@ -92,7 +92,7 @@ class Admin::WebHooksController < Admin::AdminController
|
|||
|
||||
now = Time.zone.now
|
||||
response = conn.post(headers: MultiJson.load(web_hook_event.headers), body: web_hook_event.payload)
|
||||
web_hook_event.update_attributes!(status: response.status,
|
||||
web_hook_event.update!(status: response.status,
|
||||
response_headers: MultiJson.dump(response.headers),
|
||||
response_body: response.body,
|
||||
duration: ((Time.zone.now - now) * 1000).to_i)
|
||||
|
|
|
@ -45,7 +45,7 @@ class BadgesController < ApplicationController
|
|||
if current_user
|
||||
user_badge = UserBadge.find_by(user_id: current_user.id, badge_id: @badge.id)
|
||||
if user_badge && user_badge.notification
|
||||
user_badge.notification.update_attributes read: true
|
||||
user_badge.notification.update read: true
|
||||
end
|
||||
if user_badge
|
||||
@badge.has_badge = true
|
||||
|
|
|
@ -175,7 +175,7 @@ class CategoriesController < ApplicationController
|
|||
|
||||
custom_slug = params[:slug].to_s
|
||||
|
||||
if custom_slug.present? && @category.update_attributes(slug: custom_slug)
|
||||
if custom_slug.present? && @category.update(slug: custom_slug)
|
||||
render json: success_json
|
||||
else
|
||||
render_json_error(@category)
|
||||
|
|
|
@ -7,7 +7,7 @@ module Jobs
|
|||
begin
|
||||
URI.parse(featured_link)
|
||||
rescue URI::Error
|
||||
topic.update_attributes(featured_link: URI.extract(featured_link).first)
|
||||
topic.update(featured_link: URI.extract(featured_link).first)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -518,7 +518,7 @@ class Category < ActiveRecord::Base
|
|||
.pluck("topics.id")
|
||||
.first
|
||||
|
||||
self.update_attributes(latest_topic_id: latest_topic_id, latest_post_id: latest_post_id)
|
||||
self.update(latest_topic_id: latest_topic_id, latest_post_id: latest_post_id)
|
||||
end
|
||||
|
||||
def self.query_parent_category(parent_slug)
|
||||
|
|
|
@ -520,8 +520,8 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def unhide!
|
||||
self.update_attributes(hidden: false)
|
||||
self.topic.update_attributes(visible: true) if is_first_post?
|
||||
self.update(hidden: false)
|
||||
self.topic.update(visible: true) if is_first_post?
|
||||
save(validate: false)
|
||||
publish_change_to_clients!(:acted)
|
||||
end
|
||||
|
|
|
@ -761,7 +761,7 @@ class Topic < ActiveRecord::Base
|
|||
increment!(:moderator_posts_count) if new_post.persisted?
|
||||
# If we are moving posts, we want to insert the moderator post where the previous posts were
|
||||
# in the stream, not at the end.
|
||||
new_post.update_attributes!(post_number: opts[:post_number], sort_order: opts[:post_number]) if opts[:post_number].present?
|
||||
new_post.update!(post_number: opts[:post_number], sort_order: opts[:post_number]) if opts[:post_number].present?
|
||||
|
||||
# Grab any links that are present
|
||||
TopicLink.extract_from(new_post)
|
||||
|
|
|
@ -53,7 +53,7 @@ class BadgeGranter
|
|||
badge_title: @badge.allow_title,
|
||||
username: @user.username }.to_json
|
||||
)
|
||||
user_badge.update_attributes notification_id: notification.id
|
||||
user_badge.update notification_id: notification.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ class ColorSchemeRevisor
|
|||
if has_colors
|
||||
@params[:colors].each do |c|
|
||||
if existing = @color_scheme.colors_by_name[c[:name]]
|
||||
existing.update_attributes(c)
|
||||
existing.update(c)
|
||||
else
|
||||
@color_scheme.color_scheme_colors << ColorSchemeColor.new(name: c[:name], hex: c[:hex])
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ class TopicTimestampChanger
|
|||
end
|
||||
|
||||
def update_topic(last_posted_at)
|
||||
@topic.update_attributes(
|
||||
@topic.update(
|
||||
created_at: @timestamp,
|
||||
updated_at: @timestamp,
|
||||
bumped_at: @timestamp,
|
||||
|
@ -52,6 +52,6 @@ class TopicTimestampChanger
|
|||
end
|
||||
|
||||
def update_post(post, timestamp)
|
||||
post.update_attributes(created_at: timestamp, updated_at: timestamp)
|
||||
post.update(created_at: timestamp, updated_at: timestamp)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -354,7 +354,7 @@ class UserMerger
|
|||
|
||||
def delete_source_user
|
||||
@source_user.reload
|
||||
@source_user.update_attributes(
|
||||
@source_user.update(
|
||||
admin: false,
|
||||
email: "#{@source_user.username}_#{SecureRandom.hex}@no-email.invalid"
|
||||
)
|
||||
|
|
|
@ -125,7 +125,7 @@ module Email
|
|||
end
|
||||
|
||||
def set_incoming_email_rejection_message(incoming_email, message)
|
||||
incoming_email.update_attributes!(rejection_message: message) if incoming_email
|
||||
incoming_email.update!(rejection_message: message) if incoming_email
|
||||
end
|
||||
|
||||
def log_email_process_failure(mail_string, exception)
|
||||
|
|
|
@ -515,7 +515,7 @@ class PostCreator
|
|||
|
||||
@user.user_stat.save!
|
||||
|
||||
@user.update_attributes(last_posted_at: @post.created_at)
|
||||
@user.update(last_posted_at: @post.created_at)
|
||||
end
|
||||
|
||||
def create_post_notice
|
||||
|
|
|
@ -111,7 +111,7 @@ class PostDestroyer
|
|||
counts = Post.where(post_type: Post.types[:regular], topic_id: @post.topic_id).where('post_number > 1').group(:user_id).count
|
||||
counts.each do |user_id, count|
|
||||
if user_stat = UserStat.where(user_id: user_id).first
|
||||
user_stat.update_attributes(post_count: user_stat.post_count + count)
|
||||
user_stat.update(post_count: user_stat.post_count + count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -347,7 +347,7 @@ class PostDestroyer
|
|||
counts = Post.where(post_type: Post.types[:regular], topic_id: @post.topic_id).where('post_number > 1').group(:user_id).count
|
||||
counts.each do |user_id, count|
|
||||
if user_stat = UserStat.where(user_id: user_id).first
|
||||
user_stat.update_attributes(post_count: user_stat.post_count - count)
|
||||
user_stat.update(post_count: user_stat.post_count - count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,8 +24,8 @@ describe CategoryHashtag do
|
|||
end
|
||||
|
||||
it "should be case sensitive" do
|
||||
parent_category.update_attributes!(slug: "ApPlE")
|
||||
child_category.update_attributes!(slug: "OraNGE")
|
||||
parent_category.update!(slug: "ApPlE")
|
||||
child_category.update!(slug: "OraNGE")
|
||||
|
||||
expect(Category.query_from_hashtag_slug("apple")).to eq(nil)
|
||||
expect(Category.query_from_hashtag_slug("apple#{CategoryHashtag::SEPARATOR}orange")).to eq(nil)
|
||||
|
|
|
@ -583,7 +583,7 @@ describe CookedPostProcessor do
|
|||
end
|
||||
|
||||
it "should escape the filename" do
|
||||
upload.update_attributes!(original_filename: "><img src=x onerror=alert('haha')>.png")
|
||||
upload.update!(original_filename: "><img src=x onerror=alert('haha')>.png")
|
||||
cpp.post_process_images
|
||||
cpp.optimize_urls
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ describe FileStore::S3Store do
|
|||
it "removes the file from s3 with the right paths" do
|
||||
store.expects(:get_depth_for).with(upload.id).returns(0)
|
||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||
upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/original/1X/#{upload.sha1}.png")
|
||||
upload.update!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/original/1X/#{upload.sha1}.png")
|
||||
s3_object = stub
|
||||
|
||||
s3_bucket.expects(:object).with("tombstone/original/1X/#{upload.sha1}.png").returns(s3_object)
|
||||
|
@ -164,7 +164,7 @@ describe FileStore::S3Store do
|
|||
|
||||
store.expects(:get_depth_for).with(upload.id).returns(0)
|
||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||
optimized.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/#{path}")
|
||||
optimized.update!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/#{path}")
|
||||
s3_object = stub
|
||||
|
||||
s3_bucket.expects(:object).with("tombstone/#{path}").returns(s3_object)
|
||||
|
@ -183,7 +183,7 @@ describe FileStore::S3Store do
|
|||
it "removes the file from s3 with the right paths" do
|
||||
store.expects(:get_depth_for).with(upload.id).returns(0)
|
||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||
upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/original/1X/#{upload.sha1}.png")
|
||||
upload.update!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/original/1X/#{upload.sha1}.png")
|
||||
s3_object = stub
|
||||
|
||||
s3_bucket.expects(:object).with("discourse-uploads/tombstone/original/1X/#{upload.sha1}.png").returns(s3_object)
|
||||
|
|
|
@ -309,7 +309,7 @@ describe Plugin::Instance do
|
|||
|
||||
expect(called).to eq(1)
|
||||
|
||||
user.update_attributes!(username: 'some_username')
|
||||
user.update!(username: 'some_username')
|
||||
|
||||
expect(called).to eq(1)
|
||||
end
|
||||
|
@ -325,7 +325,7 @@ describe Plugin::Instance do
|
|||
|
||||
expect(called).to eq(1)
|
||||
|
||||
user.update_attributes!(username: 'some_username')
|
||||
user.update!(username: 'some_username')
|
||||
|
||||
expect(called).to eq(1)
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ describe PostMerger do
|
|||
end
|
||||
|
||||
it "should not allow the first post in a topic to be merged" do
|
||||
post.update_attributes!(user: user)
|
||||
post.update!(user: user)
|
||||
reply1 = create_post(topic: topic, post_number: post.post_number, user: user)
|
||||
reply2 = create_post(topic: topic, post_number: post.post_number, user: user)
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ describe Search do
|
|||
end
|
||||
|
||||
it "works for unlisted topics" do
|
||||
topic.update_attributes(visible: false)
|
||||
topic.update(visible: false)
|
||||
_post = new_post('discourse is awesome', topic)
|
||||
results = Search.execute('discourse', search_context: topic)
|
||||
expect(results.posts.length).to eq(1)
|
||||
|
|
|
@ -150,12 +150,12 @@ describe Stylesheet::Manager do
|
|||
|
||||
digest1 = manager.color_scheme_digest
|
||||
|
||||
category2.update_attributes(uploaded_background_id: 789, updated_at: 1.day.ago)
|
||||
category2.update(uploaded_background_id: 789, updated_at: 1.day.ago)
|
||||
|
||||
digest2 = manager.color_scheme_digest
|
||||
expect(digest2).to_not eq(digest1)
|
||||
|
||||
category1.update_attributes(uploaded_background_id: nil, updated_at: 5.minutes.ago)
|
||||
category1.update(uploaded_background_id: nil, updated_at: 5.minutes.ago)
|
||||
|
||||
digest3 = manager.color_scheme_digest
|
||||
expect(digest3).to_not eq(digest2)
|
||||
|
|
|
@ -433,19 +433,19 @@ describe TopicQuery do
|
|||
|
||||
describe "category default sort order" do
|
||||
it "can use category's default sort order" do
|
||||
category.update_attributes!(sort_order: 'created', sort_ascending: true)
|
||||
category.update!(sort_order: 'created', sort_ascending: true)
|
||||
topic_ids = TopicQuery.new(user, category: category.id).list_latest.topics.map(&:id)
|
||||
expect(topic_ids - [topic_category.id]).to eq([topic_in_cat1.id, topic_in_cat2.id])
|
||||
end
|
||||
|
||||
it "ignores invalid order value" do
|
||||
category.update_attributes!(sort_order: 'funny')
|
||||
category.update!(sort_order: 'funny')
|
||||
topic_ids = TopicQuery.new(user, category: category.id).list_latest.topics.map(&:id)
|
||||
expect(topic_ids - [topic_category.id]).to eq([topic_in_cat2.id, topic_in_cat1.id])
|
||||
end
|
||||
|
||||
it "can be overridden" do
|
||||
category.update_attributes!(sort_order: 'created', sort_ascending: true)
|
||||
category.update!(sort_order: 'created', sort_ascending: true)
|
||||
topic_ids = TopicQuery.new(user, category: category.id, order: 'activity').list_latest.topics.map(&:id)
|
||||
expect(topic_ids - [topic_category.id]).to eq([topic_in_cat2.id, topic_in_cat1.id])
|
||||
end
|
||||
|
|
|
@ -634,7 +634,7 @@ describe TopicView do
|
|||
context "categorized topic" do
|
||||
let(:category) { Fabricate(:category) }
|
||||
|
||||
before { topic.update_attributes(category_id: category.id) }
|
||||
before { topic.update(category_id: category.id) }
|
||||
|
||||
context "topic_page_title_includes_category is false" do
|
||||
before { SiteSetting.topic_page_title_includes_category = false }
|
||||
|
|
|
@ -73,7 +73,7 @@ describe "category tag restrictions" do
|
|||
|
||||
context 'category allows other tags to be used' do
|
||||
before do
|
||||
category_with_tags.update_attributes!(allow_global_tags: true)
|
||||
category_with_tags.update!(allow_global_tags: true)
|
||||
end
|
||||
|
||||
it "search can show the permitted tags" do
|
||||
|
@ -88,7 +88,7 @@ describe "category tag restrictions" do
|
|||
end
|
||||
|
||||
it "works if no tags are restricted to the category" do
|
||||
other_category.update_attributes!(allow_global_tags: true)
|
||||
other_category.update!(allow_global_tags: true)
|
||||
expect(filter_allowed_tags(for_input: true, category: other_category)).to contain_exactly(tag3, tag4)
|
||||
expect(filter_allowed_tags(for_input: true, category: other_category, selected_tags: [tag3.name])).to contain_exactly(tag4)
|
||||
expect(filter_allowed_tags(for_input: true, category: other_category, selected_tags: [tag3.name], term: 'tag')).to contain_exactly(tag4)
|
||||
|
@ -133,7 +133,7 @@ describe "category tag restrictions" do
|
|||
|
||||
context 'category allows other tags to be used' do
|
||||
before do
|
||||
category.update_attributes!(allow_global_tags: true)
|
||||
category.update!(allow_global_tags: true)
|
||||
end
|
||||
|
||||
it 'filters tags correctly' do
|
||||
|
@ -148,7 +148,7 @@ describe "category tag restrictions" do
|
|||
end
|
||||
|
||||
it "works if no tags are restricted to the category" do
|
||||
other_category.update_attributes!(allow_global_tags: true)
|
||||
other_category.update!(allow_global_tags: true)
|
||||
expect(filter_allowed_tags(for_input: true, category: other_category)).to contain_exactly(tag3, tag4)
|
||||
tag_group1.tags = [tag2, tag3, tag4]
|
||||
expect(filter_allowed_tags(for_input: true, category: other_category)).to contain_exactly(tag1)
|
||||
|
@ -258,9 +258,9 @@ describe "category tag restrictions" do
|
|||
|
||||
context "limit one tag from each group" do
|
||||
before do
|
||||
makes.update_attributes(one_per_topic: true)
|
||||
honda_group.update_attributes(one_per_topic: true)
|
||||
ford_group.update_attributes(one_per_topic: true)
|
||||
makes.update(one_per_topic: true)
|
||||
honda_group.update(one_per_topic: true)
|
||||
ford_group.update(one_per_topic: true)
|
||||
end
|
||||
|
||||
it "can restrict one tag from each group" do
|
||||
|
|
|
@ -154,7 +154,7 @@ describe Jobs::CleanUpUploads do
|
|||
|
||||
it "does not delete profile background uploads" do
|
||||
profile_background_upload = fabricate_upload
|
||||
UserProfile.last.update_attributes!(profile_background: profile_background_upload.url)
|
||||
UserProfile.last.update!(profile_background: profile_background_upload.url)
|
||||
|
||||
Jobs::CleanUpUploads.new.execute(nil)
|
||||
|
||||
|
@ -164,7 +164,7 @@ describe Jobs::CleanUpUploads do
|
|||
|
||||
it "does not delete card background uploads" do
|
||||
card_background_upload = fabricate_upload
|
||||
UserProfile.last.update_attributes!(card_background: card_background_upload.url)
|
||||
UserProfile.last.update!(card_background: card_background_upload.url)
|
||||
|
||||
Jobs::CleanUpUploads.new.execute(nil)
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@ describe Jobs::EnqueueDigestEmails do
|
|||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
|
||||
# As an admin
|
||||
unapproved_user.update_attributes(admin: true, moderator: false)
|
||||
unapproved_user.update(admin: true, moderator: false)
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
|
||||
# As an approved user
|
||||
unapproved_user.update_attributes(admin: false, moderator: false, approved: true)
|
||||
unapproved_user.update(admin: false, moderator: false, approved: true)
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ describe Jobs::ReindexSearch do
|
|||
model = Fabricate(m.to_sym)
|
||||
# so that search data can be reindexed
|
||||
search_data = model.send("#{m}_search_data")
|
||||
search_data.update_attributes!(version: 0)
|
||||
search_data.update!(version: 0)
|
||||
model.reload
|
||||
|
||||
subject.execute({})
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Jobs::Tl3Promotions do
|
|||
|
||||
def create_qualifying_stats(user)
|
||||
user.create_user_stat if user.user_stat.nil?
|
||||
user.user_stat.update_attributes!(
|
||||
user.user_stat.update!(
|
||||
days_visited: 1000,
|
||||
topic_reply_count: 1000,
|
||||
topics_entered: 1000,
|
||||
|
|
|
@ -34,14 +34,14 @@ describe Jobs::UserEmail do
|
|||
end
|
||||
|
||||
it "doesn't call the mailer when the user is staged" do
|
||||
staged.update_attributes!(last_seen_at: 8.days.ago, last_emailed_at: 8.days.ago)
|
||||
staged.update!(last_seen_at: 8.days.ago, last_emailed_at: 8.days.ago)
|
||||
Jobs::UserEmail.new.execute(type: :digest, user_id: staged.id)
|
||||
expect(ActionMailer::Base.deliveries).to eq([])
|
||||
end
|
||||
|
||||
context 'not emailed recently' do
|
||||
before do
|
||||
user.update_attributes!(last_emailed_at: 8.days.ago)
|
||||
user.update!(last_emailed_at: 8.days.ago)
|
||||
end
|
||||
|
||||
it "calls the mailer when the user exists" do
|
||||
|
@ -52,8 +52,8 @@ describe Jobs::UserEmail do
|
|||
|
||||
context 'recently emailed' do
|
||||
before do
|
||||
user.update_attributes!(last_emailed_at: 2.hours.ago)
|
||||
user.user_option.update_attributes!(digest_after_minutes: 1.day.to_i / 60)
|
||||
user.update!(last_emailed_at: 2.hours.ago)
|
||||
user.user_option.update!(digest_after_minutes: 1.day.to_i / 60)
|
||||
end
|
||||
|
||||
it 'skips sending digest email' do
|
||||
|
@ -129,7 +129,7 @@ describe Jobs::UserEmail do
|
|||
end
|
||||
|
||||
it "does send an email to a user that's been recently seen but has email_level set to always" do
|
||||
user.user_option.update_attributes(email_level: UserOption.email_level_types[:always])
|
||||
user.user_option.update(email_level: UserOption.email_level_types[:always])
|
||||
PostTiming.create!(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id, msecs: 100)
|
||||
|
||||
Jobs::UserEmail.new.execute(
|
||||
|
@ -158,16 +158,16 @@ describe Jobs::UserEmail do
|
|||
end
|
||||
|
||||
it "doesn't send a PM email to a user that's been recently seen and has email_messages_level set to never" do
|
||||
user.user_option.update_attributes(email_messages_level: UserOption.email_level_types[:never])
|
||||
user.user_option.update_attributes(email_level: UserOption.email_level_types[:always])
|
||||
user.user_option.update(email_messages_level: UserOption.email_level_types[:never])
|
||||
user.user_option.update(email_level: UserOption.email_level_types[:always])
|
||||
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id)
|
||||
|
||||
expect(ActionMailer::Base.deliveries).to eq([])
|
||||
end
|
||||
|
||||
it "doesn't send a regular post email to a user that's been recently seen and has email_level set to never" do
|
||||
user.user_option.update_attributes(email_messages_level: UserOption.email_level_types[:always])
|
||||
user.user_option.update_attributes(email_level: UserOption.email_level_types[:never])
|
||||
user.user_option.update(email_messages_level: UserOption.email_level_types[:always])
|
||||
user.user_option.update(email_level: UserOption.email_level_types[:never])
|
||||
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
||||
|
||||
expect(ActionMailer::Base.deliveries).to eq([])
|
||||
|
@ -248,7 +248,7 @@ describe Jobs::UserEmail do
|
|||
end
|
||||
|
||||
it "doesn't send the email if user of the post has been deleted" do
|
||||
post.update_attributes!(user_id: nil)
|
||||
post.update!(user_id: nil)
|
||||
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
||||
|
||||
expect(ActionMailer::Base.deliveries).to eq([])
|
||||
|
|
|
@ -311,31 +311,31 @@ describe Category do
|
|||
end
|
||||
|
||||
it "renames the definition when renamed" do
|
||||
@category.update_attributes(name: 'Troutfishing')
|
||||
@category.update(name: 'Troutfishing')
|
||||
@topic.reload
|
||||
expect(@topic.title).to match(/Troutfishing/)
|
||||
expect(@topic.fancy_title).to match(/Troutfishing/)
|
||||
end
|
||||
|
||||
it "doesn't raise an error if there is no definition topic to rename (uncategorized)" do
|
||||
expect { @category.update_attributes(name: 'Troutfishing', topic_id: nil) }.to_not raise_error
|
||||
expect { @category.update(name: 'Troutfishing', topic_id: nil) }.to_not raise_error
|
||||
end
|
||||
|
||||
it "creates permalink when category slug is changed" do
|
||||
@category.update_attributes(slug: 'new-category')
|
||||
@category.update(slug: 'new-category')
|
||||
expect(Permalink.count).to eq(1)
|
||||
end
|
||||
|
||||
it "reuses existing permalink when category slug is changed" do
|
||||
permalink = Permalink.create!(url: "c/#{@category.slug}", category_id: 42)
|
||||
|
||||
expect { @category.update_attributes(slug: 'new-slug') }.to_not change { Permalink.count }
|
||||
expect { @category.update(slug: 'new-slug') }.to_not change { Permalink.count }
|
||||
expect(permalink.reload.category_id).to eq(@category.id)
|
||||
end
|
||||
|
||||
it "creates permalink when sub category slug is changed" do
|
||||
sub_category = Fabricate(:category, slug: 'sub-category', parent_category_id: @category.id)
|
||||
sub_category.update_attributes(slug: 'new-sub-category')
|
||||
sub_category.update(slug: 'new-sub-category')
|
||||
expect(Permalink.count).to eq(1)
|
||||
end
|
||||
|
||||
|
@ -356,7 +356,7 @@ describe Category do
|
|||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
old_url = @category.url
|
||||
@category.update_attributes(slug: 'new-category')
|
||||
@category.update(slug: 'new-category')
|
||||
permalink = Permalink.last
|
||||
expect(permalink.url).to eq(old_url[1..-1])
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ RSpec.describe GroupHistory do
|
|||
end
|
||||
|
||||
it 'should filter by subject correctly' do
|
||||
other_group_history.update_attributes!(subject: "test")
|
||||
other_group_history.update!(subject: "test")
|
||||
|
||||
expect(described_class.with_filters(
|
||||
group_history.group,
|
||||
|
@ -35,8 +35,8 @@ RSpec.describe GroupHistory do
|
|||
end
|
||||
|
||||
it 'should filter by multiple filters correctly' do
|
||||
group_history.update_attributes!(action: GroupHistory.actions[:remove_user_from_group])
|
||||
other_group_history.update_attributes!(subject: "test")
|
||||
group_history.update!(action: GroupHistory.actions[:remove_user_from_group])
|
||||
other_group_history.update!(subject: "test")
|
||||
|
||||
expect(described_class.with_filters(group_history.group,
|
||||
action: GroupHistory.actions[3], subject: 'test'
|
||||
|
|
|
@ -617,7 +617,7 @@ describe Group do
|
|||
|
||||
it 'should cook the bio' do
|
||||
group = Fabricate(:group)
|
||||
group.update_attributes!(bio_raw: 'This is a group for :unicorn: lovers')
|
||||
group.update!(bio_raw: 'This is a group for :unicorn: lovers')
|
||||
|
||||
expect(group.bio_cooked).to include("unicorn.png")
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ describe PostReply do
|
|||
expect(PostReply.new(post: post, reply: other_post)).to be_valid
|
||||
|
||||
other_topic = Fabricate(:topic)
|
||||
other_post.update_attributes!(topic_id: other_topic.id)
|
||||
other_post.update!(topic_id: other_topic.id)
|
||||
other_post.reload
|
||||
|
||||
post_reply = PostReply.new(post: post, reply: other_post)
|
||||
|
|
|
@ -28,7 +28,7 @@ describe UserSearch do
|
|||
Fabricate :post, user: user6, topic: topic
|
||||
Fabricate :post, user: staged, topic: topic4
|
||||
|
||||
user6.update_attributes(suspended_at: 1.day.ago, suspended_till: 1.year.from_now)
|
||||
user6.update(suspended_at: 1.day.ago, suspended_till: 1.year.from_now)
|
||||
end
|
||||
|
||||
def search_for(*args)
|
||||
|
|
|
@ -1633,14 +1633,14 @@ describe User do
|
|||
|
||||
describe 'when first notification has been seen' do
|
||||
it 'should return the right value' do
|
||||
user.update_attributes!(seen_notification_id: notification.id)
|
||||
user.update!(seen_notification_id: notification.id)
|
||||
expect(user.reload.read_first_notification?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when user is trust level 1' do
|
||||
it 'should return the right value' do
|
||||
user.update_attributes!(trust_level: TrustLevel[1])
|
||||
user.update!(trust_level: TrustLevel[1])
|
||||
|
||||
expect(user.read_first_notification?).to eq(false)
|
||||
end
|
||||
|
@ -1648,7 +1648,7 @@ describe User do
|
|||
|
||||
describe 'when user is trust level 2' do
|
||||
it 'should return the right value' do
|
||||
user.update_attributes!(trust_level: TrustLevel[2])
|
||||
user.update!(trust_level: TrustLevel[2])
|
||||
|
||||
expect(user.read_first_notification?).to eq(true)
|
||||
end
|
||||
|
@ -1656,7 +1656,7 @@ describe User do
|
|||
|
||||
describe 'when user is an old user' do
|
||||
it 'should return the right value' do
|
||||
user.update_attributes!(first_seen_at: 1.year.ago)
|
||||
user.update!(first_seen_at: 1.year.ago)
|
||||
|
||||
expect(user.read_first_notification?).to eq(true)
|
||||
end
|
||||
|
|
|
@ -63,7 +63,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do
|
|||
upload = build_upload
|
||||
store.expects(:get_depth_for).with(upload.id).returns(0)
|
||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||
upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/uploads/default/original/1X/#{upload.sha1}.png")
|
||||
upload.update!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/uploads/default/original/1X/#{upload.sha1}.png")
|
||||
s3_object = stub
|
||||
|
||||
s3_bucket.expects(:object).with("uploads/tombstone/default/original/1X/#{upload.sha1}.png").returns(s3_object)
|
||||
|
@ -80,7 +80,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do
|
|||
upload = build_upload
|
||||
store.expects(:get_depth_for).with(upload.id).returns(0)
|
||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||
upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/uploads/second/original/1X/#{upload.sha1}.png")
|
||||
upload.update!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/uploads/second/original/1X/#{upload.sha1}.png")
|
||||
s3_object = stub
|
||||
|
||||
s3_bucket.expects(:object).with("uploads/tombstone/second/original/1X/#{upload.sha1}.png").returns(s3_object)
|
||||
|
@ -102,7 +102,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do
|
|||
upload = build_upload
|
||||
store.expects(:get_depth_for).with(upload.id).returns(0)
|
||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||
upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/uploads/default/original/1X/#{upload.sha1}.png")
|
||||
upload.update!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/uploads/default/original/1X/#{upload.sha1}.png")
|
||||
s3_object = stub
|
||||
|
||||
s3_bucket.expects(:object).with("discourse-uploads/uploads/tombstone/default/original/1X/#{upload.sha1}.png").returns(s3_object)
|
||||
|
|
|
@ -346,7 +346,7 @@ RSpec.describe Admin::UsersController do
|
|||
stat.posts_read_count = SiteSetting.tl1_requires_read_posts + 1
|
||||
stat.time_read = SiteSetting.tl1_requires_time_spent_mins * 60
|
||||
stat.save!
|
||||
another_user.update_attributes(trust_level: TrustLevel[1])
|
||||
another_user.update(trust_level: TrustLevel[1])
|
||||
|
||||
put "/admin/users/#{another_user.id}/trust_level.json", params: {
|
||||
level: TrustLevel[0]
|
||||
|
|
|
@ -430,7 +430,7 @@ describe GroupsController do
|
|||
response_body = JSON.parse(response.body)
|
||||
expect(response_body["mentionable"]).to eq(false)
|
||||
|
||||
group.update_attributes!(
|
||||
group.update!(
|
||||
mentionable_level: Group::ALIAS_LEVELS[:everyone],
|
||||
visibility_level: Group.visibility_levels[:staff]
|
||||
)
|
||||
|
@ -561,7 +561,7 @@ describe GroupsController do
|
|||
|
||||
context "when user is group admin" do
|
||||
before do
|
||||
user.update_attributes!(admin: true)
|
||||
user.update!(admin: true)
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
|
@ -804,7 +804,7 @@ describe GroupsController do
|
|||
|
||||
context 'public group' do
|
||||
it 'should be fobidden' do
|
||||
group.update_attributes!(
|
||||
group.update!(
|
||||
public_admission: true,
|
||||
public_exit: true
|
||||
)
|
||||
|
@ -1184,7 +1184,7 @@ describe GroupsController do
|
|||
|
||||
describe 'when viewing a public group' do
|
||||
before do
|
||||
group.update_attributes!(
|
||||
group.update!(
|
||||
public_admission: true,
|
||||
public_exit: true
|
||||
)
|
||||
|
|
|
@ -26,7 +26,7 @@ describe InvitesController do
|
|||
end
|
||||
|
||||
it "returns error if invite has already been redeemed" do
|
||||
invite.update_attributes!(redeemed_at: 1.day.ago)
|
||||
invite.update!(redeemed_at: 1.day.ago)
|
||||
get "/invites/#{invite.invite_key}"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
|
|
@ -416,7 +416,7 @@ RSpec.describe ListController do
|
|||
|
||||
describe "category default views" do
|
||||
it "has a top default view" do
|
||||
category.update_attributes!(default_view: 'top', default_top_period: 'monthly')
|
||||
category.update!(default_view: 'top', default_top_period: 'monthly')
|
||||
get "/c/#{category.slug}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
@ -424,7 +424,7 @@ RSpec.describe ListController do
|
|||
end
|
||||
|
||||
it "has a default view of nil" do
|
||||
category.update_attributes!(default_view: nil)
|
||||
category.update!(default_view: nil)
|
||||
get "/c/#{category.slug}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
@ -432,7 +432,7 @@ RSpec.describe ListController do
|
|||
end
|
||||
|
||||
it "has a default view of ''" do
|
||||
category.update_attributes!(default_view: '')
|
||||
category.update!(default_view: '')
|
||||
get "/c/#{category.slug}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
@ -440,7 +440,7 @@ RSpec.describe ListController do
|
|||
end
|
||||
|
||||
it "has a default view of latest" do
|
||||
category.update_attributes!(default_view: 'latest')
|
||||
category.update!(default_view: 'latest')
|
||||
get "/c/#{category.slug}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
|
|
@ -9,7 +9,7 @@ describe ThemeJavascriptsController do
|
|||
describe '#show' do
|
||||
def update_digest_and_get(digest)
|
||||
# actually set digest to make sure 404 is raised by router
|
||||
javascript_cache.update_attributes(digest: digest)
|
||||
javascript_cache.update(digest: digest)
|
||||
|
||||
get "/theme-javascripts/#{digest}.js"
|
||||
end
|
||||
|
|
|
@ -1668,7 +1668,7 @@ describe UsersController do
|
|||
put "/u/#{user.username}/preferences/badge_title.json", params: { user_badge_id: user_badge.id }
|
||||
|
||||
expect(user.reload.title).not_to eq(badge.display_name)
|
||||
badge.update_attributes allow_title: true
|
||||
badge.update allow_title: true
|
||||
|
||||
put "/u/#{user.username}/preferences/badge_title.json", params: { user_badge_id: user_badge.id }
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ describe BadgeGranter do
|
|||
action = PostActionCreator.like(liker, post).post_action
|
||||
|
||||
# Nice post badge
|
||||
post.update_attributes like_count: 10
|
||||
post.update like_count: 10
|
||||
|
||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
||||
BadgeGranter.process_queue!
|
||||
|
@ -275,19 +275,19 @@ describe BadgeGranter do
|
|||
expect(UserBadge.where(user_id: user.id, badge_id: Badge::NicePost).count).to eq(1)
|
||||
|
||||
# Good post badge
|
||||
post.update_attributes like_count: 25
|
||||
post.update like_count: 25
|
||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
||||
BadgeGranter.process_queue!
|
||||
expect(UserBadge.find_by(user_id: user.id, badge_id: Badge::GoodPost)).not_to eq(nil)
|
||||
|
||||
# Great post badge
|
||||
post.update_attributes like_count: 50
|
||||
post.update like_count: 50
|
||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
||||
BadgeGranter.process_queue!
|
||||
expect(UserBadge.find_by(user_id: user.id, badge_id: Badge::GreatPost)).not_to eq(nil)
|
||||
|
||||
# Revoke badges on unlike
|
||||
post.update_attributes like_count: 49
|
||||
post.update like_count: 49
|
||||
BadgeGranter.backfill(Badge.find(Badge::GreatPost))
|
||||
expect(UserBadge.find_by(user_id: user.id, badge_id: Badge::GreatPost)).to eq(nil)
|
||||
end
|
||||
|
|
|
@ -119,7 +119,7 @@ RSpec.describe GroupActionLogger do
|
|||
|
||||
describe '#log_change_group_settings' do
|
||||
it 'should create the right record' do
|
||||
group.update_attributes!(public_admission: true, created_at: Time.zone.now)
|
||||
group.update!(public_admission: true, created_at: Time.zone.now)
|
||||
|
||||
expect { subject.log_change_group_settings }.to change { GroupHistory.count }.by(1)
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ describe SearchIndexer do
|
|||
it 'correctly indexes a post according to version' do
|
||||
# Preparing so that they can be indexed to right version
|
||||
SearchIndexer.update_posts_index(post_id, "dummy", "", nil, nil)
|
||||
PostSearchData.find_by(post_id: post_id).update_attributes!(version: -1)
|
||||
PostSearchData.find_by(post_id: post_id).update!(version: -1)
|
||||
|
||||
data = "<a>This</a> is a test"
|
||||
SearchIndexer.update_posts_index(post_id, "", "", nil, data)
|
||||
|
|
|
@ -72,10 +72,10 @@ describe UserAnonymizer do
|
|||
end
|
||||
|
||||
it "resets profile to default values" do
|
||||
user.update_attributes(name: "Bibi", date_of_birth: 19.years.ago, title: "Super Star")
|
||||
user.update(name: "Bibi", date_of_birth: 19.years.ago, title: "Super Star")
|
||||
|
||||
profile = user.reload.user_profile
|
||||
profile.update_attributes(location: "Moose Jaw",
|
||||
profile.update(location: "Moose Jaw",
|
||||
website: "www.bim.com",
|
||||
bio_raw: "I'm Bibi from Moosejaw. I sing and dance.",
|
||||
bio_cooked: "I'm Bibi from Moosejaw. I sing and dance.",
|
||||
|
@ -114,7 +114,7 @@ describe UserAnonymizer do
|
|||
it "changes name to anonymized username" do
|
||||
prev_username = user.username
|
||||
|
||||
user.update_attributes(name: "Bibi", date_of_birth: 19.years.ago, title: "Super Star")
|
||||
user.update(name: "Bibi", date_of_birth: 19.years.ago, title: "Super Star")
|
||||
|
||||
make_anonymous
|
||||
user.reload
|
||||
|
|
|
@ -258,7 +258,7 @@ describe UserUpdater do
|
|||
|
||||
context 'badge can be used as a title' do
|
||||
before do
|
||||
badge.update_attributes(allow_title: true)
|
||||
badge.update(allow_title: true)
|
||||
end
|
||||
|
||||
it 'can use as title, sets badge_granted_title' do
|
||||
|
@ -270,7 +270,7 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it 'badge has not been granted, does not change title' do
|
||||
badge.update_attributes(allow_title: true)
|
||||
badge.update(allow_title: true)
|
||||
updater = UserUpdater.new(user, user)
|
||||
updater.update(title: badge.name)
|
||||
user.reload
|
||||
|
@ -279,8 +279,8 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it 'changing to a title that is not from a badge, unsets badge_granted_title' do
|
||||
user.update_attributes(title: badge.name)
|
||||
user.user_profile.update_attributes(badge_granted_title: true)
|
||||
user.update(title: badge.name)
|
||||
user.user_profile.update(badge_granted_title: true)
|
||||
|
||||
guardian = stub
|
||||
guardian.stubs(:can_grant_title?).with(user, 'Dancer').returns(true)
|
||||
|
|
|
@ -45,7 +45,7 @@ RSpec.describe "Post rake tasks" do
|
|||
|
||||
describe 'rebake_match' do
|
||||
it 'rebakes matched posts' do
|
||||
post.update_attributes(cooked: '')
|
||||
post.update(cooked: '')
|
||||
|
||||
HighLine::Simulate.with('y') do
|
||||
Rake::Task['posts:rebake_match'].invoke('brown')
|
||||
|
|
Loading…
Reference in New Issue