incline 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
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,102 @@
1
+ require 'test_helper'
2
+
3
+ class DateValueExtensionsTest < 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
+ def setup
9
+ # Create a test table.
10
+ silence_stream STDOUT do
11
+ ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
12
+ t.date :tz_value
13
+ t.date :utc_value
14
+ end
15
+ end
16
+
17
+ # And then create a test model.
18
+ eval <<-EOM
19
+ class #{TEST_TABLE_CLASS} < ActiveRecord::Base
20
+ self.table_name = #{TEST_TABLE_NAME.inspect}
21
+ self.time_zone_aware_attributes = true
22
+ self.skip_time_zone_conversion_for_attributes << :utc_value
23
+ end
24
+ EOM
25
+
26
+ @backup_ar_tz = ActiveRecord::Base.default_timezone
27
+ @backup_tm_tz = Time.zone.name
28
+ ActiveRecord::Base.default_timezone = :utc
29
+ Time.zone = 'EST'
30
+
31
+ # Store the model class for use.
32
+ @model_class = self.class.const_get TEST_TABLE_CLASS
33
+ @item = @model_class.new
34
+ end
35
+
36
+ def teardown
37
+ # Undefine the model class (or at least remove it from the Object namespace).
38
+ self.class.send :remove_const, TEST_TABLE_CLASS
39
+
40
+ # Remove the table from the database.
41
+ silence_stream STDOUT do
42
+ ActiveRecord::Migration::drop_table TEST_TABLE_NAME
43
+ end
44
+
45
+ ActiveRecord::Base.default_timezone = @backup_ar_tz
46
+ Time.zone = @backup_tm_tz
47
+ end
48
+
49
+ test 'uses correct types' do
50
+ # Dates should not be TZ aware.
51
+ col = @model_class.columns.find{|c| c.name == 'tz_value'}
52
+ assert col
53
+ assert_not col.cast_type.is_a?(::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter)
54
+ assert col.cast_type.is_a?(::ActiveRecord::Type::Date)
55
+
56
+ col = @model_class.columns.find{|c| c.name == 'utc_value'}
57
+ assert col
58
+ assert_not col.cast_type.is_a?(::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter)
59
+ assert col.cast_type.is_a?(::ActiveRecord::Type::Date)
60
+ end
61
+
62
+ test 'accepts valid values' do
63
+ {
64
+ '2016-12-31' => Date.new(2016,12,31),
65
+ '12/31/2016' => Date.new(2016,12,31),
66
+ '16-12-31' => Date.new(2016,12,31),
67
+ '12/31/16' => Date.new(2016,12,31),
68
+ '1/1/2017' => Date.new(2017,1,1),
69
+ '2017-1-1' => Date.new(2017,1,1),
70
+ '01/01/2017' => Date.new(2017,1,1),
71
+ '2017-01-01' => Date.new(2017,1,1)
72
+ }.each do |s,v|
73
+ @item.utc_value = s
74
+ assert_equal v, @item.utc_value, "Should have accepted #{s.inspect}"
75
+
76
+ # Time zones should not apply to dates!
77
+ @item.tz_value = s
78
+ assert_equal v, @item.tz_value, "Should have accepted #{s.inspect}"
79
+ end
80
+
81
+ end
82
+
83
+ test 'rejects invalid values' do
84
+
85
+ [
86
+ '',
87
+ ' ',
88
+ '0000-00-00',
89
+ '2016-13-31',
90
+ '2016-12-32',
91
+ '2016-02-30',
92
+ '2/30/2016',
93
+ ].each do |val|
94
+ @item.tz_value = val
95
+ assert_nil @item.tz_value, "Should have rejected #{val.inspect}"
96
+ @item.utc_value = val
97
+ assert_nil @item.utc_value, "Should have rejected #{val.inspect}"
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,85 @@
1
+ require 'test_helper'
2
+
3
+ class DecimalValueExtensionsTest < 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
+ def setup
9
+ # Create a test table.
10
+ silence_stream STDOUT do
11
+ ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
12
+ t.decimal :scaled_value, precision: 12, scale: 4
13
+ t.decimal :unscaled_value, precision: 12
14
+ end
15
+ end
16
+
17
+ # And then create a test model.
18
+ eval <<-EOM
19
+ class #{TEST_TABLE_CLASS} < ActiveRecord::Base
20
+ self.table_name = #{TEST_TABLE_NAME.inspect}
21
+ end
22
+ EOM
23
+
24
+ # Store the model class for use.
25
+ @model_class = self.class.const_get TEST_TABLE_CLASS
26
+ @item = @model_class.new
27
+ end
28
+
29
+ def teardown
30
+ # Undefine the model class (or at least remove it from the Object namespace).
31
+ self.class.send :remove_const, TEST_TABLE_CLASS
32
+
33
+ # Remove the table from the database.
34
+ silence_stream STDOUT do
35
+ ActiveRecord::Migration::drop_table TEST_TABLE_NAME
36
+ end
37
+ end
38
+
39
+ test 'accepts valid values' do
40
+ {
41
+ '1234' => BigDecimal(1234, 12),
42
+ '1,234' => BigDecimal(1234, 12),
43
+ '12.34' => BigDecimal(12.34, 12),
44
+ '1,234.5678' => BigDecimal(1234.5678, 12),
45
+ '1234567' => BigDecimal(1234567.0, 12),
46
+ '1,234,567' => BigDecimal(1234567.0, 12),
47
+ '0' => BigDecimal(0.0, 12),
48
+ '0.0' => BigDecimal(0.0, 12),
49
+ '+125' => BigDecimal(125.0, 12),
50
+ '-125' => BigDecimal(-125.0, 12),
51
+ '+1,234' => BigDecimal(1234.0, 12),
52
+ '-1,234' => BigDecimal(-1234.0, 12)
53
+ }.each do |s,v|
54
+ @item.scaled_value = s
55
+ assert_equal v.round(4), @item.scaled_value, "#{s.inspect} did not parse to #{v}"
56
+ @item.unscaled_value = s
57
+ assert_equal v.to_i, @item.unscaled_value, "#{s.inspect} did not parse to #{v}"
58
+ end
59
+ [ 0, 1234, 567.89 ].each do |v|
60
+ @item.scaled_value = v
61
+ assert_equal BigDecimal(v, 6).round(4), @item.scaled_value
62
+ @item.unscaled_value = v
63
+ assert_equal v.to_i, @item.unscaled_value
64
+ end
65
+ end
66
+
67
+ test 'rejects invalid values' do
68
+ [
69
+ '',
70
+ '1,2,3,4',
71
+ ',234',
72
+ '1,2345',
73
+ '0,001',
74
+ ].each do |v|
75
+ @item.scaled_value = v
76
+ assert_nil @item.scaled_value
77
+ @item.unscaled_value = v
78
+ assert_nil @item.unscaled_value
79
+ end
80
+ end
81
+
82
+
83
+
84
+
85
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class ErbScaffoldGeneratorExtensionsTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @gen = Erb::Generators::ScaffoldGenerator.new [ 'fake_item' ]
7
+ end
8
+
9
+ test 'should have the correct available_views' do
10
+ req = %w(index new edit show _list _form)
11
+ actual = @gen.send :available_views
12
+ req.each do |view|
13
+ assert actual.include?(view), "Missing '#{view}' view."
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_helper'
2
+
3
+ class FloatValueExtensionsTest < 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
+ def setup
9
+ # Create a test table.
10
+ silence_stream STDOUT do
11
+ ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
12
+ t.float :my_value
13
+ end
14
+ end
15
+
16
+ # And then create a test model.
17
+ eval <<-EOM
18
+ class #{TEST_TABLE_CLASS} < ActiveRecord::Base
19
+ self.table_name = #{TEST_TABLE_NAME.inspect}
20
+ end
21
+ EOM
22
+
23
+ # Store the model class for use.
24
+ @model_class = self.class.const_get TEST_TABLE_CLASS
25
+ @item = @model_class.new
26
+ end
27
+
28
+ def teardown
29
+ # Undefine the model class (or at least remove it from the Object namespace).
30
+ self.class.send :remove_const, TEST_TABLE_CLASS
31
+
32
+ # Remove the table from the database.
33
+ silence_stream STDOUT do
34
+ ActiveRecord::Migration::drop_table TEST_TABLE_NAME
35
+ end
36
+ end
37
+
38
+ test 'accepts valid values' do
39
+ {
40
+ '1234' => 1234.0,
41
+ '1,234' => 1234.0,
42
+ '12.34' => 12.34,
43
+ '1,234.5678' => 1234.5678,
44
+ '1234567' => 1234567.0,
45
+ '1,234,567' => 1234567.0,
46
+ '0' => 0.0,
47
+ '0.0' => 0.0,
48
+ '+125' => 125.0,
49
+ '-125' => -125.0,
50
+ '+1,234' => 1234.0,
51
+ '-1,234' => -1234.0
52
+ }.each do |s,v|
53
+ @item.my_value = s
54
+ assert_equal v, @item.my_value, "#{s.inspect} did not parse to #{v}"
55
+ end
56
+ [ 0, 1234, 567.89 ].each do |v|
57
+ @item.my_value = v
58
+ assert_equal v.to_f, @item.my_value
59
+ end
60
+ end
61
+
62
+ test 'rejects invalid values' do
63
+ [
64
+ '',
65
+ '1,2,3,4',
66
+ ',234',
67
+ '1,2345',
68
+ '0,001',
69
+ ].each do |v|
70
+ @item.my_value = v
71
+ assert_nil @item.my_value
72
+ end
73
+ end
74
+
75
+
76
+
77
+
78
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class FormBuilderExtensionsTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @builder = ActionView::Helpers::FormBuilder.new('my_object', Object.new, 'no template', { })
7
+ end
8
+
9
+ test 'should have additional methods' do
10
+ assert @builder.respond_to?(:date_picker)
11
+ assert @builder.respond_to?(:multi_input)
12
+ assert @builder.respond_to?(:currency_field)
13
+ assert @builder.respond_to?(:label_w_small)
14
+ assert @builder.respond_to?(:text_form_group)
15
+ assert @builder.respond_to?(:password_form_group)
16
+ assert @builder.respond_to?(:textarea_form_group)
17
+ assert @builder.respond_to?(:currency_form_group)
18
+ assert @builder.respond_to?(:static_form_group)
19
+ assert @builder.respond_to?(:datepicker_form_group)
20
+ assert @builder.respond_to?(:multi_input_form_group)
21
+ assert @builder.respond_to?(:check_box_form_group)
22
+ assert @builder.respond_to?(:select_form_group)
23
+ assert @builder.respond_to?(:recaptcha)
24
+ end
25
+
26
+ # TODO: Test output of various methods.
27
+
28
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_helper'
2
+
3
+ class IntegerValueExtensionsTest < 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
+ def setup
9
+ # Create a test table.
10
+ silence_stream STDOUT do
11
+ ActiveRecord::Migration::create_table TEST_TABLE_NAME do |t|
12
+ t.integer :my_value
13
+ end
14
+ end
15
+
16
+ # And then create a test model.
17
+ eval <<-EOM
18
+ class #{TEST_TABLE_CLASS} < ActiveRecord::Base
19
+ self.table_name = #{TEST_TABLE_NAME.inspect}
20
+ end
21
+ EOM
22
+
23
+ # Store the model class for use.
24
+ @model_class = self.class.const_get TEST_TABLE_CLASS
25
+ @item = @model_class.new
26
+ end
27
+
28
+ def teardown
29
+ # Undefine the model class (or at least remove it from the Object namespace).
30
+ self.class.send :remove_const, TEST_TABLE_CLASS
31
+
32
+ # Remove the table from the database.
33
+ silence_stream STDOUT do
34
+ ActiveRecord::Migration::drop_table TEST_TABLE_NAME
35
+ end
36
+ end
37
+
38
+ test 'accepts valid values' do
39
+ {
40
+ '1234' => 1234,
41
+ '1,234' => 1234,
42
+ '12.34' => 12,
43
+ '1,234.5678' => 1234,
44
+ '1234567' => 1234567,
45
+ '1,234,567' => 1234567,
46
+ '0' => 0,
47
+ '0.0' => 0,
48
+ '+125' => 125,
49
+ '-125' => -125,
50
+ '+1,234' => 1234,
51
+ '-1,234' => -1234
52
+ }.each do |s,v|
53
+ @item.my_value = s
54
+ assert_equal v, @item.my_value, "#{s.inspect} did not parse to #{v}"
55
+ end
56
+ [ 0, 1234, 567.89 ].each do |v|
57
+ @item.my_value = v
58
+ assert_equal v.to_i, @item.my_value
59
+ end
60
+ end
61
+
62
+ test 'rejects invalid values' do
63
+ [
64
+ '',
65
+ '1,2,3,4',
66
+ ',234',
67
+ '1,2345',
68
+ '0,001',
69
+ ].each do |v|
70
+ @item.my_value = v
71
+ assert_nil @item.my_value
72
+ end
73
+ end
74
+
75
+
76
+
77
+
78
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class JbuilderGeneratorExtensionsTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @gen = Rails::Generators::JbuilderGenerator.new [ 'fake_item' ]
7
+ end
8
+
9
+ test 'responds to available_views' do
10
+ assert @gen.respond_to?(:available_views, true)
11
+ end
12
+
13
+ test 'should have the correct available_views' do
14
+ req = %w(index show _details)
15
+ actual = @gen.send :available_views
16
+ req.each do |view|
17
+ assert actual.include?(view), "Missing '#{view}' view."
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ require 'json'
3
+
4
+ class JbuilderTemplateExtensionsTest < ActiveSupport::TestCase
5
+
6
+ class TestClass
7
+
8
+ attr_reader :errors
9
+
10
+ def initialize
11
+ @errors = {
12
+ :base => [ 'something bad happened' ],
13
+ :name => 'is too long',
14
+ :code => [ 'is not uppercase', 'is too long' ]
15
+ }
16
+ end
17
+ end
18
+
19
+ def setup
20
+ @json = JbuilderTemplate.new(self)
21
+ @item = TestClass.new
22
+ end
23
+
24
+ test 'has extension methods' do
25
+ assert @json.respond_to?(:api_errors!)
26
+ end
27
+
28
+ test 'builds expected values' do
29
+ @json.api_errors! 'test_class', @item.errors
30
+ val = JSON.parse(@json.target!)
31
+
32
+ assert val.is_a?(::Hash)
33
+
34
+ assert val['error'].is_a?(::String)
35
+ assert_equal 'Test class ' + @item.errors[:base].first, val['error']
36
+
37
+ assert val['fieldErrors'].is_a?(::Array)
38
+ assert_equal 2, val['fieldErrors'].count
39
+ e = val['fieldErrors'].find{|v| v['name'] == 'test_class.name'}
40
+ assert e
41
+ assert_equal 'Name is too long', e['status']
42
+ e = val['fieldErrors'].find{|v| v['name'] == 'test_class.code'}
43
+ assert e
44
+ assert_equal "Code is not uppercase<br>\nCode is too long", e['status']
45
+ end
46
+
47
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ class MainAppExtensionsTest < ActiveSupport::TestCase
4
+
5
+ class TestClass
6
+ class Action2Class
7
+ include Incline::Extensions::MainApp
8
+
9
+ def action2
10
+ :action2
11
+ end
12
+ end
13
+
14
+ include Incline::Extensions::MainApp
15
+
16
+ attr_accessor :called
17
+
18
+ def initialize
19
+ self.called = false
20
+ end
21
+
22
+ def main_app
23
+ self.called = :main_app
24
+ @main_app ||= Action2Class.new
25
+ end
26
+
27
+ def action1
28
+ self.called = :action1
29
+ end
30
+
31
+ end
32
+
33
+ def setup
34
+ @item = TestClass.new
35
+ end
36
+
37
+ test 'main_app should be called automatically' do
38
+ # action1 belongs to the class itself.
39
+ assert_equal :action1, @item.action1
40
+ assert_equal :action1, @item.called
41
+
42
+ # action2 belongs to the :main_app object.
43
+ assert_equal :action2, @item.action2
44
+ assert_equal :main_app, @item.called
45
+
46
+ # and just to be sure, when a class does not define :main_app, we use rails.
47
+ # in this case the fake :main_app doesn't know :root_path and doesn't define
48
+ # its own :main_app, so it calls on rails to execute the method.
49
+ rp = Rails.application.class.routes.url_helpers.root_path
50
+ assert_equal rp, @item.main_app.root_path
51
+
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+ require 'bigdecimal'
3
+
4
+ class NumericExtensionsTest < ActiveSupport::TestCase
5
+
6
+ test 'numeric types have to_human' do
7
+ assert Integer(123).respond_to?(:to_human)
8
+ assert Float(123).respond_to?(:to_human)
9
+ assert Rational(123).respond_to?(:to_human)
10
+ assert BigDecimal.new(123).respond_to?(:to_human)
11
+ end
12
+
13
+ test 'integers convert as expected' do
14
+ {
15
+ 1 => '1',
16
+ 10 => '10',
17
+ 100 => '100',
18
+ 1000 => '1 thousand',
19
+ 1500 => '1.5 thousand',
20
+ 1000000 => '1 million',
21
+ 1050000 => '1.05 million',
22
+ 1000000000 => '1 billion',
23
+ 1245000000 => '1.25 billion', # verify that we are using round-to-nearest and not round-to-even.
24
+ 1255000000 => '1.26 billion',
25
+ 999999999 => '1000 million', # less than a billion, but rounding will put it at 1 billion.
26
+ Integer('1234'.ljust(40,'0')) => '1.23 duodecillion'
27
+ }.each do |v, s|
28
+ assert_equal s, v.to_human
29
+ end
30
+ end
31
+
32
+ test 'floats convert as expected' do
33
+ {
34
+ 0.375 => '0.38',
35
+ 1.0 => '1',
36
+ 10.0 => '10',
37
+ 100.0 => '100',
38
+ 1000.0 => '1 thousand',
39
+ 1500.0 => '1.5 thousand',
40
+ (1E36 + 1.0) => '1 undecillion'
41
+ }.each do |v,s|
42
+ assert_equal s, v.to_human
43
+ end
44
+ end
45
+
46
+ test 'rationals convert as expected' do
47
+ {
48
+ Rational('3/8') => '3/8',
49
+ Rational(1) => '1',
50
+ Rational('5/3') => '5/3',
51
+ Rational(10.0) => '10',
52
+ Rational(100) => '100',
53
+ Rational('100/1') => '100',
54
+ Rational(1000) => '1 thousand',
55
+ Rational(1500) => '1.5 thousand',
56
+ Rational('1'.ljust(34,'0')) => '1 decillion'
57
+ }.each do |v,s|
58
+ assert_equal s, v.to_human
59
+ end
60
+ end
61
+
62
+ test 'big_decimals convert as expected' do
63
+ {
64
+ BigDecimal(Rational('3/8'), 4) => '0.38',
65
+ BigDecimal(1) => '1',
66
+ BigDecimal(10) => '10',
67
+ BigDecimal(100) => '100',
68
+ BigDecimal(1000) => '1 thousand',
69
+ BigDecimal(1500) => '1.5 thousand',
70
+ BigDecimal('1'.ljust(31,'0')) => '1 nonillion'
71
+ }.each do |v,s|
72
+ assert_equal s, v.to_human
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+
3
+ class ObjectExtensionsTest < ActiveSupport::TestCase
4
+
5
+ test 'all objects have object_pointer method' do
6
+ assert Object.respond_to?(:object_pointer)
7
+ assert Object.new.respond_to?(:object_pointer)
8
+ assert 'hello'.respond_to?(:object_pointer)
9
+ assert 12345.respond_to?(:object_pointer)
10
+ assert [1, 2, 3].respond_to?(:object_pointer)
11
+ assert Hash.new(hello: :world).respond_to?(:object_pointer)
12
+ end
13
+
14
+ test 'all objects have to_bool method' do
15
+ assert Object.respond_to?(:to_bool)
16
+ assert Object.new.respond_to?(:to_bool)
17
+ assert 'hello'.respond_to?(:to_bool)
18
+ assert 12345.respond_to?(:to_bool)
19
+ assert [1, 2, 3].respond_to?(:to_bool)
20
+ assert Hash.new(hello: :world).respond_to?(:to_bool)
21
+ assert true.respond_to?(:to_bool)
22
+ assert false.respond_to?(:to_bool)
23
+ assert nil.respond_to?(:to_bool)
24
+ end
25
+
26
+
27
+ test 'object_pointer_is_formatted_correctly' do
28
+ item = Object.new
29
+ expected = '0x' + item.object_id.to_s(16).rjust(12,'0').downcase
30
+ assert_equal expected, item.object_pointer
31
+ end
32
+
33
+
34
+ test 'to_bool works as expected' do
35
+ # normal true/false
36
+ assert true.to_bool
37
+ assert_not false.to_bool
38
+
39
+ # nil => false (should not return nil!)
40
+ assert_not nil.to_bool
41
+ assert_not_nil nil.to_bool
42
+
43
+ # symbols
44
+ assert :true.to_bool
45
+ assert_not :false.to_bool
46
+ assert :yes.to_bool
47
+ assert_not :no.to_bool
48
+ assert :on.to_bool
49
+ assert_not :off.to_bool
50
+
51
+ # integers
52
+ assert_not 0.to_bool
53
+ assert 1.to_bool
54
+ assert (-1.to_bool)
55
+
56
+ # floats
57
+ assert_not 0.0.to_bool
58
+ assert 0.1.to_bool
59
+ assert 1.0.to_bool
60
+
61
+ # strings (expected true values)
62
+ assert 'true'.to_bool
63
+ assert 'True'.to_bool
64
+ assert 'TRUE'.to_bool
65
+ assert 't'.to_bool
66
+ assert 'T'.to_bool
67
+ assert 'yes'.to_bool
68
+ assert 'Yes'.to_bool
69
+ assert 'YES'.to_bool
70
+ assert 'y'.to_bool
71
+ assert 'Y'.to_bool
72
+ assert 'on'.to_bool
73
+ assert 'On'.to_bool
74
+ assert 'ON'.to_bool
75
+ assert '1'.to_bool
76
+
77
+ # strings (expected false values)
78
+ assert_not ''.to_bool
79
+ assert_not 'false'.to_bool
80
+ assert_not 'False'.to_bool
81
+ assert_not 'FALSE'.to_bool
82
+ assert_not 'f'.to_bool
83
+ assert_not 'F'.to_bool
84
+ assert_not 'no'.to_bool
85
+ assert_not 'No'.to_bool
86
+ assert_not 'NO'.to_bool
87
+ assert_not 'off'.to_bool
88
+ assert_not 'Off'.to_bool
89
+ assert_not 'OFF'.to_bool
90
+ assert_not '0'.to_bool
91
+
92
+ # strings (misc values are all false)
93
+ assert_not 'hello'.to_bool
94
+ assert_not 'maybe'.to_bool
95
+ assert_not 'true-ish'.to_bool
96
+ assert_not '123'.to_bool
97
+
98
+ # other values
99
+ assert_not Object.to_bool
100
+ assert_not Object.new.to_bool
101
+ end
102
+
103
+
104
+ end