InvalidPropertyPrefix error class
Raise a InvalidPropertyPrefix error if the prefix is invalid.
This commit is contained in:
parent
395cae7bb2
commit
3f56c99f9b
3 changed files with 12 additions and 3 deletions
|
@ -33,4 +33,7 @@ module Microformats2
|
||||||
html
|
html
|
||||||
end
|
end
|
||||||
end # class << self
|
end # class << self
|
||||||
|
|
||||||
|
class InvalidPropertyPrefix < StandardError; end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,6 +37,7 @@ module Microformats2
|
||||||
prefix = property_class.split("-").first
|
prefix = property_class.split("-").first
|
||||||
# find ruby class for kind of property
|
# find ruby class for kind of property
|
||||||
klass = Microformats2::Property::PREFIX_CLASS_MAP[prefix]
|
klass = Microformats2::Property::PREFIX_CLASS_MAP[prefix]
|
||||||
|
raise InvalidPropertyPrefix unless klass
|
||||||
# We don't have a nokogiri element so pass in nil
|
# We don't have a nokogiri element so pass in nil
|
||||||
property = klass.new(nil, property_class, value)
|
property = klass.new(nil, property_class, value)
|
||||||
assign_property(property)
|
assign_property(property)
|
||||||
|
|
|
@ -76,17 +76,22 @@ describe Microformats2::Collection do
|
||||||
|
|
||||||
describe "Format.add_property" do
|
describe "Format.add_property" do
|
||||||
let(:value) { "bar" }
|
let(:value) { "bar" }
|
||||||
before do
|
|
||||||
@collection.first.add_property("p-foo", value)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates the attr" do
|
it "creates the attr" do
|
||||||
|
@collection.first.add_property("p-foo", value)
|
||||||
@collection.first.foo.to_s.should == value
|
@collection.first.foo.to_s.should == value
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows json output of the attribute" do
|
it "allows json output of the attribute" do
|
||||||
|
@collection.first.add_property("p-foo", value)
|
||||||
@collection.first.to_json.should include(value)
|
@collection.first.to_json.should include(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises a InvalidPropertyPrefix error if the prefix is invalid" do
|
||||||
|
expect {
|
||||||
|
@collection.first.add_property("xxx-foo", value)
|
||||||
|
}.to raise_error Microformats2::InvalidPropertyPrefix
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue