-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
1 parent
1d664b8
commit f664a48
Showing
7 changed files
with
94 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class PostsController < ApplicationController | ||
# GET /posts | ||
# GET /posts.json | ||
def index | ||
@posts = Post.published | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @posts } | ||
end | ||
end | ||
|
||
# GET /posts/1 | ||
# GET /posts/1.json | ||
def show | ||
@post = Post.published.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @post } | ||
end | ||
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,13 @@ | ||
<h1>Seattle.rb Blog</h1> | ||
|
||
<% @posts.each do |post| %> | ||
<h2><%= link_to post.title, post %></h2> | ||
<h5><%= post.member.name %></h5> | ||
<p/> | ||
<p> | ||
<%= post.body.truncate(255) %> | ||
</p> | ||
<hr/> | ||
<% end %> | ||
|
||
<br /> |
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,8 @@ | ||
<h2><%= @post.title %></h2> | ||
<h5><%= @post.member.name %></h5> | ||
<p/> | ||
<p> | ||
<%= @post.body %> | ||
</p> | ||
|
||
<%= link_to 'Back', posts_path %> |
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ def test_create | |
:email => "[email protected]", | ||
:ruby_gems_id => "qrush"} | ||
end | ||
|
||
assert_redirected_to members_path | ||
get :index | ||
assert_response :success | ||
|
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,35 @@ | ||
require "minitest_helper" | ||
|
||
class PostsControllerTest < ActionController::TestCase | ||
|
||
def setup | ||
Member.create!(:name => "Big Bird") | ||
Post.all.each { |p| p.update_attribute(:member, Member.first) } | ||
@post = posts(:one) | ||
end | ||
|
||
def tear_down | ||
Member.destroy_all | ||
end | ||
|
||
def test_index | ||
get :index | ||
assert_response :success | ||
refute_nil assigns(:posts) | ||
|
||
Post.all.each do |p| | ||
assert_match p.title, @response.body | ||
assert_match p.body[0..10], @response.body | ||
assert_match p.member.name, @response.body | ||
end | ||
end | ||
|
||
def test_show | ||
get :show, id: @post | ||
assert_response :success | ||
assert_match @post.title, @response.body | ||
assert_match @post.body, @response.body | ||
assert_match @post.member.name, @response.body | ||
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,12 @@ | ||
# Read about fixtures at | ||
# http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | ||
|
||
one: | ||
title: MyString | ||
body: MyText | ||
published: true | ||
|
||
two: | ||
title: MyString | ||
body: MyText | ||
published: false |