Skip to content

Commit ddad435

Browse files
committed
Slug change and replies.
You can now view replies to a discussion. Also, to_slug now replaces spaces with _ rather than nothing.
1 parent e8c2297 commit ddad435

10 files changed

Lines changed: 46 additions & 4 deletions

File tree

controllers/forums.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
1414
#render the template!
1515
haml :"forums/show"
1616
end
17+
18+
#you view a discussion here
19+
get "/forums/:forum/:discussion" do
20+
@discussion = Discussion.first(:forum => params[:forum], :slug => params[:discussion])
21+
haml :"forums/discussion"
22+
end

factories/discussion.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
Factory.define :discussion do |t|
22

33
end
4+
Factory.define :discussion_with_reply, :parent => :discussion do |t|
5+
t.replies {|r| [Factory(:reply)] }
6+
end
7+
8+
Factory.define :reply do |r|
9+
r.body "I'm here to help!"
10+
end

features/forum.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ Feature: The Hackety Forum
1111
When I go to the forums
1212
And I follow "Learning Ruby"
1313
Then I should see "I need help!"
14+
Scenario: View replies to a discussion
15+
Given I'm logged in
16+
And there's a discussion named "I need help" in "learning_ruby" with a reply
17+
When I go to the discussion "learning_ruby/i_need_help"
18+
Then I should see "I need help"
19+
And I should see "I'm here to help!"

features/programs.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Programs
55
And I fill in "Title" with "Hello world"
66
And I fill in "Body" with "puts 'Hello, world!'"
77
And I press "Create"
8-
Then I should be on the "steve/helloworld" program page.
8+
Then I should be on the "steve/hello_world" program page.
99
And I should see "Program created"
1010
And I should see "Hello world"
1111
And I should see "By steve"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Given /^there's a discussion named "([^"]*)" in "([^"]*)"$/ do |title, forum|
22
Factory(:discussion, :title => title, :forum => forum)
33
end
4+
5+
Given /^there's a discussion named "([^"]*)" in "([^"]*)" with a reply$/ do |title, forum|
6+
Factory(:discussion_with_reply, :title => title, :forum => forum)
7+
end

features/support/paths.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def path_to(page_name)
4242
"/messages"
4343
when /the new program page/
4444
"/programs/new"
45-
when /the "(.*)\/(.*)" program page/
46-
"/programs/#{$1}/#{$2}"
45+
when /the "(.*)" program page/
46+
"/programs/#{$1}"
4747
when /the forums/
4848
"/forums"
49+
when /the discussion "(.*)"/
50+
"/forums/#{$1}"
4951

5052
# Add more mappings here.
5153
# Here is an example that pulls values out of the Regexp:

models/discussion.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class Discussion
99
#this is the forum that it's in.
1010
key :forum, String
1111

12+
#these are all the replies people make
13+
many :replies
14+
1215
#this is the slug for the url
1316
key :slug, String
1417

models/reply.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#this is a reply to a forum discussion
2+
class Reply
3+
#it's embedded in a discussion
4+
include MongoMapper::EmbeddedDocument
5+
6+
#the body of the reply
7+
key :body, String
8+
9+
end

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(/\s/, "").downcase
17+
self.gsub(/\s/, "_").downcase
1818
end
1919
end

views/forums/discussion.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%h1= @discussion.title
2+
3+
%ul
4+
- @discussion.replies.each do |reply|
5+
%li= reply.body

0 commit comments

Comments
 (0)