diff test/functional/journals_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbce1fd3b1b7
children 622f24f53b42
line wrap: on
line diff
--- a/test/functional/journals_controller_test.rb	Wed Jun 27 14:54:18 2012 +0100
+++ b/test/functional/journals_controller_test.rb	Mon Jan 07 12:01:42 2013 +0000
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -39,6 +39,20 @@
     assert_equal 'application/atom+xml', @response.content_type
   end
 
+  def test_index_should_return_privates_notes_with_permission_only
+    journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
+    @request.session[:user_id] = 2
+
+    get :index, :project_id => 1
+    assert_response :success
+    assert_include journal, assigns(:journals)
+
+    Role.find(1).remove_permission! :view_private_notes
+    get :index, :project_id => 1
+    assert_response :success
+    assert_not_include journal, assigns(:journals)
+  end
+
   def test_diff
     get :diff, :id => 3, :detail_id => 4
     assert_response :success
@@ -54,47 +68,87 @@
 
   def test_reply_to_issue
     @request.session[:user_id] = 2
-    get :new, :id => 6
+    xhr :get, :new, :id => 6
     assert_response :success
-    assert_select_rjs :show, "update"
+    assert_template 'new'
+    assert_equal 'text/javascript', response.content_type
+    assert_include '> This is an issue', response.body
   end
 
   def test_reply_to_issue_without_permission
     @request.session[:user_id] = 7
-    get :new, :id => 6
+    xhr :get, :new, :id => 6
     assert_response 403
   end
 
   def test_reply_to_note
     @request.session[:user_id] = 2
-    get :new, :id => 6, :journal_id => 4
+    xhr :get, :new, :id => 6, :journal_id => 4
     assert_response :success
-    assert_select_rjs :show, "update"
+    assert_template 'new'
+    assert_equal 'text/javascript', response.content_type
+    assert_include '> A comment with a private version', response.body
   end
 
-  def test_get_edit
+  def test_reply_to_private_note_should_fail_without_permission
+    journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
+    @request.session[:user_id] = 2
+
+    xhr :get, :new, :id => 2, :journal_id => journal.id
+    assert_response :success
+    assert_template 'new'
+    assert_equal 'text/javascript', response.content_type
+    assert_include '> Privates notes', response.body
+
+    Role.find(1).remove_permission! :view_private_notes
+    xhr :get, :new, :id => 2, :journal_id => journal.id
+    assert_response 404
+  end
+
+  def test_edit_xhr
     @request.session[:user_id] = 1
     xhr :get, :edit, :id => 2
     assert_response :success
-    assert_select_rjs :insert, :after, 'journal-2-notes' do
-      assert_select 'form[id=journal-2-form]'
-      assert_select 'textarea'
-    end
+    assert_template 'edit'
+    assert_equal 'text/javascript', response.content_type
+    assert_include 'textarea', response.body
   end
 
-  def test_post_edit
+  def test_edit_private_note_should_fail_without_permission
+    journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
+    @request.session[:user_id] = 2
+    Role.find(1).add_permission! :edit_issue_notes
+
+    xhr :get, :edit, :id => journal.id
+    assert_response :success
+    assert_template 'edit'
+    assert_equal 'text/javascript', response.content_type
+    assert_include 'textarea', response.body
+
+    Role.find(1).remove_permission! :view_private_notes
+    xhr :get, :edit, :id => journal.id
+    assert_response 404
+  end
+
+  def test_update_xhr
     @request.session[:user_id] = 1
     xhr :post, :edit, :id => 2, :notes => 'Updated notes'
     assert_response :success
-    assert_select_rjs :replace, 'journal-2-notes'
+    assert_template 'update'
+    assert_equal 'text/javascript', response.content_type
     assert_equal 'Updated notes', Journal.find(2).notes
+    assert_include 'journal-2-notes', response.body
   end
 
-  def test_post_edit_with_empty_notes
+  def test_update_xhr_with_empty_notes_should_delete_the_journal
     @request.session[:user_id] = 1
-    xhr :post, :edit, :id => 2, :notes => ''
-    assert_response :success
-    assert_select_rjs :remove, 'change-2'
+    assert_difference 'Journal.count', -1 do
+      xhr :post, :edit, :id => 2, :notes => ''
+      assert_response :success
+      assert_template 'update'
+      assert_equal 'text/javascript', response.content_type
+    end
     assert_nil Journal.find_by_id(2)
+    assert_include 'change-2', response.body
   end
 end