Skip to content
This repository has been archived by the owner on Jan 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #14 from ninech/fix-customer-link
Browse files Browse the repository at this point in the history
Handle deleted customers
  • Loading branch information
luxflux committed May 15, 2014
2 parents 36acced + 650a00d commit d191068
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/helpers/activities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def activity_source_information(activity)
def customer_link(customer_id)
return unless customer_link_enabled?
customer_url = UberZeit.config.customer_url
customer = Customer.where(id: customer_id).last || customer_id
customer = Customer.where(id: customer_id).last
return if customer.nil?
link_to(customer, (customer_url % customer.number))
end

Expand Down
28 changes: 28 additions & 0 deletions spec/helpers/activities_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,32 @@
it { should eq '.otrs: <a href="https://otrs.howdoyouturnthison/otrs/index.pl?Action=AgentTicketZoom&amp;TicketNumber=42">#42</a> und .redmine: <a href="https://redmine.yolo/issues/1337">#1337</a>' }
end
end

describe '#customer_link' do
let(:customer_id) { 1337 }
subject { helper.customer_link(customer_id) }

context 'without customer_url' do
before(:each) { UberZeit.config.customer_url = nil }

it { should be_nil }
end

context 'with customer_url' do
before(:each) { UberZeit.config.customer_url = 'https://www.nine.ch/customers/%s' }

context 'with a deleted customer' do
let(:customer_id) { FactoryGirl.create(:customer).tap { |c| c.delete }.id }

it { should be_nil }
end

context 'with an existing customer' do
let(:customer) { FactoryGirl.create(:customer) }
let(:customer_id) { customer.id }

it { should include "https://www.nine.ch/customers/#{customer.number}" }
end
end
end
end

0 comments on commit d191068

Please sign in to comment.