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
bob
committed
Oct 7, 2012
1 parent
1e1f02f
commit ba48bd1
Showing
16 changed files
with
251 additions
and
0 deletions.
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
# Place all the behaviors and hooks related to the matching controller here. | |||
# All this logic will automatically be available in application.js. | |||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
// Place all the styles related to the Microposts controller here. | |||
// They will automatically be included in application.css. | |||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,83 @@ | |||
class MicropostsController < ApplicationController | |||
# GET /microposts | |||
# GET /microposts.json | |||
def index | |||
@microposts = Micropost.all | |||
|
|||
respond_to do |format| | |||
format.html # index.html.erb | |||
format.json { render json: @microposts } | |||
end | |||
end | |||
|
|||
# GET /microposts/1 | |||
# GET /microposts/1.json | |||
def show | |||
@micropost = Micropost.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
format.html # show.html.erb | |||
format.json { render json: @micropost } | |||
end | |||
end | |||
|
|||
# GET /microposts/new | |||
# GET /microposts/new.json | |||
def new | |||
@micropost = Micropost.new | |||
|
|||
respond_to do |format| | |||
format.html # new.html.erb | |||
format.json { render json: @micropost } | |||
end | |||
end | |||
|
|||
# GET /microposts/1/edit | |||
def edit | |||
@micropost = Micropost.find(params[:id]) | |||
end | |||
|
|||
# POST /microposts | |||
# POST /microposts.json | |||
def create | |||
@micropost = Micropost.new(params[:micropost]) | |||
|
|||
respond_to do |format| | |||
if @micropost.save | |||
format.html { redirect_to @micropost, notice: 'Micropost was successfully created.' } | |||
format.json { render json: @micropost, status: :created, location: @micropost } | |||
else | |||
format.html { render action: "new" } | |||
format.json { render json: @micropost.errors, status: :unprocessable_entity } | |||
end | |||
end | |||
end | |||
|
|||
# PUT /microposts/1 | |||
# PUT /microposts/1.json | |||
def update | |||
@micropost = Micropost.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
if @micropost.update_attributes(params[:micropost]) | |||
format.html { redirect_to @micropost, notice: 'Micropost was successfully updated.' } | |||
format.json { head :no_content } | |||
else | |||
format.html { render action: "edit" } | |||
format.json { render json: @micropost.errors, status: :unprocessable_entity } | |||
end | |||
end | |||
end | |||
|
|||
# DELETE /microposts/1 | |||
# DELETE /microposts/1.json | |||
def destroy | |||
@micropost = Micropost.find(params[:id]) | |||
@micropost.destroy | |||
|
|||
respond_to do |format| | |||
format.html { redirect_to microposts_url } | |||
format.json { head :no_content } | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module MicropostsHelper | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
class Micropost < ActiveRecord::Base | |||
attr_accessible :content, :user_id | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
<%= form_for(@micropost) do |f| %> | |||
<% if @micropost.errors.any? %> | |||
<div id="error_explanation"> | |||
<h2><%= pluralize(@micropost.errors.count, "error") %> prohibited this micropost from being saved:</h2> | |||
|
|||
<ul> | |||
<% @micropost.errors.full_messages.each do |msg| %> | |||
<li><%= msg %></li> | |||
<% end %> | |||
</ul> | |||
</div> | |||
<% end %> | |||
|
|||
<div class="field"> | |||
<%= f.label :content %><br /> | |||
<%= f.text_field :content %> | |||
</div> | |||
<div class="field"> | |||
<%= f.label :user_id %><br /> | |||
<%= f.number_field :user_id %> | |||
</div> | |||
<div class="actions"> | |||
<%= f.submit %> | |||
</div> | |||
<% 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
<h1>Editing micropost</h1> | |||
|
|||
<%= render 'form' %> | |||
<%= link_to 'Show', @micropost %> | | |||
<%= link_to 'Back', microposts_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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
<h1>Listing microposts</h1> | |||
|
|||
<table> | |||
<tr> | |||
<th>Content</th> | |||
<th>User</th> | |||
<th></th> | |||
<th></th> | |||
<th></th> | |||
</tr> | |||
|
|||
<% @microposts.each do |micropost| %> | |||
<tr> | |||
<td><%= micropost.content %></td> | |||
<td><%= micropost.user_id %></td> | |||
<td><%= link_to 'Show', micropost %></td> | |||
<td><%= link_to 'Edit', edit_micropost_path(micropost) %></td> | |||
<td><%= link_to 'Destroy', micropost, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |||
</tr> | |||
<% end %> | |||
</table> | |||
|
|||
<br /> | |||
|
|||
<%= link_to 'New Micropost', new_micropost_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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<h1>New micropost</h1> | |||
|
|||
<%= render 'form' %> | |||
<%= link_to 'Back', microposts_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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
<p id="notice"><%= notice %></p> | |||
|
|||
<p> | |||
<b>Content:</b> | |||
<%= @micropost.content %> | |||
</p> | |||
|
|||
<p> | |||
<b>User:</b> | |||
<%= @micropost.user_id %> | |||
</p> | |||
|
|||
|
|||
<%= link_to 'Edit', edit_micropost_path(@micropost) %> | | |||
<%= link_to 'Back', microposts_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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
class CreateMicroposts < ActiveRecord::Migration | |||
def change | |||
create_table :microposts do |t| | |||
t.string :content | |||
t.integer :user_id | |||
|
|||
t.timestamps | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | |||
|
|||
one: | |||
content: MyString | |||
user_id: 1 | |||
|
|||
two: | |||
content: MyString | |||
user_id: 1 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
require 'test_helper' | |||
|
|||
class MicropostsControllerTest < ActionController::TestCase | |||
setup do | |||
@micropost = microposts(:one) | |||
end | |||
|
|||
test "should get index" do | |||
get :index | |||
assert_response :success | |||
assert_not_nil assigns(:microposts) | |||
end | |||
|
|||
test "should get new" do | |||
get :new | |||
assert_response :success | |||
end | |||
|
|||
test "should create micropost" do | |||
assert_difference('Micropost.count') do | |||
post :create, micropost: { content: @micropost.content, user_id: @micropost.user_id } | |||
end | |||
|
|||
assert_redirected_to micropost_path(assigns(:micropost)) | |||
end | |||
|
|||
test "should show micropost" do | |||
get :show, id: @micropost | |||
assert_response :success | |||
end | |||
|
|||
test "should get edit" do | |||
get :edit, id: @micropost | |||
assert_response :success | |||
end | |||
|
|||
test "should update micropost" do | |||
put :update, id: @micropost, micropost: { content: @micropost.content, user_id: @micropost.user_id } | |||
assert_redirected_to micropost_path(assigns(:micropost)) | |||
end | |||
|
|||
test "should destroy micropost" do | |||
assert_difference('Micropost.count', -1) do | |||
delete :destroy, id: @micropost | |||
end | |||
|
|||
assert_redirected_to microposts_path | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
require 'test_helper' | |||
|
|||
class MicropostsHelperTest < ActionView::TestCase | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
require 'test_helper' | |||
|
|||
class MicropostTest < ActiveSupport::TestCase | |||
# test "the truth" do | |||
# assert true | |||
# end | |||
end |