Set producer property

This commit is contained in:
Rohan Mitchell
2014-06-13 11:49:13 +10:00
parent 9d8629f41f
commit 0139c4bda2
2 changed files with 30 additions and 10 deletions

View File

@@ -103,13 +103,6 @@ class Enterprise < ActiveRecord::Base
end
}
# Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554
def self.distinct_count
count(distinct: true)
end
def self.find_near(suburb)
enterprises = []
@@ -121,6 +114,20 @@ class Enterprise < ActiveRecord::Base
enterprises
end
# Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554
def self.distinct_count
count(distinct: true)
end
def set_producer_property(property_name, property_value)
transaction do
property = Spree::Property.where(name: property_name).first_or_create!(presentation: property_name)
producer_property = ProducerProperty.where(producer_id: id, property_id: property.id).first_or_initialize
producer_property.value = property_value
producer_property.save!
end
end
def has_supplied_products_on_hand?
self.supplied_products.where('count_on_hand > 0').present?
end

View File

@@ -449,14 +449,27 @@ describe Enterprise do
describe "presentation of attributes" do
let(:distributor) {
create(:distributor_enterprise,
website: "http://www.google.com",
facebook: "www.facebook.com/roger",
linkedin: "http://linkedin.com")
website: "http://www.google.com",
facebook: "www.facebook.com/roger",
linkedin: "https://linkedin.com")
}
it "strips http and www from url fields" do
distributor.website.should == "google.com"
distributor.facebook.should == "facebook.com/roger"
distributor.linkedin.should == "linkedin.com"
end
end
describe "producer properties" do
let(:supplier) { create(:supplier_enterprise) }
it "sets producer properties" do
supplier.set_producer_property 'Organic Certified', 'NASAA 12345'
supplier.producer_properties.count.should == 1
supplier.producer_properties.first.value.should == 'NASAA 12345'
supplier.producer_properties.first.property.presentation.should == 'Organic Certified'
end
end
end