Get all the tests passing under ruby 1.9

This commit is contained in:
Tom Hughes 2012-05-27 13:50:41 +01:00
parent df02008ee9
commit 9813d9f1e4
14 changed files with 61 additions and 44 deletions

View file

@ -4,6 +4,9 @@ source 'http://rubygems.org'
# Require rails # Require rails
gem 'rails', '3.2.3' 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 # Require the postgres database driver
gem 'pg' gem 'pg'
@ -47,6 +50,7 @@ gem 'memcached', '>= 1.4.1'
# Gems needed for running tests # Gems needed for running tests
group :test do group :test do
gem 'timecop' gem 'timecop'
gem 'minitest', :platforms => :ruby_19
end end
# Gems needed for compiling assets # Gems needed for compiling assets

View file

@ -30,6 +30,7 @@ GEM
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
arel (3.0.2) arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.0) builder (3.0.0)
cocaine (0.2.1) cocaine (0.2.1)
coffee-rails (3.2.2) coffee-rails (3.2.2)
@ -68,6 +69,7 @@ GEM
treetop (~> 1.4.8) treetop (~> 1.4.8)
memcached (1.4.1) memcached (1.4.1)
mime-types (1.18) mime-types (1.18)
minitest (3.0.1)
multi_json (1.3.4) multi_json (1.3.4)
multipart-post (1.1.5) multipart-post (1.1.5)
nokogiri (1.5.2) nokogiri (1.5.2)
@ -154,6 +156,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
SystemTimer (>= 1.1.3) SystemTimer (>= 1.1.3)
bigdecimal
coffee-rails (~> 3.2.1) coffee-rails (~> 3.2.1)
composite_primary_keys (>= 5.0.0) composite_primary_keys (>= 5.0.0)
deadlock_retry (>= 1.2.0) deadlock_retry (>= 1.2.0)
@ -165,6 +168,7 @@ DEPENDENCIES
jquery-rails jquery-rails
libxml-ruby (>= 2.0.5) libxml-ruby (>= 2.0.5)
memcached (>= 1.4.1) memcached (>= 1.4.1)
minitest
open_id_authentication (>= 1.1.0) open_id_authentication (>= 1.1.0)
openstreetmap-oauth-plugin (>= 0.4.0.1) openstreetmap-oauth-plugin (>= 0.4.0.1)
paperclip (~> 2.0) paperclip (~> 2.0)

View file

@ -423,7 +423,7 @@ class AmfController < ApplicationController
# Remove any elements where 2 seconds doesn't elapse before next one # 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) } revdates.delete_if { |d| revdates.include?(d+1) or revdates.include?(d+2) }
# Collect all in one nested array # 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! revdates.uniq!
return ['way', wayid, revdates] return ['way', wayid, revdates]
@ -437,7 +437,7 @@ class AmfController < ApplicationController
def getnode_history(nodeid) #:doc: def getnode_history(nodeid) #:doc:
begin begin
history = Node.find(nodeid).old_nodes.unredacted.reverse.collect do |old_node| 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 end
return ['node', nodeid, history] return ['node', nodeid, history]
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View file

@ -400,7 +400,7 @@ en:
post: Post post: Post
when: When when: When
comment: Comment comment: Comment
ago: %{ago} ago ago: "%{ago} ago"
newer_comments: "Newer Comments" newer_comments: "Newer Comments"
older_comments: "Older Comments" older_comments: "Older Comments"
export: export:

View file

@ -8,18 +8,20 @@ module Potlatch
# Return two-byte integer # Return two-byte integer
def self.getint(s) def self.getint(s)
s.getc*256+s.getc s.getbyte*256+s.getbyte
end end
# Return four-byte long # Return four-byte long
def self.getlong(s) 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 end
# Return string with two-byte length # Return string with two-byte length
def self.getstring(s) def self.getstring(s)
len=s.getc*256+s.getc len=s.getbyte*256+s.getbyte
s.read(len) str=s.read(len)
str.force_encoding("UTF-8") if str.respond_to?("force_encoding")
str
end end
# Return eight-byte double-precision float # Return eight-byte double-precision float
@ -45,23 +47,23 @@ module Potlatch
if (key=='') then break end if (key=='') then break end
arr[key]=getvalue(s) arr[key]=getvalue(s)
end end
s.getc # skip the 9 'end of object' value s.getbyte # skip the 9 'end of object' value
arr arr
end end
# Parse and get value # Parse and get value
def self.getvalue(s) def self.getvalue(s)
case s.getc case s.getbyte
when 0; return getdouble(s) # number 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 2; return getstring(s) # string
when 3; return getobject(s) # object/hash when 3; return getobject(s) # object/hash
when 5; return nil # null when 5; return nil # null
when 6; return nil # undefined when 6; return nil # undefined
when 8; s.read(4) # mixedArray when 8; s.read(4) # mixedArray
return getobject(s) # | return getobject(s) # |
when 10;return getarray(s) # array when 10; return getarray(s) # array
else; return nil # error else; return nil # error
end end
end end
@ -134,7 +136,7 @@ module Potlatch
# Skip headers # Skip headers
AMF.getint(@request).times do # Read number of headers and loop AMF.getint(@request).times do # Read number of headers and loop
AMF.getstring(@request) # | skip name AMF.getstring(@request) # | skip name
req.getc # | skip boolean req.getbyte # | skip boolean
AMF.getvalue(@request) # | skip value AMF.getvalue(@request) # | skip value
end end

