tuning 0.3.3 → 1.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +80 -17
  4. data/Rakefile +3 -0
  5. data/lib/tuning.rb +7 -2
  6. data/lib/tuning/extensions/action_controller/base.rb +45 -0
  7. data/lib/tuning/extensions/action_mailer/base.rb +22 -0
  8. data/lib/tuning/extensions/action_view/base.rb +31 -0
  9. data/lib/tuning/extensions/active_record/base.rb +25 -0
  10. data/lib/tuning/locales/en.yml +12 -0
  11. data/lib/tuning/locales/es.yml +12 -0
  12. data/lib/tuning/railtie.rb +17 -3
  13. data/lib/tuning/validations/complexity.rb +22 -0
  14. data/lib/tuning/validations/count.rb +42 -0
  15. data/lib/tuning/validations/time.rb +38 -0
  16. data/lib/tuning/version.rb +1 -1
  17. data/test/controllers_test.rb +21 -0
  18. data/test/dummy/Rakefile +1 -2
  19. data/test/dummy/app/assets/javascripts/application.js +2 -2
  20. data/test/dummy/app/assets/stylesheets/application.css +6 -4
  21. data/test/dummy/app/mailers/user_mailer.rb +7 -0
  22. data/test/dummy/app/models/shop.rb +2 -0
  23. data/test/dummy/app/views/layouts/application.html.erb +0 -12
  24. data/test/dummy/app/views/layouts/market.html.erb +3 -0
  25. data/test/dummy/app/views/user_mailer/invite.text.erb +7 -0
  26. data/test/dummy/bin/bundle +0 -0
  27. data/test/dummy/bin/rails +1 -1
  28. data/test/dummy/bin/rake +0 -0
  29. data/test/dummy/bin/setup +29 -0
  30. data/test/dummy/config.ru +1 -1
  31. data/test/dummy/config/application.rb +3 -1
  32. data/test/dummy/config/boot.rb +1 -1
  33. data/test/dummy/config/database.yml +4 -22
  34. data/test/dummy/config/database.yml.travis +12 -0
  35. data/test/dummy/config/environment.rb +1 -1
  36. data/test/dummy/config/environments/development.rb +14 -2
  37. data/test/dummy/config/environments/production.rb +20 -25
  38. data/test/dummy/config/environments/test.rb +8 -10
  39. data/test/dummy/config/initializers/assets.rb +11 -0
  40. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/test/dummy/config/initializers/mime_types.rb +1 -2
  42. data/test/dummy/config/initializers/session_store.rb +1 -1
  43. data/test/dummy/config/locales/en.yml +22 -9
  44. data/test/dummy/config/routes.rb +2 -7
  45. data/test/dummy/config/secrets.yml +22 -0
  46. data/test/dummy/db/migrate/20161020200126_create_shops.rb +9 -0
  47. data/test/dummy/db/migrate/20161022144717_create_records.rb +6 -0
  48. data/test/dummy/db/schema.rb +15 -1
  49. data/test/dummy/log/test.log +70 -0
  50. data/test/dummy/public/404.html +20 -11
  51. data/test/dummy/public/422.html +20 -11
  52. data/test/dummy/public/500.html +19 -10
  53. data/test/helpers_test.rb +39 -0
  54. data/test/mailers_test.rb +10 -0
  55. data/test/records_test.rb +16 -0
  56. data/test/test_helper.rb +5 -18
  57. data/test/validations_test.rb +192 -0
  58. metadata +66 -47
  59. data/lib/tuning/action_controller/base.rb +0 -54
  60. data/lib/tuning/action_view/base.rb +0 -16
  61. data/test/active_trail_test.rb +0 -33
  62. data/test/content_tag_if_test.rb +0 -17
  63. data/test/dummy/README.rdoc +0 -28
  64. data/test/dummy/app/controllers/status_controller.rb +0 -27
  65. data/test/dummy/config/initializers/secret_token.rb +0 -13
  66. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  72. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  73. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  74. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  75. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  76. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  77. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  78. data/test/status_test.rb +0 -55
@@ -1,10 +1,5 @@
1
- Dummy::Application.routes.draw do
1
+ Rails.application.routes.draw do
2
2
 
3
- get 'exception' => 'status#exception_action'
4
- get 'error' => 'status#error_action'
5
- get 'not_found' => 'status#not_found_action'
6
- get 'unauthorized' => 'status#unauthorized_action'
7
- get 'forbidden' => 'status#forbidden_action'
8
- get 'unprocessable_entity' => 'status#unprocessable_entity_action'
3
+ resources :shops
9
4
 
10
5
  end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 921ea9f25943669d3a4b0a6c8762cb6a97a00c42732c84b3a4c80900d4f2be79081cad03e0ec8d5d0f2f293874b2bbd04c1444e7a6d6b9147de8f4ffb3acff11
15
+
16
+ test:
17
+ secret_key_base: 0e085a62fbfd58069441e0eb7dd8c3d0a7035017443181a5fba2c04041a03f8d0d427216ac56a51da79125898d125bb9fb8badb48404919fe3188eb309231570
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
@@ -0,0 +1,9 @@
1
+ class CreateShops < ActiveRecord::Migration
2
+ def change
3
+ create_table :shops do |t|
4
+ t.boolean :enabled
5
+ t.boolean :visible
6
+ t.string :name
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class CreateRecords < ActiveRecord::Migration
2
+ def change
3
+ create_table :records do |t|
4
+ end
5
+ end
6
+ end
@@ -11,6 +11,20 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 0) do
14
+ ActiveRecord::Schema.define(version: 20161022144717) do
15
+
16
+ # These are extensions that must be enabled in order to support this database
17
+ enable_extension "plpgsql"
18
+
19
+ create_table "records", force: :cascade do |t|
20
+ end
21
+
22
+ create_table "shops", force: :cascade do |t|
23
+ t.boolean "enabled"
24
+ t.boolean "visible"
25
+ t.string "name"
26
+ t.datetime "created_at", null: false
27
+ t.datetime "updated_at", null: false
28
+ end
15
29
 
16
30
  end
@@ -0,0 +1,70 @@
1
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2
+  (0.3ms) BEGIN
3
+ ------------------------------
4
+ HelpersTest: test_active_trail
5
+ ------------------------------
6
+  (0.2ms) ROLLBACK
7
+  (0.1ms) BEGIN
8
+ --------------------------------
9
+ HelpersTest: test_content_tag_if
10
+ --------------------------------
11
+  (0.2ms) ROLLBACK
12
+  (0.1ms) BEGIN
13
+ ---------------------------
14
+ HelpersTest: test_extending
15
+ ---------------------------
16
+ Rendered layouts/application.html.erb (0.3ms)
17
+ Rendered layouts/market.html.erb (7.7ms)
18
+  (0.2ms) ROLLBACK
19
+  (0.1ms) BEGIN
20
+ -----------------------------
21
+ ValidationsTest: test_methods
22
+ -----------------------------
23
+  (0.2ms) ROLLBACK
24
+  (0.1ms) BEGIN
25
+ --------------------------
26
+ ValidationsTest: test_time
27
+ --------------------------
28
+  (0.2ms) ROLLBACK
29
+  (0.2ms) BEGIN
30
+ --------------------------------
31
+ ValidationsTest: test_complexity
32
+ --------------------------------
33
+  (0.2ms) ROLLBACK
34
+  (0.2ms) BEGIN
35
+ ---------------------------
36
+ ValidationsTest: test_count
37
+ ---------------------------
38
+  (0.3ms) ROLLBACK
39
+  (0.1ms) BEGIN
40
+ -------------------------------
41
+ ControllersTest: test_callbacks
42
+ -------------------------------
43
+  (0.1ms) ROLLBACK
44
+  (0.2ms) BEGIN
45
+ ----------------------------
46
+ ControllersTest: test_render
47
+ ----------------------------
48
+  (0.2ms) ROLLBACK
49
+  (0.1ms) BEGIN
50
+ -------------------------------
51
+ MailersTest: test_normalization
52
+ -------------------------------
53
+ Rendered user_mailer/invite.text.erb (0.3ms)
54
+
55
+ UserMailer#invite: processed outbound mail in 11.4ms
56
+  (0.2ms) ROLLBACK
57
+  (0.2ms) BEGIN
58
+ -------------------------------
59
+ RecordsTest: test_nilify_blanks
60
+ -------------------------------
61
+  (0.1ms) SAVEPOINT active_record_1
62
+ SQL (0.4ms) INSERT INTO "shops" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2016-10-22 15:50:31.994321"], ["updated_at", "2016-10-22 15:50:31.994321"]]
63
+  (0.1ms) RELEASE SAVEPOINT active_record_1
64
+ Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = $1 LIMIT 1 [["id", 11]]
65
+  (0.2ms) ROLLBACK
66
+  (0.2ms) BEGIN
67
+ --------------------------
68
+ RecordsTest: test_validate
69
+ --------------------------
70
+  (0.1ms) ROLLBACK
@@ -2,17 +2,23 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
6
  <style>
6
7
  body {
7
8
  background-color: #EFEFEF;
8
9
  color: #2E2F30;
9
10
  text-align: center;
10
11
  font-family: arial, sans-serif;
12
+ margin: 0;
11
13
  }
12
14
 
13
15
  div.dialog {
14
- width: 25em;
15
- margin: 4em auto 0 auto;
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
16
22
  border: 1px solid #CCC;
17
23
  border-right-color: #999;
18
24
  border-left-color: #999;
@@ -21,7 +27,8 @@
21
27
  border-top-left-radius: 9px;
22
28
  border-top-right-radius: 9px;
23
29
  background-color: white;
24
- padding: 7px 4em 0 4em;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
25
32
  }
26
33
 
27
34
  h1 {
@@ -30,19 +37,19 @@
30
37
  line-height: 1.5em;
31
38
  }
32
39
 
33
- body > p {
34
- width: 33em;
35
- margin: 0 auto 1em;
36
- padding: 1em 0;
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
37
43
  background-color: #F7F7F7;
38
44
  border: 1px solid #CCC;
39
45
  border-right-color: #999;
46
+ border-left-color: #999;
40
47
  border-bottom-color: #999;
41
48
  border-bottom-left-radius: 4px;
42
49
  border-bottom-right-radius: 4px;
43
50
  border-top-color: #DADADA;
44
51
  color: #666;
45
- box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
46
53
  }
47
54
  </style>
48
55
  </head>
@@ -50,9 +57,11 @@
50
57
  <body>
51
58
  <!-- This file lives in public/404.html -->
52
59
  <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>
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>
55
65
  </div>
56
- <p>If you are the application owner check the logs for more information.</p>
57
66
  </body>
58
67
  </html>
@@ -2,17 +2,23 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
6
  <style>
6
7
  body {
7
8
  background-color: #EFEFEF;
8
9
  color: #2E2F30;
9
10
  text-align: center;
10
11
  font-family: arial, sans-serif;
12
+ margin: 0;
11
13
  }
12
14
 
13
15
  div.dialog {
14
- width: 25em;
15
- margin: 4em auto 0 auto;
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
16
22
  border: 1px solid #CCC;
17
23
  border-right-color: #999;
18
24
  border-left-color: #999;
@@ -21,7 +27,8 @@
21
27
  border-top-left-radius: 9px;
22
28
  border-top-right-radius: 9px;
23
29
  background-color: white;
24
- padding: 7px 4em 0 4em;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
25
32
  }
26
33
 
27
34
  h1 {
@@ -30,19 +37,19 @@
30
37
  line-height: 1.5em;
31
38
  }
32
39
 
33
- body > p {
34
- width: 33em;
35
- margin: 0 auto 1em;
36
- padding: 1em 0;
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
37
43
  background-color: #F7F7F7;
38
44
  border: 1px solid #CCC;
39
45
  border-right-color: #999;
46
+ border-left-color: #999;
40
47
  border-bottom-color: #999;
41
48
  border-bottom-left-radius: 4px;
42
49
  border-bottom-right-radius: 4px;
43
50
  border-top-color: #DADADA;
44
51
  color: #666;
45
- box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
46
53
  }
47
54
  </style>
48
55
  </head>
@@ -50,9 +57,11 @@
50
57
  <body>
51
58
  <!-- This file lives in public/422.html -->
52
59
  <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>
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>
55
65
  </div>
56
- <p>If you are the application owner check the logs for more information.</p>
57
66
  </body>
58
67
  </html>
@@ -2,17 +2,23 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
6
  <style>
6
7
  body {
7
8
  background-color: #EFEFEF;
8
9
  color: #2E2F30;
9
10
  text-align: center;
10
11
  font-family: arial, sans-serif;
12
+ margin: 0;
11
13
  }
12
14
 
13
15
  div.dialog {
14
- width: 25em;
15
- margin: 4em auto 0 auto;
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
16
22
  border: 1px solid #CCC;
17
23
  border-right-color: #999;
18
24
  border-left-color: #999;
@@ -21,7 +27,8 @@
21
27
  border-top-left-radius: 9px;
22
28
  border-top-right-radius: 9px;
23
29
  background-color: white;
24
- padding: 7px 4em 0 4em;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
25
32
  }
26
33
 
27
34
  h1 {
@@ -30,19 +37,19 @@
30
37
  line-height: 1.5em;
31
38
  }
32
39
 
33
- body > p {
34
- width: 33em;
35
- margin: 0 auto 1em;
36
- padding: 1em 0;
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
37
43
  background-color: #F7F7F7;
38
44
  border: 1px solid #CCC;
39
45
  border-right-color: #999;
46
+ border-left-color: #999;
40
47
  border-bottom-color: #999;
41
48
  border-bottom-left-radius: 4px;
42
49
  border-bottom-right-radius: 4px;
43
50
  border-top-color: #DADADA;
44
51
  color: #666;
45
- box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
46
53
  }
47
54
  </style>
48
55
  </head>
@@ -50,8 +57,10 @@
50
57
  <body>
51
58
  <!-- This file lives in public/500.html -->
52
59
  <div class="dialog">
53
- <h1>We're sorry, but something went wrong.</h1>
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>
54
64
  </div>
55
- <p>If you are the application owner check the logs for more information.</p>
56
65
  </body>
57
66
  </html>
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class HelpersTest < ActionView::TestCase
4
+ include Tuning::Extensions::ActionView::Base
5
+
6
+ test 'active trail' do
7
+ set_path '/some-path/other-path'
8
+ assert active_trail?('/')
9
+ assert active_trail?('/some-path')
10
+
11
+ set_path '/'
12
+ assert active_trail?('/')
13
+ set_path '/some-path'
14
+ assert active_trail?('/some-path')
15
+
16
+ set_path '/'
17
+ assert_not active_trail?('/some-path')
18
+ set_path '/some-path'
19
+ assert_not active_trail?('/other-path')
20
+ end
21
+
22
+ test 'content tag if' do
23
+ assert_equal 'content', content_tag_if(false, :a) { 'content' }
24
+ assert_equal '<a>content</a>', content_tag_if(true, :a) { 'content' }
25
+ assert_equal '<a href="#">content</a>', content_tag_if(true, :a, href: '#') { 'content' }
26
+ end
27
+
28
+ test 'extending' do
29
+ assert_equal '<!DOCTYPE html><p>content</p>', render(template: 'layouts/market').gsub(/\n\s+/, '')
30
+ end
31
+
32
+ private
33
+
34
+ def set_path(path)
35
+ self.request = ActionDispatch::TestRequest.new
36
+ self.request.path = path
37
+ end
38
+
39
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class MailersTest < ActionMailer::TestCase
4
+
5
+ test 'normalization' do
6
+ email = UserMailer.invite('test@mail.com')
7
+ assert_equal "Hi there,\n\nPlease come check our website!\n\n-- Signature\n", email.body.to_s
8
+ end
9
+
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class RecordsTest < ActiveSupport::TestCase
4
+
5
+ test 'nilify blanks' do
6
+ shop = Shop.new(name: '')
7
+ shop.save
8
+ assert_nil shop.name
9
+ assert_nil shop.reload.name
10
+ end
11
+
12
+ test 'validate' do
13
+ assert Shop.new.respond_to?(:validate)
14
+ end
15
+
16
+ end
data/test/test_helper.rb CHANGED
@@ -2,23 +2,10 @@
2
2
  ENV['RAILS_ENV'] = 'test'
3
3
 
4
4
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path('../dummy/db/migrate', __FILE__)]
5
6
  require 'rails/test_help'
7
+ require 'mocha/mini_test'
6
8
 
7
- Rails.backtrace_cleaner.remove_silencers!
8
-
9
- # Load support files
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
-
12
- # Load fixtures from the engine
13
- if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
- ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
15
- end
16
-
17
- # Load database
18
- config = YAML::load(File.read(File.expand_path('../dummy/config/database.yml', __FILE__)))
19
- config['test']['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
20
- ActiveRecord::Base.establish_connection(config['test'])
21
- load(File.expand_path('../dummy/db/schema.rb', __FILE__))
22
-
23
- # Include helpers
24
- ActionView::TestCase.send :include, Tuning::ActionView::Base
9
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
10
+ # to be shown.
11
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new