incline 0.1.5

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 (303) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +186 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +208 -0
  7. data/Rakefile +37 -0
  8. data/app/assets/fonts/incline/.keep +0 -0
  9. data/app/assets/images/incline/.keep +0 -0
  10. data/app/assets/images/incline/barcode-B.svg +181 -0
  11. data/app/assets/javascripts/incline/activate_classed_items.js +11 -0
  12. data/app/assets/javascripts/incline/application.js +30 -0
  13. data/app/assets/javascripts/incline/bootstrap-datepicker.js +1800 -0
  14. data/app/assets/javascripts/incline/datatables.js +22193 -0
  15. data/app/assets/javascripts/incline/escapeHtml.js +10 -0
  16. data/app/assets/javascripts/incline/inline_actions.js +479 -0
  17. data/app/assets/javascripts/incline/jquery.doubleScroll.js +112 -0
  18. data/app/assets/javascripts/incline/jquery.number.js +764 -0
  19. data/app/assets/javascripts/incline/regexMask.js +27 -0
  20. data/app/assets/javascripts/incline/select2/i18n/en.js +3 -0
  21. data/app/assets/javascripts/incline/select2/select2.full.js +6436 -0
  22. data/app/assets/stylesheets/incline/application.css +18 -0
  23. data/app/assets/stylesheets/incline/bootstrap-theme.min.css +5 -0
  24. data/app/assets/stylesheets/incline/custom.scss +279 -0
  25. data/app/assets/stylesheets/incline/datatables.css +494 -0
  26. data/app/assets/stylesheets/incline/datepicker3.css +790 -0
  27. data/app/assets/stylesheets/incline/select2.css +484 -0
  28. data/app/controllers/incline/access_groups_controller.rb +127 -0
  29. data/app/controllers/incline/access_test_controller.rb +30 -0
  30. data/app/controllers/incline/account_activations_controller.rb +28 -0
  31. data/app/controllers/incline/application_controller.rb +11 -0
  32. data/app/controllers/incline/contact_controller.rb +34 -0
  33. data/app/controllers/incline/password_resets_controller.rb +113 -0
  34. data/app/controllers/incline/security_controller.rb +100 -0
  35. data/app/controllers/incline/sessions_controller.rb +50 -0
  36. data/app/controllers/incline/users_controller.rb +304 -0
  37. data/app/controllers/incline/welcome_controller.rb +19 -0
  38. data/app/helpers/incline/.keep +0 -0
  39. data/app/mailers/incline/application_mailer_base.rb +11 -0
  40. data/app/mailers/incline/contact_form.rb +19 -0
  41. data/app/mailers/incline/user_mailer.rb +45 -0
  42. data/app/models/incline/access_group.rb +121 -0
  43. data/app/models/incline/access_group_group_member.rb +12 -0
  44. data/app/models/incline/access_group_user_member.rb +10 -0
  45. data/app/models/incline/action_group.rb +12 -0
  46. data/app/models/incline/action_security.rb +222 -0
  47. data/app/models/incline/contact_message.rb +37 -0
  48. data/app/models/incline/disable_info.rb +20 -0
  49. data/app/models/incline/password_reset.rb +14 -0
  50. data/app/models/incline/password_reset_request.rb +14 -0
  51. data/app/models/incline/user.rb +437 -0
  52. data/app/models/incline/user_login_history.rb +30 -0
  53. data/app/views/incline/access_groups/_details.json.jbuilder +10 -0
  54. data/app/views/incline/access_groups/_form.html.erb +19 -0
  55. data/app/views/incline/access_groups/_list.html.erb +60 -0
  56. data/app/views/incline/access_groups/_messages.json.jbuilder +6 -0
  57. data/app/views/incline/access_groups/edit.html.erb +2 -0
  58. data/app/views/incline/access_groups/index.html.erb +6 -0
  59. data/app/views/incline/access_groups/index.json.jbuilder +16 -0
  60. data/app/views/incline/access_groups/new.html.erb +2 -0
  61. data/app/views/incline/access_groups/show.html.erb +9 -0
  62. data/app/views/incline/access_groups/show.json.jbuilder +11 -0
  63. data/app/views/incline/contact/new.html.erb +22 -0
  64. data/app/views/incline/contact_form/contact.html.erb +16 -0
  65. data/app/views/incline/contact_form/contact.text.erb +13 -0
  66. data/app/views/incline/password_resets/edit.html.erb +16 -0
  67. data/app/views/incline/password_resets/new.html.erb +12 -0
  68. data/app/views/incline/security/_details.json.jbuilder +7 -0
  69. data/app/views/incline/security/_form.html.erb +20 -0
  70. data/app/views/incline/security/_list.html.erb +89 -0
  71. data/app/views/incline/security/_messages.json.jbuilder +6 -0
  72. data/app/views/incline/security/edit.html.erb +2 -0
  73. data/app/views/incline/security/index.html.erb +6 -0
  74. data/app/views/incline/security/index.json.jbuilder +16 -0
  75. data/app/views/incline/security/show.html.erb +31 -0
  76. data/app/views/incline/security/show.json.jbuilder +11 -0
  77. data/app/views/incline/sessions/new.html.erb +26 -0
  78. data/app/views/incline/user_mailer/account_activation.html.erb +7 -0
  79. data/app/views/incline/user_mailer/account_activation.text.erb +6 -0
  80. data/app/views/incline/user_mailer/invalid_password_reset.html.erb +3 -0
  81. data/app/views/incline/user_mailer/invalid_password_reset.text.erb +5 -0
  82. data/app/views/incline/user_mailer/password_reset.html.erb +8 -0
  83. data/app/views/incline/user_mailer/password_reset.text.erb +7 -0
  84. data/app/views/incline/users/_details.json.jbuilder +32 -0
  85. data/app/views/incline/users/_form.html.erb +21 -0
  86. data/app/views/incline/users/_list.html.erb +102 -0
  87. data/app/views/incline/users/_messages.json.jbuilder +6 -0
  88. data/app/views/incline/users/disable_confirm.html.erb +19 -0
  89. data/app/views/incline/users/edit.html.erb +5 -0
  90. data/app/views/incline/users/index.html.erb +6 -0
  91. data/app/views/incline/users/index.json.jbuilder +16 -0
  92. data/app/views/incline/users/new.html.erb +5 -0
  93. data/app/views/incline/users/show.html.erb +12 -0
  94. data/app/views/incline/users/show.json.jbuilder +11 -0
  95. data/app/views/incline/welcome/home.html.erb +5 -0
  96. data/app/views/layouts/application.html.erb +1 -0
  97. data/app/views/layouts/incline/_account_menu.html.erb +18 -0
  98. data/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
  99. data/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
  100. data/app/views/layouts/incline/_footer.html.erb +13 -0
  101. data/app/views/layouts/incline/_header.html.erb +21 -0
  102. data/app/views/layouts/incline/_html_mailer.html.erb +5 -0
  103. data/app/views/layouts/incline/_incline_app.html.erb +25 -0
  104. data/app/views/layouts/incline/_messages.html.erb +3 -0
  105. data/app/views/layouts/incline/_shim.html.erb +3 -0
  106. data/app/views/layouts/incline/_text_mailer.text.erb +1 -0
  107. data/app/views/layouts/incline/application.html.erb +1 -0
  108. data/app/views/layouts/mailer.html.erb +2 -0
  109. data/app/views/layouts/mailer.text.erb +2 -0
  110. data/bin/rails +12 -0
  111. data/bin/test_scaffold.sh +10 -0
  112. data/config/routes.rb +61 -0
  113. data/db/migrate/20170511230126_create_incline_users.rb +26 -0
  114. data/db/migrate/20170515003052_create_incline_access_groups.rb +10 -0
  115. data/db/migrate/20170515003221_create_incline_user_login_histories.rb +12 -0
  116. data/db/migrate/20170515150908_create_incline_access_group_user_members.rb +11 -0
  117. data/db/migrate/20170515151058_create_incline_access_group_group_members.rb +11 -0
  118. data/db/migrate/20170517193432_add_comments_to_incline_user.rb +5 -0
  119. data/db/migrate/20170622132700_create_incline_action_securities.rb +16 -0
  120. data/db/migrate/20170622172712_create_incline_action_groups.rb +11 -0
  121. data/db/migrate/20170622195742_add_non_standard_to_action_security.rb +5 -0
  122. data/db/migrate/20170622230422_add_visible_to_action_security.rb +5 -0
  123. data/db/seeds.rb +81 -0
  124. data/exe/new_incline_app +42 -0
  125. data/lib/generators/incline/install_generator.rb +259 -0
  126. data/lib/generators/incline/templates/_app_menu_anon.html.erb +1 -0
  127. data/lib/generators/incline/templates/_app_menu_authenticated.html.erb +1 -0
  128. data/lib/generators/incline/templates/incline_application.css +17 -0
  129. data/lib/generators/incline/templates/incline_application.html.erb +1 -0
  130. data/lib/generators/incline/templates/incline_application.js +12 -0
  131. data/lib/generators/incline/templates/incline_database.yml +25 -0
  132. data/lib/generators/incline/templates/incline_email.yml +20 -0
  133. data/lib/generators/incline/templates/incline_mailer.html.erb +2 -0
  134. data/lib/generators/incline/templates/incline_mailer.text.erb +2 -0
  135. data/lib/generators/incline/templates/incline_users.yml +64 -0
  136. data/lib/generators/incline/templates/incline_version.rb +3 -0
  137. data/lib/incline/auth_engine_base.rb +52 -0
  138. data/lib/incline/data_tables_request.rb +336 -0
  139. data/lib/incline/date_time_formats.rb +6 -0
  140. data/lib/incline/engine.rb +212 -0
  141. data/lib/incline/errors.rb +15 -0
  142. data/lib/incline/extensions/action_controller_base.rb +526 -0
  143. data/lib/incline/extensions/action_mailer_base.rb +66 -0
  144. data/lib/incline/extensions/action_view_base.rb +489 -0
  145. data/lib/incline/extensions/active_record_base.rb +308 -0
  146. data/lib/incline/extensions/application.rb +137 -0
  147. data/lib/incline/extensions/application_configuration.rb +50 -0
  148. data/lib/incline/extensions/connection_adapter.rb +55 -0
  149. data/lib/incline/extensions/date_time_value.rb +123 -0
  150. data/lib/incline/extensions/date_value.rb +77 -0
  151. data/lib/incline/extensions/decimal_value.rb +55 -0
  152. data/lib/incline/extensions/erb_scaffold_generator.rb +31 -0
  153. data/lib/incline/extensions/float_value.rb +59 -0
  154. data/lib/incline/extensions/form_builder.rb +617 -0
  155. data/lib/incline/extensions/integer_value.rb +54 -0
  156. data/lib/incline/extensions/jbuilder_generator.rb +38 -0
  157. data/lib/incline/extensions/jbuilder_template.rb +39 -0
  158. data/lib/incline/extensions/main_app.rb +40 -0
  159. data/lib/incline/extensions/numeric.rb +63 -0
  160. data/lib/incline/extensions/object.rb +31 -0
  161. data/lib/incline/extensions/resource_route_generator.rb +53 -0
  162. data/lib/incline/extensions/session.rb +113 -0
  163. data/lib/incline/extensions/string.rb +50 -0
  164. data/lib/incline/extensions/test_case.rb +764 -0
  165. data/lib/incline/extensions/time_zone_converter.rb +40 -0
  166. data/lib/incline/global_status.rb +236 -0
  167. data/lib/incline/helpers/route_hash_formatter.rb +46 -0
  168. data/lib/incline/json_log_formatter.rb +96 -0
  169. data/lib/incline/json_logger.rb +17 -0
  170. data/lib/incline/log.rb +153 -0
  171. data/lib/incline/number_formats.rb +17 -0
  172. data/lib/incline/recaptcha.rb +346 -0
  173. data/lib/incline/user_manager.rb +212 -0
  174. data/lib/incline/validators/email_validator.rb +45 -0
  175. data/lib/incline/validators/ip_address_validator.rb +32 -0
  176. data/lib/incline/validators/recaptcha_validator.rb +37 -0
  177. data/lib/incline/validators/safe_name_validator.rb +31 -0
  178. data/lib/incline/version.rb +3 -0
  179. data/lib/incline/work_path.rb +75 -0
  180. data/lib/incline.rb +197 -0
  181. data/lib/tasks/incline_tasks.rake +4 -0
  182. data/lib/templates/erb/scaffold/_form.html.erb +43 -0
  183. data/lib/templates/erb/scaffold/_list.html.erb +81 -0
  184. data/lib/templates/erb/scaffold/edit.html.erb +1 -0
  185. data/lib/templates/erb/scaffold/index.html.erb +6 -0
  186. data/lib/templates/erb/scaffold/new.html.erb +1 -0
  187. data/lib/templates/erb/scaffold/show.html.erb +34 -0
  188. data/lib/templates/jbuilder/scaffold/_details.json.jbuilder +20 -0
  189. data/lib/templates/jbuilder/scaffold/index.json.jbuilder +16 -0
  190. data/lib/templates/jbuilder/scaffold/show.json.jbuilder +16 -0
  191. data/lib/templates/rails/scaffold_controller/controller.rb +128 -0
  192. data/test/controllers/incline/access_groups_controller_test.rb +65 -0
  193. data/test/controllers/incline/access_test_controller_test.rb +53 -0
  194. data/test/controllers/incline/contact_controller_test.rb +32 -0
  195. data/test/controllers/incline/security_controller_test.rb +39 -0
  196. data/test/controllers/incline/welcome_controller_test.rb +16 -0
  197. data/test/dummy/README.rdoc +28 -0
  198. data/test/dummy/Rakefile +6 -0
  199. data/test/dummy/app/assets/images/.keep +0 -0
  200. data/test/dummy/app/assets/javascripts/application.js +12 -0
  201. data/test/dummy/app/assets/stylesheets/application.css +17 -0
  202. data/test/dummy/app/controllers/application_controller.rb +5 -0
  203. data/test/dummy/app/controllers/concerns/.keep +0 -0
  204. data/test/dummy/app/helpers/application_helper.rb +2 -0
  205. data/test/dummy/app/mailers/.keep +0 -0
  206. data/test/dummy/app/models/.keep +0 -0
  207. data/test/dummy/app/models/concerns/.keep +0 -0
  208. data/test/dummy/app/views/layouts/application.html.erb +1 -0
  209. data/test/dummy/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
  210. data/test/dummy/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
  211. data/test/dummy/app/views/layouts/mailer.html.erb +2 -0
  212. data/test/dummy/app/views/layouts/mailer.text.erb +2 -0
  213. data/test/dummy/bin/bundle +3 -0
  214. data/test/dummy/bin/rails +4 -0
  215. data/test/dummy/bin/rake +4 -0
  216. data/test/dummy/bin/setup +29 -0
  217. data/test/dummy/config/application.rb +38 -0
  218. data/test/dummy/config/boot.rb +5 -0
  219. data/test/dummy/config/database.yml +34 -0
  220. data/test/dummy/config/email.yml +24 -0
  221. data/test/dummy/config/environment.rb +5 -0
  222. data/test/dummy/config/environments/development.rb +45 -0
  223. data/test/dummy/config/environments/production.rb +85 -0
  224. data/test/dummy/config/environments/test.rb +44 -0
  225. data/test/dummy/config/initializers/assets.rb +11 -0
  226. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  227. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  228. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  229. data/test/dummy/config/initializers/inflections.rb +16 -0
  230. data/test/dummy/config/initializers/mime_types.rb +4 -0
  231. data/test/dummy/config/initializers/session_store.rb +3 -0
  232. data/test/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  233. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  234. data/test/dummy/config/locales/en.yml +23 -0
  235. data/test/dummy/config/routes.rb +6 -0
  236. data/test/dummy/config.ru +4 -0
  237. data/test/dummy/db/schema.rb +108 -0
  238. data/test/dummy/lib/assets/.keep +0 -0
  239. data/test/dummy/log/.keep +0 -0
  240. data/test/dummy/public/404.html +67 -0
  241. data/test/dummy/public/422.html +67 -0
  242. data/test/dummy/public/500.html +66 -0
  243. data/test/dummy/public/favicon.ico +0 -0
  244. data/test/extensions/action_controller_base_extensions_test.rb +21 -0
  245. data/test/extensions/action_mailer_base_extensions_test.rb +20 -0
  246. data/test/extensions/action_view_base_extensions_test.rb +267 -0
  247. data/test/extensions/active_record_extensions_test.rb +173 -0
  248. data/test/extensions/application_configuration_extensions_test.rb +46 -0
  249. data/test/extensions/application_extensions_test.rb +23 -0
  250. data/test/extensions/connection_adapter_extensions_test.rb +54 -0
  251. data/test/extensions/date_time_value_extensions_test.rb +104 -0
  252. data/test/extensions/date_value_extensions_test.rb +102 -0
  253. data/test/extensions/decimal_value_extensions_test.rb +85 -0
  254. data/test/extensions/erb_scaffold_generator_extensions_test.rb +17 -0
  255. data/test/extensions/float_value_extensions_test.rb +78 -0
  256. data/test/extensions/form_builder_extensions_test.rb +28 -0
  257. data/test/extensions/integer_value_extensions_test.rb +78 -0
  258. data/test/extensions/jbuilder_generator_extensions_test.rb +21 -0
  259. data/test/extensions/jbuilder_template_extensions_test.rb +47 -0
  260. data/test/extensions/main_app_extensions_test.rb +55 -0
  261. data/test/extensions/numeric_extensions_test.rb +76 -0
  262. data/test/extensions/object_extensions_test.rb +104 -0
  263. data/test/extensions/session_extensions_test.rb +69 -0
  264. data/test/extensions/string_extensions_test.rb +32 -0
  265. data/test/extensions/test_case_extensions_test.rb +538 -0
  266. data/test/extensions/time_zone_converter_extensions_test.rb +10 -0
  267. data/test/fixtures/incline/access_group_group_members.yml +1 -0
  268. data/test/fixtures/incline/access_group_user_members.yml +1 -0
  269. data/test/fixtures/incline/access_groups.yml +13 -0
  270. data/test/fixtures/incline/action_groups.yml +6 -0
  271. data/test/fixtures/incline/action_securities.yml +18 -0
  272. data/test/fixtures/incline/user_login_histories.yml +1 -0
  273. data/test/fixtures/incline/users.yml +64 -0
  274. data/test/incline_test.rb +63 -0
  275. data/test/integration/incline/users_edit_test.rb +180 -0
  276. data/test/integration/incline/users_login_test.rb +105 -0
  277. data/test/integration/incline/users_signup_test.rb +147 -0
  278. data/test/integration/navigation_test.rb +11 -0
  279. data/test/lib/data_tables_request_test.rb +245 -0
  280. data/test/lib/date_time_formats_test.rb +111 -0
  281. data/test/lib/global_status_test.rb +89 -0
  282. data/test/lib/json_log_formatter_test.rb +43 -0
  283. data/test/lib/log_test.rb +36 -0
  284. data/test/lib/recaptcha_test.rb +75 -0
  285. data/test/lib/user_manager_test.rb +47 -0
  286. data/test/lib/work_path_test.rb +18 -0
  287. data/test/models/incline/access_group_group_member_test.rb +30 -0
  288. data/test/models/incline/access_group_test.rb +60 -0
  289. data/test/models/incline/access_group_user_member_test.rb +29 -0
  290. data/test/models/incline/action_group_test.rb +27 -0
  291. data/test/models/incline/action_security_test.rb +176 -0
  292. data/test/models/incline/contact_message_test.rb +66 -0
  293. data/test/models/incline/disable_info_test.rb +29 -0
  294. data/test/models/incline/password_reset_request_test.rb +35 -0
  295. data/test/models/incline/password_reset_test.rb +51 -0
  296. data/test/models/incline/user_login_history_test.rb +31 -0
  297. data/test/models/incline/user_test.rb +91 -0
  298. data/test/test_helper.rb +42 -0
  299. data/test/validators/email_validator_test.rb +102 -0
  300. data/test/validators/ip_address_validator_test.rb +107 -0
  301. data/test/validators/recaptcha_validator_test.rb +57 -0
  302. data/test/validators/safe_name_validator_test.rb +101 -0
  303. metadata +584 -0
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class SessionExtensionsTest < ActionDispatch::IntegrationTest
4
+
5
+ VIEW_METHODS = [
6
+ :user_id_cookie,
7
+ :user_token_cookie,
8
+ :current_user,
9
+ :current_user?,
10
+ :logged_in?,
11
+ :system_admin?
12
+ ]
13
+
14
+ CONTROLLER_METHODS = [
15
+ :log_in,
16
+ :log_out,
17
+ :remember,
18
+ :forget
19
+ ]
20
+
21
+ # A broken mailer just to check for methods.
22
+ class TestMailer < ActionMailer::Base
23
+
24
+ def self.create_instance
25
+ new
26
+ end
27
+
28
+ end
29
+
30
+ test 'test has correct methods' do
31
+ VIEW_METHODS.each do |m|
32
+ assert respond_to?(m), "Test should respond to #{m.inspect}."
33
+ end
34
+ CONTROLLER_METHODS.each do |m|
35
+ assert_not respond_to?(m), "Test should not respond to #{m.inspect}."
36
+ end
37
+ end
38
+
39
+ test 'view has correct methods' do
40
+ view = ActionView::Base.new
41
+ VIEW_METHODS.each do |m|
42
+ assert view.respond_to?(m), "View should respond to #{m.inspect}."
43
+ end
44
+ CONTROLLER_METHODS.each do |m|
45
+ assert_not view.respond_to?(m), "View should not respond to #{m.inspect}."
46
+ end
47
+ end
48
+
49
+ test 'controller has correct methods' do
50
+ ctrlr = ActionController::Base.new
51
+ VIEW_METHODS.each do |m|
52
+ assert ctrlr.respond_to?(m), "Controller should respond to #{m.inspect}."
53
+ end
54
+ CONTROLLER_METHODS.each do |m|
55
+ assert ctrlr.respond_to?(m), "Controller should respond to #{m.inspect}."
56
+ end
57
+ end
58
+
59
+ test 'mailer has correct methods' do
60
+ mailer = TestMailer.create_instance
61
+ VIEW_METHODS.each do |m|
62
+ assert mailer.respond_to?(m), "Mailer should respond to #{m.inspect}."
63
+ end
64
+ CONTROLLER_METHODS.each do |m|
65
+ assert_not mailer.respond_to?(m), "Mailer should not respond to #{m.inspect}."
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class StringExtensionsTest < ActiveSupport::TestCase
4
+
5
+ test 'string has to_hex_string and to_byte_string' do
6
+ s = 'hello'
7
+ assert s.respond_to?(:to_hex_string)
8
+ assert s.respond_to?(:to_byte_string)
9
+ end
10
+
11
+ test 'hex and byte conversion works' do
12
+ s_text = 'Hello World'
13
+ s_hex = '48656c6c6f20576f726c64'
14
+ assert_equal s_hex, s_text.to_hex_string
15
+ assert_equal s_text, s_hex.to_byte_string
16
+ s_text += s_hex
17
+ assert_equal s_text, s_text.to_hex_string.to_byte_string
18
+ end
19
+
20
+ test 'hex grouping works' do
21
+ s_text = 'Hello World'
22
+ s_hex = '48 65 6c 6c 6f 20 57 6f 72 6c 64'
23
+ assert_equal s_hex, s_text.to_hex_string(true)
24
+ assert_equal s_text, s_text.to_hex_string(true).to_byte_string
25
+ s_hex = '486 56c 6c6 f20 576 f72 6c6 4'
26
+ assert_equal s_hex, s_text.to_hex_string(3)
27
+ assert_equal s_text, s_text.to_hex_string(3).to_byte_string
28
+ end
29
+
30
+
31
+
32
+ end
@@ -0,0 +1,538 @@
1
+ require 'test_helper'
2
+
3
+ class TestCaseExtensionsTest < ActiveSupport::TestCase
4
+
5
+ TEST_TABLE_NAME = "test_table_#{SecureRandom.random_number(1<<16).to_s(16).rjust(4,'0')}"
6
+ TEST_TABLE_CLASS = TEST_TABLE_NAME.classify.to_sym
7
+
8
+ class TestRamModel
9
+ include ActiveModel::Model
10
+ include ActiveModel::Validations
11
+
12
+ attr_accessor :recaptcha, :email, :ip_any, :ip_mask, :ip_nomask, :session, :safe_name
13
+
14
+ validates :recaptcha, 'incline/recaptcha' => true
15
+ validates :email, 'incline/email' => true
16
+ validates :ip_any, 'incline/ip_address' => true
17
+ validates :ip_mask, 'incline/ip_address' => { require_mask: true }
18
+ validates :ip_nomask, 'incline/ip_address' => { no_mask: true }
19
+ validates :safe_name, 'incline/safe_name' => true
20
+ end
21
+
22
+ def with_db_model
23
+ begin
24
+ # Create a test table.
25
+ silence_stream STDOUT do
26
+ ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
27
+ t.integer :group, null: false
28
+ t.string :name, null: false, limit: 30
29
+ t.string :description, limit: 100
30
+ end
31
+ end
32
+
33
+ # And then create a test model.
34
+ eval <<-EOM
35
+ class #{TEST_TABLE_CLASS} < ActiveRecord::Base
36
+ self.table_name = #{TEST_TABLE_NAME.inspect}
37
+
38
+ validates :group,
39
+ presence: true
40
+
41
+ validates :name,
42
+ presence: true,
43
+ length: { minimum: 5, maximum: 30 },
44
+ uniqueness: { case_sensitive: false, scope: :group }
45
+
46
+ validates :description,
47
+ length: { maximum: 100 }
48
+ end
49
+ EOM
50
+
51
+ model_class = self.class.const_get TEST_TABLE_CLASS
52
+ item = model_class.new(group: 1, name: 'Hello', description: 'World')
53
+
54
+ yield model_class, item
55
+ ensure
56
+ # Undefine the model class (or at least remove it from the Object namespace).
57
+ begin
58
+ self.class.send :remove_const, TEST_TABLE_CLASS
59
+ rescue
60
+ Incline::Log::error 'Failed to remove test model class.'
61
+ end
62
+
63
+ # Remove the table from the database.
64
+ begin
65
+ silence_stream STDOUT do
66
+ ActiveRecord::Migration::drop_table TEST_TABLE_NAME
67
+ end
68
+ rescue
69
+ Incline::Log::error 'Failed to drop test model table.'
70
+ end
71
+ end
72
+ end
73
+
74
+ def setup
75
+ @item = TestRamModel.new(session: 99, email: 'user@example.com', recaptcha: Incline::Recaptcha::DISABLED)
76
+ end
77
+
78
+ test 'have extension methods' do
79
+ assert respond_to?(:is_logged_in?)
80
+ assert respond_to?(:log_in_as)
81
+ assert respond_to?(:assert_required)
82
+ assert respond_to?(:assert_max_length)
83
+ assert respond_to?(:assert_min_length)
84
+ assert respond_to?(:assert_uniqueness)
85
+ assert respond_to?(:assert_recaptcha_validation)
86
+ assert respond_to?(:assert_email_validation)
87
+ assert respond_to?(:assert_ip_validation)
88
+ assert respond_to?(:assert_safe_name_validation)
89
+ end
90
+
91
+ test 'item should be valid' do
92
+ with_db_model do |klass,item|
93
+ assert item.valid?
94
+ end
95
+ assert @item.valid?
96
+ end
97
+
98
+ test 'item should require group' do
99
+ with_db_model do |klass,item|
100
+ assert_required item, :group
101
+ end
102
+ end
103
+
104
+ test 'item should require name' do
105
+ with_db_model do |klass,item|
106
+ assert_required item, :name
107
+ end
108
+ end
109
+
110
+ test 'item name should have min length' do
111
+ with_db_model do |klass,item|
112
+ assert_min_length item, :name, 5
113
+ end
114
+ end
115
+
116
+ test 'item name should have max length' do
117
+ with_db_model do |klass,item|
118
+ assert_max_length item, :name, 30
119
+ end
120
+ end
121
+
122
+ test 'item name should be unique within group' do
123
+ with_db_model do |klass,item|
124
+ assert_uniqueness item, :name, group: 2
125
+ end
126
+ end
127
+
128
+ test 'item description should have max length' do
129
+ with_db_model do |klass,item|
130
+ assert_max_length item, :description, 100
131
+ end
132
+ end
133
+
134
+ test 'item recaptcha should pass validation' do
135
+ assert_recaptcha_validation @item, :recaptcha
136
+ end
137
+
138
+ test 'item email should pass validation' do
139
+ assert_email_validation @item, :email
140
+ end
141
+
142
+ test 'item ips should pass validation' do
143
+ assert_ip_validation @item, :ip_any
144
+ assert_ip_validation @item, :ip_mask, :require_mask
145
+ assert_ip_validation @item, :ip_nomask, :deny_mask
146
+ end
147
+
148
+ test 'item safe_name should pass validation' do
149
+ assert_safe_name_validation @item, :safe_name, 10
150
+ end
151
+
152
+ test 'item description should not be required' do
153
+ with_db_model do |klass,item|
154
+ assert_raises(Minitest::Assertion) { assert_required item, :description }
155
+ end
156
+ end
157
+
158
+ test 'item description length is not limited to 50, 101, or 10' do
159
+ with_db_model do |klass,item|
160
+ assert_raises(Minitest::Assertion) { assert_max_length item, :description, 50 }
161
+ assert_raises(Minitest::Assertion) { assert_max_length item, :description, 101 }
162
+ assert_raises(Minitest::Assertion) { assert_min_length item, :description, 10 }
163
+ end
164
+ end
165
+
166
+ test 'item name is unique across descriptions' do
167
+ with_db_model do |klass,item|
168
+ assert_raises(Minitest::Assertion) { assert_uniqueness item, :name, description: 'something else' }
169
+ end
170
+ end
171
+
172
+ test 'item description is not a recaptcha field' do
173
+ with_db_model do |klass,item|
174
+ assert_raises(Minitest::Assertion) { assert_recaptcha_validation item, :description }
175
+ end
176
+
177
+ end
178
+
179
+ test 'item description is not an ip address field' do
180
+ with_db_model do |klass,item|
181
+ assert_raises(Minitest::Assertion) { assert_ip_validation item, :description }
182
+ end
183
+ end
184
+
185
+ test 'item description is not an email address field' do
186
+ with_db_model do |klass,item|
187
+ assert_raises(Minitest::Assertion) { assert_email_validation item, :description }
188
+ end
189
+ end
190
+
191
+ test 'item description is not a safe name field' do
192
+ with_db_model do |klass, item|
193
+ assert_raises(Minitest::Assertion) { assert_safe_name_validation item, :description }
194
+ end
195
+ end
196
+
197
+ DEFAULT_ACCESS_TEST_ANON = <<-EOC
198
+ test "should not allow access to something for anonymous" do
199
+ path = foo_path
200
+ get(path)
201
+ assert_redirected_to incline.login_path
202
+ end
203
+ EOC
204
+
205
+ DEFAULT_ACCESS_TEST_ANY = <<-EOC
206
+ test "should not allow access to something for any user" do
207
+ user = incline_users(:basic)
208
+ log_in_as user
209
+ path = foo_path
210
+ get(path)
211
+ assert_redirected_to main_app.root_path
212
+ end
213
+ EOC
214
+
215
+ DEFAULT_ACCESS_TEST_ADMIN = <<-EOC
216
+ test "should allow access to something for admin user" do
217
+ user = incline_users(:admin)
218
+ log_in_as user
219
+ path = foo_path
220
+ get(path)
221
+ assert_response :success
222
+ end
223
+ EOC
224
+
225
+ test 'access_tests_for default tests are good' do
226
+ valid = [ DEFAULT_ACCESS_TEST_ANON, DEFAULT_ACCESS_TEST_ANY, DEFAULT_ACCESS_TEST_ADMIN ].join
227
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path'
228
+ assert_equal valid, code
229
+ end
230
+
231
+ test 'access_tests_for respects allow_anon' do
232
+ valid = [ <<-EOC, DEFAULT_ACCESS_TEST_ANY, DEFAULT_ACCESS_TEST_ADMIN ].join
233
+ test "should allow access to something for anonymous" do
234
+ path = foo_path
235
+ get(path)
236
+ assert_response :success
237
+ end
238
+ EOC
239
+
240
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', allow_anon: true
241
+
242
+ assert_equal valid, code
243
+ end
244
+
245
+ test 'access_tests_for respects allow_any_user' do
246
+ valid = [ DEFAULT_ACCESS_TEST_ANON, <<-EOC, DEFAULT_ACCESS_TEST_ADMIN ].join
247
+ test "should allow access to something for any user" do
248
+ user = incline_users(:basic)
249
+ log_in_as user
250
+ path = foo_path
251
+ get(path)
252
+ assert_response :success
253
+ end
254
+ EOC
255
+
256
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', allow_any_user: true
257
+
258
+ assert_equal valid, code
259
+ end
260
+
261
+ test 'access_tests_for respects allow_admin' do
262
+ valid = [ DEFAULT_ACCESS_TEST_ANON, DEFAULT_ACCESS_TEST_ANY, <<-EOC ].join
263
+ test "should not allow access to something for admin user" do
264
+ user = incline_users(:admin)
265
+ log_in_as user
266
+ path = foo_path
267
+ get(path)
268
+ assert_redirected_to main_app.root_path
269
+ end
270
+ EOC
271
+
272
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', allow_admin: false
273
+
274
+ assert_equal valid, code
275
+ end
276
+
277
+ test 'access_tests_for respects allow_groups' do
278
+ valid = [ DEFAULT_ACCESS_TEST_ANON, DEFAULT_ACCESS_TEST_ANY, DEFAULT_ACCESS_TEST_ADMIN, <<-EOC ].join
279
+ test "should allow access to something for Group 1 member" do
280
+ user = incline_users(:basic)
281
+ group = Incline::AccessGroup.find_or_create_by(name: "Group 1")
282
+ user.groups << group
283
+ log_in_as user
284
+ path = foo_path
285
+ get(path)
286
+ assert_response :success
287
+ end
288
+ test "should allow access to something for Group 2 member" do
289
+ user = incline_users(:basic)
290
+ group = Incline::AccessGroup.find_or_create_by(name: "Group 2")
291
+ user.groups << group
292
+ log_in_as user
293
+ path = foo_path
294
+ get(path)
295
+ assert_response :success
296
+ end
297
+ EOC
298
+
299
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', allow_groups: [ 'Group 1', 'Group 2' ]
300
+ assert_equal valid, code
301
+ end
302
+
303
+ test 'access_tests_for respects deny_groups' do
304
+ valid = [ DEFAULT_ACCESS_TEST_ANON, DEFAULT_ACCESS_TEST_ANY, DEFAULT_ACCESS_TEST_ADMIN, <<-EOC ].join
305
+ test "should not allow access to something for Group 1 member" do
306
+ user = incline_users(:basic)
307
+ group = Incline::AccessGroup.find_or_create_by(name: "Group 1")
308
+ user.groups << group
309
+ log_in_as user
310
+ path = foo_path
311
+ get(path)
312
+ assert_redirected_to main_app.root_path
313
+ end
314
+ test "should not allow access to something for Group 2 member" do
315
+ user = incline_users(:basic)
316
+ group = Incline::AccessGroup.find_or_create_by(name: "Group 2")
317
+ user.groups << group
318
+ log_in_as user
319
+ path = foo_path
320
+ get(path)
321
+ assert_redirected_to main_app.root_path
322
+ end
323
+ EOC
324
+
325
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', deny_groups: [ 'Group 1', 'Group 2' ]
326
+ assert_equal valid, code
327
+ end
328
+
329
+ test 'access_tests_for respects success value' do
330
+ valid = [ DEFAULT_ACCESS_TEST_ANON, DEFAULT_ACCESS_TEST_ANY, <<-EOC ].join
331
+ test "should allow access to something for admin user" do
332
+ user = incline_users(:admin)
333
+ log_in_as user
334
+ path = foo_path
335
+ get(path)
336
+ assert_redirected_to bar_path
337
+ end
338
+ EOC
339
+
340
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', success: 'bar_path'
341
+ assert_equal valid, code
342
+ end
343
+
344
+ test 'access_tests_for respects failure value' do
345
+ valid = [ DEFAULT_ACCESS_TEST_ANON, <<-EOC, DEFAULT_ACCESS_TEST_ADMIN ].join
346
+ test "should not allow access to something for any user" do
347
+ user = incline_users(:basic)
348
+ log_in_as user
349
+ path = foo_path
350
+ get(path)
351
+ assert_redirected_to bar_path
352
+ end
353
+ EOC
354
+
355
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', failure: 'bar_path'
356
+ assert_equal valid, code
357
+ end
358
+
359
+ test 'access_tests_for respects anon_failure value' do
360
+ valid = [ <<-EOC, DEFAULT_ACCESS_TEST_ANY, DEFAULT_ACCESS_TEST_ADMIN ].join
361
+ test "should not allow access to something for anonymous" do
362
+ path = foo_path
363
+ get(path)
364
+ assert_redirected_to bar_path
365
+ end
366
+ EOC
367
+
368
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', anon_failure: 'bar_path'
369
+ assert_equal valid, code
370
+ end
371
+
372
+ test 'access_tests_for respects method value' do
373
+ valid = <<-EOC
374
+ test "should not allow access to something for anonymous" do
375
+ path = foo_path
376
+ delete(path)
377
+ assert_redirected_to incline.login_path
378
+ end
379
+ test "should not allow access to something for any user" do
380
+ user = incline_users(:basic)
381
+ log_in_as user
382
+ path = foo_path
383
+ delete(path)
384
+ assert_redirected_to main_app.root_path
385
+ end
386
+ test "should allow access to something for admin user" do
387
+ user = incline_users(:admin)
388
+ log_in_as user
389
+ path = foo_path
390
+ delete(path)
391
+ assert_redirected_to foobars_path
392
+ end
393
+ EOC
394
+
395
+ code = self.class.access_tests_for :something, return_code: true, controller: 'foobar', url_helper: 'foo_path', method: 'delete'
396
+ assert_equal valid, code
397
+ end
398
+
399
+ test 'access_tests_for guesses at url_helper correctly' do
400
+ original = <<-EOC
401
+ test "should not allow access to index for anonymous" do
402
+ path = foobars_path
403
+ get(path)
404
+ assert_redirected_to incline.login_path
405
+ end
406
+ test "should not allow access to index for any user" do
407
+ user = incline_users(:basic)
408
+ log_in_as user
409
+ path = foobars_path
410
+ get(path)
411
+ assert_redirected_to main_app.root_path
412
+ end
413
+ test "should allow access to index for admin user" do
414
+ user = incline_users(:admin)
415
+ log_in_as user
416
+ path = foobars_path
417
+ get(path)
418
+ assert_response :success
419
+ end
420
+ EOC
421
+
422
+ # index
423
+ code = self.class.access_tests_for :index, return_code: true, controller: 'foobar'
424
+ assert_equal original, code
425
+
426
+ # show
427
+ valid = original
428
+ .gsub('access to index', 'access to show')
429
+ .gsub('path = foobars_path', 'path = foobar_path(foobars(:one))')
430
+ code = self.class.access_tests_for :show, return_code: true, controller: 'foobar'
431
+ assert_equal valid, code
432
+
433
+ # edit
434
+ valid = original
435
+ .gsub('access to index', 'access to edit')
436
+ .gsub('path = foobars_path', 'path = edit_foobar_path(foobars(:one))')
437
+ code = self.class.access_tests_for :edit, return_code: true, controller: 'foobar'
438
+ assert_equal valid, code
439
+
440
+ # update
441
+ valid = original
442
+ .gsub('access to index', 'access to update')
443
+ .gsub('path = foobars_path', 'path = foobar_path(foobars(:one))')
444
+ .gsub('get(path)', 'patch(path)')
445
+ .gsub('assert_response :success', 'assert_redirected_to foobars_path')
446
+ code = self.class.access_tests_for :update, return_code: true, controller: 'foobar'
447
+ assert_equal valid, code
448
+
449
+ # new
450
+ valid = original
451
+ .gsub('access to index', 'access to new')
452
+ .gsub('path = foobars_path', 'path = new_foobar_path')
453
+ code = self.class.access_tests_for :new, return_code: true, controller: 'foobar'
454
+ assert_equal valid, code
455
+
456
+ # create
457
+ valid = original
458
+ .gsub('access to index', 'access to create')
459
+ .gsub('get(path)', 'post(path)')
460
+ .gsub('assert_response :success', 'assert_redirected_to foobars_path')
461
+ code = self.class.access_tests_for :create, return_code: true, controller: 'foobar'
462
+ assert_equal valid, code
463
+
464
+ # destroy
465
+ valid = original
466
+ .gsub('access to index', 'access to destroy')
467
+ .gsub('path = foobars_path', 'path = foobar_path(foobars(:one))')
468
+ .gsub('get(path)', 'delete(path)')
469
+ .gsub('assert_response :success', 'assert_redirected_to foobars_path')
470
+ code = self.class.access_tests_for :destroy, return_code: true, controller: 'foobar'
471
+ assert_equal valid, code
472
+
473
+ # index + show
474
+ valid = original +
475
+ original
476
+ .gsub('access to index', 'access to show')
477
+ .gsub('path = foobars_path', 'path = foobar_path(foobars(:one))')
478
+ code = self.class.access_tests_for [ :index, :show ], return_code: true, controller: 'foobar'
479
+ assert_equal valid, code
480
+
481
+ # the actions can be specified as an explicit array or as additional parameters.
482
+ # as long as the options are specified last, it will work.
483
+ code = self.class.access_tests_for :index, :show, return_code: true, controller: 'foobar'
484
+ assert_equal valid, code
485
+ end
486
+
487
+ test 'access_tests_for respects the fixture_helper value for guessed url_helpers' do
488
+ code = self.class.access_tests_for :show, return_code: true, controller: 'foobar', fixture_helper: 'foobazzes'
489
+ assert_equal <<-EOC, code
490
+ test "should not allow access to show for anonymous" do
491
+ path = foobar_path(foobazzes(:one))
492
+ get(path)
493
+ assert_redirected_to incline.login_path
494
+ end
495
+ test "should not allow access to show for any user" do
496
+ user = incline_users(:basic)
497
+ log_in_as user
498
+ path = foobar_path(foobazzes(:one))
499
+ get(path)
500
+ assert_redirected_to main_app.root_path
501
+ end
502
+ test "should allow access to show for admin user" do
503
+ user = incline_users(:admin)
504
+ log_in_as user
505
+ path = foobar_path(foobazzes(:one))
506
+ get(path)
507
+ assert_response :success
508
+ end
509
+ EOC
510
+ end
511
+
512
+ test 'access_tests_for respects the fixture_key value for guessed url_helpers' do
513
+ code = self.class.access_tests_for :show, return_code: true, controller: 'foobar', fixture_key: :forty_two
514
+ assert_equal <<-EOC, code
515
+ test "should not allow access to show for anonymous" do
516
+ path = foobar_path(foobars(:forty_two))
517
+ get(path)
518
+ assert_redirected_to incline.login_path
519
+ end
520
+ test "should not allow access to show for any user" do
521
+ user = incline_users(:basic)
522
+ log_in_as user
523
+ path = foobar_path(foobars(:forty_two))
524
+ get(path)
525
+ assert_redirected_to main_app.root_path
526
+ end
527
+ test "should allow access to show for admin user" do
528
+ user = incline_users(:admin)
529
+ log_in_as user
530
+ path = foobar_path(foobars(:forty_two))
531
+ get(path)
532
+ assert_response :success
533
+ end
534
+ EOC
535
+ end
536
+
537
+
538
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class TimeZoneConverterExtensionsTest < ActiveSupport::TestCase
4
+
5
+ # The effects of the extensions should be felt in other tests, this one simply verifies that the extension has been included.
6
+ test 'should include TimeZoneConverter extension' do
7
+ assert ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.include? Incline::Extensions::TimeZoneConverter
8
+ end
9
+
10
+ end
@@ -0,0 +1 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
@@ -0,0 +1 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
@@ -0,0 +1,13 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ name: Group 1
5
+
6
+ two:
7
+ name: Group 2
8
+
9
+ three:
10
+ name: Group 3
11
+
12
+ four:
13
+ name: Group 4
@@ -0,0 +1,6 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ test_require_group:
4
+ action_security: test_require_group
5
+ access_group: one
6
+
@@ -0,0 +1,18 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+ one:
3
+ controller_name: world
4
+ action_name: hello
5
+ path: /world/hello
6
+ visible: true
7
+
8
+ two:
9
+ controller_name: foo
10
+ action_name: bar
11
+ path: /foo/bar
12
+ visible: true
13
+
14
+ test_require_group:
15
+ controller_name: incline/access_test
16
+ action_name: test_require_group
17
+ path: /incline/test/require_group
18
+ visible: true
@@ -0,0 +1 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html