User settings mutation (#2270)
* Add user spec for settings, highlight global default mutation issue * Fix mutation issue caused by settings/preferences spec
This commit is contained in:
parent
ceecf96208
commit
ee0c897bba
|
@ -24,8 +24,8 @@ describe Settings::PreferencesController do
|
||||||
|
|
||||||
it 'updates user settings' do
|
it 'updates user settings' do
|
||||||
user.settings['boost_modal'] = false
|
user.settings['boost_modal'] = false
|
||||||
user.settings['notification_emails']['follow'] = false
|
user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
|
||||||
user.settings['interactions']['must_be_follower'] = true
|
user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
|
||||||
|
|
||||||
put :update, params: {
|
put :update, params: {
|
||||||
user: {
|
user: {
|
||||||
|
|
|
@ -24,6 +24,37 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'settings' do
|
||||||
|
it 'inherits default settings from default yml' do
|
||||||
|
expect(Setting.boost_modal).to eq false
|
||||||
|
expect(Setting.interactions['must_be_follower']).to eq false
|
||||||
|
|
||||||
|
user = User.new
|
||||||
|
expect(user.settings.boost_modal).to eq false
|
||||||
|
expect(user.settings.interactions['must_be_follower']).to eq false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can update settings' do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
expect(user.settings['interactions']['must_be_follower']).to eq false
|
||||||
|
user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
|
||||||
|
user.reload
|
||||||
|
|
||||||
|
expect(user.settings['interactions']['must_be_follower']).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
xit 'does not mutate defaults via the cache' do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
user.settings['interactions']['must_be_follower'] = true
|
||||||
|
# TODO
|
||||||
|
# This mutates the global settings default such that future user
|
||||||
|
# instances will inherit the incorrect starting values
|
||||||
|
|
||||||
|
other = Fabricate(:user)
|
||||||
|
expect(other.settings['interactions']['must_be_follower']).to eq false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'scopes' do
|
describe 'scopes' do
|
||||||
describe 'recent' do
|
describe 'recent' do
|
||||||
it 'returns an array of recent users ordered by id' do
|
it 'returns an array of recent users ordered by id' do
|
||||||
|
|
Loading…
Reference in New Issue