mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Adding presenters to the social media fields
This commit is contained in:
@@ -149,6 +149,16 @@ class Enterprise < ActiveRecord::Base
|
||||
self.relatives.is_distributor
|
||||
end
|
||||
|
||||
def website
|
||||
strip_url read_attribute(:website)
|
||||
end
|
||||
def facebook
|
||||
strip_url read_attribute(:facebook)
|
||||
end
|
||||
def linkedin
|
||||
strip_url read_attribute(:linkedin)
|
||||
end
|
||||
|
||||
def suppliers
|
||||
self.relatives.is_primary_producer
|
||||
end
|
||||
@@ -180,6 +190,10 @@ class Enterprise < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def strip_url(url)
|
||||
url.andand.sub /(https?:\/\/)?(www\.)?/, ''
|
||||
end
|
||||
|
||||
def initialize_country
|
||||
self.address ||= Spree::Address.new
|
||||
self.address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record?
|
||||
|
||||
@@ -445,4 +445,18 @@ describe Enterprise do
|
||||
supplier.supplied_taxons.should == [taxon1, taxon2]
|
||||
end
|
||||
end
|
||||
|
||||
describe "presentation of attributes" do
|
||||
let(:distributor) {
|
||||
create(:distributor_enterprise,
|
||||
website: "http://www.google.com",
|
||||
facebook: "www.facebook.com/roger",
|
||||
linkedin: "http://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
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user