diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-02-21 11:04:50 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-02-21 11:04:50 +0000 |
commit | fe28193e4eb9af2dc5262535a29ffde5249568fc (patch) | |
tree | bd4cf3a9fbada98e58e510ca0e25c42bf00676a7 /test/unit | |
parent | 9a986ac0a51fe844eee816325e6a6d4122136d9a (diff) | |
download | redmine-fe28193e4eb9af2dc5262535a29ffde5249568fc.tar.gz redmine-fe28193e4eb9af2dc5262535a29ffde5249568fc.zip |
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2493 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/default_data_test.rb | 3 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 50 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 6 | ||||
-rw-r--r-- | test/unit/lib/redmine/i18n_test.rb | 100 | ||||
-rw-r--r-- | test/unit/mailer_test.rb | 19 | ||||
-rw-r--r-- | test/unit/project_test.rb | 4 | ||||
-rw-r--r-- | test/unit/repository_test.rb | 2 | ||||
-rw-r--r-- | test/unit/user_test.rb | 2 | ||||
-rw-r--r-- | test/unit/version_test.rb | 2 | ||||
-rw-r--r-- | test/unit/wiki_page_test.rb | 6 |
10 files changed, 131 insertions, 63 deletions
diff --git a/test/unit/default_data_test.rb b/test/unit/default_data_test.rb index 39616135e..ae637ba39 100644 --- a/test/unit/default_data_test.rb +++ b/test/unit/default_data_test.rb @@ -18,6 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class DefaultDataTest < Test::Unit::TestCase + include Redmine::I18n fixtures :roles def test_no_data @@ -30,7 +31,7 @@ class DefaultDataTest < Test::Unit::TestCase end def test_load - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| begin Role.delete_all("builtin = 0") Tracker.delete_all diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index c72ab1706..c1b30c5f0 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2009 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -20,6 +20,8 @@ require File.dirname(__FILE__) + '/../../test_helper' class ApplicationHelperTest < HelperTestCase include ApplicationHelper include ActionView::Helpers::TextHelper + include ActionView::Helpers::DateHelper + fixtures :projects, :roles, :enabled_modules, :users, :repositories, :changesets, :trackers, :issue_statuses, :issues, :versions, :documents, @@ -390,50 +392,14 @@ EXPECTED Setting.text_formatting = 'textile' end - def test_date_format_default - today = Date.today - Setting.date_format = '' - assert_equal l_date(today), format_date(today) - end - - def test_date_format - today = Date.today - Setting.date_format = '%d %m %Y' - assert_equal today.strftime('%d %m %Y'), format_date(today) - end - - def test_time_format_default - now = Time.now - Setting.date_format = '' - Setting.time_format = '' - assert_equal l_datetime(now), format_time(now) - assert_equal l_time(now), format_time(now, false) - end - - def test_time_format - 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) - assert_equal now.strftime('%H %M'), format_time(now, false) - end - - def test_utc_time_format - now = Time.now.utc - Setting.date_format = '%d %m %Y' - Setting.time_format = '%H %M' - assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now) - assert_equal Time.now.strftime('%H %M'), format_time(now, false) - end - def test_due_date_distance_in_words to_test = { Date.today => 'Due in 0 days', Date.today + 1 => 'Due in 1 day', - Date.today + 100 => 'Due in 100 days', - Date.today + 20000 => 'Due in 20000 days', + Date.today + 100 => 'Due in about 3 months', + Date.today + 20000 => 'Due in over 55 years', Date.today - 1 => '1 day late', - Date.today - 100 => '100 days late', - Date.today - 20000 => '20000 days late', + Date.today - 100 => 'about 3 months late', + Date.today - 20000 => 'over 55 years late', } to_test.each do |date, expected| assert_equal expected, due_date_distance_in_words(date) diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index bfe29f552..7013d2c0d 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -47,15 +47,15 @@ class IssueTest < Test::Unit::TestCase assert issue.available_custom_fields.include?(field) # No value for the custom field assert !issue.save - assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) + assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) # Blank value issue.custom_field_values = { field.id => '' } assert !issue.save - assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) + assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) # Invalid value issue.custom_field_values = { field.id => 'SQLServer' } assert !issue.save - assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) + assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) # Valid value issue.custom_field_values = { field.id => 'PostgreSQL' } assert issue.save diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb new file mode 100644 index 000000000..0335d78b1 --- /dev/null +++ b/test/unit/lib/redmine/i18n_test.rb @@ -0,0 +1,100 @@ +# Redmine - project management software +# Copyright (C) 2006-2009 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../../../test_helper' + +class Redmine::I18nTest < Test::Unit::TestCase + include Redmine::I18n + + def setup + @hook_module = Redmine::Hook + end + + def test_date_format_default + set_language_if_valid 'en' + today = Date.today + Setting.date_format = '' + assert_equal I18n.l(today), format_date(today) + 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) + 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) + 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 + + def test_time_format_default + set_language_if_valid 'en' + now = Time.now + Setting.date_format = '' + Setting.time_format = '' + assert_equal I18n.l(now), format_time(now) + assert_equal I18n.l(now, :format => :time), format_time(now, false) + end + + def test_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) + assert_equal now.strftime('%H %M'), format_time(now, false) + end + + def test_utc_time_format + set_language_if_valid 'en' + now = Time.now.utc + Setting.date_format = '%d %m %Y' + Setting.time_format = '%H %M' + assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now) + assert_equal Time.now.strftime('%H %M'), format_time(now, false) + end + + def test_valid_languages + assert valid_languages.is_a?(Array) + assert valid_languages.first.is_a?(Symbol) + end + + def test_valid_language + to_test = {'fr' => :fr, + 'Fr' => :fr, + 'zh' => :zh, + 'zh-tw' => :"zh-TW", + 'zh-TW' => :"zh-TW", + 'zh-ZZ' => nil } + + to_test.each {|lang, expected| assert_equal expected, find_language(lang)} + end +end diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 141ff40b9..156938963 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -18,6 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class MailerTest < Test::Unit::TestCase + include Redmine::I18n fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories def test_generated_links_in_emails @@ -138,7 +139,7 @@ class MailerTest < Test::Unit::TestCase # test mailer methods for each language def test_issue_add issue = Issue.find(1) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| Setting.default_language = lang.to_s assert Mailer.deliver_issue_add(issue) end @@ -146,7 +147,7 @@ class MailerTest < Test::Unit::TestCase def test_issue_edit journal = Journal.find(1) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| Setting.default_language = lang.to_s assert Mailer.deliver_issue_edit(journal) end @@ -154,7 +155,7 @@ class MailerTest < Test::Unit::TestCase def test_document_added document = Document.find(1) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| Setting.default_language = lang.to_s assert Mailer.deliver_document_added(document) end @@ -162,7 +163,7 @@ class MailerTest < Test::Unit::TestCase def test_attachments_added attachements = [ Attachment.find_by_container_type('Document') ] - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| Setting.default_language = lang.to_s assert Mailer.deliver_attachments_added(attachements) end @@ -170,7 +171,7 @@ class MailerTest < Test::Unit::TestCase def test_news_added news = News.find(:first) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| Setting.default_language = lang.to_s assert Mailer.deliver_news_added(news) end @@ -180,7 +181,7 @@ class MailerTest < Test::Unit::TestCase message = Message.find(:first) recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} recipients = recipients.compact.uniq - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| Setting.default_language = lang.to_s assert Mailer.deliver_message_posted(message, recipients) end @@ -188,7 +189,7 @@ class MailerTest < Test::Unit::TestCase def test_account_information user = User.find(:first) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| user.update_attribute :language, lang.to_s user.reload assert Mailer.deliver_account_information(user, 'pAsswORd') @@ -197,7 +198,7 @@ class MailerTest < Test::Unit::TestCase def test_lost_password token = Token.find(2) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| token.user.update_attribute :language, lang.to_s token.reload assert Mailer.deliver_lost_password(token) @@ -206,7 +207,7 @@ class MailerTest < Test::Unit::TestCase def test_register token = Token.find(1) - GLoc.valid_languages.each do |lang| + valid_languages.each do |lang| token.user.update_attribute :language, lang.to_s token.reload assert Mailer.deliver_register(token) diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 27cff13d6..f579e14ff 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -44,7 +44,7 @@ class ProjectTest < Test::Unit::TestCase @ecookbook.name = ""
assert !@ecookbook.save
assert_equal 1, @ecookbook.errors.count
- assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
+ assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
end
def test_archive
@@ -191,7 +191,7 @@ class ProjectTest < Test::Unit::TestCase child = parent.children.find(3)
assert_equal [1, 2], parent.tracker_ids
- assert_equal [2, 3], child.tracker_ids
+ assert_equal [2, 3], child.trackers.collect(&:id)
assert_kind_of Tracker, parent.rolled_up_trackers.first
assert_equal Tracker.find(1), parent.rolled_up_trackers.first
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 6d4073c79..497eeabfd 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -60,7 +60,7 @@ class RepositoryTest < Test::Unit::TestCase Setting.enabled_scm = ['Darcs', 'Git'] repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost") assert !repository.save - assert_equal :activerecord_error_invalid, repository.errors.on(:type) + assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type) # re-enable Subversion for following tests Setting.delete_all end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index fd3403709..f6d270410 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -59,7 +59,7 @@ class UserTest < Test::Unit::TestCase u.login = 'newuser2'
u.password, u.password_confirmation = "password", "password"
assert !u.save
- assert_equal 'activerecord_error_taken', u.errors.on(:mail)
+ assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:mail)
end
def test_update
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 72f049335..6c5297fc4 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -31,7 +31,7 @@ class VersionTest < Test::Unit::TestCase def test_invalid_effective_date_validation v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01') assert !v.save - assert_equal 'activerecord_error_not_a_date', v.errors.on(:effective_date) + assert_equal I18n.translate('activerecord.errors.messages.not_a_date'), v.errors.on(:effective_date) end def test_progress_should_be_0_with_no_assigned_issues diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index e5ebeeea6..f7f62aec4 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -78,15 +78,15 @@ class WikiPageTest < Test::Unit::TestCase # A page that doesn't exist page.parent_title = 'Unknown title' assert !page.save - assert_equal :activerecord_error_invalid, page.errors.on(:parent_title) + assert_equal I18n.translate('activerecord.errors.messages.invalid'), page.errors.on(:parent_title) # A child page page.parent_title = 'Page_with_an_inline_image' assert !page.save - assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title) + assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title) # The page itself page.parent_title = 'CookBook_documentation' assert !page.save - assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title) + assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title) page.parent_title = 'Another_page' assert page.save |