spree_backend 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/spree/backend/admin.js +26 -0
  6. data/app/controllers/spree/admin/resource_controller.rb +4 -2
  7. data/app/helpers/spree/admin/navigation_helper.rb +10 -1
  8. data/app/views/spree/admin/images/new.html.erb +1 -1
  9. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  10. data/app/views/spree/admin/products/_form.html.erb +1 -1
  11. data/app/views/spree/admin/shared/_index_table_options.html.erb +1 -11
  12. data/app/views/spree/admin/shared/sub_menu/_product.html.erb +1 -1
  13. data/script/rails +9 -0
  14. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  15. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  16. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  17. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  18. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +42 -0
  19. data/spec/controllers/spree/admin/orders_controller_spec.rb +247 -0
  20. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  21. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  22. data/spec/controllers/spree/admin/products_controller_spec.rb +53 -0
  23. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  24. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  25. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  26. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  27. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  28. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  29. data/spec/controllers/spree/admin/resource_controller_spec.rb +276 -0
  30. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  31. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  32. data/spec/controllers/spree/admin/root_controller_spec.rb +35 -0
  33. data/spec/controllers/spree/admin/search_controller_spec.rb +56 -0
  34. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  35. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  36. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  37. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  38. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  39. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  40. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  41. data/spec/features/admin/configuration/analytics_tracker_spec.rb +46 -0
  42. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  43. data/spec/features/admin/configuration/general_settings_spec.rb +43 -0
  44. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  45. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  46. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  47. data/spec/features/admin/configuration/states_spec.rb +68 -0
  48. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  49. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  50. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  51. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  52. data/spec/features/admin/homepage_spec.rb +81 -0
  53. data/spec/features/admin/locale_spec.rb +31 -0
  54. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  55. data/spec/features/admin/orders/adjustments_spec.rb +129 -0
  56. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  57. data/spec/features/admin/orders/customer_details_spec.rb +182 -0
  58. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  59. data/spec/features/admin/orders/listing_spec.rb +225 -0
  60. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  61. data/spec/features/admin/orders/new_order_spec.rb +161 -0
  62. data/spec/features/admin/orders/order_details_spec.rb +620 -0
  63. data/spec/features/admin/orders/payments_spec.rb +229 -0
  64. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  65. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  66. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  67. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  68. data/spec/features/admin/products/edit/products_spec.rb +64 -0
  69. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  70. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  71. data/spec/features/admin/products/option_types_spec.rb +113 -0
  72. data/spec/features/admin/products/products_spec.rb +394 -0
  73. data/spec/features/admin/products/properties_spec.rb +140 -0
  74. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  75. data/spec/features/admin/products/stock_management_spec.rb +123 -0
  76. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  77. data/spec/features/admin/products/variant_spec.rb +50 -0
  78. data/spec/features/admin/promotions/adjustments_spec.rb +255 -0
  79. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  80. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  81. data/spec/features/admin/reports_spec.rb +61 -0
  82. data/spec/features/admin/stock_transfer_spec.rb +75 -0
  83. data/spec/features/admin/taxons_spec.rb +47 -0
  84. data/spec/features/admin/users_spec.rb +284 -0
  85. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  86. data/spec/helpers/admin/navigation_helper_spec.rb +106 -0
  87. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  88. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  89. data/spec/models/spree/resource_spec.rb +48 -0
  90. data/spec/spec_helper.rb +133 -0
  91. data/spec/support/appear_before_matcher.rb +8 -0
  92. data/spec/support/ror_ringer.jpeg +0 -0
  93. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  94. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  95. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  96. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  97. data/spree_backend.gemspec +29 -0
  98. metadata +101 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cebe3e7299845641b73d9070be94f428951ab670
4
- data.tar.gz: 4e5ec2d0d25cb341c0096b54273f5463ce1fa434
3
+ metadata.gz: 1e89bc11718ae758bfc03f3a40315797c0e08998
4
+ data.tar.gz: 704ba4903c533b4b53fd3c2669394cd70e2b0018
5
5
  SHA512:
