From 0868404e986b5c3e859b38c87718ee642397d172 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Fri, 9 Nov 2018 17:32:03 +0100 Subject: [PATCH] Add specs for new Api::EnterpriseFeesController --- .../api/enterprise_fees_controller_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/controllers/api/enterprise_fees_controller_spec.rb diff --git a/spec/controllers/api/enterprise_fees_controller_spec.rb b/spec/controllers/api/enterprise_fees_controller_spec.rb new file mode 100644 index 0000000000..fb938d43c5 --- /dev/null +++ b/spec/controllers/api/enterprise_fees_controller_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +module Api + describe EnterpriseFeesController, type: :controller do + include AuthenticationWorkflow + + let!(:unreferenced_fee) { create(:enterprise_fee) } + let!(:referenced_fee) { create(:enterprise_fee) } + let(:product) { create(:product) } + let(:distributor) { create(:distributor_enterprise) } + let!(:product_distribution) { create(:product_distribution, product: product, distributor: distributor, enterprise_fee: referenced_fee) } + let(:current_user) { create(:admin_user) } + + before do + allow(controller).to receive(:spree_current_user) { current_user } + end + + describe "destroy" do + it "removes the fee" do + expect { spree_delete :destroy, id: unreferenced_fee.id, format: :json } + .to change { EnterpriseFee.count }.by -1 + end + + context "when the fee is referenced by a product distribution" do + it "does not remove the fee" do + spree_delete :destroy, id: referenced_fee.id, format: :json + expect(response.status).to eq 403 + expect(response.body).to match(/That enterprise fee cannot be deleted/) + expect(referenced_fee.reload).to eq(referenced_fee) + end + end + end + end +end