From b5c4c7daf8e26e829ec4d7ece91f622d9e1a49fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Sat, 23 Aug 2008 17:40:16 +0300 Subject: Clear prefix_parameters cache when setting prefix --- activeresource/lib/active_resource/base.rb | 3 +++ activeresource/test/base_test.rb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 7e4a75aa70..4af30ea13f 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -356,6 +356,9 @@ module ActiveResource # Replace :placeholders with '#{embedded options[:lookups]}' prefix_call = value.gsub(/:\w+/) { |key| "\#{options[#{key}]}" } + # Clear prefix parameters in case they have been cached + @prefix_parameters = nil + # Redefine the new methods. code = <<-end_code def prefix_source() "#{value}" end diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 0d997b2a2f..9a0789e0b4 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -485,6 +485,15 @@ class BaseTest < Test::Unit::TestCase end end + def test_set_prefix_twice_should_clear_params + SetterTrap.rollback_sets(Person) do |person_class| + person_class.prefix = "the_prefix/:the_param1" + assert_equal Set.new([:the_param1]), person_class.prefix_parameters + person_class.prefix = "the_prefix/:the_param2" + assert_equal Set.new([:the_param2]), person_class.prefix_parameters + end + end + def test_set_prefix_with_default_value SetterTrap.rollback_sets(Person) do |person_class| person_class.set_prefix -- cgit v1.2.3