6
- metadata.gz: c8d848cf38a22b7ee82476b0fb552035439987a1219e3447850fdfb6d18ac2df147302e1cb6cad98b0d538620e98020136505dbe387ecc055159d74d2a0607b0
7
- data.tar.gz: ccb8dd70ac73d53bef5a00e541581391d85f4fb5c9b0e9c1154e193f24cc7c0000605482e175467b13c1370793a38b02417e9f40766aa358c78b4d03f6cb5045
6
+ metadata.gz: ed6f33fbb8928ca2c9e1bc31a1214fe213f9b4a72b82fe6a08f866d1a7b235f367bf9493ead00b004f0dd8784014cb83d94f48df176177149b61e5d1a0abba93
7
+ data.tar.gz: 1ce4af7c955243d0f8cd983e0887c935b504b0ecc4d8a0efb20893318970ae8ff85508efe3e7602285ec6fe51d1eb960fec6244d54e150554d01af3dc6d0a6e4
@@ -0,0 +1 @@
1
+ ## Spree 2.4.0 (unreleased) ##
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb'))
2
+
3
+ gem 'spree_core', path: '../core'
4
+ gem 'spree_api', path: '../api'
5
+
6
+ gemspec
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/packagetask'
5
+ require 'rubygems/package_task'
6
+ require 'rspec/core/rake_task'
7
+ require 'spree/testing_support/common_rake'
8
+
9
+ Bundler::GemHelper.install_tasks
10
+ RSpec::Core::RakeTask.new
11
+
12
+ spec = eval(File.read('spree_backend.gemspec'))
13
+ Gem::PackageTask.new(spec) do |p|
14
+ p.gem_spec = spec
15
+ end
16
+
17
+ desc "Release to gemcutter"
18
+ task :release do
19
+ version = File.read(File.expand_path("../../SPREE_VERSION", __FILE__)).strip
20
+ cmd = "cd pkg && gem push spree_backend-#{version}.gem"; puts cmd; system cmd
21
+ end
22
+
23
+ task :default => :spec
24
+
25
+ desc "Generates a dummy app for testing"
26
+ task :test_app do
27
+ ENV['LIB_NAME'] = 'spree/backend'
28
+ Rake::Task['common:test_app'].invoke
29
+ end
@@ -149,6 +149,32 @@ jQuery(function($) {
149
149
  }
150
150
  });
151
151
 
152
+ // per page dropdown
153
+ // preserves all selected filters / queries supplied by user
154
+ // changes only per_page value
155
+ $(".js-per-page-select").change(function() {
156
+ var form = $(this).closest(".js-per-page-form");
157
+ var url = form.attr('action');
158
+ var value = $(this).val().toString();
159
+ if (url.match(/\?/)) {
160
+ url += "&per_page=" + value;
161
+ } else {
162
+ url += "?per_page=" + value;
163
+ }
164
+ window.location = url;
165
+ });
166
+
167
+ // injects per_page settings to all available search forms
168
+ // so when user changes some filters / queries per_page is preserved
169
+ $(document).ready(function() {
170
+ var perPageDropdown = $(".js-per-page-select:first");
171
+ if (perPageDropdown.length) {
172
+ var perPageValue = perPageDropdown.val().toString();
173
+ var perPageInput = '<input type="hidden" name="per_page" value=' + perPageValue + ' />';
174
+ $("#table-filter form").append(perPageInput);
175
+ }
176
+ });
177
+
152
178
  // Enable sidebar toggle
