Created
April 21, 2010 17:50
-
-
Save ihoka/374153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ApplicationHelper | |
| def person_hcard_for(record, company=nil, options={ :logo => true }) | |
| return '' if record.nil? | |
| html = '' | |
| company ||= record.kind_of?(User) ? record.firm : record.parent_contact; | |
| html << %Q(<div class="vcard person #{options[:class] || ''}">) | |
| html << %Q( <h4 class="fn">#{h record.name}</h4>) | |
| html << %Q( <div><a href="mailto:#{record.email}" class="email">#{h record.email}</a></div>) | |
| html << %Q( <address class="adr">) | |
| html << %Q( <div class="street-address">#{h company.address1}</div>) unless company.address1.blank? | |
| html << %Q( <div class="extended-address">#{h company.address2}</div>) unless company.address2.blank? | |
| html << %Q( <span class="locality">#{h company.city}</span>) unless company.city.blank? | |
| html << %Q( <span class="region">#{h company.state}</span>) unless company.state.blank? | |
| html << %Q( <span class="postal-code">#{h company.zip}</span>) unless company.zip.blank? | |
| html << %Q( <div class="country-name">#{h company.country}</div>) unless company.country.blank? | |
| html << %Q( </address>) | |
| html << %Q( <div>O: <span class="tel">#{h record.phone_office}</span></div>) unless record.phone_office.blank? | |
| html << %Q( <div>M: <span class="fax">#{h record.phone_mobile}</span></div>) unless record.phone_mobile.blank? | |
| html << %Q(</div>) | |
| html | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe ApplicationHelper do | |
| describe "#person_hcard_for" do | |
| subject { helper.person_hcard_for(record, company) } | |
| let(:company) {} | |
| shared_examples_for "a person hcard" do | |
| it_should_have_tag("div.vcard.person") | |
| it_should_have_tag(".vcard > h4.fn") { { :text => record.name } } | |
| it_should_have_tag(".vcard > div > a[href=?]") { ["mailto:#{record.email}", { :text => record.email }] } | |
| it_should_have_tag(".vcard > address.adr > div.street-address") { { :text => company.address1 } } | |
| it_should_have_tag(".vcard > address.adr > div.extended-address") { { :text => company.address2 } } | |
| it_should_have_tag(".vcard > address.adr > span.locality") { { :text => company.city } } | |
| it_should_have_tag(".vcard > address.adr > span.region") { { :text => company.state } } | |
| it_should_have_tag(".vcard > address.adr > span.postal-code") { { :text => company.zip } } | |
| it_should_have_tag(".vcard > address.adr > div.country-name") { { :text => company.country } } | |
| context "when the address fields are blank" do | |
| before(:each) do | |
| %w[address1 address2 city state zip country].each do |attr| | |
| company.send(:"#{attr}=", nil) | |
| end | |
| end | |
| it_should_not_have_tag("div.street-address") | |
| it_should_not_have_tag("div.extended-address") | |
| it_should_not_have_tag("span.locality") | |
| it_should_not_have_tag("span.region") | |
| it_should_not_have_tag("span.postal-code") | |
| it_should_not_have_tag("div.country-name") | |
| end | |
| end | |
| context "for a nil record" do | |
| let(:record) { } | |
| it { should == '' } | |
| end | |
| context "for a User" do | |
| let(:record) { Factory.build(:user) } | |
| let(:company) { record.firm } | |
| it_should_behave_like "a person hcard" | |
| end | |
| context "for a Client" do | |
| let(:record) { Factory.build(:person) } | |
| let(:company) { record.parent_contact } | |
| it_should_behave_like "a person hcard" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment