Permalink
Browse files

close issue #119, fix for programs without username

  • Loading branch information...
coreypurcell committed Jan 29, 2012
1 parent 6cec366 commit c7d261bda6ee21d5dfa4358d5309d779e38b3734
Showing with 18 additions and 1 deletion.
  1. +6 −1 app/helpers/programs_helper.rb
  2. +12 −0 spec/views/programs_index.rb
@@ -1,9 +1,14 @@
module ProgramsHelper
def program_link program
- "#{link_to(program.title.titleize, user_program_path(program.author_username, program))}".html_safe
+ if program.author_username.present?
+ "#{link_to(program.title.titleize, user_program_path(program.author_username, program))}".html_safe
+ else
+ "#{link_to(program.title.titleize, url_for(:controller => '/programs', :action => 'show', :id => program.slug))}".html_safe
+ end
end
def author_link username, program = nil
+ return nil unless username
output = ""
output += link_to(username, user_path(username))
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe 'programs/index.html.haml' do
+ context 'programs without a username' do
+ it "renders the page without error" do
+ programs = [Fabricate(:program, author_username: nil)]
+ assign(:programs, programs)
+ render
+ rendered.should have_selector('div', id: 'title', contents: 'MyString')
+ end
+ end
+end

0 comments on commit c7d261b

Please sign in to comment.