diff options
Diffstat (limited to 'help/test/functional')
-rw-r--r-- | help/test/functional/tickets_controller_test.rb | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb index 6bdb6c7..bb17acc 100644 --- a/help/test/functional/tickets_controller_test.rb +++ b/help/test/functional/tickets_controller_test.rb @@ -2,7 +2,10 @@ require 'test_helper' class TicketsControllerTest < ActionController::TestCase - test "should get index" do + test "should get index if logged in" do + #todo: should redo this and actually authorize + user = User.last + session[:user_id] = user.id get :index assert_response :success assert_not_nil assigns(:tickets) @@ -28,6 +31,8 @@ class TicketsControllerTest < ActionController::TestCase assert_nil assigns(:ticket).created_by assert_equal 1, assigns(:ticket).comments.count + assigns(:ticket).destroy # destroys without checking permission. is that okay? + end @@ -48,17 +53,49 @@ class TicketsControllerTest < ActionController::TestCase assert_equal @current_user.email, ticket.email assert_equal 1, assigns(:ticket).comments.count + assigns(:ticket).destroy # ? end - test "add comment to ticket" do + test "add comment to unauthenticated ticket" do ticket = Ticket.last + ticket.created_by = nil # TODO: hacky, but this makes sure this ticket is an unauthenticated one + ticket.save +# comment_count = t.comments.count +# put :update, :id => t.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } +# assert_equal(comment_count + 1, assigns(:ticket).comments.count) + #assert_difference block isn't working assert_difference('Ticket.last.comments.count') do put :update, :id => ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } end assert_equal ticket, assigns(:ticket) + + test "add comment to authenticated ticket" do + + + params = {:title => "ticket test title", :comments_attributes => {"0" => {"body" =>"body of test ticket"}}} + + #todo: should redo this and actually authorize + user = User.last + session[:user_id] = user.id + + post :create, :ticket => params + t = assigns(:ticket) + + comment_count = t.comments.count + debugger + put :update, :id => t.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} } # this isn't working + assert_equal(comment_count + 1, t.comments.count) + + #comment_count = t.comments.count + # now log out: and retry + #session[:user_id] = nil + #put :update, :id => t.id, :ticket => {:comments_attributes => {"0" => {"body" =>"EVEN NEWER comment"}} } # should fail +# assert_equal(comment_count, t.comments.count) + #assert_difference block isn't working + t.destroy end end |