Upgrade to Rails 2.2.0
As a side benefit, fix an (non-user-visible) bug in display_s5(). Also fixed a bug where removing orphaned pages did not expire cached summary pages.
This commit is contained in:
parent
39348c65c2
commit
7600aef48b
827 changed files with 123652 additions and 11027 deletions
128
vendor/rails/activeresource/test/base_test.rb
vendored
128
vendor/rails/activeresource/test/base_test.rb
vendored
|
@ -8,7 +8,7 @@ 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')
|
||||
@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")
|
||||
|
@ -46,11 +46,25 @@ class BaseTest < Test::Unit::TestCase
|
|||
:children => [{:name => 'Natacha'}]},
|
||||
{:name => 'Milena',
|
||||
:children => []}]}]}.to_xml(:root => 'customer')
|
||||
# - resource with yaml array of strings; for ActiveRecords using serialize :bar, Array
|
||||
@marty = <<-eof
|
||||
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<person>
|
||||
<id type=\"integer\">5</id>
|
||||
<name>Marty</name>
|
||||
<colors type=\"yaml\">---
|
||||
- \"red\"
|
||||
- \"green\"
|
||||
- \"blue\"
|
||||
</colors>
|
||||
</person>
|
||||
eof
|
||||
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.get "/people/1.xml", {}, @matz
|
||||
mock.get "/people/2.xml", {}, @david
|
||||
mock.get "/people/Greg.xml", {}, @greg
|
||||
mock.get "/people/5.xml", {}, @marty
|
||||
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
|
||||
|
@ -62,7 +76,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
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.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'
|
||||
|
@ -101,13 +115,13 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal 'http://foo:bar@beast.caboo.se', Forum.site.to_s
|
||||
assert_equal 'http://foo:bar@beast.caboo.se/forums/:forum_id', Topic.site.to_s
|
||||
end
|
||||
|
||||
|
||||
def test_site_variable_can_be_reset
|
||||
actor = Class.new(ActiveResource::Base)
|
||||
actor = Class.new(ActiveResource::Base)
|
||||
assert_nil actor.site
|
||||
actor.site = 'http://localhost:31337'
|
||||
actor.site = nil
|
||||
assert_nil actor.site
|
||||
assert_nil actor.site
|
||||
end
|
||||
|
||||
def test_should_accept_setting_user
|
||||
|
@ -194,18 +208,18 @@ class BaseTest < Test::Unit::TestCase
|
|||
actor.site = 'http://nomad'
|
||||
assert_equal actor.site, jester.site
|
||||
assert jester.site.frozen?
|
||||
|
||||
# Subclasses are always equal to superclass site when not overridden
|
||||
|
||||
# Subclasses are always equal to superclass site when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
|
||||
|
||||
fruit.site = 'http://market'
|
||||
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 from parent class'
|
||||
end
|
||||
|
||||
|
||||
def test_user_reader_uses_superclass_user_until_written
|
||||
# Superclass is Object so returns nil.
|
||||
assert_nil ActiveResource::Base.user
|
||||
|
@ -317,14 +331,14 @@ class BaseTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_updating_baseclass_site_object_wipes_descendent_cached_connection_objects
|
||||
# Subclasses are always equal to superclass site when not overridden
|
||||
# Subclasses are always equal to superclass site when not overridden
|
||||
fruit = Class.new(ActiveResource::Base)
|
||||
apple = Class.new(fruit)
|
||||
|
||||
|
||||
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
|
||||
second_connection = apple.connection.object_id
|
||||
|
@ -393,34 +407,34 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal '/people.xml?gender=', Person.collection_path(:gender => nil)
|
||||
|
||||
assert_equal '/people.xml?gender=male', Person.collection_path('gender' => 'male')
|
||||
|
||||
|
||||
# Use includes? because ordering of param hash is not guaranteed
|
||||
assert Person.collection_path(:gender => 'male', :student => true).include?('/people.xml?')
|
||||
assert Person.collection_path(:gender => 'male', :student => true).include?('gender=male')
|
||||
assert Person.collection_path(:gender => 'male', :student => true).include?('student=true')
|
||||
|
||||
assert_equal '/people.xml?name%5B%5D=bob&name%5B%5D=your+uncle%2Bme&name%5B%5D=&name%5B%5D=false', Person.collection_path(:name => ['bob', 'your uncle+me', nil, false])
|
||||
|
||||
|
||||
assert_equal '/people.xml?struct%5Ba%5D%5B%5D=2&struct%5Ba%5D%5B%5D=1&struct%5Bb%5D=fred', Person.collection_path(:struct => {:a => [2,1], 'b' => 'fred'})
|
||||
end
|
||||
|
||||
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')
|
||||
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
|
||||
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)
|
||||
|
||||
|
@ -468,16 +482,16 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
def test_prefix
|
||||
assert_equal "/", Person.prefix
|
||||
assert_equal Set.new, Person.send!(:prefix_parameters)
|
||||
assert_equal Set.new, Person.__send__(:prefix_parameters)
|
||||
end
|
||||
|
||||
|
||||
def test_set_prefix
|
||||
SetterTrap.rollback_sets(Person) do |person_class|
|
||||
person_class.prefix = "the_prefix"
|
||||
assert_equal "the_prefix", person_class.prefix
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_set_prefix_with_inline_keys
|
||||
SetterTrap.rollback_sets(Person) do |person_class|
|
||||
person_class.prefix = "the_prefix:the_param"
|
||||
|
@ -504,7 +518,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
def test_custom_prefix
|
||||
assert_equal '/people//', StreetAddress.prefix
|
||||
assert_equal '/people/1/', StreetAddress.prefix(:person_id => 1)
|
||||
assert_equal [:person_id].to_set, StreetAddress.send!(:prefix_parameters)
|
||||
assert_equal [:person_id].to_set, StreetAddress.__send__(:prefix_parameters)
|
||||
end
|
||||
|
||||
def test_find_by_id
|
||||
|
@ -513,7 +527,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal "Matz", matz.name
|
||||
assert matz.name?
|
||||
end
|
||||
|
||||
|
||||
def test_respond_to
|
||||
matz = Person.find(1)
|
||||
assert matz.respond_to?(:name)
|
||||
|
@ -542,6 +556,12 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal "Matz", matz.name
|
||||
end
|
||||
|
||||
def test_find_last
|
||||
david = Person.find(:last)
|
||||
assert_kind_of Person, david
|
||||
assert_equal 'David', david.name
|
||||
end
|
||||
|
||||
def test_custom_header
|
||||
Person.headers['key'] = 'value'
|
||||
assert_raises(ActiveResource::ResourceNotFound) { Person.find(4) }
|
||||
|
@ -556,7 +576,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
def test_find_all_by_from
|
||||
ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, @people_david }
|
||||
|
||||
|
||||
people = Person.find(:all, :from => "/companies/1/people.xml")
|
||||
assert_equal 1, people.size
|
||||
assert_equal "David", people.first.name
|
||||
|
@ -564,7 +584,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
def test_find_all_by_from_with_options
|
||||
ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, @people_david }
|
||||
|
||||
|
||||
people = Person.find(:all, :from => "/companies/1/people.xml")
|
||||
assert_equal 1, people.size
|
||||
assert_equal "David", people.first.name
|
||||
|
@ -572,7 +592,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
def test_find_all_by_symbol_from
|
||||
ActiveResource::HttpMock.respond_to { |m| m.get "/people/managers.xml", {}, @people_david }
|
||||
|
||||
|
||||
people = Person.find(:all, :from => :managers)
|
||||
assert_equal 1, people.size
|
||||
assert_equal "David", people.first.name
|
||||
|
@ -601,10 +621,10 @@ class BaseTest < Test::Unit::TestCase
|
|||
def test_id_from_response
|
||||
p = Person.new
|
||||
resp = {'Location' => '/foo/bar/1'}
|
||||
assert_equal '1', p.send!(:id_from_response, resp)
|
||||
|
||||
assert_equal '1', p.__send__(:id_from_response, resp)
|
||||
|
||||
resp['Location'] << '.xml'
|
||||
assert_equal '1', p.send!(:id_from_response, resp)
|
||||
assert_equal '1', p.__send__(:id_from_response, resp)
|
||||
end
|
||||
|
||||
def test_create_with_custom_prefix
|
||||
|
@ -619,16 +639,16 @@ class BaseTest < Test::Unit::TestCase
|
|||
ryan = Person.new(:id => 1, :name => 'Ryan', :address => address)
|
||||
assert_equal address.prefix_options, ryan.address.prefix_options
|
||||
end
|
||||
|
||||
|
||||
def test_reload_works_with_prefix_options
|
||||
address = StreetAddress.find(1, :params => { :person_id => 1 })
|
||||
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
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
end
|
||||
|
@ -643,13 +663,13 @@ class BaseTest < Test::Unit::TestCase
|
|||
alias_method :reload_to_param, :to_param
|
||||
alias_method :to_param, :original_to_param_reload
|
||||
end
|
||||
end
|
||||
|
||||
def test_reload_works_without_prefix_options
|
||||
end
|
||||
|
||||
def test_reload_works_without_prefix_options
|
||||
person = Person.find(:first)
|
||||
assert_equal person, person.reload
|
||||
end
|
||||
|
||||
|
||||
|
||||
def test_create
|
||||
rick = Person.create(:name => 'Rick')
|
||||
|
@ -659,11 +679,11 @@ class BaseTest < Test::Unit::TestCase
|
|||
|
||||
# test additional attribute returned on create
|
||||
assert_equal 25, rick.age
|
||||
|
||||
|
||||
# Test that save exceptions get bubbled up too
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.post "/people.xml", {}, nil, 409
|
||||
end
|
||||
end
|
||||
assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') }
|
||||
end
|
||||
|
||||
|
@ -725,7 +745,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal "54321 Lane", addy.street
|
||||
addy.save
|
||||
end
|
||||
|
||||
|
||||
def test_update_conflict
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.get "/people/2.xml", {}, @david
|
||||
|
@ -757,7 +777,7 @@ class BaseTest < Test::Unit::TestCase
|
|||
end
|
||||
assert_raises(ActiveResource::ResourceNotFound) { Person.find(1) }
|
||||
end
|
||||
|
||||
|
||||
def test_delete_with_custom_prefix
|
||||
assert StreetAddress.delete(1, :person_id => 1)
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
|
@ -787,23 +807,23 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert !StreetAddress.new({:id => 1, :person_id => 2}).exists?
|
||||
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
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
# Class method.
|
||||
assert Person.exists?('Greg')
|
||||
assert Person.exists?('Greg')
|
||||
|
||||
# Instance method.
|
||||
assert Person.find('Greg').exists?
|
||||
assert Person.find('Greg').exists?
|
||||
|
||||
# Nested class method.
|
||||
assert StreetAddress.exists?(1, :params => { :person_id => Person.find('Greg').to_param })
|
||||
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?
|
||||
|
@ -815,8 +835,8 @@ class BaseTest < Test::Unit::TestCase
|
|||
alias_method :exists_to_param, :to_param
|
||||
alias_method :to_param, :original_to_param_exists
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_to_xml
|
||||
matz = Person.find(1)
|
||||
xml = matz.encode
|
||||
|
@ -845,4 +865,14 @@ class BaseTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_load_yaml_array
|
||||
assert_nothing_raised do
|
||||
marty = Person.find(5)
|
||||
assert_equal 3, marty.colors.size
|
||||
marty.colors.each do |color|
|
||||
assert_kind_of String, color
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue