lang.close
end
end
+
+ desc 'Checks interpolation arguments in locals against en.yml'
+ task :check_interpolation do
+ dir = ENV['DIR'] || './config/locales'
+ en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en']
+ files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
+ files.each do |file|
+ file_strings = YAML.load(File.read(file))
+ file_strings = file_strings[file_strings.keys.first]
+
+ file_strings.each do |key, string|
+ next unless string.is_a?(String)
+ string.scan /%\{\w+\}/ do |match|
+ unless en_strings[key].nil? || en_strings[key].include?(match)
+ puts "#{file}: #{key} uses #{match} not found in en.yml"
+ end
+ end
+ end
+ end
+ end
+ desc 'Checks interpolation arguments in locals against en.yml'
+ task :check_interpolation do
+ dir = ENV['DIR'] || './config/locales'
+ en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en']
+ files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
+ files.each do |file|
+ file_strings = YAML.load(File.read(file))
+ file_strings = file_strings[file_strings.keys.first]
+
+ file_strings.each do |key, string|
+ next unless string.is_a?(String)
+ string.scan /%\{\w+\}/ do |match|
+ unless en_strings[key].nil? || en_strings[key].include?(match)
+ puts "#{file}: #{key} uses #{match} not found in en.yml"
+ end
+ end
+ end
+ end
+ end
+
desc <<-END_DESC
Removes a translation string from all locale file (only works for top-level childless non-multiline keys, probably doesn\'t work on windows).
:sibling => { :tag => 'td', :content => /watcher =/ }
end
+ def test_annotate_at_given_revision
+ @repository.fetch_changesets
+ @repository.reload
+ get :annotate, :id => PRJ_ID, :rev => 'deff7',
+ :path => ['sources', 'watchers_controller.rb']
+ assert_response :success
+ assert_template 'annotate'
+ assert_tag :tag => 'h2', :content => /@ deff712f/
+ end
+
def test_annotate_binary_file
- get :annotate, :id => 3, :path => ['images', 'edit.png']
+ get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
assert_response 500
assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
- :content => /can not be annotated/
+ :content => /cannot be annotated/
+ end
+
+ def test_annotate_latin_1
+ if @ruby19_non_utf8_pass
+ puts_ruby19_non_utf8_pass()
+ else
+ with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
+ ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
+ get :annotate, :id => PRJ_ID,
+ :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
+ assert_tag :tag => 'th',
+ :content => '1',
+ :attributes => { :class => 'line-num' },
+ :sibling => { :tag => 'td',
+ :content => /test-#{@char_1}.txt/ }
+ end
+ end
+ end
+ end
+
+ def test_revision
+ @repository.fetch_changesets
+ @repository.reload
+ ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
+ get :revision, :id => PRJ_ID, :rev => r
+ assert_response :success
+ assert_template 'revision'
+ end
+ end
+
+ def test_empty_revision
+ @repository.fetch_changesets
+ @repository.reload
+ ['', ' ', nil].each do |r|
+ get :revision, :id => PRJ_ID, :rev => r
+ assert_response 404
+ assert_error_tag :content => /was not found/
+ end
+ end
+
+ private
+
+ def puts_ruby19_non_utf8_pass
+ puts "TODO: This test fails in Ruby 1.9 " +
+ "and Encoding.default_external is not UTF-8. " +
+ "Current value is '#{Encoding.default_external.to_s}'"
end
+
+ def test_revision
+ @repository.fetch_changesets
+ @repository.reload
+ ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
+ get :revision, :id => 3, :rev => r
+ assert_response :success
+ assert_template 'revision'
+ end
+ end
+
+ def test_empty_revision
+ @repository.fetch_changesets
+ @repository.reload
+ ['', ' ', nil].each do |r|
+ get :revision, :id => 3, :rev => r
+ assert_response 404
+ assert_error_tag :content => /was not found/
+ end
+ end
else
puts "Git test repository NOT FOUND. Skipping functional tests !!!"
def test_fake; assert true end
changeset = Changeset.find_by_revision('10')
assert_nil changeset.next
end
-
+
def test_comments_should_be_converted_to_utf8
- with_settings :commit_logs_encoding => 'ISO-8859-1' do
- c = Changeset.new
- c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
- assert_equal "Texte encodé en ISO-8859-1.", c.comments
+ 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)
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'ISO-8859-1' )
+ assert r
+ c = Changeset.new(:repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :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)
+ 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)
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'UTF-8' )
+ assert r
+ c = Changeset.new(:repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :scmid => '12345',
+ :comments => str1,
+ :committer => str2)
+ assert( c.save )
+ assert_equal "Texte encod? en ISO-8859-1.", c.comments
+ assert_equal "?a?b?c?d?e test", c.committer
+ end
+
+ 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
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'ISO-2022-JP' )
+ assert r
+ c = Changeset.new(:repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :scmid => '12345',
+ :comments => str)
+ assert( c.save )
+ assert_equal "test??test??", c.comments
+ end
+
+ def test_comments_should_be_converted_all_latin1_to_utf8
+ 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
+ proj = Project.find(3)
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'ISO-8859-1' )
+ assert r
+ c = Changeset.new(:repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :scmid => '12345',
+ :comments => s1)
+ assert( c.save )
+ assert_equal s4, c.comments
+ end
+
+ 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)
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'UTF-8' )
+ assert r
+ cs = Changeset.new(
+ :repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :scmid => '12345',
+ :comments => "test")
+ assert(cs.save)
+ ch = Change.new(
+ :changeset => cs,
+ :action => "A",
+ :path => str1,
+ :from_path => str2,
+ :from_revision => "345")
+ assert(ch.save)
+ assert_equal "Texte encod? en ISO-8859-1", ch.path
+ assert_equal "?a?b?c?d?e test", ch.from_path
end
-
- def test_invalid_utf8_sequences_in_comments_should_be_stripped
- c = Changeset.new
- c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
- assert_equal "Texte encod en ISO-8859-1.", c.comments
+
+ def test_comments_nil
+ proj = Project.find(3)
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'ISO-8859-1' )
+ assert r
+ c = Changeset.new(:repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :scmid => '12345',
+ :comments => nil,
+ :committer => nil)
+ 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
+ end
+
+ def test_comments_empty
+ proj = Project.find(3)
+ r = Repository::Bazaar.create!(
+ :project => proj,
+ :url => '/tmp/test/bazaar',
+ :log_encoding => 'ISO-8859-1' )
+ assert r
+ c = Changeset.new(:repository => r,
+ :committed_on => Time.now,
+ :revision => '123',
+ :scmid => '12345',
+ :comments => "",
+ :committer => "")
+ 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
+ end
+
+ def test_identifier
+ c = Changeset.find_by_revision('1')
+ assert_equal c.revision, c.identifier
end
+
+ def test_identifier
+ c = Changeset.find_by_revision('1')
+ assert_equal c.revision, c.identifier
+ end
end
assert_equal page, wiki.find_page('Another_page')
assert_equal page, wiki.find_page('Another page')
assert_equal page, wiki.find_page('ANOTHER page')
+
+ page = WikiPage.find(10)
+ assert_equal page, wiki.find_page('Этика_менеджмента')
end
-
+
+ def test_find_page_with_cyrillic_characters
+ wiki = Wiki.find(1)
+ page = WikiPage.find(10)
+ assert_equal page, wiki.find_page('Этика_менеджмента')
+ end
+
+ def test_find_page_with_backslashes
+ wiki = Wiki.find(1)
+ page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09')
+ assert_equal page, wiki.find_page('2009\\02\\09')
+ end
+
+ def test_find_page_without_redirect
+ wiki = Wiki.find(1)
+ page = wiki.find_page('Another_page')
+ assert_not_nil page
+ assert_equal 'Another_page', page.title
+ assert_equal false, wiki.page_found_with_redirect?
+ end
+
+ def test_find_page_with_redirect
+ wiki = Wiki.find(1)
+ WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
+ page = wiki.find_page('Old_title')
+ assert_not_nil page
+ assert_equal 'Another_page', page.title
+ assert_equal true, wiki.page_found_with_redirect?
+ end
+
def test_titleize
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
assert_equal 'テスト', Wiki.titleize('テスト')