elibri_xml_versions 0.1.2 → 0.1.3
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/Gemfile +3 -1
- data/lib/elibri_xml_versions/version.rb +1 -1
- data/lib/elibri_xml_versions.rb +18 -5
- data/spec/elibri_xml_versions_spec.rb +39 -7
- metadata +27 -25
data/Gemfile
CHANGED
@@ -2,5 +2,7 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in elibri_xml_versions.gemspec
|
4
4
|
gemspec
|
5
|
+
gem 'pry'
|
5
6
|
|
6
|
-
#gem 'elibri_onix_mocks', :git => 'git://github.com/elibri/elibri_onix_mocks.git'
|
7
|
+
#gem 'elibri_onix_mocks', :git => 'git://github.com/elibri/elibri_onix_mocks.git'
|
8
|
+
gem 'elibri_onix', :git => 'git://github.com/elibri/elibri_onix.git'
|
data/lib/elibri_xml_versions.rb
CHANGED
@@ -126,9 +126,15 @@ module Elibri
|
|
126
126
|
deleted += ret[:deleted]
|
127
127
|
end
|
128
128
|
else
|
129
|
-
|
129
|
+
vars = []
|
130
|
+
if a.class.to_s.include? "Elibri::ONIX"
|
131
|
+
vars += a.class::ATTRIBUTES
|
132
|
+
vars += a.class::RELATIONS
|
133
|
+
end
|
134
|
+
vars = a.instance_variables if vars.blank?
|
135
|
+
vars.each do |attrib|
|
130
136
|
next if SKIPPED_ATTRIBS.include? attrib
|
131
|
-
attrib = attrib.to_s.gsub("@", "").to_sym
|
137
|
+
attrib = attrib.to_s.gsub("@", "").to_sym if attrib.is_a?(String)
|
132
138
|
if a.send(attrib).is_a? Array
|
133
139
|
ret = check_tree(a.send(attrib), b.send(attrib))
|
134
140
|
#TODO: otestować to
|
@@ -136,7 +142,8 @@ module Elibri
|
|
136
142
|
added << {attrib => ret[:added]} if !ret[:added].blank?
|
137
143
|
deleted << {attrib => ret[:deleted]} if !ret[:deleted].blank?
|
138
144
|
else
|
139
|
-
if (a.send(attrib).is_a?(String) || a.send(attrib).is_a?(Numeric) || a.send(attrib).is_a?(NilClass) || b.send(attrib).is_a?(NilClass)
|
145
|
+
if (a.send(attrib).is_a?(String) || a.send(attrib).is_a?(Numeric) || a.send(attrib).is_a?(NilClass) || b.send(attrib).is_a?(NilClass) ||
|
146
|
+
a.send(attrib).is_a?(TrueClass) || a.send(attrib).is_a?(FalseClass) || b.send(attrib).is_a?(TrueClass) || b.send(attrib).is_a?(FalseClass))
|
140
147
|
changes << attrib if a.send(attrib) != b.send(attrib)
|
141
148
|
else
|
142
149
|
#klasa zlozona
|
@@ -156,10 +163,16 @@ module Elibri
|
|
156
163
|
if object.is_a? Array
|
157
164
|
object.each { |x| result << calculate_hash(x) }
|
158
165
|
else
|
159
|
-
|
166
|
+
vars = []
|
167
|
+
if object.class.to_s.include? "Elibri::ONIX"
|
168
|
+
vars += object.class::ATTRIBUTES
|
169
|
+
vars += object.class::RELATIONS
|
170
|
+
end
|
171
|
+
vars = object.instance_variables if vars.blank?
|
172
|
+
vars.each do |attrib|
|
160
173
|
next if SKIPPED_ATTRIBS.include? attrib
|
161
174
|
next if SKIPPED_2.include? attrib
|
162
|
-
attrib = attrib.to_s.gsub("@", "").to_sym
|
175
|
+
attrib = attrib.to_s.gsub("@", "").to_sym if attrib.is_a?(String)
|
163
176
|
if object.send(attrib).is_a? Array
|
164
177
|
result << calculate_hash(object.send(attrib))
|
165
178
|
elsif object.send(attrib).is_a?(String) || object.send(attrib).is_a?(Numeric) || object.send(attrib).is_a?(Fixnum) || object.send(attrib).is_a?(Symbol)
|
@@ -15,7 +15,6 @@ describe Elibri::XmlVersions do
|
|
15
15
|
:product_attachments => [],
|
16
16
|
:product_availabilities => []
|
17
17
|
}
|
18
|
-
|
19
18
|
it "should return no changes for same basic elibri object" do
|
20
19
|
generated_product = onix_from_mock(:basic_product)
|
21
20
|
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product.products.first)
|
@@ -95,7 +94,6 @@ describe Elibri::XmlVersions do
|
|
95
94
|
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
96
95
|
@elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
|
97
96
|
end
|
98
|
-
|
99
97
|
SPLITTING_SYMBOLS = [
|
100
98
|
:publisher_name
|
101
99
|
]
|
@@ -113,16 +111,36 @@ describe Elibri::XmlVersions do
|
|
113
111
|
:ean => :ean,
|
114
112
|
:deletion_text => :deletion_text,
|
115
113
|
:trade_title => :trade_title,
|
116
|
-
:pkwiu => :
|
114
|
+
:pkwiu => :pkwiu,
|
117
115
|
:title => :title,
|
118
116
|
:subtitle => :subtitle,
|
119
117
|
:edition_statement => :edition_statement,
|
120
118
|
:audience_age_from => :reading_age_from,
|
121
119
|
:audience_age_to => :reading_age_to,
|
122
|
-
:price_amount => :
|
123
|
-
:vat => :
|
120
|
+
:price_amount => :cover_price,
|
121
|
+
:vat => :vat,
|
122
|
+
:preview_exists? => :preview_exists,
|
123
|
+
:elibri_product_category1_id => :elibri_product_category1_id,
|
124
|
+
:elibri_product_category2_id => :elibri_product_category2_id
|
124
125
|
}
|
125
126
|
|
127
|
+
it "should find the difference in categories" do
|
128
|
+
generated_product = onix_from_mock(:onix_subjects_example)
|
129
|
+
generated_product_2 = onix_from_mock(:onix_subjects_example)
|
130
|
+
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
131
|
+
@elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
|
132
|
+
|
133
|
+
generated_product = onix_from_mock(:onix_subjects_example, :elibri_product_category1_id => 440, :elibri_product_category2_id => nil)
|
134
|
+
generated_product_2 = onix_from_mock(:onix_subjects_example, :elibri_product_category1_id => 550, :elibri_product_category2_id => nil)
|
135
|
+
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
136
|
+
@elibri_xml_versions.diff[:changes].should include(:elibri_product_category1_id)
|
137
|
+
|
138
|
+
generated_product = onix_from_mock(:onix_subjects_example, :elibri_product_category1_id => 440, :elibri_product_category2_id => 441)
|
139
|
+
generated_product_2 = onix_from_mock(:onix_subjects_example, :elibri_product_category1_id => 550, :elibri_product_category2_id => 551)
|
140
|
+
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
141
|
+
@elibri_xml_versions.diff[:changes].should include(:elibri_product_category1_id, :elibri_product_category2_id)
|
142
|
+
end
|
143
|
+
|
126
144
|
#strings
|
127
145
|
[
|
128
146
|
:publisher_name, :record_reference,
|
@@ -174,6 +192,21 @@ describe Elibri::XmlVersions do
|
|
174
192
|
#end strings
|
175
193
|
end
|
176
194
|
|
195
|
+
#bools
|
196
|
+
[
|
197
|
+
:preview_exists?
|
198
|
+
].each do |symbol|
|
199
|
+
|
200
|
+
it "should see the change in #{symbol} attribute" do
|
201
|
+
generated_product = onix_from_mock(:basic_product, symbol => true)
|
202
|
+
generated_product_2 = onix_from_mock(:basic_product, symbol => false)
|
203
|
+
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
204
|
+
@elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
|
205
|
+
end
|
206
|
+
|
207
|
+
#end bools
|
208
|
+
end
|
209
|
+
|
177
210
|
|
178
211
|
#integers
|
179
212
|
[
|
@@ -240,5 +273,4 @@ describe Elibri::XmlVersions do
|
|
240
273
|
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
241
274
|
@elibri_xml_versions.diff[:changes].should include({:imprint => [:name]})
|
242
275
|
end
|
243
|
-
|
244
|
-
end
|
276
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elibri_xml_versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Piotr Szmielew
|
@@ -15,12 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-10 00:00:00 +02:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
21
23
|
name: rspec
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
@@ -29,12 +30,12 @@ dependencies:
|
|
29
30
|
segments:
|
30
31
|
- 0
|
31
32
|
version: "0"
|
32
|
-
|
33
|
-
|
33
|
+
prerelease: false
|
34
|
+
requirement: *id001
|
34
35
|
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
35
37
|
name: rake
|
36
|
-
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
39
|
none: false
|
39
40
|
requirements:
|
40
41
|
- - ">="
|
@@ -43,12 +44,12 @@ dependencies:
|
|
43
44
|
segments:
|
44
45
|
- 0
|
45
46
|
version: "0"
|
46
|
-
|
47
|
-
|
47
|
+
prerelease: false
|
48
|
+
requirement: *id002
|
48
49
|
- !ruby/object:Gem::Dependency
|
50
|
+
type: :development
|
49
51
|
name: elibri_onix_mocks
|
50
|
-
|
51
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
53
|
none: false
|
53
54
|
requirements:
|
54
55
|
- - ">="
|
@@ -57,12 +58,12 @@ dependencies:
|
|
57
58
|
segments:
|
58
59
|
- 0
|
59
60
|
version: "0"
|
60
|
-
|
61
|
-
|
61
|
+
prerelease: false
|
62
|
+
requirement: *id003
|
62
63
|
- !ruby/object:Gem::Dependency
|
64
|
+
type: :runtime
|
63
65
|
name: elibri_api_client
|
64
|
-
|
65
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
67
|
none: false
|
67
68
|
requirements:
|
68
69
|
- - ">="
|
@@ -71,12 +72,12 @@ dependencies:
|
|
71
72
|
segments:
|
72
73
|
- 0
|
73
74
|
version: "0"
|
74
|
-
|
75
|
-
|
75
|
+
prerelease: false
|
76
|
+
requirement: *id004
|
76
77
|
- !ruby/object:Gem::Dependency
|
78
|
+
type: :runtime
|
77
79
|
name: elibri_onix_dict
|
78
|
-
|
79
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
81
|
none: false
|
81
82
|
requirements:
|
82
83
|
- - ">="
|
@@ -85,8 +86,8 @@ dependencies:
|
|
85
86
|
segments:
|
86
87
|
- 0
|
87
88
|
version: "0"
|
88
|
-
|
89
|
-
|
89
|
+
prerelease: false
|
90
|
+
requirement: *id005
|
90
91
|
description: |-
|
91
92
|
Gem created for comparing eLibri xml objects. More info coming soon. Currently working and tested only on REE.
|
92
93
|
Basic usage: Elibri::XmlVersions.new(product_ver1, product_ver2).diff
|
@@ -110,6 +111,7 @@ files:
|
|
110
111
|
- lib/elibri_xml_versions/version.rb
|
111
112
|
- spec/elibri_xml_versions_spec.rb
|
112
113
|
- spec/spec_helper.rb
|
114
|
+
has_rdoc: true
|
113
115
|
homepage: ""
|
114
116
|
licenses: []
|
115
117
|
|
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
141
|
requirements: []
|
140
142
|
|
141
143
|
rubyforge_project: elibri_xml_versions
|
142
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.5.2
|
143
145
|
signing_key:
|
144
146
|
specification_version: 3
|
145
147
|
summary: Gem created for comparing eLibri xml objects.
|