Permalink
Browse files

Added support for nokogiri >= 1.5.1 while maintaining backwards compa…

…tibility for >=1.4.2
  • Loading branch information...
1 parent abf1bbb commit 9e48dc4f8172a833e340fafff757c3e4b5a58c05 @visoft committed Feb 12, 2013
Showing with 14 additions and 7 deletions.
  1. +6 −0 lib/ruby_odata/helpers.rb
  2. +3 −2 lib/ruby_odata/property_metadata.rb
  3. +3 −3 lib/ruby_odata/service.rb
  4. +2 −2 spec/property_metadata_spec.rb
@@ -17,5 +17,11 @@ def self.uri_escape(*args)
URI.escape(*args)
end
end
+
+ # Nokogiri changed how it handles namespaced attributes with v1.5.1, this is for backwards compatibility to >= 1.4.2
+ # Nokogiri now >=1.5.1 requires the namespace prefix is used
+ def self.get_namespaced_attribute(node, attr_name, prefix)
+ return node["#{prefix}:#{attr_name}"] || node[attr_name]
+ end
end
end
@@ -24,8 +24,9 @@ def initialize(property_element)
@name = property_element['Name']
@type = property_element['Type']
@nullable = ((property_element['Nullable'] && property_element['Nullable'] == "true") || property_element.name == 'NavigationProperty') || false
- @fc_target_path = property_element['FC_TargetPath']
- @fc_keep_in_content = (property_element['FC_KeepInContent']) ? (property_element['FC_KeepInContent'] == "true") : nil
+ @fc_target_path = Helpers.get_namespaced_attribute(property_element, 'FC_TargetPath', 'm')
+ keep_in_content = Helpers.get_namespaced_attribute(property_element, 'FC_KeepInContent', 'm')
+ @fc_keep_in_content = (keep_in_content) ? (keep_in_content == "true") : nil
@nav_prop = property_element.name == 'NavigationProperty'
end
end
@@ -630,7 +630,7 @@ def build_batch_operation(operation, changeset_num)
# Complex Types
def complex_type_to_class(complex_type_xml)
- klass_name = qualify_class_name(complex_type_xml.attr('type').split('.')[-1])
+ klass_name = qualify_class_name(Helpers.get_namespaced_attribute(complex_type_xml, 'type', 'm').split('.')[-1])
klass = @classes[klass_name].new
# Fill in the properties
@@ -663,8 +663,8 @@ def parse_date(sdate)
# Parses a value into the proper type based on an xml property element
def parse_value(property_xml)
- property_type = property_xml.attr('type')
- property_null = property_xml.attr('null')
+ property_type = Helpers.get_namespaced_attribute(property_xml, 'type', 'm')
+ property_null = Helpers.get_namespaced_attribute(property_xml, 'null', 'm')
# Handle a nil property type, this is a string
return property_xml.content if property_type.nil?
@@ -28,13 +28,13 @@ module OData
property_metadata.nullable.should eq false
end
it "parses an EDMX property with the fc_target_path and fc_keep_in_content attribute" do
- property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="false" />')
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="false" />')
property_metadata = PropertyMetadata.new property_element
property_metadata.fc_target_path.should eq "SyndicationTitle"
property_metadata.fc_keep_in_content.should eq false
end
it "parses an EDMX property where fc_keep_in_content is true" do
- property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="true" />')
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="true" />')
property_metadata = PropertyMetadata.new property_element
property_metadata.fc_keep_in_content.should eq true
end

2 comments on commit 9e48dc4

@sillylogger
Contributor

Haha, I wish I had seen this yesterday... I ended up doing dirty things to nokogiri. This is much better. I don't see the impetus for that change on nokogiri's end.. it's not well documented that they were changing the [] method.

@visoft
Owner
visoft commented on 9e48dc4 Feb 20, 2013

That change drove me nuts. I'm surprised that 1.5.0 was ok (the version I was originally running) but 1.5.1+ had such a big change that wasn't really noted at all.

Please sign in to comment.