Skip to content

Commit

Permalink
Fix notes controller redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
maser committed May 21, 2015
1 parent 6e5c5fa commit bf45019
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ def create
proposal = Proposal.find(params[:id])
note = current_user.notes.new(proposal_id: proposal.id, :content => params[:note][:content])
note.save!
redirect_to proposal_path(proposal)
redirect_to admin_proposal_path(proposal)
end

def update
note = current_user.notes.where(proposal_id: params[:id]).first
note.content = params[:note][:content]
note.save!
redirect_to proposal_path(params[:id])
redirect_to admin_proposal_path(params[:id])
end
end
28 changes: 28 additions & 0 deletions test/functional/admin/notes_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'

class Admin::NotesControllerTest < ActionController::TestCase
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
end

test 'should create notes' do
sign_in users(:admin_user)

proposal = proposals(:one)
post :create, id: proposal.id, note: { content: 'some text' }
assert_response :redirect
assert_equal proposal.notes.size, 1
assert_equal proposal.notes.first.content, 'some text'
end

test 'should update notes' do
sign_in users(:admin_user)

proposal = proposals(:one)
proposal.notes.create! user_id: users(:admin_user).id, content: 'text'
put :update, id: proposal.id, note: { content: 'some text' }
assert_response :redirect
assert_equal proposal.notes.size, 1
assert_equal proposal.notes.first.content, 'some text'
end
end

0 comments on commit bf45019

Please sign in to comment.