Skip to content

Commit c7d261b

Browse files
committed
close issue #119, fix for programs without username
1 parent 6cec366 commit c7d261b

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

app/helpers/programs_helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
module ProgramsHelper
22
def program_link program
3-
"#{link_to(program.title.titleize, user_program_path(program.author_username, program))}".html_safe
3+
if program.author_username.present?
4+
"#{link_to(program.title.titleize, user_program_path(program.author_username, program))}".html_safe
5+
else
6+
"#{link_to(program.title.titleize, url_for(:controller => '/programs', :action => 'show', :id => program.slug))}".html_safe
7+
end
48
end
59

610
def author_link username, program = nil
11+
return nil unless username
712
output = ""
813
output += link_to(username, user_path(username))
914

spec/views/programs_index.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'spec_helper'
2+
3+
describe 'programs/index.html.haml' do
4+
context 'programs without a username' do
5+
it "renders the page without error" do
6+
programs = [Fabricate(:program, author_username: nil)]
7+
assign(:programs, programs)
8+
render
9+
rendered.should have_selector('div', id: 'title', contents: 'MyString')
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)