From df7ee03cbf418c9d7ccd24f1204b9116d5d112a9 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 4 Jun 2014 15:25:46 +1000 Subject: [PATCH] Adding presenters to the social media fields --- app/models/enterprise.rb | 14 ++++++++++++++ spec/models/enterprise_spec.rb | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 7c54bb1f10..3c851bde45 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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? diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 23f300fba5..542d95a4b0 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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