diff --git a/app/models/program.rb b/app/models/program.rb index f36399f6..3fb65f5e 100644 --- a/app/models/program.rb +++ b/app/models/program.rb @@ -4,6 +4,7 @@ class Program key :author_username, String key :slug, String key :title, String + key :description, String key :source_code, String key :featured, Boolean timestamps! diff --git a/app/views/programs/index.html.haml b/app/views/programs/index.html.haml index 46f0a890..702cc584 100644 --- a/app/views/programs/index.html.haml +++ b/app/views/programs/index.html.haml @@ -10,7 +10,7 @@ %h3 Featured .description Our favorite selection of projects. - %ul + %ul.featured_programs_list - @featured.each do |program| %li .title= program_link program @@ -22,7 +22,7 @@ %h3 All Programs .description Every program uploaded by our users! - %ul + %ul.programs_list - @programs.each do |program| %li .title= program_link program diff --git a/app/views/programs/show.html.haml b/app/views/programs/show.html.haml index 6a2441f8..b5ff2b1b 100644 --- a/app/views/programs/show.html.haml +++ b/app/views/programs/show.html.haml @@ -19,6 +19,9 @@ by = link_to @program.author_username, user_path(@program.author_username) +.description + %p= @program.description + #program %pre.prettyprint= @program.source_code diff --git a/features/programs.feature b/features/programs.feature index bbbe906b..5680b723 100644 --- a/features/programs.feature +++ b/features/programs.feature @@ -13,4 +13,17 @@ Feature: Access Programs Scenario: View another user's programs Given a user has uploaded a program - Then I should be able to view their programs \ No newline at end of file + Then I should be able to view their programs + + Scenario: View an individual program + Given a user has uploaded a program + And I should be able to view their programs + When I click the first program link + Then I should see the program source + + Scenario: View a program with a description + Given a user has uploaded a program + And they have given their program a description + And I should be able to view their programs + When I click the first program link + Then I should see the description of their program diff --git a/features/step_definitions/program_steps.rb b/features/step_definitions/program_steps.rb index 63105587..f391a8de 100644 --- a/features/step_definitions/program_steps.rb +++ b/features/step_definitions/program_steps.rb @@ -15,7 +15,8 @@ def upload_program(user) @program = Program.create!(:author_username => user.username, :slug => "slug", - :title => "#{user.username}'s program") + :title => "#{user.username}'s program", + :source_code => "puts 'Hello world'") end Given /^I have uploaded a program$/ do @@ -30,6 +31,13 @@ def upload_program(user) upload_program(@user) end +Given /^they have given their program a description$/ do + @program = Program.last + @program.description = "A really cool program!" + @program.save +end + + def visit_user_programs_page visit user_path(@user) within ".about-user" do @@ -44,4 +52,20 @@ def visit_user_programs_page Then /^I should be able to view their programs$/ do visit_user_programs_page -end \ No newline at end of file +end + +When /^I click the first program link$/ do + within ".programs_list" do + find("li:first-child a").click() + end +end + +Then /^I should see the program source$/ do + within("#program") do + page.should have_content("puts 'Hello world'") + end +end + +Then /^I should see the description of their program$/ do + page.should have_content("A really cool program!") +end diff --git a/spec/unit/program_spec.rb b/spec/unit/program_spec.rb index 172d9bd7..c93ba99e 100644 --- a/spec/unit/program_spec.rb +++ b/spec/unit/program_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' describe Program do - let(:prog) { Program.create(author_username: 'tester', title: 'test title')} + let(:prog) { Program.create(author_username: 'tester', title: 'test title')} + it "sets the slug" do prog.slug.should == 'test-title' end