real_settings 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -39,6 +39,16 @@ Settings.config do
|
|
39
39
|
# add some settings here
|
40
40
|
end
|
41
41
|
```
|
42
|
+
|
43
|
+
## Caution: settings in config/initializers/real_settings.rb can't store in database.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Settings.app_name # => "real_settings"
|
47
|
+
Settings.app_name = "new app name"
|
48
|
+
Settings.app_name # => "new app name"
|
49
|
+
Settings.save!
|
50
|
+
Settings.app_name # => "real_settings"
|
51
|
+
```
|
42
52
|
|
43
53
|
## Features & Usage
|
44
54
|
|
@@ -126,15 +136,19 @@ Settings.admin_name # => "Macrow"
|
|
126
136
|
### Editing Global Settings
|
127
137
|
|
128
138
|
```ruby
|
139
|
+
# config/routes.rb
|
140
|
+
get 'settings/edit' => 'settings#edit'
|
141
|
+
put 'settings/update' => 'settings#update'
|
142
|
+
|
129
143
|
# Edit Form:
|
130
|
-
form_for
|
144
|
+
form_for Settings, :as => :settings, :url => settings_update_path, :method => :put do |f|
|
131
145
|
f.text_field :app_name
|
132
146
|
f.text_field :app_url
|
133
147
|
......
|
134
148
|
end
|
135
149
|
|
136
150
|
# Update Action:
|
137
|
-
Settings.
|
151
|
+
Settings.update_settings(params[:settings])
|
138
152
|
```
|
139
153
|
|
140
154
|
### Editing User's settings
|
@@ -155,7 +169,7 @@ end
|
|
155
169
|
|
156
170
|
# Update Action:
|
157
171
|
@user = User.find(params[:user_id])
|
158
|
-
@user.settings.
|
172
|
+
@user.settings.update_settings(params[:settings])
|
159
173
|
```
|
160
174
|
|
161
175
|
|
data/spec/real_settings_spec.rb
CHANGED
@@ -63,6 +63,25 @@ describe "RealSettings" do
|
|
63
63
|
Settings.another_name.should == 'new name'
|
64
64
|
end
|
65
65
|
|
66
|
+
it "update settings from hash" do
|
67
|
+
hash = Settings.to_hash
|
68
|
+
hash[:new_feature_from_update_settings] = 'new_feature_from_update_settings'
|
69
|
+
Settings.new_feature_from_update_settings.should == nil
|
70
|
+
Settings.update_settings(hash)
|
71
|
+
Settings.new_feature_from_update_settings.should == 'new_feature_from_update_settings'
|
72
|
+
Settings.reload!
|
73
|
+
Settings.new_feature_from_update_settings.should == 'new_feature_from_update_settings'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "settings in config/initializers/real_settings.rb can't store in database" do
|
77
|
+
Settings.app_name = 'new name'
|
78
|
+
Settings.app_name.should == 'new name'
|
79
|
+
Settings.save!
|
80
|
+
Settings.app_name.should == @app_name
|
81
|
+
Settings.reload!
|
82
|
+
Settings.app_name.should == @app_name
|
83
|
+
end
|
84
|
+
|
66
85
|
it "has_settings without default values" do
|
67
86
|
@account1 = Account.create!(:name => 'account1')
|
68
87
|
@account1.settings.to_hash.should == {}
|