thecore_settings 2.0.9 → 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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/rails_admin/main/_setting_value.html.erb +51 -0
  3. data/lib/thecore_settings/rails_admin_config.rb +1 -1
  4. data/lib/thecore_settings/version.rb +2 -3
  5. metadata +25 -212
  6. data/.devcontainer/Dockerfile +0 -20
  7. data/.devcontainer/devcontainer.json +0 -33
  8. data/.github/workflows/gempush.yml +0 -33
  9. data/.gitignore +0 -542
  10. data/.rakeTasks +0 -7
  11. data/.rspec +0 -1
  12. data/.ruby-gemset +0 -1
  13. data/.ruby-version +0 -1
  14. data/.travis.yml +0 -31
  15. data/CHANGELOG.md +0 -81
  16. data/Gemfile +0 -6
  17. data/Gemfile.lock +0 -290
  18. data/LICENSE.txt +0 -22
  19. data/README.rdoc +0 -68
  20. data/app/models/.keep +0 -0
  21. data/app/views/.keep +0 -0
  22. data/app/views/rails_admin/main/_setting_value.html.haml +0 -41
  23. data/bin/rails +0 -14
  24. data/gemfiles/mongoid-6.0.gemfile +0 -5
  25. data/gemfiles/mongoid-6.3.gemfile +0 -5
  26. data/spec/advanced_usage_spec.rb +0 -11
  27. data/spec/carrierwave_spec.rb +0 -41
  28. data/spec/database_trickery_spec.rb +0 -48
  29. data/spec/defaults_spec.rb +0 -87
  30. data/spec/enabling_spec.rb +0 -29
  31. data/spec/factories/setting.rb +0 -8
  32. data/spec/label_spec.rb +0 -16
  33. data/spec/migration_spec.rb +0 -20
  34. data/spec/model_spec.rb +0 -105
  35. data/spec/namespaced_spec.rb +0 -67
  36. data/spec/paperclip_spec.rb +0 -38
  37. data/spec/settings_spec.rb +0 -75
  38. data/spec/shrine_spec.rb +0 -34
  39. data/spec/spec_helper.rb +0 -85
  40. data/spec/support/1024x768.gif +0 -0
  41. data/spec/support/database_cleaner.rb +0 -10
  42. data/spec/support/defaults.yml +0 -23
  43. data/spec/support/defaults_w_file.yml +0 -19
  44. data/spec/support/mongoid.rb +0 -6
  45. data/spec/support/mongoid.yml +0 -6
  46. data/spec/types_spec.rb +0 -101
  47. data/thecore_settings.gemspec +0 -45
data/spec/label_spec.rb DELETED
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe 'Settings label' do
6
- it "should have label" do
7
- label = "E-Mail"
8
- Settings.email(label: label, default: "my@mail.ru")
9
- expect(Settings.get(:email).name).to eq(label)
10
- end
11
-
12
- it "should properly set label as key if blank" do
13
- Settings.email(default: "my@mail.ru")
14
- expect(Settings.get(:email).name).to eq('email')
15
- end
16
- end
@@ -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: '&copy; {{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: '&copy; {{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: '&copy; {{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: '&copy; {{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: '&copy; {{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: '&copy; {{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: '&copy; {{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: "&copy; {{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: "&copy; {{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: "&copy; {{year}}\n\ncompany <a href='javascript:alert()'>test</a>", kind: 'simple_format_raw')
97
- expect(setting.val).to eq "<p>&copy; #{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: "&copy; {{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
@@ -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
@@ -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
-
@@ -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
Binary file
@@ -1,10 +0,0 @@
1
- RSpec.configure do |config|
2
- config.before :suite do
3
- DatabaseCleaner.strategy = :truncation
4
- end
5
- config.after :each do
6
- DatabaseCleaner.clean
7
- Settings.destroy_all!
8
- end
9
- end
10
-
@@ -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'
@@ -1,19 +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
- disabled:
11
- enabled: false
12
-
13
- other:
14
- footer:
15
- value: 'zzz'
16
-
17
- img:
18
- kind: 'image'
19
- value: 'spec/support/1024x768.gif'
@@ -1,6 +0,0 @@
1
- ENV["MONGOID_ENV"] = "test"
2
- Mongoid.load!("spec/support/mongoid.yml")
3
-
4
- RSpec.configure do |configuration|
5
- configuration.include Mongoid::Matchers
6
- end
@@ -1,6 +0,0 @@
1
- test:
2
- clients:
3
- default:
4
- database: thecore_settings
5
- hosts:
6
- - localhost:27017
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
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'thecore_settings/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "thecore_settings"
9
- spec.version = ThecoreSettings::VERSION
10
- spec.authors = ["Gabriele Tassoni", "Gleb Tv"]
11
- spec.email = ["gabriele.tassoni@gmail.com", "glebtv@gmail.com"]
12
- spec.description = %q{Mongoid / ActiveRecord + RailsAdmin App Settings management}
13
- spec.summary = %q{}
14
- spec.homepage = "https://github.com/gabrieletassoni/thecore_settings"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files`.split($/)
18
- # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
- spec.required_ruby_version = '~> 2.7.7'
22
-
23
- spec.add_development_dependency "mongoid", '~> 6.3'
24
- spec.add_development_dependency "rails"
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec"
28
- spec.add_development_dependency "mongoid-rspec"
29
- spec.add_development_dependency "simplecov"
30
- spec.add_development_dependency "database_cleaner"
31
- spec.add_development_dependency "factory_bot"
32
- spec.add_development_dependency "safe_yaml"
33
- spec.add_development_dependency "russian_phone"
34
- spec.add_development_dependency "sanitize"
35
- spec.add_development_dependency "validates_email_format_of"
36
- spec.add_development_dependency "geocoder"
37
- spec.add_development_dependency "addressable"
38
- spec.add_development_dependency "carrierwave-mongoid"
39
- spec.add_development_dependency "mongoid-paperclip"
40
- spec.add_development_dependency "rubocop-rspec"
41
- spec.add_development_dependency 'image_processing'
42
- spec.add_development_dependency "mini_magick"
43
- spec.add_development_dependency "shrine", "~> 3.0"
44
- spec.add_development_dependency "shrine-mongoid", "~> 1.0"
45
- end