2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-11-01 17:06:20 -04:00
|
|
|
|
|
|
|
describe UserUpdater do
|
2013-12-10 12:46:35 -05:00
|
|
|
|
|
|
|
let(:acting_user) { Fabricate.build(:user) }
|
|
|
|
|
2015-03-30 19:16:11 -04:00
|
|
|
describe '#update_muted_users' do
|
|
|
|
it 'has no cross talk' do
|
|
|
|
u1 = Fabricate(:user)
|
|
|
|
u2 = Fabricate(:user)
|
|
|
|
u3 = Fabricate(:user)
|
|
|
|
|
|
|
|
updater = UserUpdater.new(u1, u1)
|
|
|
|
updater.update_muted_users("#{u2.username},#{u3.username}")
|
|
|
|
|
|
|
|
updater = UserUpdater.new(u2, u2)
|
|
|
|
updater.update_muted_users("#{u3.username},#{u1.username}")
|
|
|
|
|
|
|
|
updater = UserUpdater.new(u3, u3)
|
|
|
|
updater.update_muted_users("")
|
|
|
|
|
2019-03-20 15:55:46 -04:00
|
|
|
expect(MutedUser.where(user_id: u2.id).pluck(:muted_user_id)).to match_array([u3.id, u1.id])
|
|
|
|
expect(MutedUser.where(user_id: u1.id).pluck(:muted_user_id)).to match_array([u2.id, u3.id])
|
|
|
|
expect(MutedUser.where(user_id: u3.id).count).to eq(0)
|
2019-03-06 06:21:58 -05:00
|
|
|
end
|
2019-03-20 06:18:46 -04:00
|
|
|
|
|
|
|
it 'excludes acting user' do
|
|
|
|
u1 = Fabricate(:user)
|
|
|
|
u2 = Fabricate(:user)
|
|
|
|
updater = UserUpdater.new(u1, u1)
|
|
|
|
updater.update_muted_users("#{u1.username},#{u2.username}")
|
|
|
|
|
2019-03-20 15:55:46 -04:00
|
|
|
expect(MutedUser.where(muted_user_id: u2.id).pluck(:muted_user_id)).to match_array([u2.id])
|
2019-03-20 06:18:46 -04:00
|
|
|
end
|
2019-03-06 06:21:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update_ignored_users' do
|
|
|
|
it 'updates ignored users' do
|
2019-03-20 10:02:34 -04:00
|
|
|
u1 = Fabricate(:user, trust_level: 2)
|
|
|
|
u2 = Fabricate(:user, trust_level: 2)
|
|
|
|
u3 = Fabricate(:user, trust_level: 2)
|
2019-03-06 06:21:58 -05:00
|
|
|
|
|
|
|
updater = UserUpdater.new(u1, u1)
|
|
|
|
updater.update_ignored_users("#{u2.username},#{u3.username}")
|
|
|
|
|
|
|
|
updater = UserUpdater.new(u2, u2)
|
|
|
|
updater.update_ignored_users("#{u3.username},#{u1.username}")
|
|
|
|
|
|
|
|
updater = UserUpdater.new(u3, u3)
|
|
|
|
updater.update_ignored_users("")
|
2015-03-30 19:16:11 -04:00
|
|
|
|
2019-03-20 15:55:46 -04:00
|
|
|
expect(IgnoredUser.where(user_id: u2.id).pluck(:ignored_user_id)).to match_array([u3.id, u1.id])
|
|
|
|
expect(IgnoredUser.where(user_id: u1.id).pluck(:ignored_user_id)).to match_array([u2.id, u3.id])
|
|
|
|
expect(IgnoredUser.where(user_id: u3.id).count).to eq(0)
|
2015-03-30 19:16:11 -04:00
|
|
|
end
|
2019-03-20 06:18:46 -04:00
|
|
|
|
|
|
|
it 'excludes acting user' do
|
2019-03-20 10:02:34 -04:00
|
|
|
u1 = Fabricate(:user, trust_level: 2)
|
2019-03-20 06:18:46 -04:00
|
|
|
u2 = Fabricate(:user)
|
|
|
|
updater = UserUpdater.new(u1, u1)
|
|
|
|
updater.update_ignored_users("#{u1.username},#{u2.username}")
|
|
|
|
|
2019-03-20 15:55:46 -04:00
|
|
|
expect(IgnoredUser.where(user_id: u1.id).pluck(:ignored_user_id)).to match_array([u2.id])
|
2019-03-20 06:18:46 -04:00
|
|
|
end
|
2019-03-20 10:02:34 -04:00
|
|
|
|
|
|
|
context 'when acting user\'s trust level is below tl2' do
|
|
|
|
it 'excludes acting user' do
|
|
|
|
u1 = Fabricate(:user, trust_level: 1)
|
|
|
|
u2 = Fabricate(:user)
|
|
|
|
updater = UserUpdater.new(u1, u1)
|
|
|
|
updater.update_ignored_users("#{u2.username}")
|
|
|
|
|
2019-03-20 15:55:46 -04:00
|
|
|
expect(IgnoredUser.where(ignored_user_id: u2.id).count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when acting user is admin' do
|
|
|
|
it 'excludes acting user' do
|
|
|
|
u1 = Fabricate(:admin)
|
|
|
|
u2 = Fabricate(:user)
|
|
|
|
updater = UserUpdater.new(u1, u1)
|
|
|
|
updater.update_ignored_users("#{u1.username},#{u2.username}")
|
|
|
|
|
|
|
|
expect(IgnoredUser.where(user_id: u1.id).pluck(:ignored_user_id)).to match_array([u2.id])
|
2019-03-20 10:02:34 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-30 19:16:11 -04:00
|
|
|
end
|
|
|
|
|
2013-11-01 17:06:20 -04:00
|
|
|
describe '#update' do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:category) { Fabricate(:category) }
|
|
|
|
fab!(:tag) { Fabricate(:tag) }
|
|
|
|
fab!(:tag2) { Fabricate(:tag) }
|
2018-03-29 15:08:22 -04:00
|
|
|
|
2013-11-01 17:06:20 -04:00
|
|
|
it 'saves user' do
|
|
|
|
user = Fabricate(:user, name: 'Billy Bob')
|
2016-02-16 23:46:19 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
|
|
|
updater.update(name: 'Jim Tom')
|
|
|
|
|
|
|
|
expect(user.reload.name).to eq 'Jim Tom'
|
|
|
|
end
|
|
|
|
|
2016-07-07 22:58:18 -04:00
|
|
|
it 'can update categories and tags' do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2018-03-29 15:08:22 -04:00
|
|
|
updater.update(watched_tags: "#{tag.name},#{tag2.name}", muted_category_ids: [category.id])
|
2016-07-07 22:58:18 -04:00
|
|
|
|
|
|
|
expect(TagUser.where(
|
|
|
|
user_id: user.id,
|
|
|
|
tag_id: tag.id,
|
|
|
|
notification_level: TagUser.notification_levels[:watching]
|
2018-03-29 15:08:22 -04:00
|
|
|
).exists?).to eq(true)
|
|
|
|
|
|
|
|
expect(TagUser.where(
|
|
|
|
user_id: user.id,
|
|
|
|
tag_id: tag2.id,
|
|
|
|
notification_level: TagUser.notification_levels[:watching]
|
|
|
|
).exists?).to eq(true)
|
2016-07-07 22:58:18 -04:00
|
|
|
|
|
|
|
expect(CategoryUser.where(
|
|
|
|
user_id: user.id,
|
|
|
|
category_id: category.id,
|
|
|
|
notification_level: CategoryUser.notification_levels[:muted]
|
|
|
|
).count).to eq(1)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-03-29 15:08:22 -04:00
|
|
|
it "doesn't remove notification prefs when updating something else" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
TagUser.create!(user: user, tag: tag, notification_level: TagUser.notification_levels[:watching])
|
|
|
|
CategoryUser.create!(user: user, category: category, notification_level: CategoryUser.notification_levels[:muted])
|
|
|
|
|
|
|
|
updater = UserUpdater.new(acting_user, user)
|
|
|
|
updater.update(name: "Steve Dave")
|
|
|
|
|
|
|
|
expect(TagUser.where(user: user).count).to eq(1)
|
|
|
|
expect(CategoryUser.where(user: user).count).to eq(1)
|
|
|
|
end
|
|
|
|
|
2016-02-16 23:46:19 -05:00
|
|
|
it 'updates various fields' do
|
2014-06-10 01:19:08 -04:00
|
|
|
user = Fabricate(:user)
|
2016-02-16 23:46:19 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2016-11-15 03:10:20 -05:00
|
|
|
date_of_birth = Time.zone.now
|
2016-02-16 23:46:19 -05:00
|
|
|
|
2018-08-08 00:46:34 -04:00
|
|
|
theme = Fabricate(:theme, user_selectable: true)
|
2019-04-28 23:58:52 -04:00
|
|
|
upload1 = Fabricate(:upload)
|
|
|
|
upload2 = Fabricate(:upload)
|
2017-05-15 12:48:08 -04:00
|
|
|
|
|
|
|
seq = user.user_option.theme_key_seq
|
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
val = updater.update(
|
|
|
|
bio_raw: 'my new bio',
|
|
|
|
email_level: UserOption.email_level_types[:always],
|
|
|
|
mailing_list_mode: true,
|
|
|
|
digest_after_minutes: "45",
|
|
|
|
new_topic_duration_minutes: 100,
|
|
|
|
auto_track_topics_after_msecs: 101,
|
|
|
|
notification_level_when_replying: 3,
|
|
|
|
email_in_reply_to: false,
|
|
|
|
date_of_birth: date_of_birth,
|
|
|
|
theme_ids: [theme.id],
|
|
|
|
allow_private_messages: false,
|
|
|
|
card_background_upload_url: upload1.url,
|
|
|
|
profile_background_upload_url: upload2.url
|
|
|
|
)
|
2017-10-06 03:56:58 -04:00
|
|
|
|
2016-08-01 01:29:28 -04:00
|
|
|
expect(val).to be_truthy
|
|
|
|
|
2016-02-16 23:46:19 -05:00
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.user_profile.bio_raw).to eq 'my new bio'
|
2019-03-15 10:55:11 -04:00
|
|
|
expect(user.user_option.email_level).to eq UserOption.email_level_types[:always]
|
2016-02-16 23:46:19 -05:00
|
|
|
expect(user.user_option.mailing_list_mode).to eq true
|
2016-03-02 15:26:27 -05:00
|
|
|
expect(user.user_option.digest_after_minutes).to eq 45
|
2016-02-18 00:57:22 -05:00
|
|
|
expect(user.user_option.new_topic_duration_minutes).to eq 100
|
|
|
|
expect(user.user_option.auto_track_topics_after_msecs).to eq 101
|
2016-09-30 12:36:43 -04:00
|
|
|
expect(user.user_option.notification_level_when_replying).to eq 3
|
2016-02-25 08:05:40 -05:00
|
|
|
expect(user.user_option.email_in_reply_to).to eq false
|
2018-07-12 00:18:21 -04:00
|
|
|
expect(user.user_option.theme_ids.first).to eq theme.id
|
2017-07-27 21:20:09 -04:00
|
|
|
expect(user.user_option.theme_key_seq).to eq(seq + 1)
|
2017-10-06 03:56:58 -04:00
|
|
|
expect(user.user_option.allow_private_messages).to eq(false)
|
2016-11-15 03:10:20 -05:00
|
|
|
expect(user.date_of_birth).to eq(date_of_birth.to_date)
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.card_background_upload).to eq(upload1)
|
|
|
|
expect(user.profile_background_upload).to eq(upload2)
|
2019-05-02 04:53:17 -04:00
|
|
|
|
|
|
|
success = updater.update(
|
|
|
|
profile_background_upload_url: "",
|
|
|
|
card_background_upload_url: ""
|
|
|
|
)
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(success).to eq(true)
|
|
|
|
expect(user.card_background_upload).to eq(nil)
|
|
|
|
expect(user.profile_background_upload).to eq(nil)
|
2014-06-10 01:19:08 -04:00
|
|
|
end
|
|
|
|
|
2016-11-28 09:52:35 -05:00
|
|
|
it "disables email_digests when enabling mailing_list_mode" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
updater = UserUpdater.new(acting_user, user)
|
|
|
|
|
|
|
|
val = updater.update(mailing_list_mode: true, email_digests: true)
|
|
|
|
expect(val).to be_truthy
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.user_option.email_digests).to eq false
|
|
|
|
expect(user.user_option.mailing_list_mode).to eq true
|
|
|
|
end
|
|
|
|
|
2018-08-10 07:12:02 -04:00
|
|
|
it "filters theme_ids blank values before updating perferences" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
user.user_option.update!(theme_ids: [1])
|
|
|
|
updater = UserUpdater.new(acting_user, user)
|
|
|
|
|
|
|
|
updater.update(theme_ids: [""])
|
|
|
|
user.reload
|
|
|
|
expect(user.user_option.theme_ids).to eq([])
|
|
|
|
|
|
|
|
updater.update(theme_ids: [nil])
|
|
|
|
user.reload
|
|
|
|
expect(user.user_option.theme_ids).to eq([])
|
|
|
|
|
|
|
|
theme = Fabricate(:theme)
|
2018-08-23 21:30:00 -04:00
|
|
|
child = Fabricate(:theme, component: true)
|
2018-08-10 07:12:02 -04:00
|
|
|
theme.add_child_theme!(child)
|
|
|
|
theme.set_default!
|
|
|
|
|
|
|
|
updater.update(theme_ids: [theme.id.to_s, child.id.to_s, "", nil])
|
|
|
|
user.reload
|
|
|
|
expect(user.user_option.theme_ids).to eq([theme.id, child.id])
|
|
|
|
end
|
|
|
|
|
2016-08-01 01:29:28 -04:00
|
|
|
context 'when sso overrides bio' do
|
|
|
|
it 'does not change bio' do
|
2017-12-23 03:46:48 -05:00
|
|
|
SiteSetting.sso_url = "https://www.example.com/sso"
|
2016-08-01 01:29:28 -04:00
|
|
|
SiteSetting.enable_sso = true
|
|
|
|
SiteSetting.sso_overrides_bio = true
|
|
|
|
|
2013-11-01 17:06:20 -04:00
|
|
|
user = Fabricate(:user)
|
2016-02-16 23:46:19 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
2016-08-01 01:29:28 -04:00
|
|
|
expect(updater.update(bio_raw: "new bio")).to be_truthy
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.user_profile.bio_raw).not_to eq 'new bio'
|
2013-11-01 17:06:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when update fails' do
|
|
|
|
it 'returns false' do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
user.stubs(save: false)
|
2016-02-16 23:46:19 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
2014-09-25 11:44:48 -04:00
|
|
|
expect(updater.update).to be_falsey
|
2013-11-01 17:06:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with permission to update title' do
|
|
|
|
it 'allows user to change title' do
|
|
|
|
user = Fabricate(:user, title: 'Emperor')
|
|
|
|
guardian = stub
|
2018-04-26 16:50:50 -04:00
|
|
|
guardian.stubs(:can_grant_title?).with(user, 'Minion').returns(true)
|
2013-12-10 12:46:35 -05:00
|
|
|
Guardian.stubs(:new).with(acting_user).returns(guardian)
|
2016-02-16 23:46:19 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
|
|
|
updater.update(title: 'Minion')
|
|
|
|
|
|
|
|
expect(user.reload.title).to eq 'Minion'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-26 16:50:50 -04:00
|
|
|
context 'title is from a badge' do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:user, title: 'Emperor') }
|
|
|
|
fab!(:badge) { Fabricate(:badge, name: 'Minion') }
|
2018-04-26 16:50:50 -04:00
|
|
|
|
|
|
|
context 'badge can be used as a title' do
|
|
|
|
before do
|
2019-04-29 03:32:25 -04:00
|
|
|
badge.update(allow_title: true)
|
2018-04-26 16:50:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can use as title, sets badge_granted_title' do
|
|
|
|
BadgeGranter.grant(badge, user)
|
|
|
|
updater = UserUpdater.new(user, user)
|
|
|
|
updater.update(title: badge.name)
|
|
|
|
user.reload
|
|
|
|
expect(user.user_profile.badge_granted_title).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'badge has not been granted, does not change title' do
|
2019-04-29 03:32:25 -04:00
|
|
|
badge.update(allow_title: true)
|
2018-04-26 16:50:50 -04:00
|
|
|
updater = UserUpdater.new(user, user)
|
|
|
|
updater.update(title: badge.name)
|
|
|
|
user.reload
|
|
|
|
expect(user.title).not_to eq(badge.name)
|
|
|
|
expect(user.user_profile.badge_granted_title).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'changing to a title that is not from a badge, unsets badge_granted_title' do
|
2019-04-29 03:32:25 -04:00
|
|
|
user.update(title: badge.name)
|
|
|
|
user.user_profile.update(badge_granted_title: true)
|
2018-04-26 16:50:50 -04:00
|
|
|
|
|
|
|
guardian = stub
|
|
|
|
guardian.stubs(:can_grant_title?).with(user, 'Dancer').returns(true)
|
|
|
|
Guardian.stubs(:new).with(user).returns(guardian)
|
|
|
|
|
|
|
|
updater = UserUpdater.new(user, user)
|
|
|
|
updater.update(title: 'Dancer')
|
|
|
|
user.reload
|
|
|
|
expect(user.title).to eq('Dancer')
|
|
|
|
expect(user.user_profile.badge_granted_title).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot use as title, does not change title' do
|
|
|
|
BadgeGranter.grant(badge, user)
|
|
|
|
updater = UserUpdater.new(user, user)
|
|
|
|
updater.update(title: badge.name)
|
|
|
|
user.reload
|
|
|
|
expect(user.title).not_to eq(badge.name)
|
|
|
|
expect(user.user_profile.badge_granted_title).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-01 17:06:20 -04:00
|
|
|
context 'without permission to update title' do
|
|
|
|
it 'does not allow user to change title' do
|
|
|
|
user = Fabricate(:user, title: 'Emperor')
|
|
|
|
guardian = stub
|
2018-04-26 16:50:50 -04:00
|
|
|
guardian.stubs(:can_grant_title?).with(user, 'Minion').returns(false)
|
2013-12-10 12:46:35 -05:00
|
|
|
Guardian.stubs(:new).with(acting_user).returns(guardian)
|
2017-02-27 15:02:00 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
|
|
|
updater.update(title: 'Minion')
|
|
|
|
|
|
|
|
expect(user.reload.title).not_to eq 'Minion'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when website includes http' do
|
|
|
|
it 'does not add http before updating' do
|
|
|
|
user = Fabricate(:user)
|
2017-02-27 15:02:00 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
|
|
|
updater.update(website: 'http://example.com')
|
|
|
|
|
2014-06-07 00:54:32 -04:00
|
|
|
expect(user.reload.user_profile.website).to eq 'http://example.com'
|
2013-11-01 17:06:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when website does not include http' do
|
|
|
|
it 'adds http before updating' do
|
|
|
|
user = Fabricate(:user)
|
2017-02-27 15:02:00 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2013-11-01 17:06:20 -04:00
|
|
|
|
|
|
|
updater.update(website: 'example.com')
|
|
|
|
|
2014-06-07 00:54:32 -04:00
|
|
|
expect(user.reload.user_profile.website).to eq 'http://example.com'
|
2013-11-01 17:06:20 -04:00
|
|
|
end
|
|
|
|
end
|
2014-09-17 13:09:39 -04:00
|
|
|
|
|
|
|
context 'when custom_fields is empty string' do
|
|
|
|
it "update is successful" do
|
|
|
|
user = Fabricate(:user)
|
2017-07-27 21:20:09 -04:00
|
|
|
user.custom_fields = { 'import_username' => 'my_old_username' }
|
2014-09-17 13:09:39 -04:00
|
|
|
user.save
|
2017-02-27 15:02:00 -05:00
|
|
|
updater = UserUpdater.new(acting_user, user)
|
2014-09-17 13:09:39 -04:00
|
|
|
|
|
|
|
updater.update(website: 'example.com', custom_fields: '')
|
2017-07-27 21:20:09 -04:00
|
|
|
expect(user.reload.custom_fields).to eq('import_username' => 'my_old_username')
|
2014-09-17 13:09:39 -04:00
|
|
|
end
|
|
|
|
end
|
2017-02-23 00:48:57 -05:00
|
|
|
|
|
|
|
it "logs the action" do
|
2017-03-01 03:12:17 -05:00
|
|
|
user_without_name = Fabricate(:user, name: nil)
|
2017-02-23 00:48:57 -05:00
|
|
|
user = Fabricate(:user, name: 'Billy Bob')
|
2018-11-21 21:10:07 -05:00
|
|
|
|
2017-10-22 23:16:14 -04:00
|
|
|
expect do
|
|
|
|
UserUpdater.new(acting_user, user).update(name: 'Jim Tom')
|
|
|
|
end.to change { UserHistory.count }.by(1)
|
|
|
|
|
2018-11-21 21:10:07 -05:00
|
|
|
expect(UserHistory.last.action).to eq(
|
|
|
|
UserHistory.actions[:change_name]
|
|
|
|
)
|
|
|
|
|
2017-10-22 23:16:14 -04:00
|
|
|
expect do
|
|
|
|
UserUpdater.new(acting_user, user).update(name: 'JiM TOm')
|
|
|
|
end.to_not change { UserHistory.count }
|
|
|
|
|
2018-11-30 05:00:34 -05:00
|
|
|
expect do
|
|
|
|
UserUpdater.new(acting_user, user).update(bio_raw: 'foo bar')
|
|
|
|
end.to_not change { UserHistory.count }
|
|
|
|
|
2017-10-22 23:16:14 -04:00
|
|
|
expect do
|
|
|
|
UserUpdater.new(acting_user, user_without_name).update(bio_raw: 'foo bar')
|
|
|
|
end.to_not change { UserHistory.count }
|
|
|
|
|
|
|
|
expect do
|
|
|
|
UserUpdater.new(acting_user, user_without_name).update(name: 'Jim Tom')
|
|
|
|
end.to change { UserHistory.count }.by(1)
|
|
|
|
|
2018-11-21 21:10:07 -05:00
|
|
|
expect(UserHistory.last.action).to eq(
|
|
|
|
UserHistory.actions[:change_name]
|
|
|
|
)
|
|
|
|
|
2017-10-22 23:16:14 -04:00
|
|
|
expect do
|
|
|
|
UserUpdater.new(acting_user, user).update(name: '')
|
|
|
|
end.to change { UserHistory.count }.by(1)
|
2018-11-21 21:10:07 -05:00
|
|
|
|
|
|
|
expect(UserHistory.last.action).to eq(
|
|
|
|
UserHistory.actions[:change_name]
|
|
|
|
)
|
2017-02-23 00:48:57 -05:00
|
|
|
end
|
2013-11-01 17:06:20 -04:00
|
|
|
end
|
|
|
|
end
|