Skip to content
Browse files

Clear prefix_parameters cache when setting prefix

  • Loading branch information...
1 parent e48e77e commit b5c4c7daf8e26e829ec4d7ece91f622d9e1a49fa @tarmo tarmo committed Aug 23, 2008
Showing with 12 additions and 0 deletions.
  1. +3 −0 activeresource/lib/active_resource/base.rb
  2. +9 −0 activeresource/test/base_test.rb
View
3 activeresource/lib/active_resource/base.rb
@@ -356,6 +356,9 @@ def prefix=(value = '/')
# 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
View
9 activeresource/test/base_test.rb
@@ -485,6 +485,15 @@ def test_set_prefix_with_inline_keys
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

0 comments on commit b5c4c7d

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