simpex 0.0.5 → 0.1.0

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 CHANGED
@@ -3,3 +3,10 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in simpex.gemspec
4
4
  gemspec
5
5
 
6
+ group :test do
7
+ gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
8
+ gem 'guard-minitest'
9
+ gem 'mocha'
10
+ gem 'growl'
11
+ end
12
+
@@ -1,14 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simpex (0.0.1)
4
+ simpex (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ growl (1.0.3)
10
+ guard (1.4.0)
11
+ listen (>= 0.4.2)
12
+ thor (>= 0.14.6)
13
+ guard-minitest (0.5.0)
14
+ guard (>= 0.4)
15
+ listen (0.5.3)
16
+ metaclass (0.0.1)
17
+ mocha (0.12.6)
18
+ metaclass (~> 0.0.1)
19
+ rb-fsevent (0.9.2)
20
+ thor (0.16.0)
9
21
 
10
22
  PLATFORMS
11
23
  ruby
12
24
 
13
25
  DEPENDENCIES
26
+ growl
27
+ guard-minitest
28
+ mocha
29
+ rb-fsevent
14
30
  simpex!
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
7
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
+ watch(%r|^test/test_helper\.rb|) { "test" }
9
+
10
+ # with Minitest::Spec
11
+ # watch(%r|^spec/(.*)_spec\.rb|)
12
+ # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ # watch(%r|^spec/spec_helper\.rb|) { "spec" }
14
+
15
+ # Rails 3.2
16
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
17
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
18
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
19
+
20
+ # Rails
21
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
22
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
23
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
24
+ end
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ namespace :simpex do
8
8
  desc "Generates ImpEx file"
9
9
  task :generate do
10
10
  output_directory = "tmp"
11
+ FileUtils.mkdir(output_directory) unless Dir.exist?(output_directory)
11
12
  Factory.generate_base_catalog_setup_to(output_directory)
12
13
  Factory.generate_base_catalog_setup_to_file(output_directory,"single_file_result.csv")
13
14
  puts "Files generated inside #{output_directory}"
@@ -25,22 +25,48 @@ class ImpexResult
25
25
 
26
26
  def impexify(result_file_name="", time_stampify = false)
27
27
  stamp = Time.now.strftime("%S_%M_%H_%d_%m_%Y") if time_stampify
28
+ validate_macros
28
29
  if result_file_name.empty?
29
- @types.each_with_index do |type, index|
30
- if time_stampify
31
- file_name = "#{@dest_folder}/#{format_number(@impexify_occurences)}_#{type.name.downcase}_#{stamp}.csv"
32
- else
33
- file_name = "#{@dest_folder}/#{format_number(@impexify_occurences)}_#{type.name.downcase}.csv"
34
- end
35
- unless type.empty?
36
- puts "writing #{type.name} to #{file_name}"
37
- File.open(file_name, 'w') do |f|
38
- f.puts type.to_imp
39
- end
40
- @impexify_occurences += 1
41
- end
42
- end
30
+ write_file_for_each_type(stamp, time_stampify)
43
31
  else
32
+ write_result_to_one_file(result_file_name, stamp, time_stampify)
33
+ end
34
+ clean_all_type_entries
35
+ end
36
+
37
+ def format_number(number_to_format, numeric_positions="4")
38
+ "%0#{numeric_positions}d" % number_to_format
39
+ end
40
+
41
+ def global_enties_number
42
+ @global_enties_number
43
+ end
44
+
45
+ def add_entries_number(added_number)
46
+ @global_enties_number +=added_number
47
+ check_for_impexify
48
+ end
49
+
50
+ private
51
+ def validate_macros
52
+
53
+ #collect all macros from all types
54
+ @macros = @types.inject([]) do |result, type|
55
+ type.macros.each do |macro|
56
+ result << macro unless result.include?(macro)
57
+ end
58
+ result
59
+ end
60
+
61
+ #make sure each macro is used in at least one type
62
+ @macros.each do |macro|
63
+ if @types.none? {|type| type.attributes.include?(macro)}
64
+ raise ArgumentError.new "the macro #{macro} is never used in all declared types"
65
+ end
66
+ end
67
+ end
68
+ def write_result_to_one_file(result_file_name, stamp, time_stampify)
69
+ #will write the complete result to one file
44
70
  result_file_name = File.basename(result_file_name)
45
71
  if time_stampify
46
72
  file_name = "#{@dest_folder}/#{stamp}_#{result_file_name}"
@@ -67,36 +93,35 @@ class ImpexResult
67
93
  end
68
94
  @impexify_occurences += 1
69
95
  end
70
- clean_all_type_entries
71
- end
72
-
73
- def format_number(number_to_format, numeric_positions="4")
74
- "%0#{numeric_positions}d" % number_to_format
75
- end
76
-
77
- def global_enties_number
78
- @global_enties_number
79
- end
80
-
81
- def add_entries_number(added_number)
82
- @global_enties_number +=added_number
83
- check_for_impexify
84
- end
85
-
86
- private
87
- def clean_all_type_entries
88
- @types.each do |type|
89
- type.entries.clear
96
+ def write_file_for_each_type(stamp, time_stampify)
97
+ @types.each_with_index do |type, index|
98
+ if time_stampify
99
+ file_name = "#{@dest_folder}/#{format_number(@impexify_occurences)}_#{type.name.downcase}_#{stamp}.csv"
100
+ else
101
+ file_name = "#{@dest_folder}/#{format_number(@impexify_occurences)}_#{type.name.downcase}.csv"
102
+ end
103
+ unless type.empty?
104
+ puts "writing #{type.name} to #{file_name}"
105
+ File.open(file_name, 'w') do |f|
106
+ f.puts type.to_imp
107
+ end
108
+ @impexify_occurences += 1
109
+ end
110
+ end
90
111
  end
91
- @global_enties_number = 0
92
- end
93
- def check_for_impexify
94
- if @memory_safe
95
- if @global_enties_number > @max_type_entries_in_tree
96
- puts "impexifying all entries since global entries #{@global_enties_number} is bigger then max #{@max_type_entries_in_tree}"
97
- self.impexify
112
+ def clean_all_type_entries
113
+ @types.each do |type|
114
+ type.entries.clear
115
+ end
116
+ @global_enties_number = 0
117
+ end
118
+ def check_for_impexify
119
+ if @memory_safe
120
+ if @global_enties_number > @max_type_entries_in_tree
121
+ puts "impexifying all entries since global entries #{@global_enties_number} is bigger then max #{@max_type_entries_in_tree}"
122
+ self.impexify
123
+ end
98
124
  end
99
125
  end
100
126
  end
101
- end
102
127
 
@@ -23,8 +23,11 @@ class TypeEntry
23
23
  end
24
24
  end
25
25
  else
26
- if @type.attributes.size != values.size
27
- raise ArgumentError.new "The number of given attributes is less then defined, expected are #{@type.attributes.inspect}"
26
+ if @type.attributes.size < values.size
27
+ raise ArgumentError.new "The number of values for the type entry is more (#{values.size}) then defined (#{@type.attributes.size}), inside the type '#{type.name}' following attributes are expected #{type.attributes.inspect}"
28
+ end
29
+ if @type.attributes.size > values.size
30
+ raise ArgumentError.new "The number of values for the type entry is less (#{values.size}) then defined (#{@type.attributes.size}), inside the type '#{type.name}' following attributes are expected #{type.attributes.inspect}"
28
31
  end
29
32
  @type.attributes.each_with_index do |att,index|
30
33
  set(att, values[index])
@@ -1,4 +1,4 @@
1
1
  module Simpex
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
4
4
 
@@ -4,12 +4,9 @@ require 'fileutils'
4
4
 
5
5
  class TestResult < Test::Unit::TestCase
6
6
  def setup
7
- macros = []
8
- macros << "$firstmacro"
9
- macros << "$secondmacro"
10
7
 
11
- @category_type = Type.new("Category", %w{code[unique=true] name[lang=de]}, macros)
12
- @product_type = Type.new("Product", %w{code[unique=true] name[lang=en]}, macros)
8
+ @category_type = Type.new("Category", %w{code[unique=true] name[lang=de]})
9
+ @product_type = Type.new("Product", %w{code[unique=true] name[lang=en]})
13
10
 
14
11
  @impex_dest_dir = "test/tmp"
15
12
  FileUtils.mkdir(@impex_dest_dir) unless Dir.exist?(@impex_dest_dir)
@@ -29,8 +26,84 @@ class TestResult < Test::Unit::TestCase
29
26
  assert File.exist?(@result_file_path), "the file #{@result_file_path} should have been created"
30
27
  end
31
28
 
32
- def teardown
33
- #File.delete(@result_file_path)
29
+ def test_should_recognize_not_used_macros
30
+ macros = []
31
+ macros << "$firstmacro"
32
+ macros << "$secondmacro"
33
+
34
+ @category_type = Type.new("Category", %w{code[unique=true] name[lang=de]}, macros)
35
+ @product_type = Type.new("Product", %w{code[unique=true] name[lang=en]}, macros)
36
+
37
+ result = ImpexResult.new(@impex_dest_dir)
38
+ result << @category_type
39
+ result << @product_type
40
+
41
+
42
+ entry = TypeEntry.new(@product_type, %w{555 myproduct555})
43
+ entry = TypeEntry.new(@category_type, %w{555 mycategory})
44
+
45
+ assert_raises ArgumentError do
46
+ result.impexify("result.csv", false)
47
+ end
48
+
49
+ @product_type = Type.new("Product", %w{code[unique=true] name[lang=en] $firstmacro}, macros)
50
+ @category_type = Type.new("Category", %w{code[unique=true] name[lang=de]})
51
+ result = ImpexResult.new(@impex_dest_dir)
52
+ result << @category_type
53
+ result << @product_type
54
+ assert_raises ArgumentError do
55
+ result.impexify("result.csv", false)
56
+ end
57
+
58
+ @product_type = Type.new("Product", %w{code[unique=true] name[lang=en] $firstmacro}, macros)
59
+ @category_type = Type.new("Category", %w{code[unique=true] name[lang=de] $secondmacro}, macros)
60
+ result = ImpexResult.new(@impex_dest_dir)
61
+ result << @category_type
62
+ result << @product_type
63
+ result.impexify("result.csv", false)
64
+ end
65
+
66
+ def test_should_write_the_impex_resupt_to_the_given_folder
67
+ impex_dest_dir = "test/tmp"
68
+ FileUtils.mkdir(impex_dest_dir) unless Dir.exist?(impex_dest_dir)
69
+
70
+ result = standard_result(impex_dest_dir)
71
+ result.impexify
72
+
73
+ FileUtils.rm_rf(impex_dest_dir)
74
+ end
75
+
76
+ def test_should_write_the_result_in_one_file
77
+ impex_dest_dir = "test/tmp"
78
+ FileUtils.mkdir(impex_dest_dir) unless Dir.exist?(impex_dest_dir)
79
+ result_file_path = "#{impex_dest_dir}/result.csv"
80
+
81
+ assert !File.exist?(result_file_path)
82
+ result = standard_result(impex_dest_dir)
83
+ result.impexify("result.csv")
84
+ assert File.exist?(result_file_path), "the file #{result_file_path} should have been created"
85
+
86
+ File.delete(result_file_path)
87
+ end
88
+
89
+ private
90
+ def standard_result(impex_dest_dir)
91
+
92
+ language_type = Type.new("Language", %w{isocode[unique=true] active})
93
+ TypeEntry.new(language_type, %w{de true})
94
+ TypeEntry.new(language_type, %w{en true})
95
+
96
+ catalog_type = Type.new("Catalog", %w{id[unique=true] name[lang=de] name[lang=en] defaultCatalog})
97
+ catalog = TypeEntry.new(catalog_type, %w{simpex_catalog SimpexCatalog SimpexCatalog true})
98
+
99
+ catalog_version_type = Type.new("CatalogVersion", %w{catalog(id)[unique=true] version[unique=true] active defaultCurrency(isocode)})
100
+ TypeEntry.new(catalog_version_type, [catalog.id, "online", "true", "EUR"])
101
+
102
+ result = ImpexResult.new(impex_dest_dir)
103
+ result << language_type
104
+ result << catalog_type
105
+ result << catalog_version_type
106
+ result
34
107
  end
35
108
 
36
109
  end
@@ -46,6 +46,7 @@ class TestType < Test::Unit::TestCase
46
46
  macros = ["$catalogVersion=adsfasdfasdf", "$contentCV=someValue"]
47
47
  Type.new("MediaReference", %w{uid[unique=true] name referencedDamMedia(code,$contentCV)[lang=$lang] altText[lang=$lang] $contentCV[unique=true]}, macros)
48
48
  Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion[unique=true] supercategories(code)}, macros)
