Skip to content

Commit

Permalink
글 등록.글 등록.
Browse files Browse the repository at this point in the history
  • Loading branch information
kakoo committed May 29, 2012
1 parent c54b2b0 commit a603693
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 17 deletions.
98 changes: 86 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/stylesheets/photos.css.scss
@@ -1,3 +1,3 @@
// Place all the styles related to the photos controller here.
// Place all the styles related to the Photos controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
78 changes: 78 additions & 0 deletions app/controllers/photos_controller.rb
@@ -1,5 +1,83 @@
class PhotosController < ApplicationController
# GET /photos
# GET /photos.json
def index
@photos = Photo.all

respond_to do |format|
format.html # index.html.erb
format.json { render :json => @photos }
end
end

# GET /photos/1
# GET /photos/1.json
def show
@photo = Photo.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render :json => @photo }
end
end

# GET /photos/new
# GET /photos/new.json
def new
@photo = Photo.new

respond_to do |format|
format.html # new.html.erb
format.json { render :json => @photo }
end
end

# GET /photos/1/edit
def edit
@photo = Photo.find(params[:id])
end

# POST /photos
# POST /photos.json
def create
@photo = Photo.new(params[:photo])

respond_to do |format|
if @photo.save
format.html { redirect_to @photo, :notice => 'Photo was successfully created.' }
format.json { render :json => @photo, :status => :created, :location => @photo }
else
format.html { render :action => "new" }
format.json { render :json => @photo.errors, :status => :unprocessable_entity }
end
end
end

# PUT /photos/1
# PUT /photos/1.json
def update
@photo = Photo.find(params[:id])

respond_to do |format|
if @photo.update_attributes(params[:photo])
format.html { redirect_to @photo, :notice => 'Photo was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @photo.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /photos/1
# DELETE /photos/1.json
def destroy
@photo = Photo.find(params[:id])
@photo.destroy

respond_to do |format|
format.html { redirect_to photos_url }
format.json { head :no_content }
end
end
end
26 changes: 25 additions & 1 deletion app/views/photos/index.html.erb
@@ -1 +1,25 @@
hello
<h1>Listing photos</h1>

<table>
<tr>
<th>Title</th>
<th>Name</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @photos.each do |photo| %>
<tr>
<td><%= photo.title %></td>
<td><%= photo.name %></td>
<td><%= link_to 'Show', photo %></td>
<td><%= link_to 'Edit', edit_photo_path(photo) %></td>
<td><%= link_to 'Destroy', photo, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Photo', new_photo_path %>
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
Chiyo::Application.routes.draw do
resources :photos

# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down
48 changes: 45 additions & 3 deletions test/functional/photos_controller_test.rb
@@ -1,7 +1,49 @@
require 'test_helper'

class PhotosControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
setup do
@photo = photos(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:photos)
end

test "should get new" do
get :new
assert_response :success
end

test "should create photo" do
assert_difference('Photo.count') do
post :create, :photo => { :name => @photo.name, :title => @photo.title }
end

assert_redirected_to photo_path(assigns(:photo))
end

test "should show photo" do
get :show, :id => @photo
assert_response :success
end

test "should get edit" do
get :edit, :id => @photo
assert_response :success
end

test "should update photo" do
put :update, :id => @photo, :photo => { :name => @photo.name, :title => @photo.title }
assert_redirected_to photo_path(assigns(:photo))
end

test "should destroy photo" do
assert_difference('Photo.count', -1) do
delete :destroy, :id => @photo
end

assert_redirected_to photos_path
end
end

0 comments on commit a603693

Please sign in to comment.