Skip to content

Commit 9646ec2

Browse files
committed
Merge pull request #120 from mathias/program_descriptions
Program descriptions
2 parents 68997eb + c7857ea commit 9646ec2

6 files changed

Lines changed: 48 additions & 6 deletions

File tree

app/models/program.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Program
44
key :author_username, String
55
key :slug, String
66
key :title, String
7+
key :description, String
78
key :source_code, String
89
key :featured, Boolean
910
timestamps!

app/views/programs/index.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
%h3 Featured
1111
.description Our favorite selection of projects.
1212

13-
%ul
13+
%ul.featured_programs_list
1414
- @featured.each do |program|
1515
%li
1616
.title= program_link program
@@ -22,7 +22,7 @@
2222
%h3 All Programs
2323
.description Every program uploaded by our users!
2424

25-
%ul
25+
%ul.programs_list
2626
- @programs.each do |program|
2727
%li
2828
.title= program_link program

app/views/programs/show.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
by
2020
= link_to @program.author_username, user_path(@program.author_username)
2121

22+
.description
23+
%p= @program.description
24+
2225
#program
2326
%pre.prettyprint= @program.source_code
2427

features/programs.feature

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,17 @@ Feature: Access Programs
1313

1414
Scenario: View another user's programs
1515
Given a user has uploaded a program
16-
Then I should be able to view their programs
16+
Then I should be able to view their programs
17+
18+
Scenario: View an individual program
19+
Given a user has uploaded a program
20+
And I should be able to view their programs
21+
When I click the first program link
22+
Then I should see the program source
23+
24+
Scenario: View a program with a description
25+
Given a user has uploaded a program
26+
And they have given their program a description
27+
And I should be able to view their programs
28+
When I click the first program link
29+
Then I should see the description of their program

features/step_definitions/program_steps.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
def upload_program(user)
1616
@program = Program.create!(:author_username => user.username,
1717
:slug => "slug",
18-
:title => "#{user.username}'s program")
18+
:title => "#{user.username}'s program",
19+
:source_code => "puts 'Hello world'")
1920
end
2021

2122
Given /^I have uploaded a program$/ do
@@ -30,6 +31,13 @@ def upload_program(user)
3031
upload_program(@user)
3132
end
3233

34+
Given /^they have given their program a description$/ do
35+
@program = Program.last
36+
@program.description = "A really cool program!"
37+
@program.save
38+
end
39+
40+
3341
def visit_user_programs_page
3442
visit user_path(@user)
3543
within ".about-user" do
@@ -44,4 +52,20 @@ def visit_user_programs_page
4452

4553
Then /^I should be able to view their programs$/ do
4654
visit_user_programs_page
47-
end
55+
end
56+
57+
When /^I click the first program link$/ do
58+
within ".programs_list" do
59+
find("li:first-child a").click()
60+
end
61+
end
62+
63+
Then /^I should see the program source$/ do
64+
within("#program") do
65+
page.should have_content("puts 'Hello world'")
66+
end
67+
end
68+
69+
Then /^I should see the description of their program$/ do
70+
page.should have_content("A really cool program!")
71+
end

spec/unit/program_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require 'spec_helper'
22

33
describe Program do
4-
let(:prog) { Program.create(author_username: 'tester', title: 'test title')}
4+
let(:prog) { Program.create(author_username: 'tester', title: 'test title')}
5+
56
it "sets the slug" do
67
prog.slug.should == 'test-title'
78
end

0 commit comments

Comments
 (0)