workarea-core 3.4.45 → 3.5.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (427) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +52 -0
  3. data/app/assets/javascripts/workarea/core/modules/duplicate_id.js +1 -5
  4. data/app/assets/javascripts/workarea/core/modules/style_guide_autocomplete_fields.js +9 -42
  5. data/app/assets/javascripts/workarea/core/modules/url.js +14 -0
  6. data/app/controllers/workarea/application_controller.rb +5 -1
  7. data/app/controllers/workarea/authentication.rb +15 -26
  8. data/app/controllers/workarea/authorization.rb +3 -3
  9. data/app/controllers/workarea/current_referrer.rb +1 -2
  10. data/app/controllers/workarea/current_release.rb +1 -1
  11. data/app/controllers/workarea/current_segments.rb +52 -0
  12. data/app/controllers/workarea/current_tracking.rb +45 -0
  13. data/app/controllers/workarea/http_caching.rb +30 -0
  14. data/app/controllers/workarea/impersonation.rb +18 -44
  15. data/app/helpers/workarea/schema_org_helper.rb +21 -0
  16. data/app/mailers/workarea/application_mailer.rb +2 -4
  17. data/app/middleware/workarea/application_middleware.rb +44 -0
  18. data/app/middleware/workarea/query_cache_middleware.rb +55 -0
  19. data/app/middleware/workarea/release_server_middleware.rb +1 -1
  20. data/app/models/workarea/application_document.rb +1 -1
  21. data/app/models/workarea/bulk_action/product_edit.rb +6 -6
  22. data/app/models/workarea/calculate_percent_change.rb +1 -1
  23. data/app/models/workarea/catalog/category.rb +0 -2
  24. data/app/models/workarea/catalog/product.rb +19 -2
  25. data/app/models/workarea/checkout/collect_payment.rb +10 -1
  26. data/app/models/workarea/checkout/fraud/analyzer.rb +44 -0
  27. data/app/models/workarea/checkout/fraud/no_decision_analyzer.rb +14 -0
  28. data/app/models/workarea/checkout/fraud/test_analyzer.rb +26 -0
  29. data/app/models/workarea/checkout.rb +18 -6
  30. data/app/models/workarea/configuration/admin.rb +25 -0
  31. data/app/models/workarea/configuration/params.rb +45 -0
  32. data/app/models/workarea/content/asset.rb +5 -18
  33. data/app/models/workarea/content/block.rb +8 -2
  34. data/app/models/workarea/content/block_draft.rb +7 -2
  35. data/app/models/workarea/content/block_type.rb +2 -2
  36. data/app/models/workarea/content/block_type_definition.rb +4 -0
  37. data/app/models/workarea/content/preset.rb +1 -1
  38. data/app/models/workarea/content.rb +12 -82
  39. data/app/models/workarea/data_file/csv.rb +6 -8
  40. data/app/models/workarea/data_file/import.rb +9 -1
  41. data/app/models/workarea/data_file/json.rb +1 -20
  42. data/app/models/workarea/data_file/operation.rb +0 -4
  43. data/app/models/workarea/data_file/tax_rates.rb +3 -0
  44. data/app/models/workarea/featured_products.rb +8 -0
  45. data/app/models/workarea/fulfillment/policies/base.rb +21 -0
  46. data/app/models/workarea/fulfillment/policies/download.rb +21 -0
  47. data/app/models/workarea/fulfillment/policies/ignore.rb +11 -0
  48. data/app/models/workarea/fulfillment/policies/ship.rb +15 -0
  49. data/app/models/workarea/fulfillment/sku.rb +72 -0
  50. data/app/models/workarea/fulfillment/token.rb +36 -0
  51. data/app/models/workarea/inquiry.rb +1 -2
  52. data/app/models/workarea/insights/customer_acquisition.rb +5 -9
  53. data/app/models/workarea/insights/trending_products.rb +2 -2
  54. data/app/models/workarea/insights/trending_searches.rb +2 -2
  55. data/app/models/workarea/inventory/collection.rb +30 -0
  56. data/app/models/workarea/inventory/collection_status.rb +40 -0
  57. data/app/models/workarea/metrics/affinity.rb +33 -0
  58. data/app/models/workarea/metrics/country_by_day.rb +4 -0
  59. data/app/models/workarea/metrics/product_by_day.rb +3 -0
  60. data/app/models/workarea/metrics/product_by_week.rb +2 -0
  61. data/app/models/workarea/metrics/product_for_last_week.rb +8 -12
  62. data/app/models/workarea/metrics/sales_by_day.rb +5 -0
  63. data/app/models/workarea/metrics/search_by_day.rb +1 -3
  64. data/app/models/workarea/metrics/search_for_last_week.rb +5 -11
  65. data/app/models/workarea/metrics/segment_by_day.rb +31 -0
  66. data/app/models/workarea/metrics/sku_by_day.rb +3 -0
  67. data/app/models/workarea/metrics/tender_by_day.rb +11 -0
  68. data/app/models/workarea/metrics/update_user_aggregations.rb +77 -0
  69. data/app/models/workarea/metrics/user.rb +73 -87
  70. data/app/models/workarea/navigation/breadcrumbs.rb +10 -1
  71. data/app/models/workarea/order/fraud_decision.rb +18 -0
  72. data/app/models/workarea/order/item.rb +5 -0
  73. data/app/models/workarea/order/queries.rb +1 -0
  74. data/app/models/workarea/order/status.rb +10 -1
  75. data/app/models/workarea/order.rb +47 -4
  76. data/app/models/workarea/payment/credit_card.rb +12 -0
  77. data/app/models/workarea/payment.rb +7 -2
  78. data/app/models/workarea/pricing/cache_key.rb +9 -3
  79. data/app/models/workarea/pricing/calculator.rb +5 -1
  80. data/app/models/workarea/pricing/calculators/tax_calculator.rb +32 -5
  81. data/app/models/workarea/pricing/discount/application_group.rb +8 -3
  82. data/app/models/workarea/pricing/discount/free_gift.rb +2 -1
  83. data/app/models/workarea/pricing/discount/redemption.rb +1 -1
  84. data/app/models/workarea/pricing/discount.rb +2 -3
  85. data/app/models/workarea/pricing/item_tax_applier.rb +41 -0
  86. data/app/models/workarea/pricing/price.rb +1 -0
  87. data/app/models/workarea/pricing/request.rb +11 -0
  88. data/app/models/workarea/pricing/sku.rb +1 -0
  89. data/app/models/workarea/pricing/tax_application.rb +21 -0
  90. data/app/models/workarea/pricing/tax_applier.rb +12 -15
  91. data/app/models/workarea/pricing/unsupported_segmentation.rb +22 -0
  92. data/app/models/workarea/product_rule.rb +5 -0
  93. data/app/models/workarea/releasable.rb +83 -89
  94. data/app/models/workarea/release/activation.rb +45 -0
  95. data/app/models/workarea/release/changes.rb +45 -0
  96. data/app/models/workarea/release/changeset.rb +42 -52
  97. data/app/models/workarea/release/preview.rb +28 -0
  98. data/app/models/workarea/release/status.rb +2 -24
  99. data/app/models/workarea/release.rb +72 -99
  100. data/app/models/workarea/release_session.rb +11 -11
  101. data/app/models/workarea/search/admin/catalog_product.rb +1 -2
  102. data/app/models/workarea/search/admin/fulfillment_sku.rb +27 -0
  103. data/app/models/workarea/search/admin/order.rb +1 -1
  104. data/app/models/workarea/search/admin/pricing_discount.rb +1 -1
  105. data/app/models/workarea/search/admin/release.rb +1 -4
  106. data/app/models/workarea/search/admin/segment.rb +19 -0
  107. data/app/models/workarea/search/admin.rb +17 -39
  108. data/app/models/workarea/search/order_text.rb +23 -6
  109. data/app/models/workarea/search/storefront/category_query.rb +152 -0
  110. data/app/models/workarea/search/storefront/product/categories.rb +11 -45
  111. data/app/models/workarea/search/storefront.rb +33 -29
  112. data/app/models/workarea/segment/first_time_customer.rb +8 -0
  113. data/app/models/workarea/segment/first_time_visitor.rb +12 -0
  114. data/app/models/workarea/segment/life_cycle.rb +44 -0
  115. data/app/models/workarea/segment/loyal_customer.rb +12 -0
  116. data/app/models/workarea/segment/returning_customer.rb +14 -0
  117. data/app/models/workarea/segment/returning_visitor.rb +12 -0
  118. data/app/models/workarea/segment/rules/base.rb +16 -0
  119. data/app/models/workarea/segment/rules/browser_info.rb +29 -0
  120. data/app/models/workarea/segment/rules/geolocation.rb +29 -0
  121. data/app/models/workarea/segment/rules/geolocation_option.rb +53 -0
  122. data/app/models/workarea/segment/rules/last_order.rb +14 -0
  123. data/app/models/workarea/segment/rules/logged_in.rb +13 -0
  124. data/app/models/workarea/segment/rules/orders.rb +17 -0
  125. data/app/models/workarea/segment/rules/revenue.rb +17 -0
  126. data/app/models/workarea/segment/rules/sessions.rb +17 -0
  127. data/app/models/workarea/segment/rules/tags.rb +14 -0
  128. data/app/models/workarea/segment/rules/traffic_referrer.rb +18 -0
  129. data/app/models/workarea/segment.rb +54 -0
  130. data/app/models/workarea/segmentable.rb +66 -0
  131. data/app/models/workarea/sort.rb +14 -2
  132. data/app/models/workarea/tax/rate.rb +35 -1
  133. data/app/models/workarea/user/authorization.rb +19 -13
  134. data/app/models/workarea/user/login.rb +4 -0
  135. data/app/models/workarea/user/password_reset.rb +1 -3
  136. data/app/queries/workarea/categorization.rb +3 -3
  137. data/app/queries/workarea/featured_categorization.rb +53 -0
  138. data/app/queries/workarea/order_cancellation_metrics.rb +155 -0
  139. data/app/queries/workarea/order_item_details.rb +16 -3
  140. data/app/queries/workarea/order_metrics.rb +32 -3
  141. data/app/queries/workarea/product_primary_navigation.rb +13 -2
  142. data/app/queries/workarea/product_releases.rb +38 -0
  143. data/app/queries/workarea/recommendation/user_activity_based.rb +14 -6
  144. data/app/queries/workarea/reports/average_order_value.rb +1 -1
  145. data/app/queries/workarea/reports/customers.rb +14 -11
  146. data/app/queries/workarea/reports/first_time_vs_returning_sales.rb +1 -1
  147. data/app/queries/workarea/reports/group_by_time.rb +13 -17
  148. data/app/queries/workarea/reports/sales_by_category.rb +1 -1
  149. data/app/queries/workarea/reports/sales_by_country.rb +10 -3
  150. data/app/queries/workarea/reports/sales_by_discount.rb +1 -1
  151. data/app/queries/workarea/reports/sales_by_menu.rb +1 -1
  152. data/app/queries/workarea/reports/sales_by_product.rb +39 -4
  153. data/app/queries/workarea/reports/sales_by_sku.rb +39 -4
  154. data/app/queries/workarea/reports/sales_by_tender.rb +42 -0
  155. data/app/queries/workarea/reports/sales_by_traffic_referrer.rb +1 -1
  156. data/app/queries/workarea/reports/sales_over_time.rb +10 -3
  157. data/app/queries/workarea/reports/searches.rb +1 -1
  158. data/app/queries/workarea/reports/searches_over_time.rb +1 -1
  159. data/app/queries/workarea/reports/searches_without_results_over_time.rb +1 -1
  160. data/app/queries/workarea/search/admin_fulfillment_skus.rb +20 -0
  161. data/app/queries/workarea/search/admin_releases.rb +1 -4
  162. data/app/queries/workarea/search/admin_search.rb +0 -4
  163. data/app/queries/workarea/search/admin_segments.rb +16 -0
  164. data/app/queries/workarea/search/admin_sorting.rb +1 -1
  165. data/app/queries/workarea/search/pagination.rb +1 -4
  166. data/app/queries/workarea/search/product_display_rules.rb +40 -8
  167. data/app/queries/workarea/search/product_entries.rb +15 -1
  168. data/app/queries/workarea/search/product_search.rb +4 -1
  169. data/app/queries/workarea/search/storefront_search/exact_matches.rb +1 -1
  170. data/app/queries/workarea/search/storefront_search/response.rb +6 -4
  171. data/app/queries/workarea/search/storefront_search.rb +5 -4
  172. data/app/seeds/workarea/assets_seeds.rb +2 -1
  173. data/app/seeds/workarea/insights_seeds.rb +0 -23
  174. data/app/seeds/workarea/orders_seeds.rb +7 -6
  175. data/app/seeds/workarea/products_seeds.rb +2 -0
  176. data/app/seeds/workarea/segments_seeds.rb +8 -0
  177. data/app/seeds/workarea/tax_seeds.rb +3 -3
  178. data/app/services/workarea/cancel_order.rb +8 -3
  179. data/app/services/workarea/copy_order.rb +6 -0
  180. data/app/services/workarea/create_fulfillment.rb +5 -3
  181. data/app/services/workarea/direct_upload.rb +11 -19
  182. data/app/services/workarea/hash_update.rb +1 -18
  183. data/app/services/workarea/packaging.rb +1 -1
  184. data/app/services/workarea/save_publishing.rb +5 -1
  185. data/app/workers/sidekiq/callbacks.rb +4 -52
  186. data/app/workers/sidekiq/callbacks_worker.rb +4 -6
  187. data/app/workers/workarea/bulk_index_admin.rb +2 -2
  188. data/app/workers/workarea/bulk_index_products.rb +6 -5
  189. data/app/workers/workarea/bulk_index_searches.rb +5 -5
  190. data/app/workers/workarea/deactivate_stale_discounts.rb +3 -3
  191. data/app/workers/workarea/generate_insights.rb +1 -1
  192. data/app/workers/workarea/index_admin_search.rb +1 -0
  193. data/app/workers/workarea/index_categorization.rb +4 -7
  194. data/app/workers/workarea/index_category.rb +2 -1
  195. data/app/workers/workarea/index_category_changes.rb +11 -6
  196. data/app/workers/workarea/index_fulfillment_changes.rb +2 -1
  197. data/app/workers/workarea/index_help.rb +2 -1
  198. data/app/workers/workarea/index_page.rb +2 -1
  199. data/app/workers/workarea/index_payment_transactions.rb +2 -1
  200. data/app/workers/workarea/index_product.rb +4 -4
  201. data/app/workers/workarea/index_product_children.rb +4 -3
  202. data/app/workers/workarea/index_product_rule.rb +3 -2
  203. data/app/workers/workarea/index_search_customizations.rb +3 -2
  204. data/app/workers/workarea/index_skus.rb +5 -6
  205. data/app/workers/workarea/keep_product_index_fresh.rb +3 -5
  206. data/app/workers/workarea/process_import.rb +3 -3
  207. data/app/workers/workarea/process_search_recommendations.rb +5 -9
  208. data/app/workers/workarea/publish_release.rb +1 -0
  209. data/app/workers/workarea/save_metrics.rb +116 -0
  210. data/app/workers/workarea/save_order_cancellation_metrics.rb +35 -0
  211. data/app/workers/workarea/save_order_metrics.rb +10 -74
  212. data/app/workers/workarea/status_reporter.rb +2 -4
  213. data/app/workers/workarea/synchronize_user_metrics.rb +17 -0
  214. data/app/workers/workarea/update_payment_profile_email.rb +22 -0
  215. data/app/workers/workarea/verify_scheduled_releases.rb +4 -11
  216. data/config/initializers/00_configuration.rb +185 -0
  217. data/config/initializers/02_assets.rb +1 -0
  218. data/config/initializers/05_scheduled_jobs.rb +0 -7
  219. data/config/initializers/10_rack_middleware.rb +2 -5
  220. data/config/initializers/11_payment.rb +4 -0
  221. data/config/initializers/13_rack_attack.rb +2 -4
  222. data/config/initializers/14_content_block_types.rb +16 -16
  223. data/config/initializers/15_endpoint_monitoring.rb +3 -6
  224. data/config/initializers/{21_premailer.rb → 24_premailer.rb} +1 -0
  225. data/config/initializers/{20_i18n_js.rb → 25_i18n_js.rb} +0 -0
  226. data/config/locales/en.yml +13 -24
  227. data/lib/generators/workarea/content_block_type/templates/initializer.rb +1 -1
  228. data/lib/generators/workarea/install/USAGE +0 -1
  229. data/lib/generators/workarea/install/install_generator.rb +0 -21
  230. data/lib/generators/workarea/install/templates/initializer.rb.erb +1 -1
  231. data/lib/tasks/insights.rake +1 -0
  232. data/lib/tasks/migrate.rake +106 -0
  233. data/lib/tasks/search.rake +17 -19
  234. data/lib/tasks/tests.rake +1 -1
  235. data/lib/workarea/cache.rb +6 -35
  236. data/lib/workarea/changelog.rake +2 -2
  237. data/lib/workarea/configuration/administrable/definition.rb +42 -0
  238. data/lib/workarea/configuration/administrable/field.rb +79 -0
  239. data/lib/workarea/configuration/administrable/fieldset.rb +44 -0
  240. data/lib/workarea/configuration/administrable_options.rb +24 -0
  241. data/lib/workarea/configuration/cache_store.rb +3 -1
  242. data/lib/workarea/configuration/content_blocks.rb +17 -0
  243. data/lib/workarea/configuration/mongoid.rb +1 -4
  244. data/lib/workarea/configuration/session.rb +36 -0
  245. data/lib/workarea/configuration/sidekiq.rb +3 -1
  246. data/lib/workarea/configuration.rb +121 -148
  247. data/lib/workarea/core/engine.rb +3 -58
  248. data/lib/workarea/core.rb +15 -11
  249. data/lib/workarea/elasticsearch/document.rb +8 -15
  250. data/lib/workarea/ext/freedom_patches/action_view_cache_helper.rb +4 -6
  251. data/lib/workarea/ext/freedom_patches/active_support_duration.rb +14 -0
  252. data/lib/workarea/ext/freedom_patches/money.rb +11 -0
  253. data/lib/workarea/ext/freedom_patches/premailer.rb +6 -0
  254. data/lib/workarea/ext/freedom_patches/string.rb +19 -4
  255. data/lib/workarea/ext/mongoid/find_ordered.rb +2 -2
  256. data/lib/workarea/ext/mongoid/lookup_hash.rb +30 -0
  257. data/lib/workarea/geolocation.rb +24 -6
  258. data/lib/workarea/routes_constraints/super_admin.rb +1 -1
  259. data/lib/workarea/version.rb +3 -4
  260. data/lib/workarea/visit.rb +92 -0
  261. data/lib/workarea/warnings.rb +95 -0
  262. data/lib/workarea.rb +102 -3
  263. data/test/dummy/config/initializers/session_store.rb +1 -1
  264. data/test/fixtures/tax_rates.csv +3 -3
  265. data/test/generators/workarea/content_block_type_generator_test.rb +1 -1
  266. data/test/generators/workarea/install_generator_test.rb +0 -13
  267. data/test/integration/workarea/authentication_test.rb +27 -4
  268. data/test/integration/workarea/authorization_test.rb +5 -0
  269. data/test/integration/workarea/cache_varies_integration_test.rb +21 -23
  270. data/test/integration/workarea/monitoring_integration_test.rb +5 -10
  271. data/test/javascripts/duplicate_id_spec.js +1 -7
  272. data/test/javascripts/fixtures/{duplicate_id_fail.html.haml → duplicate_id.html.haml} +0 -1
  273. data/test/javascripts/form_submitting_controls_spec.js +0 -1
  274. data/test/lib/workarea/asset_endpoints/favicons_test.rb +11 -13
  275. data/test/lib/workarea/configuration/administrable/definition_test.rb +71 -0
  276. data/test/lib/workarea/configuration/administrable/field_test.rb +128 -0
  277. data/test/lib/workarea/configuration/administrable/fieldset_test.rb +78 -0
  278. data/test/lib/workarea/configuration/configuration_test.rb +20 -0
  279. data/test/lib/workarea/elasticsearch/document_test.rb +0 -20
  280. data/test/lib/workarea/elasticsearch/query_cache_test.rb +7 -7
  281. data/test/lib/workarea/ext/freedom_patches/money_test.rb +11 -0
  282. data/test/lib/workarea/ext/mongoid/lookup_hash_test.rb +86 -0
  283. data/test/lib/workarea/geolocation_test.rb +20 -0
  284. data/test/mailers/workarea/application_mailer_test.rb +1 -11
  285. data/test/middleware/workarea/query_cache_middleware_test.rb +55 -0
  286. data/test/models/workarea/checkout/collect_payment_test.rb +14 -6
  287. data/test/models/workarea/checkout_test.rb +31 -57
  288. data/test/models/workarea/configuration/params_test.rb +37 -0
  289. data/test/models/workarea/data_file/csv_test.rb +8 -73
  290. data/test/models/workarea/data_file/import_test.rb +31 -0
  291. data/test/models/workarea/data_file/json_test.rb +6 -48
  292. data/test/models/workarea/data_file/tax_test.rb +3 -0
  293. data/test/models/workarea/fulfillment/policies/download_test.rb +39 -0
  294. data/test/models/workarea/fulfillment/sku_test.rb +54 -0
  295. data/test/models/workarea/insights/best_customers_test.rb +5 -2
  296. data/test/models/workarea/insights/best_full_price_customers_test.rb +5 -2
  297. data/test/models/workarea/insights/customer_acquisition_test.rb +1 -1
  298. data/test/models/workarea/insights/customers_at_risk_test.rb +1 -1
  299. data/test/models/workarea/insights/low_aov_customers_test.rb +1 -1
  300. data/test/models/workarea/inventory/collection_test.rb +75 -0
  301. data/test/models/workarea/metrics/affinity_test.rb +85 -0
  302. data/test/models/workarea/metrics/product_by_week_test.rb +27 -31
  303. data/test/models/workarea/metrics/search_by_day_test.rb +3 -0
  304. data/test/models/workarea/metrics/search_by_week_test.rb +27 -31
  305. data/test/models/workarea/metrics/update_user_aggregations_test.rb +62 -0
  306. data/test/models/workarea/metrics/user_test.rb +146 -63
  307. data/test/models/workarea/navigation/breadcrumbs_test.rb +12 -2
  308. data/test/models/workarea/order/queries_test.rb +2 -0
  309. data/test/models/workarea/order_test.rb +44 -0
  310. data/test/models/workarea/payment/address_test.rb +109 -111
  311. data/test/models/workarea/payment/credit_card_integration_test.rb +0 -52
  312. data/test/models/workarea/payment/credit_card_test.rb +5 -0
  313. data/test/models/workarea/pricing/cache_key_test.rb +7 -1
  314. data/test/models/workarea/pricing/calculators/tax_calculator_test.rb +41 -1
  315. data/test/models/workarea/pricing/discount/collection_test.rb +27 -29
  316. data/test/models/workarea/pricing/discount_test.rb +22 -24
  317. data/test/models/workarea/pricing/item_tax_applier_test.rb +83 -0
  318. data/test/models/workarea/pricing/price_test.rb +9 -0
  319. data/test/models/workarea/pricing/request_test.rb +13 -0
  320. data/test/models/workarea/pricing/sku_test.rb +9 -0
  321. data/test/models/workarea/releasable_active_test.rb +113 -0
  322. data/test/models/workarea/releasable_test.rb +69 -120
  323. data/test/models/workarea/release/changeset_test.rb +41 -0
  324. data/test/models/workarea/release_jobs_test.rb +52 -0
  325. data/test/models/workarea/release_previewing_test.rb +43 -0
  326. data/test/models/workarea/release_test.rb +59 -153
  327. data/test/models/workarea/search/admin/content_asset_test.rb +26 -28
  328. data/test/models/workarea/search/order_text_test.rb +35 -0
  329. data/test/models/workarea/search/storefront/category_query_test.rb +81 -0
  330. data/test/models/workarea/search/storefront/product/categories_test.rb +10 -70
  331. data/test/models/workarea/search/storefront/product_test.rb +10 -11
  332. data/test/models/workarea/search/storefront_test.rb +1 -13
  333. data/test/models/workarea/segment/life_cycle_test.rb +24 -0
  334. data/test/models/workarea/segment/rules/browser_info_test.rb +33 -0
  335. data/test/models/workarea/segment/rules/geolocation_option_test.rb +16 -0
  336. data/test/models/workarea/segment/rules/geolocation_test.rb +49 -0
  337. data/test/models/workarea/segment/rules/last_order_test.rb +32 -0
  338. data/test/models/workarea/segment/rules/logged_in_test.rb +25 -0
  339. data/test/models/workarea/segment/rules/orders_test.rb +59 -0
  340. data/test/models/workarea/segment/rules/revenue_test.rb +59 -0
  341. data/test/models/workarea/segment/rules/sessions_test.rb +26 -0
  342. data/test/models/workarea/segment/rules/tags_test.rb +27 -0
  343. data/test/models/workarea/segment/rules/traffic_referrer_test.rb +31 -0
  344. data/test/models/workarea/segment_test.rb +80 -0
  345. data/test/models/workarea/segmentable_test.rb +74 -0
  346. data/test/models/workarea/shipping/address_test.rb +109 -111
  347. data/test/models/workarea/shipping/sku_test.rb +8 -12
  348. data/test/models/workarea/user/password_reset_test.rb +4 -12
  349. data/test/models/workarea/user_test.rb +13 -10
  350. data/test/queries/workarea/admin_search_query_wrapper_test.rb +21 -25
  351. data/test/queries/workarea/categorization_test.rb +49 -0
  352. data/test/queries/workarea/featured_categorization_test.rb +66 -0
  353. data/test/queries/workarea/order_cancellation_metrics_test.rb +203 -0
  354. data/test/queries/workarea/order_item_details_test.rb +17 -0
  355. data/test/queries/workarea/order_metrics_test.rb +12 -0
  356. data/test/queries/workarea/product_releases_test.rb +56 -0
  357. data/test/queries/workarea/recommendation/searches_test.rb +3 -3
  358. data/test/queries/workarea/recommendation/user_activity_based_test.rb +4 -4
  359. data/test/queries/workarea/reports/customers_test.rb +12 -8
  360. data/test/queries/workarea/reports/report_test.rb +4 -6
  361. data/test/queries/workarea/reports/sales_by_country_test.rb +18 -3
  362. data/test/queries/workarea/reports/sales_by_product_test.rb +28 -8
  363. data/test/queries/workarea/reports/sales_by_sku_test.rb +28 -8
  364. data/test/queries/workarea/reports/sales_by_tender_test.rb +100 -0
  365. data/test/queries/workarea/reports/sales_by_traffic_referrer_test.rb +6 -6
  366. data/test/queries/workarea/search/admin_releases_test.rb +1 -26
  367. data/test/queries/workarea/search/admin_search_test.rb +0 -10
  368. data/test/queries/workarea/search/admin_users_test.rb +2 -2
  369. data/test/queries/workarea/search/category_browse_test.rb +53 -0
  370. data/test/queries/workarea/search/facet_sorting/size_test.rb +11 -13
  371. data/test/queries/workarea/search/pagination_test.rb +9 -26
  372. data/test/queries/workarea/search/product_entries_test.rb +27 -0
  373. data/test/queries/workarea/search/product_search_test.rb +0 -16
  374. data/test/queries/workarea/search/storefront_search/response_test.rb +26 -0
  375. data/test/queries/workarea/search/storefront_search_test.rb +34 -36
  376. data/test/services/workarea/cancel_order_test.rb +27 -13
  377. data/test/services/workarea/copy_order_test.rb +17 -0
  378. data/test/services/workarea/direct_upload_test.rb +1 -46
  379. data/test/services/workarea/export_report_test.rb +41 -45
  380. data/test/services/workarea/hash_update_test.rb +12 -12
  381. data/test/services/workarea/packaging_test.rb +9 -11
  382. data/test/services/workarea/save_publishing_test.rb +23 -0
  383. data/test/workers/sidekiq/callbacks_test.rb +0 -22
  384. data/test/workers/workarea/deactivate_stale_discounts_test.rb +2 -2
  385. data/test/workers/workarea/index_category_changes_test.rb +5 -7
  386. data/test/workers/workarea/keep_product_index_fresh_test.rb +1 -1
  387. data/test/workers/workarea/process_import_test.rb +0 -6
  388. data/test/workers/workarea/process_search_recommendations_test.rb +4 -5
  389. data/test/workers/workarea/status_reporter_test.rb +2 -1
  390. data/test/workers/workarea/synchronize_user_metrics_test.rb +57 -0
  391. data/test/workers/workarea/update_payment_profile_email_test.rb +27 -0
  392. data/test/workers/workarea/verify_scheduled_releases_test.rb +0 -26
  393. data/workarea-core.gemspec +13 -11
  394. metadata +196 -92
  395. data/app/assets/javascripts/workarea/core/templates/ui_menu_item.jst.ejs +0 -10
  396. data/app/controllers/workarea/admin_guest_browsing.rb +0 -54
  397. data/app/middleware/workarea/rack_cache_config_middleware.rb +0 -19
  398. data/app/queries/workarea/search/search_suggestions.rb +0 -43
  399. data/app/workers/workarea/bust_discount_cache.rb +0 -16
  400. data/app/workers/workarea/clean_user_activity.rb +0 -11
  401. data/app/workers/workarea/undo_release.rb +0 -15
  402. data/app/workers/workarea/update_email.rb +0 -33
  403. data/lib/generators/workarea/docker/USAGE +0 -16
  404. data/lib/generators/workarea/docker/docker_generator.rb +0 -61
  405. data/lib/generators/workarea/docker/templates/.env.erb +0 -6
  406. data/lib/generators/workarea/docker/templates/Dockerfile.erb +0 -48
  407. data/lib/generators/workarea/docker/templates/docker-compose.yml.erb +0 -72
  408. data/lib/generators/workarea/docker/templates/docker-entrypoint.sh.erb +0 -6
  409. data/lib/generators/workarea/docker/templates/docker-sync.yml.erb +0 -8
  410. data/lib/generators/workarea/docker/templates/docker-wait.sh +0 -11
  411. data/lib/generators/workarea/docker/templates/docker.env +0 -16
  412. data/lib/generators/workarea/docker/templates/docker_init.rb.erb +0 -29
  413. data/lib/workarea/configuration/headless_chrome.rb +0 -42
  414. data/lib/workarea/configuration/puma.rb +0 -37
  415. data/lib/workarea/ext/freedom_patches/i18n_js.rb +0 -27
  416. data/lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb +0 -25
  417. data/lib/workarea/ext/jbuilder/jbuilder_cache.rb +0 -29
  418. data/lib/workarea/ext/referer_parser/parser.decorator +0 -43
  419. data/lib/workarea/queues_pauser.rb +0 -26
  420. data/lib/workarea/robots.rb +0 -9
  421. data/test/generators/workarea/docker_generator_test.rb +0 -156
  422. data/test/javascripts/fixtures/duplicate_id_pass.html.haml +0 -2
  423. data/test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb +0 -25
  424. data/test/lib/workarea/ext/referer_parser/parser_test.rb +0 -20
  425. data/test/queries/workarea/search/search_suggestions_test.rb +0 -29
  426. data/test/workers/workarea/undo_release_test.rb +0 -23
  427. data/test/workers/workarea/update_email_test.rb +0 -39
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Segment
5
+ module Rules
6
+ class TagsTest < TestCase
7
+ def test_qualifies?
8
+ metrics = Metrics::User.create!(id: 'bcrouse@workarea.com')
9
+
10
+ visit = create_visit(email: 'bcrouse@workarea.com')
11
+ refute(Tags.new.qualifies?(visit))
12
+
13
+ visit = create_visit(email: 'bcrouse@workarea.com')
14
+ refute(Tags.new(tags: %w(foo)).qualifies?(visit))
15
+
16
+ metrics.update!(tags: %w(bar))
17
+ visit = create_visit(email: 'bcrouse@workarea.com')
18
+ refute(Tags.new(tags: %w(foo)).qualifies?(visit))
19
+
20
+ metrics.update!(tags: %w(foo))
21
+ visit = create_visit(email: 'bcrouse@workarea.com')
22
+ assert(Tags.new(tags: %w(foo)).qualifies?(visit))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Segment
5
+ module Rules
6
+ class TrafficReferrerTest < TestCase
7
+ def test_qualifies?
8
+ visit = create_visit
9
+ refute(TrafficReferrer.new.qualifies?(visit))
10
+
11
+ visit = create_visit('HTTP_REFERER' => 'http://workarea.com/')
12
+ refute(TrafficReferrer.new.qualifies?(visit))
13
+
14
+ visit = create_visit('HTTP_REFERER' => 'https://www.google.com/')
15
+ assert(TrafficReferrer.new(source: 'google').qualifies?(visit))
16
+ assert(TrafficReferrer.new(source: ' Google').qualifies?(visit))
17
+ assert(TrafficReferrer.new(medium: 'Search').qualifies?(visit))
18
+ refute(TrafficReferrer.new(source: 'Facebook ').qualifies?(visit))
19
+ refute(TrafficReferrer.new(source: 'social').qualifies?(visit))
20
+
21
+ visit = create_visit('HTTP_REFERER' => 'https://www.facebook.com/')
22
+ refute(TrafficReferrer.new(source: ' Google').qualifies?(visit))
23
+ refute(TrafficReferrer.new(medium: 'search').qualifies?(visit))
24
+ assert(TrafficReferrer.new(source: 'facebook ').qualifies?(visit))
25
+ assert(TrafficReferrer.new(medium: 'Social').qualifies?(visit))
26
+ assert(TrafficReferrer.new(medium: 'Social', source: 'facebook|twitter').qualifies?(visit))
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class SegmentTest < TestCase
5
+ def test_find_qualifying
6
+ one = create_segment(rules: [Segment::Rules::Orders.new(minimum: 1)])
7
+ two = create_segment(rules: [Segment::Rules::Orders.new(minimum: 2)])
8
+ three = create_segment(rules: [Segment::Rules::Orders.new(minimum: 3)])
9
+
10
+ metrics = Metrics::User.create!(id: 'bcrouse@workarea.com')
11
+
12
+ visit = create_visit(email: 'bcrouse@workarea.com')
13
+ assert(Segment.find_qualifying(visit).empty?)
14
+
15
+ metrics.update_attributes!(orders: 1)
16
+ visit = create_visit(email: 'bcrouse@workarea.com')
17
+ assert_equal([one], Segment.find_qualifying(visit))
18
+
19
+ metrics.update_attributes!(orders: 2)
20
+ visit = create_visit(email: 'bcrouse@workarea.com')
21
+ assert_equal([one, two], Segment.find_qualifying(visit))
22
+
23
+ metrics.update_attributes!(orders: 3)
24
+ visit = create_visit(email: 'bcrouse@workarea.com')
25
+ assert_equal([one, two, three], Segment.find_qualifying(visit))
26
+ end
27
+
28
+ def test_current
29
+ assert_equal([], Segment.current)
30
+
31
+ segment = create_segment
32
+ Segment.with_current(segment) { assert_equal([segment], Segment.current) }
33
+ assert_equal([], Segment.current)
34
+
35
+ Segment.with_current([segment]) { assert_equal([segment], Segment.current) }
36
+ assert_equal([], Segment.current)
37
+
38
+ assert_raises { Segment.with_current(segment) { raise 'foo' } }
39
+ assert_equal([], Segment.current)
40
+ end
41
+
42
+ def test_with_current_returns_the_value_from_the_block
43
+ segment = create_segment
44
+ result = Segment.with_current(segment) { 'foo' }
45
+ assert_equal('foo', result)
46
+ end
47
+
48
+ def test_qualifies
49
+ segment = create_segment(
50
+ rules: [
51
+ Segment::Rules::Orders.new(minimum: 2),
52
+ Segment::Rules::Sessions.new(minimum: 5)
53
+ ]
54
+ )
55
+
56
+ metrics = Metrics::User.create!(id: 'bcrouse@workarea.com')
57
+
58
+ visit = create_visit(email: 'bcrouse@workarea.com')
59
+ refute(segment.qualifies?(visit))
60
+
61
+ metrics.update_attributes!(orders: 2)
62
+ visit = create_visit(email: 'bcrouse@workarea.com')
63
+ refute(segment.qualifies?(visit))
64
+
65
+ visit = create_visit(email: 'bcrouse@workarea.com', sessions: 2)
66
+ refute(segment.qualifies?(visit))
67
+
68
+ visit = create_visit(email: 'bcrouse@workarea.com', sessions: 5)
69
+ assert(segment.qualifies?(visit))
70
+ end
71
+
72
+ def test_validates_max_segments
73
+ 15.times { create_segment }
74
+
75
+ segment = Segment.new
76
+ refute(segment.valid?)
77
+ assert_includes(segment.errors[:base], t('workarea.errors.messages.max_allowed_segments'))
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class SegmentableTest < TestCase
5
+ class Foo
6
+ include Mongoid::Document
7
+ include Releasable
8
+ include Segmentable
9
+ end
10
+
11
+ def test_active_by_segment
12
+ segment_one = create_segment(name: 'One')
13
+ segment_two = create_segment(name: 'Two')
14
+
15
+ model = Foo.create!(active: false, active_segment_ids: [])
16
+ refute(model.active?)
17
+
18
+ model.update!(active: true, active_segment_ids: [])
19
+ assert(model.active?)
20
+
21
+ model.update!(active_segment_ids: [segment_one.id])
22
+ assert(model.active?)
23
+ Segment.with_current { refute(model.active?) }
24
+ Segment.with_current(segment_one) { assert(model.active?) }
25
+ Segment.with_current(segment_two) { refute(model.active?) }
26
+ Segment.with_current(segment_one, segment_two) { assert(model.active?) }
27
+
28
+ model.update!(active_segment_ids: [segment_two.id])
29
+ assert(model.active?)
30
+ Segment.with_current { refute(model.active?) }
31
+ Segment.with_current(segment_one) { refute(model.active?) }
32
+ Segment.with_current(segment_two) { assert(model.active?) }
33
+ Segment.with_current(segment_one, segment_two) { assert(model.active?) }
34
+
35
+ model.update!(active_segment_ids: [segment_one.id, segment_two.id])
36
+ assert(model.active?)
37
+ Segment.with_current { refute(model.active?) }
38
+ Segment.with_current(segment_one) { assert(model.active?) }
39
+ Segment.with_current(segment_two) { assert(model.active?) }
40
+ Segment.with_current(segment_one, segment_two) { assert(model.active?) }
41
+ end
42
+
43
+ def test_segments_and_activate_with
44
+ segment_one = create_segment
45
+ segment_two = create_segment
46
+ release = create_release
47
+
48
+ model = Foo.create!(activate_with: release.id, active_segment_ids: [segment_one.id])
49
+ refute(model.reload.active?)
50
+
51
+ Segment.with_current do
52
+ refute(model.reload.active?)
53
+ release.as_current { refute(model.reload.active?) }
54
+ end
55
+
56
+ Segment.with_current(segment_one) do
57
+ refute(model.reload.active?)
58
+ release.as_current { assert(model.reload.active?) }
59
+ end
60
+
61
+ Segment.with_current(segment_two) do
62
+ refute(model.reload.active?)
63
+ release.as_current { refute(model.reload.active?) }
64
+ end
65
+
66
+ release.publish!
67
+ assert(model.reload.active?)
68
+
69
+ Segment.with_current { refute(model.reload.active?) }
70
+ Segment.with_current(segment_one) { assert(model.reload.active?) }
71
+ Segment.with_current(segment_two) { refute(model.reload.active?) }
72
+ end
73
+ end
74
+ end
@@ -4,117 +4,115 @@ module Workarea
4
4
  class Shipping
