elibri_xml_versions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ notifications:
5
+ email:
6
+ - p.szmielew@ava.waw.pl
7
+ - tomek@gildia.pl
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in elibri_xml_versions.gemspec
4
+ gemspec
5
+
6
+ #gem 'elibri_onix_mocks', :git => 'git://github.com/elibri/elibri_onix_mocks.git'
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ [![Build Status](https://secure.travis-ci.org/elibri/elibri_xml_versions.png?branch=master)](http://travis-ci.org/elibri/elibri_xml_versions)
2
+
3
+ Gem created for comparing eLibri xml objects.
4
+
5
+ Currently working and tested only on REE.
6
+
7
+ Basic usage:
8
+ ``Elibri::XmlVersions.new(product_ver1, product_ver2).diff``
9
+
10
+ `product_ver1` and `product_ver2` must be same classes
11
+
12
+ It will return hash:
13
+ ```ruby
14
+ {
15
+ :added => [],
16
+ :changes => [],
17
+ :deleted => []
18
+ }
19
+ ```
20
+
21
+ under changes key, will be array of symbol and/or hashes.
22
+ Symbols represents attributes that in product_ver2 are different then in product_ver1. If there is hash in changes key, it represents some changes in object that is in one <-> one relation with product_ver2.
23
+
24
+ Added and deleted contains array of hashes. Every hash has symbol as a key, that is used to access array of elements where changes occures. As a value it contains array of elements that has been added/deleted from product_ver2, in comparision to product_ver1.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Running specs"
4
+ task :spec do |t|
5
+ exec "cd spec/ && bundle exec rspec elibri_xml_versions_spec.rb"
6
+ end
7
+
8
+ task :default => ["spec"]
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "elibri_xml_versions/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "elibri_xml_versions"
7
+ s.version = ElibriXmlVersions::VERSION
8
+ s.authors = ["Piotr Szmielew"]
9
+ s.email = ["p.szmielew@ava.waw.pl"]
10
+ s.homepage = ""
11
+ s.summary = %q{Gem created for comparing eLibri xml objects.}
12
+ s.description = %q|Gem created for comparing eLibri xml objects. More info coming soon. Currently working and tested only on REE.
13
+ Basic usage: Elibri::XmlVersions.new(product_ver1, product_ver2).diff
14
+ it will return hash: {:added => [], :changes => [], :deleted => []}|
15
+
16
+ s.rubyforge_project = "elibri_xml_versions"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "rspec"
25
+
26
+ s.add_development_dependency "rake"
27
+
28
+ # s.add_development_dependency "ruby-debug"
29
+ s.add_development_dependency "elibri_onix_mocks"
30
+ s.add_runtime_dependency 'elibri_api_client'
31
+ s.add_runtime_dependency 'elibri_onix_dict'
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ module ElibriXmlVersions
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,179 @@
1
+ #encoding: UTF-8
2
+
3
+ require "elibri_xml_versions/version"
4
+ require 'elibri_api_client'
5
+ require 'elibri_onix_dict'
6
+ require 'digest/sha2'
7
+
8
+
9
+
10
+
11
+ module Elibri
12
+
13
+ class XmlVersions
14
+
15
+
16
+ SKIPPED_ATTRIBS = ["@opts", "@default_namespace", "@instance", "@roxml_references"]
17
+ SKIPPED_2 = ["@id", "@id_before_type_cast"]
18
+
19
+
20
+
21
+ attr_accessor :a, :b
22
+
23
+ def initialize(a, b)
24
+ @a = a
25
+ @b = b
26
+ end
27
+
28
+ def diff
29
+ =begin
30
+ diffs = []
31
+ @a.instance_variables.each do |attrib|
32
+ attrib = attrib.gsub("@", "").to_sym
33
+ if TREE_ATTRIBS.include? attrib
34
+ tree_attr = @a.send(attrib).map(&:id).sort
35
+ tree_attr_2 = @b.send(attrib).map(&:id).sort
36
+ if tree_attr != tree_attr_2
37
+ #coś dopisane/usunięte
38
+ else
39
+ #trzeba sprawdzić czy wszystkie są takie same
40
+ attr_1 = @a.send(attrib).sort { |x,y| x.id <=> y.id }
41
+ attr_2 = @b.send(attrib).sort! { |x,y| x.id <=> y.id }
42
+ attr_1.each_with_index do |element, i|
43
+ element.instance_variables.each do |var|
44
+ var = var.gsub("@", "").to_sym
45
+ diffs << [attrib, var] if element.send(var) != attr_2[i].send(var)
46
+ end
47
+ end
48
+ end
49
+ else
50
+ diffs << attrib if @a.send(attrib) != @b.send(attrib)
51
+ end
52
+ end
53
+ diffs
54
+ =end
55
+ check_tree(@a, @b)
56
+ end
57
+
58
+
59
+ def check_tree(a, b)
60
+ if a.class != b.class
61
+ raise "Different classes for diff"
62
+ end
63
+ =begin
64
+ if a.class.is_a? NilClass
65
+ return {:deleted => [], :added => [], :changes => [b]}
66
+ elsif b.class.is_a? NilClass
67
+ return {:deleted => [], :added => [], :changes => [a]}
68
+ else
69
+
70
+ end
71
+ end
72
+ =end
73
+ changes = []
74
+ deleted = []
75
+ added = []
76
+ if a.is_a? Array
77
+ a.sort! { |x,y| x.id <=> y.id }
78
+ b.sort! { |x,y| x.id <=> y.id }
79
+ if a.all? { |x| x.instance_variables.include? "@id_before_type_cast"} || a.all? { |x| x.instance_variables.include? "@import_id"}
80
+ a_m = a.map { |x| x.id }
81
+ b_m = b.map { |x| x.id }
82
+ else
83
+ =begin
84
+ ch = []
85
+ del = []
86
+ add = []
87
+ a.each_with_index do |element, i|
88
+ res = check_tree(element, b[i])
89
+ ch += res[:changes]
90
+ del += res[:deleted]
91
+ add += res[:added]
92
+ end
93
+ =end
94
+ #obsługa dodania i usunięcia elementów
95
+ #problematyczne są części rekordu które nie są identyfikowalne jako identyczne :(
96
+ a_m = a.map { |x| calculate_hash(x) }
97
+ b_m = b.map { |x| calculate_hash(x) }
98
+ end
99
+ # if a.map(&:id) != b.map(&:id)
100
+ if a_m != b_m
101
+ deleted_ids = a.map(&:id) - b.map(&:id)
102
+ added_ids = b.map(&:id) - a.map(&:id)
103
+ deleted_ids.each do |id|
104
+ if a.find { |x| x.id == id } && !a.find { |x| x.id == id }.blank?
105
+ deleted << a.find { |x| x.id == id }
106
+ a.delete(a.find { |x| x.id == id })
107
+ end
108
+ end
109
+ added_ids.each do |id|
110
+ if b.find { |x| x.id == id } && !b.find { |x| x.id == id }.blank?
111
+ added << b.find { |x| x.id == id }
112
+ b.delete(b.find { |x| x.id == id })
113
+ end
114
+ end
115
+ end
116
+ #obsługa różnych elementów w arrayu
117
+ a.each_with_index do |element, i|
118
+ ret = check_tree(element, b[i])
119
+ changes += ret[:changes]
120
+ added += ret[:added]
121
+ deleted += ret[:deleted]
122
+ end
123
+ else
124
+ a.instance_variables.each do |attrib|
125
+ next if SKIPPED_ATTRIBS.include? attrib
126
+ attrib = attrib.to_s.gsub("@", "").to_sym
127
+ if a.send(attrib).is_a? Array
128
+ ret = check_tree(a.send(attrib), b.send(attrib))
129
+ changes << {attrib, ret[:changes]} if !ret[:changes].blank?
130
+ added << {attrib, ret[:added]} if !ret[:added].blank?
131
+ deleted << {attrib, ret[:deleted]} if !ret[:deleted].blank?
132
+ else
133
+ 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))
134
+ changes << attrib if a.send(attrib) != b.send(attrib)
135
+ else
136
+ #klasa zlozona
137
+ ret = check_tree(a.send(attrib), b.send(attrib))
138
+ changes << {attrib, ret[:changes]} if !ret[:changes].blank?
139
+ added << {attrib, ret[:added]} if !ret[:added].blank?
140
+ deleted << {attrib, ret[:deleted]} if !ret[:deleted].blank?
141
+ end
142
+ end
143
+ end
144
+ end
145
+ return {:deleted => deleted, :added => added, :changes => changes}
146
+ end
147
+
148
+ def calculate_hash(object)
149
+ result = []
150
+ if object.is_a? Array
151
+ object.each { |x| result << calculate_hash(x) }
152
+ else
153
+ object.instance_variables.each do |attrib|
154
+ next if SKIPPED_ATTRIBS.include? attrib
155
+ next if SKIPPED_2.include? attrib
156
+ attrib = attrib.to_s.gsub("@", "").to_sym
157
+ if object.send(attrib).is_a? Array
158
+ result << calculate_hash(object.send(attrib))
159
+ 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)
160
+ result << object.send(attrib)
161
+ else
162
+ result << calculate_hash(object.send(attrib))
163
+ end
164
+ end
165
+ end
166
+ return Digest::SHA1.hexdigest(result.join("-"))
167
+ end
168
+
169
+ def convert_arr_to_hash(arr)
170
+ {}.tap do |hash|
171
+ arr.each do |pair|
172
+ hash[pair.keys.first] = pair.values.first
173
+ end
174
+ end
175
+ end
176
+
177
+ end
178
+
179
+ end
@@ -0,0 +1,232 @@
1
+ require 'spec_helper'
2
+ $VERBOSE = nil #temp: supress id warnings
3
+ describe Elibri::XmlVersions do
4
+
5
+ RAW_EXTRAS = {
6
+ :imprint => nil,
7
+ :authorship_kind => nil,
8
+ :contributors => [],
9
+ :languages => [],
10
+ :other_texts => [],
11
+ :series_membership_kind => nil,
12
+ :series_memberships => [],
13
+ :facsimiles => [],
14
+ :similar_products => [],
15
+ :product_attachments => [],
16
+ :product_availabilities => []
17
+ }
18
+
19
+ it "should return no changes for same basic elibri object" do
20
+ generated_product = onix_from_mock(:basic_product)
21
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product.products.first)
22
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
23
+ end
24
+
25
+ it "should return no changes for same basic elibri object double generated" do
26
+ generated_product = onix_from_mock(:basic_product)
27
+ generated_product_2 = onix_from_mock(:basic_product)
28
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
29
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
30
+ end
31
+
32
+ it "should return change for different basic elibri objects" do
33
+ generated_product = onix_from_mock(:basic_product, :record_reference => 'fdb8fa072be774d97a97')
34
+ generated_product_2 = onix_from_mock(:basic_product, :record_reference => 'fdb8fa072be774d97a95')
35
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
36
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => [:record_reference]})
37
+ end
38
+
39
+ it "should return no changes for same book elibri objects" do
40
+ generated_product = onix_from_mock(:book_example)
41
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product.products.first)
42
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
43
+ end
44
+
45
+ it "should return no changes for same book elibri objects double generated" do
46
+ mock = Elibri::XmlMocks::Examples.review_mock
47
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS.merge(:other_texts => [mock]) )
48
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(:other_texts => [mock]) )
49
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
50
+ result = @elibri_xml_versions.diff
51
+ (@elibri_xml_versions.convert_arr_to_hash result[:changes]).count.should eq(0)
52
+ end
53
+
54
+ it "should return change for different book elibri objects" do
55
+ review_mock = Elibri::XmlMocks::Examples.review_mock
56
+ supply_details = Elibri::XmlMocks::Examples.supply_detail_mock
57
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS.merge(:other_texts => [review_mock], :product_availabilities => [supply_details], :record_reference => 'fdb8fa072be774d97a97'))
58
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(:other_texts => [review_mock], :product_availabilities => [supply_details], :record_reference => 'fdb8fa072be774d97a95'))
59
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
60
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => [:record_reference]})
61
+ end
62
+
63
+ it "should return added element when new review is added" do
64
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS.merge(:other_texts => [Elibri::XmlMocks::Examples.review_mock]))
65
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(:other_texts => [Elibri::XmlMocks::Examples.review_mock, Elibri::XmlMocks::Examples.review_mock(:text_author => "lobuz lobuzialski")]))
66
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
67
+ result = @elibri_xml_versions.diff
68
+ (@elibri_xml_versions.convert_arr_to_hash result[:added])[:reviews].count.should eq(2)
69
+ (@elibri_xml_versions.convert_arr_to_hash result[:deleted])[:reviews].count.should eq(1)
70
+ (@elibri_xml_versions.convert_arr_to_hash result[:added])[:text_contents].count.should eq(2)
71
+ (@elibri_xml_versions.convert_arr_to_hash result[:deleted])[:text_contents].count.should eq(1)
72
+ end
73
+
74
+ it "should return no changes for same onix_record_identifiers_example objects" do
75
+ generated_product = onix_from_mock(:onix_record_identifiers_example)
76
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product.products.first)
77
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
78
+ end
79
+
80
+ it "should return no changes for double generated onix_record_identifiers_example objects" do
81
+ generated_product = onix_from_mock(:onix_record_identifiers_example)
82
+ generated_product_2 = onix_from_mock(:onix_record_identifiers_example)
83
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
84
+ @elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => []})
85
+ end
86
+
87
+ SPLITTING_SYMBOLS = [
88
+ :publisher_name
89
+ ]
90
+
91
+ SIMPLE_SYMBOLS = [
92
+ :publisher_name, :record_reference
93
+ ]
94
+
95
+ TRAVERSE_VECTOR = {
96
+ :or_title => :original_title,
97
+ :publisher_name => :publisher_name,
98
+ :record_reference => :record_reference,
99
+ :deletion_text => :deletion_text,
100
+ :isbn_value => :isbn13,
101
+ :ean => :ean,
102
+ :deletion_text => :deletion_text,
103
+ :trade_title => :trade_title,
104
+ :pkwiu => :pkwiu_from_3_0_1,
105
+ :title => :title,
106
+ :subtitle => :subtitle,
107
+ :edition_statement => :edition_statement,
108
+ :audience_age_from => :reading_age_from,
109
+ :audience_age_to => :reading_age_to,
110
+ :price_amount => :cover_price_from_3_0_1,
111
+ :vat => :vat_from_3_0_1
112
+ }
113
+
114
+ #strings
115
+ [
116
+ :publisher_name, :record_reference,
117
+ :ean, :isbn_value, :deletion_text, :or_title,
118
+ :trade_title, :pkwiu, :title, :subtitle,
119
+ :edition_statement
120
+ ].each do |symbol|
121
+
122
+ it "should return change when #{symbol} change in two books objects (one with default settings)" do
123
+ string = "ehdroruwnm"
124
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS)
125
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(symbol => string) )
126
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
127
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
128
+ end
129
+
130
+ it "should return change when #{symbol} change in two books objects" do
131
+ string = "ehdroruwnm"
132
+ string2 = "TOXYAUEJ"
133
+ review_mock = Elibri::XmlMocks::Examples.review_mock
134
+ supply_details = Elibri::XmlMocks::Examples.supply_detail_mock
135
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS.merge(symbol => string))
136
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(symbol => string2))
137
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
138
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
139
+ end
140
+
141
+ it "should return change when #{symbol} change in two basic products objects (one with default settings)" do
142
+ string = "ehdroruwnm"
143
+ generated_product = onix_from_mock(:basic_product)
144
+ generated_product_2 = onix_from_mock(:basic_product, {symbol => string})
145
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
146
+ if SPLITTING_SYMBOLS.include?(symbol)
147
+ @elibri_xml_versions.diff[:changes].should include(symbol.to_s.split("_")[0].to_sym)
148
+ else
149
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
150
+ end
151
+ end
152
+
153
+ it "should return change when #{symbol} change in two basic products objects" do
154
+ string = "ehdroruwnm"
155
+ string2 = "TOXYAUEJ"
156
+ generated_product = onix_from_mock(:basic_product, {symbol => string})
157
+ generated_product_2 = onix_from_mock(:basic_product, {symbol => string2})
158
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
159
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
160
+ end
161
+
162
+ #end strings
163
+ end
164
+
165
+
166
+ #integers
167
+ [
168
+ :audience_age_from, :audience_age_to, :price_amount, :vat
169
+ ].each do |symbol|
170
+
171
+ it "should return change when #{symbol} change in two books objects (one with default settings)" do
172
+ string = 52
173
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS)
174
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(symbol => string))
175
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
176
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
177
+ end
178
+
179
+ it "should return change when #{symbol} change in two books objects" do
180
+ string = 52
181
+ string2 = 44
182
+ review_mock = Elibri::XmlMocks::Examples.review_mock
183
+ supply_details = Elibri::XmlMocks::Examples.supply_detail_mock
184
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS.merge(symbol => string))
185
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge(symbol => string2))
186
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
187
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
188
+ end
189
+
190
+ it "should return change when #{symbol} change in two basic products objects (one with default settings)" do
191
+ string = 52
192
+ generated_product = onix_from_mock(:basic_product)
193
+ generated_product_2 = onix_from_mock(:basic_product, {symbol => string})
194
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
195
+ if SPLITTING_SYMBOLS.include?(symbol)
196
+ @elibri_xml_versions.diff[:changes].should include(symbol.to_s.split("_")[0].to_sym)
197
+ else
198
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
199
+ end
200
+ end
201
+
202
+ it "should return change when #{symbol} change in two basic products objects" do
203
+ string = 52
204
+ string2 = 44
205
+ generated_product = onix_from_mock(:basic_product, {symbol => string})
206
+ generated_product_2 = onix_from_mock(:basic_product, {symbol => string2})
207
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
208
+ @elibri_xml_versions.diff[:changes].should include(TRAVERSE_VECTOR[symbol])
209
+ end
210
+
211
+ #end of integers
212
+ end
213
+
214
+ it "should detect change in object inside basic product" do
215
+ imprint = Elibri::XmlMocks::Examples.imprint_mock
216
+ imprint_2 = Elibri::XmlMocks::Examples.imprint_mock(:name => 'second')
217
+ generated_product = onix_from_mock(:basic_product, {:imprint => imprint})
218
+ generated_product_2 = onix_from_mock(:basic_product, {:imprint => imprint_2})
219
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
220
+ @elibri_xml_versions.diff[:changes].should include({:imprint => [:name]})
221
+ end
222
+
223
+ it "should detect change in object inside book product" do
224
+ imprint = Elibri::XmlMocks::Examples.imprint_mock
225
+ imprint_2 = Elibri::XmlMocks::Examples.imprint_mock(:name => 'second')
226
+ generated_product = onix_from_mock(:book_example, RAW_EXTRAS.merge({:imprint => imprint}))
227
+ generated_product_2 = onix_from_mock(:book_example, RAW_EXTRAS.merge({:imprint => imprint_2}))
228
+ @elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
229
+ @elibri_xml_versions.diff[:changes].should include({:imprint => [:name]})
230
+ end
231
+
232
+ end
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rspec'
5
+ require 'ostruct'
6
+ #require 'mocha'
7
+ require 'elibri_xml_versions' # and any other gems you need
8
+ require 'elibri_onix_mocks'
9
+ =begin
10
+ require 'support/mocks/xml_mocks'
11
+ require 'support/mocks/mock_method_missing'
12
+ require 'support/generators/xml_generator'
13
+ require 'support/xml_variant'
14
+ require 'support/onix_helpers'
15
+ =end
16
+
17
+
18
+
19
+
20
+ RSpec.configure do |config|
21
+ # some (optional) config here
22
+ end
23
+
24
+ def onix_from_mock(sym, *args)
25
+ Elibri::ONIX::Release_3_0::ONIXMessage.from_xml(Elibri::ONIX::XMLGenerator.new(Elibri::XmlMocks::Examples.send(sym, *args)).to_s)
26
+ end
27
+
28
+ def xml_parse(xml_string)
29
+ Elibri::ONIX::Release_3_0::ONIXMessage.from_xml(xml_string)
30
+ end
31
+
32
+ def generate_xml(mock)
33
+ Elibri::ONIX::XMLGenerator.new(mock)
34
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elibri_xml_versions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Piotr Szmielew
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: elibri_onix_mocks
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: elibri_api_client
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: elibri_onix_dict
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :runtime
89
+ version_requirements: *id005
90
+ description: |-
91
+ Gem created for comparing eLibri xml objects. More info coming soon. Currently working and tested only on REE.
92
+ Basic usage: Elibri::XmlVersions.new(product_ver1, product_ver2).diff
93
+ it will return hash: {:added => [], :changes => [], :deleted => []}
94
+ email:
95
+ - p.szmielew@ava.waw.pl
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .gitignore
104
+ - .travis.yml
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - elibri_xml_versions.gemspec
109
+ - lib/elibri_xml_versions.rb
110
+ - lib/elibri_xml_versions/version.rb
111
+ - spec/elibri_xml_versions_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: ""
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project: elibri_xml_versions
142
+ rubygems_version: 1.8.17
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Gem created for comparing eLibri xml objects.
146
+ test_files:
147
+ - spec/elibri_xml_versions_spec.rb
148
+ - spec/spec_helper.rb