solidus_backend 1.1.0 → 1.1.1

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/Rakefile +15 -0
  4. data/script/rails +9 -0
  5. data/solidus_backend.gemspec +30 -0
  6. data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
  7. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
  8. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
  9. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  10. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  11. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
  12. data/spec/controllers/spree/admin/orders_controller_spec.rb +460 -0
  13. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  14. data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
  15. data/spec/controllers/spree/admin/product_properties_controller_spec.rb +69 -0
  16. data/spec/controllers/spree/admin/products_controller_spec.rb +162 -0
  17. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  18. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +18 -0
  19. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  20. data/spec/controllers/spree/admin/promotions_controller_spec.rb +122 -0
  21. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  22. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +124 -0
  23. data/spec/controllers/spree/admin/reports_controller_spec.rb +134 -0
  24. data/spec/controllers/spree/admin/resource_controller_spec.rb +166 -0
  25. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +240 -0
  26. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  27. data/spec/controllers/spree/admin/root_controller_spec.rb +41 -0
  28. data/spec/controllers/spree/admin/search_controller_spec.rb +104 -0
  29. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  30. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +50 -0
  31. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  32. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +351 -0
  33. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
  34. data/spec/controllers/spree/admin/users_controller_spec.rb +257 -0
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  36. data/spec/features/admin/configuration/analytics_tracker_spec.rb +50 -0
  37. data/spec/features/admin/configuration/countries_spec.rb +22 -0
  38. data/spec/features/admin/configuration/general_settings_spec.rb +45 -0
  39. data/spec/features/admin/configuration/payment_methods_spec.rb +124 -0
  40. data/spec/features/admin/configuration/shipping_methods_spec.rb +64 -0
  41. data/spec/features/admin/configuration/states_spec.rb +64 -0
  42. data/spec/features/admin/configuration/stock_locations_spec.rb +50 -0
  43. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  44. data/spec/features/admin/configuration/tax_rates_spec.rb +30 -0
  45. data/spec/features/admin/configuration/taxonomies_spec.rb +52 -0
  46. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  47. data/spec/features/admin/homepage_spec.rb +78 -0
  48. data/spec/features/admin/locale_spec.rb +30 -0
  49. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  50. data/spec/features/admin/orders/adjustments_spec.rb +126 -0
  51. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +48 -0
  52. data/spec/features/admin/orders/cancelling_inventory_spec.rb +48 -0
  53. data/spec/features/admin/orders/customer_details_spec.rb +163 -0
  54. data/spec/features/admin/orders/line_items_spec.rb +50 -0
  55. data/spec/features/admin/orders/listing_spec.rb +130 -0
  56. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  57. data/spec/features/admin/orders/new_order_spec.rb +185 -0
  58. data/spec/features/admin/orders/order_details_spec.rb +533 -0
  59. data/spec/features/admin/orders/payments_spec.rb +234 -0
  60. data/spec/features/admin/orders/risk_analysis_spec.rb +47 -0
  61. data/spec/features/admin/orders/shipments_spec.rb +65 -0
  62. data/spec/features/admin/payments/store_credits_spec.rb +21 -0
  63. data/spec/features/admin/products/edit/images_spec.rb +87 -0
  64. data/spec/features/admin/products/edit/products_spec.rb +66 -0
  65. data/spec/features/admin/products/edit/taxons_spec.rb +43 -0
  66. data/spec/features/admin/products/edit/variants_spec.rb +61 -0
  67. data/spec/features/admin/products/option_types_spec.rb +114 -0
  68. data/spec/features/admin/products/products_spec.rb +395 -0
  69. data/spec/features/admin/products/properties_spec.rb +139 -0
  70. data/spec/features/admin/products/prototypes_spec.rb +110 -0
  71. data/spec/features/admin/products/stock_management_spec.rb +82 -0
  72. data/spec/features/admin/products/variant_spec.rb +51 -0
  73. data/spec/features/admin/promotion_adjustments_spec.rb +220 -0
  74. data/spec/features/admin/promotions/option_value_rule_spec.rb +65 -0
  75. data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
  76. data/spec/features/admin/reports_spec.rb +61 -0
  77. data/spec/features/admin/stock_transfer_spec.rb +104 -0
  78. data/spec/features/admin/store_credits_spec.rb +82 -0
  79. data/spec/features/admin/taxons_spec.rb +31 -0
  80. data/spec/features/admin/users_spec.rb +275 -0
  81. data/spec/helpers/admin/base_helper_spec.rb +18 -0
  82. data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
  83. data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
  84. data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
  85. data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
  86. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  87. data/spec/spec_helper.rb +116 -0
  88. data/spec/support/appear_before_matcher.rb +8 -0
  89. data/spec/support/ror_ringer.jpeg +0 -0
  90. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  91. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  92. metadata +96 -6
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Stock Transfers', :type => :feature, :js => true do
4
+ stub_authorization!
5
+
6
+ let(:admin_user) { create(:admin_user) }
7
+ let(:description) { 'Test stock transfer' }
8
+
9
+ before do
10
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:spree_current_user).and_return(admin_user)
11
+ end
12
+
13
+ describe 'create stock transfer' do
14
+ it 'can create a stock transfer' do
15
+ source_location = create(:stock_location_with_items, :name => 'NY')
16
+ destination_location = create(:stock_location, :name => 'SF')
17
+
18
+ visit spree.new_admin_stock_transfer_path
19
+ select "SF", from: 'stock_transfer[source_location_id]'
20
+ fill_in 'stock_transfer_description', with: description
21
+ click_button 'Continue'
22
+
23
+ expect(page.find('#stock_transfer_description').value).to eq description
24
+
25
+ select "NY", from: 'stock_transfer[destination_location_id]'
26
+ within "form.edit_stock_transfer" do
27
+ page.find('button').trigger('click')
28
+ end
29
+
30
+ expect(page).to have_content('Stock Transfer has been successfully updated')
31
+ expect(page).to have_css(:div, '#finalize-stock-transfer-warning')
32
+ expect(page).to have_content("NY")
33
+ end
34
+ end
35
+
36
+ describe 'view a stock transfer' do
37
+ let(:stock_transfer) do
38
+ create(:stock_transfer_with_items,
39
+ source_location: source_location,
40
+ destination_location: nil,
41
+ description: "Test stock transfer")
42
+ end
43
+ let(:source_location) { create(:stock_location, name: 'SF') }
44
+
45
+ context "stock transfer does not have a destination" do
46
+ it 'displays the stock transfer details' do
47
+ visit spree.admin_stock_transfer_path(stock_transfer)
48
+ expect(page).to have_content("SF")
49
+ expect(page).to have_content("Test stock transfer")
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'ship stock transfer' do
55
+ let(:stock_transfer) { create(:stock_transfer_with_items) }
56
+
57
+ before do
58
+ stock_transfer.transfer_items do |item|
59
+ item.update_attributes(expected_quantity: 1)
60
+ end
61
+ end
62
+
63
+ describe "tracking info" do
64
+ it 'adds tracking number' do
65
+ visit spree.tracking_info_admin_stock_transfer_path(stock_transfer)
66
+
67
+ fill_in 'stock_transfer_tracking_number', :with => "12345"
68
+ click_button 'Save'
69
+
70
+ expect(page).to have_content('Stock Transfer has been successfully updated')
71
+ expect(stock_transfer.reload.tracking_number).to eq '12345'
72
+ end
73
+ end
74
+
75
+ describe 'with enough stock' do
76
+ it 'ships stock transfer' do
77
+ visit spree.tracking_info_admin_stock_transfer_path(stock_transfer)
78
+ click_link 'ship'
79
+
80
+ first('#confirm-ship-link', visible: false).click
81
+ expect(current_path).to eq spree.admin_stock_transfers_path
82
+ expect(stock_transfer.reload.shipped_at).to_not be_nil
83
+ end
84
+ end
85
+
86
+ describe 'without enough stock' do
87
+ before do
88
+ stock_transfer.transfer_items.each do |item|
89
+ stock_transfer.source_location.stock_item(item.variant).set_count_on_hand(0)
90
+ end
91
+ end
92
+
93
+ it 'does not ship stock transfer' do
94
+ visit spree.tracking_info_admin_stock_transfer_path(stock_transfer)
95
+
96
+ click_link 'ship'
97
+
98
+ first('#confirm-ship-link', visible: false).click
99
+ expect(current_path).to eq spree.tracking_info_admin_stock_transfer_path(stock_transfer)
100
+ expect(stock_transfer.reload.shipped_at).to be_nil
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Store credits admin" do
4
+ stub_authorization!
5
+ let!(:admin_user) { create(:admin_user) }
6
+ let!(:store_credit) { create(:store_credit) }
7
+ let(:user) { store_credit.user }
8
+
9
+ before do
10
+ allow(Spree.user_class).to receive(:find_by).
11
+ with(hash_including(:id)).
12
+ and_return(store_credit.user)
13
+ end
14
+
15
+ describe "visiting the store credits page" do
16
+ before do
17
+ visit spree.admin_path
18
+ click_link "Users"
19
+ end
20
+
21
+ it "should be on the store credits page" do
22
+ click_link store_credit.user.email
23
+ click_link "Store Credit"
24
+ expect(page.current_path).to eq spree.admin_user_store_credits_path(store_credit.user)
25
+
26
+ store_credit_table = page.find(".twelve.columns > table")
27
+ expect(store_credit_table.all('tr').count).to eq 1
28
+ expect(store_credit_table).to have_content(Spree::Money.new(store_credit.amount).to_s)
29
+ expect(store_credit_table).to have_content(Spree::Money.new(store_credit.amount_used).to_s)
30
+ expect(store_credit_table).to have_content(store_credit.category_name)
31
+ expect(store_credit_table).to have_content(store_credit.created_by_email)
32
+ end
33
+ end
34
+
35
+ describe "creating store credit" do
36
+ before do
37
+ visit spree.admin_path
38
+ click_link "Users"
39
+ click_link store_credit.user.email
40
+ click_link "Store Credit"
41
+ allow_any_instance_of(Spree::Admin::StoreCreditsController).to receive_messages(try_spree_current_user: admin_user)
42
+ end
43
+
44
+ it "should create store credit and associate it with the user" do
45
+ click_link "Add store credit"
46
+ page.fill_in "store_credit_amount", with: "102.00"
47
+ select "Exchange", from: "store_credit_category_id"
48
+ click_button "Create"
49
+
50
+ expect(page.current_path).to eq spree.admin_user_store_credits_path(store_credit.user)
51
+ store_credit_table = page.find(".twelve.columns > table")
52
+ expect(store_credit_table.all('tr').count).to eq 2
53
+ expect(Spree::StoreCredit.count).to eq 2
54
+ end
55
+ end
56
+
57
+ describe "updating store credit" do
58
+ let(:updated_amount) { "99.0" }
59
+ let!(:update_reason) { create(:store_credit_update_reason) }
60
+
61
+ before do
62
+ visit spree.admin_path
63
+ click_link "Users"
64
+ click_link store_credit.user.email
65
+ click_link "Store Credit"
66
+ allow_any_instance_of(Spree::Admin::StoreCreditsController).to receive_messages(try_spree_current_user: admin_user)
67
+ end
68
+
69
+ it "updates the store credit's amount" do
70
+ page.find(".twelve.columns > table td.actions a.fa-edit").click
71
+ expect(page).to have_content 'Store credit history'
72
+ click_link "Change amount"
73
+ expect(page).to have_content 'Editing store credit amount'
74
+ page.fill_in 'store_credit_amount', with: updated_amount
75
+ page.select update_reason.name, from: 'update_reason_id'
76
+ click_button "Update"
77
+ expect(page.find('#sc-detail-table')).to have_content "$99.00"
78
+ expect(store_credit.reload.amount.to_f).to eq updated_amount.to_f
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Taxonomies and taxons", :type => :feature do
4
+ stub_authorization!
5
+
6
+ it "admin should be able to edit taxon" do
7
+
8
+ visit spree.new_admin_taxonomy_path
9
+
10
+ fill_in "Name", :with => "Hello"
11
+ click_button "Create"
12
+
13
+ @taxonomy = Spree::Taxonomy.last
14
+
15
+ visit spree.edit_admin_taxonomy_taxon_path(@taxonomy, @taxonomy.root.id)
16
+
17
+ fill_in "taxon_name", :with => "Shirt"
18
+ fill_in "taxon_description", :with => "Discover our new rails shirts"
19
+
20
+ fill_in "permalink_part", :with => "shirt-rails"
21
+ click_button "Update"
22
+ expect(page).to have_content("Taxon \"Shirt\" has been successfully updated!")
23
+ end
24
+
25
+ it "can see taxon tree", js: true do
26
+ taxonomy = create :taxonomy
27
+
28
+ visit spree.edit_admin_taxonomy_path(taxonomy)
29
+ expect(page).to have_content('Brand')
30
+ end
31
+ end
@@ -0,0 +1,275 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Users', :type => :feature do
4
+ stub_authorization!
5
+ let!(:country) { create(:country) }
6
+ let!(:user_a) { create(:user_with_addreses, email: 'a@example.com') }
7
+ let!(:user_b) { create(:user_with_addreses, email: 'b@example.com') }
8
+
9
+ let(:order) { create(:completed_order_with_totals, user: user_a, number: "R123") }
10
+
11
+ let(:order_2) do
12
+ create(:completed_order_with_totals, user: user_a, number: "R456").tap do |o|
13
+ li = o.line_items.last
14
+ li.update_column(:price, li.price + 10)
15
+ end
16
+ end
17
+
18
+ let(:orders) { [order, order_2] }
19
+
20
+ shared_examples_for 'a user page' do
21
+ it 'has lifetime stats' do
22
+ orders
23
+ visit current_url # need to refresh after creating the orders for specs that did not require orders
24
+ within("#user-lifetime-stats") do
25
+ [:total_sales, :num_orders, :average_order_value, :member_since].each do |stat_name|
26
+ expect(page).to have_content Spree.t(stat_name)
27
+ end
28
+ expect(page).to have_content (order.total + order_2.total)
29
+ expect(page).to have_content orders.count
30
+ expect(page).to have_content (orders.sum(&:total) / orders.count)
31
+ expect(page).to have_content I18n.l(user_a.created_at.to_date)
32
+ end
33
+ end
34
+
35
+ it 'can go back to the users list' do
36
+ expect(page).to have_link Spree.t(:back_to_users_list), href: spree.admin_users_path
37
+ end
38
+
39
+ it 'can navigate to the account page' do
40
+ expect(page).to have_link Spree.t(:"admin.user.account"), href: spree.edit_admin_user_path(user_a)
41
+ end
42
+
43
+ it 'can navigate to the order history' do
44
+ expect(page).to have_link Spree.t(:"admin.user.orders"), href: spree.orders_admin_user_path(user_a)
45
+ end
46
+
47
+ it 'can navigate to the items purchased' do
48
+ expect(page).to have_link Spree.t(:"admin.user.items"), href: spree.items_admin_user_path(user_a)
49
+ end
50
+ end
51
+
52
+ shared_examples_for 'a sortable attribute' do
53
+ before { click_link sort_link }
54
+
55
+ it "can sort asc" do
56
+ within_table(table_id) do
57
+ expect(page).to have_text text_match_1
58
+ expect(page).to have_text text_match_2
59
+ expect(text_match_1).to appear_before text_match_2
60
+ end
61
+ end
62
+
63
+ it "can sort desc" do
64
+ within_table(table_id) do
65
+ click_link sort_link
66
+
67
+ expect(page).to have_text text_match_1
68
+ expect(page).to have_text text_match_2
69
+ expect(text_match_2).to appear_before text_match_1
70
+ end
71
+ end
72
+ end
73
+
74
+ before do
75
+ visit spree.admin_path
76
+ click_link 'Users'
77
+ end
78
+
79
+ context 'users index' do
80
+
81
+ context "email" do
82
+ it_behaves_like "a sortable attribute" do
83
+ let(:text_match_1) { user_a.email }
84
+ let(:text_match_2) { user_b.email }
85
+ let(:table_id) { "listing_users" }
86
+ let(:sort_link) { "users_email_title" }
87
+ end
88
+ end
89
+
90
+ it 'displays the correct results for a user search' do
91
+ fill_in 'q_email_cont', with: user_a.email
92
+ click_button 'Search'
93
+ within_table('listing_users') do
94
+ expect(page).to have_text user_a.email
95
+ expect(page).not_to have_text user_b.email
96
+ end
97
+ end
98
+ end
99
+
100
+ context 'editing users' do
101
+ before { click_link user_a.email }
102
+
103
+ it_behaves_like 'a user page'
104
+
105
+ it 'can edit the user email' do
106
+ fill_in 'user_email', with: 'a@example.com99'
107
+ click_button 'Update'
108
+
109
+ expect(user_a.reload.email).to eq 'a@example.com99'
110
+ expect(page).to have_text 'Account updated'
111
+ expect(find_field('user_email').value).to eq 'a@example.com99'
112
+ end
113
+
114
+ it 'can edit the user password' do
115
+ fill_in 'user_password', with: 'welcome'
116
+ fill_in 'user_password_confirmation', with: 'welcome'
117
+ click_button 'Update'
118
+
119
+ expect(page).to have_text 'Account updated'
120
+ end
121
+
122
+ it 'can edit user roles' do
123
+ Spree::Role.create name: "admin"
124
+ click_link user_a.email
125
+
126
+ check 'user_spree_role_admin'
127
+ click_button 'Update'
128
+ expect(page).to have_text 'Account updated'
129
+ expect(find_field('user_spree_role_admin')['checked']).to be true
130
+ end
131
+
132
+ it 'can edit user shipping address' do
133
+ click_link "Addresses"
134
+
135
+ within("#admin_user_edit_addresses") do
136
+ fill_in "user_ship_address_attributes_address1", with: "1313 Mockingbird Ln"
137
+ click_button 'Update'
138
+ expect(find_field('user_ship_address_attributes_address1').value).to eq "1313 Mockingbird Ln"
139
+ end
140
+
141
+ expect(user_a.reload.ship_address.address1).to eq "1313 Mockingbird Ln"
142
+ end
143
+
144
+ it 'can edit user billing address' do
145
+ click_link "Addresses"
146
+
147
+ within("#admin_user_edit_addresses") do
148
+ fill_in "user_bill_address_attributes_address1", with: "1313 Mockingbird Ln"
149
+ click_button 'Update'
150
+ expect(find_field('user_bill_address_attributes_address1').value).to eq "1313 Mockingbird Ln"
151
+ end
152
+
153
+ expect(user_a.reload.bill_address.address1).to eq "1313 Mockingbird Ln"
154
+ end
155
+
156
+ context 'no api key exists' do
157
+ it 'can generate a new api key' do
158
+ within("#admin_user_edit_api_key") do
159
+ expect(user_a.spree_api_key).to be_blank
160
+ click_button Spree.t('generate_key', :scope => 'api')
161
+ end
162
+
163
+ expect(user_a.reload.spree_api_key).to be_present
164
+
165
+ expect(page).to have_content('Key: (hidden)')
166
+ end
167
+ end
168
+
169
+ context 'an api key exists' do
170
+ before do
171
+ user_a.generate_spree_api_key!
172
+ expect(user_a.reload.spree_api_key).to be_present
173
+ visit current_path
174
+ end
175
+
176
+ it 'can clear an api key' do
177
+ expect(page).to have_css('#current-api-key')
178
+
179
+ click_button Spree.t('clear_key', :scope => 'api')
180
+
181
+ expect(page).to have_no_css('#current-api-key')
182
+
183
+ expect(user_a.reload.spree_api_key).to be_blank
184
+ end
185
+
186
+ it 'can regenerate an api key' do
187
+ old_key = user_a.spree_api_key
188
+
189
+ within("#admin_user_edit_api_key") do
190
+ click_button Spree.t('regenerate_key', :scope => 'api')
191
+ end
192
+
193
+ expect(user_a.reload.spree_api_key).to be_present
194
+ expect(user_a.reload.spree_api_key).not_to eq old_key
195
+
196
+ expect(page).to have_content('Key: (hidden)')
197
+ end
198
+ end
199
+ end
200
+
201
+ context 'order history with sorting' do
202
+
203
+ before do
204
+ orders
205
+ click_link user_a.email
206
+ within("#sidebar") { click_link Spree.t(:"admin.user.orders") }
207
+ end
208
+
209
+ it_behaves_like 'a user page'
210
+
211
+ context "completed_at" do
212
+ it_behaves_like "a sortable attribute" do
213
+ let(:text_match_1) { I18n.l(order.completed_at.to_date) }
214
+ let(:text_match_2) { I18n.l(order_2.completed_at.to_date) }
215
+ let(:table_id) { "listing_orders" }
216
+ let(:sort_link) { "orders_completed_at_title" }
217
+ end
218
+ end
219
+
220
+ [:number, :state, :total].each do |attr|
221
+ context attr do
222
+ it_behaves_like "a sortable attribute" do
223
+ let(:text_match_1) { order.send(attr).to_s }
224
+ let(:text_match_2) { order_2.send(attr).to_s }
225
+ let(:table_id) { "listing_orders" }
226
+ let(:sort_link) { "orders_#{attr}_title" }
227
+ end
228
+ end
229
+ end
230
+ end
231
+
232
+ context 'items purchased with sorting' do
233
+
234
+ before do
235
+ orders
236
+ click_link user_a.email
237
+ within("#sidebar") { click_link Spree.t(:"admin.user.items") }
238
+ end
239
+
240
+ it_behaves_like 'a user page'
241
+
242
+ context "completed_at" do
243
+ it_behaves_like "a sortable attribute" do
244
+ let(:text_match_1) { I18n.l(order.completed_at.to_date) }
245
+ let(:text_match_2) { I18n.l(order_2.completed_at.to_date) }
246
+ let(:table_id) { "listing_items" }
247
+ let(:sort_link) { "orders_completed_at_title" }
248
+ end
249
+ end
250
+
251
+ [:number, :state].each do |attr|
252
+ context attr do
253
+ it_behaves_like "a sortable attribute" do
254
+ let(:text_match_1) { order.send(attr).to_s }
255
+ let(:text_match_2) { order_2.send(attr).to_s }
256
+ let(:table_id) { "listing_items" }
257
+ let(:sort_link) { "orders_#{attr}_title" }
258
+ end
259
+ end
260
+ end
261
+
262
+ it "has item attributes" do
263
+ items = order.line_items | order_2.line_items
264
+ expect(page).to have_table 'listing_items'
265
+ within_table('listing_items') do
266
+ items.each do |item|
267
+ expect(page).to have_selector(".item-name", text: item.product.name)
268
+ expect(page).to have_selector(".item-price", text: item.single_money.to_html)
269
+ expect(page).to have_selector(".item-quantity", text: item.quantity)
270
+ expect(page).to have_selector(".item-total", text: item.money.to_html)
271
+ end
272
+ end
273
+ end
274
+ end
275
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::BaseHelper, :type => :helper do
4
+ include Spree::Admin::BaseHelper
5
+
6
+ context "#datepicker_field_value" do
7
+ it "should return nil when date is empty" do
8
+ date = nil
9
+ expect(datepicker_field_value(date)).to be_nil
10
+ end
11
+
12
+ it "should return a formatted date when date is present" do
13
+ date = "2013-08-14".to_time
14
+ expect(datepicker_field_value(date)).to eq("2013/08/14")
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,73 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Spree::Admin::NavigationHelper, :type => :helper do
5
+
6
+ describe "#tab" do
7
+ context "creating an admin tab" do
8
+ it "should capitalize the first letter of each word in the tab's label" do
9
+ admin_tab = helper.tab(:orders)
10
+ expect(admin_tab).to include("Orders")
11
+ end
12
+ end
13
+
14
+ it "should accept options with label and capitalize each word of it" do
15
+ admin_tab = helper.tab(:orders, :label => "delivered orders")
16
+ expect(admin_tab).to include("Delivered Orders")
17
+ end
18
+
19
+ it "should capitalize words with unicode characters" do
20
+ # overview
21
+ admin_tab = helper.tab(:orders, :label => "přehled")
22
+ expect(admin_tab).to include("Přehled")
23
+ end
24
+
25
+ describe "selection" do
26
+ context "when match_path option is not supplied" do
27
+ subject(:tab) { helper.tab(:orders) }
28
+
29
+ it "should be selected if the controller matches" do
30
+ allow(controller).to receive(:controller_name).and_return("orders")
31
+ expect(subject).to include('class="selected"')
32
+ end
33
+
34
+ it "should not be selected if the controller does not match" do
35
+ allow(controller).to receive(:controller_name).and_return("bonobos")
36
+ expect(subject).not_to include('class="selected"')
37
+ end
38
+
39
+ end
40
+
41
+ context "when match_path option is supplied" do
42
+ before do
43
+ allow(helper).to receive(:admin_path).and_return("/somepath")
44
+ allow(helper).to receive(:request).and_return(double(ActionDispatch::Request, :fullpath => "/somepath/orders/edit/1"))
45
+ end
46
+
47
+ it "should be selected if the fullpath matches" do
48
+ allow(controller).to receive(:controller_name).and_return("bonobos")
49
+ tab = helper.tab(:orders, :label => "delivered orders", :match_path => '/orders')
50
+ expect(tab).to include('class="selected"')
51
+ end
52
+
53
+ it "should be selected if the fullpath matches a regular expression" do
54
+ allow(controller).to receive(:controller_name).and_return("bonobos")
55
+ tab = helper.tab(:orders, :label => "delivered orders", :match_path => /orders$|orders\//)
56
+ expect(tab).to include('class="selected"')
57
+ end
58
+
59
+ it "should not be selected if the fullpath does not match" do
60
+ allow(controller).to receive(:controller_name).and_return("bonobos")
61
+ tab = helper.tab(:orders, :label => "delivered orders", :match_path => '/shady')
62
+ expect(tab).not_to include('class="selected"')
63
+ end
64
+
65
+ it "should not be selected if the fullpath does not match a regular expression" do
66
+ allow(controller).to receive(:controller_name).and_return("bonobos")
67
+ tab = helper.tab(:orders, :label => "delivered orders", :match_path => /shady$|shady\//)
68
+ expect(tab).not_to include('class="selected"')
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::ReimbursementsHelper, type: :helper do
4
+ describe '.reimbursement_status_color' do
5
+ subject { helper.reimbursement_status_color(reimbursement) }
6
+
7
+ let(:reimbursement) do
8
+ Spree::Reimbursement.new(reimbursement_status: status)
9
+ end
10
+
11
+ context 'when status is reimbursed' do
12
+ let(:status) { 'reimbursed' }
13
+ it { is_expected.to eq 'success'}
14
+ end
15
+
16
+ context 'when status is pending' do
17
+ let(:status) { 'pending' }
18
+ it { is_expected.to eq 'notice'}
19
+ end
20
+
21
+ context 'when status is pending' do
22
+ let(:status) { 'errored' }
23
+ it { is_expected.to eq 'error'}
24
+ end
25
+
26
+ context 'when status is not valid' do
27
+ let(:status) { 'noop' }
28
+
29
+ it 'should raise an error' do
30
+ expect{ subject }.to raise_error(RuntimeError)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::StockMovementsHelper, :type => :helper do
4
+
5
+ describe "#pretty_originator" do
6
+ let!(:stock_location) { create(:stock_location_with_items) }
7
+ let!(:stock_item) { stock_location.stock_items.first }
8
+ let(:stock_movement) { create(:stock_movement, stock_item: stock_item, originator: originator) }
9
+
10
+ subject { helper.pretty_originator(stock_movement) }
11
+
12
+ context "originator has a number" do
13
+ let(:originator) { create(:order) }
14
+
15
+ it "returns the originator's number" do
16
+ expect(subject).to eq originator.number
17
+ end
18
+ end
19
+
20
+ context "originator doesn't have a number" do
21
+ let(:originator) { create(:user) }
22
+
23
+ it "returns an empty string" do
24
+ expect(subject).to eq ""
25
+ end
26
+ end
27
+ end
28
+
29
+ end