solidus_backend 1.3.2 → 1.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_backend might be problematic. Click here for more details.

Files changed (290) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -0
  3. data/app/assets/javascripts/spree/backend/components/tooltips.js +2 -0
  4. data/app/assets/javascripts/spree/backend/product_picker.js +2 -2
  5. data/app/assets/javascripts/spree/backend/routes.js +0 -1
  6. data/app/assets/javascripts/spree/backend/shipments.js +147 -118
  7. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +16 -14
  8. data/app/assets/javascripts/spree/backend/templates/orders/customer_details/autocomplete.hbs +1 -1
  9. data/app/assets/javascripts/spree/backend/templates/variants/autocomplete.hbs.erb +1 -1
  10. data/app/assets/javascripts/spree/backend/templates/variants/line_items_autocomplete_stock.hbs +1 -1
  11. data/app/assets/javascripts/spree/backend/templates/variants/split.hbs +25 -27
  12. data/app/assets/javascripts/spree/backend/user_picker.js +14 -8
  13. data/app/assets/stylesheets/spree/backend/_bootstrap_custom.scss +3 -3
  14. data/app/assets/stylesheets/spree/backend/components/_breadcrumb.scss +4 -0
  15. data/app/assets/stylesheets/spree/backend/components/_date-picker.scss +0 -1
  16. data/app/assets/stylesheets/spree/backend/components/_hint.scss +3 -0
  17. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +0 -1
  18. data/app/assets/stylesheets/spree/backend/components/_progress.scss +5 -2
  19. data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +14 -5
  20. data/app/assets/stylesheets/spree/backend/components/_states.scss +1 -2
  21. data/app/assets/stylesheets/spree/backend/globals/_mixins.css +2 -0
  22. data/app/assets/stylesheets/spree/backend/globals/mixins/_line_through.scss +22 -0
  23. data/app/assets/stylesheets/spree/backend/plugins/_select2.scss +12 -3
  24. data/app/assets/stylesheets/spree/backend/sections/_products.scss +25 -7
  25. data/app/assets/stylesheets/spree/backend/sections/_promotions.scss +0 -1
  26. data/app/assets/stylesheets/spree/backend/sections/_transfer_items.scss +0 -1
  27. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +4 -6
  28. data/app/assets/stylesheets/spree/backend/shared/_header.scss +5 -2
  29. data/app/assets/stylesheets/spree/backend/shared/_layout.scss +36 -3
  30. data/app/assets/stylesheets/spree/backend/shared/_tables.scss +1 -3
  31. data/app/assets/stylesheets/spree/backend/shared/_typography.scss +0 -2
  32. data/app/assets/stylesheets/spree/backend/spree_admin.scss +3 -1
  33. data/app/controllers/spree/admin/cancellations_controller.rb +1 -1
  34. data/app/controllers/spree/admin/general_settings_controller.rb +0 -6
  35. data/app/controllers/spree/admin/orders/customer_details_controller.rb +7 -0
  36. data/app/controllers/spree/admin/orders_controller.rb +1 -1
  37. data/app/controllers/spree/admin/payment_methods_controller.rb +8 -3
  38. data/app/controllers/spree/admin/payments_controller.rb +12 -5
  39. data/app/controllers/spree/admin/products_controller.rb +1 -1
  40. data/app/controllers/spree/admin/refunds_controller.rb +1 -1
  41. data/app/controllers/spree/admin/reimbursements_controller.rb +1 -1
  42. data/app/controllers/spree/admin/root_controller.rb +1 -1
  43. data/app/controllers/spree/admin/stock_items_controller.rb +0 -8
  44. data/app/controllers/spree/admin/stock_transfers_controller.rb +6 -6
  45. data/app/controllers/spree/admin/users_controller.rb +7 -3
  46. data/app/helpers/spree/admin/base_helper.rb +11 -0
  47. data/app/helpers/spree/admin/navigation_helper.rb +46 -3
  48. data/app/helpers/spree/admin/orders_helper.rb +0 -1
  49. data/app/helpers/spree/admin/stock_locations_helper.rb +1 -5
  50. data/app/models/spree/backend_configuration.rb +100 -0
  51. data/app/views/spree/admin/adjustment_reasons/edit.html.erb +4 -7
  52. data/app/views/spree/admin/adjustment_reasons/index.html.erb +4 -4
  53. data/app/views/spree/admin/adjustment_reasons/new.html.erb +4 -4
  54. data/app/views/spree/admin/adjustments/edit.html.erb +4 -6
  55. data/app/views/spree/admin/adjustments/index.html.erb +3 -6
  56. data/app/views/spree/admin/adjustments/new.html.erb +5 -6
  57. data/app/views/spree/admin/cancellations/index.html.erb +4 -3
  58. data/app/views/spree/admin/countries/edit.html.erb +4 -6
  59. data/app/views/spree/admin/countries/index.html.erb +4 -4
  60. data/app/views/spree/admin/countries/new.html.erb +4 -4
  61. data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +1 -1
  62. data/app/views/spree/admin/customer_returns/edit.html.erb +4 -6
  63. data/app/views/spree/admin/customer_returns/index.html.erb +2 -5
  64. data/app/views/spree/admin/customer_returns/new.html.erb +5 -6
  65. data/app/views/spree/admin/general_settings/edit.html.erb +4 -28
  66. data/app/views/spree/admin/images/edit.html.erb +6 -2
  67. data/app/views/spree/admin/images/index.html.erb +3 -0
  68. data/app/views/spree/admin/images/new.html.erb +3 -3
  69. data/app/views/spree/admin/log_entries/index.html.erb +4 -8
  70. data/app/views/spree/admin/option_types/edit.html.erb +7 -9
  71. data/app/views/spree/admin/option_types/index.html.erb +4 -4
  72. data/app/views/spree/admin/orders/_shipment.html.erb +4 -1
  73. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +4 -1
  74. data/app/views/spree/admin/orders/cart.html.erb +4 -8
  75. data/app/views/spree/admin/orders/confirm.html.erb +3 -4
  76. data/app/views/spree/admin/orders/confirm/_payments.html.erb +1 -1
  77. data/app/views/spree/admin/orders/confirm_advance.html.erb +3 -4
  78. data/app/views/spree/admin/orders/customer_details/_form.html.erb +1 -1
  79. data/app/views/spree/admin/orders/customer_details/edit.html.erb +2 -4
  80. data/app/views/spree/admin/orders/customer_details/show.html.erb +3 -5
  81. data/app/views/spree/admin/orders/edit.html.erb +1 -8
  82. data/app/views/spree/admin/orders/index.html.erb +11 -5
  83. data/app/views/spree/admin/payment_methods/edit.html.erb +5 -7
  84. data/app/views/spree/admin/payment_methods/index.html.erb +6 -5
  85. data/app/views/spree/admin/payment_methods/new.html.erb +6 -7
  86. data/app/views/spree/admin/payments/_capture_events.html.erb +1 -1
  87. data/app/views/spree/admin/payments/credit.html.erb +3 -3
  88. data/app/views/spree/admin/payments/index.html.erb +4 -7
  89. data/app/views/spree/admin/payments/new.html.erb +4 -5
  90. data/app/views/spree/admin/payments/show.html.erb +4 -7
  91. data/app/views/spree/admin/prices/_form.html.erb +1 -0
  92. data/app/views/spree/admin/prices/index.html.erb +2 -2
  93. data/app/views/spree/admin/product_properties/index.html.erb +3 -1
  94. data/app/views/spree/admin/products/_form.html.erb +11 -18
  95. data/app/views/spree/admin/products/_properties_form.erb +1 -1
  96. data/app/views/spree/admin/products/edit.html.erb +3 -2
  97. data/app/views/spree/admin/products/index.html.erb +19 -28
  98. data/app/views/spree/admin/products/new.html.erb +4 -2
  99. data/app/views/spree/admin/promotion_categories/edit.html.erb +4 -3
  100. data/app/views/spree/admin/promotion_categories/index.html.erb +4 -4
  101. data/app/views/spree/admin/promotion_categories/new.html.erb +4 -3
  102. data/app/views/spree/admin/promotion_rules/create.js.erb +1 -1
  103. data/app/views/spree/admin/promotions/_actions.html.erb +3 -3
  104. data/app/views/spree/admin/promotions/_rules.html.erb +2 -2
  105. data/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb +1 -1
  106. data/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb +1 -1
  107. data/app/views/spree/admin/promotions/edit.html.erb +4 -5
  108. data/app/views/spree/admin/promotions/index.html.erb +3 -5
  109. data/app/views/spree/admin/promotions/new.html.erb +3 -3
  110. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +2 -2
  111. data/app/views/spree/admin/properties/edit.html.erb +3 -6
  112. data/app/views/spree/admin/properties/index.html.erb +5 -5
  113. data/app/views/spree/admin/prototypes/_form.html.erb +3 -3
  114. data/app/views/spree/admin/prototypes/_prototypes.html.erb +1 -1
  115. data/app/views/spree/admin/prototypes/edit.html.erb +3 -6
  116. data/app/views/spree/admin/prototypes/index.html.erb +4 -4
  117. data/app/views/spree/admin/prototypes/show.html.erb +2 -2
  118. data/app/views/spree/admin/refund_reasons/edit.html.erb +4 -4
  119. data/app/views/spree/admin/refund_reasons/index.html.erb +5 -4
  120. data/app/views/spree/admin/refund_reasons/new.html.erb +5 -4
  121. data/app/views/spree/admin/refunds/edit.html.erb +5 -6
  122. data/app/views/spree/admin/refunds/new.html.erb +6 -6
  123. data/app/views/spree/admin/reimbursement_types/index.html.erb +4 -3
  124. data/app/views/spree/admin/reimbursements/edit.html.erb +5 -6
  125. data/app/views/spree/admin/reimbursements/index.html.erb +2 -4
  126. data/app/views/spree/admin/reimbursements/show.html.erb +3 -4
  127. data/app/views/spree/admin/reports/index.html.erb +2 -3
  128. data/app/views/spree/admin/reports/sales_total.html.erb +2 -4
  129. data/app/views/spree/admin/return_authorizations/edit.html.erb +15 -16
  130. data/app/views/spree/admin/return_authorizations/index.html.erb +3 -5
  131. data/app/views/spree/admin/return_authorizations/new.html.erb +5 -6
  132. data/app/views/spree/admin/return_reasons/edit.html.erb +3 -2
  133. data/app/views/spree/admin/return_reasons/index.html.erb +3 -1
  134. data/app/views/spree/admin/return_reasons/new.html.erb +4 -2
  135. data/app/views/spree/admin/shared/_areas_tabs.html.erb +3 -3
  136. data/app/views/spree/admin/shared/_configuration_menu.html.erb +2 -2
  137. data/app/views/spree/admin/shared/_edit_resource_links.html.erb +2 -2
  138. data/app/views/spree/admin/shared/_head.html.erb +1 -8
  139. data/app/views/spree/admin/shared/_header.html.erb +8 -12
  140. data/app/views/spree/admin/shared/_new_resource_links.html.erb +2 -2
  141. data/app/views/spree/admin/shared/_no_objects_found.html.erb +1 -1
  142. data/app/views/spree/admin/shared/_order_submenu.html.erb +10 -10
  143. data/app/views/spree/admin/shared/_order_summary.html.erb +1 -1
  144. data/app/views/spree/admin/shared/_order_tabs.html.erb +3 -3
  145. data/app/views/spree/admin/shared/_payments_tabs.html.erb +1 -1
  146. data/app/views/spree/admin/shared/_product_sub_menu.html.erb +2 -2
  147. data/app/views/spree/admin/shared/_product_tabs.html.erb +8 -9
  148. data/app/views/spree/admin/shared/_report_criteria.html.erb +2 -2
  149. data/app/views/spree/admin/shared/_report_order_criteria.html.erb +2 -2
  150. data/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb +4 -4
  151. data/app/views/spree/admin/shared/_settings_sub_menu.html.erb +5 -5
  152. data/app/views/spree/admin/shared/_shipping_tabs.html.erb +4 -3
  153. data/app/views/spree/admin/shared/_sidebar.html.erb +1 -1
  154. data/app/views/spree/admin/shared/_tabs.html.erb +12 -37
  155. data/app/views/spree/admin/shared/_taxes_tabs.html.erb +2 -2
  156. data/app/views/spree/admin/shared/_variant_search.html.erb +1 -1
  157. data/app/views/spree/admin/shared/named_types/_edit.html.erb +5 -5
  158. data/app/views/spree/admin/shared/named_types/_index.html.erb +5 -4
  159. data/app/views/spree/admin/shared/named_types/_new.html.erb +5 -4
  160. data/app/views/spree/admin/shipping_categories/edit.html.erb +5 -6
  161. data/app/views/spree/admin/shipping_categories/index.html.erb +5 -4
  162. data/app/views/spree/admin/shipping_categories/new.html.erb +5 -6
  163. data/app/views/spree/admin/shipping_methods/_form.html.erb +2 -2
  164. data/app/views/spree/admin/shipping_methods/edit.html.erb +5 -6
  165. data/app/views/spree/admin/shipping_methods/index.html.erb +5 -5
  166. data/app/views/spree/admin/shipping_methods/new.html.erb +5 -6
  167. data/app/views/spree/admin/states/edit.html.erb +5 -6
  168. data/app/views/spree/admin/states/index.html.erb +5 -4
  169. data/app/views/spree/admin/states/new.html.erb +5 -3
  170. data/app/views/spree/admin/stock_items/index.html.erb +4 -7
  171. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +2 -2
  172. data/app/views/spree/admin/stock_locations/edit.html.erb +5 -5
  173. data/app/views/spree/admin/stock_locations/index.html.erb +16 -9
  174. data/app/views/spree/admin/stock_locations/new.html.erb +5 -4
  175. data/app/views/spree/admin/stock_movements/index.html.erb +3 -4
  176. data/app/views/spree/admin/stock_movements/new.html.erb +2 -3
  177. data/app/views/spree/admin/stock_transfers/_location.html.erb +7 -0
  178. data/app/views/spree/admin/stock_transfers/_transfer_item_table.html.erb +1 -1
  179. data/app/views/spree/admin/stock_transfers/edit.html.erb +5 -6
  180. data/app/views/spree/admin/stock_transfers/index.html.erb +5 -5
  181. data/app/views/spree/admin/stock_transfers/new.html.erb +6 -8
  182. data/app/views/spree/admin/stock_transfers/receive.html.erb +4 -12
  183. data/app/views/spree/admin/stock_transfers/show.html.erb +6 -12
  184. data/app/views/spree/admin/stock_transfers/tracking_info.html.erb +5 -13
  185. data/app/views/spree/admin/store_credits/edit_amount.html.erb +6 -4
  186. data/app/views/spree/admin/store_credits/edit_validity.html.erb +8 -6
  187. data/app/views/spree/admin/store_credits/index.html.erb +5 -5
  188. data/app/views/spree/admin/store_credits/new.html.erb +5 -4
  189. data/app/views/spree/admin/store_credits/show.html.erb +5 -4
  190. data/app/views/spree/admin/style_guide/topics/typography/_icons.html.erb +2 -2
  191. data/app/views/spree/admin/tax_categories/edit.html.erb +5 -4
  192. data/app/views/spree/admin/tax_categories/index.html.erb +5 -4
  193. data/app/views/spree/admin/tax_categories/new.html.erb +5 -4
  194. data/app/views/spree/admin/tax_rates/edit.html.erb +5 -6
  195. data/app/views/spree/admin/tax_rates/index.html.erb +5 -4
  196. data/app/views/spree/admin/tax_rates/new.html.erb +5 -6
  197. data/app/views/spree/admin/taxonomies/edit.erb +7 -9
  198. data/app/views/spree/admin/taxonomies/index.html.erb +4 -4
  199. data/app/views/spree/admin/taxonomies/new.html.erb +5 -7
  200. data/app/views/spree/admin/taxons/edit.html.erb +5 -6
  201. data/app/views/spree/admin/taxons/index.html.erb +2 -3
  202. data/app/views/spree/admin/trackers/edit.html.erb +5 -6
  203. data/app/views/spree/admin/trackers/index.html.erb +4 -4
  204. data/app/views/spree/admin/trackers/new.html.erb +4 -6
  205. data/app/views/spree/admin/users/_form.html.erb +2 -2
  206. data/app/views/spree/admin/users/_tabs.html.erb +5 -5
  207. data/app/views/spree/admin/users/_user_page_actions.html.erb +1 -4
  208. data/app/views/spree/admin/users/addresses.html.erb +5 -4
  209. data/app/views/spree/admin/users/edit.html.erb +6 -6
  210. data/app/views/spree/admin/users/index.html.erb +4 -5
  211. data/app/views/spree/admin/users/items.html.erb +4 -3
  212. data/app/views/spree/admin/users/new.html.erb +2 -9
  213. data/app/views/spree/admin/users/orders.html.erb +4 -3
  214. data/app/views/spree/admin/variants/_form.html.erb +1 -0
  215. data/app/views/spree/admin/variants/edit.html.erb +4 -3
  216. data/app/views/spree/admin/variants/index.html.erb +10 -8
  217. data/app/views/spree/admin/variants/new.html.erb +5 -0
  218. data/app/views/spree/admin/zones/_country_members.html.erb +2 -2
  219. data/app/views/spree/admin/zones/_state_members.html.erb +2 -2
  220. data/app/views/spree/admin/zones/edit.html.erb +5 -6
  221. data/app/views/spree/admin/zones/index.html.erb +5 -4
  222. data/app/views/spree/admin/zones/new.html.erb +6 -7
  223. data/app/views/spree/layouts/admin.html.erb +28 -15
  224. data/config/initializers/form_builder.rb +6 -0
  225. data/config/routes.rb +2 -6
  226. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +3 -3
  227. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +4 -4
  228. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +1 -1
  229. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +5 -5
  230. data/spec/controllers/spree/admin/orders_controller_spec.rb +28 -28
  231. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +5 -5
  232. data/spec/controllers/spree/admin/payments_controller_spec.rb +7 -7
  233. data/spec/controllers/spree/admin/prices_controller_spec.rb +2 -2
  234. data/spec/controllers/spree/admin/product_properties_controller_spec.rb +1 -1
  235. data/spec/controllers/spree/admin/products_controller_spec.rb +6 -6
  236. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +2 -2
  237. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +1 -1
  238. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +2 -2
  239. data/spec/controllers/spree/admin/promotions_controller_spec.rb +7 -7
  240. data/spec/controllers/spree/admin/refunds_controller_spec.rb +1 -1
  241. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +5 -5
  242. data/spec/controllers/spree/admin/reports_controller_spec.rb +2 -2
  243. data/spec/controllers/spree/admin/resource_controller_spec.rb +6 -6
  244. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +11 -11
  245. data/spec/controllers/spree/admin/return_items_controller_spec.rb +1 -1
  246. data/spec/controllers/spree/admin/search_controller_spec.rb +2 -2
  247. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +1 -1
  248. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +3 -3
  249. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +3 -3
  250. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +10 -10
  251. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +10 -10
  252. data/spec/controllers/spree/admin/users_controller_spec.rb +139 -141
  253. data/spec/controllers/spree/admin/variants_controller_spec.rb +2 -2
  254. data/spec/features/admin/configuration/general_settings_spec.rb +7 -16
  255. data/spec/features/admin/configuration/payment_methods_spec.rb +7 -7
  256. data/spec/features/admin/configuration/stock_locations_spec.rb +1 -1
  257. data/spec/features/admin/configuration/tax_categories_spec.rb +1 -1
  258. data/spec/features/admin/configuration/zones_spec.rb +1 -1
  259. data/spec/features/admin/homepage_spec.rb +2 -2
  260. data/spec/features/admin/orders/adjustments_spec.rb +1 -1
  261. data/spec/features/admin/orders/cancelling_inventory_spec.rb +8 -8
  262. data/spec/features/admin/orders/customer_details_spec.rb +20 -5
  263. data/spec/features/admin/orders/listing_spec.rb +97 -70
  264. data/spec/features/admin/orders/new_order_spec.rb +35 -6
  265. data/spec/features/admin/orders/order_details_spec.rb +37 -58
  266. data/spec/features/admin/orders/payments_spec.rb +57 -4
  267. data/spec/features/admin/orders/return_authorizations_spec.rb +25 -0
  268. data/spec/features/admin/orders/shipments_spec.rb +5 -5
  269. data/spec/features/admin/products/edit/products_spec.rb +1 -1
  270. data/spec/features/admin/products/edit/taxons_spec.rb +5 -5
  271. data/spec/features/admin/products/edit/variants_spec.rb +1 -1
  272. data/spec/features/admin/products/option_types_spec.rb +2 -2
  273. data/spec/features/admin/products/products_spec.rb +6 -6
  274. data/spec/features/admin/products/properties_spec.rb +6 -6
  275. data/spec/features/admin/products/prototypes_spec.rb +1 -1
  276. data/spec/features/admin/products/stock_management_spec.rb +5 -5
  277. data/spec/features/admin/promotion_adjustments_spec.rb +8 -8
  278. data/spec/features/admin/promotions/option_value_rule_spec.rb +4 -4
  279. data/spec/features/admin/promotions/product_rule_spec.rb +33 -0
  280. data/spec/features/admin/promotions/tiered_calculator_spec.rb +2 -2
  281. data/spec/features/admin/promotions/user_rule_spec.rb +15 -0
  282. data/spec/features/admin/reports_spec.rb +1 -1
  283. data/spec/features/admin/users_spec.rb +27 -2
  284. data/spec/helpers/admin/base_helper_spec.rb +30 -0
  285. data/spec/helpers/admin/navigation_helper_spec.rb +40 -2
  286. data/spec/spec_helper.rb +10 -8
  287. data/spec/support/feature/order_feature_helper.rb +17 -0
  288. metadata +18 -11
  289. data/app/assets/javascripts/spree/backend/general_settings.js.coffee +0 -13
  290. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +0 -41