49
+ Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code,$catalogVersion) $catalogVersion[unique=true] supercategories(code)}, macros)
49
50
  end
50
51
 
51
52
  def test_type_should_validate_the_presence_of_macros_if_no_macros_are_given
@@ -60,77 +61,12 @@ class TestType < Test::Unit::TestCase
60
61
  Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVe[unique=true] supercategories(code)}, macros)
61
62
  end
62
63
 
63
- def test_shoud_add_an_after_each_statement
64
- bash_script = "#%afterEach: "
65
- after_each = "impex.getLastImportedItem().setApprovalStatus(impex.getLastImportedItem().getBaseProduct().getApprovalStatus());"
66
- product_type = Type.new("Product", %w{code[unique=true] name[lang=en]})
67
- TypeEntry.new(product_type,%w{ 666 denis})
68
- product_type.after_each << after_each
69
- assert_match /impex/, product_type.after_each.first
70
- assert_match /#%afterEach/, product_type.to_imp
71
- puts product_type.to_imp
72
- end
73
64
 
74
65
  def test_type_should_generate_nothing_if_no_entries
75
66
  assert_equal "", @product_type.to_imp(false)
76
67
  end
77
68
 
78
- def test_should_create_a_type_entry
79
- entry = TypeEntry.new(@product_type, {"code" => "333", "name[lang=de]" => "MyName"})
80
- @product_type << entry
81
- puts entry.inspect
82
- end
83
-
84
- def test_entry_should_verity_the_number_of_given_attributes
85
- assert_raises ArgumentError do
86
- entry = TypeEntry.new(@product_type, %w{66 myname myname pieces})
87
- end
88
- end
89
-
90
- def test_entry_should_handle_array_containnig_specific_types
91
- some_type = Type.new('SomeType', %w{code some_list_attribute})
92
- entry = TypeEntry.new(some_type, ["66", [1,2,3,4]])
93
- end
94
69
 
