From 357ff5fb7d76d24882c3a1cab32e5dc5fadfb9c1 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Sat, 3 Mar 2018 12:42:42 +0000 Subject: [PATCH] Improve associating customer specs --- spec/features/consumer/shopping/shopping_spec.rb | 5 ++++- spec/models/spree/user_spec.rb | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 4e3dd8781c..d7f80d3ba7 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -469,6 +469,7 @@ feature "As a consumer I want to shop with a distributor", js: true do let!(:customer) { create(:customer, user: user, enterprise: distributor) } it "shows just products" do + visit shop_path shows_products_without_customer_warning end end @@ -477,6 +478,7 @@ feature "As a consumer I want to shop with a distributor", js: true do let!(:role) { create(:enterprise_role, user: user, enterprise: distributor) } it "shows just products" do + visit shop_path shows_products_without_customer_warning end end @@ -488,6 +490,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "shows just products" do + visit shop_path shows_products_without_customer_warning end end @@ -501,6 +504,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "shows the products without customer only message" do + visit shop_path shows_products_without_customer_warning end end @@ -508,7 +512,6 @@ feature "As a consumer I want to shop with a distributor", js: true do end def shows_products_without_customer_warning - visit shop_path expect(page).to have_no_content "This shop is for customers only." expect(page).to have_content product.name end diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index 8d1c0c0e18..39a1ce530e 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -80,12 +80,16 @@ describe Spree.user_class do context "with the the same email as existing customers" do let(:email) { Faker::Internet.email } - let!(:customer1) { create(:customer, user: nil, email: email) } - let!(:customer2) { create(:customer, user: nil, email: email) } + let(:enterprise1) { create(:enterprise) } + let(:enterprise2) { create(:enterprise) } + let!(:customer1) { create(:customer, user: nil, email: email, enterprise: enterprise1) } + let!(:customer2) { create(:customer, user: nil, email: email, enterprise: enterprise2) } let!(:user) { create(:user, email: email) } it "should associate these customers with the created user" do expect(user.customers.reload).to include customer1, customer2 + expect(user.customer_of(enterprise1)).to be_truthy + expect(user.customer_of(enterprise2)).to be_truthy end end end