solidus_backend 1.0.2 → 1.0.3

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +15 -0
  5. data/script/rails +9 -0
  6. data/solidus_backend.gemspec +28 -0
  7. data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
  8. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
  9. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
  10. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  11. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  12. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
  13. data/spec/controllers/spree/admin/orders_controller_spec.rb +472 -0
  14. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  15. data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
  16. data/spec/controllers/spree/admin/products_controller_spec.rb +45 -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 +75 -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 +226 -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 +331 -0
  33. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
  34. data/spec/controllers/spree/admin/users_controller_spec.rb +236 -0
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  36. data/spec/features/admin/configuration/analytics_tracker_spec.rb +54 -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 +125 -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 +228 -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 +392 -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/tiered_calculator_spec.rb +69 -0
  75. data/spec/features/admin/reports_spec.rb +61 -0
  76. data/spec/features/admin/stock_transfer_spec.rb +86 -0
  77. data/spec/features/admin/store_credits_spec.rb +82 -0
  78. data/spec/features/admin/taxons_spec.rb +31 -0
  79. data/spec/features/admin/users_spec.rb +270 -0
  80. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  81. data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
  82. data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
  83. data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
  84. data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
  85. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  86. data/spec/spec_helper.rb +108 -0
  87. data/spec/support/appear_before_matcher.rb +8 -0
  88. data/spec/support/ror_ringer.jpeg +0 -0
  89. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  90. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  91. metadata +95 -6
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Tiered Calculator Promotions" do
4
+ stub_authorization!
5
+
6
+ let(:promotion) { create :promotion }
7
+
8
+ background do
9
+ visit spree.edit_admin_promotion_path(promotion)
10
+ end
11
+
12
+ scenario "adding a tiered percent calculator", js: true do
13
+ select2 "Create whole-order adjustment", from: "Add action of type"
14
+ within('#action_fields') { click_button "Add" }
15
+
16
+ select2 "Tiered Percent", from: "Calculator"
17
+ within('#actions_container') { click_button "Update" }
18
+
19
+ within("#actions_container .settings") do
20
+ expect(page).to have_content("BASE PERCENT")
21
+ expect(page).to have_content("TIERS")
22
+
23
+ click_button "Add"
24
+ end
25
+
26
+ fill_in "Base Percent", with: 5
27
+
28
+ within(".tier") do
29
+ find("input:last-child").set(100)
30
+ find("input:first-child").set(10)
31
+ end
32
+
33
+ within('#actions_container') { click_button "Update" }
34
+
35
+ first_action = promotion.actions.first
36
+ expect(first_action.class).to eq Spree::Promotion::Actions::CreateAdjustment
37
+
38
+ first_action_calculator = first_action.calculator
39
+ expect(first_action_calculator.class).to eq Spree::Calculator::TieredPercent
40
+ expect(first_action_calculator.preferred_base_percent).to eq 5
41
+ expect(first_action_calculator.preferred_tiers).to eq Hash[100.0 => 10.0]
42
+ end
43
+
44
+ context "with an existing tiered flat rate calculator" do
45
+ let(:promotion) { create :promotion, :with_order_adjustment }
46
+
47
+ background do
48
+ action = promotion.actions.first
49
+
50
+ action.calculator = Spree::Calculator::TieredFlatRate.new
51
+ action.calculator.preferred_base_amount = 5
52
+ action.calculator.preferred_tiers = Hash[100 => 10, 200 => 15, 300 => 20]
53
+ action.calculator.save!
54
+
55
+ visit spree.edit_admin_promotion_path(promotion)
56
+ end
57
+
58
+ scenario "deleting a tier", js: true do
59
+ within(".tier:nth-child(2)") do
60
+ find(".remove").click
61
+ end
62
+
63
+ within('#actions_container') { click_button "Update" }
64
+
65
+ calculator = promotion.actions.first.calculator
66
+ expect(calculator.preferred_tiers).to eq Hash[100.0 => 10.0, 300.0 => 20.0]
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Reports", :type => :feature do
4
+ stub_authorization!
5
+
6
+ context "visiting the admin reports page" do
7
+ it "should have the right content" do
8
+ visit spree.admin_path
9
+ click_link "Reports"
10
+ click_link "Sales Total"
11
+
12
+ expect(page).to have_content("Sales Totals")
13
+ expect(page).to have_content("Item Total")
14
+ expect(page).to have_content("Adjustment Total")
15
+ expect(page).to have_content("Sales Total")
16
+ end
17
+ end
18
+
19
+ context "searching the admin reports page" do
20
+ before do
21
+ order = create(:order)
22
+ order.update_columns({:adjustment_total => 100})
23
+ order.completed_at = Time.now
24
+ order.save!
25
+
26
+ order = create(:order)
27
+ order.update_columns({:adjustment_total => 200})
28
+ order.completed_at = Time.now
29
+ order.save!
30
+
31
+ #incomplete order
32
+ order = create(:order)
33
+ order.update_columns({:adjustment_total => 50})
34
+ order.save!
35
+
36
+ order = create(:order)
37
+ order.update_columns({:adjustment_total => 200})
38
+ order.completed_at = 3.years.ago
39
+ order.created_at = 3.years.ago
40
+ order.save!
41
+
42
+ order = create(:order)
43
+ order.update_columns({:adjustment_total => 200})
44
+ order.completed_at = 3.years.from_now
45
+ order.created_at = 3.years.from_now
46
+ order.save!
47
+ end
48
+
49
+ it "should allow me to search for reports" do
50
+ visit spree.admin_path
51
+ click_link "Reports"
52
+ click_link "Sales Total"
53
+
54
+ fill_in "q_completed_at_gt", :with => 1.week.ago
55
+ fill_in "q_completed_at_lt", :with => 1.week.from_now
56
+ click_button "Search"
57
+
58
+ expect(page).to have_content("$300.00")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,86 @@
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 'ship stock transfer' do
37
+ let(:stock_transfer) { create(:stock_transfer_with_items) }
38
+
39
+ before do
40
+ stock_transfer.transfer_items do |item|
41
+ item.update_attributes(expected_quantity: 1)
42
+ end
43
+ end
44
+
45
+ describe "tracking info" do
46
+ it 'adds tracking number' do
47
+ visit spree.tracking_info_admin_stock_transfer_path(stock_transfer)
48
+
49
+ fill_in 'stock_transfer_tracking_number', :with => "12345"
50
+ click_button 'Save'
51
+
52
+ expect(page).to have_content('Stock Transfer has been successfully updated')
53
+ expect(stock_transfer.reload.tracking_number).to eq '12345'
54
+ end
55
+ end
56
+
57
+ describe 'with enough stock' do
58
+ it 'ships stock transfer' do
59
+ visit spree.tracking_info_admin_stock_transfer_path(stock_transfer)
60
+ click_link 'ship'
61
+
62
+ first('#confirm-ship-link', visible: false).click
63
+ expect(current_path).to eq spree.admin_stock_transfers_path
64
+ expect(stock_transfer.reload.shipped_at).to_not be_nil
65
+ end
66
+ end
67
+
68
+ describe 'without enough stock' do
69
+ before do
70
+ stock_transfer.transfer_items.each do |item|
71
+ stock_transfer.source_location.stock_item(item.variant).set_count_on_hand(0)
72
+ end
73
+ end
74
+
75
+ it 'does not ship stock transfer' do
76
+ visit spree.tracking_info_admin_stock_transfer_path(stock_transfer)
77
+
78
+ click_link 'ship'
79
+
80
+ first('#confirm-ship-link', visible: false).click
81
+ expect(current_path).to eq spree.tracking_info_admin_stock_transfer_path(stock_transfer)
82
+ expect(stock_transfer.reload.shipped_at).to be_nil
83
+ end
84
+ end
85
+ end
86
+ 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,270 @@
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
+ end
165
+ end
166
+
167
+ context 'an api key exists' do
168
+ before do
169
+ user_a.generate_spree_api_key!
170
+ expect(user_a.reload.spree_api_key).to be_present
171
+ visit current_path
172
+ end
173
+
174
+ it 'can clear an api key' do
175
+ within("#admin_user_edit_api_key") do
176
+ click_button Spree.t('clear_key', :scope => 'api')
177
+ end
178
+
179
+ expect(user_a.reload.spree_api_key).to be_blank
180
+ expect { find("#current-api-key") }.to raise_error Capybara::ElementNotFound
181
+ end
182
+
183
+ it 'can regenerate an api key' do
184
+ old_key = user_a.spree_api_key
185
+
186
+ within("#admin_user_edit_api_key") do
187
+ click_button Spree.t('regenerate_key', :scope => 'api')
188
+ end
189
+
190
+ expect(user_a.reload.spree_api_key).to be_present
191
+ expect(user_a.reload.spree_api_key).not_to eq old_key
192
+ end
193
+ end
194
+ end
195
+
196
+ context 'order history with sorting' do
197
+
198
+ before do
199
+ orders
200
+ click_link user_a.email
201
+ within("#sidebar") { click_link Spree.t(:"admin.user.orders") }
202
+ end
203
+
204
+ it_behaves_like 'a user page'
205
+
206
+ context "completed_at" do
207
+ it_behaves_like "a sortable attribute" do
208
+ let(:text_match_1) { I18n.l(order.completed_at.to_date) }
209
+ let(:text_match_2) { I18n.l(order_2.completed_at.to_date) }
210
+ let(:table_id) { "listing_orders" }
211
+ let(:sort_link) { "orders_completed_at_title" }
212
+ end
213
+ end
214
+
215
+ [:number, :state, :total].each do |attr|
216
+ context attr do
217
+ it_behaves_like "a sortable attribute" do
218
+ let(:text_match_1) { order.send(attr).to_s }
219
+ let(:text_match_2) { order_2.send(attr).to_s }
220
+ let(:table_id) { "listing_orders" }
221
+ let(:sort_link) { "orders_#{attr}_title" }
222
+ end
223
+ end
224
+ end
225
+ end
226
+
227
+ context 'items purchased with sorting' do
228
+
229
+ before do
230
+ orders
231
+ click_link user_a.email
232
+ within("#sidebar") { click_link Spree.t(:"admin.user.items") }
233
+ end
234
+
235
+ it_behaves_like 'a user page'
236
+
237
+ context "completed_at" do
238
+ it_behaves_like "a sortable attribute" do
239
+ let(:text_match_1) { I18n.l(order.completed_at.to_date) }
240
+ let(:text_match_2) { I18n.l(order_2.completed_at.to_date) }
241
+ let(:table_id) { "listing_items" }
242
+ let(:sort_link) { "orders_completed_at_title" }
243
+ end
244
+ end
245
+
246
+ [:number, :state].each do |attr|
247
+ context attr do
248
+ it_behaves_like "a sortable attribute" do
249
+ let(:text_match_1) { order.send(attr).to_s }
250
+ let(:text_match_2) { order_2.send(attr).to_s }
251
+ let(:table_id) { "listing_items" }
252
+ let(:sort_link) { "orders_#{attr}_title" }
253
+ end
254
+ end
255
+ end
256
+
257
+ it "has item attributes" do
258
+ items = order.line_items | order_2.line_items
259
+ expect(page).to have_table 'listing_items'
260
+ within_table('listing_items') do
261
+ items.each do |item|
262
+ expect(page).to have_selector(".item-name", text: item.product.name)
263
+ expect(page).to have_selector(".item-price", text: item.single_money.to_html)
264
+ expect(page).to have_selector(".item-quantity", text: item.quantity)
265
+ expect(page).to have_selector(".item-total", text: item.money.to_html)
266
+ end
267
+ end
268
+ end
269
+ end
270
+ end