mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
48 lines
1.4 KiB
Ruby
48 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Customer, type: :model do
|
|
describe 'an existing customer' do
|
|
let(:customer) { create(:customer) }
|
|
|
|
it "saves its code" do
|
|
code = "code one"
|
|
customer.code = code
|
|
customer.save
|
|
expect(customer.code).to eq code
|
|
end
|
|
|
|
it "can remove its code" do
|
|
customer.code = ""
|
|
customer.save
|
|
expect(customer.code).to be nil
|
|
end
|
|
end
|
|
|
|
describe 'creation callbacks' do
|
|
let!(:user1) { create(:user) }
|
|
let!(:user2) { create(:user) }
|
|
let!(:enterprise) { create(:distributor_enterprise) }
|
|
|
|
it "associates no user using non-existing email" do
|
|
c = Customer.create(enterprise: enterprise, email: 'some-email-not-associated-with-a-user@email.com')
|
|
expect(c.user).to be_nil
|
|
end
|
|
|
|
it "associates an existing user using email" do
|
|
non_existing_email = 'some-email-not-associated-with-a-user@email.com'
|
|
c1 = Customer.create(enterprise: enterprise, email: non_existing_email, user: user1)
|
|
expect(c1.user).to eq user1
|
|
expect(c1.email).to eq non_existing_email
|
|
expect(c1.email).to_not eq user1.email
|
|
|
|
c2 = Customer.create(enterprise: enterprise, email: user2.email)
|
|
expect(c2.user).to eq user2
|
|
end
|
|
|
|
it "associates an existing user using email case-insensitive" do
|
|
c = Customer.create(enterprise: enterprise, email: user2.email.upcase)
|
|
expect(c.user).to eq user2
|
|
end
|
|
end
|
|
end
|