@@ -3,255 +3,253 @@ require 'spree/testing_support/bar_ability'
3
3
 
4
4
  describe Spree::Admin::UsersController, type: :controller do
5
5
  let(:user) { create(:user) }
6
- let(:mock_user) { mock_model Spree.user_class }
7
6
 
8
- before do
9
- allow(controller).to receive_messages spree_current_user: user
10
- user.spree_roles.clear
7
+ let(:state) { create(:state, state_code: 'NY') }
8
+ let(:valid_address_attributes) do
9
+ {
10
+ firstname: 'Foo',
11
+ lastname: 'Bar',
12
+ city: "New York",
13
+ country_id: state.country.id,
14
+ state_id: state.id,
15
+ phone: '555-555-5555',
16
+ address1: '123 Fake St.',
17
+ zipcode: '10001',
18
+ }
11
19
  end
12
20
 
13
21
  context "#show" do
14
- before do
15
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
22
+ stub_authorization! do |_user|
23
+ can [:admin, :manage], Spree.user_class
16
24
  end
17
25
 
18
26
  it "redirects to edit" do
19
- spree_get :show, id: user.id
27
+ get :show, id: user.id
20
28
  expect(response).to redirect_to spree.edit_admin_user_path(user)
21
29
  end
22
30
  end
23
31
 
