configure_me 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/.rvmrc +1 -1
  2. data/Guardfile +9 -0
  3. data/configure_me.gemspec +3 -0
  4. data/lib/configure_me/attribute_methods.rb +10 -7
  5. data/lib/configure_me/base.rb +32 -20
  6. data/lib/configure_me/caching.rb +4 -4
  7. data/lib/configure_me/loading.rb +2 -2
  8. data/lib/configure_me/naming.rb +8 -6
  9. data/lib/configure_me/nesting.rb +35 -29
  10. data/lib/configure_me/persistence.rb +5 -4
  11. data/lib/configure_me/persisting.rb +4 -5
  12. data/lib/configure_me/validations.rb +7 -6
  13. data/lib/configure_me/version.rb +1 -1
  14. data/lib/configure_me.rb +1 -6
  15. data/spec/lib/configure_me/attribute_methods_spec.rb +113 -0
  16. data/spec/lib/configure_me/base_spec.rb +81 -0
  17. data/spec/lib/configure_me/caching_spec.rb +75 -0
  18. data/spec/lib/configure_me/loading_spec.rb +97 -0
  19. data/spec/lib/configure_me/naming_spec.rb +22 -0
  20. data/spec/lib/configure_me/nesting_spec.rb +54 -0
  21. data/spec/lib/configure_me/persistence_spec.rb +65 -0
  22. data/spec/lib/configure_me/persisting_spec.rb +119 -0
  23. data/spec/{configure_me → lib/configure_me}/setting_spec.rb +0 -0
  24. data/spec/spec_helper.rb +3 -1
  25. metadata +62 -31
  26. data/lib/configure_me/identity.rb +0 -15
  27. data/spec/configure_me/attribute_methods_spec.rb +0 -113
  28. data/spec/configure_me/base_spec.rb +0 -58
  29. data/spec/configure_me/caching_spec.rb +0 -75
  30. data/spec/configure_me/identity_spec.rb +0 -30
  31. data/spec/configure_me/loading_spec.rb +0 -84
  32. data/spec/configure_me/naming_spec.rb +0 -23
  33. data/spec/configure_me/nesting_spec.rb +0 -36
  34. data/spec/configure_me/persistence_spec.rb +0 -62
  35. data/spec/configure_me/persisting_spec.rb +0 -123
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigureMe::Loading do
4
+ class ConfigLoader
5
+ extend ConfigureMe::Loading
6
+ end
7
+
8
+ context 'a filename' do
9
+ subject { ConfigLoader }
10
+ it 'should raise an error for a non-existent file' do
11
+ lambda { subject.load('foo') }.should raise_error(ArgumentError)
12
+ end
13
+
14
+ it 'should load an existing file' do
15
+ File.stubs(:exists?).returns(true)
16
+ File.stubs(:open).returns({:foo => 'bar'}.to_yaml)
17
+ subject.expects(:from_hash)
18
+ subject.load('avalidfile')
19
+ end
20
+ end
21
+
22
+ context 'a hash' do
23
+ context 'with :app => {:setting1 => \'foo\', :setting2 => 845}' do
24
+ let(:config) { ConfigLoader.load(:app => {:setting1 => 'foo', :setting2 => 845}) }
25
+ describe 'the class' do
26
+ subject { config }
27
+ its(:config_name) { should eql('app') }
28
+ end
29
+
30
+ describe 'the instance' do
31
+ subject { config.new }
32
+ it { should respond_to(:setting1) }
33
+ it { should respond_to(:setting2) }
34
+ it { should_not respond_to(:setting3) }
35
+ its(:setting1) { should eql('foo') }
36
+ its(:setting2) { should eql(845) }
37
+ its(:parent_config) { should be_nil }
38
+ end
39
+ end
40
+
41
+ context 'with :group1 => {:setting1 => 6, :setting2 => \'foo\'}, :group2 => {:setting3 => 8, :setting4 => \'bar\'}' do
42
+
43
+ let(:config) {
44
+ ConfigLoader.load(
45
+ :group1 => {
46
+ :setting1 => 6,
47
+ :setting2 => 'foo'
48
+ },
49
+ :group2 => {
50
+ :setting3 => 8,
51
+ :setting4 => 'bar'
52
+ }
53
+ )
54
+ }
55
+ describe 'the class' do
56
+ subject { config }
57
+ its(:config_name) { should eql('root') }
58
+ end
59
+ describe 'the instance' do
60
+ let(:config_inst) { config.new }
61
+ subject { config_inst }
62
+ it { should respond_to(:group1) }
63
+ it { should respond_to(:group2) }
64
+ it { should_not respond_to(:group3) }
65
+
66
+ describe 'group1' do
67
+ subject { config_inst.group1 }
68
+ it { should_not be_nil }
69
+ it { should respond_to(:setting1) }
70
+ it { should respond_to(:setting2) }
71
+ it { should_not respond_to(:setting3) }
72
+ its(:setting1) { should eql(6) }
73
+ its(:setting2) { should eql('foo') }
74
+ its(:parent_config) { should eql(config_inst) }
75
+ end
76
+
77
+ describe 'group2' do
78
+ subject { config_inst.group2 }
79
+ it { should_not be_nil }
80
+ it { should respond_to(:setting3) }
81
+ it { should respond_to(:setting4) }
82
+ it { should_not respond_to(:setting1) }
83
+ its(:setting3) { should eql(8) }
84
+ its(:setting4) { should eql('bar') }
85
+ its(:parent_config) { should eql(config_inst) }
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'something unsupported' do
92
+ subject { ConfigLoader }
93
+ it 'should raise an exception' do
94
+ lambda { subject.load(123) }.should raise_error(ArgumentError)
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigureMe::Naming do
4
+ class NamingTester
5
+ include ConfigureMe::Naming
6
+ end
7
+
8
+ let(:persistence_klass) { stub(:model_name => 'persistence') }
9
+ before {
10
+ ConfigureMe.stubs(:persistence_klass).returns(persistence_klass)
11
+ }
12
+ subject { NamingTester }
13
+ context 'when persisting' do
14
+ before { NamingTester.stubs(:persisting?).returns(true) }
15
+ its(:model_name) { should eql('persistence') }
16
+ end
17
+
18
+ context 'when not persisting' do
19
+ before { NamingTester.stubs(:persisting?).returns(false) }
20
+ its(:model_name) { should_not eql('persistence') }
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigureMe::Nesting do
4
+ class RootConfig
5
+ include ConfigureMe::Nesting
6
+ end
7
+ class NestedConfig
8
+ include ConfigureMe::Nesting
9
+ end
10
+
11
+ subject { RootConfig }
12
+ it { should respond_to(:nest_me) }
13
+
14
+ context 'a nested class' do
15
+ before {
16
+ NestedConfig.stubs(:config_name).returns('nested')
17
+ RootConfig.stubs(:config_name).returns('root')
18
+ NestedConfig.nest_me(RootConfig)
19
+ }
20
+ subject { NestedConfig }
21
+ its(:nested_classes) { should be_empty }
22
+
23
+ context 'instance' do
24
+ let(:root_config) { RootConfig.new }
25
+ subject { root_config.nested }
26
+ its(:parent_config) { should eql(root_config) }
27
+ its(:children) { should be_empty }
28
+ its(:all_configs) { should have(1).items }
29
+ end
30
+ end
31
+
32
+ context 'a root class' do
33
+ before {
34
+ NestedConfig.stubs(:config_name).returns('nested')
35
+ RootConfig.stubs(:config_name).returns('root')
36
+ NestedConfig.nest_me(RootConfig)
37
+ }
38
+ subject { RootConfig }
39
+ its(:nested_classes) { should have(1).items }
40
+
41
+ context 'instance' do
42
+ let(:root_config) { RootConfig.new }
43
+ let(:nested_config) { root_config.nested }
44
+ before { root_config.nested }
45
+ subject { root_config }
46
+ it { should respond_to(:nested) }
47
+ its(:children) { should have(1).items }
48
+ its(:children) { should eql(:nested => nested_config) }
49
+ its(:all_configs) { should have(2).items }
50
+ its(:parent_config) { should be_nil }
51
+ its(:nested) { should eql(nested_config) }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigureMe::Persistence do
4
+ class PersistenceTester
5
+ extend ActiveModel::Callbacks
6
+ include ConfigureMe::Persistence
7
+ end
8
+
9
+ let(:test_class) { define_test_class('PersistenceConfig', PersistenceTester) }
10
+ let(:config) { test_class.new }
11
+ subject { config }
12
+ describe 'saving' do
13
+ before {
14
+ config.stubs(:write_persist)
15
+ config.stubs(:write_cache)
16
+ config.stubs(:make_clean)
17
+ @temp_attrs = {:testsetting => 'newvalue'}
18
+ config.stubs(:temp_attributes).returns(@temp_attrs)
19
+ config.stubs(:persist_guard).yields
20
+ }
21
+ it 'should run callbacks' do
22
+ config.expects(:run_callbacks).at_least_once.yields
23
+ config.save
24
+ end
25
+ it 'should not run the validations if :validate => false is passed' do
26
+ config.expects(:valid?).never
27
+ config.save(:validate => false)
28
+ end
29
+ it 'should start a transaction' do
30
+ config.expects(:persist_guard)
31
+ config.save
32
+ end
33
+
34
+ it 'should persist the temp settings' do
35
+ config.expects(:write_persist).with(:testsetting, 'newvalue')
36
+ config.save
37
+ end
38
+
39
+ it 'should cache the temp settings' do
40
+ config.expects(:write_cache).with(:testsetting, 'newvalue')
41
+ config.save
42
+ end
43
+
44
+ it 'should clear the dirty status' do
45
+ config.expects(:make_clean)
46
+ config.save
47
+ end
48
+ end
49
+
50
+ describe 'update_attributes' do
51
+ before {
52
+ config.stubs(:write_attribute)
53
+ }
54
+ it 'should store the new attributes' do
55
+ config.stubs(:save)
56
+ config.expects(:write_attribute).with(:testsetting, 'updatedvalue')
57
+ config.update_attributes(:testsetting => 'updatedvalue')
58
+ end
59
+
60
+ it 'should attempt to save' do
61
+ config.expects(:save)
62
+ config.update_attributes(:testsetting => 'updatedvalue')
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigureMe::Persisting do
4
+
5
+ class PersistingTester
6
+ include ConfigureMe::Persisting
7
+ end
8
+ subject { PersistingTester }
9
+ it { should respond_to(:persist_me) }
10
+ it { should respond_to(:persisting?) }
11
+
12
+ let(:persisting_klass) { define_test_class('PersistingConfig', PersistingTester) }
13
+
14
+ context 'when the persistence_klass is nil' do
15
+ before {
16
+ persisting_klass.send(:persist_me)
17
+ ConfigureMe.stubs(:persistence_klass).returns(nil)
18
+ }
19
+ subject { persisting_klass }
20
+ its(:persisting?) { should be_false }
21
+ end
22
+
23
+ describe 'persist_guard' do
24
+ subject { persisting_klass.new }
25
+ context 'when transactions are supported' do
26
+ it 'should begin a transaction' do
27
+ @transaction_class = mock('TransactionClass') do
28
+ expects(:transaction)
29
+ end
30
+ ConfigureMe.stubs(:persistence_klass).returns(@transaction_class)
31
+ subject.persist_guard
32
+ end
33
+ end
34
+
35
+ context 'when persisting with something else' do
36
+ it 'should just execute the block' do
37
+ @non_transaction_class = mock('NonTransactionClass')
38
+ ConfigureMe.stubs(:persistence_klass).returns(@non_transaction_class)
39
+ @testvalue = 'default'
40
+ subject.persist_guard do
41
+ @testvalue = 'changed'
42
+ end
43
+ @testvalue.should eql('changed')
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'when persisting is enabled' do
49
+ let(:persisted_setting) { stub(:value => 'foo'.to_yaml, :value= => nil, :save! => nil) }
50
+ before {
51
+ @persistence_klass = stub(:find_or_create_by_key => persisted_setting, :find_by_key => persisted_setting)
52
+ ConfigureMe.stubs(:persistence_klass).returns(@persistence_klass)
53
+ persisting_klass.stubs(:persisting?).returns(true)
54
+ }
55
+ subject { persisting_klass.new }
56
+
57
+ describe 'read_persist' do
58
+ before { subject.stubs(:storage_key).returns('key') }
59
+ it 'should read from the persistence store' do
60
+ @persistence_klass.expects(:find_by_key).once.returns(@persisted_setting)
61
+ subject.read_persist('persistedsetting')
62
+ end
63
+
64
+ context 'with a persisted value' do
65
+ it 'should return the converted value' do
66
+ subject.read_persist('persistedsetting').should eql('foo')
67
+ end
68
+ end
69
+
70
+ context 'with a non-persisted value' do
71
+ it 'should return nil' do
72
+ @persistence_klass.stubs(:find_by_key).returns(nil)
73
+ subject.read_persist('persistedsetting').should be_nil
74
+ end
75
+ end
76
+ end
77
+
78
+ describe 'write_persist' do
79
+ before { subject.stubs(:storage_key).returns('key') }
80
+ it 'should retrieve or create the setting' do
81
+ @persistence_klass.expects(:find_or_create_by_key).once.returns(persisted_setting)
82
+ subject.write_persist('persistedsetting', 'newvalue')
83
+ end
84
+ it 'should update the value' do
85
+ persisted_setting.expects(:value=).with('newvalue'.to_yaml)
86
+ subject.write_persist('persistedsetting', 'newvalue')
87
+ end
88
+ it 'should save the record' do
89
+ persisted_setting.expects(:save!)
90
+ subject.write_persist('persistedsetting', 'newvalue')
91
+ end
92
+ end
93
+ end
94
+
95
+ #describe ConfigureMe::Persisting, 'when persisting is disabled' do
96
+ # before {
97
+ # @persisting_class = define_test_class('PersistingConfig', ConfigureMe::Base)
98
+ # @persisting_class.stubs(:persisting?).returns(false)
99
+ # }
100
+ # subject { @persisting_class.new }
101
+ #
102
+ # describe 'read_persist' do
103
+ # it 'should not attempt to read from the persistence store' do
104
+ # ConfigureMe.expects(:persistence_klass).never
105
+ # subject.read_persist('persistedsetting')
106
+ # end
107
+ # it 'should return nil' do
108
+ # subject.read_persist('persistedsetting').should be_nil
109
+ # end
110
+ # end
111
+ #
112
+ # describe 'write_persist' do
113
+ # it 'should not attempt to write to the persistence store' do
114
+ # ConfigureMe.expects(:persistence_klass).never
115
+ # subject.write_persist('persistedsetting', 'newvalue')
116
+ # end
117
+ # end
118
+ #end
119
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'simplecov'
3
- SimpleCov.start
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
4
6
  require 'bundler/setup'