95
- def test_entry_should_reference_other_entries
96
- entry = TypeEntry.new(@product_type, {"code" => "333", "name[lang=en]" => "MyName"})
97
- @product_type << entry
98
-
99
- assert_equal "333", entry.get("code")
100
- assert_equal "MyName", entry.get("name[lang=en]")
101
- end
102
-
103
- def test_entry_should_validate_against_the_given_type_attributes
104
- product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de]})
105
- assert_raise ArgumentError do
106
- entry = TypeEntry.new(product_type, {"co" => "555"})
107
- end
108
- end
109
-
110
- def test_should_fail_if_wrong_values_given
111
- assert_raise ArgumentError do
112
- entry = TypeEntry.new(@product_type, "somewrong string")
113
- end
114
- assert_raise ArgumentError do
115
- entry = TypeEntry.new(nil, "somewrong string")
116
- end
117
- end
118
-
119
- def test_entry_should_accept_array_of_values_and_assign_them_to_columns_according_to_the_order
120
- entry = TypeEntry.new(@product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
121
- assert_equal "myproduct555", entry.get("name[lang=en]")
122
- assert_equal "meinproduct555", entry.get("name[lang=de]")
123
- assert_equal "SampleCategory", entry.get("supercategories(code)")
124
- end
125
-
126
-
127
- def test_entry_should_inforce_to_use_unique_attributes_if_needed_for_fuzzy_matching
128
- product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de]})
129
- entry = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 })
130
- assert_raise ArgumentError do
131
- entry.get("name")
132
- end
133
- end
134
70
 