153
179
  $("[data-toggle='offcanvas']").click(function(e) {
154
180
  e.preventDefault();
@@ -30,9 +30,11 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
30
30
  invoke_callbacks(:update, :before)
31
31
  if @object.update_attributes(permitted_resource_params)
32
32
  invoke_callbacks(:update, :after)
33
- flash[:success] = flash_message_for(@object, :successfully_updated)
34
33
  respond_with(@object) do |format|
35
- format.html { redirect_to location_after_save }
34
+ format.html do
35
+ flash[:success] = flash_message_for(@object, :successfully_updated)
36
+ redirect_to location_after_save
37
+ end
36
38
  format.js { render layout: false }
37
39
  end
38
40
  else
@@ -87,7 +87,16 @@ module Spree
87
87
 
88
88
  select_tag(:per_page,
89
89
  options_for_select(per_page_options, params['per_page'] || per_page_default),
90
- { id: "js-per-page-select", class: "form-control pull-right" })
90
+ { class: "form-control pull-right js-per-page-select" })
91
+ end
92
+
93
+ # helper method to create proper url to apply per page filtering
94
+ # fixes https://github.com/spree/spree/issues/6888
95
+ def per_page_dropdown_params
96
+ args = params.clone
97
+ args.delete(:page)
98
+ args.delete(:per_page)
99
+ args
91
100
  end
92
101
 
93
102
  # finds class for a given symbol / string
@@ -11,7 +11,7 @@
11
11
  <%= render partial: 'form', locals: { f: f } %>
12
12
 
13
13
  <div class="form-actions" data-hook="buttons">
14
- <%= button Spree.t('actions.update'), 'save' %>
14
+ <%= button Spree.t('actions.create'), 'save' %>
15
15
  <span class="or"><%= Spree.t(:or) %></span>
16
16
  <%= button_link_to Spree.t('actions.cancel'), spree.admin_product_images_url(@product), icon: 'delete', id: 'cancel_link' %>
17
17
  </div>
@@ -28,7 +28,7 @@
28
28
  <% if action == 'credit' %>
29
29
  <%= link_to_with_icon('refund', Spree.t(:refund), new_admin_order_payment_refund_path(@order, payment), no_text: true, class: "btn btn-default btn-sm") if can?(:create, Spree::Refund) %>
30
30
  <% else %>
31
- <%= link_to_with_icon(action, Spree.t(action), fire_admin_order_payment_path(@order, payment, e: action), method: :put, no_text: true, data: { action: action }, class: "btn btn-default btn-sm") if can?(action, payment) %>
31
+ <%= link_to_with_icon(action, Spree.t(action), fire_admin_order_payment_path(@order, payment, e: action), method: :put, no_text: true, data: { action: action }, class: "btn btn-default btn-sm") if can?(action.to_sym, payment) %>
32
32
  <% end %>
33
33
  <% end %>
34
34
  </td>
@@ -92,7 +92,7 @@
92
92
 
93
93
  <div data-hook="admin_product_form_promotionable">
94
94
  <%= f.field_container :promotionable, class: ['form-group'] do %>
95
- <%= f.label :promotionable %>
95
+ <%= f.label :promotionable, Spree.t(:promotionable) %>
96
96
  <%= f.error_message_on :promotionable %>
97
97
  <%= f.check_box :promotionable, class: 'form-control' %>
98
98
  <% end %>
@@ -4,20 +4,10 @@
4
4
  </div>
5
5
  <div class="col-sm-6">
6
6
  <div class="pagination-wrap">
7
- <%= form_tag({ :action => "index"}, { :method => "get", :id => "js-per-page-form", :class => 'form-inline' }) do %>
7
+ <%= form_tag(per_page_dropdown_params, { method: :get, class: 'js-per-page-form form-inline' }) do %>
8
8
  <%= per_page_dropdown %>
9
9
  <% end %>
10
10
  <div class="clearfix"></div>
11
11
  </div>
12
12
  </div>
13
13
  </div>
14
-
15
- <% content_for :head do %>
16
- <%= javascript_tag do %>
17
- $(document).ready(function() {
18
- $("#js-per-page-select").change(function() {
19
- $("#js-per-page-form").submit();
20
- });
21
- });
22
- <% end %>
23
- <% end %>
@@ -1,5 +1,5 @@
1
1
  <ul id="sidebar-product" class="collapse nav nav-pills nav-stacked" data-hook="admin_product_sub_tabs">
2
- <%= tab *Spree::BackendConfiguration::PRODUCT_TABS %>
2
+ <%= tab :products %>
3
3
  <%= tab :option_types, :match_path => '/option_types' %>
4
4
  <%= tab :properties %>
5
5
  <%= tab :prototypes %>
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/spree/backend/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
9
+
@@ -0,0 +1,46 @@
1
+ # Spree's rpsec controller tests get the Spree::ControllerHacks
2
+ # we don't need those for the anonymous controller here, so
3
+ # we call process directly instead of get
4
+ require 'spec_helper'
5
+
6
+ describe Spree::Admin::BaseController, type: :controller do
7
+ controller(Spree::Admin::BaseController) do
8
+ def index
9
+ authorize! :update, Spree::Order
10
+ render text: 'test'
11
+ end
12
+ end
13
+
14
+ context "unauthorized request" do
15
+ before do
16
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(nil)
17
+ end
18
+
19
+ it "redirects to root" do
20
+ allow(controller).to receive_message_chain(:spree, :root_path).and_return('/root')
21
+ get :index
22
+ expect(response).to redirect_to '/root'
23
+ end
24
+ end
25
+
26
+ context "#generate_api_key" do
27
+ let(:user) { mock_model(Spree.user_class, has_spree_role?: true) }
28
+
29
+ before do
30
+ allow(controller).to receive(:authorize_admin) { true }
31
+ allow(controller).to receive(:try_spree_current_user) { user }
32
+ end
33
+
34
+ it "generates the API key for a user when they visit" do
35
+ expect(user).to receive(:spree_api_key).and_return(nil)
36
+ expect(user).to receive(:generate_spree_api_key!)
37
+ get :index
38
+ end
39
+
40
+ it "does not attempt to regenerate the API key if the key is already set" do
41
+ expect(user).to receive(:spree_api_key).and_return('fake')
42
+ expect(user).not_to receive(:generate_spree_api_key!)
43
+ get :index
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe CustomerReturnsController, :type => :controller do
6
+ stub_authorization!
7
+
8
+ describe "#index" do
9
+ let(:order) { customer_return.order }
10
+ let(:customer_return) { create(:customer_return) }
11
+
12
+ subject do
13
+ spree_get :index, { order_id: customer_return.order.to_param }
14
+ end
15
+
16
+ before { subject }
17
+
18
+ it "loads the order" do
19
+ expect(assigns(:order)).to eq order
20
+ end
21
+
22
+ it "loads the customer return" do
23
+ expect(assigns(:customer_returns)).to include(customer_return)
24
+ end
25
+ end
26
+
27
+ describe "#new" do
28
+ let(:order) { create(:shipped_order, line_items_count: 1) }
29
+ let!(:rma) { create :return_authorization, order: order, return_items: [create(:return_item, inventory_unit: order.inventory_units.first)] }
30
+ let!(:inactive_reimbursement_type) { create(:reimbursement_type, active: false) }
31
+ let!(:first_active_reimbursement_type) { create(:reimbursement_type) }
32
+ let!(:second_active_reimbursement_type) { create(:reimbursement_type) }
33
+
34
+ subject do
35
+ spree_get :new, { order_id: order.to_param }
36
+ end
37
+
38
+ it "loads the order" do
39
+ subject
40
+ expect(assigns(:order)).to eq order
41
+ end
42
+
43
+ it "creates a new customer return" do
44
+ subject
45
+ expect(assigns(:customer_return)).to_not be_persisted
46
+ end
47
+
48
+ context "with previous customer return" do
49
+ let(:order) { create(:shipped_order, line_items_count: 4) }
50
+ let(:rma) { create(:return_authorization, order: order) }
51
+
52
+ let!(:rma_return_item) { create(:return_item, return_authorization: rma, inventory_unit: order.inventory_units.first) }
53
+ let!(:customer_return_return_item) { create(:return_item, return_authorization: rma, inventory_unit: order.inventory_units.last) }
54
+
55
+ context "there is a return item associated with an rma but not a customer return" do
56
+ let!(:previous_customer_return) { create(:customer_return_without_return_items, return_items: [customer_return_return_item]) }
57
+
58
+ before do
59
+ subject
60
+ end
61
+
62
+ it "loads the persisted rma return items" do
63
+ expect(assigns(:rma_return_items).all? { |return_item| return_item.persisted? }).to eq true
64
+ end
65
+
66
+ it "has one rma return item" do
67
+ expect(assigns(:rma_return_items)).to include(rma_return_item)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#edit" do
74
+ let(:order) { customer_return.order }
75
+ let(:customer_return) { create(:customer_return, line_items_count: 3) }
76
+
77
+ let!(:accepted_return_item) { customer_return.return_items.order('id').first.tap(&:accept!) }
78
+ let!(:rejected_return_item) { customer_return.return_items.order('id').second.tap(&:reject!)}
79
+ let!(:manual_intervention_return_item) { customer_return.return_items.order('id').third.tap(&:require_manual_intervention!) }
80
+
81
+ subject do
82
+ spree_get :edit, { order_id: order.to_param, id: customer_return.to_param }
83
+ end
84
+
85
+ before do
86
+ subject
87
+ end
88
+
89
+ it "loads the order" do
90
+ expect(assigns(:order)).to eq order
91
+ end
92
+
93
+ it "loads the customer return" do
94
+ expect(assigns(:customer_return)).to eq customer_return
95
+ end
96
+
97
+ it "loads the accepted return items" do
98
+ expect(assigns(:accepted_return_items)).to eq [accepted_return_item]
99
+ end
100
+
101
+ it "loads the rejected return items" do
102
+ expect(assigns(:rejected_return_items)).to eq [rejected_return_item]
103
+ end
104
+
105
+ it "loads the return items that require manual intervention" do
106
+ expect(assigns(:manual_intervention_return_items)).to eq [manual_intervention_return_item]
107
+ end
108
+
109
+ it "loads the return items that are still pending" do
110
+ expect(assigns(:pending_return_items)).to eq []
111
+ end
112
+
113
+ it "loads the reimbursements that are still pending" do
114
+ expect(assigns(:pending_reimbursements)).to eq []
115
+ end
116
+ end
117
+
118
+ describe "#create" do
119
+ let(:order) { create(:shipped_order, line_items_count: 1) }
120
+ let!(:return_authorization) { create :return_authorization, order: order, return_items: [create(:return_item, inventory_unit: order.inventory_units.shipped.last)] }
121
+
122
+ subject do
123
+ spree_post :create, customer_return_params
124
+ end
125
+
126
+ context "valid customer return" do
127
+ let(:stock_location) { order.shipments.last.stock_location }
128
+
129
+ let!(:customer_return_params) do
130
+ {
131
+ order_id: order.to_param,
132
+ customer_return: {
133
+ stock_location_id: stock_location.id,
134
+ return_items_attributes: {
135
+ "0" => {
136
+ id: return_authorization.return_items.first.id,
137
+ returned: "1",
138
+ "pre_tax_amount"=>"15.99",
139
+ inventory_unit_id: order.inventory_units.shipped.last.id
140
+ }
141
+ }
142
+ }
143
+ }
144
+ end
145
+
146
+ it "creates a customer return" do
147
+ expect{ subject }.to change { Spree::CustomerReturn.count }.by(1)
148
+ end
149
+
150
+ it "redirects to the index page" do
151
+ subject
152
+ expect(response).to redirect_to(spree.edit_admin_order_customer_return_path(order, assigns(:customer_return)))
153
+ end
154
+ end
155
+
156
+ context "invalid customer return" do
157
+ let!(:customer_return_params) do
158
+ {
159
+ order_id: order.to_param,
160
+ customer_return: {
161
+ stock_location_id: "",
162
+ return_items_attributes: {
163
+ "0" => {
164
+ returned: "1",
165
+ "pre_tax_amount"=>"15.99",
166
+ inventory_unit_id: order.inventory_units.shipped.last.id
167
+ }
168
+ }
169
+ }
170
+ }
171
+ end
172
+
173
+ it "doesn't create a customer return" do
174
+ expect{ subject }.to_not change { Spree::CustomerReturn.count }
175
+ end
176
+
177
+ it "renders the new page" do
178
+ subject
179
+ expect(response).to render_template(:new)
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::GeneralSettingsController, type: :controller do
4
+ let(:user) { create(:user) }
5
+
6
+ before do
7
+ allow(controller).to receive_messages :spree_current_user => user
8
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
9
+ end
10
+
11
+ describe '#clear_cache' do
12
+ subject { spree_post :clear_cache }
13
+
14
+ shared_examples 'a HTTP 204 response' do
15
+ it 'grant access to users with an admin role' do
16
+ subject
17
+ expect(response.status).to eq(204)
18
+ end
19
+ end
20
+
21
+ context 'when no callback' do
22
+ it_behaves_like 'a HTTP 204 response'
23
+ end
24
+
25
+ context 'when callback implemented' do
26
+ Spree::Admin::GeneralSettingsController.class_eval do
27
+ custom_callback(:clear_cache).after :foo
28
+
29
+ def foo
30
+ # Make a call to Akamai, CloudFlare, etc invalidation....
31
+ end
32
+ end
33
+
34
+ before do
35
+ expect(controller).to receive(:foo).once
36
+ end
37
+
38
+ it_behaves_like 'a HTTP 204 response'
39
+ end
40
+ end
41
+ end