##// 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:

r14856:cda9c63d9c21
r15741:f8df935dcada
Show More
issue_relation_test.rb
236 lines | 8.6 KiB | text/x-ruby | RubyLexer
/ test / unit / issue_relation_test.rb
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 Jean-Philippe Lang
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 #
# 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 test/unit/issue_relation_test.rb....
r6628 #
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 # 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 test/unit/issue_relation_test.rb....
r6628 #
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 # 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
Adds 'follows' relation (#1432)....
r3076
class IssueRelationTest < ActiveSupport::TestCase
Toshi MARUYAMA
add missing fixtures to test/unit/issue_relation_test.rb...
r10361 fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:issue_relations,
:enabled_modules,
:enumerations,
Toshi MARUYAMA
add missing fixture to test/unit/issue_relation_test.rb...
r11839 :trackers,
:projects_trackers
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076
Jean-Philippe Lang
Fixed: Circular loop when using relations and subtasks (#8794)....
r11411 include Redmine::I18n
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 def test_create
from = Issue.find(1)
to = Issue.find(2)
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Toshi MARUYAMA
code layout clean up of test_create at test/unit/issue_relation_test.rb...
r7479 relation = IssueRelation.new :issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_PRECEDES
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 assert relation.save
relation.reload
assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
assert_equal from, relation.issue_from
assert_equal to, relation.issue_to
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Set a default value for relation type....
r6057 def test_create_minimum
relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2)
assert relation.save
assert_equal IssueRelation::TYPE_RELATES, relation.relation_type
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 def test_follows_relation_should_be_reversed
from = Issue.find(1)
to = Issue.find(2)
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Toshi MARUYAMA
code layout clean up of test_follows_relation_should_be_reversed at test/unit/issue_relation_test.rb...
r7480 relation = IssueRelation.new :issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_FOLLOWS
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 assert relation.save
relation.reload
assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type
assert_equal to, relation.issue_from
assert_equal from, relation.issue_to
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Fixes 'follows' relation validation....
r3077 def test_follows_relation_should_not_be_reversed_if_validation_fails
from = Issue.find(1)
to = Issue.find(2)
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Toshi MARUYAMA
code layout clean up of test_follows_relation_should_not_be_reversed_if_validation_fails at test/unit/issue_relation_test.rb...
r7481 relation = IssueRelation.new :issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_FOLLOWS,
:delay => 'xx'
Jean-Philippe Lang
Fixes 'follows' relation validation....
r3077 assert !relation.save
assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type
assert_equal from, relation.issue_from
assert_equal to, relation.issue_to
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Adds issue relations to individual issue XML (#5305)....
r3615 def test_relation_type_for
from = Issue.find(1)
to = Issue.find(2)
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Toshi MARUYAMA
code layout clean up of test_relation_type_for at test/unit/issue_relation_test.rb...
r7482 relation = IssueRelation.new :issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_PRECEDES
Jean-Philippe Lang
Adds issue relations to individual issue XML (#5305)....
r3615 assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from)
assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to)
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Safer code in IssueRelation (#7018)....
r4353 def test_set_issue_to_dates_without_issue_to
Toshi MARUYAMA
code layout clean up of test_set_issue_to_dates_without_issue_to at test/unit/issue_relation_test.rb...
r7483 r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today),
:relation_type => IssueRelation::TYPE_PRECEDES,
:delay => 1)
Jean-Philippe Lang
Safer code in IssueRelation (#7018)....
r4353 assert_nil r.set_issue_to_dates
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Safer code in IssueRelation (#7018)....
r4353 def test_set_issue_to_dates_without_issues
r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1)
assert_nil r.set_issue_to_dates
end
Toshi MARUYAMA
remove trailing white-spaces from test/unit/issue_relation_test.rb....
r6628
Jean-Philippe Lang
Adds a test for issue circular dependency validation....
r4601 def test_validates_circular_dependency
IssueRelation.delete_all
Toshi MARUYAMA
code layout cleanup test/unit/issue_relation_test.rb...
r10362 assert IssueRelation.create!(
:issue_from => Issue.find(1), :issue_to => Issue.find(2),
:relation_type => IssueRelation::TYPE_PRECEDES
)
assert IssueRelation.create!(
:issue_from => Issue.find(2), :issue_to => Issue.find(3),
:relation_type => IssueRelation::TYPE_PRECEDES
)
r = IssueRelation.new(
:issue_from => Issue.find(3), :issue_to => Issue.find(1),
:relation_type => IssueRelation::TYPE_PRECEDES
)
Jean-Philippe Lang
Adds a test for issue circular dependency validation....
r4601 assert !r.save
Toshi MARUYAMA
not use assert_not_nil in Errors#[]...
r11840 assert_not_equal [], r.errors[:base]
Jean-Philippe Lang
Adds a test for issue circular dependency validation....
r4601 end
Jean-Baptiste Barth
Fixed circular dependencies possibly introduced when using reverse relations, for instance "blocked by" relations (#8616)....
r6004
Jean-Philippe Lang
Fixed: Circular loop when using relations and subtasks (#8794)....
r11411 def test_validates_circular_dependency_of_subtask
set_language_if_valid 'en'
issue1 = Issue.generate!
issue2 = Issue.generate!
IssueRelation.create!(
:issue_from => issue1, :issue_to => issue2,
:relation_type => IssueRelation::TYPE_PRECEDES
)
child = Issue.generate!(:parent_issue_id => issue2.id)
issue1.reload
child.reload
r = IssueRelation.new(
:issue_from => child, :issue_to => issue1,
:relation_type => IssueRelation::TYPE_PRECEDES
)
assert !r.save
assert_include 'This relation would create a circular dependency', r.errors.full_messages
end
Jean-Philippe Lang
Fixed that r11641 prevents precedes/follows relations between subtasks (#13586)....
r11462 def test_subtasks_should_allow_precedes_relation
parent = Issue.generate!
child1 = Issue.generate!(:parent_issue_id => parent.id)
child2 = Issue.generate!(:parent_issue_id => parent.id)
r = IssueRelation.new(
:issue_from => child1, :issue_to => child2,
:relation_type => IssueRelation::TYPE_PRECEDES
)
assert r.valid?
assert r.save
end
Jean-Baptiste Barth
Fixed circular dependencies possibly introduced when using reverse relations, for instance "blocked by" relations (#8616)....
r6004 def test_validates_circular_dependency_on_reverse_relations
IssueRelation.delete_all
Toshi MARUYAMA
code layout cleanup test/unit/issue_relation_test.rb...
r10362 assert IssueRelation.create!(
:issue_from => Issue.find(1), :issue_to => Issue.find(3),
:relation_type => IssueRelation::TYPE_BLOCKS
)
assert IssueRelation.create!(
:issue_from => Issue.find(1), :issue_to => Issue.find(2),
:relation_type => IssueRelation::TYPE_BLOCKED
)
r = IssueRelation.new(
:issue_from => Issue.find(2), :issue_to => Issue.find(1),
:relation_type => IssueRelation::TYPE_BLOCKED
)
Jean-Baptiste Barth
Fixed circular dependencies possibly introduced when using reverse relations, for instance "blocked by" relations (#8616)....
r6004 assert !r.save
Toshi MARUYAMA
not use assert_not_nil in Errors#[]...
r11840 assert_not_equal [], r.errors[:base]
Jean-Baptiste Barth
Fixed circular dependencies possibly introduced when using reverse relations, for instance "blocked by" relations (#8616)....
r6004 end
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655
Jean-Philippe Lang
Fixed that IssueRelation should not be responsible for calling Issue#init_journal (#18237)....
r13152 def test_create_with_initialized_journals_should_create_journals
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 from = Issue.find(1)
to = Issue.find(2)
from_journals = from.journals.size
to_journals = to.journals.size
relation = IssueRelation.new(:issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_PRECEDES)
Jean-Philippe Lang
Fixed that IssueRelation should not be responsible for calling Issue#init_journal (#18237)....
r13152 relation.init_journals User.find(1)
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 assert relation.save
from.reload
to.reload
relation.reload
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
assert_equal 'relation', from.journals.last.details.last.property
Jean-Philippe Lang
Store relation type instead of i18n key in journals (#15704)....
r12141 assert_equal 'precedes', from.journals.last.details.last.prop_key
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 assert_equal '2', from.journals.last.details.last.value
assert_nil from.journals.last.details.last.old_value
assert_equal 'relation', to.journals.last.details.last.property
Jean-Philippe Lang
Store relation type instead of i18n key in journals (#15704)....
r12141 assert_equal 'follows', to.journals.last.details.last.prop_key
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 assert_equal '1', to.journals.last.details.last.value
assert_nil to.journals.last.details.last.old_value
end
Jean-Philippe Lang
Fixed that IssueRelation should not be responsible for calling Issue#init_journal (#18237)....
r13152 def test_destroy_with_initialized_journals_should_create_journals
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 relation = IssueRelation.find(1)
from = relation.issue_from
to = relation.issue_to
from_journals = from.journals.size
to_journals = to.journals.size
Jean-Philippe Lang
Fixed that IssueRelation should not be responsible for calling Issue#init_journal (#18237)....
r13152 relation.init_journals User.find(1)
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 assert relation.destroy
from.reload
to.reload
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
assert_equal 'relation', from.journals.last.details.last.property
Jean-Philippe Lang
Store relation type instead of i18n key in journals (#15704)....
r12141 assert_equal 'blocks', from.journals.last.details.last.prop_key
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 assert_equal '9', from.journals.last.details.last.old_value
assert_nil from.journals.last.details.last.value
assert_equal 'relation', to.journals.last.details.last.property
Jean-Philippe Lang
Store relation type instead of i18n key in journals (#15704)....
r12141 assert_equal 'blocked', to.journals.last.details.last.prop_key
Toshi MARUYAMA
add journal after creating/deleting issue relation (#1005)...
r11655 assert_equal '10', to.journals.last.details.last.old_value
assert_nil to.journals.last.details.last.value
end
Jean-Philippe Lang
Overrides IssueRelation#to_s....
r13181
def test_to_s_should_return_the_relation_string
set_language_if_valid 'en'
relation = IssueRelation.find(1)
assert_equal "Blocks #9", relation.to_s(relation.issue_from)
assert_equal "Blocked by #10", relation.to_s(relation.issue_to)
end
def test_to_s_without_argument_should_return_the_relation_string_for_issue_from
set_language_if_valid 'en'
relation = IssueRelation.find(1)
assert_equal "Blocks #9", relation.to_s
end
def test_to_s_should_accept_a_block_as_custom_issue_formatting
set_language_if_valid 'en'
relation = IssueRelation.find(1)
assert_equal "Blocks Bug #9", relation.to_s {|issue| "#{issue.tracker} ##{issue.id}"}
end
Jean-Philippe Lang
Adds 'follows' relation (#1432)....
r3076 end