diff options
-rw-r--r-- | activeresource/test/abstract_unit.rb | 31 | ||||
-rw-r--r-- | activeresource/test/setter_trap.rb | 29 |
2 files changed, 32 insertions, 28 deletions
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index 08b41329a7..574080acc6 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -5,32 +5,7 @@ require 'active_resource' require 'active_resource/http_mock' require 'active_support/breakpoint' -ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log") +$:.unshift "#{File.dirname(__FILE__)}/../test" +require 'setter_trap' -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 +ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log") diff --git a/activeresource/test/setter_trap.rb b/activeresource/test/setter_trap.rb new file mode 100644 index 0000000000..284938823a --- /dev/null +++ b/activeresource/test/setter_trap.rb @@ -0,0 +1,29 @@ +require 'builder' + +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($`) if method.to_s =~ /=$/ + @obj.send method, *args, &proc + end + + def rollback_sets + @cache.each { |k, v| @obj.send k, v } + end +end |