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

Commit d191068

Browse files
committed
Merge pull request #14 from ninech/fix-customer-link
Handle deleted customers
2 parents 36acced + 650a00d commit d191068

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

app/helpers/activities_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def activity_source_information(activity)
1515
def customer_link(customer_id)
1616
return unless customer_link_enabled?
1717
customer_url = UberZeit.config.customer_url
18-
customer = Customer.where(id: customer_id).last || customer_id
18+
customer = Customer.where(id: customer_id).last
19+
return if customer.nil?
1920
link_to(customer, (customer_url % customer.number))
2021
end
2122

spec/helpers/activities_helper_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,32 @@
2323
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>' }
2424
end
2525
end
26+
27+
describe '#customer_link' do
28+
let(:customer_id) { 1337 }
29+
subject { helper.customer_link(customer_id) }
30+
31+
context 'without customer_url' do
32+
before(:each) { UberZeit.config.customer_url = nil }
33+
34+
it { should be_nil }
35+
end
36+
37+
context 'with customer_url' do
38+
before(:each) { UberZeit.config.customer_url = 'https://www.nine.ch/customers/%s' }
39+
40+
context 'with a deleted customer' do
41+
let(:customer_id) { FactoryGirl.create(:customer).tap { |c| c.delete }.id }
42+
43+
it { should be_nil }
44+
end
45+
46+
context 'with an existing customer' do
47+
let(:customer) { FactoryGirl.create(:customer) }
48+
let(:customer_id) { customer.id }
49+
50+
it { should include "https://www.nine.ch/customers/#{customer.number}" }
51+
end
52+
end
53+
end
2654
end

0 commit comments

Comments
 (0)