View file

@ -1,16 +1,21 @@
require 'iconv'
module UTF8 module UTF8
## ##
# Checks that a string is valid UTF-8 by trying to convert it to UTF-8 # 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. # using the iconv library, which is in the standard library.
def self.valid?(str) if String.new.respond_to?("valid_encoding?")
return true if str.nil? def self.valid?(str)
Iconv.conv("UTF-8", "UTF-8", str) return true if str.nil?
return true return str.valid_encoding?
end
rescue else
return false require 'iconv'
end
end
def self.valid?(str)
return true if str.nil?
Iconv.conv("UTF-8", "UTF-8", str)
return true
rescue
return false
end
end
end

View file

@ -295,11 +295,10 @@ class AmfControllerTest < ActionController::TestCase
assert_equal latest.id, history[1] assert_equal latest.id, history[1]
# We use dates rather than version numbers here, because you might # We use dates rather than version numbers here, because you might
# have moved a node within a way (i.e. way version not incremented). # 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 # The timestamp is +1 because we say "give me the revision of 15:33:02",
# revision of 15:33:02", but that might actually include changes at # but that might actually include changes at 15:33:02.457.
# 15:33:02.457. assert_equal (latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].first[0]
assert_equal latest.timestamp.succ.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]
assert_equal oldest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), history[2].last[0]
end end
def test_getway_history_nonexistent def test_getway_history_nonexistent
@ -331,10 +330,10 @@ class AmfControllerTest < ActionController::TestCase
assert_equal history[1], latest.id, assert_equal history[1], latest.id,
'second element should be the input node ID' 'second element should be the input node ID'
assert_equal history[2].first[0], 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' 'first element in third element (array) should be the latest version'
assert_equal history[2].last[0], 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' 'last element in third element (array) should be the initial version'
end end

View file

@ -104,7 +104,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
end end
assert_select "body", :count => 1 do assert_select "body", :count => 1 do
assert_select "div#content", :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 # We don't care about the layout, we just care about the form fields
# that are available # that are available
assert_select "form[action='/diary/new']", :count => 1 do assert_select "form[action='/diary/new']", :count => 1 do

View file

@ -212,7 +212,7 @@ class UserControllerTest < ActionController::TestCase
register_email = ActionMailer::Base.deliveries.first register_email = ActionMailer::Base.deliveries.first
assert_equal register_email.to[0], new_email 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 # Check the page
assert_redirected_to :action => 'login', :referer => nil assert_redirected_to :action => 'login', :referer => nil

View file

@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'
class OAuthTest < ActionController::IntegrationTest class OAuthTest < ActionController::IntegrationTest
fixtures :users, :client_applications fixtures :users, :client_applications, :gpx_files
include OAuth::Helper include OAuth::Helper

View file

@ -71,7 +71,7 @@ class UserCreationTest < ActionController::IntegrationTest
assert_equal register_email.to[0], new_email assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct # 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 # Check the page
assert_response :success assert_response :success
@ -114,7 +114,7 @@ class UserCreationTest < ActionController::IntegrationTest
# Check that the confirm account url is correct # Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)") confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
register_email.parts.each do |part| register_email.parts.each do |part|
assert_match(confirm_regex, part.body) assert_match confirm_regex, part.body.to_s
end end
confirm_string = register_email.parts[0].body.match(confirm_regex)[1] 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 # Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)") confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
register_email.parts.each do |part| register_email.parts.each do |part|
assert_match(confirm_regex, part.body) assert_match confirm_regex, part.body.to_s
end end
confirm_string = register_email.parts[0].body.match(confirm_regex)[1] confirm_string = register_email.parts[0].body.match(confirm_regex)[1]

View file

@ -7,7 +7,7 @@ class ActiveSupport::TestCase
# Load standard fixtures needed to test API methods # Load standard fixtures needed to test API methods
def self.api_fixtures def self.api_fixtures
#print "setting up the api_fixtures" #print "setting up the api_fixtures"
fixtures :users, :changesets, :changeset_tags fixtures :users, :user_roles, :changesets, :changeset_tags
fixtures :current_nodes, :nodes fixtures :current_nodes, :nodes
set_fixture_class :current_nodes => 'Node' set_fixture_class :current_nodes => 'Node'

View file

@ -19,7 +19,7 @@ class MessageTest < ActiveSupport::TestCase
assert message.errors[:title].any? assert message.errors[:title].any?
assert message.errors[:body].any? assert message.errors[:body].any?
assert message.errors[:sent_on].any? assert message.errors[:sent_on].any?
assert true, message.message_read assert !message.message_read
end end
def test_validating_msgs def test_validating_msgs
@ -76,6 +76,9 @@ class MessageTest < ActiveSupport::TestCase
db_msg = msg.class.find(msg.id) db_msg = msg.class.find(msg.id)
assert_equal char, db_msg.title, "Database silently truncated message title" 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 rescue ActiveRecord::RecordInvalid
# because we only test invalid sequences it is OK to barf on them # because we only test invalid sequences it is OK to barf on them
end end

View file

@ -52,7 +52,7 @@ class UserTest < ActiveSupport::TestCase
ok.each do |name| ok.each do |name|
user = users(:normal_user) user = users(:normal_user)
user.email = name user.email = name
assert user.valid?(:save), user.errors.full_messages assert user.valid?(:save), user.errors.full_messages.join(",")
end end
bad.each do |name| bad.each do |name|