Skip to content

Commit

Permalink
modify test
Browse files Browse the repository at this point in the history
  • Loading branch information
suisho committed Jun 20, 2012
1 parent 467f92f commit 2246e2b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 60 deletions.
4 changes: 4 additions & 0 deletions rails/app/controllers/application_controller.rb
Expand Up @@ -16,4 +16,8 @@ def current_user
@current_user = User.find_by_id( session[:user_id] )
end

def login?
return current_user ? true : false
end

end
58 changes: 17 additions & 41 deletions rails/app/controllers/copipes_controller.rb
Expand Up @@ -22,7 +22,7 @@ def show
end
end


def txt
@copipe = Copipe.find(params[:id])
render :layout => "empty"
Expand All @@ -47,23 +47,15 @@ def new
# POST /copipes.json
def create
@copipe = Copipe.new(params[:copipe])
@copipe.user_id = 0
if login? then
@copipe.user_id = session[:user_id]
else
@copipe.user_id = 0
end
respond_to do |format|
if @copipe.save
# タグ投稿
tags = params[:tags]
tags = tags.split(/[\s| ]/)
tags = tags.uniq
tags.each{|tag_name|
tag = Tag.find_or_create_by_name(tag_name)
CopipeTag.create({:copipe_id => @copipe.id, :tag_id => tag.id})
}
=begin
format.html {
redirect_to @copipe,
notice: 'Article was successfully created.'
}
=end
add_tags(@copipe.id, params[:tags])
format.html { redirect_to "/", notice: t(:create_complete)}
format.json { render json: @copipe, status: :created, location: @copipe }
else
Expand All @@ -72,33 +64,17 @@ def create
end
end
end
=begin
# PUT /copipes/1
# PUT /copipes/1.json
def update
@copipe = Copipe.find(params[:id])
respond_to do |format|
if @copipe.update_attributes(params[:copipe])
format.html { redirect_to @copipe, notice: 'Article was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @copipe.errors, status: :unprocessable_entity }
end
end
end
# DELETE /copipes/1
# DELETE /copipes/1.json

def destroy
@copipe = Copipe.find(params[:id])
@copipe.destroy
respond_to do |format|
format.html { redirect_to copipes_url }
format.json { head :no_content }
protected
def add_tags(copipe_id, tags)
unless tags
return
end
tags = tags.split(/[\s| ]/)
tags = tags.uniq
tags.each{|tag_name|
tag = Tag.find_or_create_by_name(tag_name)
CopipeTag.create({:copipe_id => copipe_id, :tag_id => tag.id})
}
end
=end
end
32 changes: 13 additions & 19 deletions rails/test/functional/copipes_controller_test.rb
Expand Up @@ -3,6 +3,7 @@
class CopipesControllerTest < ActionController::TestCase
setup do
@copipe = copipes(:one)
@tagstring = tags(:one).name + " "+ tags(:two).name
end

test "should get index" do
Expand All @@ -18,32 +19,25 @@ class CopipesControllerTest < ActionController::TestCase

test "should create copipe" do
assert_difference('Copipe.count') do
post :create, copipe: { body: @copipe.body, title: @copipe.title, user_id: @copipe.user_id }
post :create, copipe: { body: @copipe.body, title: @copipe.title }
end

assert_redirected_to copipe_path(assigns(:copipe))
assert_redirected_to :root
end

test "should show copipe" do
get :show, id: @copipe
assert_response :success
end
test "should create copipe with tags" do
assert_difference('Copipe.count') do
post :create,
copipe: { body: @copipe.body, title: @copipe.title},
tags: @tagstring
end

test "should get edit" do
get :edit, id: @copipe
assert_response :success
assert_redirected_to :root
end

test "should update copipe" do
put :update, id: @copipe, copipe: { body: @copipe.body, title: @copipe.title, user_id: @copipe.user_id }
assert_redirected_to copipe_path(assigns(:copipe))
test "should show copipe" do
get :show, id: @copipe
assert_response :success
end

test "should destroy copipe" do
assert_difference('Copipe.count', -1) do
delete :destroy, id: @copipe
end

assert_redirected_to copipes_path
end
end

0 comments on commit 2246e2b

Please sign in to comment.