Skip to content

Commit f29398a

Browse files
committed
Adding programs to your profile.
Yeah, can't believe this wasn't already in there, but we need to add programs to our profile pages. With links!
1 parent 30eea60 commit f29398a

7 files changed

Lines changed: 53 additions & 11 deletions

File tree

factories/program.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Factory.sequence :program_title do |n|
2+
"Program#{n}"
3+
end
4+
Factory.define :program do |p|
5+
p.title { Factory.next(:program_title) }
6+
p.code "puts 'hello world'"
7+
end

features/programs.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ Feature: Programs
1010
And I should see "Hello world"
1111
And I should see "By steve"
1212
And I should see "puts"
13+
Scenario: See programs on my page
14+
Given I'm logged in as "steve"
15+
And I have some programs
16+
When I go to the hacker page for "steve"
17+
Then I should see "Programs"
18+
And I should see links to my programs

features/step_definitions/common_steps.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
def hacker
2+
@hacker ||= Factory(:hacker)
3+
end
14
def login hacker
25
visit "/login"
36
fill_in "username", :with => hacker.username
@@ -7,8 +10,8 @@ def login hacker
710

811
Given /^I'm logged in as admin$/ do
912
password = "foobar"
10-
hacker = Factory(:admin,:password => password, :password_confirmation => password)
11-
login hacker
13+
@hacker = Factory(:admin,:password => password, :password_confirmation => password)
14+
login @hacker
1215
end
1316

1417
Given /^I'm not logged in$/ do
@@ -20,27 +23,27 @@ def login hacker
2023
end
2124

2225
When /^I log in as "([^"]*)"$/ do |username|
23-
hacker = Factory(:hacker, :username => username)
24-
login hacker
26+
@hacker = Factory(:hacker, :username => username)
27+
login @hacker
2528
end
2629

2730

2831
Given /^I'm logged in$/ do
2932
password = "foobar"
30-
hacker = Factory(:hacker,:password => password, :password_confirmation => password)
31-
login hacker
33+
@hacker = Factory(:hacker,:password => password, :password_confirmation => password)
34+
login @hacker
3235
end
3336

3437
Given /^I'm logged in as "([^"]*)"$/ do |username|
3538
password = "foobar"
36-
hacker = Factory(:hacker,:username => username, :password => password, :password_confirmation => password)
37-
login hacker
39+
@hacker = Factory(:hacker,:username => username, :password => password, :password_confirmation => password)
40+
login @hacker
3841
end
3942

4043
Given /^I'm logged in as a user with the email "([^"]*)"$/ do |email|
4144
password = "foobar"
42-
hacker = Factory(:hacker,:email => email, :password => password, :password_confirmation => password)
43-
login hacker
45+
@hacker = Factory(:hacker,:email => email, :password => password, :password_confirmation => password)
46+
login @hacker
4447
end
4548

4649
Given /^there's a hacker with the username "([^"]*)"$/ do |username|

features/step_definitions/hacker_steps.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,17 @@
33
followee = Hacker.first(:username => u2)
44
follower.follow! followee
55
end
6+
7+
8+
Given /^I have some programs$/ do
9+
(rand(5) + 1).times do |n|
10+
hacker.programs << Factory(:program)
11+
end
12+
end
13+
14+
Then /^I should see links to my programs$/ do
15+
hacker.programs.each do |program|
16+
Then "I should see \"#{program.title}\" within \"a\""
17+
end
18+
end
19+

models/hacker.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def following? hacker
100100
following.include? hacker
101101
end
102102

103+
#this method looks up the programs for a given user
104+
def programs
105+
Program.all(:creator_username => username)
106+
end
107+
103108
private
104109

105110
#we're going to use the SHA1 encryption method for now.

utility.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def require_directory dirname
1414

1515
class String
1616
def to_slug
17-
self.gsub(/[^a-zA-Z _]/, "").gsub(/\s/, "_").downcase
17+
self.gsub(/[^a-zA-Z _0-9]/, "").gsub(/\s/, "_").downcase
1818
end
1919
end

views/hackers/show.haml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
%hr
66
%p Following: <a href="/hackers/#{@hacker.username}/following">#{@hacker.following.count}</a>
77
%p Followers: <a href="/hackers/#{@hacker.username}/followers">#{@hacker.followers.count}</a>
8+
%hr
9+
%h2 Programs:
10+
%ul
11+
- @hacker.programs.each do |program|
12+
%li
13+
%a{:href => "/programs/#{@hacker.username}/#{program.slug}"}= program.title
14+
815
%hr
916
- if logged_in?
1017
- if @hacker.username != current_user.username

0 commit comments

Comments
 (0)