rails-settings-ui 0.0.2 → 0.1.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Rakefile +11 -10
  4. data/app/assets/stylesheets/rails_settings_ui/application.css.scss +2 -2
  5. data/app/controllers/rails_settings_ui/settings_controller.rb +1 -1
  6. data/app/helpers/rails_settings_ui/settings_helper.rb +32 -63
  7. data/lib/rails-settings-ui.rb +1 -1
  8. data/lib/rails-settings-ui/engine.rb +7 -0
  9. data/lib/rails-settings-ui/type_converter.rb +58 -0
  10. data/lib/rails-settings-ui/value_types/array.rb +17 -0
  11. data/lib/rails-settings-ui/value_types/base.rb +30 -0
  12. data/lib/rails-settings-ui/value_types/boolean.rb +11 -0
  13. data/lib/rails-settings-ui/value_types/fixnum.rb +17 -0
  14. data/lib/rails-settings-ui/value_types/float.rb +17 -0
  15. data/lib/rails-settings-ui/value_types/hash.rb +19 -0
  16. data/lib/rails-settings-ui/value_types/string.rb +11 -0
  17. data/lib/rails-settings-ui/value_types/symbol.rb +11 -0
  18. data/lib/rails-settings-ui/version.rb +1 -1
  19. data/spec/dummy/README.rdoc +28 -0
  20. data/spec/dummy/Rakefile +6 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/models/settings.rb +16 -0
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/spec/dummy/bin/bundle +3 -0
  28. data/spec/dummy/bin/rails +4 -0
  29. data/spec/dummy/bin/rake +4 -0
  30. data/spec/dummy/config.ru +4 -0
  31. data/spec/dummy/config/application.rb +28 -0
  32. data/spec/dummy/config/boot.rb +5 -0
  33. data/spec/dummy/config/database.yml +24 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +29 -0
  36. data/spec/dummy/config/environments/production.rb +80 -0
  37. data/spec/dummy/config/environments/test.rb +36 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/spec/dummy/config/initializers/inflections.rb +16 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  43. data/spec/dummy/config/initializers/session_store.rb +3 -0
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/spec/dummy/config/locales/en.yml +23 -0
  46. data/spec/dummy/config/routes.rb +3 -0
  47. data/spec/dummy/db/migrate/20140320182332_create_settings.rb +17 -0
  48. data/spec/dummy/db/schema.rb +27 -0
  49. data/spec/dummy/db/test.sqlite3 +0 -0
  50. data/spec/dummy/log/development.log +264 -0
  51. data/spec/dummy/log/test.log +3237 -0
  52. data/spec/dummy/public/404.html +58 -0
  53. data/spec/dummy/public/422.html +58 -0
  54. data/spec/dummy/public/500.html +57 -0
  55. data/spec/dummy/public/favicon.ico +0 -0
  56. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  57. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  58. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  59. data/spec/dummy/tmp/capybara/capybara-201403251000145108838835.html +68 -0
  60. data/spec/dummy/tmp/capybara/capybara-201403251029034025293240.html +95 -0
  61. data/spec/features/settings_spec.rb +63 -0
  62. data/spec/lib/rails-settings-ui/type_converter_spec.rb +33 -0
  63. data/spec/lib/rails-settings-ui/value_types/array_spec.rb +15 -0
  64. data/spec/lib/rails-settings-ui/value_types/base_spec.rb +23 -0
  65. data/spec/lib/rails-settings-ui/value_types/boolean_spec.rb +10 -0
  66. data/spec/lib/rails-settings-ui/value_types/fixnum_spec.rb +17 -0
  67. data/spec/lib/rails-settings-ui/value_types/float_spec.rb +17 -0
  68. data/spec/lib/rails-settings-ui/value_types/hash_spec.rb +26 -0
  69. data/spec/lib/rails-settings-ui/value_types/string_spec.rb +10 -0
  70. data/spec/lib/rails-settings-ui/value_types/symbol_spec.rb +10 -0
  71. data/spec/spec_helper.rb +27 -0
  72. metadata +175 -3
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,68 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rails settings</title>
5
+ <meta charset='utf-8'>
6
+ <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
7
+ <meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'>
8
+ <link href="/assets/application.css" media="screen" rel="stylesheet" />
9
+
10
+ </head>
11
+ <body>
12
+ <div class='navbar navbar-fixed-top'>
13
+ <div class='navbar-inner'>
14
+ <div class='container-fluid'>
15
+ <a class='brand' href='/'>Rails settings ui</a>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ <div class='container-fluid'>
20
+ <div class='row-fluid'>
21
+ <div class='content'><ul class='breadcrumb'>
22
+ <li class='active'>Settings</li>
23
+ </ul>
24
+ <form accept-charset="UTF-8" action="/settings/update_all" class="form-inline" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /></div>
25
+ <table class='table table-striped'>
26
+ <thead>
27
+ <tr>
28
+ <th>Description</th>
29
+ <th>Value</th>
30
+ </tr>
31
+ </thead>
32
+ <tbody>
33
+ <tr>
34
+ <td>translation missing: en.settings.attributes.project_name.name</td>
35
+ <td>
36
+ <div class='control-group '>
37
+ <input id="settings_project_name" name="settings[project_name]" type="text" value="Dummy" />
38
+ </div>
39
+ </td>
40
+ </tr>
41
+ <tr>
42
+ <td>translation missing: en.settings.attributes.check_something.name</td>
43
+ <td>
44
+ <div class='control-group '>
45
+ <input id="settings_check_something" name="settings[check_something]" type="text" value="test" />
46
+ </div>
47
+ </td>
48
+ </tr>
49
+ <tr>
50
+ <td>translation missing: en.settings.attributes.description.name</td>
51
+ <td>
52
+ <div class='control-group '>
53
+ <textarea id="settings_description" name="settings[description]" rows="10">
54
+ But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.</textarea>
55
+ </div>
56
+ </td>
57
+ </tr>
58
+ </tbody>
59
+ </table>
60
+ <input class="btn btn-info" name="commit" type="submit" value="Save all" />
61
+ </form>
62
+
63
+ </div>
64
+ </div>
65
+ <footer></footer>
66
+ </div>
67
+ </body>
68
+ </html>
@@ -0,0 +1,95 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rails settings</title>
5
+ <meta charset='utf-8'>
6
+ <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
7
+ <meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'>
8
+ <link href="/assets/application.css" media="screen" rel="stylesheet" />
9
+
10
+ </head>
11
+ <body>
12
+ <div class='navbar navbar-fixed-top'>
13
+ <div class='navbar-inner'>
14
+ <div class='container-fluid'>
15
+ <a class='brand' href='/'>Rails settings ui</a>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ <div class='container-fluid'>
20
+ <div class='row-fluid'>
21
+ <div class='content'><ul class='breadcrumb'>
22
+ <li class='active'>Settings</li>
23
+ </ul>
24
+ <div class='alert alert-error'>Settings include errors</div>
25
+ <form accept-charset="UTF-8" action="/settings/update_all" class="form-inline" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /></div>
26
+ <table class='table table-striped'>
27
+ <thead>
28
+ <tr>
29
+ <th>Description</th>
30
+ <th>Value</th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <tr>
35
+ <td>translation missing: en.settings.attributes.project_name.name</td>
36
+ <td>
37
+ <div class='control-group '>
38
+ <input id="settings_project_name" name="settings[project_name]" type="text" value="Dummy" />
39
+ </div>
40
+ </td>
41
+ </tr>
42
+ <tr>
43
+ <td>translation missing: en.settings.attributes.limit.name</td>
44
+ <td>
45
+ <div class='control-group error'>
46
+ <input id="settings_limit" name="settings[limit]" type="text" value="150" />
47
+ <span class='help-inline'>Invalid numeric</span>
48
+ </div>
49
+ </td>
50
+ </tr>
51
+ <tr>
52
+ <td>translation missing: en.settings.attributes.style.name</td>
53
+ <td>
54
+ <div class='control-group '>
55
+ <textarea id="settings_style" name="settings[style]" rows="10">
56
+ {&quot;border_color&quot;=&gt;&quot;e0e0e0&quot;, &quot;block_color&quot;=&gt;&quot;ffffff&quot;, &quot;title&quot;=&gt;{&quot;font&quot;=&gt;&quot;Tahoma&quot;, &quot;size&quot;=&gt;&quot;12&quot;, &quot;color&quot;=&gt;&quot;107821&quot;}}</textarea>
57
+ </div>
58
+ </td>
59
+ </tr>
60
+ <tr>
61
+ <td>translation missing: en.settings.attributes.check_something.name</td>
62
+ <td>
63
+ <div class='control-group '>
64
+ <input checked="checked" id="settings_check_something" name="settings[check_something]" type="checkbox" />
65
+ </div>
66
+ </td>
67
+ </tr>
68
+ <tr>
69
+ <td>translation missing: en.settings.attributes.description.name</td>
70
+ <td>
71
+ <div class='control-group '>
72
+ <textarea id="settings_description" name="settings[description]" rows="10">
73
+ But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.</textarea>
74
+ </div>
75
+ </td>
76
+ </tr>
77
+ <tr>
78
+ <td>translation missing: en.settings.attributes.mode.name</td>
79
+ <td>
80
+ <div class='control-group '>
81
+ <input checked="checked" id="settings_mode_auto" name="settings[mode][auto]" style="margin: 0 10px;" type="checkbox" /><label for="settings_mode_auto" style="display: inline-block;">auto</label><input checked="checked" id="settings_mode_manual" name="settings[mode][manual]" style="margin: 0 10px;" type="checkbox" /><label for="settings_mode_manual" style="display: inline-block;">manual</label>
82
+ </div>
83
+ </td>
84
+ </tr>
85
+ </tbody>
86
+ </table>
87
+ <input class="btn btn-info" name="commit" type="submit" value="Save all" />
88
+ </form>
89
+
90
+ </div>
91
+ </div>
92
+ <footer></footer>
93
+ </div>
94
+ </body>
95
+ </html>
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Settings interface" do
4
+ after do
5
+ RailsSettingsUi.settings_displayed_as_select_tag = []
6
+ RailsSettingsUi.ignored_settings = []
7
+ end
8
+
9
+ describe "settings display correctly for" do
10
+ it "string" do
11
+ visit "/settings"
12
+ expect(page).to have_selector('input#settings_project_name[type=text]')
13
+ end
14
+
15
+ it "long text" do
16
+ visit "/settings"
17
+ page.should have_selector('textarea#settings_description')
18
+ end
19
+
20
+ it "boolean" do
21
+ visit "/settings"
22
+ page.should have_selector('input#settings_check_something[type=checkbox]')
23
+ end
24
+
25
+ describe "array" do
26
+ it "should display as checkboxes group by default" do
27
+ visit "/settings"
28
+ page.should have_selector('input#settings_mode_manual[type=checkbox]')
29
+ page.should have_selector('input#settings_mode_auto[type=checkbox]')
30
+ end
31
+
32
+ it "should display as select if setting defined in RailsSettingsUi.settings_displayed_as_select_tag" do
33
+ RailsSettingsUi.settings_displayed_as_select_tag = [:mode]
34
+ visit "/settings"
35
+ page.should have_selector('select#settings_mode')
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "if setting defined in RailsSettingsUi.ignored_settings" do
41
+ it "should not to be displayed" do
42
+ RailsSettingsUi.ignored_settings = [:mode]
43
+ visit "/settings"
44
+ expect(page).not_to have_selector('select#settings_mode')
45
+ end
46
+ end
47
+
48
+ describe "validations" do
49
+ it "should validate numeric setting" do
50
+ visit "/settings"
51
+ fill_in("settings[limit]", with: "test")
52
+ click_on I18n.t("settings.index.save_all")
53
+ expect(page).to have_content("Invalid numeric")
54
+ end
55
+
56
+ it "should validate hash setting" do
57
+ visit "/settings"
58
+ fill_in("settings[style]", with: "test")
59
+ click_on I18n.t("settings.index.save_all")
60
+ expect(page).to have_content("Invalid hash")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsSettingsUi::TypeConverter do
4
+ describe "default setting value type unknown" do
5
+ it "should raise exception" do
6
+ Settings.defaults[:project_name] = nil
7
+ expect do
8
+ RailsSettingsUi::TypeConverter.cast({project_name: :test})
9
+ end.to raise_error(RailsSettingsUi::UnknownDefaultValueType)
10
+ Settings.defaults[:project_name] = "Dummy"
11
+ end
12
+ end
13
+
14
+ describe "if setting not passed" do
15
+ describe "and default value type is boolean" do
16
+ it "should to set false" do
17
+ Settings.defaults[:check_something] = true
18
+ settings = RailsSettingsUi::TypeConverter.cast({})
19
+ expect(settings[:check_something]).to be_false
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".cast" do
25
+ it "should cast settings value by default setting type" do
26
+ Settings.defaults[:project_name] = :foo
27
+ settings = RailsSettingsUi::TypeConverter.cast({project_name: "bar", limit: "100"})
28
+ expect(settings[:project_name]).to equal(:bar)
29
+ expect(settings[:limit]).to equal(100)
30
+ Settings.defaults[:project_name] = "Dummy"
31
+ end
32
+ end
33
+ end