thecore_settings 2.0.8 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/rails_admin/main/_setting_value.html.erb +51 -0
- data/lib/thecore_settings/rails_admin_config.rb +1 -1
- data/lib/thecore_settings/version.rb +2 -1
- metadata +24 -211
- data/.devcontainer/Dockerfile +0 -20
- data/.devcontainer/devcontainer.json +0 -33
- data/.github/workflows/gempush.yml +0 -34
- data/.gitignore +0 -542
- data/.rakeTasks +0 -7
- data/.rspec +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -31
- data/CHANGELOG.md +0 -81
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -274
- data/LICENSE.txt +0 -22
- data/README.rdoc +0 -68
- data/app/models/.keep +0 -0
- data/app/views/.keep +0 -0
- data/app/views/rails_admin/main/_setting_value.html.haml +0 -41
- data/bin/rails +0 -13
- data/gemfiles/mongoid-6.0.gemfile +0 -5
- data/gemfiles/mongoid-6.3.gemfile +0 -5
- data/spec/advanced_usage_spec.rb +0 -11
- data/spec/carrierwave_spec.rb +0 -41
- data/spec/database_trickery_spec.rb +0 -48
- data/spec/defaults_spec.rb +0 -87
- data/spec/enabling_spec.rb +0 -29
- data/spec/factories/setting.rb +0 -8
- data/spec/label_spec.rb +0 -16
- data/spec/migration_spec.rb +0 -20
- data/spec/model_spec.rb +0 -105
- data/spec/namespaced_spec.rb +0 -67
- data/spec/paperclip_spec.rb +0 -38
- data/spec/settings_spec.rb +0 -75
- data/spec/shrine_spec.rb +0 -34
- data/spec/spec_helper.rb +0 -85
- data/spec/support/1024x768.gif +0 -0
- data/spec/support/database_cleaner.rb +0 -10
- data/spec/support/defaults.yml +0 -23
- data/spec/support/defaults_w_file.yml +0 -19
- data/spec/support/mongoid.rb +0 -6
- data/spec/support/mongoid.yml +0 -6
- data/spec/types_spec.rb +0 -101
- data/thecore_settings.gemspec +0 -44
data/spec/migration_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Migrating from old versions' do
|
6
|
-
it 'sets ns' do
|
7
|
-
coll = ThecoreSettings::Setting.collection
|
8
|
-
if coll.respond_to?(:insert_one)
|
9
|
-
coll.insert_one({enabled: true, key: 'test', raw: '9060000000', type: 'phone'})
|
10
|
-
else
|
11
|
-
coll.insert({enabled: true, key: 'test', raw: '9060000000', type: 'phone'})
|
12
|
-
end
|
13
|
-
ThecoreSettings.migrate!
|
14
|
-
expect(ThecoreSettings::Setting.first.key).to eq 'test'
|
15
|
-
expect(ThecoreSettings::Setting.first.raw).to eq '9060000000'
|
16
|
-
expect(ThecoreSettings::Setting.first.ns).to eq 'main'
|
17
|
-
expect(ThecoreSettings::Setting.first.kind).to eq 'phone'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
data/spec/model_spec.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe ThecoreSettings::Setting do
|
6
|
-
it { is_expected.to have_fields(:enabled, :key, :kind, :raw) }
|
7
|
-
|
8
|
-
it "correctly return content when enabled" do
|
9
|
-
setting = FactoryBot.create(:setting)
|
10
|
-
expect(setting.to_s).to eq "Контент 1"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "return empty string when disabled" do
|
14
|
-
setting = FactoryBot.create(:setting, enabled: false)
|
15
|
-
expect(setting.to_s).to eq ""
|
16
|
-
end
|
17
|
-
|
18
|
-
it "correctly process {{year}}" do
|
19
|
-
setting = FactoryBot.create(:setting, raw: '© {{year}} company')
|
20
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "correctly process {{year|2010}}" do
|
24
|
-
setting = FactoryBot.create(:setting, raw: '© {{year|2010}} company')
|
25
|
-
expect(setting.val).to eq "© 2010-#{Time.now.strftime('%Y')} company"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "correctly process {{year|current_year}}" do
|
29
|
-
setting = FactoryBot.create(:setting, raw: '© {{year|' + Time.now.strftime('%Y') + '}} company')
|
30
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company"
|
31
|
-
expect(setting.val.class.name).not_to eq "ActiveSupport::SafeBuffer"
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'return html_safe string when in html mode' do
|
35
|
-
setting = FactoryBot.create(:setting, raw: '© {{year}} company', kind: 'html')
|
36
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company"
|
37
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'sanitize html when in sanitized mode' do
|
41
|
-
setting = FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'sanitized')
|
42
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company <a>test</a>"
|
43
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'sanitize html when in sanitize mode' do
|
47
|
-
if defined?(Rails)
|
48
|
-
setting = FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'sanitize')
|
49
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company <a>test</a>"
|
50
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
51
|
-
else
|
52
|
-
expect {
|
53
|
-
FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'sanitize')
|
54
|
-
}.to raise_error(ThecoreSettings::NoRailsError)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'sanitize html when in sanitize_code mode' do
|
59
|
-
if defined?(Rails)
|
60
|
-
setting = FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'sanitize_code')
|
61
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company <a>test</a>"
|
62
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
63
|
-
else
|
64
|
-
expect {
|
65
|
-
FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'sanitize_code')
|
66
|
-
}.to raise_error(ThecoreSettings::NoRailsError)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'remove html when in strip_tags mode' do
|
71
|
-
if defined?(Rails)
|
72
|
-
setting = FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'strip_tags')
|
73
|
-
expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company test"
|
74
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
75
|
-
else
|
76
|
-
expect {
|
77
|
-
FactoryBot.create(:setting, raw: '© {{year}} company <a href="javascript:alert()">test</a>', kind: 'strip_tags')
|
78
|
-
}.to raise_error(ThecoreSettings::NoRailsError)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'formats text and cleans html in simple_format mode' do
|
83
|
-
if defined?(Rails)
|
84
|
-
setting = FactoryBot.create(:setting, raw: "© {{year}}\n\ncompany <a href='javascript:alert()'>test</a>", kind: 'simple_format')
|
85
|
-
expect(setting.val).to eq "<p>© #{Time.now.strftime('%Y')}</p>\n\n<p>company <a>test</a></p>"
|
86
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
87
|
-
else
|
88
|
-
expect {
|
89
|
-
FactoryBot.create(:setting, raw: "© {{year}}\n\ncompany <a href='javascript:alert()'>test</a>", kind: 'simple_format')
|
90
|
-
}.to raise_error(ThecoreSettings::NoRailsError)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'formats text and DOESNT html in simple_format_raw mode' do
|
95
|
-
if defined?(Rails)
|
96
|
-
setting = FactoryBot.create(:setting, raw: "© {{year}}\n\ncompany <a href='javascript:alert()'>test</a>", kind: 'simple_format_raw')
|
97
|
-
expect(setting.val).to eq "<p>© #{Time.now.strftime('%Y')}</p>\n\n<p>company <a href='javascript:alert()'>test</a></p>"
|
98
|
-
expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
|
99
|
-
else
|
100
|
-
expect {
|
101
|
-
FactoryBot.create(:setting, raw: "© {{year}}\n\ncompany <a href='javascript:alert()'>test</a>", kind: 'simple_format_raw')
|
102
|
-
}.to raise_error(ThecoreSettings::NoRailsError)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
data/spec/namespaced_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Namespaced settings' do
|
6
|
-
before :each do
|
7
|
-
Settings.destroy_all!
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'sets namespaced' do
|
11
|
-
Settings.ns(:other).test = 'test'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'reads namespaced from cache' do
|
15
|
-
ns = Settings.ns(:other)
|
16
|
-
ns.test = 'test'
|
17
|
-
expect(ns.test).to eq 'test'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'reads namespaced from db' do
|
21
|
-
Settings.ns(:other).test = 'test'
|
22
|
-
expect(Settings.ns(:other).test).to eq 'test'
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'destroys' do
|
26
|
-
Settings.ns(:other).test = 'test'
|
27
|
-
Settings.ns(:other).destroy_all!
|
28
|
-
expect(Settings.ns(:other).test).to eq ''
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'sets kind' do
|
32
|
-
expect {
|
33
|
-
Settings.ns(:other).set(:phone, 'test', kind: 'phone')
|
34
|
-
}.to raise_error
|
35
|
-
Settings.ns(:other).set(:phone, '906 111 11 11', kind: 'phone')
|
36
|
-
expect(Settings.get(:phone, ns: 'other').phone_kind?).to be_truthy
|
37
|
-
expect(Settings.get(:phone, ns: 'other').val.city).to eq '906'
|
38
|
-
expect(Settings.get(:phone, ns: 'other').val.formatted_subscriber).to eq '111-11-11'
|
39
|
-
|
40
|
-
ns = Settings.ns(:other)
|
41
|
-
expect(ns.get(:phone).phone_kind?).to be_truthy
|
42
|
-
expect(ns.get(:phone).val.city).to eq '906'
|
43
|
-
expect(ns.get(:phone).val.formatted_subscriber).to eq '111-11-11'
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'works with custom defaults' do
|
47
|
-
Settings.ns_default = 'hitfood'
|
48
|
-
Settings.ns_fallback = 'main'
|
49
|
-
expect(Settings.test).to eq ''
|
50
|
-
Settings.test = 'zzz'
|
51
|
-
expect(Settings.get(:test, ns: 'hitfood').raw).to eq 'zzz'
|
52
|
-
expect(Settings.get(:test, ns: 'main').raw).to eq ''
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'falls back to default ns' do
|
56
|
-
Settings.ns_default = 'main'
|
57
|
-
Settings.ns_fallback = 'main'
|
58
|
-
|
59
|
-
Settings.ns(:main).test = 'main'
|
60
|
-
Settings.ns(:other).test = 'other'
|
61
|
-
|
62
|
-
expect(Settings.ns('main').test).to eq 'main'
|
63
|
-
expect(Settings.ns('other').test).to eq 'other'
|
64
|
-
expect(Settings.ns('other1').test).to eq 'main'
|
65
|
-
expect(Settings.ns('other2', fallback: nil).test).to eq ''
|
66
|
-
end
|
67
|
-
end
|
data/spec/paperclip_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe "Uploads" do
|
5
|
-
if Settings.file_uploads_engine != :paperclip
|
6
|
-
pending "paperclip not detected, skipped. To run use UPLOADS=paperclip rspec"
|
7
|
-
else
|
8
|
-
Paperclip.options[:log] = false
|
9
|
-
before :each do
|
10
|
-
f = "#{File.dirname(__FILE__)}/../uploads/1024x768.gif"
|
11
|
-
if File.file?(f)
|
12
|
-
File.unlink(f)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
it 'supports file kind' do
|
16
|
-
Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'file')
|
17
|
-
expect(Settings.get(:file).file_file_name).to eq '1024x768.gif'
|
18
|
-
expect(Settings.get(:file).file_file_size).to eq 4357
|
19
|
-
expect(Settings.file[0..21]).to eq '/uploads/1024x768.gif?'
|
20
|
-
expect(File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif")).to be_truthy
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'supports image kind' do
|
24
|
-
Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'image')
|
25
|
-
expect(Settings.get(:file).file_file_name).to eq '1024x768.gif'
|
26
|
-
expect(Settings.get(:file).file_file_size).to eq 4357
|
27
|
-
expect(Settings.file[0..21]).to eq '/uploads/1024x768.gif?'
|
28
|
-
|
29
|
-
expect(File.exists?("#{File.dirname(__FILE__)}/../uploads/1024x768.gif")).to be_truthy
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'supports defaults' do
|
33
|
-
Settings.apply_defaults!(File.join(File.dirname(__FILE__), 'support/defaults_w_file.yml'))
|
34
|
-
expect(File.exists?(Settings.root_file_path.join("uploads/1024x768.gif"))).to be_truthy
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
data/spec/settings_spec.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Settings' do
|
6
|
-
it "should works as RailsSettings" do
|
7
|
-
Settings.destroy_all!
|
8
|
-
|
9
|
-
email = "my@mail.ru"
|
10
|
-
Settings.email = email
|
11
|
-
expect(Settings.email).to eq(email)
|
12
|
-
end
|
13
|
-
|
14
|
-
it '#get should return new setting when setting does not exist' do
|
15
|
-
t = Settings.get(:test)
|
16
|
-
expect(t.class.name).to eq 'ThecoreSettings::Setting'
|
17
|
-
expect(t.persisted?).to eq true
|
18
|
-
expect(t.value).to eq ''
|
19
|
-
end
|
20
|
-
|
21
|
-
it '#name should return empty string when setting does not exist' do
|
22
|
-
expect(Settings.test).to eq ''
|
23
|
-
expect(Settings['test'].value).to eq ''
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should save default" do
|
27
|
-
Settings.destroy_all!
|
28
|
-
|
29
|
-
email = "my@mail.ru"
|
30
|
-
email2 = "my2@mail.ru"
|
31
|
-
Settings.save_default(:email, email)
|
32
|
-
expect(Settings.email).to eq(email)
|
33
|
-
Settings.email = email2
|
34
|
-
expect(Settings.email).to eq(email2)
|
35
|
-
Settings.save_default(:email, email)
|
36
|
-
expect(Settings.email).to eq(email2)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should properly unload' do
|
40
|
-
Settings.load!
|
41
|
-
expect(Settings.loaded).to eq true
|
42
|
-
Settings.unload!
|
43
|
-
expect(Settings.loaded).to eq false
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should work with kind and default' do
|
47
|
-
expect(Settings.phone(kind: 'phone', default: '906 111 11 11')).to eq '+7 (906) 111-11-11'
|
48
|
-
Settings.phone = '906 222 22 22'
|
49
|
-
expect(Settings.phone(kind: 'phone', default: '906 111 11 11')).to eq '+7 (906) 222-22-22'
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should properly store settings to DB' do
|
53
|
-
Settings.unload!
|
54
|
-
expect(Settings.loaded).to eq false
|
55
|
-
Settings.temp = '123'
|
56
|
-
expect(Settings.loaded).to eq true
|
57
|
-
Settings.unload!
|
58
|
-
expect(Settings.loaded).to eq false
|
59
|
-
expect(Settings.temp).to eq '123'
|
60
|
-
expect(Settings.loaded).to eq true
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should support yaml kind' do
|
64
|
-
Settings.tdata(kind: 'yaml')
|
65
|
-
Settings.tdata = ['one', 'two', 'three']
|
66
|
-
expect(YAML.safe_load(Settings.get(:tdata).raw)).to eq ['one', 'two', 'three']
|
67
|
-
expect(Settings.tdata).to eq ['one', 'two', 'three']
|
68
|
-
end
|
69
|
-
|
70
|
-
it '#enabled? sets defaults' do
|
71
|
-
expect(Settings.enabled?(:phone, kind: 'phone')).to eq true
|
72
|
-
expect(Settings.get(:phone).kind).to eq 'phone'
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
data/spec/shrine_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe "Uploads" do
|
5
|
-
if Settings.file_uploads_engine != :shrine
|
6
|
-
pending "shrine not detected, skipped. To run use UPLOADS=shrine rspec"
|
7
|
-
else
|
8
|
-
before :each do
|
9
|
-
f = "#{File.dirname(__FILE__)}/../uploads/1024x768.gif"
|
10
|
-
if File.file?(f)
|
11
|
-
File.unlink(f)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
it 'supports file kind' do
|
15
|
-
Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'file')
|
16
|
-
expect(Settings.get(:file).file.metadata["filename"]).to eq '1024x768.gif'
|
17
|
-
expect(Settings.get(:file).file.metadata["size"]).to eq 4357
|
18
|
-
expect(Settings.get(:file).file.metadata["mime_type"]).to eq "image/gif"
|
19
|
-
expect(Settings.get(:file).file.id.split(".").last).to eq "gif"
|
20
|
-
expect(Settings.file.split("/").second + "/" + Settings.file.split("/").last.split(".").last).to eq "uploads/gif"
|
21
|
-
expect(File.exists?("public/uploads/#{Settings.get(:file).file.id}")).to be_truthy
|
22
|
-
end
|
23
|
-
it 'supports image kind' do
|
24
|
-
Settings.set('file', File.open("#{File.dirname(__FILE__)}/support/1024x768.gif"), kind: 'image')
|
25
|
-
expect(Settings.get(:file).file.metadata["filename"]).to eq '1024x768.gif'
|
26
|
-
expect(Settings.get(:file).file.metadata["size"]).to eq 4357
|
27
|
-
expect(Settings.get(:file).file.metadata["mime_type"]).to eq "image/gif"
|
28
|
-
expect(Settings.get(:file).file.id.split(".").last).to eq "gif"
|
29
|
-
expect(Settings.file.split("/").second + "/" + Settings.file.split("/").last.split(".").last).to eq "uploads/gif"
|
30
|
-
expect(File.exists?("public/uploads/#{Settings.get(:file).file.id}")).to be_truthy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
data/spec/spec_helper.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
|
-
require 'simplecov'
|
6
|
-
SimpleCov.start
|
7
|
-
|
8
|
-
require 'bundler/setup'
|
9
|
-
require 'active_support'
|
10
|
-
require 'active_support/core_ext'
|
11
|
-
|
12
|
-
unless ENV['ACTIVERECORD']
|
13
|
-
require 'mongoid'
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'database_cleaner'
|
17
|
-
require 'factory_bot'
|
18
|
-
require 'mongoid-rspec'
|
19
|
-
|
20
|
-
if ENV['UPLOADS'] == 'paperclip'
|
21
|
-
require "mongoid-paperclip"
|
22
|
-
end
|
23
|
-
if ENV['UPLOADS'] == 'carrierwave'
|
24
|
-
require "carrierwave/mongoid"
|
25
|
-
CarrierWave.configure do |config|
|
26
|
-
config.asset_host = proc do |file|
|
27
|
-
"http://localhost"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
if ENV['UPLOADS'] == 'shrine'
|
32
|
-
require "shrine"
|
33
|
-
require "shrine/storage/file_system"
|
34
|
-
Shrine.storages = {
|
35
|
-
cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
|
36
|
-
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), # permanent
|
37
|
-
}
|
38
|
-
|
39
|
-
if ENV['ACTIVERECORD']
|
40
|
-
Shrine.plugin :activerecord
|
41
|
-
end
|
42
|
-
Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays
|
43
|
-
Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
I18n.enforce_available_locales = true
|
49
|
-
I18n.load_path << File.join(File.dirname(__FILE__), "..", "config", "locales", "en.yml")
|
50
|
-
|
51
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
|
52
|
-
require f
|
53
|
-
end
|
54
|
-
|
55
|
-
if ENV['RAILS'] == '1'
|
56
|
-
require "active_model/railtie"
|
57
|
-
require "action_controller/railtie"
|
58
|
-
require "action_view/railtie"
|
59
|
-
module RAS
|
60
|
-
class Application < Rails::Application
|
61
|
-
end
|
62
|
-
end
|
63
|
-
# Initialize the Rails application.
|
64
|
-
Rails.application.initialize!
|
65
|
-
end
|
66
|
-
|
67
|
-
require 'thecore_settings'
|
68
|
-
|
69
|
-
|
70
|
-
if ENV['UPLOADS'] == 'paperclip'
|
71
|
-
module ThecoreSettings::Uploads
|
72
|
-
def self.paperclip_options
|
73
|
-
{path: "#{File.dirname(__FILE__)}/../uploads/:filename", url: '/uploads/:filename'}
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
Dir["#{File.dirname(__FILE__)}/factories/**/*.rb"].each do |f|
|
80
|
-
require f
|
81
|
-
end
|
82
|
-
|
83
|
-
#RSpec.configure do |config|
|
84
|
-
#config.expect_with(:rspec) { |c| c.syntax = :should }
|
85
|
-
#end
|
data/spec/support/1024x768.gif
DELETED
Binary file
|
data/spec/support/defaults.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
main:
|
2
|
-
footer:
|
3
|
-
kind: html
|
4
|
-
value: 'test <b></b>'
|
5
|
-
|
6
|
-
phone:
|
7
|
-
kind: 'phone'
|
8
|
-
value: '906 1111111'
|
9
|
-
|
10
|
-
true_setting:
|
11
|
-
kind: 'boolean'
|
12
|
-
value: true
|
13
|
-
|
14
|
-
false_setting:
|
15
|
-
kind: 'boolean'
|
16
|
-
value: false
|
17
|
-
|
18
|
-
disabled:
|
19
|
-
enabled: false
|
20
|
-
|
21
|
-
other:
|
22
|
-
footer:
|
23
|
-
value: 'zzz'
|
data/spec/support/mongoid.rb
DELETED
data/spec/support/mongoid.yml
DELETED
data/spec/types_spec.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Settings kind' do
|
6
|
-
it 'boolean' do
|
7
|
-
expect(Settings.get(:testbool, kind: 'boolean').value).to be(false)
|
8
|
-
expect(Settings.get(:testbool, default: true, kind: 'boolean').value).to be(false)
|
9
|
-
expect(Settings.get(:testbool2, default: true, kind: 'boolean').value).to be(true)
|
10
|
-
expect(Settings.testbool2).to be(true)
|
11
|
-
Settings.set(:testbool3, true, kind: 'boolean')
|
12
|
-
expect(Settings.testbool3).to be(true)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'html' do
|
16
|
-
expect(Settings.get(:email, kind: 'html', default: 'test@example.com').to_s).to eq 'test@example.com'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'integer' do
|
20
|
-
expect(Settings.get(:testint, kind: 'integer').value).to eq 0
|
21
|
-
expect(Settings.get(:testint, default: 5, kind: 'integer').value).to eq 0
|
22
|
-
expect(Settings.get(:testint2, default: 5, kind: 'integer').value).to eq 5
|
23
|
-
expect(Settings.testint2).to eq 5
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'float' do
|
27
|
-
expect(Settings.get(:testfloat, kind: 'float').value).to eq 0
|
28
|
-
expect(Settings.get(:testfloat, default: 5.2, kind: 'float').value).to eq 0
|
29
|
-
expect(Settings.get(:testfloat2, default: 5.5, kind: 'float').value).to eq 5.5
|
30
|
-
expect(Settings.testfloat2).to eq 5.5
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'does yaml' do
|
34
|
-
Settings.set(:data, '[one, two, three]', kind: 'yaml')
|
35
|
-
expect(Settings.get(:data).raw).to eq '[one, two, three]'
|
36
|
-
expect(Settings.data).to eq ['one', 'two', 'three']
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'does json' do
|
40
|
-
Settings.set(:data, '{"a": 1, "b": 2}', kind: 'json')
|
41
|
-
expect(Settings.get(:data).raw).to eq '{"a": 1, "b": 2}'
|
42
|
-
expect(Settings.data).to eq({"a" => 1, "b" => 2})
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'phone' do
|
46
|
-
Settings.set(:tphone, '906 111 11 11', kind: 'phone')
|
47
|
-
expect(Settings.get(:tphone).val.class.name).to eq 'RussianPhone::Number'
|
48
|
-
expect(Settings.tphone.class.name).to eq 'RussianPhone::Number'
|
49
|
-
expect(Settings.tphone).to eq '906 111 11 11'
|
50
|
-
expect(Settings.get(:tphone).phone_kind?).to be_truthy
|
51
|
-
expect(Settings.get(:tphone).val.city).to eq '906'
|
52
|
-
expect(Settings.get(:tphone).val.formatted_subscriber).to eq '111-11-11'
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'supports phones kind' do
|
56
|
-
Settings.set(:tphone, ['906 111 11 11', '907 111 11 11'] * "\n", kind: 'phones')
|
57
|
-
expect(Settings.get(:tphone).val.class.name).to eq 'Array'
|
58
|
-
expect(Settings.tphone.class.name).to eq 'Array'
|
59
|
-
expect(Settings.get(:tphone).val.first.class.name).to eq 'RussianPhone::Number'
|
60
|
-
expect(Settings.tphone.first.class.name).to eq 'RussianPhone::Number'
|
61
|
-
expect(Settings.tphone.first).to eq '906 111 11 11'
|
62
|
-
expect(Settings.get(:tphone).phones_kind?).to be_truthy
|
63
|
-
expect(Settings.get(:tphone).val.first.city).to eq '906'
|
64
|
-
expect(Settings.get(:tphone).val.last.city).to eq '907'
|
65
|
-
expect(Settings.get(:tphone).val.first.formatted_subscriber).to eq '111-11-11'
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'defaults for phone' do
|
69
|
-
Settings.dphone(kind: 'phone')
|
70
|
-
expect(Settings.get(:dphone).phone_kind?).to be_truthy
|
71
|
-
expect(Settings.dphone.formatted_area).to eq ''
|
72
|
-
expect(Settings.dphone.formatted_subscriber).to eq ''
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'email validates' do
|
76
|
-
Settings.eml(kind: 'email')
|
77
|
-
expect(Settings.get(:eml).email_kind?).to be_truthy
|
78
|
-
expect { Settings.eml = '1' }.to raise_error
|
79
|
-
Settings.eml = 'test@example.com'
|
80
|
-
expect(Settings.eml).to eq 'test@example.com'
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'url processing' do
|
84
|
-
Settings.url(kind: 'url')
|
85
|
-
expect(Settings.get(:url).url_kind?).to be_truthy
|
86
|
-
expect(Settings.get(:url).color_kind?).to be_falsey
|
87
|
-
Settings.url = 'test.ru'
|
88
|
-
expect(Settings.url).to eq 'http://test.ru'
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'color' do
|
92
|
-
Settings.col(kind: 'color')
|
93
|
-
expect(Settings.get(:col).color_kind?).to be_truthy
|
94
|
-
expect { Settings.col = 'test'}.to raise_error
|
95
|
-
Settings.col = 'ffffff'
|
96
|
-
expect(Settings.col).to eq 'ffffff'
|
97
|
-
expect {
|
98
|
-
Settings.col = 'zzzzzz'
|
99
|
-
}.to raise_error
|
100
|
-
end
|
101
|
-
end
|
data/thecore_settings.gemspec
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'thecore_settings/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "thecore_settings"
|
8
|
-
spec.version = ThecoreSettings::VERSION
|
9
|
-
spec.authors = ["Gabriele Tassoni", "Gleb Tv"]
|
10
|
-
spec.email = ["gabriele.tassoni@gmail.com", "glebtv@gmail.com"]
|
11
|
-
spec.description = %q{Mongoid / ActiveRecord + RailsAdmin App Settings management}
|
12
|
-
spec.summary = %q{}
|
13
|
-
spec.homepage = "https://github.com/gabrieletassoni/thecore_settings"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
|
22
|
-
spec.add_development_dependency "mongoid", '~> 6.3'
|
23
|
-
spec.add_development_dependency "rails"
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
27
|
-
spec.add_development_dependency "mongoid-rspec"
|
28
|
-
spec.add_development_dependency "simplecov"
|
29
|
-
spec.add_development_dependency "database_cleaner"
|
30
|
-
spec.add_development_dependency "factory_bot"
|
31
|
-
spec.add_development_dependency "safe_yaml"
|
32
|
-
spec.add_development_dependency "russian_phone"
|
33
|
-
spec.add_development_dependency "sanitize"
|
34
|
-
spec.add_development_dependency "validates_email_format_of"
|
35
|
-
spec.add_development_dependency "geocoder"
|
36
|
-
spec.add_development_dependency "addressable"
|
37
|
-
spec.add_development_dependency "carrierwave-mongoid"
|
38
|
-
spec.add_development_dependency "mongoid-paperclip"
|
39
|
-
spec.add_development_dependency "rubocop-rspec"
|
40
|
-
spec.add_development_dependency 'image_processing'
|
41
|
-
spec.add_development_dependency "mini_magick"
|
42
|
-
spec.add_development_dependency "shrine", "~> 3.0"
|
43
|
-
spec.add_development_dependency "shrine-mongoid", "~> 1.0"
|
44
|
-
end
|