##// END OF EJS Templates
Speeds up rendering of the project list for users who belong to hundreds of projects....
Speeds up rendering of the project list for users who belong to hundreds of projects. git-svn-id: http://svn.redmine.org/redmine/trunk@16123 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r15678:bf5dade8df89
r15741:f8df935dcada
Show More
journal_test.rb
223 lines | 7.8 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 Jean-Philippe Lang
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688 #
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688 #
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Baptiste Barth
Use absolute paths in test/**/* requires for Ruby 1.9.2 compatibility. #4050...
r4395 require File.expand_path('../../test_helper', __FILE__)
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879
Eric Davis
Upgraded to Rails 2.3.4 (#3597)...
r2773 class JournalTest < ActiveSupport::TestCase
Jean-Baptiste Barth
Fixed some more test/unit/*_test.rb breaking when run alone (#12285)...
r10564 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details,
Toshi MARUYAMA
add missing fixtures to test/unit/journal_test.rb...
r12965 :issue_relations, :workflows,
Jean-Baptiste Barth
Fixed some more test/unit/*_test.rb breaking when run alone (#12285)...
r10564 :users, :members, :member_roles, :roles, :enabled_modules,
Toshi MARUYAMA
add missing fixture to test/unit/journal_test.rb...
r13547 :groups_users, :email_addresses,
Toshi MARUYAMA
add missing fixtures to test/unit/journal_test.rb...
r12965 :enumerations,
Toshi MARUYAMA
backport rails-4.1 r13296 to trunk...
r12964 :projects_trackers, :trackers, :custom_fields
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879
def setup
@journal = Journal.find 1
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 User.current = nil
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879 end
def test_journalized_is_an_issue
issue = @journal.issue
assert_kind_of Issue, issue
assert_equal 1, issue.id
end
def test_new_status
status = @journal.new_status
assert_not_nil status
assert_kind_of IssueStatus, status
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688 assert_equal 2, status.id
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879 end
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688
Eric Davis
Added observers to watch model objects for mail delivery instead of calling Mailer....
r2548 def test_create_should_send_email_notification
ActionMailer::Base.deliveries.clear
Jean-Philippe Lang
Replaces find(:first) calls....
r10701 issue = Issue.first
user = User.first
Eric Davis
Added observers to watch model objects for mail delivery instead of calling Mailer....
r2548 journal = issue.init_journal(user, issue)
assert journal.save
assert_equal 1, ActionMailer::Base.deliveries.size
end
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688
Jean-Philippe Lang
Private issue notes (#1554)....
r10336 def test_should_not_save_journal_with_blank_notes_and_no_details
journal = Journal.new(:journalized => Issue.first, :user => User.first)
assert_no_difference 'Journal.count' do
assert_equal false, journal.save
end
end
def test_create_should_not_split_non_private_notes
assert_difference 'Journal.count' do
assert_no_difference 'JournalDetail.count' do
journal = Journal.generate!(:notes => 'Notes')
end
end
assert_difference 'Journal.count' do
assert_difference 'JournalDetail.count' do
journal = Journal.generate!(:notes => 'Notes', :details => [JournalDetail.new])
end
end
assert_difference 'Journal.count' do
assert_difference 'JournalDetail.count' do
journal = Journal.generate!(:notes => '', :details => [JournalDetail.new])
end
end
end
def test_create_should_split_private_notes
assert_difference 'Journal.count' do
assert_no_difference 'JournalDetail.count' do
journal = Journal.generate!(:notes => 'Notes', :private_notes => true)
journal.reload
assert_equal true, journal.private_notes
assert_equal 'Notes', journal.notes
end
end
assert_difference 'Journal.count', 2 do
assert_difference 'JournalDetail.count' do
journal = Journal.generate!(:notes => 'Notes', :private_notes => true, :details => [JournalDetail.new])
journal.reload
assert_equal true, journal.private_notes
assert_equal 'Notes', journal.notes
assert_equal 0, journal.details.size
journal_with_changes = Journal.order('id DESC').offset(1).first
assert_equal false, journal_with_changes.private_notes
assert_nil journal_with_changes.notes
assert_equal 1, journal_with_changes.details.size
assert_equal journal.created_on, journal_with_changes.created_on
end
end
assert_difference 'Journal.count' do
assert_difference 'JournalDetail.count' do
journal = Journal.generate!(:notes => '', :private_notes => true, :details => [JournalDetail.new])
journal.reload
assert_equal false, journal.private_notes
assert_equal '', journal.notes
assert_equal 1, journal.details.size
end
end
end
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 def test_visible_scope_for_anonymous
# Anonymous user should see issues of public projects only
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 journals = Journal.visible(User.anonymous).to_a
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.any?
assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
# Anonymous user should not see issues without permission
Role.anonymous.remove_permission!(:view_issues)
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 journals = Journal.visible(User.anonymous).to_a
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.empty?
end
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 def test_visible_scope_for_user
user = User.find(9)
assert user.projects.empty?
# Non member user should see issues of public projects only
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 journals = Journal.visible(user).to_a
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.any?
assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
# Non member user should not see issues without permission
Role.non_member.remove_permission!(:view_issues)
user.reload
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 journals = Journal.visible(user).to_a
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.empty?
Toshi MARUYAMA
gender neutral source comment at test/unit/journal_test.rb...
r11763 # User should see issues of projects for which user has view_issues permissions only
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 Member.create!(:principal => user, :project_id => 1, :role_ids => [1])
user.reload
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 journals = Journal.visible(user).to_a
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.any?
assert_nil journals.detect {|journal| journal.issue.project_id != 1}
end
Toshi MARUYAMA
remove trailing white-spaces from unit journal test....
r5688
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 def test_visible_scope_for_admin
user = User.find(1)
user.members.each(&:destroy)
assert user.projects.empty?
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 journals = Journal.visible(user).to_a
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.any?
Toshi MARUYAMA
gender neutral source comment at test/unit/journal_test.rb...
r11763 # Admin should see issues on private projects that admin does not belong to
Jean-Philippe Lang
Adds a visible scope to the Journal model....
r5022 assert journals.detect {|journal| !journal.issue.project.is_public?}
end
Jean-Philippe Lang
Make sure that dates are stored as YYYY-MM-DD in journal details (#12713)....
r10887
Jean-Philippe Lang
Avoid lots of CustomField.find_by_id calls when displaying an issue history with custom fields (#15072)....
r11987 def test_preload_journals_details_custom_fields_should_set_custom_field_instance_variable
d = JournalDetail.new(:property => 'cf', :prop_key => '2')
journals = [Journal.new(:details => [d])]
d.expects(:instance_variable_set).with("@custom_field", CustomField.find(2)).once
Journal.preload_journals_details_custom_fields(journals)
end
def test_preload_journals_details_custom_fields_with_empty_set
assert_nothing_raised do
Journal.preload_journals_details_custom_fields([])
end
end
Jean-Philippe Lang
Make sure that dates are stored as YYYY-MM-DD in journal details (#12713)....
r10887 def test_details_should_normalize_dates
j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02'))
j.reload
assert_equal '2012-11-03', j.old_value
assert_equal '2013-01-02', j.value
end
def test_details_should_normalize_true_values
j = JournalDetail.create!(:old_value => true, :value => true)
j.reload
assert_equal '1', j.old_value
assert_equal '1', j.value
end
def test_details_should_normalize_false_values
j = JournalDetail.create!(:old_value => false, :value => false)
j.reload
assert_equal '0', j.old_value
assert_equal '0', j.value
end
Jean-Philippe Lang
Fixed that relations to issues that are not visible are displayed in the issue history (#1005)....
r11784
Jean-Philippe Lang
Avoid lots of CustomField.find_by_id calls when displaying an issue history with custom fields (#15072)....
r11987 def test_custom_field_should_return_custom_field_for_cf_detail
d = JournalDetail.new(:property => 'cf', :prop_key => '2')
assert_equal CustomField.find(2), d.custom_field
end
def test_custom_field_should_return_nil_for_non_cf_detail
d = JournalDetail.new(:property => 'subject')
Jean-Philippe Lang
Use assert_nil instead of assert_equal....
r15678 assert_nil d.custom_field
Jean-Philippe Lang
Avoid lots of CustomField.find_by_id calls when displaying an issue history with custom fields (#15072)....
r11987 end
Jean-Philippe Lang
Fixed that relations to issues that are not visible are displayed in the issue history (#1005)....
r11784 def test_visible_details_should_include_relations_to_visible_issues_only
issue = Issue.generate!
visible_issue = Issue.generate!
hidden_issue = Issue.generate!(:is_private => true)
Jean-Philippe Lang
Fixed that IssueRelation should not be responsible for calling Issue#init_journal (#18237)....
r13152
journal = Journal.new
journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'relates', :value => visible_issue.id)
journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'relates', :value => hidden_issue.id)
Jean-Philippe Lang
Fixed that relations to issues that are not visible are displayed in the issue history (#1005)....
r11784
visible_details = journal.visible_details(User.anonymous)
assert_equal 1, visible_details.size
Jean-Philippe Lang
Fixed that IssueRelation should not be responsible for calling Issue#init_journal (#18237)....
r13152 assert_equal visible_issue.id.to_s, visible_details.first.value.to_s
Jean-Philippe Lang
Fixed that relations to issues that are not visible are displayed in the issue history (#1005)....
r11784
visible_details = journal.visible_details(User.find(2))
assert_equal 2, visible_details.size
end
Jean-Philippe Lang
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
r879 end