scatter_swapper 0.3.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 (106) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.md +21 -0
  4. data/Rakefile +30 -0
  5. data/lib/ext/rails/action_controller/obfuscator.rb +18 -0
  6. data/lib/ext/rails/active_record/obfuscator.rb +9 -0
  7. data/lib/scatter_swap.rb +30 -0
  8. data/lib/scatter_swap/hasher.rb +98 -0
  9. data/lib/scatter_swap/run.rb +93 -0
  10. data/lib/scatter_swap/version.rb +3 -0
  11. data/lib/scatter_swapper.rb +8 -0
  12. data/lib/scatter_swapper/configuration.rb +21 -0
  13. data/lib/scatter_swapper/engine.rb +23 -0
  14. data/lib/scatter_swapper/version.rb +3 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/config/manifest.js +4 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  18. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  19. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  20. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  21. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  23. data/spec/dummy/app/controllers/products_controller.rb +5 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/jobs/application_job.rb +2 -0
  26. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  27. data/spec/dummy/app/models/application_record.rb +3 -0
  28. data/spec/dummy/app/models/product.rb +2 -0
  29. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  31. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  32. data/spec/dummy/app/views/products/show.html.erb +1 -0
  33. data/spec/dummy/bin/bundle +3 -0
  34. data/spec/dummy/bin/rails +4 -0
  35. data/spec/dummy/bin/rake +4 -0
  36. data/spec/dummy/bin/setup +34 -0
  37. data/spec/dummy/bin/update +29 -0
  38. data/spec/dummy/config.ru +5 -0
  39. data/spec/dummy/config/application.rb +15 -0
  40. data/spec/dummy/config/boot.rb +5 -0
  41. data/spec/dummy/config/cable.yml +9 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +54 -0
  45. data/spec/dummy/config/environments/production.rb +86 -0
  46. data/spec/dummy/config/environments/test.rb +42 -0
  47. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  48. data/spec/dummy/config/initializers/assets.rb +11 -0
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  51. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/spec/dummy/config/initializers/inflections.rb +16 -0
  53. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  54. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  55. data/spec/dummy/config/initializers/session_store.rb +3 -0
  56. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/spec/dummy/config/locales/en.yml +23 -0
  58. data/spec/dummy/config/puma.rb +47 -0
  59. data/spec/dummy/config/routes.rb +4 -0
  60. data/spec/dummy/config/secrets.yml +22 -0
  61. data/spec/dummy/config/spring.rb +6 -0
  62. data/spec/dummy/db/migrate/20161005174710_create_products.rb +6 -0
  63. data/spec/dummy/db/schema.rb +18 -0
  64. data/spec/dummy/db/test.sqlite3 +0 -0
  65. data/spec/dummy/log/development.log +0 -0
  66. data/spec/dummy/log/test.log +2094 -0
  67. data/spec/dummy/public/404.html +67 -0
  68. data/spec/dummy/public/422.html +67 -0
  69. data/spec/dummy/public/500.html +66 -0
  70. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  71. data/spec/dummy/public/apple-touch-icon.png +0 -0
  72. data/spec/dummy/public/favicon.ico +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4X/4XqW7VPZr2Y6Zqt02vR0CcMUOTOjCd25G2oW7u9KhBc.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6L/6L4feDvIbZEbLi3sESVSzmMvY3tFWkBTHTRwQfzLzoI.cache +1 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Bu/BuE1MKiZRiA2ei8bcxwYLjyJdTpEy4wxW852s55oNNk.cache +1 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/CE/CE5DGZEH9y0snNT45v25qIPc45wsznAviN6HLO6e04o.cache +1 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DO/DORBTyAOLvfL9rAmgDHLzChNdxQSC12MecLn9eigz8g.cache +1 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/FQ/FQxGtXX5z7AKIBv1JU_-tAR-KiyoPaYdpDGdatI-HsA.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/GT/GT-f7w_E3cEGHS6pJrn83Cix3Z8lEWnosqX-x1Hh42c.cache +1 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IK/IKb0FntHxXnlCyVchY4VUrzWmqysAPvPqVCJhc_AJjU.cache +1 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/JD/JDCUTDoF2rC0R-NS53x4NhZ_wcTPq8E_ccURRvkjrbg.cache +3 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/M4/M4D-0ZpI2t7XsfOVSm85cQfXE9GVBWVH1Y7vzI00d7o.cache +2 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Mh/Mhzf0rpLZVXBSmJkZSw7S8BjpYsj8HmgsG6nGRDEcLQ.cache +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qp/Qpkoqed0UuRM6qvNCxiFc3SPEjhkfsuMSukOq4dYUNo.cache +1 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VH/VHaBur7LnA7kgAtiXpY22v0aQkBWOFSTzVH3i3hH2Bg.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vv/VviPzDHPOuLlGJWdGBm5P3F3xUDHrDm8Ulz2K5R0RYU.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/W0/W0uTQRHqzQj0C4wgLX55zhV3K0cnz0Q_JBhdYzsbRls.cache +1 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/b-/b-ZN5Mf92R5XLHvBNThDj9wY56ctPdfONViJHGIbJAg.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/b_/b_Itlk9QZZd7Rvf8kcA4yLP1R5Acu7jB-m1xQiSU0qE.cache +2 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lV/lVt8G4NTNqewg9C9PXeaR1Abtx7AHu0vaSkHAhGWR0M.cache +1 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mX/mX1nlsL_SWOB4y22W5FheRX0YEONKyOY7xUeIvRiHco.cache +2 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mt/mtcHS-4C2owd8bjhO4wTCvArR0UZjvhGnn7bxyxUmec.cache +1 -0
  93. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nC/nC5Vv_N9ICSY-OdjPBzWULwOUy7IO7ugOGV2RAQPYRw.cache +1 -0
  94. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/n_/n_xYqQYhwEMQknb3jFQnjlxxBE9TzMNHCdJ-bEyZFIw.cache +2 -0
  95. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nx/nxTv3sKVUQZADJyM3dPaVmUA78MIsMLD_K279yN_GsI.cache +2 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/rJ/rJs4Papy2IL4JNryEPrcUBNrc64xnKDvqo0tfQu7NS4.cache +1 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sE/sEz6mxBNwtI3fGWPauHZO9BzFXOvCivWdI9oGRKFT1o.cache +1 -0
  98. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7PYh8DJvPykcEqpVab2vcY9-GFz-3cqtoMlRAu94Uc.cache +2 -0
  99. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yR/yRtopfP_e1z4fqF6apVsxZDI3pCtWFSRfFkmpIOFcq0.cache +1 -0
  100. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yX/yX8aXb78CFZHgzB3A6MVhi9nC0V-efr_Z8CvseJ6T0M.cache +0 -0
  101. data/spec/ext/rails/action_controller/obfuscator_spec.rb +30 -0
  102. data/spec/ext/rails/active_record/obfuscator_spec.rb +10 -0
  103. data/spec/rails_helper.rb +59 -0
  104. data/spec/scatter_swap_spec.rb +179 -0
  105. data/spec/spec_helper.rb +99 -0
  106. metadata +310 -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
