-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
class MicropostsController < ApplicationController | ||
before_filter :authenticate | ||
before_filter :authorized_user, :only => :destroy | ||
|
||
def create | ||
@micropost = current_user.microposts.build(params[:micropost]) | ||
if @micropost.save | ||
redirect_to root_path, :flash => { :success => "Micropost created!" } | ||
else | ||
@feed_items = [] | ||
render 'pages/home' | ||
end | ||
end | ||
|
||
def destroy | ||
@micropost.destroy | ||
redirect_to root_path, :flash => { :success => "Micropost deleted!" } | ||
end | ||
|
||
private | ||
|
||
def authorized_user | ||
@micropost = Micropost.find(params[:id]) | ||
redirect_to root_path unless current_user?(@micropost.user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if @feed_items.any? %> | ||
<table class="microposts" summary="Status feed"> | ||
<%= render :partial => 'shared/feed_item', :collection => @feed_items %> | ||
</table> | ||
<%= will_paginate @feed_items %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<tr> | ||
<td class="gravatar"> | ||
<%= link_to gravatar_for(feed_item.user), feed_item.user %> | ||
</td> | ||
<td class="micropost"> | ||
<span class="user"> | ||
<%= link_to feed_item.user.name, feed_item.user %> | ||
</span> | ||
<span class="content"><%= feed_item.content %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(feed_item.created_at) %> ago. | ||
</span> | ||
</td> | ||
<% if current_user?(feed_item.user) %> | ||
<td> | ||
<%= link_to "delete", feed_item, :method => :delete, | ||
:confirm => "You sure?", | ||
:title => feed_item.content %> | ||
</td> | ||
<% end %> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
describe "Microposts" do | ||
|
||
before(:each) do | ||
user = Factory(:user) | ||
visit signin_path | ||
fill_in :email, :with => user.email | ||
fill_in :password, :with => user.password | ||
click_button | ||
end | ||
|
||
describe "creation" do | ||
|
||
describe "failure" do | ||
it "should not make a new micropost" do | ||
lambda do | ||
visit root_path | ||
fill_in :micropost_content, :with => "" | ||
click_button | ||
response.should render_template('pages/home') | ||
response.should have_selector('div#error_explanation') | ||
end.should_not change(Micropost, :count) | ||
end | ||
end | ||
|
||
describe "success" do | ||
it "should make a new micropost" do | ||
content = "Lorem ipsum dolor sit amet" | ||
lambda do | ||
visit root_path | ||
fill_in :micropost_content, :with => content | ||
click_button | ||
response.should have_selector('span.content', :content => content) | ||
end.should change(Micropost, :count).by(1) | ||
end | ||
end | ||
end | ||
end |