Skip to content
This repository
Browse code

Increase ActiveResource::Base test coverage. Closes #7173, #7174 [Ric…

…h Collins]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6020 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 1bdb14bdd3cad4ae8850040d6d82c3c3c624f224 1 parent f3f691e
risk danger olson authored January 23, 2007
2  activeresource/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Increase ActiveResource::Base test coverage.  Closes #7173, #7174 [Rich Collins]
  4
+
3 5
 * Interpret 422 Unprocessable Entity as ResourceInvalid.  #7097 [dkubb]
4 6
 
5 7
 * Mega documentation patches. #7025, #7069 [rwdaigle]
28  activeresource/test/abstract_unit.rb
@@ -6,3 +6,31 @@
6 6
 require 'active_support/breakpoint'
7 7
 
8 8
 ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
  9
+
  10
+class SetterTrap < Builder::BlankSlate
  11
+  class << self
  12
+    def rollback_sets(obj)
  13
+      returning yield(setter_trap = new(obj)) do
  14
+        setter_trap.rollback_sets
  15
+      end
  16
+    end
  17
+  end
  18
+  
  19
+  def initialize(obj)
  20
+    @cache = {}
  21
+    @obj = obj
  22
+  end
  23
+  
  24
+  def respond_to?(method)
  25
+    @obj.respond_to?(method)
  26
+  end
  27
+  
  28
+  def method_missing(method, *args, &proc)
  29
+    @cache[method] = @obj.send(method.to_s[0 ... -1]) if method.to_s[-1 .. -1] == "=" unless @cache[method]
  30
+    @obj.send method, *args, &proc
  31
+  end
  32
+  
  33
+  def rollback_sets
  34
+    @cache.each { |k, v| @obj.send k, v }
  35
+  end
  36
+end
26  activeresource/test/base_test.rb
@@ -137,6 +137,27 @@ def test_prefix
137 137
     assert_equal "/", Person.prefix
138 138
     assert_equal Set.new, Person.send(:prefix_parameters)
139 139
   end
  140
+  
  141
+  def test_set_prefix
  142
+    SetterTrap.rollback_sets(Person) do |person_class|
  143
+      person_class.prefix = "the_prefix"
  144
+      assert_equal "the_prefix", person_class.prefix
  145
+    end
  146
+  end
  147
+  
  148
+  def test_set_prefix_with_inline_keys
  149
+    SetterTrap.rollback_sets(Person) do |person_class|
  150
+      person_class.prefix = "the_prefix:the_param"
  151
+      assert_equal "the_prefixthe_param_value", person_class.prefix(:the_param => "the_param_value")
  152
+    end
  153
+  end
  154
+  
  155
+  def test_set_prefix_with_default_value
  156
+    SetterTrap.rollback_sets(Person) do |person_class|
  157
+      person_class.set_prefix
  158
+      assert_equal "/", person_class.prefix
  159
+    end
  160
+  end
140 161
 
141 162
   def test_custom_prefix
142 163
     assert_equal '/people//', StreetAddress.prefix
@@ -261,4 +282,9 @@ def test_exists
261 282
     assert !StreetAddress.new({:id => 1}, {:person_id => 2}).exists?
262 283
     assert !StreetAddress.new({:id => 2}, {:person_id => 1}).exists?
263 284
   end
  285
+  
  286
+  def test_to_xml
  287
+    matz = Person.find(1)
  288
+    assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n  <name>Matz</name>\n  <id type=\"integer\">1</id>\n</person>\n", matz.to_xml
  289
+  end
264 290
 end

0 notes on commit 1bdb14b

Please sign in to comment.
Something went wrong with that request. Please try again.