5
7
  Bundler.require(:default)
6
8
  require 'rspec/core'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configure_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-02 00:00:00.000000000Z
12
+ date: 2012-01-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &22468760 !ruby/object:Gem::Requirement
16
+ requirement: &19476980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22468760
24
+ version_requirements: *19476980
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &19476340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *19476340
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &22463680 !ruby/object:Gem::Requirement
38
+ requirement: &19475680 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 2.7.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *22463680
46
+ version_requirements: *19475680
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: simplecov
38
- requirement: &22463200 !ruby/object:Gem::Requirement
49
+ requirement: &19474860 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 0.5.4
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *22463200
57
+ version_requirements: *19474860
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: mocha
49
- requirement: &22462720 !ruby/object:Gem::Requirement
60
+ requirement: &19474400 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,7 +65,29 @@ dependencies:
54
65
  version: 0.10.0
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *22462720
68
+ version_requirements: *19474400
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: &19473920 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.5.10
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *19473920
80
+ - !ruby/object:Gem::Dependency
81
+ name: libnotify
82
+ requirement: &19473240 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.6.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *19473240
58
91
  description: Simple gem to assist with persisting configuration data.
59
92
  email:
60
93
  - theprime@codingprime.com
@@ -66,6 +99,7 @@ files:
66
99
  - .rspec
67
100
  - .rvmrc
68
101
  - Gemfile
102
+ - Guardfile
69
103
  - README.rdoc
70
104
  - Rakefile
71
105
  - configure_me.gemspec
@@ -73,7 +107,6 @@ files:
73
107
  - lib/configure_me/attribute_methods.rb
74
108
  - lib/configure_me/base.rb
75
109
  - lib/configure_me/caching.rb
76
- - lib/configure_me/identity.rb
77
110
  - lib/configure_me/loading.rb
78
111
  - lib/configure_me/naming.rb
79
112
  - lib/configure_me/nesting.rb
@@ -87,16 +120,15 @@ files:
87
120
  - lib/generators/configure_me/templates/migration.rb
88
121
  - lib/generators/configure_me/templates/model.erb
89
122
  - lib/generators/configure_me/templates/model.rb
90
- - spec/configure_me/attribute_methods_spec.rb
91
- - spec/configure_me/base_spec.rb
92
- - spec/configure_me/caching_spec.rb
93
- - spec/configure_me/identity_spec.rb
94
- - spec/configure_me/loading_spec.rb
95
- - spec/configure_me/naming_spec.rb
96
- - spec/configure_me/nesting_spec.rb
97
- - spec/configure_me/persistence_spec.rb
98
- - spec/configure_me/persisting_spec.rb
99
- - spec/configure_me/setting_spec.rb
123
+ - spec/lib/configure_me/attribute_methods_spec.rb
124
+ - spec/lib/configure_me/base_spec.rb
125
+ - spec/lib/configure_me/caching_spec.rb
126
+ - spec/lib/configure_me/loading_spec.rb
127
+ - spec/lib/configure_me/naming_spec.rb
128
+ - spec/lib/configure_me/nesting_spec.rb
129
+ - spec/lib/configure_me/persistence_spec.rb
130
+ - spec/lib/configure_me/persisting_spec.rb
131
+ - spec/lib/configure_me/setting_spec.rb
100
132
  - spec/spec_helper.rb