5
5
  class AddressTest < TestCase
6
6
  def test_po_box_addresses
7
- Workarea.with_config do |config|
8
- address = Shipping::Address.new(
9
- first_name: 'Ben',
10
- last_name: 'Crouse',
11
- street: '22 S. 3rd St.',
12
- street_2: 'Second Floor',
13
- city: 'Philadelphia',
14
- region: 'PA',
15
- postal_code: '19106',
16
- country: 'US'
17
- )
18
-
19
- config.allow_shipping_address_po_box = false
20
-
21
- po_boxes = [
22
- 'PO Box 123',
23
- 'P O box 123',
24
- 'P. O. Box 123',
25
- 'P.O.Box 123',
26
- 'post box 123',
27
- 'post office box 123',
28
- 'post office 123',
29
- 'P.O.B 123',
30
- 'P.O.B. 123',
31
- 'Post Office Bin 123',
32
- 'Postal Code 123',
33
- 'Post Box #123',
34
- 'Postal Box 123',
35
- 'P.O. Box 123',
36
- 'PO. Box 123',
37
- 'P.o box 123',
38
- 'Pobox 123',
39
- 'pob 123',
40
- 'pob123',
41
- 'pobox123',
42
- 'p.o. Box123',
43
- 'po-box123',
44
- 'p.o.-box 123',
45
- 'PO-Box 123',
46
- 'p-o-box 123',
47
- 'p-o box 123',
48
- 'box 123',
49
- 'Box123',
50
- 'Box-123'
51
- ]
52
-
53
- non_po_boxes = [
54
- '123 Box Turtle Circle',
55
- '123 Boxing Pass',
56
- '123 Poblano Lane',
57
- '123 P O Davis Drive',
58
- '123 Postal Circle'
59
- ]
60
-
61
- po_boxes.each do |po_box|
62
- address.street = po_box
63
- refute(address.valid?)
64
- refute(address.errors[:street].empty?)
65
- end
66
-
67
- address.street = '22 S. 3rd St'
68
- po_boxes.each do |po_box|
69
- address.street_2 = po_box
70
- refute(address.valid?)
71
- refute(address.errors[:street_2].empty?)
72
- end
73
-
74
- config.allow_shipping_address_po_box = true
75
- address.street_2 = 'Second Floor'
76
-
77
- po_boxes.each do |po_box|
78
- address.street = po_box
79
- assert(address.valid?)
80
- refute(address.errors[:street].present?)
81
- end
82
-
83
- address.street = '22 S. 3rd St'
84
- po_boxes.each do |po_box|
85
- address.street_2 = po_box
86
- assert(address.valid?)
87
- refute(address.errors[:street_2].present?)
88
- end
89
-
90
- non_po_boxes.each do |non_po_box|
91
- address.street = non_po_box
92
- assert(address.valid?)
93
- assert(address.errors[:street].empty?)
94
- end
95
-
96
- address.street = '22 S. 3rd St'
97
- non_po_boxes.each do |non_po_box|
98
- address.street_2 = non_po_box
99
- assert(address.valid?)
100
- assert(address.errors[:street_2].empty?)
101
- end
102
-
103
- config.allow_shipping_address_po_box = true
104
- address.street_2 = 'Second Floor'
105
-
106
- non_po_boxes.each do |non_po_box|
107
- address.street = non_po_box
108
- assert(address.valid?)
109
- refute(address.errors[:street].present?)
110
- end
111
-
112
- address.street = '22 S. 3rd St'
113
- non_po_boxes.each do |non_po_box|
114
- address.street_2 = non_po_box
115
- assert(address.valid?)
116
- refute(address.errors[:street_2].present?)
117
- end
7
+ address = Shipping::Address.new(
8
+ first_name: 'Ben',
9
+ last_name: 'Crouse',
10
+ street: '22 S. 3rd St.',
11
+ street_2: 'Second Floor',
12
+ city: 'Philadelphia',
13
+ region: 'PA',
14
+ postal_code: '19106',
15
+ country: 'US'
16
+ )
17
+
18
+ Workarea.config.allow_shipping_address_po_box = false
19
+
20
+ po_boxes = [
21
+ 'PO Box 123',
22
+ 'P O box 123',
23
+ 'P. O. Box 123',
24
+ 'P.O.Box 123',
25
+ 'post box 123',
26
+ 'post office box 123',
27
+ 'post office 123',
28
+ 'P.O.B 123',
29
+ 'P.O.B. 123',
30
+ 'Post Office Bin 123',
31
+ 'Postal Code 123',
32
+ 'Post Box #123',
33
+ 'Postal Box 123',
34
+ 'P.O. Box 123',
35
+ 'PO. Box 123',
36
+ 'P.o box 123',
37
+ 'Pobox 123',
38
+ 'pob 123',
39
+ 'pob123',
40
+ 'pobox123',
41
+ 'p.o. Box123',
42
+ 'po-box123',
43
+ 'p.o.-box 123',
44
+ 'PO-Box 123',
45
+ 'p-o-box 123',
46
+ 'p-o box 123',
47
+ 'box 123',
48
+ 'Box123',
49
+ 'Box-123'
50
+ ]
51
+
52
+ non_po_boxes = [
53
+ '123 Box Turtle Circle',
54
+ '123 Boxing Pass',
55
+ '123 Poblano Lane',
56
+ '123 P O Davis Drive',
57
+ '123 Postal Circle'
58
+ ]
59
+
60
+ po_boxes.each do |po_box|
61
+ address.street = po_box
62
+ refute(address.valid?)
63
+ refute(address.errors[:street].empty?)
64
+ end
65
+
66
+ address.street = '22 S. 3rd St'
67
+ po_boxes.each do |po_box|
68
+ address.street_2 = po_box
69
+ refute(address.valid?)
70
+ refute(address.errors[:street_2].empty?)
71
+ end
72
+
73
+ Workarea.config.allow_shipping_address_po_box = true
74
+ address.street_2 = 'Second Floor'
75
+
76
+ po_boxes.each do |po_box|
77
+ address.street = po_box
78
+ assert(address.valid?)
79
+ refute(address.errors[:street].present?)
80
+ end
81
+
82
+ address.street = '22 S. 3rd St'
83
+ po_boxes.each do |po_box|
84
+ address.street_2 = po_box
85
+ assert(address.valid?)
86
+ refute(address.errors[:street_2].present?)
87
+ end
88
+
89
+ non_po_boxes.each do |non_po_box|
90
+ address.street = non_po_box
91
+ assert(address.valid?)
92
+ assert(address.errors[:street].empty?)
93
+ end
94
+
95
+ address.street = '22 S. 3rd St'
96
+ non_po_boxes.each do |non_po_box|
97
+ address.street_2 = non_po_box
98
+ assert(address.valid?)
99
+ assert(address.errors[:street_2].empty?)
100
+ end
101
+
102
+ Workarea.config.allow_shipping_address_po_box = true
103
+ address.street_2 = 'Second Floor'
104
+
105
+ non_po_boxes.each do |non_po_box|
106
+ address.street = non_po_box
107
+ assert(address.valid?)
108
+ refute(address.errors[:street].present?)
109
+ end
110
+
111
+ address.street = '22 S. 3rd St'
112
+ non_po_boxes.each do |non_po_box|
113
+ address.street_2 = non_po_box
114
+ assert(address.valid?)
115
+ refute(address.errors[:street_2].present?)
118
116
  end