24
32
  context '#authorize_admin' do
25
- before { use_mock_user }
26
-
27
- it 'grant access to users with an admin role' do
28
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
29
- spree_post :index
30
- expect(response).to render_template :index
31
- end
33
+ context "with ability to admin users" do
34
+ stub_authorization! do |_user|
35
+ can [:manage], Spree.user_class
36
+ end
32
37
 
33
- it "allows admins to update a user's API key" do
34
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
35
- expect(mock_user).to receive(:generate_spree_api_key!).and_return(true)
36
- spree_put :generate_api_key, id: mock_user.id
37
- expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
38
- end
38
+ it 'can visit index' do
39
+ post :index
40
+ expect(response).to be_success
41
+ end
39
42
 
40
- it "allows admins to clear a user's API key" do
41
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
42
- expect(mock_user).to receive(:clear_spree_api_key!).and_return(true)
43
- spree_put :clear_api_key, id: mock_user.id
44
- expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
45
- end
43
+ it "allows admins to update a user's API key" do
44
+ expect {
45
+ put :generate_api_key, id: user.id
46
+ }.to change { user.reload.spree_api_key }
47
+ expect(response).to redirect_to(spree.edit_admin_user_path(user))
48
+ end
46
49
 
47
- it 'deny access to users with an bar role' do
48
- user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
49
- Spree::Ability.register_ability(BarAbility)
50
- spree_post :index
51
- expect(response).to redirect_to '/unauthorized'
50
+ it "allows admins to clear a user's API key" do
51
+ user.generate_spree_api_key!
52
+ expect {
53
+ put :clear_api_key, id: user.id
54
+ }.to change{ user.reload.spree_api_key }.to(nil)
55
+ expect(response).to redirect_to(spree.edit_admin_user_path(user))
56
+ end
52
57
  end
53
58
 
54
- it 'deny access to users with an bar role' do
55
- user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
56
- Spree::Ability.register_ability(BarAbility)
57
- spree_post :update, { id: '9' }
58
- expect(response).to redirect_to '/unauthorized'
59
- end
59
+ context "without ability to admin users" do
60
+ stub_authorization! do |_user|
61
+ end
60
62
 
61
- it 'deny access to users without an admin role' do
62
- allow(user).to receive_messages has_spree_role?: false
63
- spree_post :index
64
- expect(response).to redirect_to '/unauthorized'
63
+ it 'denies access' do
64
+ post :index
65
+ expect(response).to redirect_to '/unauthorized'
66
+ end
65
67
  end
66
68
  end
67
69
 
68
70
  describe "#create" do
69
71
  let(:dummy_role) { Spree::Role.create(name: "dummyrole") }
70
72
 
71
- before do
72
- use_mock_user
73
- allow(mock_user).to receive_messages(:spree_roles= => true, :stock_locations= => true)
74
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
73
+ # The created user
74
+ def user
75
+ Spree.user_class.last
76
+ end
77
+
78
+ stub_authorization! do |_user|
79
+ can :manage, Spree.user_class
75
80
  end
76
81
 
77
82
  context "when the user can manage roles" do
78
- it "can set roles" do
79
- expect(mock_user).to receive(:spree_roles=).with([dummy_role])
80
- spree_post :create, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
83
+ stub_authorization! do |_user|
84
+ can :manage, Spree.user_class
85
+ can :manage, Spree::Role
81
86
  end
