bizarroids_settings 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +77 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/bizarroids/application.js +13 -0
- data/app/assets/stylesheets/bizarroids/application.css +15 -0
- data/app/controllers/bizarroids/settings/application_controller.rb +4 -0
- data/app/controllers/bizarroids/settings/options_controller.rb +33 -0
- data/app/helpers/bizarroids/settings/options_helper.rb +15 -0
- data/app/helpers/bizarroids/settings/settings_helper.rb +27 -0
- data/app/models/bizarroids/settings/option.rb +65 -0
- data/app/views/bizarroids/settings/options/edit.html.erb +21 -0
- data/app/views/bizarroids/settings/options/index.html.erb +42 -0
- data/app/views/layouts/bizarroids/settings/application.html.erb +14 -0
- data/config/routes.rb +7 -0
- data/db/schema.rb +38 -0
- data/lib/bizarroids/settings/bizarroids_settings_option_uploader.rb +29 -0
- data/lib/bizarroids/settings/config_error.rb +4 -0
- data/lib/bizarroids/settings/engine.rb +7 -0
- data/lib/bizarroids/settings/helpers/settings_helper.rb +27 -0
- data/lib/bizarroids/settings/version.rb +5 -0
- data/lib/bizarroids/settings.rb +123 -0
- data/lib/bizarroids.rb +4 -0
- data/lib/bizarroids_settings.rb +1 -0
- data/lib/generators/bizarroids/settings/install/USAGE +14 -0
- data/lib/generators/bizarroids/settings/install/install_generator.rb +23 -0
- data/lib/generators/bizarroids/settings/install/templates/bizarroids_settings.en.yml +30 -0
- data/lib/generators/bizarroids/settings/install/templates/bizarroids_settings.ru.yml +31 -0
- data/lib/generators/bizarroids/settings/install/templates/initializer.rb +34 -0
- data/lib/generators/bizarroids/settings/install/templates/options_migration.rb +29 -0
- data/lib/tasks/bizarroids_tasks.rake +4 -0
- data/test/bizarroids_test.rb +7 -0
- data/test/controllers/bizarroids/settings/options_controller_test.rb +9 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +11 -0
- data/test/dummy/app/controllers/home_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/ability.rb +9 -0
- data/test/dummy/app/views/home/index.html.erb +1 -0
- data/test/dummy/app/views/layouts/application.html.erb +21 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +82 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/bizarroids_settings.rb +39 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/bizarroids_settings.en.yml +30 -0
- data/test/dummy/config/locales/bizarroids_settings.ru.yml +31 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140731121008_create_bizarroids_settings_options.rb +29 -0
- data/test/dummy/db/schema.rb +39 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +51360 -0
- data/test/dummy/log/test.log +94685 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/system/settings/file_option/0_832a7_af94124e_-1-L.jpg +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/48917139f539fdb146b469bb51d3d8a9 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/51ba48ea70bfd46c0656e1d96ef04eab +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9ce90cea0febc5c40bd72ea48e76bff7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/dd426b5348faf19a98e0326dc07bec37 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e7a8c6fc20a213fe7e6dbe204e74166b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/edabf3e4354e52066357ed9706cc6b9c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/generators/config/initializers/bizarroids_settings.rb +34 -0
- data/test/dummy/tmp/generators/config/locales/bizarroids_settings.en.yml +30 -0
- data/test/dummy/tmp/generators/config/locales/bizarroids_settings.ru.yml +31 -0
- data/test/dummy/tmp/generators/config/routes.rb +7 -0
- data/test/dummy/tmp/generators/db/migrate/20140802143121_create_bizarroids_settings_options.rb +29 -0
- data/test/fixtures/bizarroids/settings/options.yml +5 -0
- data/test/helpers/bizarroids/settings/options_helper_test.rb +17 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/lib/bizarroids/settings_test.rb +151 -0
- data/test/lib/generators/bizarroids/bizarroids/settings/install_generator_test.rb +35 -0
- data/test/models/bizarroids/settings/option_test.rb +48 -0
- data/test/test_helper.rb +47 -0
- metadata +316 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Bizarroids::Settings.setup do |config|
|
2
|
+
# avaliable option types
|
3
|
+
# config.option :string_option, :string, value: 'MyString'
|
4
|
+
# config.option :integer_option, :integer, value: 0
|
5
|
+
# config.option :float_option, :float, value: 0.0
|
6
|
+
# config.option :boolean_option, :boolean, value: true
|
7
|
+
# config.option :date_option, :date, value: Date.today
|
8
|
+
# config.option :datetime_option, :datetime, value: Time.now
|
9
|
+
# config.option :text_option, :text
|
10
|
+
# config.option :file_option, :file, extension_white_list: %w(jpg jpeg png gif)
|
11
|
+
|
12
|
+
# collection option suggests user an array of values to choose from
|
13
|
+
# config.option :string_collection, :string, collection: %w(white red black)
|
14
|
+
|
15
|
+
# this option will not be visible by user in admin panel
|
16
|
+
# config.option :hidden_option, :string, value: 'MyString', hidden: true
|
17
|
+
|
18
|
+
# option with required flag prevents user to set empty value
|
19
|
+
# it requires value to be set in config
|
20
|
+
# config.option :required_option, :string, value: 'MyString', required: true
|
21
|
+
|
22
|
+
# description and human readable name can be set
|
23
|
+
# config.option :user_friendly_option, :string, value: 'MyString', name: 'User friendly', description: 'Option for user'
|
24
|
+
|
25
|
+
# set custom class to admin panel input (to enable wysiwyg or something like this)
|
26
|
+
# config.option :text_option_with_class, :text, input_class: [:tinymce, :huge_text_field]
|
27
|
+
|
28
|
+
# directory where uploaded files will be stored.
|
29
|
+
# config.files_storage_dir = 'system/settings'
|
30
|
+
|
31
|
+
# The parent controller all Settings controllers inherits from.
|
32
|
+
# Defaults to ApplicationController. This should be set to a string.
|
33
|
+
config.parent_controller = '::ApplicationController'
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
en:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
bizarroids/settings/option:
|
5
|
+
one: Option
|
6
|
+
other: Options
|
7
|
+
attributes:
|
8
|
+
bizarroids/settings/option:
|
9
|
+
name: Name
|
10
|
+
value_type: Type
|
11
|
+
value: Value
|
12
|
+
remove_file_value: Remove file
|
13
|
+
|
14
|
+
bizarroids:
|
15
|
+
settings:
|
16
|
+
name: Options
|
17
|
+
option_updated: Option updated
|
18
|
+
types:
|
19
|
+
string: String
|
20
|
+
integer: Integer
|
21
|
+
float: Float
|
22
|
+
boolean: Boolean
|
23
|
+
text: Text
|
24
|
+
date: Date
|
25
|
+
datetime: Date and Time
|
26
|
+
file: File
|
27
|
+
cancel: Cancel
|
28
|
+
edit: Edit
|
29
|
+
save: Save
|
30
|
+
not_set: Not set
|
@@ -0,0 +1,31 @@
|
|
1
|
+
ru:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
bizarroids/settings/option:
|
5
|
+
one: Настройка
|
6
|
+
few: Настройки
|
7
|
+
other: Настроек
|
8
|
+
attributes:
|
9
|
+
bizarroids/settings/option:
|
10
|
+
name: Название
|
11
|
+
value_type: Тип
|
12
|
+
value: Значение
|
13
|
+
remove_file_value: Удалить файл
|
14
|
+
|
15
|
+
bizarroids:
|
16
|
+
settings:
|
17
|
+
name: Настройки
|
18
|
+
option_updated: Настройка обновлена
|
19
|
+
types:
|
20
|
+
string: Строка
|
21
|
+
integer: Целое число
|
22
|
+
float: Вещественное число
|
23
|
+
boolean: Логическое
|
24
|
+
text: Текстовое
|
25
|
+
date: Дата
|
26
|
+
datetime: Дата и время
|
27
|
+
file: Файл
|
28
|
+
cancel: Отмена
|
29
|
+
edit: Редактировать
|
30
|
+
save: Сохранить
|
31
|
+
not_set: Не установлено
|
data/test/dummy/tmp/generators/db/migrate/20140802143121_create_bizarroids_settings_options.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class CreateBizarroidsSettingsOptions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :bizarroids_settings_options do |t|
|
4
|
+
t.string :key
|
5
|
+
|
6
|
+
t.string :value_type, limit: 10
|
7
|
+
t.string :name
|
8
|
+
t.string :description
|
9
|
+
t.boolean :required, default: false
|
10
|
+
t.boolean :hidden, default: false
|
11
|
+
t.boolean :collection, default: false
|
12
|
+
t.integer :position
|
13
|
+
|
14
|
+
# values
|
15
|
+
t.string :string_value
|
16
|
+
t.integer :integer_value
|
17
|
+
t.float :float_value
|
18
|
+
t.boolean :boolean_value, default: false
|
19
|
+
t.text :text_value
|
20
|
+
t.date :date_value
|
21
|
+
t.datetime :datetime_value
|
22
|
+
t.string :file_value
|
23
|
+
|
24
|
+
t.timestamps
|
25
|
+
end
|
26
|
+
|
27
|
+
add_index :bizarroids_settings_options, :key
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Bizarroids::Settings
|
4
|
+
class OptionsHelperTest < ActionView::TestCase
|
5
|
+
test 'bizarroids_settings_input_options should return hash' do
|
6
|
+
create_string_option
|
7
|
+
@option = Bizarroids::Settings::Option.find_by key: :string_option
|
8
|
+
assert_instance_of Hash, bizarroids_settings_input_options
|
9
|
+
assert bizarroids_settings_input_options(a: 1)[:a], 1
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'bizarroids_settings_select_collection should return array' do
|
13
|
+
create_string_collection_option
|
14
|
+
assert_instance_of Array, bizarroids_settings_select_collection(:string_collection_option)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Bizarroids
|
4
|
+
class SettingsTest < ActiveSupport::TestCase
|
5
|
+
test "is a module module" do
|
6
|
+
assert_kind_of Module, Bizarroids::Settings
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# config
|
11
|
+
#
|
12
|
+
test 'setup block yields self' do
|
13
|
+
Settings.setup do |config|
|
14
|
+
assert_equal Settings, config
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "creating option from config" do
|
19
|
+
create_string_option
|
20
|
+
assert_equal Settings[:string_option], 'MyStringValue'
|
21
|
+
end
|
22
|
+
|
23
|
+
test "collection must be an array" do
|
24
|
+
clean_options
|
25
|
+
|
26
|
+
assert_raises Bizarroids::Settings::ConfigError do
|
27
|
+
Settings.setup do |config|
|
28
|
+
config.option :string_option, :string, collection: true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test "collection sets attribute to true" do
|
34
|
+
clean_options
|
35
|
+
|
36
|
+
Settings.setup do |config|
|
37
|
+
config.option :string_option, :string, collection: %w(a b c)
|
38
|
+
end
|
39
|
+
|
40
|
+
assert Bizarroids::Settings::Option.find_by(key: :string_option).collection
|
41
|
+
end
|
42
|
+
|
43
|
+
test "Duplicate option raises error" do
|
44
|
+
clean_options
|
45
|
+
|
46
|
+
assert_raises Bizarroids::Settings::ConfigError do
|
47
|
+
Settings.setup do |config|
|
48
|
+
config.option :string_option, :string
|
49
|
+
config.option :string_option, :string
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
test "Require flag requires non blank value" do
|
55
|
+
assert_raises Bizarroids::Settings::ConfigError do
|
56
|
+
clean_options
|
57
|
+
Settings.setup do |config|
|
58
|
+
config.option :string_option, :string, required: true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test "Hidden flag requires non blank value" do
|
64
|
+
assert_raises Bizarroids::Settings::ConfigError do
|
65
|
+
clean_options
|
66
|
+
Settings.setup do |config|
|
67
|
+
config.option :string_option, :string, hidden: true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# get & set
|
74
|
+
#
|
75
|
+
test "respond to #get" do
|
76
|
+
assert_respond_to Bizarroids::Settings, :get
|
77
|
+
end
|
78
|
+
|
79
|
+
test "get :key retuns value" do
|
80
|
+
create_string_option
|
81
|
+
assert_equal Bizarroids::Settings.get(:string_option), 'MyStringValue'
|
82
|
+
end
|
83
|
+
|
84
|
+
test "respond to #set" do
|
85
|
+
assert_respond_to Bizarroids::Settings, :set
|
86
|
+
end
|
87
|
+
|
88
|
+
test "set :key, value updates option" do
|
89
|
+
create_string_option
|
90
|
+
str = "NewStringValue"
|
91
|
+
assert_equal Bizarroids::Settings.set(:string_option, str), true
|
92
|
+
assert_equal Bizarroids::Settings.get(:string_option), str
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# aliases
|
97
|
+
#
|
98
|
+
test "respond to #[]" do
|
99
|
+
assert_respond_to Bizarroids::Settings, :[]
|
100
|
+
end
|
101
|
+
|
102
|
+
test "respond to #[]=" do
|
103
|
+
assert_respond_to Bizarroids::Settings, :[]=
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# unknown key
|
108
|
+
#
|
109
|
+
test "get raises ActiveRecord::RecordNotFound with unknown key" do
|
110
|
+
create_string_option
|
111
|
+
assert_raises ActiveRecord::RecordNotFound do
|
112
|
+
Bizarroids::Settings.get :not_existing_key
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
test "set raises ActiveRecord::RecordNotFound with unknown key" do
|
118
|
+
create_string_option
|
119
|
+
assert_raises ActiveRecord::RecordNotFound do
|
120
|
+
Bizarroids::Settings.set :not_existing_key, 'MyString'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# not configured key
|
126
|
+
#
|
127
|
+
test "get raises ActiveRecord::RecordNotFound with not configured key" do
|
128
|
+
Settings::Option.create key: :not_configured_key,
|
129
|
+
value_type: :string, value: 'MyString'
|
130
|
+
|
131
|
+
assert_raises ActiveRecord::RecordNotFound do
|
132
|
+
Bizarroids::Settings.get :not_configured_key
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
test "set raises ActiveRecord::RecordNotFound with not configured key" do
|
137
|
+
Settings::Option.create key: :not_configured_key,
|
138
|
+
value_type: :string, value: 'MyString'
|
139
|
+
|
140
|
+
assert_raises ActiveRecord::RecordNotFound do
|
141
|
+
Bizarroids::Settings.set :not_configured_key, 'MyString'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
test "keys returns all known keys" do
|
146
|
+
create_string_option
|
147
|
+
assert_equal Bizarroids::Settings.keys, [:string_option]
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/bizarroids/settings/install/install_generator'
|
3
|
+
|
4
|
+
module Bizarroids::Settings
|
5
|
+
class Bizarroids::Settings::InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests Bizarroids::Settings::InstallGenerator
|
7
|
+
destination Rails.root.join('tmp/generators')
|
8
|
+
setup do
|
9
|
+
prepare_destination
|
10
|
+
copy_routes
|
11
|
+
end
|
12
|
+
|
13
|
+
test "generator runs without errors" do
|
14
|
+
assert_nothing_raised do
|
15
|
+
run_generator
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test "generator creates files" do
|
20
|
+
run_generator
|
21
|
+
assert_file 'config/initializers/bizarroids_settings.rb'
|
22
|
+
assert_file "config/locales/bizarroids_settings.en.yml"
|
23
|
+
assert_file "config/locales/bizarroids_settings.ru.yml"
|
24
|
+
assert_migration 'db/migrate/*create_bizarroids_settings_options.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_routes
|
28
|
+
routes = File.expand_path("config/routes.rb", Rails.root)
|
29
|
+
destination = File.join(destination_root, "config")
|
30
|
+
|
31
|
+
FileUtils.mkdir_p(destination)
|
32
|
+
FileUtils.cp routes, destination
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Bizarroids::Settings
|
4
|
+
class OptionTest < ActiveSupport::TestCase
|
5
|
+
test "the truth" do
|
6
|
+
assert true
|
7
|
+
end
|
8
|
+
|
9
|
+
test "test fixtures" do
|
10
|
+
create_string_option # TODO remove with fixtures
|
11
|
+
assert_equal Option.count, 1
|
12
|
+
end
|
13
|
+
|
14
|
+
test "create string type" do
|
15
|
+
# TODO fixtures
|
16
|
+
option = Option.create key: :test_string, value_type: :string, value: 'MyString'
|
17
|
+
|
18
|
+
assert_equal option.persisted?, true
|
19
|
+
assert_equal option.value, 'MyString'
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should validate presence of value if required set to true" do
|
23
|
+
# TODO fixtures
|
24
|
+
option = Option.create key: :test_string, value_type: :string, required: true
|
25
|
+
|
26
|
+
assert option.invalid?
|
27
|
+
assert option.errors.messages.include?(:string_value)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "set_value should update option" do
|
31
|
+
# TODO fixtures
|
32
|
+
option = Option.create key: :test_string, value_type: :string, value: 'MyString'
|
33
|
+
|
34
|
+
option.set_value 'MyNewString'
|
35
|
+
assert_equal option.value, 'MyNewString'
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'avaliable_values' do
|
39
|
+
clean_options
|
40
|
+
Bizarroids::Settings.setup do |config|
|
41
|
+
config.option :string_option, :string, collection: %w(a b c)
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_equal Option.find_by(key: :string_option).avaliable_values, %w(a b c)
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|