119
117
  end
120
118
 
@@ -6,25 +6,21 @@ module Workarea
6
6
  def test_length_units
7
7
  sku = create_shipping_sku
8
8
 
9
- Workarea.with_config do |config|
10
- config.shipping_options = { units: :imperial }
11
- assert_equal(:inches, sku.length_units)
9
+ Workarea.config.shipping_options = { units: :imperial }
10
+ assert_equal(:inches, sku.length_units)
12
11
 
13
- config.shipping_options = { units: :metric }
14
- assert_equal(:centimeters, sku.length_units)
15
- end
12
+ Workarea.config.shipping_options = { units: :metric }
13
+ assert_equal(:centimeters, sku.length_units)
16
14
  end
17
15
 
18
16
  def test_weight_units
19
17
  sku = create_shipping_sku
20
18
 
21
- Workarea.with_config do |config|
22
- config.shipping_options = { units: :imperial }
23
- assert_equal(:ounces, sku.weight_units)
19
+ Workarea.config.shipping_options = { units: :imperial }
20
+ assert_equal(:ounces, sku.weight_units)
24
21
 
25
- config.shipping_options = { units: :metric }
26
- assert_equal(:grams, sku.weight_units)
27
- end
22
+ Workarea.config.shipping_options = { units: :metric }
23
+ assert_equal(:grams, sku.weight_units)
28
24
  end
