From 4eee7d4901342faa1b83b596cdbf042d7e397f60 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 18 Jun 2014 16:04:41 +1000 Subject: [PATCH] Enterprise user can manage their enterprises' producer properties --- app/models/spree/ability_decorator.rb | 2 ++ spec/features/admin/enterprises_spec.rb | 24 ++++++++++++++++++++++-- spec/models/spree/ability_spec.rb | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 44e7d5e02e..e6d93f25aa 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -72,6 +72,8 @@ class AbilityDecorator can [:admin, :index, :read, :create, :edit, :update], Exchange can [:admin, :index, :read, :create, :edit, :update], ExchangeFee + can [:admin, :index, :read, :create, :edit, :update_positions, :destroy], ProducerProperty + can [:admin, :index, :create], Enterprise can [:read, :edit, :update, :bulk_update], Enterprise do |enterprise| user.enterprises.include? enterprise diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index df3198b757..50ce2aad7f 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -273,7 +273,7 @@ feature %q{ Enterprise.managed_by(@new_user).should include enterprise end - scenario "can edit enterprises I have permission to" do + scenario "editing enterprises I have permission to" do click_link 'Enterprises' within('#listing_enterprises tbody tr:first') { click_link 'Edit Profile' } @@ -284,11 +284,31 @@ feature %q{ page.should have_field 'enterprise_name', :with => 'Eaterprises' end - scenario "Editing images for an enterprise" do + scenario "editing images for an enterprise" do click_link 'Enterprises' first(".edit").click page.should have_content "Logo" page.should have_content "Promo" end + + scenario "managing producer properties", js: true do + click_link 'Enterprises' + within(".enterprise-#{supplier1.id}") { click_link 'Properties' } + + # -- Create / update + fill_in 'enterprise_producer_properties_attributes_0_property_name', with: "Certified Organic" + fill_in 'enterprise_producer_properties_attributes_0_value', with: "NASAA 12345" + click_button 'Update' + page.should have_selector '#listing_enterprises a', text: supplier1.name + supplier1.producer_properties(true).count.should == 1 + + # -- Destroy + pp = supplier1.producer_properties.first + within(".enterprise-#{supplier1.id}") { click_link 'Properties' } + + within("#spree_producer_property_#{pp.id}") { page.find('a.remove_fields').click } + page.should_not have_selector '#progress' + supplier1.producer_properties(true).should be_empty + end end end diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 111c8e5196..9705fee70e 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -75,6 +75,10 @@ module Spree should have_ability([:admin, :index, :read, :create, :edit], for: Spree::Classification) end + it "should be able to read/write their enterprises' producer properties" do + should have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: ProducerProperty) + end + it "should be able to read and create enterprise relationships" do should have_ability([:admin, :index, :create], for: EnterpriseRelationship) end