mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-22 16:56:10 +01:00
Upgraded to Rails 2.1. This can have wide ranging consequences, so please help track down any issues introduced by the upgrade. Requires environment.rb modifications.
Changes you will need to make: * In your environment.rb, you will need to update references to a few files per environment.rb.tmpl * In your environment.rb, you will need to specify the local time zone of the computer that is running your Tracks install. Other notes on my changes: * Modified our code to take advantage of Rails 2.1's slick time zone support. * Upgraded will_paginate for compatibility * Hacked the Selenium on Rails plugin, which has not been updated in some time and does not support Rails 2.1 * Verified that all tests pass on my machine, including Selenium tests -- I'd like confirmation from others, too.
This commit is contained in:
parent
f3bae73868
commit
901a58f8a3
1086 changed files with 51452 additions and 19526 deletions
391
vendor/rails/activeresource/test/base_test.rb
vendored
391
vendor/rails/activeresource/test/base_test.rb
vendored
|
|
@ -1,4 +1,4 @@
|
|||
require "#{File.dirname(__FILE__)}/abstract_unit"
|
||||
require 'abstract_unit'
|
||||
require "fixtures/person"
|
||||
require "fixtures/street_address"
|
||||
require "fixtures/beast"
|
||||
|
|
@ -7,36 +7,49 @@ class BaseTest < Test::Unit::TestCase
|
|||
def setup
|
||||
@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
|
||||
@david = { :id => 2, :name => 'David' }.to_xml(:root => 'person')
|
||||
@greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person')
|
||||
@addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address')
|
||||
@default_request_headers = { 'Content-Type' => 'application/xml' }
|
||||
@rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person")
|
||||
@people = [{ :id => 1, :name => 'Matz' }, { :id => 2, :name => 'David' }].to_xml(:root => 'people')
|
||||
@people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people')
|
||||
@addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses')
|
||||
|
||||
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.get "/people/1.xml", {}, @matz
|
||||
mock.get "/people/2.xml", {}, @david
|
||||
mock.get "/people/3.xml", {'key' => 'value'}, nil, 404
|
||||
mock.put "/people/1.xml", {}, nil, 204
|
||||
mock.delete "/people/1.xml", {}, nil, 200
|
||||
mock.delete "/people/2.xml", {}, nil, 400
|
||||
mock.get "/people/99.xml", {}, nil, 404
|
||||
mock.post "/people.xml", {}, @rick, 201, 'Location' => '/people/5.xml'
|
||||
mock.get "/people.xml", {}, @people
|
||||
mock.get "/people/1/addresses.xml", {}, @addresses
|
||||
mock.get "/people/1/addresses/1.xml", {}, @addy
|
||||
mock.get "/people/1/addresses/2.xml", {}, nil, 404
|
||||
mock.get "/people/2/addresses/1.xml", {}, nil, 404
|
||||
mock.put "/people/1/addresses/1.xml", {}, nil, 204
|
||||
mock.delete "/people/1/addresses/1.xml", {}, nil, 200
|
||||
mock.post "/people/1/addresses.xml", {}, nil, 201, 'Location' => '/people/1/addresses/5'
|
||||
mock.get "/people//addresses.xml", {}, nil, 404
|
||||
mock.get "/people//addresses/1.xml", {}, nil, 404
|
||||
mock.put "/people//addresses/1.xml", {}, nil, 404
|
||||
mock.delete "/people//addresses/1.xml", {}, nil, 404
|
||||
mock.post "/people//addresses.xml", {}, nil, 404
|
||||
mock.get "/people/1.xml", {}, @matz
|
||||
mock.get "/people/2.xml", {}, @david
|
||||
mock.get "/people/Greg.xml", {}, @greg
|
||||
mock.get "/people/4.xml", {'key' => 'value'}, nil, 404
|
||||
mock.put "/people/1.xml", {}, nil, 204
|
||||
mock.delete "/people/1.xml", {}, nil, 200
|
||||
mock.delete "/people/2.xml", {}, nil, 400
|
||||
mock.get "/people/99.xml", {}, nil, 404
|
||||
mock.post "/people.xml", {}, @rick, 201, 'Location' => '/people/5.xml'
|
||||
mock.get "/people.xml", {}, @people
|
||||
mock.get "/people/1/addresses.xml", {}, @addresses
|
||||
mock.get "/people/1/addresses/1.xml", {}, @addy
|
||||
mock.get "/people/1/addresses/2.xml", {}, nil, 404
|
||||
mock.get "/people/2/addresses/1.xml", {}, nil, 404
|
||||
mock.get "/people/Greg/addresses/1.xml", {}, @addy
|
||||
mock.put "/people/1/addresses/1.xml", {}, nil, 204
|
||||
mock.delete "/people/1/addresses/1.xml", {}, nil, 200
|
||||
mock.post "/people/1/addresses.xml", {}, nil, 201, 'Location' => '/people/1/addresses/5'
|
||||
mock.get "/people//addresses.xml", {}, nil, 404
|
||||
mock.get "/people//addresses/1.xml", {}, nil, 404
|
||||
mock.put "/people//addresses/1.xml", {}, nil, 404
|
||||
mock.delete "/people//addresses/1.xml", {}, nil, 404
|
||||
mock.post "/people//addresses.xml", {}, nil, 404
|
||||
mock.head "/people/1.xml", {}, nil, 200
|
||||
mock.head "/people/Greg.xml", {}, nil, 200
|
||||
mock.head "/people/99.xml", {}, nil, 404
|
||||
mock.head "/people/1/addresses/1.xml", {}, nil, 200
|
||||
mock.head "/people/1/addresses/2.xml", {}, nil, 404
|
||||
mock.head "/people/2/addresses/1.xml", {}, nil, 404
|
||||
mock.head "/people/Greg/addresses/1.xml", {}, nil, 200
|
||||
end
|
||||
|
||||
Person.user = nil
|
||||
Person.password = nil
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -63,6 +76,61 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_nil actor.site
|
||||
end
|
||||
|
||||
def test_should_accept_setting_user
|
||||
Forum.user = 'david'
|
||||
assert_equal('david', Forum.user)
|
||||
assert_equal('david', Forum.connection.user)
|
||||
end
|
||||
|
||||
def test_should_accept_setting_password
|
||||
Forum.password = 'test123'
|
||||
assert_equal('test123', Forum.password)
|
||||
assert_equal('test123', Forum.connection.password)
|
||||
end
|
||||
|
||||
def test_should_accept_setting_timeout
|
||||
Forum.timeout = 5
|
||||
assert_equal(5, Forum.timeout)
|
||||
assert_equal(5, Forum.connection.timeout)
|
||||
end
|
||||
|
||||
def test_user_variable_can_be_reset
|
||||
actor = Class.new(ActiveResource::Base)
|
||||
actor.site = 'http://cinema'
|
||||
assert_nil actor.user
|
||||
actor.user = 'username'
|
||||
actor.user = nil
|
||||
assert_nil actor.user
|
||||
assert_nil actor.connection.user
|
||||
end
|
||||
|
||||
def test_password_variable_can_be_reset
|
||||
actor = Class.new(ActiveResource::Base)
|
||||
actor.site = 'http://cinema'
|
||||
assert_nil actor.password
|
||||
actor.password = 'username'
|
||||
actor.password = nil
|
||||
assert_nil actor.password
|
||||
assert_nil actor.connection.password
|
||||
end
|
||||
|
||||
def test_timeout_variable_can_be_reset
|
||||
actor = Class.new(ActiveResource::Base)
|
||||
actor.site = 'http://cinema'
|
||||
assert_nil actor.timeout
|
||||
actor.timeout = 5
|
||||
actor.timeout = nil
|
||||
assert_nil actor.timeout
|
||||
assert_nil actor.connection.timeout
|
||||
end
|
||||
|
||||
def test_credentials_from_site_are_decoded
|
||||
actor = Class.new(ActiveResource::Base)
|
||||
actor.site = 'http://my%40email.com:%31%32%33@cinema'
|
||||
assert_equal("my@email.com", actor.user)
|
||||
assert_equal("123", actor.password)
|
||||
end
|
||||
|
||||
def test_site_reader_uses_superclass_site_until_written
|
||||
# Superclass is Object so returns nil.
|
||||
assert_nil ActiveResource::Base.site
|
||||
|
|
@ -98,12 +166,122 @@ class BaseTest < Test::Unit::TestCase
|
|||
apple = Class.new(fruit)
|
||||
|
||||
fruit.site = 'http://market'
|
||||
assert_equal fruit.site, apple.site, 'subclass did not adopt changes to parent class'
|
||||
assert_equal fruit.site, apple.site, 'subclass did not adopt changes from parent class'
|
||||
|
||||
fruit.site = 'http://supermarket'
|
||||
assert_equal fruit.site, apple.site, 'subclass did not adopt changes to parent class'
|
||||
assert_equal fruit.site, apple.site, 'subclass did not adopt changes from parent class'
|
||||
end
|
||||
|
||||
def test_user_reader_uses_superclass_user_until_written
|
||||
# Superclass is Object so returns nil.
|
||||
assert_nil ActiveResource::Base.user
|
||||
assert_nil Class.new(ActiveResource::Base).user
|
||||
Person.user = 'anonymous'
|
||||
|
||||
# Subclass uses superclass user.
|
||||
actor = Class.new(Person)
|
||||
assert_equal Person.user, actor.user
|
||||
|
||||
# Subclass returns frozen superclass copy.
|
||||
assert !Person.user.frozen?
|
||||
assert actor.user.frozen?
|
||||
|
||||
# Changing subclass user doesn't change superclass user.
|
||||
actor.user = 'david'
|
||||
assert_not_equal Person.user, actor.user
|
||||
|
||||
# Changing superclass user doesn't overwrite subclass user.
|
||||
Person.user = 'john'
|
||||
assert_not_equal Person.user, actor.user
|
||||
|
||||
# Changing superclass user after subclassing changes subclass user.
|
||||
jester = Class.new(actor)
|
||||
actor.user = 'john.doe'
|
||||
assert_equal actor.user, jester.user
|
||||
|
||||
# Subclasses are always equal to superclass user when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
|
||||
fruit.user = 'manager'
|
||||
assert_equal fruit.user, apple.user, 'subclass did not adopt changes from parent class'
|
||||
|
||||
fruit.user = 'client'
|
||||
assert_equal fruit.user, apple.user, 'subclass did not adopt changes from parent class'
|
||||
end
|
||||
|
||||
def test_password_reader_uses_superclass_password_until_written
|
||||
# Superclass is Object so returns nil.
|
||||
assert_nil ActiveResource::Base.password
|
||||
assert_nil Class.new(ActiveResource::Base).password
|
||||
Person.password = 'my-password'
|
||||
|
||||
# Subclass uses superclass password.
|
||||
actor = Class.new(Person)
|
||||
assert_equal Person.password, actor.password
|
||||
|
||||
# Subclass returns frozen superclass copy.
|
||||
assert !Person.password.frozen?
|
||||
assert actor.password.frozen?
|
||||
|
||||
# Changing subclass password doesn't change superclass password.
|
||||
actor.password = 'secret'
|
||||
assert_not_equal Person.password, actor.password
|
||||
|
||||
# Changing superclass password doesn't overwrite subclass password.
|
||||
Person.password = 'super-secret'
|
||||
assert_not_equal Person.password, actor.password
|
||||
|
||||
# Changing superclass password after subclassing changes subclass password.
|
||||
jester = Class.new(actor)
|
||||
actor.password = 'even-more-secret'
|
||||
assert_equal actor.password, jester.password
|
||||
|
||||
# Subclasses are always equal to superclass password when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
|
||||
fruit.password = 'mega-secret'
|
||||
assert_equal fruit.password, apple.password, 'subclass did not adopt changes from parent class'
|
||||
|
||||
fruit.password = 'ok-password'
|
||||
assert_equal fruit.password, apple.password, 'subclass did not adopt changes from parent class'
|
||||
end
|
||||
|
||||
def test_timeout_reader_uses_superclass_timeout_until_written
|
||||
# Superclass is Object so returns nil.
|
||||
assert_nil ActiveResource::Base.timeout
|
||||
assert_nil Class.new(ActiveResource::Base).timeout
|
||||
Person.timeout = 5
|
||||
|
||||
# Subclass uses superclass timeout.
|
||||
actor = Class.new(Person)
|
||||
assert_equal Person.timeout, actor.timeout
|
||||
|
||||
# Changing subclass timeout doesn't change superclass timeout.
|
||||
actor.timeout = 10
|
||||
assert_not_equal Person.timeout, actor.timeout
|
||||
|
||||
# Changing superclass timeout doesn't overwrite subclass timeout.
|
||||
Person.timeout = 15
|
||||
assert_not_equal Person.timeout, actor.timeout
|
||||
|
||||
# Changing superclass timeout after subclassing changes subclass timeout.
|
||||
jester = Class.new(actor)
|
||||
actor.timeout = 20
|
||||
assert_equal actor.timeout, jester.timeout
|
||||
|
||||
# Subclasses are always equal to superclass timeout when not overridden.
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
|
||||
fruit.timeout = 25
|
||||
assert_equal fruit.timeout, apple.timeout, 'subclass did not adopt changes from parent class'
|
||||
|
||||
fruit.timeout = 30
|
||||
assert_equal fruit.timeout, apple.timeout, 'subclass did not adopt changes from parent class'
|
||||
end
|
||||
|
||||
def test_updating_baseclass_site_object_wipes_descendent_cached_connection_objects
|
||||
# Subclasses are always equal to superclass site when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
|
|
@ -111,9 +289,60 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
fruit.site = 'http://market'
|
||||
assert_equal fruit.connection.site, apple.connection.site
|
||||
first_connection = apple.connection.object_id
|
||||
|
||||
fruit.site = 'http://supermarket'
|
||||
assert_equal fruit.connection.site, apple.connection.site
|
||||
assert_equal fruit.connection.site, apple.connection.site
|
||||
second_connection = apple.connection.object_id
|
||||
assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
|
||||
end
|
||||
|
||||
def test_updating_baseclass_user_wipes_descendent_cached_connection_objects
|
||||
# Subclasses are always equal to superclass user when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
fruit.site = 'http://market'
|
||||
|
||||
fruit.user = 'david'
|
||||
assert_equal fruit.connection.user, apple.connection.user
|
||||
first_connection = apple.connection.object_id
|
||||
|
||||
fruit.user = 'john'
|
||||
assert_equal fruit.connection.user, apple.connection.user
|
||||
second_connection = apple.connection.object_id
|
||||
assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
|
||||
end
|
||||
|
||||
def test_updating_baseclass_password_wipes_descendent_cached_connection_objects
|
||||
# Subclasses are always equal to superclass password when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
fruit.site = 'http://market'
|
||||
|
||||
fruit.password = 'secret'
|
||||
assert_equal fruit.connection.password, apple.connection.password
|
||||
first_connection = apple.connection.object_id
|
||||
|
||||
fruit.password = 'supersecret'
|
||||
assert_equal fruit.connection.password, apple.connection.password
|
||||
second_connection = apple.connection.object_id
|
||||
assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
|
||||
end
|
||||
|
||||
def test_updating_baseclass_timeout_wipes_descendent_cached_connection_objects
|
||||
# Subclasses are always equal to superclass timeout when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
fruit.site = 'http://market'
|
||||
|
||||
fruit.timeout = 5
|
||||
assert_equal fruit.connection.timeout, apple.connection.timeout
|
||||
first_connection = apple.connection.object_id
|
||||
|
||||
fruit.timeout = 10
|
||||
assert_equal fruit.connection.timeout, apple.connection.timeout
|
||||
second_connection = apple.connection.object_id
|
||||
assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
|
||||
end
|
||||
|
||||
def test_collection_name
|
||||
|
|
@ -144,6 +373,30 @@ class BaseTest < Test::Unit::TestCase
|
|||
def test_custom_element_path
|
||||
assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, :person_id => 1)
|
||||
assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 1)
|
||||
assert_equal '/people/Greg/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 'Greg')
|
||||
end
|
||||
|
||||
def test_custom_element_path_with_redefined_to_param
|
||||
Person.module_eval do
|
||||
alias_method :original_to_param_element_path, :to_param
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
# Class method.
|
||||
assert_equal '/people/Greg.xml', Person.element_path('Greg')
|
||||
|
||||
# Protected Instance method.
|
||||
assert_equal '/people/Greg.xml', Person.find('Greg').send(:element_path)
|
||||
|
||||
ensure
|
||||
# revert back to original
|
||||
Person.module_eval do
|
||||
# save the 'new' to_param so we don't get a warning about discarding the method
|
||||
alias_method :element_path_to_param, :to_param
|
||||
alias_method :to_param, :original_to_param_element_path
|
||||
end
|
||||
end
|
||||
|
||||
def test_custom_element_path_with_parameters
|
||||
|
|
@ -248,7 +501,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
def test_custom_header
|
||||
Person.headers['key'] = 'value'
|
||||
assert_raises(ActiveResource::ResourceNotFound) { Person.find(3) }
|
||||
assert_raises(ActiveResource::ResourceNotFound) { Person.find(4) }
|
||||
ensure
|
||||
Person.headers.delete('key')
|
||||
end
|
||||
|
|
@ -329,6 +582,26 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal address, address.reload
|
||||
end
|
||||
|
||||
def test_reload_with_redefined_to_param
|
||||
Person.module_eval do
|
||||
alias_method :original_to_param_reload, :to_param
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
person = Person.find('Greg')
|
||||
assert_equal person, person.reload
|
||||
|
||||
ensure
|
||||
# revert back to original
|
||||
Person.module_eval do
|
||||
# save the 'new' to_param so we don't get a warning about discarding the method
|
||||
alias_method :reload_to_param, :to_param
|
||||
alias_method :to_param, :original_to_param_reload
|
||||
end
|
||||
end
|
||||
|
||||
def test_reload_works_without_prefix_options
|
||||
person = Person.find(:first)
|
||||
assert_equal person, person.reload
|
||||
|
|
@ -351,6 +624,41 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') }
|
||||
end
|
||||
|
||||
def test_clone
|
||||
matz = Person.find(1)
|
||||
matz_c = matz.clone
|
||||
assert matz_c.new?
|
||||
matz.attributes.each do |k, v|
|
||||
assert_equal v, matz_c.send(k) if k != Person.primary_key
|
||||
end
|
||||
end
|
||||
|
||||
def test_nested_clone
|
||||
addy = StreetAddress.find(1, :params => {:person_id => 1})
|
||||
addy_c = addy.clone
|
||||
assert addy_c.new?
|
||||
addy.attributes.each do |k, v|
|
||||
assert_equal v, addy_c.send(k) if k != StreetAddress.primary_key
|
||||
end
|
||||
assert_equal addy.prefix_options, addy_c.prefix_options
|
||||
end
|
||||
|
||||
def test_complex_clone
|
||||
matz = Person.find(1)
|
||||
matz.address = StreetAddress.find(1, :params => {:person_id => matz.id})
|
||||
matz.non_ar_hash = {:not => "an ARes instance"}
|
||||
matz.non_ar_arr = ["not", "ARes"]
|
||||
matz_c = matz.clone
|
||||
assert matz_c.new?
|
||||
assert_raises(NoMethodError) {matz_c.address}
|
||||
assert_equal matz.non_ar_hash, matz_c.non_ar_hash
|
||||
assert_equal matz.non_ar_arr, matz_c.non_ar_arr
|
||||
|
||||
# Test that actual copy, not just reference copy
|
||||
matz.non_ar_hash[:not] = "changed"
|
||||
assert_not_equal matz.non_ar_hash, matz_c.non_ar_hash
|
||||
end
|
||||
|
||||
def test_update
|
||||
matz = Person.find(:first)
|
||||
matz.name = "David"
|
||||
|
|
@ -437,6 +745,35 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert !StreetAddress.new({:id => 2, :person_id => 1}).exists?
|
||||
end
|
||||
|
||||
def test_exists_with_redefined_to_param
|
||||
Person.module_eval do
|
||||
alias_method :original_to_param_exists, :to_param
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
# Class method.
|
||||
assert Person.exists?('Greg')
|
||||
|
||||
# Instance method.
|
||||
assert Person.find('Greg').exists?
|
||||
|
||||
# Nested class method.
|
||||
assert StreetAddress.exists?(1, :params => { :person_id => Person.find('Greg').to_param })
|
||||
|
||||
# Nested instance method.
|
||||
assert StreetAddress.find(1, :params => { :person_id => Person.find('Greg').to_param }).exists?
|
||||
|
||||
ensure
|
||||
# revert back to original
|
||||
Person.module_eval do
|
||||
# save the 'new' to_param so we don't get a warning about discarding the method
|
||||
alias_method :exists_to_param, :to_param
|
||||
alias_method :to_param, :original_to_param_exists
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_xml
|
||||
matz = Person.find(1)
|
||||
xml = matz.to_xml
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue