slugs 2.0.1 → 4.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +59 -19
  3. data/Rakefile +1 -19
  4. data/lib/generators/slugs/install/install_generator.rb +24 -0
  5. data/lib/generators/slugs/{templates/configuration.rb → install/templates/initializer.rb} +1 -1
  6. data/lib/generators/slugs/install/templates/migration.rb +15 -0
  7. data/lib/slugs.rb +7 -4
  8. data/lib/slugs/concern.rb +16 -9
  9. data/lib/slugs/configuration.rb +11 -1
  10. data/lib/slugs/extensions/action_dispatch/generator.rb +1 -0
  11. data/lib/slugs/extensions/action_dispatch/optimized_url_helper.rb +1 -0
  12. data/lib/slugs/extensions/active_record/finders.rb +27 -0
  13. data/lib/slugs/railtie.rb +10 -4
  14. data/lib/slugs/slug.rb +9 -0
  15. data/lib/slugs/version.rb +1 -1
  16. data/test/dummy/bin/bundle +1 -0
  17. data/test/dummy/bin/rails +1 -0
  18. data/test/dummy/bin/rake +1 -0
  19. data/test/dummy/bin/setup +1 -0
  20. data/test/dummy/config/database.yml.travis +2 -11
  21. data/test/dummy/config/environments/development.rb +1 -1
  22. data/test/dummy/config/environments/production.rb +1 -1
  23. data/test/dummy/config/environments/test.rb +2 -2
  24. data/test/dummy/config/initializers/slugs.rb +1 -1
  25. data/test/dummy/config/secrets.yml +2 -2
  26. data/test/dummy/db/migrate/20161016174020_create_users.rb +2 -0
  27. data/test/dummy/db/migrate/20161016174126_create_shops.rb +2 -0
  28. data/test/dummy/db/migrate/20161016174202_create_products.rb +2 -0
  29. data/test/dummy/db/migrate/20161016174225_create_categories.rb +2 -0
  30. data/test/dummy/db/migrate/20161124162802_create_slugs.rb +15 -0
  31. data/test/dummy/db/schema.rb +33 -13
  32. data/test/dummy/log/development.log +394 -30
  33. data/test/dummy/log/test.log +3017 -3978
  34. data/test/dummy/public/404.html +57 -63
  35. data/test/dummy/public/422.html +57 -63
  36. data/test/dummy/public/500.html +56 -62
  37. data/test/generator_test.rb +3 -4
  38. data/test/record_test.rb +65 -0
  39. data/test/{routes_test.rb → route_test.rb} +1 -1
  40. data/test/test_helper.rb +2 -2
  41. metadata +14 -9
  42. data/lib/generators/slugs/install_generator.rb +0 -15
  43. data/test/records_test.rb +0 -27
@@ -1,67 +1,61 @@
1
1
  <!DOCTYPE html>
2
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>
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
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The page you were looking for doesn't exist.</h1>
56
+ <p>You may have mistyped the address or the page may have moved.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
63
59
  </div>
64
- <p>If you are the application owner check the logs for more information.</p>
65
- </div>
66
- </body>
60
+ </body>
67
61
  </html>
@@ -1,67 +1,61 @@
1
1
  <!DOCTYPE html>
2
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>
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
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The change you wanted was rejected.</h1>
56
+ <p>Maybe you tried to change something you didn't have access to.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
63
59
  </div>
64
- <p>If you are the application owner check the logs for more information.</p>
65
- </div>
66
- </body>
60
+ </body>
67
61
  </html>
@@ -1,66 +1,60 @@
1
1
  <!DOCTYPE html>
2
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>
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
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>We're sorry, but something went wrong.</h1>
56
+ </div>
57
+ <p>If you are the application owner check the logs for more information.</p>
62
58
  </div>
63
- <p>If you are the application owner check the logs for more information.</p>
64
- </div>
65
- </body>
59
+ </body>
66
60
  </html>
@@ -1,17 +1,16 @@
1
1
  require 'test_helper'
2
2
  require 'rails/generators'
3
- require 'generators/slugs/install_generator'
3
+ require 'generators/slugs/install/install_generator'
4
4
 
5
5
  class GeneratorsTest < Rails::Generators::TestCase
6
-
7
- tests Cronjobs::Generators::InstallGenerator
8
6
  destination Rails.root.join('tmp')
9
7
 
10
8
  teardown do
11
9
  FileUtils.rm_rf destination_root
12
10
  end
13
11
 
14
- test 'file generation' do
12
+ test 'install' do
13
+ self.class.tests Slugs::Generators::InstallGenerator
15
14
  run_generator
16
15
  assert_file 'config/initializers/slugs.rb'
17
16
  end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ class RecordTest < ActiveSupport::TestCase
4
+
5
+ test 'finders' do
6
+ user = User.create(first_name: 'Zakk', last_name: 'Wylde')
7
+ assert_equal 'zakk-wylde', user.slug
8
+ assert User.exists?('zakk-wylde')
9
+ assert User.exists?(user.id)
10
+ assert User.exists?(user.id.to_s)
11
+ assert_equal user, User.find('zakk-wylde')
12
+ assert_equal user, User.find(user.id)
13
+ assert_equal user, User.find(user.id.to_s)
14
+
15
+ user.update first_name: 'Yngwie', last_name: 'Malmsteen'
16
+ assert_equal 'yngwie-malmsteen', user.slug
17
+ assert User.exists?('zakk-wylde')
18
+ assert_equal user, User.find('zakk-wylde')
19
+ assert User.exists?('yngwie-malmsteen')
20
+ assert_equal user, User.find('yngwie-malmsteen')
21
+ assert_equal user, User.find(user.id)
22
+ assert_equal user, User.find(user.id.to_s)
23
+
24
+ user = User.create(first_name: 'Zakk', last_name: 'Wylde')
25
+ assert_equal 'zakk-wylde', user.slug
26
+ assert User.exists?('zakk-wylde')
27
+ assert User.exists?(user.id)
28
+ assert User.exists?(user.id.to_s)
29
+ assert_equal user, User.find('zakk-wylde')
30
+ assert_equal user, User.find(user.id)
31
+ assert_equal user, User.find(user.id.to_s)
32
+ end
33
+
34
+ test 'indices' do
35
+ 3.times.each do |index|
36
+ shop = Shop.create(name: 'Guitar Shop')
37
+ if index == 0
38
+ assert_equal 'guitar-shop', shop.slug
39
+ else
40
+ assert_equal "guitar-shop-#{index}", shop.slug
41
+ end
42
+ end
43
+
44
+ shop = Shop.first
45
+ 3.times.each do |index|
46
+ product = Product.create(name: 'Les Paul', shop: shop)
47
+ if index == 0
48
+ assert_equal 'les-paul', product.slug
49
+ else
50
+ assert_equal "les-paul-#{index}", product.slug
51
+ end
52
+ end
53
+
54
+ shop = Shop.last
55
+ 3.times.each do |index|
56
+ product = Product.create(name: 'Les Paul', shop: shop)
57
+ if index == 0
58
+ assert_equal 'les-paul', product.slug
59
+ else
60
+ assert_equal "les-paul-#{index}", product.slug
61
+ end
62
+ end
63
+ end
64
+
65
+ end