From 1bdb14bdd3cad4ae8850040d6d82c3c3c624f224 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Tue, 23 Jan 2007 05:22:33 +0000 Subject: Increase ActiveResource::Base test coverage. Closes #7173, #7174 [Rich Collins] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6020 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activeresource/CHANGELOG | 2 ++ activeresource/test/abstract_unit.rb | 28 ++++++++++++++++++++++++++++ activeresource/test/base_test.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) (limited to 'activeresource') diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index 70bc5675e2..71d9067dc9 100644 --- a/activeresource/CHANGELOG +++ b/activeresource/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Increase ActiveResource::Base test coverage. Closes #7173, #7174 [Rich Collins] + * Interpret 422 Unprocessable Entity as ResourceInvalid. #7097 [dkubb] * Mega documentation patches. #7025, #7069 [rwdaigle] diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index f19635826c..08b41329a7 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -6,3 +6,31 @@ require 'active_resource/http_mock' require 'active_support/breakpoint' ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log") + +class SetterTrap < Builder::BlankSlate + class << self + def rollback_sets(obj) + returning yield(setter_trap = new(obj)) do + setter_trap.rollback_sets + end + end + end + + def initialize(obj) + @cache = {} + @obj = obj + end + + def respond_to?(method) + @obj.respond_to?(method) + end + + def method_missing(method, *args, &proc) + @cache[method] = @obj.send(method.to_s[0 ... -1]) if method.to_s[-1 .. -1] == "=" unless @cache[method] + @obj.send method, *args, &proc + end + + def rollback_sets + @cache.each { |k, v| @obj.send k, v } + end +end \ No newline at end of file diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index f9f2b24c72..040bd02b52 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -137,6 +137,27 @@ class BaseTest < Test::Unit::TestCase assert_equal "/", Person.prefix 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" + assert_equal "the_prefixthe_param_value", person_class.prefix(:the_param => "the_param_value") + end + end + + def test_set_prefix_with_default_value + SetterTrap.rollback_sets(Person) do |person_class| + person_class.set_prefix + assert_equal "/", person_class.prefix + end + end def test_custom_prefix assert_equal '/people//', StreetAddress.prefix @@ -261,4 +282,9 @@ 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_to_xml + matz = Person.find(1) + assert_equal "\n\n Matz\n 1\n\n", matz.to_xml + end end -- cgit v1.2.3