29
25
  end
30
26
  end
@@ -4,22 +4,14 @@ module Workarea
4
4
  class User
5
5
  class PasswordResetTest < TestCase
6
6
  def user
7
- @user ||= create_user(email: 'one@workarea.com')
7
+ @user ||= create_user
8
8
  end
9
9
 
10
10
  def test_setup!
11
- 2.times do
12
- PasswordReset.setup!(user.email)
11
+ PasswordReset.setup!(user.email)
13
12
 
14
- assert_equal(1, PasswordReset.count)
15
- assert_equal(user.id, PasswordReset.first.user_id)
16
- end
17
-
18
- two = create_user(email: 'two@workarea.com')
19
- PasswordReset.setup!('two@workarea.com')
20
-
21
- assert_equal(2, PasswordReset.count)
22
- assert_equal(two.id, PasswordReset.last.user_id)
13
+ assert_equal(1, PasswordReset.count)
14
+ assert_equal(user.id, PasswordReset.first.user_id)
23
15
  end
24
16
 
25
17
  def test_complete
@@ -280,24 +280,27 @@ module Workarea
280
280
  end
281
281
 
282
282
  def test_admins_have_more_advanced_password_requirements
283
- Workarea.with_config do |config|
284
- config.password_strength = :weak
283
+ Workarea.config.password_strength = :weak
285
284
 
