-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10704 from abdellani/hide-customers-with-no-compl…
…eted-orders Hide users with no completed orders from a hub's customers list
- Loading branch information
Showing
13 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
db/migrate/20230516072511_add_created_manually_flag_to_customer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddCreatedManuallyFlagToCustomer < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :customers, :created_manually, :boolean, null: false, default: false | ||
add_index :customers, :created_manually | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
db/migrate/20230525081252_update_created_manually_flag_on_customers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdateCreatedManuallyFlagOnCustomers < ActiveRecord::Migration[7.0] | ||
class Customer < ApplicationRecord | ||
has_many :orders | ||
end | ||
|
||
class Order < ApplicationRecord | ||
self.table_name = 'spree_orders' | ||
end | ||
|
||
def up | ||
Customer.where.missing(:orders).update_all(created_manually: true) | ||
end | ||
|
||
def down | ||
Customer.where(created_manually: true).update_all(created_manually: false) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,17 @@ | |
describe "using the customers index" do | ||
let!(:customer1) { | ||
create(:customer, first_name: 'John', last_name: 'Doe', enterprise: managed_distributor1, | ||
code: nil) | ||
code: nil, created_manually: true) | ||
} | ||
let!(:customer2) { | ||
create(:customer, enterprise: managed_distributor1, created_manually: true, code: nil) | ||
} | ||
let!(:customer3) { | ||
create(:customer, enterprise: unmanaged_distributor, created_manually: true,) | ||
} | ||
let!(:customer4) { | ||
create(:customer, enterprise: managed_distributor2, created_manually: true,) | ||
} | ||
let!(:customer2) { create(:customer, enterprise: managed_distributor1, code: nil) } | ||
let!(:customer3) { create(:customer, enterprise: unmanaged_distributor) } | ||
let!(:customer4) { create(:customer, enterprise: managed_distributor2) } | ||
|
||
before do | ||
login_as user | ||
|
@@ -346,6 +352,7 @@ def wait_for_modal_fade_in(time = 0.4) | |
context "when a shop is selected" do | ||
before do | ||
select2_select managed_distributor1.name, from: "shop_id" | ||
customer1.update!(created_manually: false) | ||
end | ||
|
||
it "creates customers when the email provided is valid" do | ||
|
@@ -366,21 +373,30 @@ def wait_for_modal_fade_in(time = 0.4) | |
text: "Email is invalid" | ||
}.to_not change{ Customer.of(managed_distributor1).count } | ||
|
||
# When an existing email is used | ||
expect{ | ||
fill_in 'email', with: customer1.email | ||
click_button 'Add Customer' | ||
expect(page).to have_selector "#new-customer-dialog .error", | ||
text: "Email is associated with an existing customer" | ||
}.to_not change{ Customer.of(managed_distributor1).count } | ||
|
||
# When a new valid email is used | ||
expect{ | ||
fill_in 'email', with: "[email protected]" | ||
click_button 'Add Customer' | ||
expect(page).not_to have_selector "#new-customer-dialog" | ||
}.to change{ Customer.of(managed_distributor1).count }.from(2).to(3) | ||
end | ||
|
||
it "shows a hidden customer when trying to create it" do | ||
click_link('New Customer') | ||
fill_in 'email', with: customer1.email | ||
|
||
expect do | ||
click_button 'Add Customer' | ||
expect(page).not_to have_selector "#new-customer-dialog" | ||
customer1.reload | ||
end | ||
.to change { customer1.created_manually }.from(false).to(true) | ||
.and change { Customer.count }.by(0) | ||
|
||
expect(page).to have_content customer1.email | ||
expect(page).to have_field "first_name", with: "John" | ||
expect(page).to have_field "last_name", with: "Doe" | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters