Adding presenters to the social media fields

This commit is contained in:
Will Marshall
2014-06-04 15:25:46 +10:00
parent d384b18d1b
commit df7ee03cbf
2 changed files with 28 additions and 0 deletions

View File

@@ -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?

View File

@@ -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