Fixes functionals

[skip ci]
pull/312/head
Hagen Schink 11 years ago
parent d0ca65dbaf
commit c25bbee177
  1. 15
      spec/factories/journal/attachable_journal_factory.rb
  2. 3
      spec/factories/journal/wiki_content_journal_factory.rb
  3. 2
      spec/factories/journal/work_package_journal_factory.rb
  4. 6
      spec/factories/journal_factory.rb
  5. 3
      test/fixtures/custom_fields_types.yml
  6. 12
      test/fixtures/custom_values.yml
  7. 54
      test/functional/activities_controller_test.rb
  8. 11
      test/functional/attachments_controller_test.rb
  9. 118
      test/functional/issues_controller_test.rb
  10. 23
      test/functional/issues_controller_transaction_test.rb
  11. 38
      test/functional/journals_controller_test.rb
  12. 5
      test/functional/search_controller_test.rb
  13. 2
      test/functional/timelog_controller_test.rb
  14. 2
      test/functional/user_mailer_test.rb
  15. 60
      test/functional/wiki_controller_test.rb

@ -0,0 +1,15 @@
#-- copyright
# OpenProject is a project management system.
#
# Copyright (C) 2012-2013 the OpenProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
FactoryGirl.define do
factory :journal_attachable_journal, :class => Journal::AttachableJournal do
end
end

@ -10,6 +10,7 @@
#++ #++
FactoryGirl.define do FactoryGirl.define do
factory :journal_work_package_journal, :class => Journal::WorkPackageJournal do factory :journal_wiki_content_journal, :class => Journal::WikiContentJournal do
page_id 1
end end
end end

@ -10,6 +10,6 @@
#++ #++
FactoryGirl.define do FactoryGirl.define do
factory :journal_wiki_content_journal, :class => Journal::WikiContentJournal do factory :journal_work_package_journal, :class => Journal::WorkPackageJournal do
end end
end end

@ -15,12 +15,14 @@ FactoryGirl.define do
sequence(:version) {|n| n} sequence(:version) {|n| n}
factory :work_package_journal, class: Journal do factory :work_package_journal, class: Journal do
journaled_type "WorkPackageJournal" journable_type "WorkPackage"
activity_type "work_packages"
data FactoryGirl.build(:journal_work_package_journal) data FactoryGirl.build(:journal_work_package_journal)
end end
factory :wiki_content_journal, class: Journal do factory :wiki_content_journal, class: Journal do
journaled_type "WikiContentJournal" journable_type "WikiContent"
activity_type "wiki_edits"
data FactoryGirl.build(:journal_wiki_content_journal) data FactoryGirl.build(:journal_wiki_content_journal)
end end
end end

@ -17,3 +17,6 @@ custom_fields_types_005:
custom_fields_types_006: custom_fields_types_006:
custom_field_id: 6 custom_field_id: 6
type_id: 3 type_id: 3
custom_fields_types_007:
custom_field_id: 8
type_id: 1

@ -101,3 +101,15 @@ custom_values_017:
customized_id: 1 customized_id: 1
id: 17 id: 17
value: '2009-12-01' value: '2009-12-01'
custom_values_018:
customized_type: WorkPackage
custom_field_id: 1
customized_id: 1
id: 18
value: "Oracle"
custom_values_019:
customized_type: WorkPackage
custom_field_id: 8
customized_id: 3
id: 19
value: '2009-12-01'

@ -16,6 +16,28 @@ class ActivitiesControllerTest < ActionController::TestCase
fixtures :all fixtures :all
def test_project_index def test_project_index
project = Project.find(1)
issue = FactoryGirl.create :issue,
status_id: 2,
priority_id: 4,
author_id: 2,
start_date: 1.day.ago.to_date.to_s(:db),
due_date: 10.day.from_now.to_date.to_s(:db)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 3.days.ago.to_date.to_s(:db),
data: FactoryGirl.build(:journal_work_package_journal,
project_id: issue.project_id,
status_id: 1)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
notes: "Some notes with Redmine links: #2, r2.",
created_at: 1.days.ago.to_date.to_s(:db),
data: FactoryGirl.build(:journal_work_package_journal,
project_id: issue.project_id,
status_id: 2)
get :index, :id => 1, :with_subprojects => 0 get :index, :id => 1, :with_subprojects => 0
assert_response :success assert_response :success
assert_template 'index' assert_template 'index'
@ -34,6 +56,13 @@ class ActivitiesControllerTest < ActionController::TestCase
end end
def test_previous_project_index def test_previous_project_index
issue = Issue.find(1)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 3.days.ago.to_date.to_s(:db),
data: FactoryGirl.build(:journal_work_package_journal,
project_id: issue.project_id)
get :index, :id => 1, :from => 3.days.ago.to_date get :index, :id => 1, :from => 3.days.ago.to_date
assert_response :success assert_response :success
assert_template 'index' assert_template 'index'
@ -45,13 +74,20 @@ class ActivitiesControllerTest < ActionController::TestCase
:child => { :tag => "dt", :child => { :tag => "dt",
:attributes => { :class => /work_package/ }, :attributes => { :class => /work_package/ },
:child => { :tag => "a", :child => { :tag => "a",
:content => /#{ERB::Util.html_escape(Issue.find(1).subject)}/ :content => /#{ERB::Util.html_escape(issue.subject)}/
} }
} }
} }
end end
def test_global_index def test_global_index
issue = Issue.find(1)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 3.days.ago.to_date.to_s(:db),
data: FactoryGirl.build(:journal_work_package_journal,
project_id: issue.project_id)
get :index get :index
assert_response :success assert_response :success
assert_template 'index' assert_template 'index'
@ -63,13 +99,20 @@ class ActivitiesControllerTest < ActionController::TestCase
:child => { :tag => "dt", :child => { :tag => "dt",
:attributes => { :class => /work_package/ }, :attributes => { :class => /work_package/ },
:child => { :tag => "a", :child => { :tag => "a",
:content => /#{ERB::Util.html_escape(Issue.find(1).subject)}/ :content => /#{ERB::Util.html_escape(issue.subject)}/
} }
} }
} }
end end
def test_user_index def test_user_index
issue = Issue.find(1)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 3.days.ago.to_date.to_s(:db),
data: FactoryGirl.build(:journal_work_package_journal,
project_id: issue.project_id)
get :index, :user_id => 2 get :index, :user_id => 2
assert_response :success assert_response :success
assert_template 'index' assert_template 'index'
@ -88,6 +131,13 @@ class ActivitiesControllerTest < ActionController::TestCase
end end
def test_index_atom_feed def test_index_atom_feed
issue = Issue.find(11)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
version: 1,
data: FactoryGirl.build(:journal_work_package_journal,
project_id: issue.project_id,
subject: issue.subject)
get :index, :format => 'atom' get :index, :format => 'atom'
assert_response :success assert_response :success
assert_template 'common/feed' assert_template 'common/feed'

@ -105,17 +105,22 @@ class AttachmentsControllerTest < ActionController::TestCase
def test_destroy_issue_attachment def test_destroy_issue_attachment
issue = Issue.find(3) issue = Issue.find(3)
issue.recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference 'issue.attachments.count', -1 do assert_difference 'issue.attachments.count', -1 do
delete :destroy, :id => 1 delete :destroy, :id => 1
end end
# no referrer # no referrer
issue.reload
assert_redirected_to '/projects/ecookbook' assert_redirected_to '/projects/ecookbook'
assert_nil Attachment.find_by_id(1) assert_nil Attachment.find_by_id(1)
j = issue.journals.find(:first, :order => 'created_at DESC')
assert_equal ['attachments_1'], j.details.keys j = issue.journals.last
assert_equal 'error281.txt', j.details['attachments_1'].first
assert_equal [:attachments_1], j.details.keys
assert_equal 'error281.txt', j.details[:attachments_1].first
end end
def test_destroy_wiki_page_attachment def test_destroy_wiki_page_attachment