286
- user = User.new(admin: false, password: 'password').tap(&:valid?)
287
- assert(user.errors[:password].blank?)
285
+ user = User.new(admin: false, password: 'password').tap(&:valid?)
286
+ assert(user.errors[:password].blank?)
288
287
 
289
- user = User.new(admin: true, password: 'password').tap(&:valid?)
290
- assert(user.errors[:password].present?)
288
+ user = User.new(admin: true, password: 'password').tap(&:valid?)
289
+ assert(user.errors[:password].present?)
291
290
 
292
- user = User.new(admin: true, password: 'xykrDQXT]9Ai7XEXfe').tap(&:valid?)
293
- assert(user.errors[:password].blank?)
294
- end
291
+ user = User.new(admin: true, password: 'xykrDQXT]9Ai7XEXfe').tap(&:valid?)
292
+ assert(user.errors[:password].blank?)
295
293
  end
296
294
 
297
295
  def test_admin_permissions_revoked_when_no_longer_admin
298
296
  user = create_user(admin: true, releases_access: true)
299
297
  user.update_attributes!(admin: false)
300
298
  refute(user.releases_access?)
299
+
300
+ user = create_user(super_admin: true, releases_access: true)
301
+ user.update!(super_admin: false)
302
+ refute(user.admin?)
303
+ refute(user.releases_access?)
301
304
  end
