Skip to content

Commit 1561cd7

Browse files
committed
Users can see the messages sent to them.
1 parent b8a89d0 commit 1561cd7

7 files changed

Lines changed: 40 additions & 0 deletions

File tree

controllers/messages.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@
1818
#render the page of the recipient
1919
redirect "/hackers/#{message.recipient}"
2020
end
21+
22+
#this is the page where you can see your messages
23+
get "/messages" do
24+
require_login!
25+
@messages = Message.all({"recipient" => current_user.username})
26+
haml :"messages/index"
27+
end

factories/message.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Factory.define :message do |m|
2+
m.body "Hello there!"
3+
m.recipient "fela"
4+
m.sender "steve"
5+
end

features/messages.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ Feature: Messages
1313
And there's a hacker with the username "fela"
1414
When I go to the hacker page for "fela"
1515
Then I should not see "Send fela a message"
16+
Scenario: I can see messages sent to me
17+
Given I'm logged in as "steve"
18+
And I send a message to "fela" that says "Hello, fela!"
19+
And I log out
20+
When I log in as "fela"
21+
And I go to my messages page
22+
Then I should see "Hello, fela!"
23+
And I should see "From: steve"

features/step_definitions/common_steps.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def login hacker
1515
visit "/logout"
1616
end
1717

18+
Given /^I log out$/ do
19+
visit "/logout"
20+
end
21+
22+
When /^I log in as "([^"]*)"$/ do |username|
23+
hacker = Factory(:hacker, :username => username)
24+
login hacker
25+
end
26+
27+
1828
Given /^I'm logged in$/ do
1929
password = "foobar"
2030
hacker = Factory(:hacker,:password => password, :password_confirmation => password)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Given /^I send a message to "([^"]*)" that says "([^"]*)"$/ do |recipient, body|
2+
Factory(:message, :recipient => recipient, :body => body)
3+
end
4+

features/support/paths.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def path_to(page_name)
3838
"/"
3939
when /the hacker page for "(.*)"/
4040
"/hackers/#{$1}"
41+
when /my messages page/
42+
"/messages"
4143

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

views/messages/index.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%ul
2+
- @messages.each do |message|
3+
%li From: #{message.sender}
4+
%li Message: #{message.body}

0 commit comments

Comments
 (0)