@ -315,10 +315,14 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_show_atom def test_show_atom
get :show, :id => 1, :format => 'atom' issue = Issue.find(2)
issue.recreate_initial_journal!
get :show, :id => 2, :format => 'atom'
assert_response :success assert_response :success
assert_template 'journals/index' assert_template 'journals/index'
assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/work_packages/2')) assert_match /http:\/\/test\.host\/work_packages\/2/, response.body
end end
def test_show_export_to_pdf def test_show_export_to_pdf
@ -635,14 +639,14 @@ class IssuesControllerTest < ActionController::TestCase
context "#update" do context "#update" do
should "ignore status change" do should "ignore status change" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
end end
assert_equal 1, Issue.find(1).status_id assert_equal 1, Issue.find(1).status_id
end end
should "ignore attributes changes" do should "ignore attributes changes" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
end end
issue = Issue.find(1) issue = Issue.find(1)
@ -662,21 +666,21 @@ class IssuesControllerTest < ActionController::TestCase
context "#update" do context "#update" do
should "accept authorized status" do should "accept authorized status" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
end end
assert_equal 3, Issue.find(1).status_id assert_equal 3, Issue.find(1).status_id
end end
should "ignore unauthorized status" do should "ignore unauthorized status" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
end end
assert_equal 1, Issue.find(1).status_id assert_equal 1, Issue.find(1).status_id
end end
should "accept authorized attributes changes" do should "accept authorized attributes changes" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
end end
issue = Issue.find(1) issue = Issue.find(1)
@ -684,7 +688,7 @@ class IssuesControllerTest < ActionController::TestCase
end end
should "ignore unauthorized attributes changes" do should "ignore unauthorized attributes changes" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
end end
issue = Issue.find(1) issue = Issue.find(1)
@ -698,21 +702,21 @@ class IssuesControllerTest < ActionController::TestCase
end end
should "accept authorized status" do should "accept authorized status" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
end end
assert_equal 3, Issue.find(1).status_id assert_equal 3, Issue.find(1).status_id
end end
should "ignore unauthorized status" do should "ignore unauthorized status" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
end end
assert_equal 1, Issue.find(1).status_id assert_equal 1, Issue.find(1).status_id
end end
should "accept authorized attributes changes" do should "accept authorized attributes changes" do
assert_difference 'WorkPackageJournal.count' do assert_difference 'Journal::WorkPackageJournal.count' do
put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
end end
issue = Issue.find(1) issue = Issue.find(1)
@ -793,19 +797,22 @@ class IssuesControllerTest < ActionController::TestCase
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
issue = Issue.find(1) issue = Issue.find(1)
issue.recreate_initial_journal!
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
old_subject = issue.subject old_subject = issue.subject
new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
assert_difference('WorkPackageJournal.count') do assert_difference('Journal::WorkPackageJournal.count') do
put :update, :id => 1, :issue => {:subject => new_subject, put :update, :id => 1, :issue => {:subject => new_subject,
:priority_id => '6', :priority_id => '6',
:category_id => '1' # no change :category_id => '1' # no change
} }
end end
assert issue.current_journal.changed_data.has_key? "subject" issue.reload
assert issue.current_journal.changed_data.has_key? "priority_id" assert issue.current_journal.changed_data.has_key? :subject
assert !issue.current_journal.changed_data.has_key?("category_id") assert issue.current_journal.changed_data.has_key? :priority_id
assert !issue.current_journal.changed_data.has_key?(:category_id)
assert_redirected_to work_package_path(1) assert_redirected_to work_package_path(1)
issue.reload issue.reload
@ -823,20 +830,23 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_custom_field_change def test_put_update_with_custom_field_change
@request.session[:user_id] = 2 @request.session[:user_id] = 2
issue = Issue.find(1) issue = Issue.find(1)
issue.recreate_initial_journal!
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
assert_difference('WorkPackageJournal.count') do assert_difference('Journal::WorkPackageJournal.count') do
put :update, :id => 1, :issue => {:subject => 'Custom field change', put :update, :id => 1, :issue => {:subject => 'Custom field change',
:priority_id => '6', :priority_id => '6',
:category_id => '1', # no change :category_id => '1', # no change
:custom_field_values => { '2' => 'New custom value' } :custom_field_values => { '2' => 'New custom value' }
} }
end end
assert issue.current_journal.changed_data.has_key? "subject" issue.reload
assert issue.current_journal.changed_data.has_key? "priority_id" assert issue.current_journal.changed_data.has_key? :subject
assert !issue.current_journal.changed_data.has_key?("category_id") assert issue.current_journal.changed_data.has_key? :priority_id
assert issue.current_journal.changed_data.has_key? "custom_values2" assert !issue.current_journal.changed_data.has_key?(:category_id)
assert issue.current_journal.changed_data.has_key? :custom_fields_2
assert_redirected_to work_package_path(1) assert_redirected_to work_package_path(1)
issue.reload issue.reload
@ -849,6 +859,8 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_status_and_assignee_change def test_put_update_with_status_and_assignee_change
issue = Issue.find(1) issue = Issue.find(1)
issue.recreate_initial_journal!
assert_equal 1, issue.status_id assert_equal 1, issue.status_id
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('TimeEntry.count', 0) do assert_difference('TimeEntry.count', 0) do
@ -861,7 +873,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_redirected_to work_package_path(1) assert_redirected_to work_package_path(1)
issue.reload issue.reload
assert_equal 2, issue.status_id assert_equal 2, issue.status_id
j = WorkPackageJournal.find(:first, :order => 'id DESC') j = Journal.find(:first, :order => 'id DESC')
assert_equal 'Assigned to dlopper', j.notes assert_equal 'Assigned to dlopper', j.notes
assert_equal 2, j.details.size assert_equal 2, j.details.size
@ -872,13 +884,17 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_put_update_with_note_only def test_put_update_with_note_only
issue = Issue.find(1)
issue.recreate_initial_journal!
notes = 'Note added by IssuesControllerTest#test_update_with_note_only' notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
# anonymous user # anonymous user
put :update, put :update,
:id => 1, :id => 1,
:notes => notes :notes => notes
assert_redirected_to work_package_path(1) assert_redirected_to work_package_path(1)
j = WorkPackageJournal.find(:first, :order => 'id DESC') issue.reload
j = Journal.find(:first, :order => 'id DESC')
assert_equal notes, j.notes assert_equal notes, j.notes
assert_equal 0, j.details.size assert_equal 0, j.details.size
assert_equal User.anonymous, j.user assert_equal User.anonymous, j.user
@ -888,6 +904,9 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_put_update_with_note_and_spent_time def test_put_update_with_note_and_spent_time
issue = Issue.find(1)
issue.recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
spent_hours_before = Issue.find(1).spent_hours spent_hours_before = Issue.find(1).spent_hours
assert_difference('TimeEntry.count') do assert_difference('TimeEntry.count') do
@ -898,9 +917,8 @@ class IssuesControllerTest < ActionController::TestCase
end end
assert_redirected_to work_package_path(1) assert_redirected_to work_package_path(1)
issue = Issue.find(1) issue.reload
j = Journal.find(:first, :order => 'id DESC')
j = WorkPackageJournal.find(:first, :order => 'id DESC')
assert_equal '2.5 hours added', j.notes assert_equal '2.5 hours added', j.notes
assert_equal 0, j.details.size assert_equal 0, j.details.size
@ -911,6 +929,9 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_put_update_with_attachment_only def test_put_update_with_attachment_only
issue = Issue.find(1)
issue.recreate_initial_journal!
Setting.host_name = 'mydomain.foo' Setting.host_name = 'mydomain.foo'
Setting.protocol = 'https' Setting.protocol = 'https'
@ -938,7 +959,7 @@ class IssuesControllerTest < ActionController::TestCase
# Delete all fixtured journals, a race condition can occur causing the wrong # Delete all fixtured journals, a race condition can occur causing the wrong
# journal to get fetched in the next find. # journal to get fetched in the next find.
WorkPackageJournal.delete_all Journal.delete_all
# Mock out the unsaved attachment # Mock out the unsaved attachment
Attachment.any_instance.stubs(:create).returns(Attachment.new) Attachment.any_instance.stubs(:create).returns(Attachment.new)
@ -955,9 +976,11 @@ class IssuesControllerTest < ActionController::TestCase
def test_put_update_with_no_change def test_put_update_with_no_change
issue = Issue.find(1) issue = Issue.find(1)
issue.recreate_initial_journal!
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
assert_no_difference('WorkPackageJournal.count') do assert_no_difference('Journal.count') do
put :update, put :update,
:id => 1, :id => 1,
:notes => '' :notes => ''
@ -973,6 +996,7 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
issue = Issue.find(1) issue = Issue.find(1)
issue.recreate_initial_journal!
old_subject = issue.subject old_subject = issue.subject
new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
@ -1003,7 +1027,7 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
assert_no_difference('WorkPackageJournal.count') do assert_no_difference('Journal::WorkPackageJournal.count') do
put :update, put :update,
:id => 1, :id => 1,
:notes => notes, :notes => notes,
@ -1021,7 +1045,7 @@ class IssuesControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
assert_no_difference('WorkPackageJournal.count') do assert_no_difference('Journal::WorkPackageJournal.count') do
put :update, put :update,
:id => 1, :id => 1,
:notes => notes, :notes => notes,
@ -1118,6 +1142,9 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_bulk_update def test_bulk_update
issue = Issue.find(1)
issue.recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
# update issues priority # update issues priority
put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
@ -1129,7 +1156,7 @@ class IssuesControllerTest < ActionController::TestCase
# check that the issues were updated # check that the issues were updated
assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
issue = Issue.find(1) issue.reload
journal = issue.journals.reorder('created_at DESC').first journal = issue.journals.reorder('created_at DESC').first
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
assert_equal 'Bulk editing', journal.notes assert_equal 'Bulk editing', journal.notes
@ -1156,6 +1183,9 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_bulk_update_on_different_projects def test_bulk_update_on_different_projects
issue = Issue.find(1)
issue.recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
# update issues priority # update issues priority
put :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', put :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
@ -1167,7 +1197,7 @@ class IssuesControllerTest < ActionController::TestCase
# check that the issues were updated # check that the issues were updated
assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
issue = Issue.find(1) issue.reload
journal = issue.journals.reorder('created_at DESC').first journal = issue.journals.reorder('created_at DESC').first
assert_equal '125', issue.custom_value_for(2).value assert_equal '125', issue.custom_value_for(2).value
assert_equal 'Bulk editing', journal.notes assert_equal 'Bulk editing', journal.notes
@ -1185,10 +1215,13 @@ class IssuesControllerTest < ActionController::TestCase
:assigned_to_id => '', :assigned_to_id => '',
:custom_field_values => {'2' => ''}} :custom_field_values => {'2' => ''}}
assert_response 403 assert_response 403
assert_not_equal "Bulk should fail", WorkPackageJournal.last.notes assert Journal::WorkPackageJournal.all.empty?
end end
def test_bulk_update_should_send_a_notification def test_bulk_update_should_send_a_notification
WorkPackage.find(1).recreate_initial_journal!
WorkPackage.find(2).recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
put(:bulk_update, put(:bulk_update,
@ -1233,6 +1266,9 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_bulk_update_custom_field def test_bulk_update_custom_field
issue = Issue.find(1)
issue.recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
# update issues priority # update issues priority
put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
@ -1242,12 +1278,12 @@ class IssuesControllerTest < ActionController::TestCase
assert_response 302 assert_response 302
issue = Issue.find(1) issue.reload
journal = issue.journals.last journal = issue.journals.last
assert_equal '777', issue.custom_value_for(2).value assert_equal '777', issue.custom_value_for(2).value
assert_equal 1, journal.details.size assert_equal 1, journal.details.size
assert_equal '125', journal.old_value_for('custom_values2') assert_equal '125', journal.old_value_for(:custom_fields_2)
assert_equal '777', journal.new_value_for('custom_values2') assert_equal '777', journal.new_value_for(:custom_fields_2)
end end
def test_bulk_update_unassign def test_bulk_update_unassign
@ -1359,12 +1395,14 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_quote_issue def test_quote_issue
issue = WorkPackage.find(6)
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :quoted, :id => 6 get :quoted, :id => 6
assert_response :success assert_response :success
assert_template 'edit' assert_template 'edit'
assert_not_nil assigns(:issue) assert_not_nil assigns(:issue)
assert_equal Issue.find(6), assigns(:issue) assert_equal issue, assigns(:issue)
end end
def test_quote_issue_without_permission def test_quote_issue_without_permission
@ -1374,12 +1412,16 @@ class IssuesControllerTest < ActionController::TestCase
end end
def test_quote_note def test_quote_note
issue = Issue.find(6)
journal = FactoryGirl.create :work_package_journal, journable_id: issue.id
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :quoted, :id => 6, :journal_id => 4 get :quoted, :id => 6, :journal_id => journal.id
assert_response :success assert_response :success
assert_template 'edit' assert_template 'edit'
assert_not_nil assigns(:issue) assert_not_nil assigns(:issue)
assert_equal Issue.find(6), assigns(:issue) assert_equal Issue.find(6), assigns(:issue)
assert_equal Journal.find(4), assigns(:journal) assert_equal journal, assigns(:journal)
end end
end end

@ -56,6 +56,27 @@ class IssuesControllerTransactionTest < ActionController::TestCase
def test_put_update_stale_issue_prints_users_that_were_changing_it def test_put_update_stale_issue_prints_users_that_were_changing_it
issue = Issue.find(1) issue = Issue.find(1)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 4.days.ago.to_date.to_s(:db),
user_id: 1,
data: FactoryGirl.build(:journal_work_package_journal,
status_id: 1,
done_ratio: 40)
journal_from = FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 3.days.ago.to_date.to_s(:db),
user_id: 1,
notes: "Journal notes",
data: FactoryGirl.build(:journal_work_package_journal,
status_id: 2,
done_ratio: 30)
journal_to = FactoryGirl.create :work_package_journal,
journable_id: issue.id,
created_at: 1.days.ago.to_date.to_s(:db),
user_id: 2,
notes: "Some notes with Redmine links: #2, r2.",
data: FactoryGirl.build(:journal_work_package_journal)
@request.session[:user_id] = 3 @request.session[:user_id] = 3
put :update, put :update,
@ -72,7 +93,7 @@ class IssuesControllerTransactionTest < ActionController::TestCase
assert_template 'edit' assert_template 'edit'
assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
:content => /redMine Admin \(#{Journal.find(1).created_at.strftime("%d %b 00:00")}\), John Smith \(#{Journal.find(2).created_at.strftime("%d %b 00:00")}\)/ :content => /redMine Admin \(#{journal_from.created_at.strftime("%d %b 00:00")}\), John Smith \(#{journal_to.created_at.strftime("%d %b 00:00")}\)/
assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
:content => /Please reload the page/ :content => /Please reload the page/
end end

@ -27,29 +27,49 @@ class JournalsControllerTest < ActionController::TestCase
end end
def test_get_edit def test_get_edit
issue = Issue.find(1)
journal = FactoryGirl.create :work_package_journal,
journable_id: issue.id
identifier = "journal-#{journal.id}"
@request.session[:user_id] = 1 @request.session[:user_id] = 1
xhr :get, :edit, :id => 2 xhr :get, :edit, :id => journal.id
assert_response :success assert_response :success
assert_select_rjs :insert, :after, 'journal-2-notes' do assert_select_rjs :insert, :after, "#{identifier}-notes" do
assert_select 'form[id=journal-2-form]' assert_select "form[id=#{identifier}-form]"
assert_select 'textarea' assert_select 'textarea'
end end
end end
def test_post_edit def test_post_edit
issue = Issue.find(1)
journal = FactoryGirl.create :work_package_journal,
journable_id: issue.id,
data: FactoryGirl.build(:journal_work_package_journal)
identifier = "journal-#{journal.id}-notes"
@request.session[:user_id] = 1 @request.session[:user_id] = 1
xhr :post, :update, :id => 2, :notes => 'Updated notes' xhr :post, :update, :id => journal.id, :notes => 'Updated notes'
assert_response :success assert_response :success
assert_select_rjs :replace, 'journal-2-notes' assert_select_rjs :replace, identifier
assert_equal 'Updated notes', Journal.find(2).notes assert_equal 'Updated notes', Journal.find(journal.id).notes
end end
def test_post_edit_with_empty_notes def test_post_edit_with_empty_notes
issue = Issue.find(1)
FactoryGirl.create :work_package_journal,
journable_id: issue.id,
data: FactoryGirl.build(:journal_work_package_journal)
journal = FactoryGirl.create :work_package_journal,
journable_id: issue.id,
data: FactoryGirl.build(:journal_work_package_journal)
identifier = "change-#{journal.id}"
@request.session[:user_id] = 1 @request.session[:user_id] = 1
xhr :post, :update, :id => 2, :notes => '' xhr :post, :update, :id => journal.id, :notes => ''
assert_response :success assert_response :success
assert_select_rjs :remove, 'change-2' assert_select_rjs :remove, identifier
assert_nil Journal.find_by_id(2) assert_nil Journal.find_by_id(journal.id)
end end
def test_index def test_index

@ -53,13 +53,16 @@ class SearchControllerTest < ActionController::TestCase
end end
def test_search_issues def test_search_issues
Issue.find(5).recreate_initial_journal!
Issue.find(8).recreate_initial_journal!
get :index, :q => 'issue', :issues => 1 get :index, :q => 'issue', :issues => 1
assert_response :success assert_response :success
assert_template 'index' assert_template 'index'
assert assigns(:results).include?(Issue.find(8)) assert assigns(:results).include?(Issue.find(8))
assert assigns(:results).include?(Issue.find(5)) assert assigns(:results).include?(Issue.find(5))
assert_select "dt.work_package" do assert_select "dt.work_package-edit" do
assert_select "a", :text => /Closed/ assert_select "a", :text => /Closed/
end end
end end

@ -231,6 +231,8 @@ class TimelogControllerTest < ActionController::TestCase
end end
def test_index_atom_feed def test_index_atom_feed
TimeEntry.all.each(&:recreate_initial_journal!)
get :index, :project_id => 1, :format => 'atom' get :index, :project_id => 1, :format => 'atom'
assert_response :success assert_response :success
assert_equal 'application/atom+xml', @response.content_type assert_equal 'application/atom+xml', @response.content_type

@ -262,7 +262,7 @@ class UserMailerTest < ActionMailer::TestCase
mail = ActionMailer::Base.deliveries.last mail = ActionMailer::Base.deliveries.last
assert_not_nil mail assert_not_nil mail
assert_equal UserMailer.generate_message_id(journal), mail.message_id assert_equal UserMailer.generate_message_id(journal), mail.message_id
assert_match mail.references, UserMailer.generate_message_id(journal.journaled) assert_match mail.references, UserMailer.generate_message_id(journal.journable)
end end
def test_message_posted_message_id def test_message_posted_message_id

@ -104,25 +104,28 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_update_page def test_update_page
page = Wiki.find(1).pages.find_by_title('Another_page')
page.content.recreate_initial_journal!
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_no_difference 'WikiPage.count' do assert_no_difference 'WikiPage.count' do
assert_no_difference 'WikiContent.count' do assert_no_difference 'WikiContent.count' do
assert_difference 'WikiContentJournal.count' do assert_difference 'Journal.count' do
put :update, :project_id => 1, put :update, :project_id => 1,
:id => 'Another_page', :id => 'Another_page',
:content => { :content => {
:comments => "my comments", :comments => "my comments",
:text => "edited", :text => "edited",
:lock_version => 1 :lock_version => 2
} }
end end
end end
end end
assert_redirected_to '/projects/ecookbook/wiki/Another_page' assert_redirected_to '/projects/ecookbook/wiki/Another_page'
page = Wiki.find(1).pages.find_by_title('Another_page') page.reload
assert_equal "edited", page.content.text assert_equal "edited", page.content.text
assert_equal 2, page.content.version assert_equal page.content.journals.map(&:version).max, page.content.version
assert_equal "my comments", page.content.last_journal.notes assert_equal "my comments", page.content.last_journal.notes
end end
@ -130,7 +133,7 @@ class WikiControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_no_difference 'WikiPage.count' do assert_no_difference 'WikiPage.count' do
assert_no_difference 'WikiContent.count' do assert_no_difference 'WikiContent.count' do
assert_no_difference 'WikiContentJournal.count' do assert_no_difference 'Journal.count' do
put :update, :project_id => 1, put :update, :project_id => 1,
:id => 'Another_page', :id => 'Another_page',
:content => { :content => {
@ -150,6 +153,10 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_update_stale_page_should_not_raise_an_error def test_update_stale_page_should_not_raise_an_error
journal = FactoryGirl.create :wiki_content_journal,
journable_id: 2,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. Another page\n\n\nthis is a link to ticket: #2")
@request.session[:user_id] = 2 @request.session[:user_id] = 2
c = Wiki.find(1).find_page('Another_page').content c = Wiki.find(1).find_page('Another_page').content
c.text = 'Previous text' c.text = 'Previous text'
@ -158,7 +165,7 @@ class WikiControllerTest < ActionController::TestCase
assert_no_difference 'WikiPage.count' do assert_no_difference 'WikiPage.count' do
assert_no_difference 'WikiContent.count' do assert_no_difference 'WikiContent.count' do
assert_no_difference 'WikiContentJournal.count' do assert_no_difference 'Journal.count' do
put :update, :project_id => 1, put :update, :project_id => 1,
:id => 'Another_page', :id => 'Another_page',
:content => { :content => {
@ -182,7 +189,7 @@ class WikiControllerTest < ActionController::TestCase
c.reload c.reload
assert_equal 'Previous text', c.text assert_equal 'Previous text', c.text
assert_equal 2, c.version assert_equal journal.version, c.version
end end
def test_preview def test_preview
@ -208,6 +215,19 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_history def test_history
FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation")
FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...")
FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\nSome updated [[documentation]] here...")
get :history, :project_id => 1, :id => 'CookBook_documentation' get :history, :project_id => 1, :id => 'CookBook_documentation'
assert_response :success assert_response :success
assert_template 'history' assert_template 'history'
@ -217,6 +237,10 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_history_with_one_version def test_history_with_one_version
FactoryGirl.create :wiki_content_journal,
journable_id: 2,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. Another page\n\n\nthis is a link to ticket: #2")
get :history, :project_id => 1, :id => 'Another_page' get :history, :project_id => 1, :id => 'Another_page'
assert_response :success assert_response :success
assert_template 'history' assert_template 'history'
@ -226,7 +250,16 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_diff def test_diff
get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 journal_from = FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation")
journal_to = FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...")
get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => journal_to.version, :version_from => journal_from.version
assert_response :success assert_response :success
assert_template 'diff' assert_template 'diff'
assert_tag :tag => 'ins', :attributes => { :class => 'diffins'}, assert_tag :tag => 'ins', :attributes => { :class => 'diffins'},
@ -234,7 +267,16 @@ class WikiControllerTest < ActionController::TestCase
end end
def test_annotate def test_annotate
get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation")
journal_to = FactoryGirl.create :wiki_content_journal,
journable_id: 1,
data: FactoryGirl.build(:journal_wiki_content_journal,
text: "h1. CookBook documentation\n\n\nSome [[documentation]] here...")
get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => journal_to.version
assert_response :success assert_response :success
assert_template 'annotate' assert_template 'annotate'
# Line 1 # Line 1

Loading…
Cancel
Save