ledermann-rails-settings 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71d258f55435ac0936befafa014944f3a3ae72da
4
- data.tar.gz: 0f9f767391fad56c4ff44a7ff44494ad4b6c09b6
3
+ metadata.gz: 0b32592febac17831f730dd18e33ef0af56c1251
4
+ data.tar.gz: 6c4c04520451889bf5ad7ca407d53530415aa7e6
5
5
  SHA512:
6
- metadata.gz: d621905d20eab2e0962c943242286d0eb9097731f3eb4f7d23edb3102494ce774e5eaf64cff455ff2c7f49461050976f4c44b6af4550888955f39ed8d83feac6
7
- data.tar.gz: 378399bc595e654aa79323d51cdc963b778024427713332f9c93aff0a25595146be562604299681f931fd644fbb230208c07ca7e6164ebde5b64c0d8dea9d895
6
+ metadata.gz: 71033242a7e5ff5cc1d6c1da91fc968aae2df1513e83678cd7fb7d199b71fa6f42b4354dd35cfaa8c70671a552adff2041cb7cb65920878b61e42ba0e83f9398
7
+ data.tar.gz: dcb7360d13a853702e90efe91329ae3db9c052c8c4062164b68a170a9d97411fc8136c8ced228fad2d30bde7e871c36c257d456cb67bfb579b90ba93b8d738c8
@@ -2,15 +2,22 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.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
- env:
12
- - DB=sqlite
13
- - DB=mysql
14
- before_script:
15
- - "mysql -e 'create database rails_settings_test;' >/dev/null"
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Georg Ledermann
1
+ Copyright (c) 2012-2015 Georg Ledermann
2
2
 
3
3
  MIT License
4
4
 
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) 2013 [Georg Ledermann](http://www.georg-ledermann.de)
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)
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.1.12'
4
- gem 'sqlite3', '~> 1.3'
5
- gem 'mysql2', '>= 0.3.6'
6
- gem 'rake', '~> 10.0'
7
- gem 'rspec', '~> 2.13'
4
+ gem 'sqlite3'
5
+ gem 'rake'
6
+ gem 'rspec'
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '~> 3.2.17'
4
- gem 'sqlite3', '~> 1.3'
5
- gem 'mysql2', '>= 0.3.6'
6
- gem 'rake', '~> 10.0'
7
- gem 'rspec', '~> 2.13'
4
+ gem 'sqlite3'
5
+ gem 'rake'
6
+ gem 'rspec'
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 4.0.4'
4
- gem 'sqlite3', '~> 1.3'
5
- gem 'mysql2', '>= 0.3.6'
6
- gem 'rake', '~> 10.0'
7
- gem 'rspec', '~> 2.13'
3
+ gem 'activerecord', '~> 4.0.13'
4
+ gem 'protected_attributes' if ENV['PROTECTED_ATTRIBUTES'] == 'true'
5
+ gem 'sqlite3'
6
+ gem 'rake'
7
+ gem 'rspec'
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 4.1.0'
4
- gem 'sqlite3', '~> 1.3'
5
- gem 'mysql2', '>= 0.3.6'
6
- gem 'rake', '~> 10.0'
7
- gem 'rspec', '~> 2.13'
3
+ gem 'activerecord', '~> 4.1.10'
4
+ gem 'protected_attributes' if ENV['PROTECTED_ATTRIBUTES'] == 'true'
5
+ gem 'sqlite3'
6
+ gem 'rake'
7
+ gem 'rspec'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 4.2.1'
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
@@ -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 ActiveRecord::VERSION::MAJOR < 4
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 used because it touches the database which is not connected yet.
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 ActiveRecord::VERSION::MAJOR < 4
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 ActiveRecord::VERSION::MAJOR < 4
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
@@ -1,3 +1,3 @@
1
1
  module RailsSettings
2
- VERSION = '2.3.0'
2
+ VERSION = '2.4.0'
3
3
  end
@@ -21,6 +21,5 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency 'rake'
23
23
  gem.add_development_dependency 'sqlite3'
24
- gem.add_development_dependency 'mysql2'
25
24
  gem.add_development_dependency 'rspec'
26
25
  end
@@ -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.should == { :dashboard => {} }
12
- Dummy.setting_object_class_name.should == 'RailsSettings::SettingObject'
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.should == { :dashboard => {}, :calendar => {} }
19
- Dummy.setting_object_class_name.should == 'RailsSettings::SettingObject'
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.should == { :dashboard => {} }
25
- Dummy.setting_object_class_name.should == 'MyClass'
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.should == { :dashboard => {}, :calendar => {} }
32
- Dummy.setting_object_class_name.should == 'MyClass'
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.should == { :dashboard => {}, :calendar => {} }
42
- Dummy.setting_object_class_name.should == 'RailsSettings::SettingObject'
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.should == { :dashboard => { 'theme' => 'red' }, :calendar => { 'scope' => 'all'} }
52
- Dummy.setting_object_class_name.should == 'RailsSettings::SettingObject'
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.should == { :dashboard => {}, :calendar => {} }
62
- Dummy.setting_object_class_name.should == 'MyClass'
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
 
@@ -1,8 +1,3 @@
1
1
  sqlite:
2
2
  adapter: sqlite3
3
3
  database: ":memory:"
4
- mysql:
5
- adapter: mysql2
6
- database: rails_settings_test
7
- username:
8
- encoding: utf8
@@ -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
@@ -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.should eq([user1])
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).should eq([user1])
13
- User.with_settings_for(:foo).should eq([])
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.should eq([user2])
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).should eq([user1, user2])
22
- User.without_settings_for(:dashboard).should eq([user2])
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
@@ -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.should == 'dashboard'
19
- dashboard_settings.value.should eq({'theme' => 'white'})
18
+ expect(dashboard_settings.var).to eq('dashboard')
19
+ expect(dashboard_settings.value).to eq({'theme' => 'white'})
20
20
 
