summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/changeset_test.rb47
-rw-r--r--test/unit/custom_field_test.rb14
-rw-r--r--test/unit/enabled_module_test.rb2
-rw-r--r--test/unit/group_test.rb19
-rw-r--r--test/unit/helpers/application_helper_test.rb47
-rw-r--r--test/unit/helpers/projects_helper_test.rb28
-rw-r--r--test/unit/initializers/patches_test.rb42
-rw-r--r--test/unit/issue_nested_set_test.rb2
-rw-r--r--test/unit/issue_priority_test.rb8
-rw-r--r--test/unit/issue_status_test.rb2
-rw-r--r--test/unit/issue_test.rb53
-rw-r--r--test/unit/journal_test.rb13
-rw-r--r--test/unit/lib/redmine/codeset_util_test.rb65
-rw-r--r--test/unit/lib/redmine/export/pdf_test.rb96
-rw-r--r--test/unit/lib/redmine/hook_test.rb1
-rw-r--r--test/unit/lib/redmine/i18n_test.rb88
-rw-r--r--test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb343
-rw-r--r--test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb149
-rw-r--r--test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb71
-rw-r--r--test/unit/lib/redmine/scm/adapters/git_adapter_test.rb1028
-rw-r--r--test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb781
-rw-r--r--test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb74
-rw-r--r--test/unit/lib/redmine/unified_diff_test.rb36
-rw-r--r--test/unit/lib/redmine/wiki_formatting/macros_test.rb14
-rw-r--r--test/unit/mail_handler_test.rb61
-rw-r--r--test/unit/mailer_test.rb1
-rw-r--r--test/unit/member_test.rb7
-rw-r--r--test/unit/principal_test.rb2
-rw-r--r--test/unit/project_copy_test.rb11
-rw-r--r--test/unit/project_nested_set_test.rb5
-rw-r--r--test/unit/project_test.rb10
-rw-r--r--test/unit/query_test.rb8
-rw-r--r--test/unit/repository_bazaar_test.rb76
-rw-r--r--test/unit/repository_cvs_test.rb8
-rw-r--r--test/unit/repository_darcs_test.rb3
-rw-r--r--test/unit/repository_filesystem_test.rb3
-rw-r--r--test/unit/repository_git_test.rb23
-rw-r--r--test/unit/repository_mercurial_test.rb25
-rw-r--r--test/unit/repository_subversion_test.rb8
-rw-r--r--test/unit/repository_test.rb7
-rw-r--r--test/unit/role_test.rb8
-rw-r--r--test/unit/tracker_test.rb2
-rw-r--r--test/unit/user_test.rb51
-rw-r--r--test/unit/version_test.rb2
-rw-r--r--test/unit/wiki_test.rb3
45 files changed, 1567 insertions, 1780 deletions
diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb
index 0467d59a1..eee7da81c 100644
--- a/test/unit/changeset_test.rb
+++ b/test/unit/changeset_test.rb
@@ -388,8 +388,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_comments_should_be_converted_to_utf8
proj = Project.find(3)
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
- str = "Texte encod\xe9 en ISO-8859-1."
- str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
+ str = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@@ -401,18 +400,15 @@ class ChangesetTest < ActiveSupport::TestCase
:scmid => '12345',
:comments => str)
assert( c.save )
- str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
- str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
+ str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1.".force_encoding("UTF-8")
assert_equal str_utf8, c.comments
end
def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
proj = Project.find(3)
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
- str1 = "Texte encod\xe9 en ISO-8859-1."
- str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
- str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
- str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
+ str1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("UTF-8")
+ str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@@ -431,10 +427,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
proj = Project.find(3)
- str = "test\xb5\xfetest\xb5\xfe"
- if str.respond_to?(:force_encoding)
- str.force_encoding('ASCII-8BIT')
- end
+ str = "test\xb5\xfetest\xb5\xfe".force_encoding('ASCII-8BIT')
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@@ -453,14 +446,12 @@ class ChangesetTest < ActiveSupport::TestCase
s1 = "\xC2\x80"
s2 = "\xc3\x82\xc2\x80"
s4 = s2.dup
- if s1.respond_to?(:force_encoding)
- s3 = s1.dup
- s1.force_encoding('ASCII-8BIT')
- s2.force_encoding('ASCII-8BIT')
- s3.force_encoding('ISO-8859-1')
- s4.force_encoding('UTF-8')
- assert_equal s3.encode('UTF-8'), s4
- end
+ s3 = s1.dup
+ s1.force_encoding('ASCII-8BIT')
+ s2.force_encoding('ASCII-8BIT')
+ s3.force_encoding('ISO-8859-1')
+ s4.force_encoding('UTF-8')
+ assert_equal s3.encode('UTF-8'), s4
proj = Project.find(3)
r = Repository::Bazaar.create!(
:project => proj,
@@ -478,10 +469,8 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_paths_should_be_replaced
proj = Project.find(3)
- str1 = "Texte encod\xe9 en ISO-8859-1"
- str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
- str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
- str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
+ str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
+ str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@@ -521,9 +510,7 @@ class ChangesetTest < ActiveSupport::TestCase
assert( c.save )
assert_equal "", c.comments
assert_equal nil, c.committer
- if c.comments.respond_to?(:force_encoding)
- assert_equal "UTF-8", c.comments.encoding.to_s
- end
+ assert_equal "UTF-8", c.comments.encoding.to_s
end
def test_comments_empty
@@ -542,10 +529,8 @@ class ChangesetTest < ActiveSupport::TestCase
assert( c.save )
assert_equal "", c.comments
assert_equal "", c.committer
- if c.comments.respond_to?(:force_encoding)
- assert_equal "UTF-8", c.comments.encoding.to_s
- assert_equal "UTF-8", c.committer.encoding.to_s
- end
+ assert_equal "UTF-8", c.comments.encoding.to_s
+ assert_equal "UTF-8", c.committer.encoding.to_s
end
def test_comments_should_accept_more_than_64k
diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb
index 7814061f1..56cdbcb72 100644
--- a/test/unit/custom_field_test.rb
+++ b/test/unit/custom_field_test.rb
@@ -95,14 +95,12 @@ class CustomFieldTest < ActiveSupport::TestCase
assert_equal ["One value", "And another one"], field.possible_values
end
- if "string".respond_to?(:encoding)
- def test_possible_values_stored_as_binary_should_be_utf8_encoded
- field = CustomField.find(11)
- assert_kind_of Array, field.possible_values
- assert field.possible_values.size > 0
- field.possible_values.each do |value|
- assert_equal "UTF-8", value.encoding.name
- end
+ def test_possible_values_stored_as_binary_should_be_utf8_encoded
+ field = CustomField.find(11)
+ assert_kind_of Array, field.possible_values
+ assert field.possible_values.size > 0
+ field.possible_values.each do |value|
+ assert_equal "UTF-8", value.encoding.name
end
end
diff --git a/test/unit/enabled_module_test.rb b/test/unit/enabled_module_test.rb
index b4c7acebc..918d53e48 100644
--- a/test/unit/enabled_module_test.rb
+++ b/test/unit/enabled_module_test.rb
@@ -22,7 +22,7 @@ class EnabledModuleTest < ActiveSupport::TestCase
def test_enabling_wiki_should_create_a_wiki
CustomField.delete_all
- project = Project.create!(:name => 'Project with wiki', :identifier => 'wikiproject')
+ project = Project.create!(:name => 'Project with wiki', :identifier => 'wikiproject', :enabled_module_names => [])
assert_nil project.wiki
project.enabled_module_names = ['wiki']
project.reload
diff --git a/test/unit/group_test.rb b/test/unit/group_test.rb
index fa5ded8f1..d2f09f9a7 100644
--- a/test/unit/group_test.rb
+++ b/test/unit/group_test.rb
@@ -52,8 +52,7 @@ class GroupTest < ActiveSupport::TestCase
def test_blank_name_error_message_fr
set_language_if_valid 'fr'
- str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
g = Group.new
assert !g.save
assert_include str, g.errors.full_messages
@@ -133,20 +132,4 @@ class GroupTest < ActiveSupport::TestCase
assert_equal nil, Issue.find(1).assigned_to_id
end
-
- def test_builtin_id_with_anonymous_user_should_return_anonymous_group
- assert_equal 13, Group.builtin_id(User.anonymous)
- end
-
- def test_builtin_id_with_anonymous_role_should_return_anonymous_group
- assert_equal 13, Group.builtin_id(Role.anonymous)
- end
-
- def test_builtin_id_with_user_should_return_non_member_group
- assert_equal 12, Group.builtin_id(User.find(1))
- end
-
- def test_builtin_id_with_non_member_role_should_return_non_member_group
- assert_equal 12, Group.builtin_id(Role.non_member)
- end
end
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 0bdcba359..6ce52ed72 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -35,10 +35,7 @@ class ApplicationHelperTest < ActionView::TestCase
def setup
super
set_tmp_attachments_directory
- @russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82"
- if @russian_test.respond_to?(:force_encoding)
- @russian_test.force_encoding('UTF-8')
- end
+ @russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82".force_encoding('UTF-8')
end
test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
@@ -99,16 +96,12 @@ class ApplicationHelperTest < ActionView::TestCase
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end
- if 'ruby'.respond_to?(:encoding)
- def test_auto_links_with_non_ascii_characters
- to_test = {
- "http://foo.bar/#{@russian_test}" =>
- %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
- }
- to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
- end
- else
- puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version'
+ def test_auto_links_with_non_ascii_characters
+ to_test = {
+ "http://foo.bar/#{@russian_test}" =>
+ %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
+ }
+ to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end
def test_auto_mailto
@@ -254,16 +247,12 @@ RAW
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end
- if 'ruby'.respond_to?(:encoding)
- def test_textile_external_links_with_non_ascii_characters
- to_test = {
- %|This is a "link":http://foo.bar/#{@russian_test}| =>
- %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
- }
- to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
- end
- else
- puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version'
+ def test_textile_external_links_with_non_ascii_characters
+ to_test = {
+ %|This is a "link":http://foo.bar/#{@russian_test}| =>
+ %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
+ }
+ to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end
def test_redmine_links
@@ -1336,13 +1325,8 @@ RAW
project = Project.find(1)
assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
link_to_project(project)
- assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
- link_to_project(project, :action => 'settings')
assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
link_to_project(project, {:only_path => false, :jump => 'blah'})
- result = link_to("eCookbook", "/projects/ecookbook/settings", :class => "project")
- assert_equal result,
- link_to_project(project, {:action => 'settings'}, :class => "project")
end
def test_link_to_project_settings
@@ -1433,7 +1417,7 @@ RAW
def test_raw_json_should_escape_closing_tags
s = raw_json(["<foo>bar</foo>"])
- assert_equal '["<foo>bar<\/foo>"]', s
+ assert_include '\/foo', s
end
def test_raw_json_should_be_html_safe
@@ -1508,8 +1492,7 @@ RAW
end
def test_truncate_single_line_non_ascii
- ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10)
assert_equal "#{ja} #{ja}...", result
assert !result.html_safe?
diff --git a/test/unit/helpers/projects_helper_test.rb b/test/unit/helpers/projects_helper_test.rb
index b4db5d42f..20f4283fe 100644
--- a/test/unit/helpers/projects_helper_test.rb
+++ b/test/unit/helpers/projects_helper_test.rb
@@ -42,23 +42,16 @@ class ProjectsHelperTest < ActionView::TestCase
def test_link_to_version_within_project
@project = Project.find(2)
User.current = User.find(1)
- assert_equal '<a href="/versions/5" title="07/01/2006">Alpha</a>', link_to_version(Version.find(5))
+ assert_equal '<a href="/versions/5">Alpha</a>', link_to_version(Version.find(5))
end
def test_link_to_version
User.current = User.find(1)
- assert_equal '<a href="/versions/5" title="07/01/2006">Alpha</a>', link_to_version(Version.find(5))
- end
-
- def test_link_to_version_without_effective_date
- User.current = User.find(1)
- version = Version.find(5)
- version.effective_date = nil
- assert_equal '<a href="/versions/5">Alpha</a>', link_to_version(version)
+ assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5))
end
def test_link_to_private_version
- assert_equal 'Alpha', link_to_version(Version.find(5))
+ assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5))
end
def test_link_to_version_invalid_version
@@ -71,20 +64,11 @@ class ProjectsHelperTest < ActionView::TestCase
end
def test_format_version_name
- assert_equal "0.1", format_version_name(Version.find(1))
- end
-
- def test_format_version_name_for_shared_version_within_project_should_not_display_project_name
- @project = Project.find(1)
- version = Version.find(1)
- version.sharing = 'system'
- assert_equal "0.1", format_version_name(version)
+ assert_equal "eCookbook - 0.1", format_version_name(Version.find(1))
end
- def test_format_version_name_for_shared_version_should_display_project_name
- version = Version.find(1)
- version.sharing = 'system'
- assert_equal "eCookbook - 0.1", format_version_name(version)
+ def test_format_version_name_for_system_version
+ assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7))
end
def test_version_options_for_select_with_no_versions
diff --git a/test/unit/initializers/patches_test.rb b/test/unit/initializers/patches_test.rb
index ac4b12b43..2b761a427 100644
--- a/test/unit/initializers/patches_test.rb
+++ b/test/unit/initializers/patches_test.rb
@@ -47,21 +47,19 @@ class PatchesTest < ActiveSupport::TestCase
end
# https://github.com/rails/rails/pull/14198/files
- if RUBY_VERSION >= "1.9"
- def test_indifferent_select
- hash = ActiveSupport::HashWithIndifferentAccess.new(@symbols).select { |_ ,v| v == 1 }
- assert_equal({ 'a' => 1 }, hash)
- assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
- Hash : ActiveSupport::HashWithIndifferentAccess),
- hash
- end
+ def test_indifferent_select
+ hash = ActiveSupport::HashWithIndifferentAccess.new(@symbols).select { |_ ,v| v == 1 }
+ assert_equal({ 'a' => 1 }, hash)
+ assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
+ Hash : ActiveSupport::HashWithIndifferentAccess),
+ hash
+ end
- def test_indifferent_select_bang
- indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@symbols)
- indifferent_strings.select! { |_, v| v == 1 }
- assert_equal({ 'a' => 1 }, indifferent_strings)
- assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
- end
+ def test_indifferent_select_bang
+ indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@symbols)
+ indifferent_strings.select! { |_, v| v == 1 }
+ assert_equal({ 'a' => 1 }, indifferent_strings)
+ assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
end
def test_indifferent_reject
@@ -77,15 +75,13 @@ class PatchesTest < ActiveSupport::TestCase
assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
end
- if RUBY_VERSION >= "1.9"
- def test_select
- assert_equal @keys, @ordered_hash.select { true }.map(&:first)
- new_ordered_hash = @ordered_hash.select { true }
- assert_equal @keys, new_ordered_hash.map(&:first)
- assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
- Hash : ActiveSupport::OrderedHash),
- new_ordered_hash
- end
+ def test_select
+ assert_equal @keys, @ordered_hash.select { true }.map(&:first)
+ new_ordered_hash = @ordered_hash.select { true }
+ assert_equal @keys, new_ordered_hash.map(&:first)
+ assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
+ Hash : ActiveSupport::OrderedHash),
+ new_ordered_hash
end
def test_reject
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb
index 5b540e588..d31acdee2 100644
--- a/test/unit/issue_nested_set_test.rb
+++ b/test/unit/issue_nested_set_test.rb
@@ -416,7 +416,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
c.reload
assert_equal 5, c.issues.count
- ic1, ic2, ic3, ic4, ic5 = c.issues.order('subject').all
+ ic1, ic2, ic3, ic4, ic5 = c.issues.order('subject').to_a
assert ic1.root?
assert_equal ic1, ic2.parent
assert_equal ic1, ic3.parent
diff --git a/test/unit/issue_priority_test.rb b/test/unit/issue_priority_test.rb
index f9c0c9793..7c4a38061 100644
--- a/test/unit/issue_priority_test.rb
+++ b/test/unit/issue_priority_test.rb
@@ -83,7 +83,7 @@ class IssuePriorityTest < ActiveSupport::TestCase
IssuePriority.clear_position_names
IssuePriority.compute_position_names
- assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
+ assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
def test_compute_position_names_without_default_priority_should_split_priorities
@@ -91,16 +91,16 @@ class IssuePriorityTest < ActiveSupport::TestCase
IssuePriority.update_all :is_default => false
IssuePriority.compute_position_names
- assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
+ assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
def test_adding_a_priority_should_update_position_names
priority = IssuePriority.create!(:name => 'New')
- assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
+ assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
def test_destroying_a_priority_should_update_position_names
IssuePriority.find_by_position_name('highest').destroy
- assert_equal %w(lowest default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
+ assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
end
diff --git a/test/unit/issue_status_test.rb b/test/unit/issue_status_test.rb
index f9855af53..387fa16a6 100644
--- a/test/unit/issue_status_test.rb
+++ b/test/unit/issue_status_test.rb
@@ -112,7 +112,7 @@ class IssueStatusTest < ActiveSupport::TestCase
end
def test_sorted_scope
- assert_equal IssueStatus.all.sort, IssueStatus.sorted.all
+ assert_equal IssueStatus.all.sort, IssueStatus.sorted.to_a
end
def test_named_scope
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 3454c71f5..2cf00f5ff 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -204,7 +204,7 @@ class IssueTest < ActiveSupport::TestCase
def test_visible_scope_for_anonymous
# Anonymous user should see issues of public projects only
- issues = Issue.visible(User.anonymous).all
+ issues = Issue.visible(User.anonymous).to_a
assert issues.any?
assert_nil issues.detect {|issue| !issue.project.is_public?}
assert_nil issues.detect {|issue| issue.is_private?}
@@ -214,7 +214,7 @@ class IssueTest < ActiveSupport::TestCase
def test_visible_scope_for_anonymous_without_view_issues_permissions
# Anonymous user should not see issues without permission
Role.anonymous.remove_permission!(:view_issues)
- issues = Issue.visible(User.anonymous).all
+ issues = Issue.visible(User.anonymous).to_a
assert issues.empty?
assert_visibility_match User.anonymous, issues
end
@@ -247,7 +247,7 @@ class IssueTest < ActiveSupport::TestCase
user = User.find(9)
assert user.projects.empty?
# Non member user should see issues of public projects only
- issues = Issue.visible(user).all
+ issues = Issue.visible(user).to_a
assert issues.any?
assert_nil issues.detect {|issue| !issue.project.is_public?}
assert_nil issues.detect {|issue| issue.is_private?}
@@ -259,7 +259,7 @@ class IssueTest < ActiveSupport::TestCase
Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member')
user = User.find(9)
- issues = Issue.visible(user).all
+ issues = Issue.visible(user).to_a
assert issues.any?
assert_nil issues.detect {|issue| issue.author != user}
assert_visibility_match user, issues
@@ -270,7 +270,7 @@ class IssueTest < ActiveSupport::TestCase
Role.non_member.remove_permission!(:view_issues)
user = User.find(9)
assert user.projects.empty?
- issues = Issue.visible(user).all
+ issues = Issue.visible(user).to_a
assert issues.empty?
assert_visibility_match user, issues
end
@@ -291,7 +291,7 @@ class IssueTest < ActiveSupport::TestCase
# User should see issues of projects for which user has view_issues permissions only
Role.non_member.remove_permission!(:view_issues)
Member.create!(:principal => user, :project_id => 3, :role_ids => [2])
- issues = Issue.visible(user).all
+ issues = Issue.visible(user).to_a
assert issues.any?
assert_nil issues.detect {|issue| issue.project_id != 3}
assert_nil issues.detect {|issue| issue.is_private?}
@@ -311,12 +311,12 @@ class IssueTest < ActiveSupport::TestCase
:is_private => true)
Role.find(2).update_attribute :issues_visibility, 'default'
- issues = Issue.visible(User.find(8)).all
+ issues = Issue.visible(User.find(8)).to_a
assert issues.any?
assert issues.include?(issue)
Role.find(2).update_attribute :issues_visibility, 'own'
- issues = Issue.visible(User.find(8)).all
+ issues = Issue.visible(User.find(8)).to_a
assert issues.any?
assert issues.include?(issue)
end
@@ -325,7 +325,7 @@ class IssueTest < ActiveSupport::TestCase
user = User.find(1)
user.members.each(&:destroy)
assert user.projects.empty?
- issues = Issue.visible(user).all
+ issues = Issue.visible(user).to_a
assert issues.any?
# Admin should see issues on private projects that admin does not belong to
assert issues.detect {|issue| !issue.project.is_public?}
@@ -336,7 +336,7 @@ class IssueTest < ActiveSupport::TestCase
def test_visible_scope_with_project
project = Project.find(1)
- issues = Issue.visible(User.find(2), :project => project).all
+ issues = Issue.visible(User.find(2), :project => project).to_a
projects = issues.collect(&:project).uniq
assert_equal 1, projects.size
assert_equal project, projects.first
@@ -344,7 +344,7 @@ class IssueTest < ActiveSupport::TestCase
def test_visible_scope_with_project_and_subprojects
project = Project.find(1)
- issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all
+ issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).to_a
projects = issues.collect(&:project).uniq
assert projects.size > 1
assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)}
@@ -370,13 +370,20 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 2, parent.descendants.visible(user).collect{|i| i}.size
end
+ def test_visible_scope_with_unsaved_user_should_not_raise_an_error
+ user = User.new
+ assert_nothing_raised do
+ Issue.visible(user).to_a
+ end
+ end
+
def test_open_scope
- issues = Issue.open.all
+ issues = Issue.open.to_a
assert_nil issues.detect(&:closed?)
end
def test_open_scope_with_arg
- issues = Issue.open(false).all
+ issues = Issue.open(false).to_a
assert_equal issues, issues.select(&:closed?)
end
@@ -1289,7 +1296,7 @@ class IssueTest < ActiveSupport::TestCase
end
test "#copy should not create a journal" do
- copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
+ copy = Issue.find(1).copy({:project_id => 3, :tracker_id => 2, :assigned_to_id => 3}, :link => false)
copy.save!
assert_equal 0, copy.reload.journals.size
end
@@ -1325,7 +1332,7 @@ class IssueTest < ActiveSupport::TestCase
test "#copy should create a journal with notes" do
date = Date.today
notes = "Notes added when copying"
- copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date)
+ copy = Issue.find(1).copy({:project_id => 3, :tracker_id => 2, :start_date => date}, :link => false)
copy.init_journal(User.current, notes)
copy.save!
@@ -1619,13 +1626,15 @@ class IssueTest < ActiveSupport::TestCase
issue2.reload
assert_equal Date.parse('2012-10-18'), issue2.start_date
- child = Issue.new(:parent_issue_id => issue2.id, :start_date => '2012-10-16',
- :project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Child', :author_id => 1)
- assert !child.valid?
- assert_include 'Start date cannot be earlier than 10/18/2012 because of preceding issues', child.errors.full_messages
- assert_equal Date.parse('2012-10-18'), child.soonest_start
- child.start_date = '2012-10-18'
- assert child.save
+ with_settings :date_format => '%m/%d/%Y' do
+ child = Issue.new(:parent_issue_id => issue2.id, :start_date => '2012-10-16',
+ :project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Child', :author_id => 1)
+ assert !child.valid?
+ assert_include 'Start date cannot be earlier than 10/18/2012 because of preceding issues', child.errors.full_messages
+ assert_equal Date.parse('2012-10-18'), child.soonest_start
+ child.start_date = '2012-10-18'
+ assert child.save
+ end
end
def test_setting_parent_to_a_dependent_issue_should_not_validate
diff --git a/test/unit/journal_test.rb b/test/unit/journal_test.rb
index ccfd2635f..36f494807 100644
--- a/test/unit/journal_test.rb
+++ b/test/unit/journal_test.rb
@@ -27,6 +27,7 @@ class JournalTest < ActiveSupport::TestCase
def setup
@journal = Journal.find 1
+ User.current = nil
end
def test_journalized_is_an_issue
@@ -119,12 +120,12 @@ class JournalTest < ActiveSupport::TestCase
def test_visible_scope_for_anonymous
# Anonymous user should see issues of public projects only
- journals = Journal.visible(User.anonymous).all
+ journals = Journal.visible(User.anonymous).to_a
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)
- journals = Journal.visible(User.anonymous).all
+ journals = Journal.visible(User.anonymous).to_a
assert journals.empty?
end
@@ -132,18 +133,18 @@ class JournalTest < ActiveSupport::TestCase
user = User.find(9)
assert user.projects.empty?
# Non member user should see issues of public projects only
- journals = Journal.visible(user).all
+ journals = Journal.visible(user).to_a
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
- journals = Journal.visible(user).all
+ journals = Journal.visible(user).to_a
assert journals.empty?
# User should see issues of projects for which user has view_issues permissions only
Member.create!(:principal => user, :project_id => 1, :role_ids => [1])
user.reload
- journals = Journal.visible(user).all
+ journals = Journal.visible(user).to_a
assert journals.any?
assert_nil journals.detect {|journal| journal.issue.project_id != 1}
end
@@ -152,7 +153,7 @@ class JournalTest < ActiveSupport::TestCase
user = User.find(1)
user.members.each(&:destroy)
assert user.projects.empty?
- journals = Journal.visible(user).all
+ journals = Journal.visible(user).to_a
assert journals.any?
# Admin should see issues on private projects that admin does not belong to
assert journals.detect {|journal| !journal.issue.project.is_public?}
diff --git a/test/unit/lib/redmine/codeset_util_test.rb b/test/unit/lib/redmine/codeset_util_test.rb
index 496ab5f09..0758ec485 100644
--- a/test/unit/lib/redmine/codeset_util_test.rb
+++ b/test/unit/lib/redmine/codeset_util_test.rb
@@ -21,14 +21,9 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_from_latin1
with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
- s1 = "Texte encod\xc3\xa9"
- s2 = "Texte encod\xe9"
- s3 = s2.dup
- if s1.respond_to?(:force_encoding)
- s1.force_encoding("UTF-8")
- s2.force_encoding("ASCII-8BIT")
- s3.force_encoding("UTF-8")
- end
+ s1 = "Texte encod\xc3\xa9".force_encoding("UTF-8")
+ s2 = "Texte encod\xe9".force_encoding("ASCII-8BIT")
+ s3 = s2.dup.force_encoding("UTF-8")
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
end
@@ -36,14 +31,9 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_from_euc_jp
with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
- s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
- s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
- s3 = s2.dup
- if s1.respond_to?(:force_encoding)
- s1.force_encoding("UTF-8")
- s2.force_encoding("ASCII-8BIT")
- s3.force_encoding("UTF-8")
- end
+ s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3".force_encoding("UTF-8")
+ s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3".force_encoding("ASCII-8BIT")
+ s3 = s2.dup.force_encoding("UTF-8")
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
end
@@ -51,14 +41,9 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_should_be_converted_all_latin1
with_settings :repositories_encodings => 'ISO-8859-1' do
- s1 = "\xc3\x82\xc2\x80"
- s2 = "\xC2\x80"
- s3 = s2.dup
- if s1.respond_to?(:force_encoding)
- s1.force_encoding("UTF-8")
- s2.force_encoding("ASCII-8BIT")
- s3.force_encoding("UTF-8")
- end
+ s1 = "\xc3\x82\xc2\x80".force_encoding("UTF-8")
+ s2 = "\xC2\x80".force_encoding("ASCII-8BIT")
+ s3 = s2.dup.force_encoding("UTF-8")
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
end
@@ -70,45 +55,33 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
end
def test_to_utf8_by_setting_returns_ascii_as_utf8
- s1 = "ASCII"
- s2 = s1.dup
- if s1.respond_to?(:force_encoding)
- s1.force_encoding("UTF-8")
- s2.force_encoding("ISO-8859-1")
- end
+ s1 = "ASCII".force_encoding("UTF-8")
+ s2 = s1.dup.force_encoding("ISO-8859-1")
str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, str1
assert_equal s1, str2
- if s1.respond_to?(:force_encoding)
- assert_equal "UTF-8", str1.encoding.to_s
- assert_equal "UTF-8", str2.encoding.to_s
- end
+ assert_equal "UTF-8", str1.encoding.to_s
+ assert_equal "UTF-8", str2.encoding.to_s
end
def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
with_settings :repositories_encodings => '' do
# s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
- s1 = "Texte encod\xe9 en ISO-8859-1."
- s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
+ s1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
- if str.respond_to?(:force_encoding)
- assert str.valid_encoding?
- assert_equal "UTF-8", str.encoding.to_s
- end
+ assert str.valid_encoding?
+ assert_equal "UTF-8", str.encoding.to_s
assert_equal "Texte encod? en ISO-8859-1.", str
end
end
def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
with_settings :repositories_encodings => 'ISO-2022-JP' do
- s1 = "test\xb5\xfetest\xb5\xfe"
- s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
+ s1 = "test\xb5\xfetest\xb5\xfe".force_encoding("ASCII-8BIT")
str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
- if str.respond_to?(:force_encoding)
- assert str.valid_encoding?
- assert_equal "UTF-8", str.encoding.to_s
- end
+ assert str.valid_encoding?
+ assert_equal "UTF-8", str.encoding.to_s
assert_equal "test??test??", str
end
end
diff --git a/test/unit/lib/redmine/export/pdf_test.rb b/test/unit/lib/redmine/export/pdf_test.rb
index a0821d62d..8af672660 100644
--- a/test/unit/lib/redmine/export/pdf_test.rb
+++ b/test/unit/lib/redmine/export/pdf_test.rb
@@ -27,11 +27,10 @@ class PdfTest < ActiveSupport::TestCase
end
def test_rdm_pdf_iconv_cannot_convert_ja_cp932
- encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b"
utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
- if utf8_txt_1.respond_to?(:force_encoding)
+ ["CP932", "SJIS"].each do |encoding|
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
@@ -41,88 +40,65 @@ class PdfTest < ActiveSupport::TestCase
assert_equal "ASCII-8BIT", txt_1.encoding.to_s
assert_equal "ASCII-8BIT", txt_2.encoding.to_s
assert_equal "ASCII-8BIT", txt_3.encoding.to_s
- elsif RUBY_PLATFORM == 'java'
- assert_equal "??",
- Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
- assert_equal "???",
- Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
- assert_equal "????",
- Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
- else
- assert_equal "???\x91\xd4",
- Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
- assert_equal "???\x91\xd4???",
- Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
- assert_equal "??????\x91\xd4???",
- Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
end
end
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en
- str1 = "Texte encod\xe9 en ISO-8859-1"
- str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
- str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
- str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
+ str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
+ str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, 'UTF-8')
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, 'UTF-8')
- if txt_1.respond_to?(:force_encoding)
- assert_equal "ASCII-8BIT", txt_1.encoding.to_s
- assert_equal "ASCII-8BIT", txt_2.encoding.to_s
- end
+ assert_equal "ASCII-8BIT", txt_1.encoding.to_s
+ assert_equal "ASCII-8BIT", txt_2.encoding.to_s
assert_equal "Texte encod? en ISO-8859-1", txt_1
assert_equal "?a?b?c?d?e test", txt_2
end
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
- str1 = "Texte encod\xe9 en ISO-8859-1"
- str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
- str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
- str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
+ str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
+ str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding)
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding)
- if txt_1.respond_to?(:force_encoding)
- assert_equal "ASCII-8BIT", txt_1.encoding.to_s
- assert_equal "ASCII-8BIT", txt_2.encoding.to_s
- end
+ assert_equal "ASCII-8BIT", txt_1.encoding.to_s
+ assert_equal "ASCII-8BIT", txt_2.encoding.to_s
assert_equal "Texte encod? en ISO-8859-1", txt_1
assert_equal "?a?b?c?d?e test", txt_2
end
def test_attach
- set_fixtures_attachments_directory
+ ["CP932", "SJIS"].each do |encoding|
+ set_fixtures_attachments_directory
- str2 = "\x83e\x83X\x83g"
- str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
- encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
+ str2 = "\x83e\x83X\x83g".force_encoding("ASCII-8BIT")
- a1 = Attachment.find(17)
- a2 = Attachment.find(19)
+ a1 = Attachment.find(17)
+ a2 = Attachment.find(19)
+ User.current = User.find(1)
+ assert a1.readable?
+ assert a1.visible?
+ assert a2.readable?
+ assert a2.visible?
- User.current = User.find(1)
- assert a1.readable?
- assert a1.visible?
- assert a2.readable?
- assert a2.visible?
+ aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
+ assert_not_nil aa1
+ assert_equal 17, aa1.id
- aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
- assert_not_nil aa1
- assert_equal 17, aa1.id
- aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
- assert_not_nil aa2
- assert_equal 19, aa2.id
+ aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
+ assert_not_nil aa2
+ assert_equal 19, aa2.id
- User.current = nil
- assert a1.readable?
- assert (! a1.visible?)
- assert a2.readable?
- assert (! a2.visible?)
+ User.current = nil
+ assert a1.readable?
+ assert (! a1.visible?)
+ assert a2.readable?
+ assert (! a2.visible?)
+ aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
+ assert_equal nil, aa1
+ aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
+ assert_equal nil, aa2
- aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
- assert_equal nil, aa1
- aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
- assert_equal nil, aa2
-
- set_tmp_attachments_directory
+ set_tmp_attachments_directory
+ end
end
end
diff --git a/test/unit/lib/redmine/hook_test.rb b/test/unit/lib/redmine/hook_test.rb
index 1352d251e..af9ca9ded 100644
--- a/test/unit/lib/redmine/hook_test.rb
+++ b/test/unit/lib/redmine/hook_test.rb
@@ -66,6 +66,7 @@ class Redmine::Hook::ManagerTest < ActionView::TestCase
def setup
@hook_module = Redmine::Hook
+ @hook_module.clear_listeners
end
def teardown
diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb
index 6d3561486..a267fd7b9 100644
--- a/test/unit/lib/redmine/i18n_test.rb
+++ b/test/unit/lib/redmine/i18n_test.rb
@@ -32,47 +32,50 @@ class Redmine::I18nTest < ActiveSupport::TestCase
def test_date_format_default
set_language_if_valid 'en'
today = Date.today
- Setting.date_format = ''
- assert_equal I18n.l(today), format_date(today)
+ with_settings :date_format => '' do
+ assert_equal I18n.l(today), format_date(today)
+ end
end
def test_date_format
set_language_if_valid 'en'
today = Date.today
- Setting.date_format = '%d %m %Y'
- assert_equal today.strftime('%d %m %Y'), format_date(today)
+ with_settings :date_format => '%d %m %Y' do
+ assert_equal today.strftime('%d %m %Y'), format_date(today)
+ end
end
def test_date_format_default_with_user_locale
set_language_if_valid 'es'
today = now = Time.parse('2011-02-20 14:00:00')
- Setting.date_format = '%d %B %Y'
- User.current.language = 'fr'
- s1 = "20 f\xc3\xa9vrier 2011"
- s1.force_encoding("UTF-8") if s1.respond_to?(:force_encoding)
- assert_equal s1, format_date(today)
- User.current.language = nil
- assert_equal '20 Febrero 2011', format_date(today)
+ with_settings :date_format => '%d %B %Y' do
+ User.current.language = 'fr'
+ s1 = "20 f\xc3\xa9vrier 2011".force_encoding("UTF-8")
+ assert_equal s1, format_date(today)
+ User.current.language = nil
+ assert_equal '20 Febrero 2011', format_date(today)
+ end
end
def test_date_and_time_for_each_language
- Setting.date_format = ''
- valid_languages.each do |lang|
- set_language_if_valid lang
- assert_nothing_raised "#{lang} failure" do
- format_date(Date.today)
- format_time(Time.now)
- format_time(Time.now, false)
- assert_not_equal 'default', ::I18n.l(Date.today, :format => :default),
- "date.formats.default missing in #{lang}"
- assert_not_equal 'time', ::I18n.l(Time.now, :format => :time),
- "time.formats.time missing in #{lang}"
+ with_settings :date_format => '' do
+ valid_languages.each do |lang|
+ set_language_if_valid lang
+ assert_nothing_raised "#{lang} failure" do
+ format_date(Date.today)
+ format_time(Time.now)
+ format_time(Time.now, false)
+ assert_not_equal 'default', ::I18n.l(Date.today, :format => :default),
+ "date.formats.default missing in #{lang}"
+ assert_not_equal 'time', ::I18n.l(Time.now, :format => :time),
+ "time.formats.time missing in #{lang}"
+ end
+ assert l('date.day_names').is_a?(Array)
+ assert_equal 7, l('date.day_names').size
+
+ assert l('date.month_names').is_a?(Array)
+ assert_equal 13, l('date.month_names').size
end
- assert l('date.day_names').is_a?(Array)
- assert_equal 7, l('date.day_names').size
-
- assert l('date.month_names').is_a?(Array)
- assert_equal 13, l('date.month_names').size
end
end
@@ -134,10 +137,10 @@ class Redmine::I18nTest < ActiveSupport::TestCase
def test_utc_time_format
set_language_if_valid 'en'
now = Time.now
- Setting.date_format = '%d %m %Y'
- Setting.time_format = '%H %M'
- assert_equal now.strftime('%d %m %Y %H %M'), format_time(now.utc)
- assert_equal now.strftime('%H %M'), format_time(now.utc, false)
+ with_settings :date_format => '%d %m %Y', :time_format => '%H %M' do
+ assert_equal now.strftime('%d %m %Y %H %M'), format_time(now.utc)
+ assert_equal now.strftime('%H %M'), format_time(now.utc, false)
+ end
end
def test_number_to_human_size_for_each_language
@@ -175,8 +178,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase
set_language_if_valid 'bs'
assert_equal "KM -1000,20", number_to_currency(-1000.2)
set_language_if_valid 'de'
- euro_sign = "\xe2\x82\xac"
- euro_sign.force_encoding('UTF-8') if euro_sign.respond_to?(:force_encoding)
+ euro_sign = "\xe2\x82\xac".force_encoding('UTF-8')
assert_equal "-1000,20 #{euro_sign}", number_to_currency(-1000.2)
end
@@ -193,8 +195,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase
assert_nil options.detect {|option| option.size != 2}
assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)}
assert_include ["English", "en"], options
- ja = "Japanese (\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e)"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja = "Japanese (\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e)".force_encoding('UTF-8')
assert_include [ja, "ja"], options
end
@@ -238,30 +239,21 @@ class Redmine::I18nTest < ActiveSupport::TestCase
def test_utf8
set_language_if_valid 'ja'
- str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84"
+ str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84".force_encoding('UTF-8')
i18n_ja_yes = l(:general_text_Yes)
- if str_ja_yes.respond_to?(:force_encoding)
- str_ja_yes.force_encoding('UTF-8')
- assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
- end
assert_equal str_ja_yes, i18n_ja_yes
+ assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
end
def test_traditional_chinese_locale
set_language_if_valid 'zh-TW'
- str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
- if str_tw.respond_to?(:force_encoding)
- str_tw.force_encoding('UTF-8')
- end
+ str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8')
assert_equal str_tw, l(:general_lang_name)
end
def test_french_locale
set_language_if_valid 'fr'
- str_fr = "Fran\xc3\xa7ais"
- if str_fr.respond_to?(:force_encoding)
- str_fr.force_encoding('UTF-8')
- end
+ str_fr = "Fran\xc3\xa7ais".force_encoding('UTF-8')
assert_equal str_fr, l(:general_lang_name)
end
end
diff --git a/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb
index a4699ef4d..272b7ba13 100644
--- a/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb
+++ b/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb
@@ -16,210 +16,203 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
-begin
- require 'mocha/setup'
-
- class BazaarAdapterTest < ActiveSupport::TestCase
- REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
- REPOSITORY_PATH.gsub!(/\/+/, '/')
-
- if File.directory?(REPOSITORY_PATH)
- def setup
- @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(
- File.join(REPOSITORY_PATH, "trunk")
- )
- end
- def test_scm_version
- to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2],
- "2.1.1\n1.7\n1.8" => [2,1,1],
- "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]}
- to_test.each do |s, v|
- test_scm_version_for(s, v)
- end
- end
+class BazaarAdapterTest < ActiveSupport::TestCase
+ REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
+ REPOSITORY_PATH.gsub!(/\/+/, '/')
- def test_cat
- cat = @adapter.cat('directory/document.txt')
- assert cat =~ /Write the contents of a file as of a given revision to standard output/
- end
+ if File.directory?(REPOSITORY_PATH)
+ def setup
+ @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(
+ File.join(REPOSITORY_PATH, "trunk")
+ )
+ end
- def test_cat_path_invalid
- assert_nil @adapter.cat('invalid')
+ def test_scm_version
+ to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2],
+ "2.1.1\n1.7\n1.8" => [2,1,1],
+ "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]}
+ to_test.each do |s, v|
+ test_scm_version_for(s, v)
end
+ end
- def test_cat_revision_invalid
- assert_nil @adapter.cat('doc-mkdir.txt', '12345678')
- end
+ def test_cat
+ cat = @adapter.cat('directory/document.txt')
+ assert cat =~ /Write the contents of a file as of a given revision to standard output/
+ end
- def test_diff
- diff1 = @adapter.diff('doc-mkdir.txt', 3, 2)
- assert_equal 21, diff1.size
- buf = diff1[14].gsub(/\r\n|\r|\n/, "")
- assert_equal "-Display more information.", buf
- end
+ def test_cat_path_invalid
+ assert_nil @adapter.cat('invalid')
+ end
- def test_diff_path_invalid
- assert_equal [], @adapter.diff('invalid', 1)
- end
+ def test_cat_revision_invalid
+ assert_nil @adapter.cat('doc-mkdir.txt', '12345678')
+ end
- def test_diff_revision_invalid
- assert_equal [], @adapter.diff(nil, 12345678)
- assert_equal [], @adapter.diff(nil, 12345678, 87654321)
- end
+ def test_diff
+ diff1 = @adapter.diff('doc-mkdir.txt', 3, 2)
+ assert_equal 21, diff1.size
+ buf = diff1[14].gsub(/\r\n|\r|\n/, "")
+ assert_equal "-Display more information.", buf
+ end
- def test_annotate
- annotate = @adapter.annotate('doc-mkdir.txt')
- assert_equal 17, annotate.lines.size
- assert_equal '1', annotate.revisions[0].identifier
- assert_equal 'jsmith@', annotate.revisions[0].author
- assert_equal 'mkdir', annotate.lines[0]
- end
+ def test_diff_path_invalid
+ assert_equal [], @adapter.diff('invalid', 1)
+ end
- def test_annotate_path_invalid
- assert_nil @adapter.annotate('invalid')
- end
+ def test_diff_revision_invalid
+ assert_equal [], @adapter.diff(nil, 12345678)
+ assert_equal [], @adapter.diff(nil, 12345678, 87654321)
+ end
- def test_annotate_revision_invalid
- assert_nil @adapter.annotate('doc-mkdir.txt', '12345678')
- end
+ def test_annotate
+ annotate = @adapter.annotate('doc-mkdir.txt')
+ assert_equal 17, annotate.lines.size
+ assert_equal '1', annotate.revisions[0].identifier
+ assert_equal 'jsmith@', annotate.revisions[0].author
+ assert_equal 'mkdir', annotate.lines[0]
+ end
- def test_branch_conf_path
- p = "c:\\test\\test\\"
- bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
- assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
- p = "c:\\test\\test\\.bzr"
- bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
- assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
- p = "c:\\test\\test\\.bzr\\"
- bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
- assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
- p = "c:\\test\\test"
- bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
- assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
- p = "\\\\server\\test\\test\\"
- bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
- assert_equal File.join("\\\\server\\test\\test", ".bzr", "branch", "branch.conf"), bcp
- end
+ def test_annotate_path_invalid
+ assert_nil @adapter.annotate('invalid')
+ end
- def test_append_revisions_only_true
- assert_equal true, @adapter.append_revisions_only
- end
+ def test_annotate_revision_invalid
+ assert_nil @adapter.annotate('doc-mkdir.txt', '12345678')
+ end
- def test_append_revisions_only_false
- adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
- File.join(REPOSITORY_PATH, "empty-branch")
- )
- assert_equal false, adpt.append_revisions_only
- end
+ def test_branch_conf_path
+ p = "c:\\test\\test\\"
+ bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
+ assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
+ p = "c:\\test\\test\\.bzr"
+ bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
+ assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
+ p = "c:\\test\\test\\.bzr\\"
+ bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
+ assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
+ p = "c:\\test\\test"
+ bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
+ assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
+ p = "\\\\server\\test\\test\\"
+ bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
+ assert_equal File.join("\\\\server\\test\\test", ".bzr", "branch", "branch.conf"), bcp
+ end
- def test_append_revisions_only_shared_repo
- adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
- REPOSITORY_PATH
- )
- assert_equal false, adpt.append_revisions_only
- end
+ def test_append_revisions_only_true
+ assert_equal true, @adapter.append_revisions_only
+ end
- def test_info_not_nil
- assert_not_nil @adapter.info
- end
+ def test_append_revisions_only_false
+ adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
+ File.join(REPOSITORY_PATH, "empty-branch")
+ )
+ assert_equal false, adpt.append_revisions_only
+ end
- def test_info_nil
- adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
- "/invalid/invalid/"
- )
- assert_nil adpt.info
- end
+ def test_append_revisions_only_shared_repo
+ adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
+ REPOSITORY_PATH
+ )
+ assert_equal false, adpt.append_revisions_only
+ end
- def test_info
- info = @adapter.info
- assert_equal 4, info.lastrev.identifier.to_i
- end
+ def test_info_not_nil
+ assert_not_nil @adapter.info
+ end
- def test_info_emtpy
- adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
- File.join(REPOSITORY_PATH, "empty-branch")
- )
- assert_equal 0, adpt.info.lastrev.identifier.to_i
- end
+ def test_info_nil
+ adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
+ "/invalid/invalid/"
+ )
+ assert_nil adpt.info
+ end
- def test_entries_path_invalid
- assert_equal [], @adapter.entries('invalid')
- end
+ def test_info
+ info = @adapter.info
+ assert_equal 4, info.lastrev.identifier.to_i
+ end
- def test_entries_revision_invalid
- assert_nil @adapter.entries(nil, 12345678)
- end
+ def test_info_emtpy
+ adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
+ File.join(REPOSITORY_PATH, "empty-branch")
+ )
+ assert_equal 0, adpt.info.lastrev.identifier.to_i
+ end
- def test_revisions
- revisions = @adapter.revisions(nil, 4, 2)
- assert_equal 3, revisions.size
- assert_equal 2, revisions[2].identifier
- assert_equal 'jsmith@foo.bar-20071203175224-v0eog5d5wrgdrshg', revisions[2].scmid
- assert_equal 4, revisions[0].identifier
- assert_equal 'jsmith@foo.bar-20071203175422-t40bf8li5zz0c4cg', revisions[0].scmid
- assert_equal 2, revisions[0].paths.size
- assert_equal 'D', revisions[0].paths[0][:action]
- assert_equal '/doc-deleted.txt', revisions[0].paths[0][:path]
- assert_equal 'docdeleted.txt-20071203175320-iwwj561ojuubs3gt-1', revisions[0].paths[0][:revision]
- assert_equal 'M', revisions[0].paths[1][:action]
- assert_equal '/directory/doc-ls.txt', revisions[0].paths[1][:path]
- assert_equal 'docls.txt-20071203175005-a3hyc3mn0shl7cgu-1', revisions[0].paths[1][:revision]
- end
+ def test_entries_path_invalid
+ assert_equal [], @adapter.entries('invalid')
+ end
- def test_revisions_path_invalid
- assert_nil @adapter.revisions('invalid')
- end
+ def test_entries_revision_invalid
+ assert_nil @adapter.entries(nil, 12345678)
+ end
- def test_revisions_revision_invalid
- assert_nil @adapter.revisions(nil, 12345678)
- assert_nil @adapter.revisions(nil, 12345678, 87654321)
- end
+ def test_revisions
+ revisions = @adapter.revisions(nil, 4, 2)
+ assert_equal 3, revisions.size
+ assert_equal 2, revisions[2].identifier
+ assert_equal 'jsmith@foo.bar-20071203175224-v0eog5d5wrgdrshg', revisions[2].scmid
+ assert_equal 4, revisions[0].identifier
+ assert_equal 'jsmith@foo.bar-20071203175422-t40bf8li5zz0c4cg', revisions[0].scmid
+ assert_equal 2, revisions[0].paths.size
+ assert_equal 'D', revisions[0].paths[0][:action]
+ assert_equal '/doc-deleted.txt', revisions[0].paths[0][:path]
+ assert_equal 'docdeleted.txt-20071203175320-iwwj561ojuubs3gt-1', revisions[0].paths[0][:revision]
+ assert_equal 'M', revisions[0].paths[1][:action]
+ assert_equal '/directory/doc-ls.txt', revisions[0].paths[1][:path]
+ assert_equal 'docls.txt-20071203175005-a3hyc3mn0shl7cgu-1', revisions[0].paths[1][:revision]
+ end
- def test_entry
- entry = @adapter.entry()
- assert_equal "", entry.path
- assert_equal "dir", entry.kind
- entry = @adapter.entry('')
- assert_equal "", entry.path
+ def test_revisions_path_invalid
+ assert_nil @adapter.revisions('invalid')
+ end
+
+ def test_revisions_revision_invalid
+ assert_nil @adapter.revisions(nil, 12345678)
+ assert_nil @adapter.revisions(nil, 12345678, 87654321)
+ end
+
+ def test_entry
+ entry = @adapter.entry()
+ assert_equal "", entry.path
+ assert_equal "dir", entry.kind
+ entry = @adapter.entry('')
+ assert_equal "", entry.path
+ assert_equal "dir", entry.kind
+ assert_nil @adapter.entry('invalid')
+ assert_nil @adapter.entry('/invalid')
+ assert_nil @adapter.entry('/invalid/')
+ assert_nil @adapter.entry('invalid/invalid')
+ assert_nil @adapter.entry('invalid/invalid/')
+ assert_nil @adapter.entry('/invalid/invalid')
+ assert_nil @adapter.entry('/invalid/invalid/')
+ ["doc-ls.txt", "/doc-ls.txt"].each do |path|
+ entry = @adapter.entry(path, 2)
+ assert_equal "doc-ls.txt", entry.path
+ assert_equal "file", entry.kind
+ end
+ ["directory", "/directory", "/directory/"].each do |path|
+ entry = @adapter.entry(path, 2)
+ assert_equal "directory", entry.path
assert_equal "dir", entry.kind
- assert_nil @adapter.entry('invalid')
- assert_nil @adapter.entry('/invalid')
- assert_nil @adapter.entry('/invalid/')
- assert_nil @adapter.entry('invalid/invalid')
- assert_nil @adapter.entry('invalid/invalid/')
- assert_nil @adapter.entry('/invalid/invalid')
- assert_nil @adapter.entry('/invalid/invalid/')
- ["doc-ls.txt", "/doc-ls.txt"].each do |path|
- entry = @adapter.entry(path, 2)
- assert_equal "doc-ls.txt", entry.path
- assert_equal "file", entry.kind
- end
- ["directory", "/directory", "/directory/"].each do |path|
- entry = @adapter.entry(path, 2)
- assert_equal "directory", entry.path
- assert_equal "dir", entry.kind
- end
- ["directory/document.txt", "/directory/document.txt"].each do |path|
- entry = @adapter.entry(path, 2)
- assert_equal "directory/document.txt", entry.path
- assert_equal "file", entry.kind
- end
end
+ ["directory/document.txt", "/directory/document.txt"].each do |path|
+ entry = @adapter.entry(path, 2)
+ assert_equal "directory/document.txt", entry.path
+ assert_equal "file", entry.kind
+ end
+ end
- private
+ private
- def test_scm_version_for(scm_command_version, version)
- @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
- assert_equal version, @adapter.class.scm_command_version
- end
- else
- puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
- def test_fake; assert true end
+ def test_scm_version_for(scm_command_version, version)
+ @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
+ assert_equal version, @adapter.class.scm_command_version
end
- end
-rescue LoadError
- class BazaarMochaFake < ActiveSupport::TestCase
- def test_fake; assert(false, "Requires mocha to run those tests") end
+ else
+ puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
end
end
diff --git a/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb
index cf5ab791c..504a3ad78 100644
--- a/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb
+++ b/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb
@@ -16,100 +16,91 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
-begin
- require 'mocha/setup'
- class CvsAdapterTest < ActiveSupport::TestCase
- REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
- REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
- MODULE_NAME = 'test'
+class CvsAdapterTest < ActiveSupport::TestCase
+ REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
+ REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
+ MODULE_NAME = 'test'
- if File.directory?(REPOSITORY_PATH)
- def setup
- @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
- end
+ if File.directory?(REPOSITORY_PATH)
+ def setup
+ @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
+ end
- def test_scm_version
- to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
- "\r\n1.12.12\r\n1.12.11" => [1,12,12],
- "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
- to_test.each do |s, v|
- test_scm_version_for(s, v)
- end
+ def test_scm_version
+ to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
+ "\r\n1.12.12\r\n1.12.11" => [1,12,12],
+ "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
+ to_test.each do |s, v|
+ test_scm_version_for(s, v)
end
+ end
- def test_revisions_all
- cnt = 0
- @adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
- cnt += 1
- end
- assert_equal 16, cnt
+ def test_revisions_all
+ cnt = 0
+ @adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
+ cnt += 1
end
+ assert_equal 16, cnt
+ end
- def test_revisions_from_rev3
- rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
- cnt = 0
- @adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
- cnt += 1
- end
- assert_equal 4, cnt
+ def test_revisions_from_rev3
+ rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
+ cnt = 0
+ @adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
+ cnt += 1
end
+ assert_equal 4, cnt
+ end
- def test_entries_rev3
- rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
- entries = @adapter.entries('sources', rev3_committed_on)
- assert_equal 2, entries.size
- assert_equal entries[0].name, "watchers_controller.rb"
- assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
- end
+ def test_entries_rev3
+ rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
+ entries = @adapter.entries('sources', rev3_committed_on)
+ assert_equal 2, entries.size
+ assert_equal entries[0].name, "watchers_controller.rb"
+ assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
+ end
- def test_path_encoding_default_utf8
- adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
- MODULE_NAME,
- REPOSITORY_PATH
- )
- assert_equal "UTF-8", adpt1.path_encoding
- adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
- MODULE_NAME,
- REPOSITORY_PATH,
- nil,
- nil,
- ""
- )
- assert_equal "UTF-8", adpt2.path_encoding
- end
+ def test_path_encoding_default_utf8
+ adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
+ MODULE_NAME,
+ REPOSITORY_PATH
+ )
+ assert_equal "UTF-8", adpt1.path_encoding
+ adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
+ MODULE_NAME,
+ REPOSITORY_PATH,
+ nil,
+ nil,
+ ""
+ )
+ assert_equal "UTF-8", adpt2.path_encoding
+ end
- def test_root_url_path
- to_test = {
- ':pserver:cvs_user:cvs_password@123.456.789.123:9876/repo' => '/repo',
- ':pserver:cvs_user:cvs_password@123.456.789.123/repo' => '/repo',
- ':pserver:cvs_user:cvs_password@cvs_server:/repo' => '/repo',
- ':pserver:cvs_user:cvs_password@cvs_server:9876/repo' => '/repo',
- ':pserver:cvs_user:cvs_password@cvs_server/repo' => '/repo',
- ':pserver:cvs_user:cvs_password@cvs_server/path/repo' => '/path/repo',
- ':ext:cvsservername:/path' => '/path'
- }
+ def test_root_url_path
+ to_test = {
+ ':pserver:cvs_user:cvs_password@123.456.789.123:9876/repo' => '/repo',
+ ':pserver:cvs_user:cvs_password@123.456.789.123/repo' => '/repo',
+ ':pserver:cvs_user:cvs_password@cvs_server:/repo' => '/repo',
+ ':pserver:cvs_user:cvs_password@cvs_server:9876/repo' => '/repo',
+ ':pserver:cvs_user:cvs_password@cvs_server/repo' => '/repo',
+ ':pserver:cvs_user:cvs_password@cvs_server/path/repo' => '/path/repo',
+ ':ext:cvsservername:/path' => '/path'
+ }
- to_test.each do |string, expected|
- assert_equal expected, Redmine::Scm::Adapters::CvsAdapter.new('foo', string).send(:root_url_path), "#{string} failed"
- end
+ to_test.each do |string, expected|
+ assert_equal expected, Redmine::Scm::Adapters::CvsAdapter.new('foo', string).send(:root_url_path), "#{string} failed"
end
+ end
- private
+ private
- def test_scm_version_for(scm_command_version, version)
- @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
- assert_equal version, @adapter.class.scm_command_version
- end
- else
- puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
- def test_fake; assert true end
+ def test_scm_version_for(scm_command_version, version)
+ @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
+ assert_equal version, @adapter.class.scm_command_version
end
- end
-
-rescue LoadError
- class CvsMochaFake < ActiveSupport::TestCase
- def test_fake; assert(false, "Requires mocha to run those tests") end
+ else
+ puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
end
end
-
diff --git a/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb
index b6f877521..e28c84946 100644
--- a/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb
+++ b/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb
@@ -16,54 +16,45 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
-begin
- require 'mocha/setup'
- class DarcsAdapterTest < ActiveSupport::TestCase
- REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
+class DarcsAdapterTest < ActiveSupport::TestCase
+ REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
- if File.directory?(REPOSITORY_PATH)
- def setup
- @adapter = Redmine::Scm::Adapters::DarcsAdapter.new(REPOSITORY_PATH)
- end
-
- def test_darcsversion
- to_test = { "1.0.9 (release)\n" => [1,0,9] ,
- "2.2.0 (release)\n" => [2,2,0] }
- to_test.each do |s, v|
- test_darcsversion_for(s, v)
- end
- end
+ if File.directory?(REPOSITORY_PATH)
+ def setup
+ @adapter = Redmine::Scm::Adapters::DarcsAdapter.new(REPOSITORY_PATH)
+ end
- def test_revisions
- id1 = '20080308225258-98289-761f654d669045eabee90b91b53a21ce5593cadf.gz'
- revs = @adapter.revisions('', nil, nil, {:with_path => true})
- assert_equal 6, revs.size
- assert_equal id1, revs[5].scmid
- paths = revs[5].paths
- assert_equal 5, paths.size
- assert_equal 'A', paths[0][:action]
- assert_equal '/README', paths[0][:path]
- assert_equal 'A', paths[1][:action]
- assert_equal '/images', paths[1][:path]
+ def test_darcsversion
+ to_test = { "1.0.9 (release)\n" => [1,0,9] ,
+ "2.2.0 (release)\n" => [2,2,0] }
+ to_test.each do |s, v|
+ test_darcsversion_for(s, v)
end
+ end
- private
+ def test_revisions
+ id1 = '20080308225258-98289-761f654d669045eabee90b91b53a21ce5593cadf.gz'
+ revs = @adapter.revisions('', nil, nil, {:with_path => true})
+ assert_equal 6, revs.size
+ assert_equal id1, revs[5].scmid
+ paths = revs[5].paths
+ assert_equal 5, paths.size
+ assert_equal 'A', paths[0][:action]
+ assert_equal '/README', paths[0][:path]
+ assert_equal 'A', paths[1][:action]
+ assert_equal '/images', paths[1][:path]
+ end
- def test_darcsversion_for(darcsversion, version)
- @adapter.class.expects(:darcs_binary_version_from_command_line).returns(darcsversion)
- assert_equal version, @adapter.class.darcs_binary_version
- end
+ private
- else
- puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
- def test_fake; assert true end
+ def test_darcsversion_for(darcsversion, version)
+ @adapter.class.expects(:darcs_binary_version_from_command_line).returns(darcsversion)
+ assert_equal version, @adapter.class.darcs_binary_version
end
- end
-rescue LoadError
- class DarcsMochaFake < ActiveSupport::TestCase
- def test_fake; assert(false, "Requires mocha to run those tests") end
+ else
+ puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
end
end
-
diff --git a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
index a140d25dc..7342b2244 100644
--- a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
+++ b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
@@ -16,594 +16,582 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
-begin
- require 'mocha/setup'
-
- class GitAdapterTest < ActiveSupport::TestCase
- REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
-
- FELIX_HEX = "Felix Sch\xC3\xA4fer"
- CHAR_1_HEX = "\xc3\x9c"
-
- ## Git, Mercurial and CVS path encodings are binary.
- ## Subversion supports URL encoding for path.
- ## Redmine Mercurial adapter and extension use URL encoding.
- ## Git accepts only binary path in command line parameter.
- ## So, there is no way to use binary command line parameter in JRuby.
- JRUBY_SKIP = (RUBY_PLATFORM == 'java')
- JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
-
- if File.directory?(REPOSITORY_PATH)
- ## Ruby uses ANSI api to fork a process on Windows.
- ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
- ## and these are incompatible with ASCII.
- ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
- ## http://code.google.com/p/msysgit/issues/detail?id=80
- ## So, Latin-1 path tests fail on Japanese Windows
- WINDOWS_PASS = (Redmine::Platform.mswin? &&
- Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
- WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
-
- def setup
- adapter_class = Redmine::Scm::Adapters::GitAdapter
- assert adapter_class
- assert adapter_class.client_command
- assert_equal true, adapter_class.client_available
- assert_equal true, adapter_class.client_version_above?([1])
- assert_equal true, adapter_class.client_version_above?([1, 0])
-
- @adapter = Redmine::Scm::Adapters::GitAdapter.new(
- REPOSITORY_PATH,
- nil,
- nil,
- nil,
- 'ISO-8859-1'
- )
- assert @adapter
- @char_1 = CHAR_1_HEX.dup
- @str_felix_hex = FELIX_HEX.dup
- if @char_1.respond_to?(:force_encoding)
- @char_1.force_encoding('UTF-8')
- @str_felix_hex.force_encoding('ASCII-8BIT')
- end
- end
- def test_scm_version
- to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
- "1.6.1\n1.7\n1.8" => [1,6,1],
- "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
- to_test.each do |s, v|
- test_scm_version_for(s, v)
- end
- end
+class GitAdapterTest < ActiveSupport::TestCase
+ REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
+
+ FELIX_HEX = "Felix Sch\xC3\xA4fer"
+ CHAR_1_HEX = "\xc3\x9c"
+
+ ## Git, Mercurial and CVS path encodings are binary.
+ ## Subversion supports URL encoding for path.
+ ## Redmine Mercurial adapter and extension use URL encoding.
+ ## Git accepts only binary path in command line parameter.
+ ## So, there is no way to use binary command line parameter in JRuby.
+ JRUBY_SKIP = (RUBY_PLATFORM == 'java')
+ JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
+
+ if File.directory?(REPOSITORY_PATH)
+ ## Ruby uses ANSI api to fork a process on Windows.
+ ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
+ ## and these are incompatible with ASCII.
+ ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
+ ## http://code.google.com/p/msysgit/issues/detail?id=80
+ ## So, Latin-1 path tests fail on Japanese Windows
+ WINDOWS_PASS = (Redmine::Platform.mswin? &&
+ Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
+ WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
+
+ def setup
+ adapter_class = Redmine::Scm::Adapters::GitAdapter
+ assert adapter_class
+ assert adapter_class.client_command
+ assert_equal true, adapter_class.client_available
+ assert_equal true, adapter_class.client_version_above?([1])
+ assert_equal true, adapter_class.client_version_above?([1, 0])
+
+ @adapter = Redmine::Scm::Adapters::GitAdapter.new(
+ REPOSITORY_PATH,
+ nil,
+ nil,
+ nil,
+ 'ISO-8859-1'
+ )
+ assert @adapter
+ @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
+ @str_felix_hex = FELIX_HEX.dup.force_encoding('ASCII-8BIT')
+ end
- def test_branches
- brs = []
- @adapter.branches.each do |b|
- brs << b
- end
- assert_equal 6, brs.length
- br_issue_8857 = brs[0]
- assert_equal 'issue-8857', br_issue_8857.to_s
- assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision
- assert_equal br_issue_8857.scmid, br_issue_8857.revision
- assert_equal false, br_issue_8857.is_default
- br_latin_1_path = brs[1]
- assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s
- assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision
- assert_equal br_latin_1_path.scmid, br_latin_1_path.revision
- assert_equal false, br_latin_1_path.is_default
- br_master = brs[2]
- assert_equal 'master', br_master.to_s
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision
- assert_equal br_master.scmid, br_master.revision
- assert_equal false, br_master.is_default
- br_master_20120212 = brs[3]
- assert_equal 'master-20120212', br_master_20120212.to_s
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision
- assert_equal br_master_20120212.scmid, br_master_20120212.revision
- assert_equal true, br_master_20120212.is_default
- br_latin_1 = brs[-2]
- assert_equal 'test-latin-1', br_latin_1.to_s
- assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision
- assert_equal br_latin_1.scmid, br_latin_1.revision
- assert_equal false, br_latin_1.is_default
- br_test = brs[-1]
- assert_equal 'test_branch', br_test.to_s
- assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision
- assert_equal br_test.scmid, br_test.revision
- assert_equal false, br_test.is_default
+ def test_scm_version
+ to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
+ "1.6.1\n1.7\n1.8" => [1,6,1],
+ "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
+ to_test.each do |s, v|
+ test_scm_version_for(s, v)
end
+ end
- def test_default_branch
- assert_equal 'master-20120212', @adapter.default_branch
- end
+ def test_branches
+ brs = []
+ @adapter.branches.each do |b|
+ brs << b
+ end
+ assert_equal 6, brs.length
+ br_issue_8857 = brs[0]
+ assert_equal 'issue-8857', br_issue_8857.to_s
+ assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision
+ assert_equal br_issue_8857.scmid, br_issue_8857.revision
+ assert_equal false, br_issue_8857.is_default
+ br_latin_1_path = brs[1]
+ assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s
+ assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision
+ assert_equal br_latin_1_path.scmid, br_latin_1_path.revision
+ assert_equal false, br_latin_1_path.is_default
+ br_master = brs[2]
+ assert_equal 'master', br_master.to_s
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision
+ assert_equal br_master.scmid, br_master.revision
+ assert_equal false, br_master.is_default
+ br_master_20120212 = brs[3]
+ assert_equal 'master-20120212', br_master_20120212.to_s
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision
+ assert_equal br_master_20120212.scmid, br_master_20120212.revision
+ assert_equal true, br_master_20120212.is_default
+ br_latin_1 = brs[-2]
+ assert_equal 'test-latin-1', br_latin_1.to_s
+ assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision
+ assert_equal br_latin_1.scmid, br_latin_1.revision
+ assert_equal false, br_latin_1.is_default
+ br_test = brs[-1]
+ assert_equal 'test_branch', br_test.to_s
+ assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision
+ assert_equal br_test.scmid, br_test.revision
+ assert_equal false, br_test.is_default
+ end
- def test_tags
- assert_equal [
- "tag00.lightweight",
- "tag01.annotated",
- ], @adapter.tags
- end
+ def test_default_branch
+ assert_equal 'master-20120212', @adapter.default_branch
+ end
- def test_revisions_master_all
- revs1 = []
- @adapter.revisions('', nil, "master",{}) do |rev|
- revs1 << rev
- end
- assert_equal 15, revs1.length
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier
- assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
-
- revs2 = []
- @adapter.revisions('', nil, "master",
- {:reverse => true}) do |rev|
- revs2 << rev
- end
- assert_equal 15, revs2.length
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
- assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
- end
+ def test_tags
+ assert_equal [
+ "tag00.lightweight",
+ "tag01.annotated",
+ ], @adapter.tags
+ end
- def test_revisions_master_merged_rev
- revs1 = []
- @adapter.revisions('',
- "713f4944648826f558cf548222f813dabe7cbb04",
- "master",
- {:reverse => true}) do |rev|
- revs1 << rev
- end
- assert_equal 8, revs1.length
- assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier
- assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier
- # 4a07fe31b is not a child of 713f49446
- assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier
- # Merged revision
- assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
-
- revs2 = []
- @adapter.revisions('',
- "fba357b886984ee71185ad2065e65fc0417d9b92",
- "master",
- {:reverse => true}) do |rev|
- revs2 << rev
- end
- assert_equal 7, revs2.length
- assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier
- # 4a07fe31b is not a child of fba357b8869
- assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier
- # Merged revision
- assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
+ def test_revisions_master_all
+ revs1 = []
+ @adapter.revisions('', nil, "master",{}) do |rev|
+ revs1 << rev
end
+ assert_equal 15, revs1.length
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier
+ assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
- def test_revisions_branch_latin_1_path_encoding_all
- revs1 = []
- @adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev|
- revs1 << rev
- end
- assert_equal 8, revs1.length
- assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier
- assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
-
- revs2 = []
- @adapter.revisions('', nil, "latin-1-path-encoding",
- {:reverse => true}) do |rev|
- revs2 << rev
- end
- assert_equal 8, revs2.length
- assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
- assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
+ revs2 = []
+ @adapter.revisions('', nil, "master",
+ {:reverse => true}) do |rev|
+ revs2 << rev
end
+ assert_equal 15, revs2.length
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
+ assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
+ end
- def test_revisions_branch_latin_1_path_encoding_with_rev
- revs1 = []
- @adapter.revisions('',
- '7234cb2750b63f47bff735edc50a1c0a433c2518',
- "latin-1-path-encoding",
- {:reverse => true}) do |rev|
- revs1 << rev
- end
- assert_equal 7, revs1.length
- assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier
- assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
+ def test_revisions_master_merged_rev
+ revs1 = []
+ @adapter.revisions('',
+ "713f4944648826f558cf548222f813dabe7cbb04",
+ "master",
+ {:reverse => true}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 8, revs1.length
+ assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier
+ assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier
+ # 4a07fe31b is not a child of 713f49446
+ assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier
+ # Merged revision
+ assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
+
+ revs2 = []
+ @adapter.revisions('',
+ "fba357b886984ee71185ad2065e65fc0417d9b92",
+ "master",
+ {:reverse => true}) do |rev|
+ revs2 << rev
+ end
+ assert_equal 7, revs2.length
+ assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier
+ # 4a07fe31b is not a child of fba357b8869
+ assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier
+ # Merged revision
+ assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
+ end
- revs2 = []
- @adapter.revisions('',
- '57ca437c0acbbcb749821fdf3726a1367056d364',
- "latin-1-path-encoding",
- {:reverse => true}) do |rev|
- revs2 << rev
- end
- assert_equal 3, revs2.length
- assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier
- assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
+ def test_revisions_branch_latin_1_path_encoding_all
+ revs1 = []
+ @adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev|
+ revs1 << rev
end
+ assert_equal 8, revs1.length
+ assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier
+ assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
- def test_revisions_invalid_rev
- assert_equal [], @adapter.revisions('', '1234abcd', "master")
- assert_raise Redmine::Scm::Adapters::CommandFailed do
- revs1 = []
- @adapter.revisions('',
- '1234abcd',
- "master",
- {:reverse => true}) do |rev|
- revs1 << rev
- end
- end
+ revs2 = []
+ @adapter.revisions('', nil, "latin-1-path-encoding",
+ {:reverse => true}) do |rev|
+ revs2 << rev
end
+ assert_equal 8, revs2.length
+ assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
+ assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
+ end
- def test_revisions_includes_master_two_revs
- revs1 = []
- @adapter.revisions('', nil, nil,
- {:reverse => true,
- :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
- :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev|
- revs1 << rev
- end
- assert_equal 2, revs1.length
- assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
- end
+ def test_revisions_branch_latin_1_path_encoding_with_rev
+ revs1 = []
+ @adapter.revisions('',
+ '7234cb2750b63f47bff735edc50a1c0a433c2518',
+ "latin-1-path-encoding",
+ {:reverse => true}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 7, revs1.length
+ assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier
+ assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
+
+ revs2 = []
+ @adapter.revisions('',
+ '57ca437c0acbbcb749821fdf3726a1367056d364',
+ "latin-1-path-encoding",
+ {:reverse => true}) do |rev|
+ revs2 << rev
+ end
+ assert_equal 3, revs2.length
+ assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier
+ assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
+ end
- def test_revisions_includes_master_two_revs_from_origin
+ def test_revisions_invalid_rev
+ assert_equal [], @adapter.revisions('', '1234abcd', "master")
+ assert_raise Redmine::Scm::Adapters::CommandFailed do
revs1 = []
- @adapter.revisions('', nil, nil,
- {:reverse => true,
- :includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9'],
- :excludes => []}) do |rev|
+ @adapter.revisions('',
+ '1234abcd',
+ "master",
+ {:reverse => true}) do |rev|
revs1 << rev
end
- assert_equal 2, revs1.length
- assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier
- assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier
end
+ end
- def test_revisions_includes_merged_revs
- revs1 = []
- @adapter.revisions('', nil, nil,
- {:reverse => true,
- :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
- :excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev|
- revs1 << rev
- end
- assert_equal 7, revs1.length
- assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier
- assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier
- assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
- end
+ def test_revisions_includes_master_two_revs
+ revs1 = []
+ @adapter.revisions('', nil, nil,
+ {:reverse => true,
+ :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
+ :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 2, revs1.length
+ assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
+ end
- def test_revisions_includes_two_heads
- revs1 = []
- @adapter.revisions('', nil, nil,
- {:reverse => true,
- :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c',
- '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'],
- :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43',
- '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev|
- revs1 << rev
- end
- assert_equal 4, revs1.length
- assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
- assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier
- assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
- end
+ def test_revisions_includes_master_two_revs_from_origin
+ revs1 = []
+ @adapter.revisions('', nil, nil,
+ {:reverse => true,
+ :includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9'],
+ :excludes => []}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 2, revs1.length
+ assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier
+ assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier
+ end
- def test_revisions_disjointed_histories_revisions
+ def test_revisions_includes_merged_revs
+ revs1 = []
+ @adapter.revisions('', nil, nil,
+ {:reverse => true,
+ :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
+ :excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 7, revs1.length
+ assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier
+ assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier
+ assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
+ end
+
+ def test_revisions_includes_two_heads
+ revs1 = []
+ @adapter.revisions('', nil, nil,
+ {:reverse => true,
+ :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c',
+ '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'],
+ :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43',
+ '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 4, revs1.length
+ assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
+ assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier
+ assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
+ end
+
+ def test_revisions_disjointed_histories_revisions
+ revs1 = []
+ @adapter.revisions('', nil, nil,
+ {:reverse => true,
+ :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c',
+ '92397af84d22f27389c822848ecd5b463c181583'],
+ :excludes => ['95488a44bc25f7d1f97d775a31359539ff333a63',
+ '4f26664364207fa8b1af9f8722647ab2d4ac5d43'] }) do |rev|
+ revs1 << rev
+ end
+ assert_equal 4, revs1.length
+ assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
+ assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
+ assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier
+ assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier
+ end
+
+ def test_revisions_invalid_rev_excludes
+ assert_equal [],
+ @adapter.revisions('', nil, nil,
+ {:reverse => true,
+ :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
+ :excludes => ['0123abcd4567']})
+ assert_raise Redmine::Scm::Adapters::CommandFailed do
revs1 = []
@adapter.revisions('', nil, nil,
{:reverse => true,
- :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c',
- '92397af84d22f27389c822848ecd5b463c181583'],
- :excludes => ['95488a44bc25f7d1f97d775a31359539ff333a63',
- '4f26664364207fa8b1af9f8722647ab2d4ac5d43'] }) do |rev|
+ :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
+ :excludes => ['0123abcd4567']}) do |rev|
revs1 << rev
end
- assert_equal 4, revs1.length
- assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
- assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
- assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier
- assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier
- end
-
- def test_revisions_invalid_rev_excludes
- assert_equal [],
- @adapter.revisions('', nil, nil,
- {:reverse => true,
- :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
- :excludes => ['0123abcd4567']})
- assert_raise Redmine::Scm::Adapters::CommandFailed do
- revs1 = []
- @adapter.revisions('', nil, nil,
- {:reverse => true,
- :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
- :excludes => ['0123abcd4567']}) do |rev|
- revs1 << rev
- end
- end
end
+ end
- def test_getting_revisions_with_spaces_in_filename
- assert_equal 1, @adapter.revisions("filemane with spaces.txt",
- nil, "master").length
- end
+ def test_getting_revisions_with_spaces_in_filename
+ assert_equal 1, @adapter.revisions("filemane with spaces.txt",
+ nil, "master").length
+ end
- def test_parents
- revs1 = []
- @adapter.revisions('',
- nil,
- "master",
- {:reverse => true}) do |rev|
- revs1 << rev
- end
- assert_equal 15, revs1.length
- assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
- revs1[0].identifier
- assert_equal nil, revs1[0].parents
- assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9",
- revs1[1].identifier
- assert_equal 1, revs1[1].parents.length
- assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
- revs1[1].parents[0]
- assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
- revs1[10].identifier
- assert_equal 2, revs1[10].parents.length
- assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
- revs1[10].parents[0]
- assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da",
- revs1[10].parents[1]
- end
+ def test_parents
+ revs1 = []
+ @adapter.revisions('',
+ nil,
+ "master",
+ {:reverse => true}) do |rev|
+ revs1 << rev
+ end
+ assert_equal 15, revs1.length
+ assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
+ revs1[0].identifier
+ assert_equal nil, revs1[0].parents
+ assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9",
+ revs1[1].identifier
+ assert_equal 1, revs1[1].parents.length
+ assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
+ revs1[1].parents[0]
+ assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
+ revs1[10].identifier
+ assert_equal 2, revs1[10].parents.length
+ assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
+ revs1[10].parents[0]
+ assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da",
+ revs1[10].parents[1]
+ end
- def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
- assert_equal " filename with a leading space.txt ",
- @adapter.revisions(" filename with a leading space.txt ",
- nil, "master")[0].paths[0][:path]
- end
+ def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
+ assert_equal " filename with a leading space.txt ",
+ @adapter.revisions(" filename with a leading space.txt ",
+ nil, "master")[0].paths[0][:path]
+ end
- def test_getting_entries_with_leading_and_trailing_spaces_in_filename
- assert_equal " filename with a leading space.txt ",
- @adapter.entries('',
- '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
- end
+ def test_getting_entries_with_leading_and_trailing_spaces_in_filename
+ assert_equal " filename with a leading space.txt ",
+ @adapter.entries('',
+ '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
+ end
- def test_annotate
- annotate = @adapter.annotate('sources/watchers_controller.rb')
- assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
- assert_equal 41, annotate.lines.size
- assert_equal "# This program is free software; you can redistribute it and/or",
- annotate.lines[4].strip
- assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
- annotate.revisions[4].identifier
- assert_equal "jsmith", annotate.revisions[4].author
- end
+ def test_annotate
+ annotate = @adapter.annotate('sources/watchers_controller.rb')
+ assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
+ assert_equal 41, annotate.lines.size
+ assert_equal "# This program is free software; you can redistribute it and/or",
+ annotate.lines[4].strip
+ assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
+ annotate.revisions[4].identifier
+ assert_equal "jsmith", annotate.revisions[4].author
+ end
- def test_annotate_moved_file
- annotate = @adapter.annotate('renamed_test.txt')
- assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
- assert_equal 2, annotate.lines.size
- end
+ def test_annotate_moved_file
+ annotate = @adapter.annotate('renamed_test.txt')
+ assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
+ assert_equal 2, annotate.lines.size
+ end
- def test_last_rev
- last_rev = @adapter.lastrev("README",
- "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
- assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
- assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
- assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
- assert_equal Time.gm(2009, 6, 24, 5, 27, 38), last_rev.time
- end
+ def test_last_rev
+ last_rev = @adapter.lastrev("README",
+ "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
+ assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
+ assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
+ assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
+ assert_equal Time.gm(2009, 6, 24, 5, 27, 38), last_rev.time
+ end
- def test_last_rev_with_spaces_in_filename
- last_rev = @adapter.lastrev("filemane with spaces.txt",
- "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
- last_rev_author = last_rev.author
- assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
- assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
- assert_equal "#{@str_felix_hex} <felix@fachschaften.org>",
- last_rev.author
- assert_equal Time.gm(2010, 9, 18, 19, 59, 46), last_rev.time
- end
+ def test_last_rev_with_spaces_in_filename
+ last_rev = @adapter.lastrev("filemane with spaces.txt",
+ "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
+ last_rev_author = last_rev.author
+ assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
+ assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
+ assert_equal "#{@str_felix_hex} <felix@fachschaften.org>",
+ last_rev.author
+ assert_equal Time.gm(2010, 9, 18, 19, 59, 46), last_rev.time
+ end
- def test_latin_1_path
- if WINDOWS_PASS
- puts WINDOWS_SKIP_STR
- elsif JRUBY_SKIP
- puts JRUBY_SKIP_STR
- else
- p2 = "latin-1-dir/test-#{@char_1}-2.txt"
- ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
- assert @adapter.diff(p2, r1)
- assert @adapter.cat(p2, r1)
- assert_equal 1, @adapter.annotate(p2, r1).lines.length
- ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
- assert @adapter.diff(p2, r1, r2)
- end
+ def test_latin_1_path
+ if WINDOWS_PASS
+ puts WINDOWS_SKIP_STR
+ elsif JRUBY_SKIP
+ puts JRUBY_SKIP_STR
+ else
+ p2 = "latin-1-dir/test-#{@char_1}-2.txt"
+ ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
+ assert @adapter.diff(p2, r1)
+ assert @adapter.cat(p2, r1)
+ assert_equal 1, @adapter.annotate(p2, r1).lines.length
+ ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
+ assert @adapter.diff(p2, r1, r2)
end
end
end
+ end
- def test_latin_1_user_annotate
- ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
- annotate = @adapter.annotate(" filename with a leading space.txt ", r1)
- assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
- assert_equal 1, annotate.lines.size
- assert_equal "And this is a file with a leading and trailing space...",
- annotate.lines[0].strip
- assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
- annotate.revisions[0].identifier
- assert_equal @str_felix_hex, annotate.revisions[0].author
- end
+ def test_latin_1_user_annotate
+ ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
+ annotate = @adapter.annotate(" filename with a leading space.txt ", r1)
+ assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
+ assert_equal 1, annotate.lines.size
+ assert_equal "And this is a file with a leading and trailing space...",
+ annotate.lines[0].strip
+ assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
+ annotate.revisions[0].identifier
+ assert_equal @str_felix_hex, annotate.revisions[0].author
end
+ end
- def test_entries_tag
- entries1 = @adapter.entries(nil, 'tag01.annotated',
- options = {:report_last_commit => true})
- assert entries1
- assert_equal 3, entries1.size
- assert_equal 'sources', entries1[1].name
- assert_equal 'sources', entries1[1].path
- assert_equal 'dir', entries1[1].kind
- readme = entries1[2]
- assert_equal 'README', readme.name
- assert_equal 'README', readme.path
- assert_equal 'file', readme.kind
- assert_equal 27, readme.size
- assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
- assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
- end
+ def test_entries_tag
+ entries1 = @adapter.entries(nil, 'tag01.annotated',
+ options = {:report_last_commit => true})
+ assert entries1
+ assert_equal 3, entries1.size
+ assert_equal 'sources', entries1[1].name
+ assert_equal 'sources', entries1[1].path
+ assert_equal 'dir', entries1[1].kind
+ readme = entries1[2]
+ assert_equal 'README', readme.name
+ assert_equal 'README', readme.path
+ assert_equal 'file', readme.kind
+ assert_equal 27, readme.size
+ assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
+ assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
+ end
- def test_entries_branch
- entries1 = @adapter.entries(nil, 'test_branch',
- options = {:report_last_commit => true})
- assert entries1
- assert_equal 4, entries1.size
- assert_equal 'sources', entries1[1].name
- assert_equal 'sources', entries1[1].path
- assert_equal 'dir', entries1[1].kind
- readme = entries1[2]
- assert_equal 'README', readme.name
- assert_equal 'README', readme.path
- assert_equal 'file', readme.kind
- assert_equal 159, readme.size
- assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
- assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
- end
+ def test_entries_branch
+ entries1 = @adapter.entries(nil, 'test_branch',
+ options = {:report_last_commit => true})
+ assert entries1
+ assert_equal 4, entries1.size
+ assert_equal 'sources', entries1[1].name
+ assert_equal 'sources', entries1[1].path
+ assert_equal 'dir', entries1[1].kind
+ readme = entries1[2]
+ assert_equal 'README', readme.name
+ assert_equal 'README', readme.path
+ assert_equal 'file', readme.kind
+ assert_equal 159, readme.size
+ assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
+ assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
+ end
- def test_entries_wrong_path_encoding
- adpt = Redmine::Scm::Adapters::GitAdapter.new(
- REPOSITORY_PATH,
- nil,
- nil,
- nil,
- 'EUC-JP'
- )
- entries1 = adpt.entries('latin-1-dir', '64f1f3e8')
- assert entries1
- assert_equal 3, entries1.size
- f1 = entries1[1]
- assert_equal nil, f1.name
- assert_equal nil, f1.path
- assert_equal 'file', f1.kind
- end
+ def test_entries_wrong_path_encoding
+ adpt = Redmine::Scm::Adapters::GitAdapter.new(
+ REPOSITORY_PATH,
+ nil,
+ nil,
+ nil,
+ 'EUC-JP'
+ )
+ entries1 = adpt.entries('latin-1-dir', '64f1f3e8')
+ assert entries1
+ assert_equal 3, entries1.size
+ f1 = entries1[1]
+ assert_equal nil, f1.name
+ assert_equal nil, f1.path
+ assert_equal 'file', f1.kind
+ end
+
+ def test_entries_latin_1_files
+ entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
+ assert entries1
+ assert_equal 3, entries1.size
+ f1 = entries1[1]
+ assert_equal "test-#{@char_1}-2.txt", f1.name
+ assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
+ assert_equal 'file', f1.kind
+ end
- def test_entries_latin_1_files
- entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
+ def test_entries_latin_1_dir
+ if WINDOWS_PASS
+ puts WINDOWS_SKIP_STR
+ elsif JRUBY_SKIP
+ puts JRUBY_SKIP_STR
+ else
+ entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
+ '1ca7f5ed')
assert entries1
assert_equal 3, entries1.size
f1 = entries1[1]
assert_equal "test-#{@char_1}-2.txt", f1.name
- assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
+ assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
assert_equal 'file', f1.kind
end
+ end
- def test_entries_latin_1_dir
- if WINDOWS_PASS
- puts WINDOWS_SKIP_STR
- elsif JRUBY_SKIP
- puts JRUBY_SKIP_STR
- else
- entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
- '1ca7f5ed')
- assert entries1
- assert_equal 3, entries1.size
- f1 = entries1[1]
- assert_equal "test-#{@char_1}-2.txt", f1.name
- assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
- assert_equal 'file', f1.kind
- end
- end
-
- def test_entry
- entry = @adapter.entry()
- assert_equal "", entry.path
+ def test_entry
+ entry = @adapter.entry()
+ assert_equal "", entry.path
+ assert_equal "dir", entry.kind
+ entry = @adapter.entry('')
+ assert_equal "", entry.path
+ assert_equal "dir", entry.kind
+ assert_nil @adapter.entry('invalid')
+ assert_nil @adapter.entry('/invalid')
+ assert_nil @adapter.entry('/invalid/')
+ assert_nil @adapter.entry('invalid/invalid')
+ assert_nil @adapter.entry('invalid/invalid/')
+ assert_nil @adapter.entry('/invalid/invalid')
+ assert_nil @adapter.entry('/invalid/invalid/')
+ ["README", "/README"].each do |path|
+ entry = @adapter.entry(path, '7234cb2750b63f')
+ assert_equal "README", entry.path
+ assert_equal "file", entry.kind
+ end
+ ["sources", "/sources", "/sources/"].each do |path|
+ entry = @adapter.entry(path, '7234cb2750b63f')
+ assert_equal "sources", entry.path
assert_equal "dir", entry.kind
- entry = @adapter.entry('')
- assert_equal "", entry.path
- assert_equal "dir", entry.kind
- assert_nil @adapter.entry('invalid')
- assert_nil @adapter.entry('/invalid')
- assert_nil @adapter.entry('/invalid/')
- assert_nil @adapter.entry('invalid/invalid')
- assert_nil @adapter.entry('invalid/invalid/')
- assert_nil @adapter.entry('/invalid/invalid')
- assert_nil @adapter.entry('/invalid/invalid/')
- ["README", "/README"].each do |path|
- entry = @adapter.entry(path, '7234cb2750b63f')
- assert_equal "README", entry.path
- assert_equal "file", entry.kind
- end
- ["sources", "/sources", "/sources/"].each do |path|
- entry = @adapter.entry(path, '7234cb2750b63f')
- assert_equal "sources", entry.path
- assert_equal "dir", entry.kind
- end
- ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
- entry = @adapter.entry(path, '7234cb2750b63f')
- assert_equal "sources/watchers_controller.rb", entry.path
- assert_equal "file", entry.kind
- end
end
-
- def test_path_encoding_default_utf8
- adpt1 = Redmine::Scm::Adapters::GitAdapter.new(
- REPOSITORY_PATH
- )
- assert_equal "UTF-8", adpt1.path_encoding
- adpt2 = Redmine::Scm::Adapters::GitAdapter.new(
- REPOSITORY_PATH,
- nil,
- nil,
- nil,
- ""
- )
- assert_equal "UTF-8", adpt2.path_encoding
+ ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
+ entry = @adapter.entry(path, '7234cb2750b63f')
+ assert_equal "sources/watchers_controller.rb", entry.path
+ assert_equal "file", entry.kind
end
+ end
- def test_cat_path_invalid
- assert_nil @adapter.cat('invalid')
- end
+ def test_path_encoding_default_utf8
+ adpt1 = Redmine::Scm::Adapters::GitAdapter.new(
+ REPOSITORY_PATH
+ )
+ assert_equal "UTF-8", adpt1.path_encoding
+ adpt2 = Redmine::Scm::Adapters::GitAdapter.new(
+ REPOSITORY_PATH,
+ nil,
+ nil,
+ nil,
+ ""
+ )
+ assert_equal "UTF-8", adpt2.path_encoding
+ end
- def test_cat_revision_invalid
- assert @adapter.cat('README')
- assert_nil @adapter.cat('README', '1234abcd5678')
- end
+ def test_cat_path_invalid
+ assert_nil @adapter.cat('invalid')
+ end
- def test_diff_path_invalid
- assert_equal [], @adapter.diff('invalid', '713f4944648826f5')
- end
+ def test_cat_revision_invalid
+ assert @adapter.cat('README')
+ assert_nil @adapter.cat('README', '1234abcd5678')
+ end
- def test_diff_revision_invalid
- assert_nil @adapter.diff(nil, '1234abcd5678')
- assert_nil @adapter.diff(nil, '713f4944648826f5', '1234abcd5678')
- assert_nil @adapter.diff(nil, '1234abcd5678', '713f4944648826f5')
- end
+ def test_diff_path_invalid
+ assert_equal [], @adapter.diff('invalid', '713f4944648826f5')
+ end
- def test_annotate_path_invalid
- assert_nil @adapter.annotate('invalid')
- end
+ def test_diff_revision_invalid
+ assert_nil @adapter.diff(nil, '1234abcd5678')
+ assert_nil @adapter.diff(nil, '713f4944648826f5', '1234abcd5678')
+ assert_nil @adapter.diff(nil, '1234abcd5678', '713f4944648826f5')
+ end
- def test_annotate_revision_invalid
- assert @adapter.annotate('README')
- assert_nil @adapter.annotate('README', '1234abcd5678')
- end
+ def test_annotate_path_invalid
+ assert_nil @adapter.annotate('invalid')
+ end
- private
+ def test_annotate_revision_invalid
+ assert @adapter.annotate('README')
+ assert_nil @adapter.annotate('README', '1234abcd5678')
+ end
- def test_scm_version_for(scm_command_version, version)
- @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
- assert_equal version, @adapter.class.scm_command_version
- end
+ private
- else
- puts "Git test repository NOT FOUND. Skipping unit tests !!!"
- def test_fake; assert true end
+ def test_scm_version_for(scm_command_version, version)
+ @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
+ assert_equal version, @adapter.class.scm_command_version
end
- end
-rescue LoadError
- class GitMochaFake < ActiveSupport::TestCase
- def test_fake; assert(false, "Requires mocha to run those tests") end
+ else
+ puts "Git test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
end
end
diff --git a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
index 7f062d1f1..ebbb75008 100644
--- a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
+++ b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
@@ -16,221 +16,184 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
-begin
- require 'mocha/setup'
-
- class MercurialAdapterTest < ActiveSupport::TestCase
- HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR
- TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
- TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
-
- REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
- CHAR_1_HEX = "\xc3\x9c"
-
- if File.directory?(REPOSITORY_PATH)
- def setup
- adapter_class = Redmine::Scm::Adapters::MercurialAdapter
- assert adapter_class
- assert adapter_class.client_command
- assert_equal true, adapter_class.client_available
- assert_equal true, adapter_class.client_version_above?([0, 9, 5])
-
- @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(
- REPOSITORY_PATH,
- nil,
- nil,
- nil,
- 'ISO-8859-1')
- @diff_c_support = true
- @char_1 = CHAR_1_HEX.dup
- @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
- @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
- @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
- if @tag_char_1.respond_to?(:force_encoding)
- @char_1.force_encoding('UTF-8')
- @tag_char_1.force_encoding('UTF-8')
- @branch_char_0.force_encoding('UTF-8')
- @branch_char_1.force_encoding('UTF-8')
- end
- end
- def test_hgversion
- to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
- "Mercurial Distributed SCM (1.0)\n" => [1,0],
- "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
- "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
- "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
- "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
- "(1.6)\n(1.7)\n(1.8)" => [1,6],
- "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
-
- to_test.each do |s, v|
- test_hgversion_for(s, v)
- end
- end
+class MercurialAdapterTest < ActiveSupport::TestCase
+ HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR
+ TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
+ TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
+
+ REPOSITORY_PATH = repository_path('mercurial')
+ CHAR_1_HEX = "\xc3\x9c"
+
+ if File.directory?(REPOSITORY_PATH)
+ def setup
+ adapter_class = Redmine::Scm::Adapters::MercurialAdapter
+ assert adapter_class
+ assert adapter_class.client_command
+ assert_equal true, adapter_class.client_available
+ assert_equal true, adapter_class.client_version_above?([0, 9, 5])
+
+ @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(
+ REPOSITORY_PATH,
+ nil,
+ nil,
+ nil,
+ 'ISO-8859-1')
+ @diff_c_support = true
+ @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
+ @tag_char_1 = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
+ @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
+ @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
+ end
- def test_template_path
- to_test = {
- [1,2] => "1.0",
- [] => "1.0",
- [1,2,1] => "1.0",
- [1,7] => "1.0",
- [1,7,1] => "1.0",
- [2,0] => "1.0",
- }
- to_test.each do |v, template|
- test_template_path_for(v, template)
- end
+ def test_hgversion
+ to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
+ "Mercurial Distributed SCM (1.0)\n" => [1,0],
+ "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
+ "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
+ "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
+ "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
+ "(1.6)\n(1.7)\n(1.8)" => [1,6],
+ "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
+
+ to_test.each do |s, v|
+ test_hgversion_for(s, v)
end
+ end
- def test_info
- [REPOSITORY_PATH, REPOSITORY_PATH + "/",
- REPOSITORY_PATH + "//"].each do |repo|
- adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
- repo_path = adp.info.root_url.gsub(/\\/, "/")
- assert_equal REPOSITORY_PATH, repo_path
- assert_equal '33', adp.info.lastrev.revision
- assert_equal '2e6d546429230f377d7d19c2078abd2dd909f235',adp.info.lastrev.scmid
- end
+ def test_template_path
+ to_test = {
+ [1,2] => "1.0",
+ [] => "1.0",
+ [1,2,1] => "1.0",
+ [1,7] => "1.0",
+ [1,7,1] => "1.0",
+ [2,0] => "1.0",
+ }
+ to_test.each do |v, template|
+ test_template_path_for(v, template)
end
+ end
- def test_revisions
- revisions = @adapter.revisions(nil, 2, 4)
- assert_equal 3, revisions.size
- assert_equal '2', revisions[0].revision
- assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
- assert_equal '4', revisions[2].revision
- assert_equal 'def6d2f1254a56fb8fbe9ec3b5c0451674dbd8b8', revisions[2].scmid
-
- revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
- assert_equal 2, revisions.size
- assert_equal '2', revisions[0].revision
- assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
+ def test_info
+ [REPOSITORY_PATH, REPOSITORY_PATH + "/",
+ REPOSITORY_PATH + "//"].each do |repo|
+ adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
+ repo_path = adp.info.root_url.gsub(/\\/, "/")
+ assert_equal REPOSITORY_PATH, repo_path
+ assert_equal '33', adp.info.lastrev.revision
+ assert_equal '2e6d546429230f377d7d19c2078abd2dd909f235',adp.info.lastrev.scmid
end
+ end
- def test_parents
- revs1 = @adapter.revisions(nil, 0, 0)
- assert_equal 1, revs1.size
- assert_equal [], revs1[0].parents
- revs2 = @adapter.revisions(nil, 1, 1)
- assert_equal 1, revs2.size
- assert_equal 1, revs2[0].parents.size
- assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", revs2[0].parents[0]
- revs3 = @adapter.revisions(nil, 30, 30)
- assert_equal 1, revs3.size
- assert_equal 2, revs3[0].parents.size
- assert_equal "a94b0528f24fe05ebaef496ae0500bb050772e36", revs3[0].parents[0]
- assert_equal "3a330eb329586ea2adb3f83237c23310e744ebe9", revs3[0].parents[1]
- end
+ def test_revisions
+ revisions = @adapter.revisions(nil, 2, 4)
+ assert_equal 3, revisions.size
+ assert_equal '2', revisions[0].revision
+ assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
+ assert_equal '4', revisions[2].revision
+ assert_equal 'def6d2f1254a56fb8fbe9ec3b5c0451674dbd8b8', revisions[2].scmid
+
+ revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
+ assert_equal 2, revisions.size
+ assert_equal '2', revisions[0].revision
+ assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
+ end
- def test_diff
- if @adapter.class.client_version_above?([1, 2])
- assert_nil @adapter.diff(nil, '100000')
- end
- assert_nil @adapter.diff(nil, '100000', '200000')
- [2, '400bb8672109', '400', 400].each do |r1|
- diff1 = @adapter.diff(nil, r1)
- if @diff_c_support
- assert_equal 28, diff1.size
- buf = diff1[24].gsub(/\r\n|\r|\n/, "")
- assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
- else
- assert_equal 0, diff1.size
- end
- [4, 'def6d2f1254a'].each do |r2|
- diff2 = @adapter.diff(nil, r1, r2)
- assert_equal 49, diff2.size
- buf = diff2[41].gsub(/\r\n|\r|\n/, "")
- assert_equal "+class WelcomeController < ApplicationController", buf
- diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
- assert_equal 20, diff3.size
- buf = diff3[12].gsub(/\r\n|\r|\n/, "")
- assert_equal "+ @watched.remove_watcher(user)", buf
-
- diff4 = @adapter.diff(nil, r2, r1)
- assert_equal 49, diff4.size
- buf = diff4[41].gsub(/\r\n|\r|\n/, "")
- assert_equal "-class WelcomeController < ApplicationController", buf
- diff5 = @adapter.diff('sources/watchers_controller.rb', r2, r1)
- assert_equal 20, diff5.size
- buf = diff5[9].gsub(/\r\n|\r|\n/, "")
- assert_equal "- @watched.remove_watcher(user)", buf
- end
- end
- end
+ def test_parents
+ revs1 = @adapter.revisions(nil, 0, 0)
+ assert_equal 1, revs1.size
+ assert_equal [], revs1[0].parents
+ revs2 = @adapter.revisions(nil, 1, 1)
+ assert_equal 1, revs2.size
+ assert_equal 1, revs2[0].parents.size
+ assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", revs2[0].parents[0]
+ revs3 = @adapter.revisions(nil, 30, 30)
+ assert_equal 1, revs3.size
+ assert_equal 2, revs3[0].parents.size
+ assert_equal "a94b0528f24fe05ebaef496ae0500bb050772e36", revs3[0].parents[0]
+ assert_equal "3a330eb329586ea2adb3f83237c23310e744ebe9", revs3[0].parents[1]
+ end
- def test_diff_made_by_revision
+ def test_diff
+ if @adapter.class.client_version_above?([1, 2])
+ assert_nil @adapter.diff(nil, '100000')
+ end
+ assert_nil @adapter.diff(nil, '100000', '200000')
+ [2, '400bb8672109', '400', 400].each do |r1|
+ diff1 = @adapter.diff(nil, r1)
if @diff_c_support
- [24, '24', '4cddb4e45f52'].each do |r1|
- diff1 = @adapter.diff(nil, r1)
- assert_equal 5, diff1.size
- buf = diff1[4].gsub(/\r\n|\r|\n/, "")
- assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
- end
+ assert_equal 28, diff1.size
+ buf = diff1[24].gsub(/\r\n|\r|\n/, "")
+ assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
+ else
+ assert_equal 0, diff1.size
+ end
+ [4, 'def6d2f1254a'].each do |r2|
+ diff2 = @adapter.diff(nil, r1, r2)
+ assert_equal 49, diff2.size
+ buf = diff2[41].gsub(/\r\n|\r|\n/, "")
+ assert_equal "+class WelcomeController < ApplicationController", buf
+ diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
+ assert_equal 20, diff3.size
+ buf = diff3[12].gsub(/\r\n|\r|\n/, "")
+ assert_equal "+ @watched.remove_watcher(user)", buf
+
+ diff4 = @adapter.diff(nil, r2, r1)
+ assert_equal 49, diff4.size
+ buf = diff4[41].gsub(/\r\n|\r|\n/, "")
+ assert_equal "-class WelcomeController < ApplicationController", buf
+ diff5 = @adapter.diff('sources/watchers_controller.rb', r2, r1)
+ assert_equal 20, diff5.size
+ buf = diff5[9].gsub(/\r\n|\r|\n/, "")
+ assert_equal "- @watched.remove_watcher(user)", buf
end
end
+ end
- def test_cat
- [2, '400bb8672109', '400', 400].each do |r|
- buf = @adapter.cat('sources/welcome_controller.rb', r)
- assert buf
- lines = buf.split("\r\n")
- assert_equal 25, lines.length
- assert_equal 'class WelcomeController < ApplicationController', lines[17]
+ def test_diff_made_by_revision
+ if @diff_c_support
+ [24, '24', '4cddb4e45f52'].each do |r1|
+ diff1 = @adapter.diff(nil, r1)
+ assert_equal 5, diff1.size
+ buf = diff1[4].gsub(/\r\n|\r|\n/, "")
+ assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
end
- assert_nil @adapter.cat('sources/welcome_controller.rb')
end
+ end
- def test_annotate
- assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
- [2, '400bb8672109', '400', 400].each do |r|
- ann = @adapter.annotate('sources/welcome_controller.rb', r)
- assert ann
- assert_equal '1', ann.revisions[17].revision
- assert_equal '9d5b5b004199', ann.revisions[17].identifier
- assert_equal 'jsmith', ann.revisions[0].author
- assert_equal 25, ann.lines.length
- assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
- end
+ def test_cat
+ [2, '400bb8672109', '400', 400].each do |r|
+ buf = @adapter.cat('sources/welcome_controller.rb', r)
+ assert buf
+ lines = buf.split("\r\n")
+ assert_equal 25, lines.length
+ assert_equal 'class WelcomeController < ApplicationController', lines[17]
end
+ assert_nil @adapter.cat('sources/welcome_controller.rb')
+ end
- def test_entries
- assert_nil @adapter.entries(nil, '100000')
-
- assert_equal 1, @adapter.entries("sources", 3).size
- assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size
-
- [2, '400bb8672109', '400', 400].each do |r|
- entries1 = @adapter.entries(nil, r)
- assert entries1
- assert_equal 3, entries1.size
- assert_equal 'sources', entries1[1].name
- assert_equal 'sources', entries1[1].path
- assert_equal 'dir', entries1[1].kind
- readme = entries1[2]
- assert_equal 'README', readme.name
- assert_equal 'README', readme.path
- assert_equal 'file', readme.kind
- assert_equal 27, readme.size
- assert_equal '1', readme.lastrev.revision
- assert_equal '9d5b5b00419901478496242e0768deba1ce8c51e', readme.lastrev.identifier
- # 2007-12-14 10:24:01 +0100
- assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
-
- entries2 = @adapter.entries('sources', r)
- assert entries2
- assert_equal 2, entries2.size
- assert_equal 'watchers_controller.rb', entries2[0].name
- assert_equal 'sources/watchers_controller.rb', entries2[0].path
- assert_equal 'file', entries2[0].kind
- assert_equal 'welcome_controller.rb', entries2[1].name
- assert_equal 'sources/welcome_controller.rb', entries2[1].path
- assert_equal 'file', entries2[1].kind
- end
+ def test_annotate
+ assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
+ [2, '400bb8672109', '400', 400].each do |r|
+ ann = @adapter.annotate('sources/welcome_controller.rb', r)
+ assert ann
+ assert_equal '1', ann.revisions[17].revision
+ assert_equal '9d5b5b004199', ann.revisions[17].identifier
+ assert_equal 'jsmith', ann.revisions[0].author
+ assert_equal 25, ann.lines.length
+ assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
end
+ end
+
+ def test_entries
+ assert_nil @adapter.entries(nil, '100000')
- def test_entries_tag
- entries1 = @adapter.entries(nil, 'tag_test.00')
+ assert_equal 1, @adapter.entries("sources", 3).size
+ assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size
+
+ [2, '400bb8672109', '400', 400].each do |r|
+ entries1 = @adapter.entries(nil, r)
assert entries1
assert_equal 3, entries1.size
assert_equal 'sources', entries1[1].name
@@ -240,236 +203,260 @@ begin
assert_equal 'README', readme.name
assert_equal 'README', readme.path
assert_equal 'file', readme.kind
- assert_equal 21, readme.size
- assert_equal '0', readme.lastrev.revision
- assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', readme.lastrev.identifier
- # 2007-12-14 10:22:52 +0100
- assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time
+ assert_equal 27, readme.size
+ assert_equal '1', readme.lastrev.revision
+ assert_equal '9d5b5b00419901478496242e0768deba1ce8c51e', readme.lastrev.identifier
+ # 2007-12-14 10:24:01 +0100
+ assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
+
+ entries2 = @adapter.entries('sources', r)
+ assert entries2
+ assert_equal 2, entries2.size
+ assert_equal 'watchers_controller.rb', entries2[0].name
+ assert_equal 'sources/watchers_controller.rb', entries2[0].path
+ assert_equal 'file', entries2[0].kind
+ assert_equal 'welcome_controller.rb', entries2[1].name
+ assert_equal 'sources/welcome_controller.rb', entries2[1].path
+ assert_equal 'file', entries2[1].kind
end
+ end
- def test_entries_branch
- entries1 = @adapter.entries(nil, 'test-branch-00')
- assert entries1
- assert_equal 5, entries1.size
- assert_equal 'sql_escape', entries1[2].name
- assert_equal 'sql_escape', entries1[2].path
- assert_equal 'dir', entries1[2].kind
- readme = entries1[4]
- assert_equal 'README', readme.name
- assert_equal 'README', readme.path
- assert_equal 'file', readme.kind
- assert_equal 365, readme.size
- assert_equal '8', readme.lastrev.revision
- assert_equal 'c51f5bb613cd60793c2a9fe9df29332e74bb949f', readme.lastrev.identifier
- # 2001-02-01 00:00:00 -0900
- assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time
- end
+ def test_entries_tag
+ entries1 = @adapter.entries(nil, 'tag_test.00')
+ assert entries1
+ assert_equal 3, entries1.size
+ assert_equal 'sources', entries1[1].name
+ assert_equal 'sources', entries1[1].path
+ assert_equal 'dir', entries1[1].kind
+ readme = entries1[2]
+ assert_equal 'README', readme.name
+ assert_equal 'README', readme.path
+ assert_equal 'file', readme.kind
+ assert_equal 21, readme.size
+ assert_equal '0', readme.lastrev.revision
+ assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', readme.lastrev.identifier
+ # 2007-12-14 10:22:52 +0100
+ assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time
+ end
- def test_entry
- entry = @adapter.entry()
- assert_equal "", entry.path
- assert_equal "dir", entry.kind
- entry = @adapter.entry('')
- assert_equal "", entry.path
- assert_equal "dir", entry.kind
- assert_nil @adapter.entry('invalid')
- assert_nil @adapter.entry('/invalid')
- assert_nil @adapter.entry('/invalid/')
- assert_nil @adapter.entry('invalid/invalid')
- assert_nil @adapter.entry('invalid/invalid/')
- assert_nil @adapter.entry('/invalid/invalid')
- assert_nil @adapter.entry('/invalid/invalid/')
- ["README", "/README"].each do |path|
- ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
- entry = @adapter.entry(path, rev)
- assert_equal "README", entry.path
- assert_equal "file", entry.kind
- assert_equal '0', entry.lastrev.revision
- assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
- end
+ def test_entries_branch
+ entries1 = @adapter.entries(nil, 'test-branch-00')
+ assert entries1
+ assert_equal 5, entries1.size
+ assert_equal 'sql_escape', entries1[2].name
+ assert_equal 'sql_escape', entries1[2].path
+ assert_equal 'dir', entries1[2].kind
+ readme = entries1[4]
+ assert_equal 'README', readme.name
+ assert_equal 'README', readme.path
+ assert_equal 'file', readme.kind
+ assert_equal 365, readme.size
+ assert_equal '8', readme.lastrev.revision
+ assert_equal 'c51f5bb613cd60793c2a9fe9df29332e74bb949f', readme.lastrev.identifier
+ # 2001-02-01 00:00:00 -0900
+ assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time
+ end
+
+ def test_entry
+ entry = @adapter.entry()
+ assert_equal "", entry.path
+ assert_equal "dir", entry.kind
+ entry = @adapter.entry('')
+ assert_equal "", entry.path
+ assert_equal "dir", entry.kind
+ assert_nil @adapter.entry('invalid')
+ assert_nil @adapter.entry('/invalid')
+ assert_nil @adapter.entry('/invalid/')
+ assert_nil @adapter.entry('invalid/invalid')
+ assert_nil @adapter.entry('invalid/invalid/')
+ assert_nil @adapter.entry('/invalid/invalid')
+ assert_nil @adapter.entry('/invalid/invalid/')
+ ["README", "/README"].each do |path|
+ ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
+ entry = @adapter.entry(path, rev)
+ assert_equal "README", entry.path
+ assert_equal "file", entry.kind
+ assert_equal '0', entry.lastrev.revision
+ assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
end
- ["sources", "/sources", "/sources/"].each do |path|
- ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
- entry = @adapter.entry(path, rev)
- assert_equal "sources", entry.path
- assert_equal "dir", entry.kind
- end
+ end
+ ["sources", "/sources", "/sources/"].each do |path|
+ ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
+ entry = @adapter.entry(path, rev)
+ assert_equal "sources", entry.path
+ assert_equal "dir", entry.kind
end
- ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
- ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
- entry = @adapter.entry(path, rev)
- assert_equal "sources/watchers_controller.rb", entry.path
- assert_equal "file", entry.kind
- assert_equal '0', entry.lastrev.revision
- assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
- end
+ end
+ ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
+ ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
+ entry = @adapter.entry(path, rev)
+ assert_equal "sources/watchers_controller.rb", entry.path
+ assert_equal "file", entry.kind
+ assert_equal '0', entry.lastrev.revision
+ assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
end
end
+ end
- def test_locate_on_outdated_repository
- assert_equal 1, @adapter.entries("images", 0).size
- assert_equal 2, @adapter.entries("images").size
- assert_equal 2, @adapter.entries("images", 2).size
- end
+ def test_locate_on_outdated_repository
+ assert_equal 1, @adapter.entries("images", 0).size
+ assert_equal 2, @adapter.entries("images").size
+ assert_equal 2, @adapter.entries("images", 2).size
+ end
- def test_access_by_nodeid
- path = 'sources/welcome_controller.rb'
- assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
- end
+ def test_access_by_nodeid
+ path = 'sources/welcome_controller.rb'
+ assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
+ end
- def test_access_by_fuzzy_nodeid
- path = 'sources/welcome_controller.rb'
- # falls back to nodeid
- assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
- end
+ def test_access_by_fuzzy_nodeid
+ path = 'sources/welcome_controller.rb'
+ # falls back to nodeid
+ assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
+ end
- def test_tags
- assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
- end
+ def test_tags
+ assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
+ end
- def test_tagmap
- tm = {
- @tag_char_1 => 'adf805632193500ad3b615cd04f58f9b0769f576',
- 'tag_test.00' => '6987191f453a5f6557018d522feea2c450d5588d',
- 'tag-init-revision' => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
- }
- assert_equal tm, @adapter.tagmap
- end
+ def test_tagmap
+ tm = {
+ @tag_char_1 => 'adf805632193500ad3b615cd04f58f9b0769f576',
+ 'tag_test.00' => '6987191f453a5f6557018d522feea2c450d5588d',
+ 'tag-init-revision' => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
+ }
+ assert_equal tm, @adapter.tagmap
+ end
- def test_branches
- brs = []
- @adapter.branches.each do |b|
- brs << b
- end
- assert_equal 7, brs.length
- assert_equal 'default', brs[0].to_s
- assert_equal '31', brs[0].revision
- assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355', brs[0].scmid
- assert_equal 'test-branch-01', brs[1].to_s
- assert_equal '30', brs[1].revision
- assert_equal 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7', brs[1].scmid
- assert_equal @branch_char_1, brs[2].to_s
- assert_equal '27', brs[2].revision
- assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', brs[2].scmid
- assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
- assert_equal '25', brs[3].revision
- assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', brs[3].scmid
- assert_equal @branch_char_0, brs[4].to_s
- assert_equal '23', brs[4].revision
- assert_equal 'c8d3e4887474af6a589190140508037ebaa9d9c3', brs[4].scmid
- assert_equal 'test_branch.latin-1', brs[5].to_s
- assert_equal '22', brs[5].revision
- assert_equal 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768', brs[5].scmid
- assert_equal 'test-branch-00', brs[6].to_s
- assert_equal '13', brs[6].revision
- assert_equal '3a330eb329586ea2adb3f83237c23310e744ebe9', brs[6].scmid
+ def test_branches
+ brs = []
+ @adapter.branches.each do |b|
+ brs << b
end
+ assert_equal 7, brs.length
+ assert_equal 'default', brs[0].to_s
+ assert_equal '31', brs[0].revision
+ assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355', brs[0].scmid
+ assert_equal 'test-branch-01', brs[1].to_s
+ assert_equal '30', brs[1].revision
+ assert_equal 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7', brs[1].scmid
+ assert_equal @branch_char_1, brs[2].to_s
+ assert_equal '27', brs[2].revision
+ assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', brs[2].scmid
+ assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
+ assert_equal '25', brs[3].revision
+ assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', brs[3].scmid
+ assert_equal @branch_char_0, brs[4].to_s
+ assert_equal '23', brs[4].revision
+ assert_equal 'c8d3e4887474af6a589190140508037ebaa9d9c3', brs[4].scmid
+ assert_equal 'test_branch.latin-1', brs[5].to_s
+ assert_equal '22', brs[5].revision
+ assert_equal 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768', brs[5].scmid
+ assert_equal 'test-branch-00', brs[6].to_s
+ assert_equal '13', brs[6].revision
+ assert_equal '3a330eb329586ea2adb3f83237c23310e744ebe9', brs[6].scmid
+ end
- def test_branchmap
- bm = {
- 'default' => '31eeee7395c8c78e66dd54c50addd078d10b2355',
- 'test_branch.latin-1' => 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768',
- 'branch (1)[2]&,%.-3_4' => 'afc61e85bde74de930e5846c8451bd55b5bafc9c',
- 'test-branch-00' => '3a330eb329586ea2adb3f83237c23310e744ebe9',
- "test-branch-01" => 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7',
- @branch_char_0 => 'c8d3e4887474af6a589190140508037ebaa9d9c3',
- @branch_char_1 => '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914',
- }
- assert_equal bm, @adapter.branchmap
- end
+ def test_branchmap
+ bm = {
+ 'default' => '31eeee7395c8c78e66dd54c50addd078d10b2355',
+ 'test_branch.latin-1' => 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768',
+ 'branch (1)[2]&,%.-3_4' => 'afc61e85bde74de930e5846c8451bd55b5bafc9c',
+ 'test-branch-00' => '3a330eb329586ea2adb3f83237c23310e744ebe9',
+ "test-branch-01" => 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7',
+ @branch_char_0 => 'c8d3e4887474af6a589190140508037ebaa9d9c3',
+ @branch_char_1 => '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914',
+ }
+ assert_equal bm, @adapter.branchmap
+ end
- def test_path_space
- p = 'README (1)[2]&,%.-3_4'
- [15, '933ca60293d7'].each do |r1|
- assert @adapter.diff(p, r1)
- assert @adapter.cat(p, r1)
- assert_equal 1, @adapter.annotate(p, r1).lines.length
- [25, 'afc61e85bde7'].each do |r2|
- assert @adapter.diff(p, r1, r2)
- end
+ def test_path_space
+ p = 'README (1)[2]&,%.-3_4'
+ [15, '933ca60293d7'].each do |r1|
+ assert @adapter.diff(p, r1)
+ assert @adapter.cat(p, r1)
+ assert_equal 1, @adapter.annotate(p, r1).lines.length
+ [25, 'afc61e85bde7'].each do |r2|
+ assert @adapter.diff(p, r1, r2)
end
end
+ end
- def test_tag_non_ascii
- p = "latin-1-dir/test-#{@char_1}-1.txt"
- assert @adapter.cat(p, @tag_char_1)
- assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length
- end
+ def test_tag_non_ascii
+ p = "latin-1-dir/test-#{@char_1}-1.txt"
+ assert @adapter.cat(p, @tag_char_1)
+ assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length
+ end
- def test_branch_non_ascii
- p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt"
- assert @adapter.cat(p, @branch_char_1)
- assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length
- end
+ def test_branch_non_ascii
+ p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt"
+ assert @adapter.cat(p, @branch_char_1)
+ assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length
+ end
- def test_nodes_in_branch
- [
- 'default',
- @branch_char_1,
- 'branch (1)[2]&,%.-3_4',
- @branch_char_0,
- 'test_branch.latin-1',
- 'test-branch-00',
- ].each do |bra|
- nib0 = @adapter.nodes_in_branch(bra)
- assert nib0
- nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
- assert_equal 1, nib1.size
- case bra
- when 'branch (1)[2]&,%.-3_4'
- if @adapter.class.client_version_above?([1, 6])
- assert_equal 3, nib0.size
- assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', nib0[0]
- nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
- assert_equal 2, nib2.size
- assert_equal '933ca60293d78f7c7979dd123cc0c02431683575', nib2[1]
- end
- when @branch_char_1
- if @adapter.class.client_version_above?([1, 6])
- assert_equal 2, nib0.size
- assert_equal '08ff3227303ec0dfcc818efa8e9cc652fe81859f', nib0[1]
- nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
- assert_equal 1, nib2.size
- assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', nib2[0]
- end
- end
+ def test_nodes_in_branch
+ [
+ 'default',
+ @branch_char_1,
+ 'branch (1)[2]&,%.-3_4',
+ @branch_char_0,
+ 'test_branch.latin-1',
+ 'test-branch-00',
+ ].each do |bra|
+ nib0 = @adapter.nodes_in_branch(bra)
+ assert nib0
+ nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
+ assert_equal 1, nib1.size
+ case bra
+ when 'branch (1)[2]&,%.-3_4'
+ if @adapter.class.client_version_above?([1, 6])
+ assert_equal 3, nib0.size
+ assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', nib0[0]
+ nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
+ assert_equal 2, nib2.size
+ assert_equal '933ca60293d78f7c7979dd123cc0c02431683575', nib2[1]
+ end
+ when @branch_char_1
+ if @adapter.class.client_version_above?([1, 6])
+ assert_equal 2, nib0.size
+ assert_equal '08ff3227303ec0dfcc818efa8e9cc652fe81859f', nib0[1]
+ nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
+ assert_equal 1, nib2.size
+ assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', nib2[0]
+ end
end
end
+ end
- def test_path_encoding_default_utf8
- adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new(
- REPOSITORY_PATH
- )
- assert_equal "UTF-8", adpt1.path_encoding
- adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new(
- REPOSITORY_PATH,
- nil,
- nil,
- nil,
- ""
- )
- assert_equal "UTF-8", adpt2.path_encoding
- end
+ def test_path_encoding_default_utf8
+ adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new(
+ REPOSITORY_PATH
+ )
+ assert_equal "UTF-8", adpt1.path_encoding
+ adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new(
+ REPOSITORY_PATH,
+ nil,
+ nil,
+ nil,
+ ""
+ )
+ assert_equal "UTF-8", adpt2.path_encoding
+ end
- private
+ private
- def test_hgversion_for(hgversion, version)
- @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
- assert_equal version, @adapter.class.hgversion
- end
+ def test_hgversion_for(hgversion, version)
+ @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
+ assert_equal version, @adapter.class.hgversion
+ end
- def test_template_path_for(version, template)
- assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
- @adapter.class.template_path_for(version)
- assert File.exist?(@adapter.class.template_path_for(version))
- end
- else
- puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
- def test_fake; assert true end
+ def test_template_path_for(version, template)
+ assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
+ @adapter.class.template_path_for(version)
+ assert File.exist?(@adapter.class.template_path_for(version))
end
- end
-rescue LoadError
- class MercurialMochaFake < ActiveSupport::TestCase
- def test_fake; assert(false, "Requires mocha to run those tests") end
+ else
+ puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
end
end
diff --git a/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb
index f272c0a0e..161f7d2e7 100644
--- a/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb
+++ b/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb
@@ -17,55 +17,47 @@
require File.expand_path('../../../../../../test_helper', __FILE__)
-begin
- require 'mocha/setup'
+class SubversionAdapterTest < ActiveSupport::TestCase
- class SubversionAdapterTest < ActiveSupport::TestCase
-
- if repository_configured?('subversion')
- def setup
- @adapter = Redmine::Scm::Adapters::SubversionAdapter.new(self.class.subversion_repository_url)
- end
+ if repository_configured?('subversion')
+ def setup
+ @adapter = Redmine::Scm::Adapters::SubversionAdapter.new(self.class.subversion_repository_url)
+ end
- def test_client_version
- v = Redmine::Scm::Adapters::SubversionAdapter.client_version
- assert v.is_a?(Array)
- end
+ def test_client_version
+ v = Redmine::Scm::Adapters::SubversionAdapter.client_version
+ assert v.is_a?(Array)
+ end
- def test_scm_version
- to_test = { "svn, version 1.6.13 (r1002816)\n" => [1,6,13],
- "svn, versione 1.6.13 (r1002816)\n" => [1,6,13],
- "1.6.1\n1.7\n1.8" => [1,6,1],
- "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
- to_test.each do |s, v|
- test_scm_version_for(s, v)
- end
+ def test_scm_version
+ to_test = { "svn, version 1.6.13 (r1002816)\n" => [1,6,13],
+ "svn, versione 1.6.13 (r1002816)\n" => [1,6,13],
+ "1.6.1\n1.7\n1.8" => [1,6,1],
+ "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
+ to_test.each do |s, v|
+ test_scm_version_for(s, v)
end
+ end
- def test_info_not_nil
- assert_not_nil @adapter.info
- end
+ def test_info_not_nil
+ assert_not_nil @adapter.info
+ end
- def test_info_nil
- adpt = Redmine::Scm::Adapters::SubversionAdapter.new(
- "file:///invalid/invalid/"
- )
- assert_nil adpt.info
- end
+ def test_info_nil
+ adpt = Redmine::Scm::Adapters::SubversionAdapter.new(
+ "file:///invalid/invalid/"
+ )
+ assert_nil adpt.info
+ end
- private
+ private
- def test_scm_version_for(scm_version, version)
- @adapter.class.expects(:scm_version_from_command_line).returns(scm_version)
- assert_equal version, @adapter.class.svn_binary_version
- end
- else
- puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
- def test_fake; assert true end
+ def test_scm_version_for(scm_version, version)
+ @adapter.class.expects(:scm_version_from_command_line).returns(scm_version)
+ assert_equal version, @adapter.class.svn_binary_version
end
- end
-rescue LoadError
- class SubversionMochaFake < ActiveSupport::TestCase
- def test_fake; assert(false, "Requires mocha to run those tests") end
+ else
+ puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
end
end
diff --git a/test/unit/lib/redmine/unified_diff_test.rb b/test/unit/lib/redmine/unified_diff_test.rb
index 4956e52f6..e3130fd28 100644
--- a/test/unit/lib/redmine/unified_diff_test.rb
+++ b/test/unit/lib/redmine/unified_diff_test.rb
@@ -223,8 +223,7 @@ DIFF
def test_utf8_ja
ja = " text_tip_issue_end_day: "
- ja += "\xe3\x81\x93\xe3\x81\xae\xe6\x97\xa5\xe3\x81\xab\xe7\xb5\x82\xe4\xba\x86\xe3\x81\x99\xe3\x82\x8b<span>\xe3\x82\xbf\xe3\x82\xb9\xe3\x82\xaf</span>"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja += "\xe3\x81\x93\xe3\x81\xae\xe6\x97\xa5\xe3\x81\xab\xe7\xb5\x82\xe4\xba\x86\xe3\x81\x99\xe3\x82\x8b<span>\xe3\x82\xbf\xe3\x82\xb9\xe3\x82\xaf</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ja.diff'), :type => 'inline')
assert_equal 1, diff.size
@@ -234,8 +233,7 @@ DIFF
end
def test_utf8_ru
- ru = " other: &quot;\xd0\xbe\xd0\xba\xd0\xbe\xd0\xbb\xd0\xbe %{count} \xd1\x87\xd0\xb0\xd1\x81<span>\xd0\xb0</span>&quot;"
- ru.force_encoding('UTF-8') if ru.respond_to?(:force_encoding)
+ ru = " other: &quot;\xd0\xbe\xd0\xba\xd0\xbe\xd0\xbb\xd0\xbe %{count} \xd1\x87\xd0\xb0\xd1\x81<span>\xd0\xb0</span>&quot;".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ru.diff'), :type => 'inline')
assert_equal 1, diff.size
@@ -279,10 +277,8 @@ DIFF
end
def test_offset_range_japanese_1
- ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>"
- ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
- ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>"
- ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
+ ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>".force_encoding('UTF-8')
+ ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-1.diff'), :type => 'sbs')
@@ -294,10 +290,8 @@ DIFF
end
def test_offset_range_japanese_2
- ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac"
- ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
- ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac"
- ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
+ ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8')
+ ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-2.diff'), :type => 'sbs')
@@ -310,10 +304,8 @@ DIFF
def test_offset_range_japanese_3
# UTF-8 The 1st byte differs.
- ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>"
- ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
- ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe5\xa8\x98</span>"
- ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
+ ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8')
+ ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe5\xa8\x98</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-3.diff'), :type => 'sbs')
@@ -326,10 +318,8 @@ DIFF
def test_offset_range_japanese_4
# UTF-8 The 2nd byte differs.
- ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>"
- ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
- ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>"
- ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
+ ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8')
+ ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-4.diff'), :type => 'sbs')
@@ -342,10 +332,8 @@ DIFF
def test_offset_range_japanese_5
# UTF-8 The 2nd byte differs.
- ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>ok"
- ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
- ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>ok"
- ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
+ ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>ok".force_encoding('UTF-8')
+ ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>ok".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-5.diff'), :type => 'sbs')
diff --git a/test/unit/lib/redmine/wiki_formatting/macros_test.rb b/test/unit/lib/redmine/wiki_formatting/macros_test.rb
index 7f5308d1b..8c218849d 100644
--- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb
+++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb
@@ -207,12 +207,14 @@ class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase
def test_macro_collapse
text = "{{collapse\n*Collapsed* block of text\n}}"
- result = textilizable(text)
-
- assert_select_in result, 'div.collapsed-text'
- assert_select_in result, 'strong', :text => 'Collapsed'
- assert_select_in result, 'a.collapsible.collapsed', :text => 'Show'
- assert_select_in result, 'a.collapsible', :text => 'Hide'
+ with_locale 'en' do
+ result = textilizable(text)
+
+ assert_select_in result, 'div.collapsed-text'
+ assert_select_in result, 'strong', :text => 'Collapsed'
+ assert_select_in result, 'a.collapsible.collapsed', :text => 'Show'
+ assert_select_in result, 'a.collapsible', :text => 'Hide'
+ end
end
def test_macro_collapse_with_one_arg
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 1a3469031..bb91ac3f7 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -411,8 +411,7 @@ class MailHandlerTest < ActiveSupport::TestCase
end
def test_add_issue_with_japanese_keywords
- ja_dev = "\xe9\x96\x8b\xe7\x99\xba"
- ja_dev.force_encoding('UTF-8') if ja_dev.respond_to?(:force_encoding)
+ ja_dev = "\xe9\x96\x8b\xe7\x99\xba".force_encoding('UTF-8')
tracker = Tracker.create!(:name => ja_dev)
Project.find(1).trackers << tracker
issue = submit_email(
@@ -447,8 +446,7 @@ class MailHandlerTest < ActiveSupport::TestCase
)
assert_kind_of Issue, issue
assert_equal 1, issue.attachments.size
- ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
attachment = issue.attachments.first
assert_equal ja, attachment.filename
assert_equal 5, attachment.filesize
@@ -464,8 +462,7 @@ class MailHandlerTest < ActiveSupport::TestCase
)
assert_kind_of Issue, issue
assert_equal 1, issue.attachments.size
- ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
attachment = issue.attachments.first
assert_equal ja, attachment.filename
assert_equal 5, attachment.filesize
@@ -481,10 +478,8 @@ class MailHandlerTest < ActiveSupport::TestCase
)
assert_kind_of Issue, issue
assert_equal 1, issue.attachments.size
- u = ""
- u.force_encoding('UTF-8') if u.respond_to?(:force_encoding)
- u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc"
- u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding)
+ u = "".force_encoding('UTF-8')
+ u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
11.times { u << u1 }
attachment = issue.attachments.first
assert_equal "#{u}.png", attachment.filename
@@ -501,10 +496,8 @@ class MailHandlerTest < ActiveSupport::TestCase
)
assert_kind_of Issue, issue
assert_equal 1, issue.attachments.size
- u = ""
- u.force_encoding('UTF-8') if u.respond_to?(:force_encoding)
- u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc"
- u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding)
+ u = "".force_encoding('UTF-8')
+ u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
11.times { u << u1 }
attachment = issue.attachments.first
assert_equal "#{u}.txt", attachment.filename
@@ -534,8 +527,7 @@ class MailHandlerTest < ActiveSupport::TestCase
'subject_as_iso-8859-1.eml',
:issue => {:project => 'ecookbook'}
)
- str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc..."
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc...".force_encoding('UTF-8')
assert_kind_of Issue, issue
assert_equal str, issue.subject
end
@@ -546,8 +538,7 @@ class MailHandlerTest < ActiveSupport::TestCase
:issue => {:project => 'ecookbook'}
)
assert_kind_of Issue, issue
- str = "Freundliche Gr\xc3\xbcsse"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Freundliche Gr\xc3\xbcsse".force_encoding('UTF-8')
assert_equal str, issue.description
end
@@ -557,8 +548,7 @@ class MailHandlerTest < ActiveSupport::TestCase
:issue => {:project => 'ecookbook'}
)
assert_kind_of Issue, issue
- str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87."
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87.".force_encoding('UTF-8')
assert issue.description.include?(str)
end
@@ -568,26 +558,20 @@ class MailHandlerTest < ActiveSupport::TestCase
:issue => {:project => 'ecookbook'}
)
assert_kind_of Issue, issue
- ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
assert_equal ja, issue.subject
end
def test_add_issue_with_korean_body
# Make sure mail bodies with a charset unknown to Ruby
# but known to the Mail gem 2.5.4 are handled correctly
- kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4."
- if !kr.respond_to?(:force_encoding)
- puts "\nOn Ruby 1.8, skip Korean encoding mail body test"
- else
- kr.force_encoding('UTF-8')
- issue = submit_email(
- 'body_ks_c_5601-1987.eml',
- :issue => {:project => 'ecookbook'}
- )
- assert_kind_of Issue, issue
- assert_equal kr, issue.description
- end
+ kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4.".force_encoding('UTF-8')
+ issue = submit_email(
+ 'body_ks_c_5601-1987.eml',
+ :issue => {:project => 'ecookbook'}
+ )
+ assert_kind_of Issue, issue
+ assert_equal kr, issue.description
end
def test_add_issue_with_no_subject_header
@@ -605,8 +589,7 @@ class MailHandlerTest < ActiveSupport::TestCase
:issue => {:project => 'ecookbook'}
)
assert_kind_of Issue, issue
- ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
- ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+ ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
assert_equal ja, issue.subject
end
@@ -910,10 +893,8 @@ class MailHandlerTest < ActiveSupport::TestCase
end
user = User.order('id DESC').first
assert_equal "foo@example.org", user.mail
- str1 = "\xc3\x84\xc3\xa4"
- str2 = "\xc3\x96\xc3\xb6"
- str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
- str2.force_encoding('UTF-8') if str2.respond_to?(:force_encoding)
+ str1 = "\xc3\x84\xc3\xa4".force_encoding('UTF-8')
+ str2 = "\xc3\x96\xc3\xb6".force_encoding('UTF-8')
assert_equal str1, user.firstname
assert_equal str2, user.lastname
end
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index 983e9fc4f..b3678ebb5 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -34,6 +34,7 @@ class MailerTest < ActiveSupport::TestCase
Setting.host_name = 'mydomain.foo'
Setting.protocol = 'http'
Setting.plain_text_mail = '0'
+ User.current = nil
end
def test_generated_links_in_emails
diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb
index 124aa3719..f45824ce9 100644
--- a/test/unit/member_test.rb
+++ b/test/unit/member_test.rb
@@ -79,9 +79,8 @@ class MemberTest < ActiveSupport::TestCase
member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
assert !member.save
assert_include I18n.translate('activerecord.errors.messages.empty'), member.errors[:role]
- str = "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
- assert_equal str, [member.errors.full_messages].flatten.join
+ assert_equal "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8'),
+ [member.errors.full_messages].flatten.join
end
def test_validate_member_role
@@ -131,7 +130,7 @@ class MemberTest < ActiveSupport::TestCase
end
assert m.destroyed?
ensure
- Member._destroy_callbacks.reject! {|c| c.filter==:destroy_test_callback}
+ Member._destroy_callbacks.delete(:destroy_test_callback)
end
def test_sort_without_roles
diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb
index b37f781a3..3b599c373 100644
--- a/test/unit/principal_test.rb
+++ b/test/unit/principal_test.rb
@@ -23,7 +23,7 @@ class PrincipalTest < ActiveSupport::TestCase
fixtures :users, :projects, :members, :member_roles
def test_active_scope_should_return_groups_and_active_users
- result = Principal.active.all
+ result = Principal.active.to_a
assert_include Group.first, result
assert_not_nil result.detect {|p| p.is_a?(User)}
assert_nil result.detect {|p| p.is_a?(User) && !p.active?}
diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb
index 2f1f6ee59..238417a2d 100644
--- a/test/unit/project_copy_test.rb
+++ b/test/unit/project_copy_test.rb
@@ -222,17 +222,6 @@ class ProjectCopyTest < ActiveSupport::TestCase
assert_equal @source_project.queries.map(&:user_id).sort, @project.queries.map(&:user_id).sort
end
- def test_copy_should_copy_queries_roles_visibility
- source = Project.generate!
- target = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
- IssueQuery.generate!(:project => source, :visibility => Query::VISIBILITY_ROLES, :roles => Role.where(:id => [1, 3]).to_a)
-
- assert target.copy(source)
- assert_equal 1, target.queries.size
- query = target.queries.first
- assert_equal [1, 3], query.role_ids.sort
- end
-
test "#copy should copy versions" do
@source_project.versions << Version.generate!
@source_project.versions << Version.generate!
diff --git a/test/unit/project_nested_set_test.rb b/test/unit/project_nested_set_test.rb
index 43c55dff8..3ecd78512 100644
--- a/test/unit/project_nested_set_test.rb
+++ b/test/unit/project_nested_set_test.rb
@@ -61,6 +61,11 @@ class ProjectNestedSetTest < ActiveSupport::TestCase
assert_valid_nested_set
end
+ def test_rebuild_without_projects_should_not_fail
+ Project.delete_all
+ assert Project.rebuild_tree!
+ end
+
def test_moving_a_child_to_a_different_parent_should_keep_valid_tree
assert_no_difference 'Project.count' do
Project.find_by_name('B1').set_parent!(Project.find_by_name('A2'))
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 0dc3a54f1..ff859b6f3 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -316,7 +316,7 @@ class ProjectTest < ActiveSupport::TestCase
parent.reload
assert_equal 4, parent.children.size
- assert_equal parent.children.all.sort_by(&:name), parent.children.all
+ assert_equal parent.children.sort_by(&:name), parent.children.to_a
end
def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy
@@ -729,7 +729,7 @@ class ProjectTest < ActiveSupport::TestCase
def test_activities_should_use_the_system_activities
project = Project.find(1)
- assert_equal project.activities, TimeEntryActivity.where(:active => true).all
+ assert_equal project.activities.to_a, TimeEntryActivity.where(:active => true).to_a
assert_kind_of ActiveRecord::Relation, project.activities
end
@@ -944,4 +944,10 @@ class ProjectTest < ActiveSupport::TestCase
assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option"
assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option"
end
+
+ def test_override_roles_without_builtin_group_memberships
+ project = Project.generate!
+ assert_equal [Role.anonymous], project.override_roles(Role.anonymous)
+ assert_equal [Role.non_member], project.override_roles(Role.non_member)
+ end
end
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 102efd4de..692fbdbbe 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -101,9 +101,9 @@ class QueryTest < ActiveSupport::TestCase
end
def find_issues_with_query(query)
- Issue.includes([:assigned_to, :status, :tracker, :project, :priority]).where(
+ Issue.joins(:status, :tracker, :project, :priority).where(
query.statement
- ).all
+ ).references([:assigned_to, :status, :tracker, :project, :priority]).to_a
end
def assert_find_issues_with_query_is_successful(query)
@@ -1118,9 +1118,7 @@ class QueryTest < ActiveSupport::TestCase
def test_label_for_fr
set_language_if_valid 'fr'
q = IssueQuery.new
- s = "Assign\xc3\xa9 \xc3\xa0"
- s.force_encoding('UTF-8') if s.respond_to?(:force_encoding)
- assert_equal s, q.label_for('assigned_to_id')
+ assert_equal "Assign\xc3\xa9 \xc3\xa0".force_encoding('UTF-8'), q.label_for('assigned_to_id')
end
def test_editable_by
diff --git a/test/unit/repository_bazaar_test.rb b/test/unit/repository_bazaar_test.rb
index 3e15958c0..da2103797 100644
--- a/test/unit/repository_bazaar_test.rb
+++ b/test/unit/repository_bazaar_test.rb
@@ -22,7 +22,7 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
include Redmine::I18n
- REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
+ REPOSITORY_PATH = repository_path('bazaar')
REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
NUM_REV = 4
@@ -42,11 +42,10 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
# you cannot run Bazaar non ASCII path tests.
#
RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
- REPOSITORY_PATH.respond_to?(:force_encoding) &&
Encoding.locale_charmap == "ISO-8859-1")
- CHAR_1_UTF8_HEX = "\xc3\x9c"
- CHAR_1_LATIN1_HEX = "\xdc"
+ CHAR_1_UTF8_HEX = "\xc3\x9c".force_encoding('UTF-8')
+ CHAR_1_LATIN1_HEX = "\xdc".force_encoding('ASCII-8BIT')
def setup
@project = Project.find(3)
@@ -54,12 +53,6 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
:project => @project, :url => REPOSITORY_PATH_TRUNK,
:log_encoding => 'UTF-8')
assert @repository
- @char_1_utf8 = CHAR_1_UTF8_HEX.dup
- @char_1_ascii8bit = CHAR_1_LATIN1_HEX.dup
- if @char_1_utf8.respond_to?(:force_encoding)
- @char_1_utf8.force_encoding('UTF-8')
- @char_1_ascii8bit.force_encoding('ASCII-8BIT')
- end
end
def test_blank_path_to_repository_error_message
@@ -76,8 +69,7 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
def test_blank_path_to_repository_error_message_fr
set_language_if_valid 'fr'
- str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Bazaar.new(
:project => @project,
:url => "",
@@ -178,70 +170,70 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
def test_cat_latin1_path
latin1_repo = create_latin1_repo
buf = latin1_repo.cat(
- "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
+ "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", 2)
assert buf
lines = buf.split("\n")
assert_equal 2, lines.length
assert_equal 'It is written in Python.', lines[1]
buf = latin1_repo.cat(
- "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
+ "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", 2)
assert buf
lines = buf.split("\n")
assert_equal 1, lines.length
- assert_equal "test-#{@char_1_ascii8bit}.txt", lines[0]
+ assert_equal "test-#{CHAR_1_LATIN1_HEX}.txt", lines[0]
end
def test_annotate_latin1_path
latin1_repo = create_latin1_repo
ann1 = latin1_repo.annotate(
- "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
+ "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", 2)
assert_equal 2, ann1.lines.size
assert_equal '2', ann1.revisions[0].identifier
assert_equal 'test00@', ann1.revisions[0].author
assert_equal 'It is written in Python.', ann1.lines[1]
ann2 = latin1_repo.annotate(
- "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
+ "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", 2)
assert_equal 1, ann2.lines.size
assert_equal '2', ann2.revisions[0].identifier
assert_equal 'test00@', ann2.revisions[0].author
- assert_equal "test-#{@char_1_ascii8bit}.txt", ann2.lines[0]
+ assert_equal "test-#{CHAR_1_LATIN1_HEX}.txt", ann2.lines[0]
end
def test_diff_latin1_path
latin1_repo = create_latin1_repo
diff1 = latin1_repo.diff(
- "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2, 1)
+ "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", 2, 1)
assert_equal 7, diff1.size
buf = diff1[5].gsub(/\r\n|\r|\n/, "")
- assert_equal "+test-#{@char_1_ascii8bit}.txt", buf
+ assert_equal "+test-#{CHAR_1_LATIN1_HEX}.txt", buf
end
def test_entries_latin1_path
latin1_repo = create_latin1_repo
- entries = latin1_repo.entries("test-#{@char_1_utf8}-dir", 2)
+ entries = latin1_repo.entries("test-#{CHAR_1_UTF8_HEX}-dir", 2)
assert_kind_of Redmine::Scm::Adapters::Entries, entries
assert_equal 3, entries.size
assert_equal 'file', entries[1].kind
- assert_equal "test-#{@char_1_utf8}-1.txt", entries[0].name
- assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", entries[0].path
+ assert_equal "test-#{CHAR_1_UTF8_HEX}-1.txt", entries[0].name
+ assert_equal "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", entries[0].path
end
def test_entry_latin1_path
latin1_repo = create_latin1_repo
- ["test-#{@char_1_utf8}-dir",
- "/test-#{@char_1_utf8}-dir",
- "/test-#{@char_1_utf8}-dir/"
+ ["test-#{CHAR_1_UTF8_HEX}-dir",
+ "/test-#{CHAR_1_UTF8_HEX}-dir",
+ "/test-#{CHAR_1_UTF8_HEX}-dir/"
].each do |path|
entry = latin1_repo.entry(path, 2)
- assert_equal "test-#{@char_1_utf8}-dir", entry.path
+ assert_equal "test-#{CHAR_1_UTF8_HEX}-dir", entry.path
assert_equal "dir", entry.kind
end
- ["test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
- "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt"
+ ["test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt",
+ "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt"
].each do |path|
entry = latin1_repo.entry(path, 2)
- assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
+ assert_equal "test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt",
entry.path
assert_equal "file", entry.kind
end
@@ -256,35 +248,33 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
cs2 = latin1_repo.changesets.find_by_revision('2')
assert_not_nil cs2
- assert_equal "test-#{@char_1_utf8}", cs2.comments
+ assert_equal "test-#{CHAR_1_UTF8_HEX}", cs2.comments
c2 = cs2.filechanges.sort_by(&:path)
assert_equal 4, c2.size
assert_equal 'A', c2[0].action
- assert_equal "/test-#{@char_1_utf8}-dir/", c2[0].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/", c2[0].path
assert_equal 'A', c2[1].action
- assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", c2[1].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-1.txt", c2[1].path
assert_equal 'A', c2[2].action
- assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c2[2].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", c2[2].path
assert_equal 'A', c2[3].action
- assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c2[3].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}.txt", c2[3].path
cs3 = latin1_repo.changesets.find_by_revision('3')
assert_not_nil cs3
- assert_equal "modify, move and delete #{@char_1_utf8} files", cs3.comments
+ assert_equal "modify, move and delete #{CHAR_1_UTF8_HEX} files", cs3.comments
c3 = cs3.filechanges.sort_by(&:path)
assert_equal 3, c3.size
assert_equal 'M', c3[0].action
- assert_equal "/test-#{@char_1_utf8}-1.txt", c3[0].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-1.txt", c3[0].path
assert_equal 'D', c3[1].action
- assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c3[1].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}-2.txt", c3[1].path
assert_equal 'M', c3[2].action
- assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c3[2].path
+ assert_equal "/test-#{CHAR_1_UTF8_HEX}-dir/test-#{CHAR_1_UTF8_HEX}.txt", c3[2].path
end
else
- msg = "Bazaar non ASCII output test cannot run this environment." + "\n"
- if msg.respond_to?(:force_encoding)
- msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
- end
+ msg = "Bazaar non ASCII output test cannot run this environment.\n"
+ msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
puts msg
end
diff --git a/test/unit/repository_cvs_test.rb b/test/unit/repository_cvs_test.rb
index 223b8ec45..8b5ac6271 100644
--- a/test/unit/repository_cvs_test.rb
+++ b/test/unit/repository_cvs_test.rb
@@ -22,7 +22,7 @@ class RepositoryCvsTest < ActiveSupport::TestCase
include Redmine::I18n
- REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
+ REPOSITORY_PATH = repository_path('cvs')
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
# CVS module
MODULE_NAME = 'test'
@@ -52,8 +52,7 @@ class RepositoryCvsTest < ActiveSupport::TestCase
def test_blank_module_error_message_fr
set_language_if_valid 'fr'
- str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Cvs.new(
:project => @project,
:identifier => 'test',
@@ -81,8 +80,7 @@ class RepositoryCvsTest < ActiveSupport::TestCase
def test_blank_cvsroot_error_message_fr
set_language_if_valid 'fr'
- str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Cvs.new(
:project => @project,
:identifier => 'test',
diff --git a/test/unit/repository_darcs_test.rb b/test/unit/repository_darcs_test.rb
index 255fcaf1c..9e98b0f2c 100644
--- a/test/unit/repository_darcs_test.rb
+++ b/test/unit/repository_darcs_test.rb
@@ -49,8 +49,7 @@ class RepositoryDarcsTest < ActiveSupport::TestCase
def test_blank_path_to_repository_error_message_fr
set_language_if_valid 'fr'
- str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Darcs.new(
:project => @project,
:url => "",
diff --git a/test/unit/repository_filesystem_test.rb b/test/unit/repository_filesystem_test.rb
index 1a4dfc737..dd6546518 100644
--- a/test/unit/repository_filesystem_test.rb
+++ b/test/unit/repository_filesystem_test.rb
@@ -47,8 +47,7 @@ class RepositoryFilesystemTest < ActiveSupport::TestCase
def test_blank_root_directory_error_message_fr
set_language_if_valid 'fr'
- str = "R\xc3\xa9pertoire racine doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "R\xc3\xa9pertoire racine doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Filesystem.new(
:project => @project,
:url => "",
diff --git a/test/unit/repository_git_test.rb b/test/unit/repository_git_test.rb
index c7836fe06..94e5747cc 100644
--- a/test/unit/repository_git_test.rb
+++ b/test/unit/repository_git_test.rb
@@ -28,8 +28,8 @@ class RepositoryGitTest < ActiveSupport::TestCase
NUM_REV = 28
NUM_HEAD = 6
- FELIX_HEX = "Felix Sch\xC3\xA4fer"
- CHAR_1_HEX = "\xc3\x9c"
+ FELIX_HEX = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8')
+ CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
## Git, Mercurial and CVS path encodings are binary.
## Subversion supports URL encoding for path.
@@ -47,10 +47,6 @@ class RepositoryGitTest < ActiveSupport::TestCase
:path_encoding => 'ISO-8859-1'
)
assert @repository
- @char_1 = CHAR_1_HEX.dup
- if @char_1.respond_to?(:force_encoding)
- @char_1.force_encoding('UTF-8')
- end
end
def test_blank_path_to_repository_error_message
@@ -66,8 +62,7 @@ class RepositoryGitTest < ActiveSupport::TestCase
def test_blank_path_to_repository_error_message_fr
set_language_if_valid 'fr'
- str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Git.new(
:project => @project,
:url => "",
@@ -450,14 +445,14 @@ class RepositoryGitTest < ActiveSupport::TestCase
else
# latin-1 encoding path
changesets = @repository.latest_changesets(
- "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
+ "latin-1-dir/test-#{CHAR_1_HEX}-2.txt", '64f1f3e89')
assert_equal [
'64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
'4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets(
- "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
+ "latin-1-dir/test-#{CHAR_1_HEX}-2.txt", '64f1f3e89', 1)
assert_equal [
'64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
], changesets.collect(&:revision)
@@ -475,7 +470,7 @@ class RepositoryGitTest < ActiveSupport::TestCase
@project.reload
assert_equal NUM_REV, @repository.changesets.count
changesets = @repository.latest_changesets(
- "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
+ "latin-1-dir/test-#{CHAR_1_HEX}-subdir", '1ca7f5ed')
assert_equal [
'1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
], changesets.collect(&:revision)
@@ -538,13 +533,9 @@ class RepositoryGitTest < ActiveSupport::TestCase
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
- str_felix_hex = FELIX_HEX.dup
- if str_felix_hex.respond_to?(:force_encoding)
- str_felix_hex.force_encoding('UTF-8')
- end
c = @repository.changesets.find_by_revision(
'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
- assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
+ assert_equal "#{FELIX_HEX} <felix@fachschaften.org>", c.committer
end
def test_previous
diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb
index 9762e47a9..0518055a2 100644
--- a/test/unit/repository_mercurial_test.rb
+++ b/test/unit/repository_mercurial_test.rb
@@ -24,7 +24,9 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
NUM_REV = 34
- CHAR_1_HEX = "\xc3\x9c"
+
+ CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
+ BRANCH_CHAR_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
def setup
@project = Project.find(3)
@@ -34,16 +36,6 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
:path_encoding => 'ISO-8859-1'
)
assert @repository
- @char_1 = CHAR_1_HEX.dup
- @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
- @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
- @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
- if @char_1.respond_to?(:force_encoding)
- @char_1.force_encoding('UTF-8')
- @tag_char_1.force_encoding('UTF-8')
- @branch_char_0.force_encoding('UTF-8')
- @branch_char_1.force_encoding('UTF-8')
- end
end
def test_blank_path_to_repository_error_message
@@ -59,8 +51,7 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
def test_blank_path_to_repository_error_message_fr
set_language_if_valid 'fr'
- str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Mercurial.new(
:project => @project,
:url => "",
@@ -362,11 +353,11 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
assert_equal NUM_REV, @repository.changesets.count
if @repository.scm.class.client_version_above?([1, 6])
- changesets = @repository.latest_changesets('', @branch_char_1)
+ changesets = @repository.latest_changesets('', BRANCH_CHAR_1)
assert_equal %w|27 26|, changesets.collect(&:revision)
end
- changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
+ changesets = @repository.latest_changesets("latin-1-dir/test-#{CHAR_1_HEX}-subdir", BRANCH_CHAR_1)
assert_equal %w|27|, changesets.collect(&:revision)
end
@@ -429,8 +420,8 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
scmid3 = scmid_for_assert(hex3, is_short_scmid)
assert_equal 1, c3.size
assert_equal 'A', c3[0].action
- assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
- assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
+ assert_equal "/latin-1-dir/test-#{CHAR_1_HEX}-1.txt", c3[0].path
+ assert_equal "/latin-1-dir/test-#{CHAR_1_HEX}.txt", c3[0].from_path
assert_equal scmid3, c3[0].from_revision
end
private :assert_copied_files
diff --git a/test/unit/repository_subversion_test.rb b/test/unit/repository_subversion_test.rb
index d9b9a15f4..2fe50da14 100644
--- a/test/unit/repository_subversion_test.rb
+++ b/test/unit/repository_subversion_test.rb
@@ -202,13 +202,7 @@ class RepositorySubversionTest < ActiveSupport::TestCase
def test_log_encoding_ignore_setting
with_settings :commit_logs_encoding => 'windows-1252' do
- s1 = "\xC2\x80"
- s2 = "\xc3\x82\xc2\x80"
- if s1.respond_to?(:force_encoding)
- s1.force_encoding('ISO-8859-1')
- s2.force_encoding('UTF-8')
- assert_equal s1.encode('UTF-8'), s2
- end
+ s2 = "\xc3\x82\xc2\x80".force_encoding('UTF-8')
c = Changeset.new(:repository => @repository,
:comments => s2,
:revision => '123',
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb
index 2de4972dc..9537e50a6 100644
--- a/test/unit/repository_test.rb
+++ b/test/unit/repository_test.rb
@@ -54,8 +54,7 @@ class RepositoryTest < ActiveSupport::TestCase
def test_blank_log_encoding_error_message_fr
set_language_if_valid 'fr'
- str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)"
- str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
+ str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
repo = Repository::Bazaar.new(
:project => Project.find(3),
:url => "/test"
@@ -175,7 +174,7 @@ class RepositoryTest < ActiveSupport::TestCase
def test_destroy_should_delete_parents_associations
changeset = Changeset.find(102)
- changeset.parents = Changeset.where(:id => [100, 101]).all
+ changeset.parents = Changeset.where(:id => [100, 101]).to_a
assert_difference 'Changeset.connection.select_all("select * from changeset_parents").count', -2 do
Repository.find(10).destroy
end
@@ -183,7 +182,7 @@ class RepositoryTest < ActiveSupport::TestCase
def test_destroy_should_delete_issues_associations
changeset = Changeset.find(102)
- changeset.issues = Issue.where(:id => [1, 2]).all
+ changeset.issues = Issue.where(:id => [1, 2]).to_a
assert_difference 'Changeset.connection.select_all("select * from changesets_issues").count', -2 do
Repository.find(10).destroy
end
diff --git a/test/unit/role_test.rb b/test/unit/role_test.rb
index 710120dab..e1ba993ee 100644
--- a/test/unit/role_test.rb
+++ b/test/unit/role_test.rb
@@ -21,16 +21,16 @@ class RoleTest < ActiveSupport::TestCase
fixtures :roles, :workflows, :trackers
def test_sorted_scope
- assert_equal Role.all.sort, Role.sorted.all
+ assert_equal Role.all.sort, Role.sorted.to_a
end
def test_givable_scope
- assert_equal Role.all.reject(&:builtin?).sort, Role.givable.all
+ assert_equal Role.all.reject(&:builtin?).sort, Role.givable.to_a
end
def test_builtin_scope
- assert_equal Role.all.select(&:builtin?).sort, Role.builtin(true).all.sort
- assert_equal Role.all.reject(&:builtin?).sort, Role.builtin(false).all.sort
+ assert_equal Role.all.select(&:builtin?).sort, Role.builtin(true).to_a.sort
+ assert_equal Role.all.reject(&:builtin?).sort, Role.builtin(false).to_a.sort
end
def test_copy_from
diff --git a/test/unit/tracker_test.rb b/test/unit/tracker_test.rb
index 64f1078d1..70d892b77 100644
--- a/test/unit/tracker_test.rb
+++ b/test/unit/tracker_test.rb
@@ -21,7 +21,7 @@ class TrackerTest < ActiveSupport::TestCase
fixtures :trackers, :workflows, :issue_statuses, :roles, :issues
def test_sorted_scope
- assert_equal Tracker.all.sort, Tracker.sorted.all
+ assert_equal Tracker.all.sort, Tracker.sorted.to_a
end
def test_named_scope
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 187ec7c8b..df0e79f18 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -27,6 +27,8 @@ class UserTest < ActiveSupport::TestCase
:groups_users,
:enabled_modules
+ include Redmine::I18n
+
def setup
@admin = User.find(1)
@jsmith = User.find(2)
@@ -34,8 +36,9 @@ class UserTest < ActiveSupport::TestCase
end
def test_sorted_scope_should_sort_user_by_display_name
- assert_equal User.all.map(&:name).map(&:downcase).sort,
- User.sorted.map(&:name).map(&:downcase)
+ # Use .active to ignore anonymous with localized display name
+ assert_equal User.active.map(&:name).map(&:downcase).sort,
+ User.active.sorted.map(&:name).map(&:downcase)
end
def test_generate
@@ -853,29 +856,61 @@ class UserTest < ActiveSupport::TestCase
end
def test_roles_for_project_with_non_member_with_public_project_should_return_non_member
+ set_language_if_valid 'en'
roles = User.find(8).roles_for_project(Project.find(1))
assert_equal ["Non member"], roles.map(&:name)
end
- def test_roles_for_project_with_non_member_with_public_project_should_return_no_roles
+ def test_roles_for_project_with_non_member_with_public_project_and_override_should_return_override_roles
+ project = Project.find(1)
+ Member.create!(:project => project, :principal => Group.non_member, :role_ids => [1, 2])
+ roles = User.find(8).roles_for_project(project)
+ assert_equal ["Developer", "Manager"], roles.map(&:name).sort
+ end
+
+ def test_roles_for_project_with_non_member_with_private_project_should_return_no_roles
Project.find(1).update_attribute :is_public, false
roles = User.find(8).roles_for_project(Project.find(1))
assert_equal [], roles.map(&:name)
end
+ def test_roles_for_project_with_non_member_with_private_project_and_override_should_return_no_roles
+ project = Project.find(1)
+ project.update_attribute :is_public, false
+ Member.create!(:project => project, :principal => Group.non_member, :role_ids => [1, 2])
+ roles = User.find(8).roles_for_project(project)
+ assert_equal [], roles.map(&:name).sort
+ end
+
def test_roles_for_project_with_anonymous_with_public_project_should_return_anonymous
+ set_language_if_valid 'en'
roles = User.anonymous.roles_for_project(Project.find(1))
assert_equal ["Anonymous"], roles.map(&:name)
end
- def test_roles_for_project_with_anonymous_with_public_project_should_return_no_roles
+ def test_roles_for_project_with_anonymous_with_public_project_and_override_should_return_override_roles
+ project = Project.find(1)
+ Member.create!(:project => project, :principal => Group.anonymous, :role_ids => [1, 2])
+ roles = User.anonymous.roles_for_project(project)
+ assert_equal ["Developer", "Manager"], roles.map(&:name).sort
+ end
+
+ def test_roles_for_project_with_anonymous_with_private_project_should_return_no_roles
Project.find(1).update_attribute :is_public, false
roles = User.anonymous.roles_for_project(Project.find(1))
assert_equal [], roles.map(&:name)
end
+ def test_roles_for_project_with_anonymous_with_private_project_and_override_should_return_no_roles
+ project = Project.find(1)
+ project.update_attribute :is_public, false
+ Member.create!(:project => project, :principal => Group.anonymous, :role_ids => [1, 2])
+ roles = User.anonymous.roles_for_project(project)
+ assert_equal [], roles.map(&:name).sort
+ end
+
def test_projects_by_role_for_user_with_role
user = User.find(2)
assert_kind_of Hash, user.projects_by_role
@@ -1059,10 +1094,10 @@ class UserTest < ActiveSupport::TestCase
end
should "return true only if user has permission on all these projects" do
- assert_equal true, @admin.allowed_to?(:view_project, Project.all)
- assert_equal false, @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2)
- assert_equal true, @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere
- assert_equal false, @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers
+ assert_equal true, @admin.allowed_to?(:view_project, Project.all.to_a)
+ assert_equal false, @dlopper.allowed_to?(:view_project, Project.all.to_a) #cannot see Project(2)
+ assert_equal true, @jsmith.allowed_to?(:edit_issues, @jsmith.projects.to_a) #Manager or Developer everywhere
+ assert_equal false, @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects.to_a) #Dev cannot delete_issue_watchers
end
should "behave correctly with arrays of 1 project" do
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb
index 55a315af0..a1dddd905 100644
--- a/test/unit/version_test.rb
+++ b/test/unit/version_test.rb
@@ -124,7 +124,7 @@ class VersionTest < ActiveSupport::TestCase
v5 = Version.create!(:project_id => 1, :name => 'v5', :effective_date => '2012-07-02')
assert_equal [v5, v3, v1, v2, v4], [v1, v2, v3, v4, v5].sort
- assert_equal [v5, v3, v1, v2, v4], Version.sorted.all
+ assert_equal [v5, v3, v1, v2, v4], Version.sorted.to_a
end
def test_completed_should_be_false_when_due_today
diff --git a/test/unit/wiki_test.rb b/test/unit/wiki_test.rb
index e363b4134..a852b2393 100644
--- a/test/unit/wiki_test.rb
+++ b/test/unit/wiki_test.rb
@@ -78,8 +78,7 @@ class WikiTest < ActiveSupport::TestCase
end
def test_titleize
- ja_test = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
- ja_test.force_encoding('UTF-8') if ja_test.respond_to?(:force_encoding)
+ ja_test = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
assert_equal ja_test, Wiki.titleize(ja_test)
end