Skip to content
Browse files

nested resource at controller level.

  • Loading branch information...
1 parent 0d2095d commit b9ef18c0481091ed3ebaa7b6f32614662b646115 @ruseel committed Nov 21, 2012
Showing with 11 additions and 11 deletions.
  1. +2 −2 app/controllers/topics_controller.rb
  2. +9 −9 test/functional/topics_controller_test.rb
View
4 app/controllers/topics_controller.rb
@@ -39,7 +39,7 @@ def edit
def update
@topic = Topic.find(params[:id])
if @topic.update_attributes(params[:topic])
- redirect_to @topic, notice: 'Topic was successfuly updated.'
+ redirect_to [@board, @topic], notice: 'Topic was successfuly updated.'
else
render action: 'edit'
end
@@ -49,7 +49,7 @@ def destroy
@topic = Topic.find(params[:id])
@topic.destroy
- redirect_to topics_url
+ redirect_to board_topics_url(@board)
end
private
View
18 test/functional/topics_controller_test.rb
@@ -13,15 +13,15 @@ class TopicsControllerTest < ActionController::TestCase
end
test "should show" do
- get :show, id: @topic
+ get :show, id: @topic, board_id: @board
assert_response :success
assert_not_nil assigns(:topic)
assert_not_nil assigns(:comment)
assert_not_nil assigns(:comments)
end
test "should get new" do
- get :new
+ get :new, board_id: @board
assert_response :success
assert_not_nil assigns(:topic)
end
@@ -35,28 +35,28 @@ class TopicsControllerTest < ActionController::TestCase
end
test "should get edit" do
- get :edit, id: @topic
+ get :edit, id: @topic, board_id: @board
assert_response :success
end
test "should update topic" do
- put :update, id: @topic, topic: { body: @topic.body, subject: @topic.subject }
- assert_redirected_to topic_path(assigns(:topic))
+ put :update, id: @topic, topic: { body: @topic.body, subject: @topic.subject }, board_id: @board
+ assert_redirected_to board_topic_path(@board, assigns(:topic))
end
test "should get destroy" do
assert_difference('Topic.count', -1) do
- delete :destroy, id: @topic
+ delete :destroy, id: @topic, board_id: @board
end
- assert_redirected_to topics_path
+ assert_redirected_to board_topics_path(@board)
end
test "should handle reply" do
- post :create, topic: { subject: @topic.subject, body: @topic.body }
+ post :create, topic: { subject: @topic.subject, body: @topic.body }, board_id: @board
parent = assigns(:topic)
- post :create, topic: { subject: "reply-1", body: "reply-1" }, parent_id: parent.id
+ post :create, topic: { subject: "reply-1", body: "reply-1" }, parent_id: parent.id, board_id: @board
assert_equal parent.boardish.inc_at_depth(1), assigns(:topic).boardish
end
end

0 comments on commit b9ef18c

Please sign in to comment.
Something went wrong with that request. Please try again.