File without changes
@@ -0,0 +1 @@
1
+ "%�<������X���̀#+�����,�(o���
@@ -0,0 +1 @@
1
+ "%A�>��N�6�n���f��9��V�~K��
@@ -0,0 +1 @@
1
+ I"�app/assets/javascripts/cable.js?type=application/javascript&pipeline=self&id=a8f4e9db313f2d1f20668f865da56bc289bd4a06f8227391a4870f232c9fa55e:ET
@@ -0,0 +1 @@
1
+ I"}app/assets/stylesheets/application.css?type=text/css&id=4c709bbb8f0edf776998166ebc0360ac3ef99fa1556608d4304562015458bad9:ET
@@ -0,0 +1 @@
1
+ I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=2b107aa23a03bfe94c583e524e02444e54416f75b786995cffb262bc6cb08f59:ET
@@ -0,0 +1 @@
1
+ "%��B�����șo�$'�A�d��L���xR�U
@@ -0,0 +1,3 @@
1
+ [o:Set:
2
+ @hash}
3
+ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"�file-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled/action_cable.js;TTF
@@ -0,0 +1,2 @@
1
+ "%��T���l�
2
+ %�`H�!o��"��}�M�g�
@@ -0,0 +1 @@
1
+ "%�aY}�)�vH`�=�T��y��-��0�@��g~�
@@ -0,0 +1 @@
1
+ I"�app/assets/javascripts/application.js?type=application/javascript&id=3d3f25288b4519a9be50969feabd94958e7d9064b36991c18b742da339e69ca9:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"8file-digest://app/assets/javascripts/application.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"�file-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled/action_cable.js;TTI"2file-digest://app/assets/javascripts/cable.js;TTI"$file-digest://app/assets/config;TTI"1file-digest://app/assets/config/action_cable;TTI"$file-digest://app/assets/images;TTI"1file-digest://app/assets/images/action_cable;TTI")file-digest://app/assets/javascripts;TTI"6file-digest://app/assets/javascripts/action_cable;TTI")file-digest://app/assets/stylesheets;TTI"6file-digest://app/assets/stylesheets/action_cable;TTI"vfile-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled;TTI"~file-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled/action_cable;TTI"2file-digest://app/assets/javascripts/channels;TTF
@@ -0,0 +1 @@
1
+ "%�d�-�K���`���8Y��3�͹/Y����a~K
@@ -0,0 +1 @@
1
+ I"�app/assets/stylesheets/application.css?type=text/css&pipeline=self&id=c0a82080b57c80a6ba99d3a71b6d4b418c68d3541e1a99a482a7d5271321c62d:ET
@@ -0,0 +1 @@
1
+ I"�/home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled/action_cable.js?type=application/javascript&pipeline=self&id=77038a55f9b81d309dcf8bdfb3916236a56a0e8e92e2405b8abd64756ff270a5:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash} I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"9file-digest://app/assets/stylesheets/application.css;TTI")file-digest://app/assets/stylesheets;TTF
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash} I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"0processors:type=text/css&file_type=text/css;TTI"9file-digest://app/assets/stylesheets/application.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI")file-digest://app/assets/stylesheets;TTF
@@ -0,0 +1 @@
1
+ "%��B�����șo�$'�A�d��L���xR�U
@@ -0,0 +1 @@
1
+ "%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"2file-digest://app/assets/javascripts/cable.js;TTI"$file-digest://app/assets/config;TTI"1file-digest://app/assets/config/action_cable;TTI"$file-digest://app/assets/images;TTI"1file-digest://app/assets/images/action_cable;TTI")file-digest://app/assets/javascripts;TTI"6file-digest://app/assets/javascripts/action_cable;TTI")file-digest://app/assets/stylesheets;TTI"6file-digest://app/assets/stylesheets/action_cable;TTI"vfile-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled;TTI"~file-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled/action_cable;TTI"�file-digest:///home/plebel/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled/action_cable.js;TTI"2file-digest://app/assets/javascripts/channels;TTF
@@ -0,0 +1 @@
1
+ "%A��G �{h t�l�m�V���NE���f���
@@ -0,0 +1,30 @@
1
+ require 'rails_helper'
2
+
3
+ describe ProductsController, type: :controller do
4
+ describe '#show' do
5
+ let(:encoded_id) { 623140965 }
6
+ let(:decoded_id) { 1 }
7
+
8
+ it 'converts :id param' do
9
+ get :show, params: { id: encoded_id }
10
+
11
+ expect(response.body).to include("<p>#{decoded_id}</p>")
12
+ end
13
+
14
+ context 'when ' do
15
+ before do
16
+ ScatterSwapper.configure do |config|
17
+ config.skip_controller_params = true
18
+ end
19
+ end
20
+
21
+ after { ScatterSwapper.class_variable_set :@@config, nil }
22
+
23
+ it 'does not convert :id params' do
24
+ get :show, params: { id: encoded_id }
25
+
26
+ expect(response.body).to include("<p>#{encoded_id}</p>")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails_helper'
2
+
3
+ describe Product, type: :model do
4
+ let(:encoded_id) { 623140965 }
5
+ let(:decoded_id) { 1 }
6
+
7
+ subject { Product.new(id: decoded_id) }
8
+
9
+ it { expect(subject.encoded_id).to eq(encoded_id) }
10
+ end
@@ -0,0 +1,59 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.expand_path('../dummy/config/environment', __FILE__)
4
+ # Prevent database truncation if the environment is production
5
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
6
+ require 'spec_helper'
7
+ require 'rspec/rails'
8
+ # Add additional requires below this line. Rails is not loaded until this point!
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc, in
11
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
+ # run as spec files by default. This means that files in spec/support that end
13
+ # in _spec.rb will both be required and run as specs, causing the specs to be
14
+ # run twice. It is recommended that you do not name files matching this glob to
15
+ # end with _spec.rb. You can configure this pattern with the --pattern
16
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
+ #
18
+ # The following line is provided for convenience purposes. It has the downside
19
+ # of increasing the boot-up time by auto-requiring all files in the support
20
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
+ # require only the support files necessary.
22
+ #
23
+ # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
24
+
25
+ # Checks for pending migration and applies them before tests are run.
26
+ # If you are not using ActiveRecord, you can remove this line.
27
+ ActiveRecord::Migration.maintain_test_schema!
28
+
29
+ RSpec.configure do |config|
30
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
31
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
32
+
33
+ config.render_views
34
+
35
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
36
+ # examples within a transaction, remove the following line or assign false
37
+ # instead of true.
38
+ config.use_transactional_fixtures = true
39
+
40
+ # RSpec Rails can automatically mix in different behaviours to your tests
41
+ # based on their file location, for example enabling you to call `get` and
42
+ # `post` in specs under `spec/controllers`.
43
+ #
44
+ # You can disable this behaviour by removing the line below, and instead
45
+ # explicitly tag your specs with their type, e.g.:
46
+ #
47
+ # RSpec.describe UsersController, :type => :controller do
48
+ # # ...
49
+ # end
50
+ #
51
+ # The different available types are documented in the features, such as in
52
+ # https://relishapp.com/rspec/rspec-rails/docs
53
+ config.infer_spec_type_from_file_location!
54
+
55
+ # Filter lines from Rails gems in backtraces.
56
+ config.filter_rails_from_backtrace!
57
+ # arbitrary gems may also be filtered via:
58
+ # config.filter_gems_from_backtrace("gem name")
59
+ end
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScatterSwap do
4
+
5
+ it 'has a version number' do
6
+ expect(ScatterSwap::VERSION).not_to be nil
7
+ end
8
+
9
+ describe '#hash' do
10
+
11
+ it 'should not be sequential' do
12
+ 100.times do |integer|
13
+ first = ScatterSwap.hash(integer)
14
+ second = ScatterSwap.hash(integer + 1)
15
+ expect(second).not_to eq(first.to_i + 1)
16
+ end
17
+ end
18
+
19
+
20
+ it 'should be reversible' do
21
+ 100.times do |integer|
22
+ hashed = ScatterSwap.hash(integer)
23
+ expect(ScatterSwap.reverse_hash(hashed).to_i).to eq(integer)
24
+ # puts "#{integer.to_s.rjust(4)} -> #{ScatterSwap.hash(integer)} -> #{ScatterSwap.reverse_hash(hashed).to_i.to_s.rjust(4)}"
25
+ end
26
+ end
27
+
28
+
29
+ it 'should be consistent across platforms' do
30
+ expect(ScatterSwap.hash(1234, 0, 10)).to eq('3942201503')
31
+ expect(ScatterSwap.hash(9876543210, 99, 10)).to eq('5529302155')
32
+ end
33
+
34
+
35
+ it 'should produce a different value for each seed' do
36
+ integer = 12345
37
+ results = []
38
+ 100.times do |seed|
39
+ results << ScatterSwap.hash(integer, seed)
40
+ end
41
+ results = results.sort.uniq
42
+ expect(results.size).to eq(100)
43
+ # results.each_with_index { |r, i| puts "#{i.to_s.rjust(2)} -> #{r}" }
44
+ end
45
+
46
+
47
+ describe 'uniqueness of output' do
48
+
49
+ let(:seed) { 12345 }
50
+ let(:length) { 3 }
51
+ let(:max) { '9'.ljust(length, '9').to_i }
52
+
53
+ it 'should produce unique results' do
54
+ # puts "Testing numbers 0 to #{max}"
55
+ results = []
56
+ (0..max).each do |input|
57
+ results << ScatterSwap.hash(input, seed, length)
58
+ end
59
+
60
+ expect(results.length).to eq(max + 1)
61
+ sorted = results.sort.uniq
62
+ expect(sorted.length).to eq(max + 1)
63
+
64
+ (0...max).each do |i|
65
+ expect(sorted[i].to_i).to eq(i)
66
+ end
67
+ end
68
+ end
69
+
70
+
71
+ describe 'length' do
72
+
73
+ context 'default' do
74
+ it 'should produce 10 digits' do
75
+ 100.times do |integer|
76
+ expect(ScatterSwap.hash(integer).to_s.length).to eq 10
77
+ end
78
+ end
79
+ end
80
+
81
+ context '7 to 12 digits' do
82
+
83
+ let(:seed) { 0 }
84
+
85
+ (7..12).each do |length|
86
+
87
+ it 'should produce 10 digits' do
88
+ 100.times do |input|
89
+ output = ScatterSwap.hash(input, seed, length)
90
+ expect(output.to_s.length).to eq length
91
+ end
92
+ end
93
+
94
+ it 'should be reversible' do
95
+ 100.times do |input|
96
+ hashed = ScatterSwap.hash(input, seed, length)
97
+ reversed = ScatterSwap.reverse_hash(hashed, seed, length).to_i
98
+ expect(reversed).to eq(input)
99
+ # puts "#{input.to_s.rjust(4)} -> #{hashed} -> #{reversed.to_s.rjust(4)}"
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+ describe 'private methods' do
109
+
110
+ describe '#swapper_map' do
111
+
112
+ let(:swapper_map_size) { 10.freeze } # Must ALWAYS be 10!
113
+
114
+ before do
115
+ @map_set = []
116
+ s = ScatterSwap::Hasher.new(1)
117
+ swapper_map_size.times do |digit|
118
+ @map_set.push s.send(:swapper_map, digit) # Use send to access :private methods
119
+ end
120
+ end
121
+
122
+ it 'should create a unique map array for each digit' do
123
+ expect(@map_set.length).to eq(swapper_map_size)
124
+ expect(@map_set.uniq.length).to eq(swapper_map_size)
125
+ end
126
+
127
+ it 'should include all 10 digits in each map' do
128
+ @map_set.each do |map|
129
+ expect(map.length).to eq(swapper_map_size)
130
+ expect(map.uniq.length).to eq(swapper_map_size)
131
+ end
132
+ end
133
+ end
134
+
135
+
136
+ describe '#scatter' do
137
+ it 'should return a number different from original' do
138
+ 100.times do |integer|
139
+ s = ScatterSwap::Hasher.new(integer)
140
+ original_array = s.working_array
141
+ s.send(:scatter)
142
+ expect(s.working_array).not_to eq(original_array)
143
+ end
144
+ end
145
+
146
+ it 'should be reversible' do
147
+ 100.times do |integer|
148
+ s = ScatterSwap::Hasher.new(integer)
149
+ original_array = s.working_array.clone
150
+ s.send(:scatter)
151
+ s.send(:unscatter)
152
+ expect(s.working_array).to eq(original_array)
153
+ end
154
+ end
155
+ end
156
+
157
+
158
+ describe '#swap' do
159
+ it 'should be different from original' do
160
+ 100.times do |integer|
161
+ s = ScatterSwap::Hasher.new(integer)
162
+ original_array = s.working_array.clone
163
+ s.send(:swap)
164
+ expect(s.working_array).not_to eq(original_array)
165
+ end
166
+ end
167
+
168
+ it 'should be reversible' do
169
+ 100.times do |integer|
170
+ s = ScatterSwap::Hasher.new(integer)
171
+ original_array = s.working_array.clone
172
+ s.send(:swap)
173
+ s.send(:unswap)
174
+ expect(s.working_array).to eq(original_array)
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end