From: Tom Hughes Date: Sun, 27 May 2012 12:50:41 +0000 (+0100) Subject: Get all the tests passing under ruby 1.9 X-Git-Tag: live~5556 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/9813d9f1e48d575bb0e0b5029dc0ec134a011090?hp=df02008ee970338a992c364419d6f59fdc54e63d Get all the tests passing under ruby 1.9 --- diff --git a/Gemfile b/Gemfile index 0075f1771..76872dfff 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,9 @@ source 'http://rubygems.org' # Require rails gem 'rails', '3.2.3' +# Require things which have moved to gems in ruby 1.9 +gem 'bigdecimal', :platforms => :ruby_19 + # Require the postgres database driver gem 'pg' @@ -47,6 +50,7 @@ gem 'memcached', '>= 1.4.1' # Gems needed for running tests group :test do gem 'timecop' + gem 'minitest', :platforms => :ruby_19 end # Gems needed for compiling assets diff --git a/Gemfile.lock b/Gemfile.lock index 0ea879021..dca0097f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,6 +30,7 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) + bigdecimal (1.1.0) builder (3.0.0) cocaine (0.2.1) coffee-rails (3.2.2) @@ -68,6 +69,7 @@ GEM treetop (~> 1.4.8) memcached (1.4.1) mime-types (1.18) + minitest (3.0.1) multi_json (1.3.4) multipart-post (1.1.5) nokogiri (1.5.2) @@ -154,6 +156,7 @@ PLATFORMS DEPENDENCIES SystemTimer (>= 1.1.3) + bigdecimal coffee-rails (~> 3.2.1) composite_primary_keys (>= 5.0.0) deadlock_retry (>= 1.2.0) @@ -165,6 +168,7 @@ DEPENDENCIES jquery-rails libxml-ruby (>= 2.0.5) memcached (>= 1.4.1) + minitest open_id_authentication (>= 1.1.0) openstreetmap-oauth-plugin (>= 0.4.0.1) paperclip (~> 2.0) diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 091bdea0e..a24ac5265 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -423,7 +423,7 @@ class AmfController < ApplicationController # Remove any elements where 2 seconds doesn't elapse before next one revdates.delete_if { |d| revdates.include?(d+1) or revdates.include?(d+2) } # Collect all in one nested array - revdates.collect! {|d| [d.succ.strftime("%d %b %Y, %H:%M:%S")] + revusers[d.to_i] } + revdates.collect! {|d| [(d + 1).strftime("%d %b %Y, %H:%M:%S")] + revusers[d.to_i] } revdates.uniq! return ['way', wayid, revdates] @@ -437,7 +437,7 @@ class AmfController < ApplicationController def getnode_history(nodeid) #:doc: begin history = Node.find(nodeid).old_nodes.unredacted.reverse.collect do |old_node| - [old_node.timestamp.succ.strftime("%d %b %Y, %H:%M:%S")] + change_user(old_node) + [(old_node.timestamp + 1).strftime("%d %b %Y, %H:%M:%S")] + change_user(old_node) end return ['node', nodeid, history] rescue ActiveRecord::RecordNotFound diff --git a/config/locales/en.yml b/config/locales/en.yml index d5577ff64..7bfda9593 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -400,7 +400,7 @@ en: post: Post when: When comment: Comment - ago: %{ago} ago + ago: "%{ago} ago" newer_comments: "Newer Comments" older_comments: "Older Comments" export: diff --git a/lib/potlatch.rb b/lib/potlatch.rb index 43be2f8b4..919eb0122 100644 --- a/lib/potlatch.rb +++ b/lib/potlatch.rb @@ -8,18 +8,20 @@ module Potlatch # Return two-byte integer def self.getint(s) - s.getc*256+s.getc + s.getbyte*256+s.getbyte end # Return four-byte long def self.getlong(s) - ((s.getc*256+s.getc)*256+s.getc)*256+s.getc + ((s.getbyte*256+s.getbyte)*256+s.getbyte)*256+s.getbyte end # Return string with two-byte length def self.getstring(s) - len=s.getc*256+s.getc - s.read(len) + len=s.getbyte*256+s.getbyte + str=s.read(len) + str.force_encoding("UTF-8") if str.respond_to?("force_encoding") + str end # Return eight-byte double-precision float @@ -45,23 +47,23 @@ module Potlatch if (key=='') then break end arr[key]=getvalue(s) end - s.getc # skip the 9 'end of object' value + s.getbyte # skip the 9 'end of object' value arr end # Parse and get value def self.getvalue(s) - case s.getc + case s.getbyte when 0; return getdouble(s) # number - when 1; return s.getc # boolean + when 1; return s.getbyte # boolean when 2; return getstring(s) # string when 3; return getobject(s) # object/hash - when 5; return nil # null - when 6; return nil # undefined - when 8; s.read(4) # mixedArray - return getobject(s) # | - when 10;return getarray(s) # array - else; return nil # error + when 5; return nil # null + when 6; return nil # undefined + when 8; s.read(4) # mixedArray + return getobject(s) # | + when 10; return getarray(s) # array + else; return nil # error end end @@ -134,7 +136,7 @@ module Potlatch # Skip headers AMF.getint(@request).times do # Read number of headers and loop AMF.getstring(@request) # | skip name - req.getc # | skip boolean + req.getbyte # | skip boolean AMF.getvalue(@request) # | skip value end diff --git a/lib/utf8.rb b/lib/utf8.rb index 90b8f0413..c6e1918af 100644 --- a/lib/utf8.rb +++ b/lib/utf8.rb @@ -1,16 +1,21 @@ -require 'iconv' - module UTF8 ## # Checks that a string is valid UTF-8 by trying to convert it to UTF-8 # using the iconv library, which is in the standard library. - def self.valid?(str) - return true if str.nil? - Iconv.conv("UTF-8", "UTF-8", str) - return true - - rescue - return false - end -end + if String.new.respond_to?("valid_encoding?") + def self.valid?(str) + return true if str.nil? + return str.valid_encoding? + end + else + require 'iconv' + def self.valid?(str) + return true if str.nil? + Iconv.conv("UTF-8", "UTF-8", str) + return true + rescue + return false + end + end +end diff --git a/test/functional/amf_controller_test.rb b/test/functional/amf_controller_test.rb index 46ff71eb7..757acf6ac 100644 --- a/test/functional/amf_controller_test.rb +++ b/test/functional/amf_controller_test.rb @@ -295,11 +295,10 @@ class AmfControllerTest < ActionController::TestCase assert_equal latest.id, history[1] # We use dates rather than version numbers here, because you might # have moved a node within a way (i.e. way version not incremented). - # The timestamp is +1 (timestamp.succ) because we say "give me the - # revision of 15:33:02", but that might actually include changes at - # 15:33:02.457. - assert_equal latest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), history[2].first[0] - assert_equal oldest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), history[2].last[0] + # The timestamp is +1 because we say "give me the revision of 15:33:02", + # but that might actually include changes at 15:33:02.457. + assert_equal (latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].first[0] + assert_equal (oldest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].last[0] end def test_getway_history_nonexistent @@ -331,10 +330,10 @@ class AmfControllerTest < ActionController::TestCase assert_equal history[1], latest.id, 'second element should be the input node ID' assert_equal history[2].first[0], - latest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), + (latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), 'first element in third element (array) should be the latest version' assert_equal history[2].last[0], - nodes(:node_with_versions_v1).timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), + (nodes(:node_with_versions_v1).timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), 'last element in third element (array) should be the initial version' end diff --git a/test/functional/diary_entry_controller_test.rb b/test/functional/diary_entry_controller_test.rb index 724fb48a5..0fa9ea97f 100644 --- a/test/functional/diary_entry_controller_test.rb +++ b/test/functional/diary_entry_controller_test.rb @@ -104,7 +104,7 @@ class DiaryEntryControllerTest < ActionController::TestCase end assert_select "body", :count => 1 do assert_select "div#content", :count => 1 do - assert_select "h1", "New Diary Entry", :count => 1 + assert_select "h1", :text => "New Diary Entry", :count => 1 # We don't care about the layout, we just care about the form fields # that are available assert_select "form[action='/diary/new']", :count => 1 do diff --git a/test/functional/user_controller_test.rb b/test/functional/user_controller_test.rb index 576eb0db9..4379a1d49 100644 --- a/test/functional/user_controller_test.rb +++ b/test/functional/user_controller_test.rb @@ -212,7 +212,7 @@ class UserControllerTest < ActionController::TestCase register_email = ActionMailer::Base.deliveries.first assert_equal register_email.to[0], new_email - assert_match /#{@url}/, register_email.body + assert_match /#{@url}/, register_email.body.to_s # Check the page assert_redirected_to :action => 'login', :referer => nil diff --git a/test/integration/oauth_test.rb b/test/integration/oauth_test.rb index 8639c8e53..2bda77379 100644 --- a/test/integration/oauth_test.rb +++ b/test/integration/oauth_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class OAuthTest < ActionController::IntegrationTest - fixtures :users, :client_applications + fixtures :users, :client_applications, :gpx_files include OAuth::Helper diff --git a/test/integration/user_creation_test.rb b/test/integration/user_creation_test.rb index 3c716e99e..b5b3e91c7 100644 --- a/test/integration/user_creation_test.rb +++ b/test/integration/user_creation_test.rb @@ -71,7 +71,7 @@ class UserCreationTest < ActionController::IntegrationTest assert_equal register_email.to[0], new_email # Check that the confirm account url is correct - assert_match /#{@url}/, register_email.body + assert_match /#{@url}/, register_email.body.to_s # Check the page assert_response :success @@ -114,7 +114,7 @@ class UserCreationTest < ActionController::IntegrationTest # Check that the confirm account url is correct confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)") register_email.parts.each do |part| - assert_match(confirm_regex, part.body) + assert_match confirm_regex, part.body.to_s end confirm_string = register_email.parts[0].body.match(confirm_regex)[1] @@ -211,7 +211,7 @@ class UserCreationTest < ActionController::IntegrationTest # Check that the confirm account url is correct confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)") register_email.parts.each do |part| - assert_match(confirm_regex, part.body) + assert_match confirm_regex, part.body.to_s end confirm_string = register_email.parts[0].body.match(confirm_regex)[1] diff --git a/test/test_helper.rb b/test/test_helper.rb index 59b87da84..703347c9c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,7 +7,7 @@ class ActiveSupport::TestCase # Load standard fixtures needed to test API methods def self.api_fixtures #print "setting up the api_fixtures" - fixtures :users, :changesets, :changeset_tags + fixtures :users, :user_roles, :changesets, :changeset_tags fixtures :current_nodes, :nodes set_fixture_class :current_nodes => 'Node' diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb index 260852aea..3da91de38 100644 --- a/test/unit/message_test.rb +++ b/test/unit/message_test.rb @@ -19,7 +19,7 @@ class MessageTest < ActiveSupport::TestCase assert message.errors[:title].any? assert message.errors[:body].any? assert message.errors[:sent_on].any? - assert true, message.message_read + assert !message.message_read end def test_validating_msgs @@ -76,6 +76,9 @@ class MessageTest < ActiveSupport::TestCase db_msg = msg.class.find(msg.id) assert_equal char, db_msg.title, "Database silently truncated message title" + rescue ArgumentError => ex + assert_equal ex.to_s, "invalid byte sequence in UTF-8" + rescue ActiveRecord::RecordInvalid # because we only test invalid sequences it is OK to barf on them end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 9f04bd1d6..225eca02b 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -52,7 +52,7 @@ class UserTest < ActiveSupport::TestCase ok.each do |name| user = users(:normal_user) user.email = name - assert user.valid?(:save), user.errors.full_messages + assert user.valid?(:save), user.errors.full_messages.join(",") end bad.each do |name|