From 9248ac05aca132ac31b706bc12584977759f30cd Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Wed, 20 Sep 2017 11:24:13 +0100 Subject: [PATCH] Adjustments for failing specs --- app/controllers/admin/enterprises_controller.rb | 2 +- app/models/enterprise.rb | 2 +- app/models/enterprise_role.rb | 1 + spec/features/consumer/shopping/cart_spec.rb | 4 ++-- .../controllers/enterprise_controller_spec.js.coffee | 5 ++++- spec/models/enterprise_spec.rb | 9 +++------ 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 673f5c31c1..666db81e68 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -188,7 +188,7 @@ module Admin def load_roles @enterprise_roles = EnterpriseRole.find_all_by_enterprise_id(@enterprise.id) - @notification_user = EnterpriseRole.receives_notifications_for(@enterprise.id).try(:id) + @notification_user = EnterpriseRole.receives_notifications_for(@enterprise.id).try(:id) || @enterprise.owner.id end def update_tag_rules(tag_rules_attributes) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index d842c51b90..9fd5b6030c 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -178,7 +178,7 @@ class Enterprise < ActiveRecord::Base end def contact - EnterpriseRole.receives_notifications_for self.id + EnterpriseRole.receives_notifications_for id || owner end def activated? diff --git a/app/models/enterprise_role.rb b/app/models/enterprise_role.rb index 9c99c4ffe8..1cb23ba738 100644 --- a/app/models/enterprise_role.rb +++ b/app/models/enterprise_role.rb @@ -9,6 +9,7 @@ class EnterpriseRole < ActiveRecord::Base def self.receives_notifications_for(enterprise_id) manager = EnterpriseRole.find_by_enterprise_id_and_receives_notifications(enterprise_id, true) + return nil if manager.blank? Spree::User.find(manager.user_id) end diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index a39173064d..04acf0847a 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -87,15 +87,15 @@ feature "full-page cart", js: true do it "shows the quantities saved, not those submitted" do # Given we load the page with 3 on hand, then the number available drops to 2 + variant.update_attributes! on_hand: 3 visit spree.cart_path variant.update_attributes! on_hand: 2 fill_in "order_line_items_attributes_0_quantity", with: '4' - click_button 'Update' expect(page).to have_content "Insufficient stock available, only 2 remaining" - expect(page).to have_field "order[line_items_attributes][0][quantity]", with: '1' + expect(page).to have_field "order_line_items_attributes_0_quantity", with: '1' end end diff --git a/spec/javascripts/unit/admin/enterprises/controllers/enterprise_controller_spec.js.coffee b/spec/javascripts/unit/admin/enterprises/controllers/enterprise_controller_spec.js.coffee index 450876c9e6..3f0617a817 100644 --- a/spec/javascripts/unit/admin/enterprises/controllers/enterprise_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/enterprises/controllers/enterprise_controller_spec.js.coffee @@ -10,14 +10,17 @@ describe "enterpriseCtrl", -> enterprise = is_primary_producer: true sells: "none" + owner: + id: 98 PaymentMethods = paymentMethods: "payment methods" ShippingMethods = shippingMethods: "shipping methods" + receivesNotifications = 99 inject ($rootScope, $controller) -> scope = $rootScope - ctrl = $controller 'enterpriseCtrl', {$scope: scope, enterprise: enterprise, EnterprisePaymentMethods: PaymentMethods, EnterpriseShippingMethods: ShippingMethods} + ctrl = $controller 'enterpriseCtrl', {$scope: scope, enterprise: enterprise, EnterprisePaymentMethods: PaymentMethods, EnterpriseShippingMethods: ShippingMethods, receivesNotifications: receivesNotifications} describe "initialisation", -> it "stores enterprise", -> diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index e678831daa..560103eaa7 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -146,7 +146,6 @@ describe Enterprise do end it "sets the enterprise contact to the owner by default" do - enterprise.contact.should be_present enterprise.contact.should eq enterprise.owner end end @@ -217,15 +216,13 @@ describe Enterprise do describe "activated" do let!(:unconfirmed_user) { create(:user, confirmed_at: nil, enterprise_limit: 2) } - let!(:inactive_enterprise1) { create(:enterprise, sells: "unspecified", owner: unconfirmed_user) } - let!(:inactive_enterprise2) { create(:enterprise, sells: "none", owner: unconfirmed_user) } + let!(:inactive_enterprise) { create(:enterprise, sells: "unspecified") } let!(:active_enterprise) { create(:enterprise, sells: "none") } - it "finds enterprises that have a sells property other than 'unspecified' and have a confirmed user" do + it "finds enterprises that have a sells property other than 'unspecified'" do activated_enterprises = Enterprise.activated expect(activated_enterprises).to include active_enterprise - expect(activated_enterprises).to_not include inactive_enterprise1 - expect(activated_enterprises).to_not include inactive_enterprise2 + expect(activated_enterprises).to_not include inactive_enterprise end end