101
133
  - spec/support/active_model_lint.rb
102
134
  homepage: http://www.github.com/t3hpr1m3/configure_me
@@ -124,15 +156,14 @@ signing_key:
124
156
  specification_version: 3
125
157
  summary: Simple configuration library
126
158
  test_files:
127
- - spec/configure_me/attribute_methods_spec.rb
128
- - spec/configure_me/base_spec.rb
129
- - spec/configure_me/caching_spec.rb
130
- - spec/configure_me/identity_spec.rb
131
- - spec/configure_me/loading_spec.rb
132
- - spec/configure_me/naming_spec.rb
133
- - spec/configure_me/nesting_spec.rb
134
- - spec/configure_me/persistence_spec.rb
135
- - spec/configure_me/persisting_spec.rb
136
- - spec/configure_me/setting_spec.rb
159
+ - spec/lib/configure_me/attribute_methods_spec.rb
160
+ - spec/lib/configure_me/base_spec.rb
161
+ - spec/lib/configure_me/caching_spec.rb
162
+ - spec/lib/configure_me/loading_spec.rb
163
+ - spec/lib/configure_me/naming_spec.rb
164
+ - spec/lib/configure_me/nesting_spec.rb
165
+ - spec/lib/configure_me/persistence_spec.rb
166
+ - spec/lib/configure_me/persisting_spec.rb
167
+ - spec/lib/configure_me/setting_spec.rb
137
168
  - spec/spec_helper.rb
