From 94c42abf56764602a020f902c9facd5f2e1d9df2 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 18 Jun 2014 12:34:42 +1000 Subject: [PATCH] Admin can update producer properties --- app/models/enterprise.rb | 4 +++- spec/features/admin/enterprises_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 1fc09d2880..cc21f866db 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -19,7 +19,9 @@ class Enterprise < ActiveRecord::Base delegate :latitude, :longitude, :city, :state_name, :to => :address - accepts_nested_attributes_for :address, :producer_properties + accepts_nested_attributes_for :address + accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? } + has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" } has_attached_file :promo_image, :styles => { :large => "1200x260#", :thumb => "100x100>" } diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 7a143d59fb..b868434952 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -183,6 +183,29 @@ feature %q{ s.producer_properties.first.property.presentation.should == "Certified Organic" s.producer_properties.first.value.should == "NASAA 12345" end + + it "updates producer properties" do + # Given a producer enterprise with a property + s = create(:supplier_enterprise) + s.producer_properties.create! property_name: 'Certified Organic', value: 'NASAA 12345' + + # When I go to its properties page + login_to_admin_section + visit main_app.admin_enterprise_producer_properties_path(s) + + # And I update the property + fill_in 'enterprise_producer_properties_attributes_0_property_name', with: "Biodynamic" + fill_in 'enterprise_producer_properties_attributes_0_value', with: "Shininess" + click_button 'Update' + + # Then I should be returned to the producer properties page + page.should have_selector 'h1.page-title', text: "Producer Properties" + + # And the property should be updated + s.producer_properties(true).count.should == 1 + s.producer_properties.first.property.presentation.should == "Biodynamic" + s.producer_properties.first.value.should == "Shininess" + end end