302
305
 
303
306
  def test_status_email_recipients_only_admins
@@ -306,7 +309,7 @@ module Workarea
306
309
 
307
310
  status_email_recipients = User.status_email_recipients
308
311
  assert_equal(1, status_email_recipients.size)
309
- assert_equal(admin.email, status_email_recipients.first)
312
+ assert_equal(admin, status_email_recipients.first)
310
313
  end
311
314
  end
312
315
  end
@@ -60,31 +60,27 @@ module Workarea
60
60
  def test_scroll
61
61
  50.times { |i| create_redirect(path: "/#{i}", destination: '/bar') }
62
62
 
63
- Workarea.with_config do |config|
64
- config.per_page = 5
65
-
66
- query = AdminSearchQueryWrapper.new(
67
- model_type: 'Workarea::Navigation::Redirect'
68
- )
69
-
70
- count = 0
71
- passes = 0
72
- query.scroll { |results| count += results.size; passes += 1 }
73
- assert_equal(50, count)
74
- assert_equal(10, passes)
75
-
76
- config.per_page = 500
77
-
78
- query = AdminSearchQueryWrapper.new(
79
- model_type: 'Workarea::Navigation::Redirect'
80
- )
81
-
82
- count = 0
83
- passes = 0
84
- query.scroll { |results| count += results.size; passes += 1 }
85
- assert_equal(50, count)
86
- assert_equal(1, passes)
87
- end
63
+ query = AdminSearchQueryWrapper.new(
64
+ model_type: 'Workarea::Navigation::Redirect',
65
+ per_page: 5
66
+ )
67
+
68
+ count = 0
69
+ passes = 0
70
+ query.scroll { |results| count += results.size; passes += 1 }
71
+ assert_equal(50, count)
72
+ assert_equal(10, passes)
73
+
74
+ query = AdminSearchQueryWrapper.new(
75
+ model_type: 'Workarea::Navigation::Redirect',
76
+ per_page: 500
77
+ )
78
+
79
+ count = 0
80
+ passes = 0
81
+ query.scroll { |results| count += results.size; passes += 1 }
82
+ assert_equal(50, count)
83
+ assert_equal(1, passes)
88
84
  end