135
71
  def test_should_create_impex_list_from_array
136
72
  catalog_version_type = Type.new("CatalogVersion", %w{languages(isocode)})
@@ -161,92 +97,10 @@ class TestType < Test::Unit::TestCase
161
97
  assert_equal 2, found.size
162
98
  end
163
99
 
164
- def test_entry_should_match_fuzzy_attribute_names
165
- product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion supercategories(code)}, @macros)
166
- entry = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
167
-
168
- assert_equal "555", entry.get("code")
169
- assert_equal "pieces", entry.get("unit")
170
- assert_equal "SampleCategory", entry.get("supercategories")
171
-
172
- assert_raise ArgumentError do
173
- entry.get("supercat")
174
- end
175
- end
176
-
177
100
  def test_entry_should_match_nested_brakets_attributes
178
101
  product_type = Type.new("Product", %w{code[unique=true] catalog(id)[unique=true]})
179
102
  entry = TypeEntry.new(product_type, %w{555 myCatalogId})
180
103
  assert_equal "myCatalogId", entry.catalog
181
104
  end
182
105
 
183
- def test_entry_should_give_catalog_version_specific_attributes
184
- product_type = Type.new("Product", %w{code[unique=true] $catalogVersion}, @macros)
185
- entry = TypeEntry.new(product_type, %w{555 myCatalogId:staged })
186
- assert_equal "555:myCatalogId:staged", entry.cat_ver_specific("code")
187
-
188
- assert_raise ArgumentError do
189
- product_type = Type.new("Product", %w{code[unique=true] someattr})
190
- entry = TypeEntry.new(product_type, %w{555 myCatalogId:staged })
191
- assert_equal "555:myCatalogId:staged", entry.cat_ver_specific("code")
192
- end
193
- end
194
-
195
- def test_entry_should_match_macro_attributes
196
- product_type = Type.new("Product", %w{code[unique=true] $catalogVersion},"$catalogVersion=asdfadsfasdfasdf")
197
- entry = TypeEntry.new(product_type, %w{555 myCatalogId})
198
- assert_equal "myCatalogId", entry.catalogVersion
199
- end
200
-
201
- def test_entry_should_match_fuzzy_attribute_names_to_real_attributes
202
- product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion supercategories(code)}, @macros)
203
- entry = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
204
-
205
- assert_equal "555", entry.code
206
- assert_equal "pieces", entry.unit
207
- assert_equal "SampleCategory", entry.supercategories
208
- end
209
-
210
- def test_should_write_the_impex_resupt_to_the_given_folder
211
- impex_dest_dir = "test/tmp"
212
- FileUtils.mkdir(impex_dest_dir) unless Dir.exist?(impex_dest_dir)
213
-
214
- result = standard_result(impex_dest_dir)
215
- result.impexify
216
-
217
- FileUtils.rm_rf(impex_dest_dir)
218
- end
219
-
220
- def test_should_write_the_result_in_one_file
221
- impex_dest_dir = "test/tmp"
222
- FileUtils.mkdir(impex_dest_dir) unless Dir.exist?(impex_dest_dir)
223
- result_file_path = "#{impex_dest_dir}/result.csv"
224
-
225
- assert !File.exist?(result_file_path)
226
- result = standard_result(impex_dest_dir)
227
- result.impexify("result.csv")
228
- assert File.exist?(result_file_path), "the file #{result_file_path} should have been created"
229
-
230
- File.delete(result_file_path)
231
- end
232
-
233
- private
234
- def standard_result(impex_dest_dir)
235
-
236
- language_type = Type.new("Language", %w{isocode[unique=true] active})
237
- TypeEntry.new(language_type, %w{de true})
238
- TypeEntry.new(language_type, %w{en true})
239
-
240
- catalog_type = Type.new("Catalog", %w{id[unique=true] name[lang=de] name[lang=en] defaultCatalog})
241
- catalog = TypeEntry.new(catalog_type, %w{simpex_catalog SimpexCatalog SimpexCatalog true})
242
-
243
- catalog_version_type = Type.new("CatalogVersion", %w{catalog(id)[unique=true] version[unique=true] active defaultCurrency(isocode)})
244
- TypeEntry.new(catalog_version_type, [catalog.id, "online", "true", "EUR"])
245
-
246
- result = ImpexResult.new(impex_dest_dir)
247
- result << language_type
248
- result << catalog_type
249
- result << catalog_version_type
250
- result
251
- end
252
106
  end
@@ -0,0 +1,182 @@
1
+ require 'test/unit'
2
+ require File.expand_path('simpex.rb', 'lib')
3
+ require 'fileutils'
4
+
5
+ class TestTypeEntry < Test::Unit::TestCase
6
+ def setup
7
+ @macros = "$catalogVersion=catalogversion(catalog(id[default='simpexproducts']), version[default='staged'])[unique=true,default='simpexproducts:staged']"
8
+
9
+ @category_type = Type.new("Category", %w{code[unique=true] $catalogVersion name[lang=de] name[lang=en]}, @macros)
10
+
11
+ @product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion supercategories(code)}, @macros)
12
+ end
13
+
14
+
15
+ def test_shoud_add_an_after_each_statement
16
+ bash_script = "#%afterEach: "
17
+ after_each = "impex.getLastImportedItem().setApprovalStatus(impex.getLastImportedItem().getBaseProduct().getApprovalStatus());"
18
+ product_type = Type.new("Product", %w{code[unique=true] name[lang=en]})
19
+ TypeEntry.new(product_type,%w{ 666 denis})
20
+ product_type.after_each << after_each
21
+ assert_match /impex/, product_type.after_each.first
22
+ assert_match /#%afterEach/, product_type.to_imp
23
+ end
24
+
25
+ def test_should_create_a_type_entry
26
+ entry = TypeEntry.new(@product_type, {"code" => "333", "name[lang=de]" => "MyName"})
27
+ @product_type << entry
28
+ end
29
+
30
+ def test_entry_should_handle_array_containnig_specific_types
31
+ some_type = Type.new('SomeType', %w{code some_list_attribute})
32
+ entry = TypeEntry.new(some_type, ["66", [1,2,3,4]])
33
+ end
34
+
35
+ def test_entry_should_reference_other_entries
36
+ entry = TypeEntry.new(@product_type, {"code" => "333", "name[lang=en]" => "MyName"})
37
+ @product_type << entry
38
+
39
+ assert_equal "333", entry.get("code")
40
+ assert_equal "MyName", entry.get("name[lang=en]")
41
+ end
42
+
43
+ def test_entry_should_validate_against_the_given_type_attributes
44
+ product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de]})
45
+ assert_raise ArgumentError do
46
+ entry = TypeEntry.new(product_type, {"co" => "555"})
47
+ end
48
+ end
49
+
50
+ def test_should_fail_if_wrong_values_given
51
+ assert_raise ArgumentError do
52
+ entry = TypeEntry.new(@product_type, "somewrong string")
53
+ end
54
+ assert_raise ArgumentError do
55
+ entry = TypeEntry.new(nil, "somewrong string")
56
+ end
57
+ end
58
+
59
+ def test_entry_should_accept_array_of_values_and_assign_them_to_columns_according_to_the_order
60
+ entry = TypeEntry.new(@product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
61
+ assert_equal "myproduct555", entry.get("name[lang=en]")
62
+ assert_equal "meinproduct555", entry.get("name[lang=de]")
63
+ assert_equal "SampleCategory", entry.get("supercategories(code)")
64
+ end
65
+
66
+
67
+ def test_entry_should_inforce_to_use_unique_attributes_if_needed_for_fuzzy_matching
68
+ product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de]})
69
+ entry = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 })
70
+ assert_raise ArgumentError do
71
+ entry.get("name")
72
+ end
73
+ end
74
+
75
+ def test_should_create_impex_list_from_array
76
+ catalog_version_type = Type.new("CatalogVersion", %w{languages(isocode)})
77
+
78
+ entry = TypeEntry.new(catalog_version_type, [%w{en de fr it}])
79
+ assert_equal "en,de,fr,it", entry.languages
80
+
81
+ entry2 = TypeEntry.new(catalog_version_type, [["en", nil, "it"]])
82
+ assert_equal "en,it", entry2.languages
83
+ end
84
+
85
+ def test_type_should_unregister_an_entry_by_attribute
86
+ product_type = Type.new("Product", %w{code})
87
+ entry = TypeEntry.new(product_type, %w{555 })
88
+
89
+ assert product_type.entries.one?{|e|e.code == "555"}
90
+ product_type.unregister_by("code", "555")
91
+ assert product_type.entries.none?{|e|e.code == "555"}
92
+ end
93
+
94
+ def test_type_should_find_entry_by_attribute
95
+ product_type = Type.new("Product", %w{code})
96
+ assert product_type.find_by("code", "555").empty?
97
+ entry = TypeEntry.new(product_type, %w{555})
98
+ entry = TypeEntry.new(product_type, %w{555})
99
+ entry = TypeEntry.new(product_type, %w{556})
100
+ found = product_type.find_by("code", "555")
101
+ assert_equal 2, found.size
102
+ end
103
+
104
+ def test_entry_should_match_fuzzy_attribute_names
105
+ product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion supercategories(code)}, @macros)
106
+ entry = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
107
+
108
+ assert_equal "555", entry.get("code")
109
+ assert_equal "pieces", entry.get("unit")
110
+ assert_equal "SampleCategory", entry.get("supercategories")
111
+
112
+ assert_raise ArgumentError do
113
+ entry.get("supercat")
114
+ end
115
+ end
116
+
117
+ def test_entry_should_match_nested_brakets_attributes
118
+ product_type = Type.new("Product", %w{code[unique=true] catalog(id)[unique=true]})
119
+ entry = TypeEntry.new(product_type, %w{555 myCatalogId})
120
+ assert_equal "myCatalogId", entry.catalog
121
+ end
122
+
123
+ def test_entry_should_give_catalog_version_specific_attributes
124
+ product_type = Type.new("Product", %w{code[unique=true] $catalogVersion}, @macros)
125
+ entry = TypeEntry.new(product_type, %w{555 myCatalogId:staged })
126
+ assert_equal "555:myCatalogId:staged", entry.cat_ver_specific("code")
127
+
128
+ assert_raise ArgumentError do
129
+ product_type = Type.new("Product", %w{code[unique=true] someattr})
130
+ entry = TypeEntry.new(product_type, %w{555 myCatalogId:staged })
131
+ assert_equal "555:myCatalogId:staged", entry.cat_ver_specific("code")
132
+ end
133
+ end
134
+
135
+ def test_entry_should_match_macro_attributes
136
+ product_type = Type.new("Product", %w{code[unique=true] $catalogVersion},"$catalogVersion=asdfadsfasdfasdf")
137
+ entry = TypeEntry.new(product_type, %w{555 myCatalogId})
138
+ assert_equal "myCatalogId", entry.catalogVersion
139
+ end
140
+
141
+ def test_entry_should_match_fuzzy_attribute_names_to_real_attributes
142
+ product_type = Type.new("Product", %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion supercategories(code)}, @macros)
143
+ entry = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
144
+
145
+ assert_equal "555", entry.code
146
+ assert_equal "pieces", entry.unit
147
+ assert_equal "SampleCategory", entry.supercategories
148
+ end
149
+
150
+ def test_should_give_feedback_about_wrong_numbers_of_attributes
151
+ assert_raises ArgumentError do
152
+ language_type = Type.new("Language", %w{isocode[unique=true] active someOtherAtt})
153
+ TypeEntry.new(language_type, %w{de true})
154
+ end
155
+
156
+ assert_raises ArgumentError do
157
+ language_type = Type.new("Language", %w{isocode[unique=true] active})
158
+ TypeEntry.new(language_type, %w{de true xxx})
159
+ end
160
+
161
+ end
162
+
163
+ private
164
+ def standard_result(impex_dest_dir)
165
+
166
+ language_type = Type.new("Language", %w{isocode[unique=true] active})
167
+ TypeEntry.new(language_type, %w{de true})
168
+ TypeEntry.new(language_type, %w{en true})
169
+
170
+ catalog_type = Type.new("Catalog", %w{id[unique=true] name[lang=de] name[lang=en] defaultCatalog})
171
+ catalog = TypeEntry.new(catalog_type, %w{simpex_catalog SimpexCatalog SimpexCatalog true})
172
+
173
+ catalog_version_type = Type.new("CatalogVersion", %w{catalog(id)[unique=true] version[unique=true] active defaultCurrency(isocode)})
174
+ TypeEntry.new(catalog_version_type, [catalog.id, "online", "true", "EUR"])
175
+
176
+ result = ImpexResult.new(impex_dest_dir)
177
+ result << language_type
178
+ result << catalog_type
179
+ result << catalog_version_type
180
+ result
181
+ end
182
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
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: 2012-09-10 00:00:00.000000000Z
12
+ date: 2012-10-04 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Read more details at the homepage https://github.com/denislutz/simpex
15
15
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - .rvmrc
24
24
  - Gemfile
25
25
  - Gemfile.lock
26
+ - Guardfile
26
27
  - Rakefile
27
28
  - lib/simpex.rb
28
29
  - lib/simpex/catalog.rb
@@ -37,6 +38,7 @@ files:
37
38
  - test/test_result.rb
38
39
  - test/test_rich_types.rb
39
40
  - test/test_type.rb
41
+ - test/test_type_entry.rb
40
42
  homepage: https://github.com/denislutz/simpex
41
43
  licenses: []
42
44
  post_install_message:
@@ -66,3 +68,4 @@ test_files:
66
68
  - test/test_result.rb
67
69
  - test/test_rich_types.rb
68
70
  - test/test_type.rb
71
+ - test/test_type_entry.rb