mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Wiring up update action for customers controller
This commit is contained in:
@@ -57,6 +57,39 @@ describe Admin::CustomersController, type: :controller do
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let(:another_enterprise) { create(:distributor_enterprise) }
|
||||
|
||||
context "json" do
|
||||
let!(:customer) { create(:customer, enterprise: enterprise) }
|
||||
|
||||
context "where I manage the customer's enterprise" do
|
||||
before do
|
||||
controller.stub spree_current_user: enterprise.owner
|
||||
end
|
||||
|
||||
it "allows me to update the customer" do
|
||||
spree_put :update, format: :json, id: customer.id, customer: { email: 'new.email@gmail.com' }
|
||||
expect(assigns(:customer)).to eq customer
|
||||
expect(customer.reload.email).to eq 'new.email@gmail.com'
|
||||
end
|
||||
end
|
||||
|
||||
context "where I don't manage the customer's enterprise" do
|
||||
before do
|
||||
controller.stub spree_current_user: another_enterprise.owner
|
||||
end
|
||||
|
||||
it "prevents me from updating the customer" do
|
||||
spree_put :update, format: :json, id: customer.id, customer: { email: 'new.email@gmail.com' }
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
expect(assigns(:customer)).to eq nil
|
||||
expect(customer.email).to_not eq 'new.email@gmail.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user