activeadmin_settings_cached 2.3.1 → 3.0.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/.github/stale.yml +17 -0
- data/.github/workflows/ci.yml +27 -0
- data/Appraisals +4 -12
- data/CHANGELOG.md +15 -0
- data/Dockerfile +3 -16
- data/Gemfile +4 -1
- data/Makefile +11 -6
- data/README.md +60 -14
- data/activeadmin_settings_cached.gemspec +3 -6
- data/app/views/admin/settings/_index.html.erb +20 -13
- data/config/locales/de.yml +1 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/ru.yml +1 -0
- data/docker-compose.yml +7 -2
- data/gemfiles/{rails4.2.gemfile → rails7.2.gemfile} +3 -2
- data/gemfiles/rails8.0.gemfile +14 -0
- data/lib/activeadmin_settings_cached/dsl.rb +17 -9
- data/lib/activeadmin_settings_cached/engine.rb +0 -3
- data/lib/activeadmin_settings_cached/model.rb +64 -67
- data/lib/activeadmin_settings_cached/options.rb +1 -2
- data/lib/activeadmin_settings_cached/version.rb +1 -1
- data/lib/activeadmin_settings_cached.rb +3 -0
- data/spec/model_spec.rb +75 -120
- data/spec/settings_spec.rb +112 -195
- data/spec/spec_helper.rb +3 -26
- data/spec/support/admin.rb +3 -10
- data/spec/support/rails_template.rb +36 -22
- data/tasks/test.rake +4 -6
- metadata +24 -67
- data/.travis.yml +0 -17
- data/gemfiles/rails5.0.gemfile +0 -15
- data/gemfiles/rails5.1.gemfile +0 -15
- data/lib/activeadmin_settings_cached/coercions.rb +0 -58
- data/spec/coercions_spec.rb +0 -86
data/spec/settings_spec.rb
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
RSpec.describe 'settings', type: :feature
|
|
3
|
+
RSpec.describe 'settings', type: :feature do
|
|
4
4
|
before do
|
|
5
|
-
|
|
6
|
-
'first_setting' => 'CCC',
|
|
7
|
-
'second_setting' => false
|
|
8
|
-
}
|
|
9
|
-
Setting['base.first_setting'] = 'AAA'
|
|
10
|
-
Setting['base.second_setting'] = true
|
|
11
|
-
Setting['second.first_setting'] = false
|
|
12
|
-
Setting['second.second_setting'] = 'BBB'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
let(:initial_some_settings) do
|
|
16
|
-
{
|
|
17
|
-
first_setting: 'CCC',
|
|
18
|
-
second_setting: false
|
|
19
|
-
}.with_indifferent_access
|
|
5
|
+
ActiveadminSettingsCached.config.display = {}
|
|
20
6
|
end
|
|
21
7
|
|
|
22
8
|
shared_examples_for 'render input with value' do |input_value|
|
|
@@ -25,112 +11,140 @@ RSpec.describe 'settings', type: :feature, js: true do
|
|
|
25
11
|
end
|
|
26
12
|
end
|
|
27
13
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
fill_in('settings_base.four_setting', with: '50.5')
|
|
34
|
-
fill_in('settings_base.five_setting', with: 'five')
|
|
14
|
+
context 'all settings page' do
|
|
15
|
+
before do
|
|
16
|
+
add_all_setting_resource
|
|
17
|
+
visit '/admin/settings'
|
|
18
|
+
end
|
|
35
19
|
|
|
36
|
-
|
|
20
|
+
it_behaves_like 'render input with value', 'AAA'
|
|
21
|
+
it_behaves_like 'render input with value', 'BBB'
|
|
37
22
|
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
expect(
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
it 'groups fields by scope' do
|
|
24
|
+
expect(page).to have_selector('th', text: 'Base')
|
|
25
|
+
expect(page).to have_selector('th', text: 'Second')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'hides readonly fields' do
|
|
29
|
+
expect(page).not_to have_field('settings_secret')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'renders field help text' do
|
|
33
|
+
expect(page).to have_content('Interface language')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'renders array and hash values' do
|
|
37
|
+
expect(find_field('settings_admin_emails').value.strip).to eq("a@example.com\nb@example.com")
|
|
38
|
+
expect(find_field('settings_notification_options').value.strip).to eq('send_all: true')
|
|
43
39
|
end
|
|
44
|
-
end
|
|
45
40
|
|
|
46
|
-
shared_examples_for 'fill and save second settings to db' do
|
|
47
41
|
it 'saves settings to db' do
|
|
48
|
-
fill_in('
|
|
49
|
-
|
|
42
|
+
fill_in('settings_app_name', with: 'App')
|
|
43
|
+
fill_in('settings_title', with: 'First')
|
|
44
|
+
uncheck('settings_captcha_enabled')
|
|
45
|
+
fill_in('settings_user_limit', with: '100')
|
|
46
|
+
fill_in('settings_tax_rate', with: '50.5')
|
|
47
|
+
select('de', from: 'settings_default_locale')
|
|
48
|
+
fill_in('settings_admin_emails', with: "x@example.com\ny@example.com")
|
|
49
|
+
fill_in('settings_notification_options', with: "send_all: false\nlogging: true")
|
|
50
50
|
|
|
51
51
|
submit
|
|
52
52
|
|
|
53
|
-
expect(
|
|
54
|
-
expect(Setting
|
|
55
|
-
expect(Setting.
|
|
53
|
+
expect(page).to have_content('Settings was successfully updated.')
|
|
54
|
+
expect(Setting.app_name).to eq 'App'
|
|
55
|
+
expect(Setting.title).to eq 'First'
|
|
56
|
+
expect(Setting.captcha_enabled).to eq false
|
|
57
|
+
expect(Setting.user_limit).to eq 100
|
|
58
|
+
expect(Setting.tax_rate).to eq 50.5
|
|
59
|
+
expect(Setting.default_locale).to eq 'de'
|
|
60
|
+
expect(Setting.admin_emails).to eq %w[x@example.com y@example.com]
|
|
61
|
+
expect(Setting.notification_options).to eq('send_all' => false, 'logging' => true)
|
|
56
62
|
end
|
|
57
|
-
end
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
fill_in('settings_some.first_setting', with: 'Awesome value')
|
|
62
|
-
check('settings_some.second_setting')
|
|
64
|
+
it 'does not persist unchanged values' do
|
|
65
|
+
fill_in('settings_title', with: 'First')
|
|
63
66
|
|
|
64
67
|
submit
|
|
65
68
|
|
|
66
|
-
expect(Setting
|
|
67
|
-
|
|
69
|
+
expect(Setting.pluck(:var)).to eq %w[title]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'shows validation errors' do
|
|
73
|
+
fill_in('settings_title', with: 'A' * 11)
|
|
74
|
+
fill_in('settings_app_name', with: 'App')
|
|
75
|
+
|
|
76
|
+
submit
|
|
77
|
+
|
|
78
|
+
expect(page).to have_content('Settings were not saved: Title is too long')
|
|
79
|
+
expect(Setting.title).to eq 'BBB'
|
|
80
|
+
expect(Setting.app_name).to eq 'App'
|
|
68
81
|
end
|
|
69
82
|
end
|
|
70
83
|
|
|
71
|
-
context '
|
|
84
|
+
context 'when settings on different pages' do
|
|
72
85
|
before do
|
|
73
|
-
|
|
74
|
-
config.display = {
|
|
75
|
-
'base.first_setting' => 'string',
|
|
76
|
-
'base.second_setting' => 'boolean',
|
|
77
|
-
'base.third_setting' => 'number',
|
|
78
|
-
'base.four_setting' => 'number',
|
|
79
|
-
'base.five_setting' => 'string',
|
|
80
|
-
'second.first_setting' => 'boolean',
|
|
81
|
-
'second.second_setting' => 'string',
|
|
82
|
-
'some.first_setting' => 'string',
|
|
83
|
-
'some.second_setting' => 'boolean'
|
|
84
|
-
}
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
add_setting_resource
|
|
86
|
+
add_base_setting_resource
|
|
88
87
|
add_second_setting_resource
|
|
89
|
-
add_some_setting_resource
|
|
90
|
-
add_all_setting_resource
|
|
91
88
|
end
|
|
92
89
|
|
|
93
|
-
context '
|
|
94
|
-
before { visit '/admin/
|
|
90
|
+
context 'base settings page' do
|
|
91
|
+
before { visit '/admin/base_settings' }
|
|
95
92
|
|
|
96
|
-
it_behaves_like 'render input with value', 'AAA'
|
|
97
93
|
it_behaves_like 'render input with value', 'BBB'
|
|
98
94
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
it 'shows only base fields' do
|
|
96
|
+
expect(page).to have_field('settings_title')
|
|
97
|
+
expect(page).not_to have_field('settings_app_name')
|
|
98
|
+
expect(page).not_to have_field('settings_admin_emails')
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'saves settings to db' do
|
|
102
|
+
fill_in('settings_title', with: 'Base')
|
|
103
|
+
check('settings_captcha_enabled')
|
|
104
|
+
submit
|
|
105
|
+
|
|
106
|
+
expect(Setting.title).to eq 'Base'
|
|
107
|
+
expect(Setting.captcha_enabled).to eq true
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context 'second settings page' do
|
|
112
|
+
before { visit '/admin/second_settings' }
|
|
113
|
+
|
|
114
|
+
it 'shows only second fields' do
|
|
115
|
+
expect(page).to have_field('settings_admin_emails')
|
|
116
|
+
expect(page).not_to have_field('settings_title')
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context 'with display options' do
|
|
122
|
+
before do
|
|
123
|
+
add_all_setting_resource(display: { app_name: :text })
|
|
124
|
+
visit '/admin/settings'
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'uses display input type' do
|
|
128
|
+
expect(page).to have_selector('textarea#settings_app_name')
|
|
103
129
|
end
|
|
104
130
|
end
|
|
105
131
|
|
|
106
132
|
context 'with custom template_object' do
|
|
107
133
|
context 'when right object' do
|
|
108
134
|
before do
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
'base.second_setting' => 'boolean',
|
|
112
|
-
'base.third_setting' => 'number',
|
|
113
|
-
'base.four_setting' => 'number',
|
|
114
|
-
'base.five_setting' => 'string',
|
|
115
|
-
'second.first_setting' => 'boolean',
|
|
116
|
-
'second.second_setting' => 'string'
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
add_all_setting_resource(
|
|
120
|
-
template_object: ActiveadminSettingsCached::Model.new(display: display_settings)
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
visit '/admin/base_settings'
|
|
135
|
+
add_all_setting_resource(template_object: ActiveadminSettingsCached::Model.new(scope: :base))
|
|
136
|
+
visit '/admin/settings'
|
|
124
137
|
end
|
|
125
138
|
|
|
126
|
-
it_behaves_like 'render input with value', '
|
|
139
|
+
it_behaves_like 'render input with value', 'BBB'
|
|
140
|
+
|
|
141
|
+
it { expect(page).not_to have_field('settings_app_name') }
|
|
127
142
|
end
|
|
128
143
|
|
|
129
144
|
context 'when wrong object' do
|
|
130
145
|
before do
|
|
131
146
|
add_all_setting_resource(template_object: nil)
|
|
132
|
-
|
|
133
|
-
visit '/admin/base_settings'
|
|
147
|
+
visit '/admin/settings'
|
|
134
148
|
end
|
|
135
149
|
|
|
136
150
|
it_behaves_like 'render input with value', 'AAA'
|
|
@@ -138,136 +152,39 @@ RSpec.describe 'settings', type: :feature, js: true do
|
|
|
138
152
|
end
|
|
139
153
|
|
|
140
154
|
describe 'with after_save' do
|
|
141
|
-
context 'when
|
|
155
|
+
context 'when submitted' do
|
|
142
156
|
before do
|
|
143
|
-
after_save = ->
|
|
144
|
-
display_settings = {
|
|
145
|
-
'base.first_setting' => 'string',
|
|
146
|
-
'base.second_setting' => 'boolean',
|
|
147
|
-
'base.third_setting' => 'number',
|
|
148
|
-
'base.four_setting' => 'number',
|
|
149
|
-
'base.five_setting' => 'string',
|
|
150
|
-
'second.first_setting' => 'boolean',
|
|
151
|
-
'second.second_setting' => 'string'
|
|
152
|
-
}
|
|
153
|
-
|
|
157
|
+
after_save = -> {}
|
|
154
158
|
expect(after_save).to receive(:call).and_call_original
|
|
155
159
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
after_save: after_save
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
visit '/admin/some_settings'
|
|
162
|
-
|
|
160
|
+
add_base_setting_resource(after_save: after_save)
|
|
161
|
+
visit '/admin/base_settings'
|
|
163
162
|
submit
|
|
164
163
|
end
|
|
165
164
|
|
|
166
|
-
it_behaves_like 'render input with value', '
|
|
165
|
+
it_behaves_like 'render input with value', 'BBB'
|
|
167
166
|
end
|
|
168
167
|
|
|
169
168
|
context 'when only open' do
|
|
170
169
|
before do
|
|
171
|
-
after_save = ->
|
|
172
|
-
|
|
170
|
+
after_save = -> {}
|
|
173
171
|
expect(after_save).not_to receive(:call)
|
|
174
172
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
visit '/admin/some_settings'
|
|
173
|
+
add_base_setting_resource(after_save: after_save)
|
|
174
|
+
visit '/admin/base_settings'
|
|
179
175
|
end
|
|
180
176
|
|
|
181
|
-
it_behaves_like 'render input with value', '
|
|
177
|
+
it_behaves_like 'render input with value', 'BBB'
|
|
182
178
|
end
|
|
183
179
|
|
|
184
180
|
context 'when wrong object' do
|
|
185
181
|
before do
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
visit '/admin/some_settings'
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
it_behaves_like 'render input with value', 'CCC'
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
context 'when settings on different pages' do
|
|
197
|
-
before do
|
|
198
|
-
ActiveadminSettingsCached.configure do |config|
|
|
199
|
-
config.display = {}
|
|
182
|
+
add_base_setting_resource(after_save: 'some')
|
|
183
|
+
visit '/admin/base_settings'
|
|
184
|
+
submit
|
|
200
185
|
end
|
|
201
186
|
|
|
202
|
-
add_setting_resource(
|
|
203
|
-
display: {
|
|
204
|
-
'base.first_setting' => 'string',
|
|
205
|
-
'base.second_setting' => 'boolean',
|
|
206
|
-
'base.third_setting' => 'number',
|
|
207
|
-
'base.four_setting' => 'number',
|
|
208
|
-
'base.five_setting' => 'string'
|
|
209
|
-
}
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
add_second_setting_resource(
|
|
213
|
-
display: {
|
|
214
|
-
'second.first_setting' => 'boolean',
|
|
215
|
-
'second.second_setting' => 'string'
|
|
216
|
-
}
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
add_some_setting_resource(
|
|
220
|
-
display: {
|
|
221
|
-
'some.first_setting' => 'string',
|
|
222
|
-
'some.second_setting' => 'boolean'
|
|
223
|
-
}
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
add_all_setting_resource(
|
|
227
|
-
display: {
|
|
228
|
-
'base.first_setting' => 'string',
|
|
229
|
-
'base.second_setting' => 'boolean',
|
|
230
|
-
'base.third_setting' => 'number',
|
|
231
|
-
'base.four_setting' => 'number',
|
|
232
|
-
'base.five_setting' => 'string',
|
|
233
|
-
'second.first_setting' => 'boolean',
|
|
234
|
-
'second.second_setting' => 'string'
|
|
235
|
-
}
|
|
236
|
-
)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
context 'base settings page' do
|
|
240
|
-
before { visit '/admin/base_settings' }
|
|
241
|
-
|
|
242
|
-
it_behaves_like 'render input with value', 'AAA'
|
|
243
|
-
it_behaves_like 'fill and save base settings to db'
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
context 'second setting page' do
|
|
247
|
-
before { visit '/admin/second_settings' }
|
|
248
|
-
|
|
249
187
|
it_behaves_like 'render input with value', 'BBB'
|
|
250
|
-
it_behaves_like 'fill and save second settings to db'
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
context 'some setting index' do
|
|
254
|
-
before { visit '/admin/some_settings' }
|
|
255
|
-
|
|
256
|
-
it_behaves_like 'render input with value', 'CCC'
|
|
257
|
-
it_behaves_like 'fill and save some settings to db'
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
context 'all setting index' do
|
|
261
|
-
before { visit '/admin/settings' }
|
|
262
|
-
|
|
263
|
-
it_behaves_like 'render input with value', 'AAA'
|
|
264
|
-
it_behaves_like 'render input with value', 'BBB'
|
|
265
|
-
# FIXME
|
|
266
|
-
#it_behaves_like 'render input with value', Setting['some'].with_indifferent_access
|
|
267
|
-
|
|
268
|
-
it_behaves_like 'fill and save base settings to db'
|
|
269
|
-
it_behaves_like 'fill and save second settings to db'
|
|
270
|
-
it { expect(Setting.some.with_indifferent_access).to eq(initial_some_settings) }
|
|
271
188
|
end
|
|
272
189
|
end
|
|
273
190
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'database_cleaner'
|
|
4
|
-
|
|
5
|
-
require 'coveralls'
|
|
6
|
-
Coveralls.wear!
|
|
3
|
+
require 'database_cleaner/active_record'
|
|
7
4
|
|
|
8
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
9
6
|
$LOAD_PATH << File.expand_path('../support', __FILE__)
|
|
10
7
|
|
|
11
|
-
ENV['BUNDLE_GEMFILE']
|
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
|
12
9
|
require 'bundler'
|
|
13
10
|
Bundler.setup
|
|
14
11
|
|
|
@@ -22,11 +19,6 @@ unless File.exist?(ENV['RAILS_ROOT'])
|
|
|
22
19
|
system 'rake setup'
|
|
23
20
|
end
|
|
24
21
|
|
|
25
|
-
require 'active_model'
|
|
26
|
-
# require ActiveRecord to ensure that Ransack loads correctly
|
|
27
|
-
require 'active_record'
|
|
28
|
-
require 'active_admin'
|
|
29
|
-
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + '/app/admin']
|
|
30
22
|
require ENV['RAILS_ROOT'] + '/config/environment.rb'
|
|
31
23
|
# Disabling authentication in specs so that we don't have to worry about
|
|
32
24
|
# it allover the place
|
|
@@ -38,22 +30,6 @@ require 'support/admin'
|
|
|
38
30
|
require 'capybara/rails'
|
|
39
31
|
require 'capybara/rspec'
|
|
40
32
|
|
|
41
|
-
unless ENV['CAPYBARA_FIREFOX']
|
|
42
|
-
require 'capybara/poltergeist'
|
|
43
|
-
|
|
44
|
-
Capybara.register_driver :poltergeist do |app|
|
|
45
|
-
Capybara::Poltergeist::Driver.new(app, {
|
|
46
|
-
js_errors: true,
|
|
47
|
-
timeout: 80,
|
|
48
|
-
debug: true,
|
|
49
|
-
:phantomjs_options => ['--debug=no', '--load-images=no']
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
Capybara.javascript_driver = :poltergeist
|
|
55
|
-
end
|
|
56
|
-
|
|
57
33
|
RSpec.configure do |config|
|
|
58
34
|
DatabaseCleaner.strategy = :truncation
|
|
59
35
|
|
|
@@ -63,5 +39,6 @@ RSpec.configure do |config|
|
|
|
63
39
|
|
|
64
40
|
config.after(:each) do
|
|
65
41
|
DatabaseCleaner.clean
|
|
42
|
+
Setting.clear_cache
|
|
66
43
|
end
|
|
67
44
|
end
|
data/spec/support/admin.rb
CHANGED
|
@@ -8,21 +8,14 @@ def base_add_resource(options = {}, &block)
|
|
|
8
8
|
Rails.application.reload_routes!
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
options = { model_name: 'Setting',
|
|
11
|
+
def add_base_setting_resource(options = {}, &block)
|
|
12
|
+
options = { model_name: 'Setting', scope: :base, title: 'Base Settings',
|
|
13
13
|
after_save: -> {} }.merge!(options)
|
|
14
14
|
base_add_resource(options, &block)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def add_second_setting_resource(options = {}, &block)
|
|
18
|
-
options = { model_name: 'Setting',
|
|
19
|
-
title: 'Second Settings' }.merge!(options)
|
|
20
|
-
base_add_resource(options, &block)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def add_some_setting_resource(options = {}, &block)
|
|
24
|
-
options = { model_name: 'Setting', title: 'Some Settings', key: 'some',
|
|
25
|
-
after_save: -> {} }.merge!(options)
|
|
18
|
+
options = { model_name: 'Setting', scope: :second, title: 'Second Settings' }.merge!(options)
|
|
26
19
|
base_add_resource(options, &block)
|
|
27
20
|
end
|
|
28
21
|
|
|
@@ -1,37 +1,51 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# Rails template to build the sample app for specs
|
|
3
3
|
|
|
4
|
-
generate :settings, 'Setting'
|
|
5
|
-
|
|
6
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
create_file 'app/assets/config/manifest.js', <<-JS
|
|
7
|
+
//= link_tree ../images
|
|
8
|
+
//= link active_admin.css
|
|
9
|
+
//= link active_admin.js
|
|
10
|
+
JS
|
|
11
|
+
|
|
12
|
+
generate :'active_admin:install', '--skip-users'
|
|
10
13
|
generate :'settings:install'
|
|
11
14
|
|
|
15
|
+
# Both generators can create migrations within the same second
|
|
16
|
+
Dir[File.join(destination_root, 'db/migrate/*_create_settings.rb')].each do |file|
|
|
17
|
+
File.rename(file, file.sub(/\d{14}(?=_create_settings)/) { |version| (version.to_i + 1).to_s })
|
|
18
|
+
end
|
|
19
|
+
|
|
12
20
|
# Configure Setup
|
|
13
21
|
inject_into_file 'config/initializers/active_admin.rb', <<-RUBY, before: "ActiveAdmin.setup do |config|"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
ActiveadminSettingsCached.configure do |config|
|
|
23
|
+
config.model_name = 'Setting'
|
|
24
|
+
end
|
|
25
|
+
|
|
17
26
|
RUBY
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
create_file 'app/models/setting.rb', <<-RUBY, force: true
|
|
29
|
+
class Setting < RailsSettings::Base
|
|
30
|
+
field :app_name, default: 'AAA'
|
|
31
|
+
|
|
32
|
+
scope :base do
|
|
33
|
+
field :title, default: 'BBB', validates: { length: { maximum: 10 } }
|
|
34
|
+
field :captcha_enabled, type: :boolean, default: true
|
|
35
|
+
field :user_limit, type: :integer, default: 5
|
|
36
|
+
field :tax_rate, type: :float, default: 5.5
|
|
37
|
+
field :default_locale, default: 'en', option_values: %w[en de ru], help_text: 'Interface language'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
scope :second do
|
|
41
|
+
field :admin_emails, type: :array, default: %w[a@example.com b@example.com]
|
|
42
|
+
field :notification_options, type: :hash, default: { 'send_all' => true }
|
|
43
|
+
field :secret, default: 'hidden', readonly: true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
RUBY
|
|
33
47
|
|
|
34
48
|
route "root :to => 'admin/dashboard#index'"
|
|
35
49
|
|
|
36
50
|
rake 'db:migrate'
|
|
37
|
-
rake 'db:
|
|
51
|
+
rake 'db:migrate', env: 'test'
|
data/tasks/test.rake
CHANGED
|
@@ -3,20 +3,18 @@
|
|
|
3
3
|
desc 'Creates a test rails app for the specs to run against'
|
|
4
4
|
task :setup do
|
|
5
5
|
require 'rails/version'
|
|
6
|
-
if File.
|
|
6
|
+
if File.exist? dir = "spec/rails/rails-#{Rails::VERSION::STRING}"
|
|
7
7
|
puts "test app #{dir} already exists; skipping"
|
|
8
8
|
else
|
|
9
9
|
system 'mkdir -p spec/rails'
|
|
10
10
|
|
|
11
11
|
args = %w[
|
|
12
12
|
-m\ spec/support/rails_template.rb
|
|
13
|
-
--
|
|
13
|
+
--minimal
|
|
14
14
|
--skip-bundle
|
|
15
15
|
--skip-git
|
|
16
|
-
--skip-
|
|
17
|
-
--skip-
|
|
18
|
-
--skip-test-unit
|
|
19
|
-
--skip-spring
|
|
16
|
+
--skip-test
|
|
17
|
+
--skip-asset-pipeline
|
|
20
18
|
]
|
|
21
19
|
|
|
22
20
|
system "bundle exec rails new #{dir} #{args.join ' '}"
|