match_point 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/match_point/version.rb +1 -1
- data/lib/match_point/xml_instance.rb +32 -3
- data/spec/match_point_spec.rb +20 -1
- metadata +2 -2
data/lib/match_point/version.rb
CHANGED
@@ -41,11 +41,12 @@ module MatchPoint
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def document
|
44
|
-
@xml.document.clone
|
44
|
+
xml = @xml.document.clone
|
45
|
+
remove_unassigned_values_from xml
|
45
46
|
end
|
46
47
|
|
47
48
|
def at_xpath a_path
|
48
|
-
|
49
|
+
document.at_xpath a_path
|
49
50
|
end
|
50
51
|
|
51
52
|
def assign_values data
|
@@ -58,8 +59,36 @@ module MatchPoint
|
|
58
59
|
!@xml.at_xpath(@error_node[:path]).has_attribute?(@error_node[:attribute])
|
59
60
|
end
|
60
61
|
|
62
|
+
def remove_unspecified_values
|
63
|
+
|
64
|
+
end
|
65
|
+
|
61
66
|
protected
|
62
67
|
|
68
|
+
def remove_unassigned_values_from xml
|
69
|
+
@nodes_paths.each do |name, path|
|
70
|
+
node = xml.at_xpath(path)
|
71
|
+
remove_node node if !node.nil? && node.text == name.to_s
|
72
|
+
end
|
73
|
+
xml
|
74
|
+
end
|
75
|
+
|
76
|
+
def remove_node node
|
77
|
+
parent = node.parent.parent
|
78
|
+
node.parent.remove
|
79
|
+
remove_parent_node parent if has_children? parent
|
80
|
+
end
|
81
|
+
|
82
|
+
def has_children? node
|
83
|
+
return false if node.nil?
|
84
|
+
!node.children.select { |child| !is_a? Nokogiri::XML::Text}.empty?
|
85
|
+
end
|
86
|
+
|
87
|
+
def remove_parent_node parent
|
88
|
+
parent.remove
|
89
|
+
remove_parent_node parent.parent if has_children? parent.parent
|
90
|
+
end
|
91
|
+
|
63
92
|
def initialize template
|
64
93
|
@template= Nokogiri::XML(template)
|
65
94
|
@xml = Nokogiri::XML(template)
|
@@ -98,7 +127,7 @@ module MatchPoint
|
|
98
127
|
|
99
128
|
def add_attr_reader_for node_in_template, attr_path
|
100
129
|
define_singleton_method node_in_template.text.to_sym, lambda {
|
101
|
-
@xml.at_xpath(attr_path).text
|
130
|
+
value = @xml.at_xpath(attr_path).text
|
102
131
|
}
|
103
132
|
end
|
104
133
|
|
data/spec/match_point_spec.rb
CHANGED
@@ -37,6 +37,20 @@ describe MatchPoint do
|
|
37
37
|
</TIX>"
|
38
38
|
end
|
39
39
|
|
40
|
+
let(:uncomplete_xml) do
|
41
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
|
42
|
+
<TIX errCd=\"123\" version=\"TIX 4.11.0\">
|
43
|
+
<AccessControl method=\"AccessControlAuthenticate\">
|
44
|
+
<AuthRequest>
|
45
|
+
<AuthID><MatchPointSpec>auth_id</MatchPointSpec></AuthID>
|
46
|
+
<SubNode>
|
47
|
+
<AnotherId><MatchPointSpec>another_id</MatchPointSpec></AnotherId>
|
48
|
+
</SubNode>
|
49
|
+
</AuthRequest>
|
50
|
+
</AccessControl>
|
51
|
+
</TIX>"
|
52
|
+
end
|
53
|
+
|
40
54
|
let(:error_node) {
|
41
55
|
{
|
42
56
|
:path => "//TIX",
|
@@ -94,6 +108,11 @@ describe MatchPoint do
|
|
94
108
|
failed_response.success?.should be_false
|
95
109
|
end
|
96
110
|
|
111
|
+
it "should remove auth_id because was not specified" do
|
112
|
+
some_operation = MatchPoint::XmlInstance.from_hash uncomplete_xml, {:auth_id => "1234" }
|
113
|
+
some_operation.auth_id.should == "1234"
|
114
|
+
some_operation.at_xpath("/TIX/AccessControl/AuthRequest/SubNode/AnotherId").nil?.should be_true
|
115
|
+
some_operation.at_xpath("/TIX/AccessControl/AuthRequest/SubNode").nil?.should be_true
|
116
|
+
end
|
97
117
|
end
|
98
|
-
|
99
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: match_point
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|