ledermann-rails-settings 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +13 -6
- data/MIT-LICENSE +1 -1
- data/README.md +1 -1
- data/ci/Gemfile-rails-3-1 +3 -4
- data/ci/Gemfile-rails-3-2 +3 -4
- data/ci/Gemfile-rails-4-0 +5 -5
- data/ci/Gemfile-rails-4-1 +5 -5
- data/ci/Gemfile-rails-4-2 +7 -0
- data/lib/generators/rails_settings/migration/templates/migration.rb +1 -1
- data/lib/rails-settings/base.rb +1 -1
- data/lib/rails-settings/setting_object.rb +3 -16
- data/lib/rails-settings/version.rb +1 -1
- data/rails-settings.gemspec +0 -1
- data/spec/configuration_spec.rb +14 -14
- data/spec/database.yml +0 -5
- data/spec/queries_spec.rb +0 -7
- data/spec/scopes_spec.rb +6 -6
- data/spec/serialize_spec.rb +8 -8
- data/spec/setting_object_spec.rb +34 -34
- data/spec/settings_spec.rb +51 -51
- data/spec/spec_helper.rb +3 -3
- data/spec/support/matchers/perform_queries.rb +5 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b32592febac17831f730dd18e33ef0af56c1251
|
4
|
+
data.tar.gz: 6c4c04520451889bf5ad7ca407d53530415aa7e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71033242a7e5ff5cc1d6c1da91fc968aae2df1513e83678cd7fb7d199b71fa6f42b4354dd35cfaa8c70671a552adff2041cb7cb65920878b61e42ba0e83f9398
|
7
|
+
data.tar.gz: dcb7360d13a853702e90efe91329ae3db9c052c8c4062164b68a170a9d97411fc8136c8ced228fad2d30bde7e871c36c257d456cb67bfb579b90ba93b8d738c8
|
data/.travis.yml
CHANGED
@@ -2,15 +2,22 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
-
- 2.1.
|
5
|
+
- 2.1.5
|
6
|
+
- 2.2.1
|
6
7
|
gemfile:
|
7
8
|
- ci/Gemfile-rails-3-1
|
8
9
|
- ci/Gemfile-rails-3-2
|
9
10
|
- ci/Gemfile-rails-4-0
|
10
11
|
- ci/Gemfile-rails-4-1
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
- ci/Gemfile-rails-4-2
|
13
|
+
matrix:
|
14
|
+
include:
|
15
|
+
- rvm: 2.2.1
|
16
|
+
gemfile: ci/Gemfile-rails-4-2
|
17
|
+
env: PROTECTED_ATTRIBUTES=true
|
18
|
+
exclude:
|
19
|
+
- rvm: 2.2.1
|
20
|
+
gemfile: ci/Gemfile-rails-3-1
|
21
|
+
- rvm: 2.2.1
|
22
|
+
gemfile: ci/Gemfile-rails-3-2
|
16
23
|
before_install: gem update bundler
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -140,6 +140,6 @@ See https://github.com/ledermann/rails-settings/releases
|
|
140
140
|
|
141
141
|
MIT License
|
142
142
|
|
143
|
-
Copyright (c)
|
143
|
+
Copyright (c) 2012-2015 [Georg Ledermann](http://www.georg-ledermann.de)
|
144
144
|
|
145
145
|
This gem is a complete rewrite of [rails-settings](https://github.com/Squeegy/rails-settings) by [Alex Wayne](https://github.com/Squeegy)
|
data/ci/Gemfile-rails-3-1
CHANGED
data/ci/Gemfile-rails-3-2
CHANGED
data/ci/Gemfile-rails-4-0
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 4.0.
|
4
|
-
gem '
|
5
|
-
gem '
|
6
|
-
gem 'rake'
|
7
|
-
gem 'rspec'
|
3
|
+
gem 'activerecord', '~> 4.0.13'
|
4
|
+
gem 'protected_attributes' if ENV['PROTECTED_ATTRIBUTES'] == 'true'
|
5
|
+
gem 'sqlite3'
|
6
|
+
gem 'rake'
|
7
|
+
gem 'rspec'
|
data/ci/Gemfile-rails-4-1
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 4.1.
|
4
|
-
gem '
|
5
|
-
gem '
|
6
|
-
gem 'rake'
|
7
|
-
gem 'rspec'
|
3
|
+
gem 'activerecord', '~> 4.1.10'
|
4
|
+
gem 'protected_attributes' if ENV['PROTECTED_ATTRIBUTES'] == 'true'
|
5
|
+
gem 'sqlite3'
|
6
|
+
gem 'rake'
|
7
|
+
gem 'rspec'
|
@@ -4,7 +4,7 @@ class RailsSettingsMigration < ActiveRecord::Migration
|
|
4
4
|
t.string :var, :null => false
|
5
5
|
t.text :value
|
6
6
|
t.references :target, :null => false, :polymorphic => true
|
7
|
-
t.timestamps
|
7
|
+
t.timestamps :null => true
|
8
8
|
end
|
9
9
|
add_index :settings, [ :target_type, :target_id, :var ], :unique => true
|
10
10
|
end
|
data/lib/rails-settings/base.rb
CHANGED
@@ -12,7 +12,7 @@ module RailsSettings
|
|
12
12
|
raise ArgumentError unless var.is_a?(Symbol)
|
13
13
|
raise ArgumentError.new("Unknown key: #{var}") unless self.class.default_settings[var]
|
14
14
|
|
15
|
-
if
|
15
|
+
if defined?(ProtectedAttributes)
|
16
16
|
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build({ :var => var.to_s }, :without_protection => true)
|
17
17
|
else
|
18
18
|
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build(:var => var.to_s, :target => self)
|
@@ -15,9 +15,9 @@ module RailsSettings
|
|
15
15
|
|
16
16
|
serialize :value, Hash
|
17
17
|
|
18
|
-
# attr_protected can not be here
|
18
|
+
# attr_protected can not be used here because it touches the database which is not connected yet.
|
19
19
|
# So allow no attributes and override <tt>#sanitize_for_mass_assignment</tt>
|
20
|
-
if
|
20
|
+
if defined?(ProtectedAttributes)
|
21
21
|
attr_accessible
|
22
22
|
end
|
23
23
|
|
@@ -45,7 +45,7 @@ module RailsSettings
|
|
45
45
|
end
|
46
46
|
|
47
47
|
protected
|
48
|
-
if
|
48
|
+
if defined?(ProtectedAttributes)
|
49
49
|
# Simulate attr_protected by removing all regular attributes
|
50
50
|
def sanitize_for_mass_assignment(attributes, role = nil)
|
51
51
|
attributes.except('id', 'var', 'value', 'target_id', 'target_type', 'created_at', 'updated_at')
|
@@ -76,18 +76,5 @@ module RailsSettings
|
|
76
76
|
def _target_class
|
77
77
|
target_type.constantize
|
78
78
|
end
|
79
|
-
|
80
|
-
# Patch ActiveRecord to save serialized attributes only if they are changed
|
81
|
-
if ActiveRecord::VERSION::MAJOR < 4
|
82
|
-
# https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L70
|
83
|
-
def update(*)
|
84
|
-
super(changed) if changed?
|
85
|
-
end
|
86
|
-
else
|
87
|
-
# https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L73
|
88
|
-
def update_record(*)
|
89
|
-
super(keys_for_partial_write) if changed?
|
90
|
-
end
|
91
|
-
end
|
92
79
|
end
|
93
80
|
end
|
data/rails-settings.gemspec
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -8,28 +8,28 @@ module RailsSettings
|
|
8
8
|
it "should define single key" do
|
9
9
|
Configuration.new(Dummy, :dashboard)
|
10
10
|
|
11
|
-
Dummy.default_settings.
|
12
|
-
Dummy.setting_object_class_name.
|
11
|
+
expect(Dummy.default_settings).to eq({ :dashboard => {} })
|
12
|
+
expect(Dummy.setting_object_class_name).to eq('RailsSettings::SettingObject')
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should define multiple keys" do
|
16
16
|
Configuration.new(Dummy, :dashboard, :calendar)
|
17
17
|
|
18
|
-
Dummy.default_settings.
|
19
|
-
Dummy.setting_object_class_name.
|
18
|
+
expect(Dummy.default_settings).to eq({ :dashboard => {}, :calendar => {} })
|
19
|
+
expect(Dummy.setting_object_class_name).to eq('RailsSettings::SettingObject')
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should define single key with class_name" do
|
23
23
|
Configuration.new(Dummy, :dashboard, :class_name => 'MyClass')
|
24
|
-
Dummy.default_settings.
|
25
|
-
Dummy.setting_object_class_name.
|
24
|
+
expect(Dummy.default_settings).to eq({ :dashboard => {} })
|
25
|
+
expect(Dummy.setting_object_class_name).to eq('MyClass')
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should define multiple keys with class_name" do
|
29
29
|
Configuration.new(Dummy, :dashboard, :calendar, :class_name => 'MyClass')
|
30
30
|
|
31
|
-
Dummy.default_settings.
|
32
|
-
Dummy.setting_object_class_name.
|
31
|
+
expect(Dummy.default_settings).to eq({ :dashboard => {}, :calendar => {} })
|
32
|
+
expect(Dummy.setting_object_class_name).to eq('MyClass')
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should define using block" do
|
@@ -38,8 +38,8 @@ module RailsSettings
|
|
38
38
|
c.key :calendar
|
39
39
|
end
|
40
40
|
|
41
|
-
Dummy.default_settings.
|
42
|
-
Dummy.setting_object_class_name.
|
41
|
+
expect(Dummy.default_settings).to eq({ :dashboard => {}, :calendar => {} })
|
42
|
+
expect(Dummy.setting_object_class_name).to eq('RailsSettings::SettingObject')
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should define using block with defaults" do
|
@@ -48,8 +48,8 @@ module RailsSettings
|
|
48
48
|
c.key :calendar, :defaults => { :scope => 'all' }
|
49
49
|
end
|
50
50
|
|
51
|
-
Dummy.default_settings.
|
52
|
-
Dummy.setting_object_class_name.
|
51
|
+
expect(Dummy.default_settings).to eq({ :dashboard => { 'theme' => 'red' }, :calendar => { 'scope' => 'all'} })
|
52
|
+
expect(Dummy.setting_object_class_name).to eq('RailsSettings::SettingObject')
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should define using block and class_name" do
|
@@ -58,8 +58,8 @@ module RailsSettings
|
|
58
58
|
c.key :calendar
|
59
59
|
end
|
60
60
|
|
61
|
-
Dummy.default_settings.
|
62
|
-
Dummy.setting_object_class_name.
|
61
|
+
expect(Dummy.default_settings).to eq({ :dashboard => {}, :calendar => {} })
|
62
|
+
expect(Dummy.setting_object_class_name).to eq('MyClass')
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
data/spec/database.yml
CHANGED
data/spec/queries_spec.rb
CHANGED
@@ -97,12 +97,5 @@ describe 'Queries performed' do
|
|
97
97
|
user.settings(:dashboard).update_attributes! :foo => 'bar'
|
98
98
|
}.to perform_queries(1)
|
99
99
|
end
|
100
|
-
|
101
|
-
it "should not touch database if there are no changes made" do
|
102
|
-
expect {
|
103
|
-
user.settings(:dashboard).update_attributes :theme => 'pink'
|
104
|
-
user.settings(:calendar).update_attributes :scope => 'all'
|
105
|
-
}.to perform_queries(0)
|
106
|
-
end
|
107
100
|
end
|
108
101
|
end
|
data/spec/scopes_spec.rb
CHANGED
@@ -5,21 +5,21 @@ describe 'scopes' do
|
|
5
5
|
let!(:user2) { User.create! :name => 'Mr. Blue' }
|
6
6
|
|
7
7
|
it "should find objects with existing settings" do
|
8
|
-
User.with_settings.
|
8
|
+
expect(User.with_settings).to eq([user1])
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should find objects with settings for key" do
|
12
|
-
User.with_settings_for(:dashboard).
|
13
|
-
User.with_settings_for(:foo).
|
12
|
+
expect(User.with_settings_for(:dashboard)).to eq([user1])
|
13
|
+
expect(User.with_settings_for(:foo)).to eq([])
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should records without settings" do
|
17
|
-
User.without_settings.
|
17
|
+
expect(User.without_settings).to eq([user2])
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should records without settings for key" do
|
21
|
-
User.without_settings_for(:foo).
|
22
|
-
User.without_settings_for(:dashboard).
|
21
|
+
expect(User.without_settings_for(:foo)).to eq([user1, user2])
|
22
|
+
expect(User.without_settings_for(:dashboard)).to eq([user2])
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should require symbol as key" do
|
data/spec/serialize_spec.rb
CHANGED
@@ -15,11 +15,11 @@ describe "Serialization" do
|
|
15
15
|
dashboard_settings = user.setting_objects.where(:var => 'dashboard').first
|
16
16
|
calendar_settings = user.setting_objects.where(:var => 'calendar').first
|
17
17
|
|
18
|
-
dashboard_settings.var.
|
19
|
-
dashboard_settings.value.
|
18
|
+
expect(dashboard_settings.var).to eq('dashboard')
|
19
|
+
expect(dashboard_settings.value).to eq({'theme' => 'white'})
|
20
20
|
|
21
|
-
calendar_settings.var.
|
22
|
-
calendar_settings.value.
|
21
|
+
expect(calendar_settings.var).to eq('calendar')
|
22
|
+
expect(calendar_settings.value).to eq({'scope' => 'all'})
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -30,11 +30,11 @@ describe "Serialization" do
|
|
30
30
|
dashboard_settings = user.setting_objects.where(:var => 'dashboard').first
|
31
31
|
calendar_settings = user.setting_objects.where(:var => 'calendar').first
|
32
32
|
|
33
|
-
dashboard_settings.var.
|
34
|
-
dashboard_settings.value.
|
33
|
+
expect(dashboard_settings.var).to eq('dashboard')
|
34
|
+
expect(dashboard_settings.value).to eq({'theme' => 'white', 'smart' => true})
|
35
35
|
|
36
|
-
calendar_settings.var.
|
37
|
-
calendar_settings.value.
|
36
|
+
expect(calendar_settings.var).to eq('calendar')
|
37
|
+
expect(calendar_settings.value).to eq({'scope' => 'all'})
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/spec/setting_object_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe RailsSettings::SettingObject do
|
4
4
|
let(:user) { User.create! :name => 'Mr. Pink' }
|
5
5
|
|
6
|
-
if
|
6
|
+
if defined?(ProtectedAttributes)
|
7
7
|
let(:new_setting_object) { user.setting_objects.build({ :var => 'dashboard'}, :without_protection => true) }
|
8
8
|
let(:saved_setting_object) { user.setting_objects.create!({ :var => 'dashboard', :value => { 'theme' => 'pink', 'filter' => false}}, :without_protection => true) }
|
9
9
|
else
|
@@ -13,15 +13,15 @@ describe RailsSettings::SettingObject do
|
|
13
13
|
|
14
14
|
describe "serialization" do
|
15
15
|
it "should have a hash default" do
|
16
|
-
RailsSettings::SettingObject.new.value.
|
16
|
+
expect(RailsSettings::SettingObject.new.value).to eq({})
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "Getter and Setter" do
|
21
21
|
context "on unsaved settings" do
|
22
22
|
it "should respond to setters" do
|
23
|
-
new_setting_object.
|
24
|
-
new_setting_object.
|
23
|
+
expect(new_setting_object).to respond_to(:foo=)
|
24
|
+
expect(new_setting_object).to respond_to(:bar=)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should not respond to some getters" do
|
@@ -42,14 +42,14 @@ describe RailsSettings::SettingObject do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should return nil for unknown attribute" do
|
45
|
-
new_setting_object.foo.
|
46
|
-
new_setting_object.bar.
|
45
|
+
expect(new_setting_object.foo).to eq(nil)
|
46
|
+
expect(new_setting_object.bar).to eq(nil)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should return defaults" do
|
50
|
-
new_setting_object.theme.
|
51
|
-
new_setting_object.view.
|
52
|
-
new_setting_object.filter.
|
50
|
+
expect(new_setting_object.theme).to eq('blue')
|
51
|
+
expect(new_setting_object.view).to eq('monthly')
|
52
|
+
expect(new_setting_object.filter).to eq(true)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should store different objects to value hash" do
|
@@ -59,7 +59,7 @@ describe RailsSettings::SettingObject do
|
|
59
59
|
new_setting_object.array = [ 1,2,3 ]
|
60
60
|
new_setting_object.symbol = :foo
|
61
61
|
|
62
|
-
new_setting_object.value.
|
62
|
+
expect(new_setting_object.value).to eq('integer' => 42,
|
63
63
|
'float' => 1.234,
|
64
64
|
'string' => 'Hello, World!',
|
65
65
|
'array' => [ 1,2,3 ],
|
@@ -71,53 +71,53 @@ describe RailsSettings::SettingObject do
|
|
71
71
|
new_setting_object.foo = 42
|
72
72
|
new_setting_object.bar = 'hello'
|
73
73
|
|
74
|
-
new_setting_object.theme.
|
75
|
-
new_setting_object.foo.
|
76
|
-
new_setting_object.bar.
|
74
|
+
expect(new_setting_object.theme).to eq('pink')
|
75
|
+
expect(new_setting_object.foo).to eq(42)
|
76
|
+
expect(new_setting_object.bar).to eq('hello')
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should set dirty trackers on change" do
|
80
80
|
new_setting_object.theme = 'pink'
|
81
|
-
new_setting_object.
|
82
|
-
new_setting_object.
|
81
|
+
expect(new_setting_object).to be_value_changed
|
82
|
+
expect(new_setting_object).to be_changed
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
context "on saved settings" do
|
87
87
|
it "should not set dirty trackers on setting same value" do
|
88
88
|
saved_setting_object.theme = 'pink'
|
89
|
-
saved_setting_object.
|
90
|
-
saved_setting_object.
|
89
|
+
expect(saved_setting_object).not_to be_value_changed
|
90
|
+
expect(saved_setting_object).not_to be_changed
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should delete key on assigning nil" do
|
94
94
|
saved_setting_object.theme = nil
|
95
|
-
saved_setting_object.value.
|
95
|
+
expect(saved_setting_object.value).to eq({ 'filter' => false })
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "update_attributes" do
|
101
101
|
it 'should save' do
|
102
|
-
new_setting_object.update_attributes(:foo => 42, :bar => 'string').
|
102
|
+
expect(new_setting_object.update_attributes(:foo => 42, :bar => 'string')).to be_truthy
|
103
103
|
new_setting_object.reload
|
104
104
|
|
105
|
-
new_setting_object.foo.
|
106
|
-
new_setting_object.bar.
|
107
|
-
new_setting_object.
|
108
|
-
new_setting_object.id.
|
105
|
+
expect(new_setting_object.foo).to eq(42)
|
106
|
+
expect(new_setting_object.bar).to eq('string')
|
107
|
+
expect(new_setting_object).not_to be_new_record
|
108
|
+
expect(new_setting_object.id).not_to be_zero
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should not save blank hash' do
|
112
|
-
new_setting_object.update_attributes({}).
|
112
|
+
expect(new_setting_object.update_attributes({})).to be_truthy
|
113
113
|
end
|
114
114
|
|
115
|
-
if
|
115
|
+
if defined?(ProtectedAttributes)
|
116
116
|
it 'should not allow changing protected attributes' do
|
117
117
|
new_setting_object.update_attributes!(:var => 'calendar', :foo => 42)
|
118
118
|
|
119
|
-
new_setting_object.var.
|
120
|
-
new_setting_object.foo.
|
119
|
+
expect(new_setting_object.var).to eq('dashboard')
|
120
|
+
expect(new_setting_object.foo).to eq(42)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -126,13 +126,13 @@ describe RailsSettings::SettingObject do
|
|
126
126
|
it "should save" do
|
127
127
|
new_setting_object.foo = 42
|
128
128
|
new_setting_object.bar = 'string'
|
129
|
-
new_setting_object.save.
|
129
|
+
expect(new_setting_object.save).to be_truthy
|
130
130
|
new_setting_object.reload
|
131
131
|
|
132
|
-
new_setting_object.foo.
|
133
|
-
new_setting_object.bar.
|
134
|
-
new_setting_object.
|
135
|
-
new_setting_object.id.
|
132
|
+
expect(new_setting_object.foo).to eq(42)
|
133
|
+
expect(new_setting_object.bar).to eq('string')
|
134
|
+
expect(new_setting_object).not_to be_new_record
|
135
|
+
expect(new_setting_object.id).not_to be_zero
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -140,8 +140,8 @@ describe RailsSettings::SettingObject do
|
|
140
140
|
it "should not validate for unknown var" do
|
141
141
|
new_setting_object.var = "unknown-var"
|
142
142
|
|
143
|
-
new_setting_object.
|
144
|
-
new_setting_object.errors[:var].
|
143
|
+
expect(new_setting_object).not_to be_valid
|
144
|
+
expect(new_setting_object.errors[:var]).to be_present
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
data/spec/settings_spec.rb
CHANGED
@@ -2,16 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Defaults" do
|
4
4
|
it "should be stored for simple class" do
|
5
|
-
Account.default_settings.
|
5
|
+
expect(Account.default_settings).to eq(:portal => {})
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should be stored for parent class" do
|
9
|
-
User.default_settings.
|
9
|
+
expect(User.default_settings).to eq(:dashboard => { 'theme' => 'blue', 'view' => 'monthly', 'filter' => true },
|
10
10
|
:calendar => { 'scope' => 'company'})
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should be stored for child class" do
|
14
|
-
GuestUser.default_settings.
|
14
|
+
expect(GuestUser.default_settings).to eq(:dashboard => { 'theme' => 'red', 'view' => 'monthly', 'filter' => true })
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,12 +22,12 @@ describe "Getter/Setter" do
|
|
22
22
|
account.settings(:portal).enabled = true
|
23
23
|
account.settings(:portal).template = 'black'
|
24
24
|
|
25
|
-
account.settings(:portal).enabled.
|
26
|
-
account.settings(:portal).template.
|
25
|
+
expect(account.settings(:portal).enabled).to eq(true)
|
26
|
+
expect(account.settings(:portal).template).to eq('black')
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should return nil for not existing key" do
|
30
|
-
account.settings(:portal).foo.
|
30
|
+
expect(account.settings(:portal).foo).to eq(nil)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,12 +36,12 @@ describe 'Objects' do
|
|
36
36
|
let(:account) { Account.new :subdomain => 'foo' }
|
37
37
|
|
38
38
|
it 'should have blank settings' do
|
39
|
-
account.settings(:portal).value.
|
39
|
+
expect(account.settings(:portal).value).to eq({})
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should allow saving a blank value' do
|
43
43
|
account.save!
|
44
|
-
account.settings(:portal).save.
|
44
|
+
expect(account.settings(:portal).save).to be_truthy
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should allow removing all values' do
|
@@ -50,15 +50,15 @@ describe 'Objects' do
|
|
50
50
|
account.save!
|
51
51
|
|
52
52
|
account.settings(:portal).premium = nil
|
53
|
-
account.save.
|
53
|
+
expect(account.save).to be_truthy
|
54
54
|
|
55
55
|
account.settings(:portal).fee = nil
|
56
|
-
account.save.
|
56
|
+
expect(account.save).to be_truthy
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should not add settings on saving' do
|
60
60
|
account.save!
|
61
|
-
RailsSettings::SettingObject.count.
|
61
|
+
expect(RailsSettings::SettingObject.count).to eq(0)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should save object with settings" do
|
@@ -67,11 +67,11 @@ describe 'Objects' do
|
|
67
67
|
account.save!
|
68
68
|
|
69
69
|
account.reload
|
70
|
-
account.settings(:portal).premium.
|
71
|
-
account.settings(:portal).fee.
|
70
|
+
expect(account.settings(:portal).premium).to eq(true)
|
71
|
+
expect(account.settings(:portal).fee).to eq(42.5)
|
72
72
|
|
73
|
-
RailsSettings::SettingObject.count.
|
74
|
-
RailsSettings::SettingObject.first.value.
|
73
|
+
expect(RailsSettings::SettingObject.count).to eq(1)
|
74
|
+
expect(RailsSettings::SettingObject.first.value).to eq({ 'premium' => true, 'fee' => 42.5 })
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should save settings separated" do
|
@@ -83,8 +83,8 @@ describe 'Objects' do
|
|
83
83
|
settings.save!
|
84
84
|
|
85
85
|
account.reload
|
86
|
-
account.settings(:portal).enabled.
|
87
|
-
account.settings(:portal).template.
|
86
|
+
expect(account.settings(:portal).enabled).to eq(true)
|
87
|
+
expect(account.settings(:portal).template).to eq('black')
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,19 +92,19 @@ describe 'Objects' do
|
|
92
92
|
let(:user) { User.new :name => 'Mr. Brown' }
|
93
93
|
|
94
94
|
it 'should have default settings' do
|
95
|
-
user.settings(:dashboard).theme.
|
96
|
-
user.settings(:dashboard).view.
|
97
|
-
user.settings(:dashboard).filter.
|
98
|
-
user.settings(:calendar).scope.
|
95
|
+
expect(user.settings(:dashboard).theme).to eq('blue')
|
96
|
+
expect(user.settings(:dashboard).view).to eq('monthly')
|
97
|
+
expect(user.settings(:dashboard).filter).to eq(true)
|
98
|
+
expect(user.settings(:calendar).scope).to eq('company')
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should have default settings after changing one' do
|
102
102
|
user.settings(:dashboard).theme = 'gray'
|
103
103
|
|
104
|
-
user.settings(:dashboard).theme.
|
105
|
-
user.settings(:dashboard).view.
|
106
|
-
user.settings(:dashboard).filter.
|
107
|
-
user.settings(:calendar).scope.
|
104
|
+
expect(user.settings(:dashboard).theme).to eq('gray')
|
105
|
+
expect(user.settings(:dashboard).view).to eq('monthly')
|
106
|
+
expect(user.settings(:dashboard).filter).to eq(true)
|
107
|
+
expect(user.settings(:calendar).scope).to eq('company')
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should overwrite settings" do
|
@@ -113,10 +113,10 @@ describe 'Objects' do
|
|
113
113
|
user.save!
|
114
114
|
|
115
115
|
user.reload
|
116
|
-
user.settings(:dashboard).theme.
|
117
|
-
user.settings(:dashboard).filter.
|
118
|
-
RailsSettings::SettingObject.count.
|
119
|
-
RailsSettings::SettingObject.first.value.
|
116
|
+
expect(user.settings(:dashboard).theme).to eq('brown')
|
117
|
+
expect(user.settings(:dashboard).filter).to eq(false)
|
118
|
+
expect(RailsSettings::SettingObject.count).to eq(1)
|
119
|
+
expect(RailsSettings::SettingObject.first.value).to eq({ 'theme' => 'brown', 'filter' => false })
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should merge settings with defaults" do
|
@@ -124,10 +124,10 @@ describe 'Objects' do
|
|
124
124
|
user.save!
|
125
125
|
|
126
126
|
user.reload
|
127
|
-
user.settings(:dashboard).theme.
|
128
|
-
user.settings(:dashboard).filter.
|
129
|
-
RailsSettings::SettingObject.count.
|
130
|
-
RailsSettings::SettingObject.first.value.
|
127
|
+
expect(user.settings(:dashboard).theme).to eq('brown')
|
128
|
+
expect(user.settings(:dashboard).filter).to eq(true)
|
129
|
+
expect(RailsSettings::SettingObject.count).to eq(1)
|
130
|
+
expect(RailsSettings::SettingObject.first.value).to eq({ 'theme' => 'brown' })
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -136,19 +136,19 @@ describe "Object without settings" do
|
|
136
136
|
let!(:user) { User.create! :name => 'Mr. White' }
|
137
137
|
|
138
138
|
it "should respond to #settings?" do
|
139
|
-
user.settings
|
140
|
-
user.settings?(:dashboard).
|
139
|
+
expect(user.settings?).to eq(false)
|
140
|
+
expect(user.settings?(:dashboard)).to eq(false)
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should have no setting objects" do
|
144
|
-
RailsSettings::SettingObject.count.
|
144
|
+
expect(RailsSettings::SettingObject.count).to eq(0)
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should add settings" do
|
148
148
|
user.settings(:dashboard).update_attributes! :smart => true
|
149
149
|
|
150
150
|
user.reload
|
151
|
-
user.settings(:dashboard).smart.
|
151
|
+
expect(user.settings(:dashboard).smart).to eq(true)
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should not save settings if assigned nil" do
|
@@ -168,23 +168,23 @@ describe "Object with settings" do
|
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should respond to #settings?" do
|
171
|
-
user.settings
|
171
|
+
expect(user.settings?).to eq(true)
|
172
172
|
|
173
|
-
user.settings?(:dashboard).
|
174
|
-
user.settings?(:calendar).
|
173
|
+
expect(user.settings?(:dashboard)).to eq(true)
|
174
|
+
expect(user.settings?(:calendar)).to eq(true)
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should have two setting objects" do
|
178
|
-
RailsSettings::SettingObject.count.
|
178
|
+
expect(RailsSettings::SettingObject.count).to eq(2)
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should update settings" do
|
182
182
|
user.settings(:dashboard).update_attributes! :smart => true
|
183
183
|
user.reload
|
184
184
|
|
185
|
-
user.settings(:dashboard).smart.
|
186
|
-
user.settings(:dashboard).theme.
|
187
|
-
user.settings(:calendar).scope.
|
185
|
+
expect(user.settings(:dashboard).smart).to eq(true)
|
186
|
+
expect(user.settings(:dashboard).theme).to eq('white')
|
187
|
+
expect(user.settings(:calendar).scope).to eq('all')
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should update settings by saving object" do
|
@@ -192,7 +192,7 @@ describe "Object with settings" do
|
|
192
192
|
user.save!
|
193
193
|
|
194
194
|
user.reload
|
195
|
-
user.settings(:dashboard).smart.
|
195
|
+
expect(user.settings(:dashboard).smart).to eq(true)
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should destroy settings with nil" do
|
@@ -201,7 +201,7 @@ describe "Object with settings" do
|
|
201
201
|
user.save!
|
202
202
|
}.to change(RailsSettings::SettingObject, :count).by(-2)
|
203
203
|
|
204
|
-
user.settings
|
204
|
+
expect(user.settings?).to eq(false)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
@@ -210,15 +210,15 @@ describe "Customized SettingObject" do
|
|
210
210
|
|
211
211
|
it "should not accept invalid attributes" do
|
212
212
|
project.settings(:info).owner_name = 42
|
213
|
-
project.settings(:info).
|
213
|
+
expect(project.settings(:info)).not_to be_valid
|
214
214
|
|
215
215
|
project.settings(:info).owner_name = ''
|
216
|
-
project.settings(:info).
|
216
|
+
expect(project.settings(:info)).not_to be_valid
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should accept valid attributes" do
|
220
220
|
project.settings(:info).owner_name = 'Mr. Brown'
|
221
|
-
project.settings(:info).
|
221
|
+
expect(project.settings(:info)).to be_valid
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
@@ -232,10 +232,10 @@ describe "to_settings_hash" do
|
|
232
232
|
end
|
233
233
|
|
234
234
|
it "should return defaults" do
|
235
|
-
User.new.to_settings_hash.
|
235
|
+
expect(User.new.to_settings_hash).to eq({:dashboard=>{"theme"=>"blue", "view"=>"monthly", "filter"=>true}, :calendar=>{"scope"=>"company"}})
|
236
236
|
end
|
237
237
|
|
238
238
|
it "should return merged settings" do
|
239
|
-
user.to_settings_hash.
|
239
|
+
expect(user.to_settings_hash).to eq({:dashboard=>{"theme"=>"green", "view"=>"monthly", "filter"=>true, "sound" => 11}, :calendar=>{"scope"=>"some"}})
|
240
240
|
end
|
241
241
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,6 +21,7 @@ RSpec.configure do |config|
|
|
21
21
|
end
|
22
22
|
|
23
23
|
require 'active_record'
|
24
|
+
require 'protected_attributes' if ENV['PROTECTED_ATTRIBUTES'] == 'true'
|
24
25
|
require 'rails-settings'
|
25
26
|
|
26
27
|
if I18n.respond_to?(:enforce_available_locales=)
|
@@ -58,10 +59,9 @@ end
|
|
58
59
|
|
59
60
|
def setup_db
|
60
61
|
ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
61
|
-
|
62
|
-
ActiveRecord::Base.establish_connection(db_name.to_sym)
|
62
|
+
ActiveRecord::Base.establish_connection(:sqlite)
|
63
63
|
ActiveRecord::Migration.verbose = false
|
64
|
-
puts "Testing
|
64
|
+
puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING} #{defined?(ProtectedAttributes) ? 'with' : 'without'} protected_attributes"
|
65
65
|
|
66
66
|
require File.expand_path('../../lib/generators/rails_settings/migration/templates/migration.rb', __FILE__)
|
67
67
|
RailsSettingsMigration.migrate(:up)
|
@@ -3,7 +3,7 @@ RSpec::Matchers.define :perform_queries do |expected|
|
|
3
3
|
query_count(&block) == expected
|
4
4
|
end
|
5
5
|
|
6
|
-
|
6
|
+
failure_message do |actual|
|
7
7
|
"Expected to run #{expected} queries, got #{@counter.query_count}"
|
8
8
|
end
|
9
9
|
|
@@ -15,4 +15,8 @@ RSpec::Matchers.define :perform_queries do |expected|
|
|
15
15
|
|
16
16
|
@counter.query_count
|
17
17
|
end
|
18
|
+
|
19
|
+
def supports_block_expectations?
|
20
|
+
true
|
21
|
+
end
|
18
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledermann-rails-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: mysql2
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,6 +83,7 @@ files:
|
|
97
83
|
- ci/Gemfile-rails-3-2
|
98
84
|
- ci/Gemfile-rails-4-0
|
99
85
|
- ci/Gemfile-rails-4-1
|
86
|
+
- ci/Gemfile-rails-4-2
|
100
87
|
- lib/generators/rails_settings/migration/migration_generator.rb
|
101
88
|
- lib/generators/rails_settings/migration/templates/migration.rb
|
102
89
|
- lib/ledermann-rails-settings.rb
|
@@ -136,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
123
|
version: '0'
|
137
124
|
requirements: []
|
138
125
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.4.6
|
140
127
|
signing_key:
|
141
128
|
specification_version: 4
|
142
129
|
summary: Ruby gem to handle settings for ActiveRecord instances by storing them as
|