about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-04-21 12:07:17 -0400
committerEugen <eugen@zeonfederated.com>2017-04-21 18:07:17 +0200
commitee0c897bba7c332ee3077db7605c9c3781cb4cb1 (patch)
treea622b385f6509a533f68156452230763637f3723 /spec/models
parentceecf962081b858f40978829041bfc2b282ddcae (diff)
User settings mutation (#2270)
* Add user spec for settings, highlight global default mutation issue

* Fix mutation issue caused by settings/preferences spec
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/user_spec.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 4ed1d5a0a..846a206ec 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -24,6 +24,37 @@ RSpec.describe User, type: :model do
     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 'recent' do
       it 'returns an array of recent users ordered by id' do