82
87
 
83
- it "can clear roles" do
84
- expect(mock_user).to receive(:spree_roles=).with([])
85
- spree_post :create, { id: mock_user.id, user: { first_name: "Bob" } }
88
+ it "can create user with roles" do
89
+ post :create, { user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
90
+ expect(user.spree_roles).to eq([dummy_role])
86
91
  end
87
- end
88
92
 
89
- context "when the user cannot manage roles" do
90
- before do
91
- user.spree_roles = [Spree::Role.find_or_create_by(name: "user_management")]
93
+ it "can create user without roles" do
94
+ post :create, { user: { first_name: "Bob" } }
95
+ expect(user.spree_roles).to eq([])
92
96
  end
97
+ end
93
98
 
94
- it "cannot set roles" do
95
- expect(mock_user).to_not receive(:spree_roles=)
96
- spree_post :create, { user: { spree_role_ids: [dummy_role.id] } }
99
+ context "when the user cannot manage roles" do
100
+ it "cannot assign users roles" do
101
+ post :create, { user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
102
+ expect(user.spree_roles).to eq([])
97
103
  end
98
104
 
99
- it "cannot set roles" do
100
- expect(mock_user).to_not receive(:spree_roles=)
101
- spree_post :create, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
102
- end
103
-
104
- it "cannot clear roles" do
105
- expect(mock_user).to_not receive(:spree_roles=)
106
- spree_post :create, { id: mock_user.id, user: { first_name: "Bob" } }
105
+ it "can create user without roles" do
106
+ post :create, { user: { first_name: "Bob" } }
107
+ expect(user.spree_roles).to eq([])
107
108
  end
108
109
  end
109
110
 
110
111
  it "can create a shipping_address" do
111
- expect(Spree.user_class).to receive(:new).with(hash_including(
112
- "ship_address_attributes" => { "city" => "New York" }
113
- ))
114
- spree_post :create, { user: { ship_address_attributes: { city: "New York" } } }
112
+ post :create, { user: { ship_address_attributes: valid_address_attributes } }
113
+ expect(user.reload.ship_address.city).to eq('New York')
115
114
  end
116
115
 
117
116
  it "can create a billing_address" do
118
- expect(Spree.user_class).to receive(:new).with(hash_including(
119
- "bill_address_attributes" => { "city" => "New York" }
120
- ))
121
- spree_post :create, { user: { bill_address_attributes: { city: "New York" } } }
117
+ post :create, { user: { bill_address_attributes: valid_address_attributes } }
118
+ expect(user.reload.bill_address.city).to eq('New York')
122
119
  end
123
120
 
124
121
  it "can set stock locations" do
125
122
  location = Spree::StockLocation.create(name: "my_location")
126
123
  location_2 = Spree::StockLocation.create(name: "my_location_2")
127
- expect(mock_user).to receive(:stock_locations=).with([location, location_2])
128
- spree_post :create, { user: { stock_location_ids: [location.id, location_2.id] } }
124
+ post :create, { user: { stock_location_ids: [location.id, location_2.id] } }
125
+ expect(user.stock_locations).to match_array([location, location_2])
129
126
  end
130
127
  end
131
128
 
132
129
  describe "#update" do
133
130
  let(:dummy_role) { Spree::Role.create(name: "dummyrole") }
134
131
  let(:ability) { Spree::Ability.new(user) }
135
- before do
136
- use_mock_user
137
- allow(mock_user).to receive_messages(:spree_roles= => true, :stock_locations= => true)
138
- allow(controller).to receive(:current_ability) { ability }
139
- Spree::PermissionSets::UserManagement.new(ability).activate!
132
+
133
+ stub_authorization! do |_user|
134
+ can :manage, Spree.user_class
140
135
  end
141
136
 
142
- context "as a superuser" do
143
- before { Spree::PermissionSets::SuperUser.new(ability).activate! }
137
+ context "when the user can manage roles" do
138
+ stub_authorization! do |_user|
139
+ can :manage, Spree.user_class
140
+ can :manage, Spree::Role
141
+ end
144
142
 
145
143
  it "can set roles" do
146
- expect(mock_user).to receive(:spree_roles=).with([dummy_role])
147
- spree_put :update, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
144
+ expect {
145
+ put :update, { id: user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
146
+ }.to change { user.reload.spree_roles.to_a }.to([dummy_role])
148
147
  end
149
148
 
150
149
  it "can clear roles" do
151
- expect(mock_user).to receive(:spree_roles=).with([])
152
- spree_put :update, { id: mock_user.id, user: { first_name: "Bob" } }
150
+ user.spree_roles << dummy_role
151
+ expect {
152
+ put :update, { id: user.id, user: { first_name: "Bob", spree_role_ids: [] } }
153
+ }.to change { user.reload.spree_roles.to_a }.to([])
153
154
  end
155
+ end
154
156
 
155
- it "can change email of a user with no roles" do
156
- expect(mock_user).to receive(:update_attributes).with({ email: "bob@example.com" })
157
- spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
157
+ context "when the user cannot manage roles" do
158
+ it "cannot set roles" do
159
+ expect {
160
+ put :update, { id: user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
161
+ }.not_to change { user.reload.spree_roles.to_a }
158
162
  end
159
163
 
160
- it "can change email of a user with roles" do
161
- allow(mock_user).to receive(:spree_roles) { [dummy_role] }
162
- expect(mock_user).to receive(:update_attributes).with({ email: "bob@example.com" })
163
- spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
164
+ it "cannot clear roles" do
165
+ user.spree_roles << dummy_role
166
+ expect {
167
+ put :update, { id: user.id, user: { first_name: "Bob" } }
168
+ }.not_to change { user.reload.spree_roles.to_a }
164
169
  end
165
170
  end
166
171
 
167
- it "cannot set roles" do
168
- expect(mock_user).to_not receive(:spree_roles=)
169
- spree_put :update, { id: mock_user.id, user: { first_name: "Bob", spree_role_ids: [dummy_role.id] } }
170
- end
172
+ context "allowed to update email" do
173
+ stub_authorization! do |_user|
174
+ can [:admin, :update, :update_email], Spree.user_class
175
+ end
171
176
 
172
- it "cannot clear roles" do
173
- expect(mock_user).to_not receive(:spree_roles=)
174
- spree_put :update, { id: mock_user.id, user: { first_name: "Bob" } }
177
+ it "can change email of a user" do
178
+ expect {
179
+ put :update, { id: user.id, user: { email: "bob@example.com" } }
180
+ }.to change { user.reload.email }.to("bob@example.com")
181
+ end
175
182
  end
176
183
 
177
- it "can change email of a user with no roles" do
178
- expect(mock_user).to receive(:update_attributes).with({ email: "bob@example.com" })
179
- spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
180
- end
184
+ context "not allowed to update email" do
185
+ stub_authorization! do |_user|
186
+ can [:admin, :update], Spree.user_class
187
+ end
181
188
 
182
- it "cannot change email of a user with roles" do
183
- allow(mock_user).to receive(:spree_roles) { [dummy_role] }
184
- expect(mock_user).to receive(:update_attributes).with({})
185
- spree_put :update, { id: mock_user.id, user: { email: "bob@example.com" } }
189
+ it "cannot change email of a user" do
190
+ expect {
191
+ put :update, { id: user.id, user: { email: "bob@example.com" } }
192
+ }.not_to change { user.reload.email }
193
+ end
186
194
  end
187
195
 
188
- it "allows shipping address attributes through" do
189
- expect(mock_user).to receive(:update_attributes).with(hash_including(
190
- "ship_address_attributes" => { "city" => "New York" }
191
- ))
192
- spree_put :update, { id: mock_user.id, user: { ship_address_attributes: { city: "New York" } } }
196
+ it "can update ship_address attributes" do
197
+ post :update, { id: user.id, user: { ship_address_attributes: valid_address_attributes } }
198
+ expect(user.reload.ship_address.city).to eq('New York')
193
199
  end
194
200
 
195
- it "allows billing address attributes through" do
196
- expect(mock_user).to receive(:update_attributes).with(hash_including(
197
- "bill_address_attributes" => { "city" => "New York" }
198
- ))
199
- spree_put :update, { id: mock_user.id, user: { bill_address_attributes: { city: "New York" } } }
201
+ it "can update bill_address attributes" do
202
+ post :update, { id: user.id, user: { bill_address_attributes: valid_address_attributes } }
203
+ expect(user.reload.bill_address.city).to eq('New York')
200
204
  end
201
205
 
202
206
  it "can set stock locations" do
203
207
  location = Spree::StockLocation.create(name: "my_location")
204
208
  location_2 = Spree::StockLocation.create(name: "my_location_2")
205
- expect(mock_user).to receive(:stock_locations=).with([location, location_2])
206
- spree_put :update, { id: mock_user.id, user: { stock_location_ids: [location.id, location_2.id] } }
209
+ post :update, { id: user.id, user: { stock_location_ids: [location.id, location_2.id] } }
210
+ expect(user.stock_locations).to match_array([location, location_2])
207
211
  end
208
212
  end
209
213
 
210
214
  describe "#orders" do
211
- let(:order) { create(:order) }
212
- before do
213
- user.orders << order
214
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
215
+ stub_authorization! do |_user|
216
+ can :manage, Spree.user_class
215
217
  end
216
218
 
219
+ let(:order) { create(:order) }
220
+ before { user.orders << order }
221
+
217
222
  it "assigns a list of the users orders" do
218
- spree_get :orders, { id: user.id }
223
+ get :orders, { id: user.id }
219
224
  expect(assigns[:orders].count).to eq 1
220
225
  expect(assigns[:orders].first).to eq order
221
226
  end
222
227
 
223
228
  it "assigns a ransack search for Spree::Order" do
224
- spree_get :orders, { id: user.id }
229
+ get :orders, { id: user.id }
225
230
  expect(assigns[:search]).to be_a Ransack::Search
226
231
  expect(assigns[:search].klass).to eq Spree::Order
227
232
  end
228
233
  end
229
234
 
230
235
  describe "#items" do
231
- let(:order) { create(:order) }
232
- before do
233
- user.orders << order
234
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
236
+ stub_authorization! do |_user|
237
+ can :manage, Spree.user_class
235
238
  end
236
239
 
240
+ let(:order) { create(:order) }
241
+ before { user.orders << order }
242
+
237
243
  it "assigns a list of the users orders" do
238
- spree_get :items, { id: user.id }
244
+ get :items, { id: user.id }
239
245
  expect(assigns[:orders].count).to eq 1
240
246
  expect(assigns[:orders].first).to eq order
241
247
  end
242
248
 
243
249
  it "assigns a ransack search for Spree::Order" do
244
- spree_get :items, { id: user.id }
250
+ get :items, { id: user.id }
245
251
  expect(assigns[:search]).to be_a Ransack::Search
246
252
  expect(assigns[:search].klass).to eq Spree::Order
247
253
  end
248
254
  end
249
255
  end
250
-
251
- def use_mock_user
252
- allow(mock_user).to receive(:save).and_return(true)
253
- allow(mock_user).to receive(:update_attributes).and_return(true)
254
- allow(mock_user).to receive(:spree_roles).and_return([])
255
- allow(Spree.user_class).to receive(:find).with(mock_user.id.to_s).and_return(mock_user)
256
- allow(Spree.user_class).to receive(:new).and_return(mock_user)
257
- end
@@ -14,7 +14,7 @@ module Spree
14
14
 
15
15
  context "deleted is not requested" do
16
16
  it "does not assign deleted variants for a requested product" do
17
- spree_get :index, product_id: product.slug
17
+ get :index, product_id: product.slug
18
18
  expect(assigns(:collection)).to include variant_1
19
19
  expect(assigns(:collection)).not_to include variant_2
20
20
  end
@@ -22,7 +22,7 @@ module Spree
22
22
 
23
23
  context "deleted is requested" do
24
24
  it "assigns deleted along with non-deleted variants for a requested product" do
25
- spree_get :index, product_id: product.slug, deleted: "on"
25
+ get :index, product_id: product.slug, deleted: "on"
26
26
  expect(assigns(:collection)).to include variant_1
27
27
  expect(assigns(:collection)).to include variant_2
28
28
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "General Settings", type: :feature, js: true do
3
+ describe "Store", type: :feature, js: true do
4
4
  stub_authorization!
5
5
 
6
6
  let!(:store) do
@@ -11,19 +11,21 @@ describe "General Settings", type: :feature, js: true do
11
11
  before(:each) do
12
12
  visit spree.admin_path
13
13
  click_link "Settings"
14
- click_link "General Settings"
14
+ within('.admin-nav') do
15
+ click_link "Store"
16
+ end
15
17
  end
16
18
 
17
- context "visiting general settings" do
19
+ context "visiting general store settings" do
18
20
  it "should have the right content" do
19
- expect(page).to have_content("General Settings")
21
+ expect(page).to have_content("SettingsStore")
20
22
  expect(page).to have_field("store_name", with: "Test Store")
21
23
  expect(page).to have_field("store_url", with: "test.example.org")
22
24
  expect(page).to have_field("store_mail_from_address", with: "test@example.org")
23
25
  end
24
26
  end
25
27
 
26
- context "editing general settings" do
28
+ context "editing general store settings" do
27
29
  it "should be able to update the site name" do
28
30
  fill_in "store_name", with: "Spree Demo Site99"
29
31
  fill_in "store_mail_from_address", with: "spree@example.org"
@@ -44,15 +46,4 @@ describe "General Settings", type: :feature, js: true do
44
46
  expect(page).to have_field("Site Name", with: "")
45
47
  end
46
48
  end
47
-
48
- context "clearing the cache" do
49
- it "should clear the cache" do
50
- expect(page).to_not have_content(Spree.t(:clear_cache_ok))
51
- expect(page).to have_content(Spree.t(:clear_cache_warning))
52
-
53
- click_button "Clear Cache"
54
-
55
- expect(page).to have_content(Spree.t(:clear_cache_ok))
56
- end
57
- end
58
49
  end