21
- calendar_settings.var.should == 'calendar'
22
- calendar_settings.value.should eq({'scope' => 'all'})
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.should == 'dashboard'
34
- dashboard_settings.value.should eq({'theme' => 'white', 'smart' => true})
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.should == 'calendar'
37
- calendar_settings.value.should eq({'scope' => 'all'})
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
@@ -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 ActiveRecord::VERSION::MAJOR < 4
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.should == {}
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.should respond_to(:foo=)
24
- new_setting_object.should respond_to(:bar=)
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.should eq(nil)
46
- new_setting_object.bar.should eq(nil)
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.should eq('blue')
51
- new_setting_object.view.should eq('monthly')
52
- new_setting_object.filter.should eq(true)
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.should eq('integer' => 42,
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.should eq('pink')
75
- new_setting_object.foo.should eq(42)
76
- new_setting_object.bar.should eq('hello')
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.should be_value_changed
82
- new_setting_object.should be_changed
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.should_not be_value_changed
90
- saved_setting_object.should_not be_changed
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.should == { 'filter' => false }
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').should be_true
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.should eq(42)
106
- new_setting_object.bar.should eq('string')
107
- new_setting_object.should_not be_new_record
108
- new_setting_object.id.should_not be_zero
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({}).should be_true
112
+ expect(new_setting_object.update_attributes({})).to be_truthy
113
113
  end
114
114
 
115
- if ActiveRecord::VERSION::MAJOR < 4
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.should eq('dashboard')
120
- new_setting_object.foo.should eq(42)
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.should be_true
129
+ expect(new_setting_object.save).to be_truthy
130
130
  new_setting_object.reload
131
131
 
132
- new_setting_object.foo.should eq(42)
133
- new_setting_object.bar.should eq('string')
134
- new_setting_object.should_not be_new_record
135
- new_setting_object.id.should_not be_zero
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.should_not be_valid
144
- new_setting_object.errors[:var].should be_present
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
@@ -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.should eq(:portal => {})
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.should eq(:dashboard => { 'theme' => 'blue', 'view' => 'monthly', 'filter' => true },
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.should eq(:dashboard => { 'theme' => 'red', 'view' => 'monthly', 'filter' => true })
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.should eq(true)
26
- account.settings(:portal).template.should eq('black')
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.should eq(nil)
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.should eq({})
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.should be_true
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.should be_true
53
+ expect(account.save).to be_truthy
54
54
 
55
55
  account.settings(:portal).fee = nil
56
- account.save.should be_true
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.should eq(0)
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.should eq(true)
71
- account.settings(:portal).fee.should eq(42.5)
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.should eq(1)
74
- RailsSettings::SettingObject.first.value.should == { 'premium' => true, 'fee' => 42.5 }
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.should eq(true)
87
- account.settings(:portal).template.should eq('black')
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.should eq('blue')
96
- user.settings(:dashboard).view.should eq('monthly')
97
- user.settings(:dashboard).filter.should eq(true)
98
- user.settings(:calendar).scope.should eq('company')
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.should eq('gray')
105
- user.settings(:dashboard).view.should eq('monthly')
106
- user.settings(:dashboard).filter.should eq(true)
107
- user.settings(:calendar).scope.should eq('company')
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.should eq('brown')
117
- user.settings(:dashboard).filter.should eq(false)
118
- RailsSettings::SettingObject.count.should eq(1)
119
- RailsSettings::SettingObject.first.value.should == { 'theme' => 'brown', 'filter' => false }
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.should eq('brown')
128
- user.settings(:dashboard).filter.should eq(true)
129
- RailsSettings::SettingObject.count.should eq(1)
130
- RailsSettings::SettingObject.first.value.should == { 'theme' => 'brown' }
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?.should eq(false)
140
- user.settings?(:dashboard).should eq(false)
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.should eq(0)
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.should eq(true)
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?.should eq(true)
171
+ expect(user.settings?).to eq(true)
172
172
 
173
- user.settings?(:dashboard).should eq(true)
174
- user.settings?(:calendar).should eq(true)
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.should eq(2)
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.should eq(true)
186
- user.settings(:dashboard).theme.should eq('white')
187
- user.settings(:calendar).scope.should eq('all')
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.should eq(true)
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?.should == false
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).should_not be_valid
213
+ expect(project.settings(:info)).not_to be_valid
214
214
 
215
215
  project.settings(:info).owner_name = ''
216
- project.settings(:info).should_not be_valid
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).should be_valid
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.should == {:dashboard=>{"theme"=>"blue", "view"=>"monthly", "filter"=>true}, :calendar=>{"scope"=>"company"}}
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.should == {:dashboard=>{"theme"=>"green", "view"=>"monthly", "filter"=>true, "sound" => 11}, :calendar=>{"scope"=>"some"}}
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
@@ -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
- db_name = ENV['DB'] || 'sqlite'
62
- ActiveRecord::Base.establish_connection(db_name.to_sym)
62
+ ActiveRecord::Base.establish_connection(:sqlite)
63
63
  ActiveRecord::Migration.verbose = false
64
- puts "Testing on #{db_name} with ActiveRecord #{ActiveRecord::VERSION::STRING}"
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
- failure_message_for_should do |actual|
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.3.0
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: 2014-04-25 00:00:00.000000000 Z
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.2.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