diff --git a/app/assets/javascripts/admin/enterprise_fees.js b/app/assets/javascripts/admin/enterprise_fees.js index 14e638dc70..15a80b3e02 100644 --- a/app/assets/javascripts/admin/enterprise_fees.js +++ b/app/assets/javascripts/admin/enterprise_fees.js @@ -1,6 +1,17 @@ angular.module('enterprise_fees', []) - .controller('AdminEnterpriseFeesCtrl', ['$scope', '$http', function($scope, $http) { - $http.get('/admin/enterprise_fees.json?include_calculators=1').success(function(data) { + .controller('AdminEnterpriseFeesCtrl', ['$scope', '$http', '$window', function($scope, $http, $window) { + $scope.enterpriseFeesUrl = function() { + var url = '/admin/enterprise_fees.json?include_calculators=1'; + + var match = $window.location.search.match(/enterprise_id=(\d+)/); + if(match) { + url += "&"+match[0]; + } + + return url; + }; + + $http.get($scope.enterpriseFeesUrl()).success(function(data) { $scope.enterprise_fees = data; for(i=0; i<3; i++) { diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 0b74409ee8..75035a2d64 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -51,7 +51,14 @@ module Admin end def collection - EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name') + collection = EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name') + + if params.key? :enterprise_id + enterprise = Enterprise.find params[:enterprise_id] + collection = collection.for_enterprise(enterprise) + end + + collection end end end diff --git a/app/views/admin/enterprises/index.html.erb b/app/views/admin/enterprises/index.html.erb index 5a66ca495e..626c59deaf 100644 --- a/app/views/admin/enterprises/index.html.erb +++ b/app/views/admin/enterprises/index.html.erb @@ -43,7 +43,7 @@ <%= link_to_with_icon 'icon-chevron-right', 'Payment Methods', spree.admin_payment_methods_path(enterprise_id: enterprise.id) %> (<%= enterprise.payment_methods.count %>)
<%= link_to_with_icon 'icon-plane', 'Shipping Methods', spree.admin_shipping_methods_path(enterprise_id: enterprise.id) %> (<%= enterprise.shipping_methods.count %>)
- <%= link_to_with_icon 'icon-money', 'Enterprise Fees', main_app.admin_enterprise_fees_path %> (<%= enterprise.enterprise_fees.count %>) + <%= link_to_with_icon 'icon-money', 'Enterprise Fees', main_app.admin_enterprise_fees_path(enterprise_id: enterprise.id) %> (<%= enterprise.enterprise_fees.count %>) <% end %> diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb index ebb04ea575..0d700fab13 100644 --- a/spec/features/admin/enterprise_fees_spec.rb +++ b/spec/features/admin/enterprise_fees_spec.rb @@ -128,8 +128,8 @@ feature %q{ let(:enterprise_user) { create_enterprise_user } let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') } let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') } - let(:ef1) { create(:enterprise_fee, name: 'One', distributors: [distributor1]) } - let(:ef2) { create(:enterprise_fee, name: 'Two', distributors: [distributor2]) } + let(:ef1) { create(:enterprise_fee, name: 'One', enterprise: distributor1) } + let(:ef2) { create(:enterprise_fee, name: 'Two', enterprise: distributor2) } before(:each) do enterprise_user.enterprise_roles.build(enterprise: distributor1).save @@ -151,5 +151,20 @@ feature %q{ enterprise_fee = EnterpriseFee.find_by_name 'foo' enterprise_fee.enterprise.should == distributor1 end + + it "shows me only enterprise fees for the enterprise I select" do + ef1 + ef2 + + click_link 'Enterprises' + within(".enterprise-#{distributor1.id}") { click_link 'Enterprise Fees' } + page.should have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One' + page.should_not have_field 'enterprise_fee_set_collection_attributes_1_name', with: 'Two' + + click_link 'Enterprises' + within(".enterprise-#{distributor2.id}") { click_link 'Enterprise Fees' } + page.should_not have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One' + page.should have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'Two' + end end end