89
85
  end
90
86
  end
@@ -84,5 +84,54 @@ module Workarea
84
84
  assert_equal(0, categorization.size)
85
85
  assert_equal([], categorization.to_models)
86
86
  end
87
+
88
+ def test_finding_categories_based_on_current_release
89
+ release = create_release(publish_at: 1.day.from_now)
90
+ category_one = create_category
91
+ category_two = create_category(product_ids: [@product.id])
92
+
93
+ release.as_current do
94
+ category_one.update!(product_ids: [@product.id])
95
+ assert_equal(
96
+ [category_two.id.to_s, category_one.id.to_s],
97
+ Categorization.new(@product).to_a
98
+ )
99
+ end
100
+
101
+ release.changesets.destroy_all
102
+ category_one.reload.update!(product_ids: [@product.id])
103
+
104
+ release.as_current do
105
+ category_one.update!(product_ids: [])
106
+ assert_equal([category_two.id.to_s], Categorization.new(@product).to_a)
107
+ end
108
+
109
+ create_release(publish_at: 2.days.from_now).as_current do
110
+ assert_equal([category_two.id.to_s], Categorization.new(@product).to_a)
111
+ end
112
+ end
113
+
114
+ def test_finding_rule_categories_based_on_current_release
115
+ bar = create_product(name: 'Bar')
116
+ category_one = create_category(product_rules: [{ name: 'search', operator: 'equals', value: 'foo' }])
117
+ category_two = create_category(product_rules: [{ name: 'search', operator: 'equals', value: 'bar' }])
118
+
119
+ assert_equal([category_one.id.to_s], Categorization.new(@product).queries)
120
+ assert_equal([category_two.id.to_s], Categorization.new(bar).queries)
121
+
122
+ release = create_release
123
+ release.as_current do
124
+ category_one.product_rules.first.update!(name: 'search', operator: 'equals', value: 'bar')
125
+
126
+ assert_equal([], Categorization.new(@product).queries)
127
+ assert_equal(
128
+ [category_two.id.to_s, category_one.id.to_s],
129
+ Categorization.new(bar).queries
130
+ )
131
+ end
132
+
133
+ assert_equal([category_one.id.to_s], Categorization.new(@product).queries)
134
+ assert_equal([category_two.id.to_s], Categorization.new(bar).queries)
135
+ end
87
136
  end
88
137
  end