138
169
  - spec/support/active_model_lint.rb
@@ -1,15 +0,0 @@
1
- module ConfigureMe
2
- module Identity
3
- def config_key
4
- to_param
5
- end
6
-
7
- def config_name
8
- self.class.name.split('::').last.gsub(/^(.*)Config$/, '\1').underscore
9
- end
10
-
11
- def storage_key(name)
12
- "#{config_key}-#{name.to_s}"
13
- end
14
- end
15
- end
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ConfigureMe::AttributeMethods do
4
- before {
5
- @config_class = define_test_class('MyTestConfig', ConfigureMe::Base)
6
- }
7
- subject { @config_class.instance }
8
- it 'make clean should clear the temp_attributes' do
9
- subject.send(:temp_attributes).expects(:clear)
10
- subject.send(:make_clean)
11
- end
12
- end
13
-
14
- describe ConfigureMe::AttributeMethods, 'reading an attribute' do
15
- before {
16
- @config_class = define_test_class('MyTestConfig', ConfigureMe::Base)
17
- @config_class.send(:setting, :testsetting, :default => 'foo')
18
- @config = @config_class.instance
19
- @config.stubs(:read_cache)
20
- @config.stubs(:read_persist)
21
- }
22
- subject { @config }
23
- it 'should call "read_attribute"' do
24
- @config.expects(:read_attribute).with('testsetting')
25
- subject.testsetting
26
- end
27
- context 'with a pristine instance' do
28
- it 'should attempt to read from the cache' do
29
- subject.expects(:read_cache)
30
- subject.testsetting
31
- end
32
- it 'should attempt to read from the persistence store' do
33
- subject.expects(:read_persist)
34
- subject.testsetting
35
- end
36
- it 'should return the default value' do
37
- subject.testsetting.should eql('foo')
38
- end
39
- end
40
- context 'with a persisted value' do
41
- context 'with a non-cached value' do
42
- before { @config.stubs(:read_cache).returns(nil) }
43
- it 'should attempt to read from the cache' do
44
- subject.expects(:read_cache).returns(nil)
45
- subject.testsetting
46
- end
47
- it 'should attempt to read from the persistence store' do
48
- subject.expects(:read_persist)
49
- subject.testsetting
50
- end
51
- it 'should write the value to the cache' do
52
- subject.stubs(:read_persist).returns('persisted')
53
- subject.expects(:write_cache).with(:testsetting, 'persisted')
54
- subject.testsetting
55
- end
56
- it 'should return the persisted value' do
57
- subject.stubs(:read_cache).returns('persisted')
58
- subject.testsetting.should eql('persisted')
59
- end
60
- end
61
-
62
- context 'with a cached value' do
63
- before { @config.stubs(:read_cache).returns('cached') }
64
- it 'should attempt to read from the cache' do
65
- subject.expects(:read_cache).returns('cached')
66
- subject.testsetting
67
- end
68
- it 'should not attempt to read from the persistence store' do
69
- subject.expects(:read_persist).never
70
- subject.testsetting
71
- end
72
- it 'should return the cached value' do
73
- subject.testsetting.should eql('cached')
74
- end
75
- end
76
- end
77
-
78
- context 'with a dirty value' do
79
- before { @config.stubs(:testsetting_changed?).returns(true) }
80
- it 'should not attempt to read from the cache' do
81
- subject.expects(:read_cache).never
82
- subject.testsetting
83
- end
84
- it 'should not attempt to read from the persistence store' do
85
- subject.expects(:read_persist).never
86
- subject.testsetting
87
- end
88
- it 'should return the value from the temp_attributes hash' do
89
- subject.expects(:temp_attributes).returns(:testsetting => 'iamdirty')
90
- subject.testsetting.should eql('iamdirty')
91
- end
92
- end
93
- end
94
-
95
- describe ConfigureMe::AttributeMethods, 'writing an attribute' do
96
- before {
97
- @config_class = define_test_class('MyTestConfig', ConfigureMe::Base)
98
- @config_class.send(:setting, :testsetting, :default => 'foo')
99
- @config = @config_class.instance
100
- @config.stubs(:read_cache)
101
- @config.stubs(:read_persist)
102
- }
103
- subject { @config }
104
-
105
- it 'should set the attribute to dirty' do
106
- subject.expects(:make_dirty).with(:testsetting)
107
- subject.testsetting = 'newvalue'
108
- end
109
- it 'should write the value to the temp_attributes hash' do
110
- subject.testsetting = 'newvalue'
111
- subject.send(:temp_attributes)[:testsetting].should eql('newvalue')
112
- end
113
- end