forked from RiverGlide/sample_app_2nd_ed
-
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
29 changed files
with
374 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
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,27 @@ | ||
class MicropostsController < ApplicationController | ||
before_filter :signed_in_user | ||
before_filter :correct_user, only: :destroy | ||
|
||
def create | ||
@micropost = current_user.microposts.build(params[:micropost]) | ||
if @micropost.save | ||
flash[:success] = "Micropost created!" | ||
redirect_to root_path | ||
else | ||
@feed_items = [] | ||
render 'static_pages/home' | ||
end | ||
end | ||
|
||
def destroy | ||
@micropost.destroy | ||
redirect_back_or root_path | ||
end | ||
|
||
private | ||
|
||
def correct_user | ||
@micropost = current_user.microposts.find_by_id(params[:id]) | ||
redirect_to root_path if @micropost.nil? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Micropost < ActiveRecord::Base | ||
attr_accessible :content | ||
belongs_to :user | ||
|
||
validates :content, presence: true, length: { maximum: 140 } | ||
validates :user_id, presence: true | ||
|
||
default_scope order: 'microposts.created_at DESC' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<li> | ||
<span class="content"><%= micropost.content %></span> | ||
<span class="timestamp"> | ||
Posted <%= time_ago_in_words(micropost.created_at) %> ago. | ||
</span> | ||
<% if current_user?(micropost.user) %> | ||
<%= link_to "delete", micropost, method: :delete, | ||
confirm: "You sure?", | ||
title: micropost.content %> | ||
<% end %> | ||
</li> |
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,12 +1,12 @@ | ||
<% if @user.errors.any? %> | ||
<% if object.errors.any? %> | ||
<div id="error_explanation"> | ||
<div class="alert alert-error"> | ||
The form contains <%= pluralize(@user.errors.count, "error") %>. | ||
The form contains <%= pluralize(object.errors.count, "error") %>. | ||
</div> | ||
<ul> | ||
<% @user.errors.full_messages.each do |msg| %> | ||
<% object.errors.full_messages.each do |msg| %> | ||
<li>* <%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if @feed_items.any? %> | ||
<ol class="microposts"> | ||
<%= render partial: 'shared/feed_item', collection: @feed_items %> | ||
</ol> | ||
<%= 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,15 @@ | ||
<li id="<%= feed_item.id %>"> | ||
<%= link_to gravatar_for(feed_item.user), feed_item.user %> | ||
<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> | ||
<% if current_user?(feed_item.user) %> | ||
<%= link_to "delete", feed_item, method: :delete, | ||
confirm: "You sure?", | ||
title: feed_item.content %> | ||
<% end %> | ||
</li> |
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,7 @@ | ||
<%= form_for(@micropost) do |f| %> | ||
<%= render 'shared/error_messages', object: f.object %> | ||
<div class="field"> | ||
<%= f.text_area :content, placeholder: "Compose new micropost..." %> | ||
</div> | ||
<%= f.submit "Post", class: "btn btn-large btn-primary" %> | ||
<% 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,12 @@ | ||
<a href="<%= user_path(current_user) %>"> | ||
<%= gravatar_for current_user, size: 52 %> | ||
</a> | ||
<h1> | ||
<%= current_user.name %> | ||
</h1> | ||
<span> | ||
<%= link_to "view my profile", current_user %> | ||
</span> | ||
<span> | ||
<%= pluralize(current_user.microposts.count, "micropost") %> | ||
</span> |
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,13 +1,31 @@ | ||
<div class="center hero-unit"> | ||
<h1>Welcome to the Sample App</h1> | ||
<% if signed_in? %> | ||
<div class="row"> | ||
<aside class="span4"> | ||
<section> | ||
<%= render 'shared/user_info' %> | ||
</section> | ||
<section> | ||
<%= render 'shared/micropost_form' %> | ||
</section> | ||
</aside> | ||
<div class="span8"> | ||
<h3>Micropost Feed</h3> | ||
<%= render 'shared/feed' %> | ||
</div> | ||
</div> | ||
<% else %> | ||
<div class="center hero-unit"> | ||
<h1>Welcome to the Sample App</h1> | ||
|
||
<h2> | ||
This is the home page for the | ||
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | ||
sample application. | ||
</h2> | ||
<h2> | ||
This is the home page for the | ||
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | ||
sample application. | ||
</h2> | ||
|
||
<%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %> | ||
</div> | ||
<%= link_to "Sign up now!", signup_path, | ||
class: "btn btn-large btn-primary" %> | ||
</div> | ||
|
||
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %> | ||
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %> | ||
<% end %> |
Binary file not shown.
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,11 @@ | ||
class CreateMicroposts < ActiveRecord::Migration | ||
def change | ||
create_table :microposts do |t| | ||
t.string :content | ||
t.integer :user_id | ||
|
||
t.timestamps | ||
end | ||
add_index :microposts, [:user_id, :created_at] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,9 @@ | |
admin true | ||
end | ||
end | ||
|
||
factory :micropost do | ||
content "Lorem ipsum" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
|
||
describe Micropost do | ||
|
||
let(:user) { FactoryGirl.create(:user) } | ||
before { @micropost = user.microposts.build(content: "Lorem ipsum") } | ||
|
||
subject { @micropost } | ||
|
||
it { should respond_to(:content) } | ||
it { should respond_to(:user_id) } | ||
it { should respond_to(:user) } | ||
its(:user) { should == user } | ||
|
||
it { should be_valid } | ||
|
||
describe "when user_id is not present" do | ||
before { @micropost.user_id = nil } | ||
it { should_not be_valid } | ||
end | ||
|
||
describe "when user_id is not present" do | ||
before { @micropost.user_id = nil } | ||
it { should_not be_valid } | ||
end | ||
|
||
describe "with blank content" do | ||
before { @micropost.content = " " } | ||
it { should_not be_valid } | ||
end | ||
|
||
describe "with content that is too long" do | ||
before { @micropost.content = "a" * 141 } | ||
it { should_not be_valid } | ||
end | ||
end |
Oops, something went wrong.