diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-03-02 21:24:56 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-03-04 09:30:27 +0000 |
commit | 735844db712c511dd8abf36a5279318fbc0ff9d0 (patch) | |
tree | 5fbd5d224ef85d8c878bf221db98b422c9345466 /activeresource | |
parent | 9a98c766e045aebc2ef6d5b716936b73407f095d (diff) | |
parent | b171b9e73dcc6a89b1da652da61c5127fe605b51 (diff) | |
download | rails-735844db712c511dd8abf36a5279318fbc0ff9d0.tar.gz rails-735844db712c511dd8abf36a5279318fbc0ff9d0.tar.bz2 rails-735844db712c511dd8abf36a5279318fbc0ff9d0.zip |
Merge branch 'master' into nested_has_many_through
Conflicts:
activerecord/CHANGELOG
activerecord/lib/active_record/association_preload.rb
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations/class_methods/join_dependency.rb
activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb
activerecord/lib/active_record/associations/has_many_association.rb
activerecord/lib/active_record/associations/has_many_through_association.rb
activerecord/lib/active_record/associations/has_one_association.rb
activerecord/lib/active_record/associations/has_one_through_association.rb
activerecord/lib/active_record/associations/through_association_scope.rb
activerecord/lib/active_record/reflection.rb
activerecord/test/cases/associations/has_many_through_associations_test.rb
activerecord/test/cases/associations/has_one_through_associations_test.rb
activerecord/test/cases/reflection_test.rb
activerecord/test/cases/relations_test.rb
activerecord/test/fixtures/memberships.yml
activerecord/test/models/categorization.rb
activerecord/test/models/category.rb
activerecord/test/models/member.rb
activerecord/test/models/reference.rb
activerecord/test/models/tagging.rb
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/MIT-LICENSE | 2 | ||||
-rw-r--r-- | activeresource/README.rdoc | 2 | ||||
-rwxr-xr-x | activeresource/Rakefile | 2 | ||||
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 4 | ||||
-rw-r--r-- | activeresource/lib/active_resource/http_mock.rb | 17 | ||||
-rw-r--r-- | activeresource/test/cases/http_mock_test.rb | 27 | ||||
-rw-r--r-- | activeresource/test/cases/validations_test.rb | 6 | ||||
-rw-r--r-- | activeresource/test/fixtures/project.rb | 19 |
8 files changed, 56 insertions, 23 deletions
diff --git a/activeresource/MIT-LICENSE b/activeresource/MIT-LICENSE index 1bf965ff1e..216b6e5ba0 100644 --- a/activeresource/MIT-LICENSE +++ b/activeresource/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2006-2010 David Heinemeier Hansson +Copyright (c) 2006-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc index 0aaad1d097..afa25e1676 100644 --- a/activeresource/README.rdoc +++ b/activeresource/README.rdoc @@ -95,7 +95,7 @@ Collections can also be requested in a similar fashion # # for GET http://api.people.com:3000/people.xml # - people = Person.find(:all) + people = Person.all people.first # => <Person::xxx 'first' => 'Ryan' ...> people.last # => <Person::xxx 'first' => 'Jim' ...> diff --git a/activeresource/Rakefile b/activeresource/Rakefile index cf01bc1389..42e450da66 100755 --- a/activeresource/Rakefile +++ b/activeresource/Rakefile @@ -19,7 +19,7 @@ namespace :test do ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) activesupport_path = "#{File.dirname(__FILE__)}/../activesupport/lib" Dir.glob("test/**/*_test.rb").all? do |file| - system(ruby, '-w', "-Ilib:test:#{activesupport_path}", file) + sh(ruby, '-w', "-Ilib:test:#{activesupport_path}", file) end or raise "Failures" end end diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index d959fd103a..daa8962929 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -200,7 +200,7 @@ module ActiveResource # an ActiveResource::MissingPrefixParam will be raised. # # class Comment < ActiveResource::Base - # self.site = "http://someip.com/posts/:post_id/" + # self.site = "http://someip.com/posts/:post_id/" # end # # Comment.find(1) @@ -1095,7 +1095,7 @@ module ActiveResource end # Delegates to id in order to allow two resources of the same type and \id to work with something like: - # [Person.find(1), Person.find(2)] & [Person.find(1), Person.find(4)] # => [Person.find(1)] + # [(a = Person.find 1), (b = Person.find 2)] & [(c = Person.find 1), (d = Person.find 4)] # => [a] def hash id.hash end diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index 9aefde7c30..75649053d0 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -60,10 +60,21 @@ module ActiveResource # end module_eval <<-EOE, __FILE__, __LINE__ + 1 def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {}) - @responses << [Request.new(:#{method}, path, nil, request_headers), Response.new(body || "", status, response_headers)] + request = Request.new(:#{method}, path, nil, request_headers) + response = Response.new(body || "", status, response_headers) + + delete_duplicate_responses(request) + + @responses << [request, response] end EOE end + + private + + def delete_duplicate_responses(request) + @responses.delete_if {|r| r[0] == request } + end end class << self @@ -181,11 +192,11 @@ module ActiveResource pairs = args.first || {} reset! if args.last.class != FalseClass - delete_responses_to_replace pairs.to_a - responses.concat pairs.to_a if block_given? yield Responder.new(responses) else + delete_responses_to_replace pairs.to_a + responses.concat pairs.to_a Responder.new(responses) end end diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb index 82b5e60c77..43cf5f5ef0 100644 --- a/activeresource/test/cases/http_mock_test.rb +++ b/activeresource/test/cases/http_mock_test.rb @@ -140,7 +140,19 @@ class HttpMockTest < ActiveSupport::TestCase assert_equal 2, ActiveResource::HttpMock.responses.length end - test "allows you to replace the existing reponse with the same request" do + test "allows you to replace the existing reponse with the same request by calling a block" do + ActiveResource::HttpMock.respond_to do |mock| + mock.send(:get, "/people/1", {}, "XML1") + end + assert_equal 1, ActiveResource::HttpMock.responses.length + + ActiveResource::HttpMock.respond_to(false) do |mock| + mock.send(:get, "/people/1", {}, "XML2") + end + assert_equal 1, ActiveResource::HttpMock.responses.length + end + + test "allows you to replace the existing reponse with the same request by passing pairs" do ActiveResource::HttpMock.respond_to do |mock| mock.send(:get, "/people/1", {}, "XML1") end @@ -151,11 +163,22 @@ class HttpMockTest < ActiveSupport::TestCase ok_response = ActiveResource::Response.new(matz, 200, {}) ActiveResource::HttpMock.respond_to({get_matz => ok_response}, false) + assert_equal 1, ActiveResource::HttpMock.responses.length + end + test "do not replace the response with the same path but different method by calling a block" do + ActiveResource::HttpMock.respond_to do |mock| + mock.send(:get, "/people/1", {}, "XML1") + end assert_equal 1, ActiveResource::HttpMock.responses.length + + ActiveResource::HttpMock.respond_to(false) do |mock| + mock.send(:put, "/people/1", {}, "XML2") + end + assert_equal 2, ActiveResource::HttpMock.responses.length end - test "do not replace the response with the same path but different method" do + test "do not replace the response with the same path but different method by passing pairs" do ActiveResource::HttpMock.respond_to do |mock| mock.send(:get, "/people/1", {}, "XML1") end diff --git a/activeresource/test/cases/validations_test.rb b/activeresource/test/cases/validations_test.rb index bd79fdd952..671d1ea8f0 100644 --- a/activeresource/test/cases/validations_test.rb +++ b/activeresource/test/cases/validations_test.rb @@ -48,6 +48,12 @@ class ValidationsTest < ActiveModel::TestCase assert p.save, "should have saved after fixing the validation, but had: #{p.errors.inspect}" end + def test_client_side_validation_maximum + project = Project.new(:description => '123456789012345') + assert ! project.valid? + assert_equal ['is too long (maximum is 10 characters)'], project.errors[:description] + end + protected # quickie helper to create a new project with all the required diff --git a/activeresource/test/fixtures/project.rb b/activeresource/test/fixtures/project.rb index e15fa6f620..53de666601 100644 --- a/activeresource/test/fixtures/project.rb +++ b/activeresource/test/fixtures/project.rb @@ -1,25 +1,18 @@ # used to test validations class Project < ActiveResource::Base self.site = "http://37s.sunrise.i:3000" + schema do + string :email + string :name + end - validates_presence_of :name + validates :name, :presence => true + validates :description, :presence => false, :length => {:maximum => 10} validate :description_greater_than_three_letters # to test the validate *callback* works def description_greater_than_three_letters errors.add :description, 'must be greater than three letters long' if description.length < 3 unless description.blank? end - - - # stop-gap accessor to default this attribute to nil - # Otherwise the validations fail saying that the method does not exist. - # In future, method_missing will be updated to not explode on a known - # attribute. - def name - attributes['name'] || nil - end - def description - attributes['description'] || nil - end end |