提交 b5c4c7da 编写于 作者: T Tarmo Tänav

Clear prefix_parameters cache when setting prefix

上级 e48e77e0
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册