Flush Element#namespace cache
When setting a new namespace name using Element#namespace_name= the cache used by Element#namespace is flushed properly.
This commit is contained in:
parent
b0359b37e5
commit
fa838154fc
|
@ -8,7 +8,7 @@ module Oga
|
|||
# The name of the element.
|
||||
# @return [String]
|
||||
#
|
||||
# @!attribute [ww] namespace_name
|
||||
# @!attribute [r] namespace_name
|
||||
# The name of the namespace.
|
||||
# @return [String]
|
||||
#
|
||||
|
@ -23,7 +23,9 @@ module Oga
|
|||
class Element < Node
|
||||
include Querying
|
||||
|
||||
attr_accessor :name, :namespace_name, :attributes
|
||||
attr_reader :namespace_name
|
||||
|
||||
attr_accessor :name, :attributes
|
||||
|
||||
attr_writer :namespaces
|
||||
|
||||
|
@ -56,6 +58,14 @@ module Oga
|
|||
register_namespaces_from_attributes
|
||||
end
|
||||
|
||||
##
|
||||
# @param [String] name
|
||||
#
|
||||
def namespace_name=(name)
|
||||
@namespace_name = name
|
||||
@namespace = nil
|
||||
end
|
||||
|
||||
##
|
||||
# Returns an attribute matching the given name (with or without the
|
||||
# namespace).
|
||||
|
|
|
@ -42,6 +42,16 @@ describe Oga::XML::Element do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#namespace_name=' do
|
||||
it 'sets the namepace name' do
|
||||
element = described_class.new(:name => 'a')
|
||||
|
||||
element.namespace_name = 'foo'
|
||||
|
||||
element.namespace_name.should == 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#attribute' do
|
||||
before do
|
||||
attributes = [
|
||||
|
@ -209,6 +219,17 @@ describe Oga::XML::Element do
|
|||
element.namespace.should == namespace
|
||||
end
|
||||
|
||||
it 'flushes the cache when changing the namespace name' do
|
||||
namespace = Oga::XML::Namespace.new(:name => 'bar')
|
||||
element = described_class.new(
|
||||
:namespaces => {'bar' => namespace}
|
||||
)
|
||||
|
||||
element.namespace_name = 'foo'
|
||||
|
||||
element.namespace.should be_nil
|
||||
end
|
||||
|
||||
describe 'in an HTML document' do
|
||||
it 'returns nil' do
|
||||
ns = Oga::XML::Namespace.new(:name => 'xmlns')
|
||||
|
|
Loading…
Reference in New Issue