persistent_settings 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Persistent Settings
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/dabit/persistent_settings.png)](http://travis-ci.org/dabit/persistent_settings)
4
+
3
5
  A simple key value store for ActiveRecord based applications.
4
6
 
5
7
  Best used to store global app settings.
@@ -35,6 +37,17 @@ Reload your app:
35
37
 
36
38
  It accepts all kinds of objects as the value
37
39
 
40
+ ## Known Issues
41
+
42
+ Sometimes, settings are not loaded automatically at startup. If that's the case
43
+ add an initializer to your Rails app.
44
+
45
+ #
46
+ # config/initializers/settings.rb
47
+ #
48
+
49
+ Settings.load_from_persistance
50
+
38
51
  # License
39
52
 
40
53
  MIT License. Copyright 2011, Crowd Interactive http://www.crowdint.com
@@ -1,3 +1,3 @@
1
1
  module PersistentSettings
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/settings.rb CHANGED
@@ -40,15 +40,19 @@ class Settings < ActiveRecord::Base
40
40
  end
41
41
  end
42
42
 
43
- def self.load_from_persistance
43
+ def self.load_from_persistance!
44
44
  self.all.each do |setting|
45
45
  self.send("#{setting.var}=", setting.value)
46
46
  end
47
47
  end
48
48
 
49
+ def self.load_from_persistance
50
+ load_from_persistance! if connected? && table_exists?
51
+ end
52
+
49
53
  def self.keys
50
54
  Settings.select(:var).collect { |s| s.var.to_sym }
51
55
  end
52
56
 
53
- load_from_persistance if connected? && table_exists?
57
+ load_from_persistance
54
58
  end
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Settings do
4
- before do
5
- end
6
4
  describe :assignation? do
7
5
  context "the method name ends with =" do
8
6
  it "returns true" do
@@ -68,7 +66,7 @@ describe Settings do
68
66
 
69
67
  it "pulls the value from the database and creates its setter and getter" do
70
68
  Settings.should_receive(:persisted_method=).with('some value')
71
- Settings.load_from_persistance
69
+ Settings.load_from_persistance!
72
70
  end
73
71
  end
74
72
 
@@ -96,4 +94,52 @@ describe Settings do
96
94
  specify { should include(:a_key) }
97
95
  specify { should include(:another_key) }
98
96
  end
97
+
98
+ describe :load_from_persistance! do
99
+ it "loads all settings from persistance and sets it up" do
100
+ settings = [ Settings.new(:var => 'foo', :value => 'bar') ]
101
+ Settings.should_receive(:all).and_return(settings)
102
+ Settings.should_receive("foo=").with('bar')
103
+
104
+ Settings.load_from_persistance!
105
+ end
106
+ end
107
+
108
+ describe :load_from_persistance do
109
+ context "AR is connected and table is created" do
110
+ before do
111
+ Settings.stub(:connected?).and_return true
112
+ Settings.stub(:table_exists?).and_return true
113
+ end
114
+
115
+ it "calls load_from_persistance!" do
116
+ Settings.should_receive(:load_from_persistance!)
117
+ Settings.load_from_persistance
118
+ end
119
+ end
120
+
121
+ context "AR is not connected" do
122
+ before do
123
+ Settings.stub(:connected?).and_return false
124
+ Settings.stub(:table_exists?).and_return true
125
+ end
126
+
127
+ it "calls load_from_persistance!" do
128
+ Settings.should_not_receive(:load_from_persistance!)
129
+ Settings.load_from_persistance
130
+ end
131
+ end
132
+
133
+ context "table is not created" do
134
+ before do
135
+ Settings.stub(:connected?).and_return false
136
+ Settings.stub(:table_exists?).and_return false
137
+ end
138
+
139
+ it "calls load_from_persistance!" do
140
+ Settings.should_not_receive(:load_from_persistance!)
141
+ Settings.load_from_persistance
142
+ end
143
+ end
144
+ end
99
145
  end
data/spec/spec_helper.rb CHANGED
@@ -2,3 +2,9 @@ require 'persistent_settings'
2
2
 
3
3
  ::ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
4
4
 
5
+ ::ActiveRecord::Schema.define(:version => 1) do
6
+ create_table "settings", :force => true do |t|
7
+ t.string "var"
8
+ t.string "value"
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persistent_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.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: 2011-12-15 00:00:00.000000000 Z
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70348682989280 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70348682989280
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activerecord
27
- requirement: &70348682988780 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '3.0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70348682988780
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: cucumber
38
- requirement: &70348682988280 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 1.1.4
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70348682988280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.4
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &70348682987800 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70348682987800
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rspec
60
- requirement: &70348682987200 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: 2.7.0
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70348682987200
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.7.0
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: sqlite3
71
- requirement: &70348683003000 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: '1.3'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70348683003000
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.3'
80
110
  description: Simple global Settings class for ActiveRecord based applications
81
111
  email:
82
112
  - david@crowdint.com
@@ -115,15 +145,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
145
  - - ! '>='
116
146
  - !ruby/object:Gem::Version
117
147
  version: '0'
148
+ segments:
149
+ - 0
150
+ hash: 3753706074841151251
118
151
  required_rubygems_version: !ruby/object:Gem::Requirement
119
152
  none: false
120
153
  requirements:
121
154
  - - ! '>='
122
155
  - !ruby/object:Gem::Version
123
156
  version: '0'
157
+ segments:
158
+ - 0
159
+ hash: 3753706074841151251
124
160
  requirements: []
125
161
  rubyforge_project: persistent_settings
126
- rubygems_version: 1.8.10
162
+ rubygems_version: 1.8.23
127
163
  signing_key:
128
164
  specification_version: 3
129
165
  summary: Simple global Settings class for ActiveRecord based applications