importer 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +110 -0
- data/Rakefile +3 -57
- data/importer.gemspec +23 -111
- data/lib/importer.rb +2 -2
- data/lib/importer/parser.rb +0 -2
- data/lib/importer/version.rb +3 -0
- data/test/helper.rb +9 -5
- data/test/importer/adapters/active_record_adapter_test.rb +14 -5
- data/test/importer/adapters/data_mapper_adapter_test.rb +18 -6
- data/test/importer/adapters/mongo_mapper_adapter_test.rb +4 -3
- metadata +57 -92
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
importer (0.4.3)
|
5
|
+
crack (>= 0.1.6)
|
6
|
+
fastercsv (>= 1.5.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.2.5)
|
12
|
+
activesupport (= 3.2.5)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activerecord (3.2.5)
|
15
|
+
activemodel (= 3.2.5)
|
16
|
+
activesupport (= 3.2.5)
|
17
|
+
arel (~> 3.0.2)
|
18
|
+
tzinfo (~> 0.3.29)
|
19
|
+
activesupport (3.2.5)
|
20
|
+
i18n (~> 0.6)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
addressable (2.2.8)
|
23
|
+
arel (3.0.2)
|
24
|
+
bcrypt-ruby (3.0.1)
|
25
|
+
bson (1.6.2)
|
26
|
+
builder (3.0.0)
|
27
|
+
crack (0.3.1)
|
28
|
+
data_objects (0.10.8)
|
29
|
+
addressable (~> 2.1)
|
30
|
+
datamapper (1.2.0)
|
31
|
+
dm-aggregates (~> 1.2.0)
|
32
|
+
dm-constraints (~> 1.2.0)
|
33
|
+
dm-core (~> 1.2.0)
|
34
|
+
dm-migrations (~> 1.2.0)
|
35
|
+
dm-serializer (~> 1.2.0)
|
36
|
+
dm-timestamps (~> 1.2.0)
|
37
|
+
dm-transactions (~> 1.2.0)
|
38
|
+
dm-types (~> 1.2.0)
|
39
|
+
dm-validations (~> 1.2.0)
|
40
|
+
dm-aggregates (1.2.0)
|
41
|
+
dm-core (~> 1.2.0)
|
42
|
+
dm-constraints (1.2.0)
|
43
|
+
dm-core (~> 1.2.0)
|
44
|
+
dm-core (1.2.0)
|
45
|
+
addressable (~> 2.2.6)
|
46
|
+
dm-do-adapter (1.2.0)
|
47
|
+
data_objects (~> 0.10.6)
|
48
|
+
dm-core (~> 1.2.0)
|
49
|
+
dm-migrations (1.2.0)
|
50
|
+
dm-core (~> 1.2.0)
|
51
|
+
dm-serializer (1.2.1)
|
52
|
+
dm-core (~> 1.2.0)
|
53
|
+
fastercsv (~> 1.5.4)
|
54
|
+
json (~> 1.6.1)
|
55
|
+
json_pure (~> 1.6.1)
|
56
|
+
multi_json (~> 1.0.3)
|
57
|
+
dm-sqlite-adapter (1.2.0)
|
58
|
+
dm-do-adapter (~> 1.2.0)
|
59
|
+
do_sqlite3 (~> 0.10.6)
|
60
|
+
dm-timestamps (1.2.0)
|
61
|
+
dm-core (~> 1.2.0)
|
62
|
+
dm-transactions (1.2.0)
|
63
|
+
dm-core (~> 1.2.0)
|
64
|
+
dm-types (1.2.1)
|
65
|
+
bcrypt-ruby (~> 3.0.0)
|
66
|
+
dm-core (~> 1.2.0)
|
67
|
+
fastercsv (~> 1.5.4)
|
68
|
+
json (~> 1.6.1)
|
69
|
+
multi_json (~> 1.0.3)
|
70
|
+
stringex (~> 1.3.0)
|
71
|
+
uuidtools (~> 2.1.2)
|
72
|
+
dm-validations (1.2.0)
|
73
|
+
dm-core (~> 1.2.0)
|
74
|
+
do_sqlite3 (0.10.8)
|
75
|
+
data_objects (= 0.10.8)
|
76
|
+
fastercsv (1.5.5)
|
77
|
+
i18n (0.6.0)
|
78
|
+
json (1.6.7)
|
79
|
+
json_pure (1.6.7)
|
80
|
+
mongo (1.6.2)
|
81
|
+
bson (~> 1.6.2)
|
82
|
+
mongo_mapper (0.11.1)
|
83
|
+
activemodel (~> 3.0)
|
84
|
+
activesupport (~> 3.0)
|
85
|
+
plucky (~> 0.4.0)
|
86
|
+
multi_json (1.0.4)
|
87
|
+
plucky (0.4.4)
|
88
|
+
mongo (~> 1.5)
|
89
|
+
rr (1.0.4)
|
90
|
+
sqlite3 (1.3.6)
|
91
|
+
sqlite3-ruby (1.3.3)
|
92
|
+
sqlite3 (>= 1.3.3)
|
93
|
+
stringex (1.3.3)
|
94
|
+
thoughtbot-shoulda (2.11.1)
|
95
|
+
tzinfo (0.3.33)
|
96
|
+
uuidtools (2.1.2)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
activerecord (= 3.2.5)
|
103
|
+
datamapper (= 1.2)
|
104
|
+
dm-sqlite-adapter (= 1.2)
|
105
|
+
do_sqlite3 (= 0.10.8)
|
106
|
+
importer!
|
107
|
+
mongo_mapper (= 0.11.1)
|
108
|
+
rr (= 1.0.4)
|
109
|
+
sqlite3-ruby (= 1.3.3)
|
110
|
+
thoughtbot-shoulda (= 2.11.1)
|
data/Rakefile
CHANGED
@@ -1,63 +1,9 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "importer"
|
8
|
-
gem.summary = %Q{Import objects from external files}
|
9
|
-
gem.description = %Q{Define new objects or modifications of existing ones in external file (xml, csv, etc) and import them to your application. Importer will not only import all the objects but also will give you detailed summary of the import process.}
|
10
|
-
gem.email = "michal.szajbe@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/szajbus/importer"
|
12
|
-
gem.authors = ["Michał Szajbe"]
|
13
|
-
gem.add_dependency "crack", ">= 0.1.6"
|
14
|
-
gem.add_dependency "fastercsv", ">= 1.5.0"
|
15
|
-
gem.add_dependency "activesupport", ">= 0"
|
16
|
-
gem.add_development_dependency "activerecord", ">= 0"
|
17
|
-
gem.add_development_dependency "mongo_mapper", ">= 0.7.0"
|
18
|
-
gem.add_development_dependency "dm-core", ">= 0.10.2"
|
19
|
-
gem.add_development_dependency "dm-validations", ">= 0.10.2"
|
20
|
-
gem.add_development_dependency "dm-aggregates", ">= 0.10.2"
|
21
|
-
gem.add_development_dependency "do_sqlite3", ">= 0.10.1.1"
|
22
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
23
|
-
gem.add_development_dependency 'sqlite3-ruby'
|
24
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
25
|
-
end
|
26
|
-
Jeweler::GemcutterTasks.new
|
27
|
-
rescue LoadError
|
28
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
29
|
-
end
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
30
3
|
|
31
4
|
require 'rake/testtask'
|
32
5
|
Rake::TestTask.new(:test) do |test|
|
33
6
|
test.libs << 'lib' << 'test'
|
34
7
|
test.pattern = 'test/**/*_test.rb'
|
35
8
|
test.verbose = true
|
36
|
-
end
|
37
|
-
|
38
|
-
begin
|
39
|
-
require 'rcov/rcovtask'
|
40
|
-
Rcov::RcovTask.new do |test|
|
41
|
-
test.libs << 'test'
|
42
|
-
test.pattern = 'test/**/*_test.rb'
|
43
|
-
test.verbose = true
|
44
|
-
end
|
45
|
-
rescue LoadError
|
46
|
-
task :rcov do
|
47
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
task :test => :check_dependencies
|
52
|
-
|
53
|
-
task :default => :test
|
54
|
-
|
55
|
-
require 'rake/rdoctask'
|
56
|
-
Rake::RDocTask.new do |rdoc|
|
57
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
58
|
-
|
59
|
-
rdoc.rdoc_dir = 'rdoc'
|
60
|
-
rdoc.title = "importer #{version}"
|
61
|
-
rdoc.rdoc_files.include('README*')
|
62
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
63
|
-
end
|
9
|
+
end
|
data/importer.gemspec
CHANGED
@@ -1,117 +1,29 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/importer/version', __FILE__)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Micha\xC5\x82 Szajbe"]
|
6
|
+
gem.email = ["michal.szajbe@gmail.com"]
|
7
|
+
gem.description = %q{Define new objects or modifications of existing ones in external file (xml, csv, etc) and import them to your application. Importer will not only import all the objects but also will give you detailed summary of the import process.}
|
8
|
+
gem.summary = %q{Import objects from external files}
|
9
|
+
gem.homepage = %q{http://github.com/szajbus/importer}
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"importer.gemspec",
|
27
|
-
"lib/importer.rb",
|
28
|
-
"lib/importer/adapters/active_record_adapter.rb",
|
29
|
-
"lib/importer/adapters/data_mapper_adapter.rb",
|
30
|
-
"lib/importer/adapters/mongo_mapper_adapter.rb",
|
31
|
-
"lib/importer/import.rb",
|
32
|
-
"lib/importer/imported_object.rb",
|
33
|
-
"lib/importer/parser.rb",
|
34
|
-
"lib/importer/parser/base.rb",
|
35
|
-
"lib/importer/parser/csv.rb",
|
36
|
-
"lib/importer/parser/xml.rb",
|
37
|
-
"rails/init.rb",
|
38
|
-
"test/database.yml",
|
39
|
-
"test/factories.rb",
|
40
|
-
"test/fixtures/empty.csv",
|
41
|
-
"test/fixtures/empty.xml",
|
42
|
-
"test/fixtures/product.csv",
|
43
|
-
"test/fixtures/product.xml",
|
44
|
-
"test/fixtures/products.csv",
|
45
|
-
"test/fixtures/products.xml",
|
46
|
-
"test/helper.rb",
|
47
|
-
"test/importer/adapters/active_record_adapter_test.rb",
|
48
|
-
"test/importer/adapters/data_mapper_adapter_test.rb",
|
49
|
-
"test/importer/adapters/mongo_mapper_adapter_test.rb",
|
50
|
-
"test/importer/import_test.rb",
|
51
|
-
"test/importer/imported_object_test.rb",
|
52
|
-
"test/importer/parser/csv_test.rb",
|
53
|
-
"test/importer/parser/xml_test.rb",
|
54
|
-
"test/importer/parser_test.rb"
|
55
|
-
]
|
56
|
-
s.homepage = %q{http://github.com/szajbus/importer}
|
57
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
58
|
-
s.require_paths = ["lib"]
|
59
|
-
s.rubygems_version = %q{1.3.6}
|
60
|
-
s.summary = %q{Import objects from external files}
|
61
|
-
s.test_files = [
|
62
|
-
"test/factories.rb",
|
63
|
-
"test/helper.rb",
|
64
|
-
"test/importer/adapters/active_record_adapter_test.rb",
|
65
|
-
"test/importer/adapters/data_mapper_adapter_test.rb",
|
66
|
-
"test/importer/adapters/mongo_mapper_adapter_test.rb",
|
67
|
-
"test/importer/import_test.rb",
|
68
|
-
"test/importer/imported_object_test.rb",
|
69
|
-
"test/importer/parser/csv_test.rb",
|
70
|
-
"test/importer/parser/xml_test.rb",
|
71
|
-
"test/importer/parser_test.rb"
|
72
|
-
]
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "importer"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Importer::VERSION
|
73
17
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
s.add_development_dependency(%q<dm-core>, [">= 0.10.2"])
|
85
|
-
s.add_development_dependency(%q<dm-validations>, [">= 0.10.2"])
|
86
|
-
s.add_development_dependency(%q<dm-aggregates>, [">= 0.10.2"])
|
87
|
-
s.add_development_dependency(%q<do_sqlite3>, [">= 0.10.1.1"])
|
88
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
89
|
-
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
90
|
-
else
|
91
|
-
s.add_dependency(%q<crack>, [">= 0.1.6"])
|
92
|
-
s.add_dependency(%q<fastercsv>, [">= 1.5.0"])
|
93
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
94
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
95
|
-
s.add_dependency(%q<mongo_mapper>, [">= 0.7.0"])
|
96
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.2"])
|
97
|
-
s.add_dependency(%q<dm-validations>, [">= 0.10.2"])
|
98
|
-
s.add_dependency(%q<dm-aggregates>, [">= 0.10.2"])
|
99
|
-
s.add_dependency(%q<do_sqlite3>, [">= 0.10.1.1"])
|
100
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
101
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
102
|
-
end
|
103
|
-
else
|
104
|
-
s.add_dependency(%q<crack>, [">= 0.1.6"])
|
105
|
-
s.add_dependency(%q<fastercsv>, [">= 1.5.0"])
|
106
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
107
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
108
|
-
s.add_dependency(%q<mongo_mapper>, [">= 0.7.0"])
|
109
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.2"])
|
110
|
-
s.add_dependency(%q<dm-validations>, [">= 0.10.2"])
|
111
|
-
s.add_dependency(%q<dm-aggregates>, [">= 0.10.2"])
|
112
|
-
s.add_dependency(%q<do_sqlite3>, [">= 0.10.1.1"])
|
113
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
114
|
-
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
115
|
-
end
|
18
|
+
gem.add_runtime_dependency "crack", ">= 0.1.6"
|
19
|
+
gem.add_runtime_dependency "fastercsv", ">= 1.5.0"
|
20
|
+
gem.add_development_dependency "activerecord", "3.2.5"
|
21
|
+
gem.add_development_dependency "mongo_mapper", "0.11.1"
|
22
|
+
gem.add_development_dependency "datamapper", "1.2"
|
23
|
+
gem.add_development_dependency "dm-sqlite-adapter", "1.2"
|
24
|
+
gem.add_development_dependency "do_sqlite3", "0.10.8"
|
25
|
+
gem.add_development_dependency "thoughtbot-shoulda", "2.11.1"
|
26
|
+
gem.add_development_dependency "sqlite3-ruby", "1.3.3"
|
27
|
+
gem.add_development_dependency "rr", "1.0.4"
|
116
28
|
end
|
117
29
|
|
data/lib/importer.rb
CHANGED
@@ -31,9 +31,9 @@ module Importer
|
|
31
31
|
def included(base)
|
32
32
|
if base.respond_to?(:descends_from_active_record?) && base.descends_from_active_record?
|
33
33
|
base.send(:include, Importer::Adapters::ActiveRecordAdapter)
|
34
|
-
elsif defined?(MongoMapper) && (base.include?(MongoMapper::Document) || base.include?(MongoMapper::EmbeddedDocument))
|
34
|
+
elsif defined?(MongoMapper) && (base.ancestors.include?(MongoMapper::Document) || base.ancestors.include?(MongoMapper::EmbeddedDocument))
|
35
35
|
base.send(:include, Importer::Adapters::MongoMapperAdapter)
|
36
|
-
elsif defined?(DataMapper) && (base.include?(DataMapper::Resource))
|
36
|
+
elsif defined?(DataMapper) && (base.ancestors.include?(DataMapper::Resource))
|
37
37
|
base.send(:include, Importer::Adapters::DataMapperAdapter)
|
38
38
|
else
|
39
39
|
raise AdapterError.new("Can't determine adapter for #{base.class} class.")
|
data/lib/importer/parser.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
##
|
2
|
+
# Use Bundler
|
3
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
3
6
|
require 'shoulda'
|
4
7
|
require 'rr'
|
5
8
|
require 'active_record'
|
6
9
|
require 'mongo_mapper'
|
7
10
|
require 'dm-core'
|
8
11
|
require 'dm-validations'
|
12
|
+
require 'dm-migrations'
|
9
13
|
require 'dm-aggregates'
|
14
|
+
require 'dm-transactions'
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
##
|
17
|
+
# Load importer
|
14
18
|
require 'importer'
|
15
19
|
|
16
20
|
config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
@@ -42,9 +42,10 @@ class Importer::Adapters::ActiveRecordAdapterTest < Test::Unit::TestCase
|
|
42
42
|
@import = Product.import(fixture_file("products.xml"))
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
should "correctly update existing product" do
|
46
|
+
assert_equal "A black ball", @product.reload.name
|
47
|
+
end
|
46
48
|
|
47
|
-
should_change("products count", :by => 1) { Product.count }
|
48
49
|
should "correctly create new product" do
|
49
50
|
product = Product.last
|
50
51
|
|
@@ -82,7 +83,7 @@ class Importer::Adapters::ActiveRecordAdapterTest < Test::Unit::TestCase
|
|
82
83
|
context "when there is exception during import process" do
|
83
84
|
setup do
|
84
85
|
def_class("InvalidProduct", Product) do
|
85
|
-
|
86
|
+
table_name = "products"
|
86
87
|
|
87
88
|
def self.find_on_import(import, attributes)
|
88
89
|
if attributes["customid"] == "3"
|
@@ -98,14 +99,22 @@ class Importer::Adapters::ActiveRecordAdapterTest < Test::Unit::TestCase
|
|
98
99
|
rescue ::Exception => e
|
99
100
|
@exception = e
|
100
101
|
end
|
102
|
+
|
103
|
+
@count = InvalidProduct.count
|
101
104
|
end
|
102
105
|
|
103
106
|
def teardown
|
104
107
|
undef_class("InvalidProduct")
|
105
108
|
end
|
106
109
|
|
107
|
-
|
108
|
-
|
110
|
+
should "not update existing product" do
|
111
|
+
assert_equal "A pink ball", @product.reload.name
|
112
|
+
end
|
113
|
+
|
114
|
+
should "not create new products" do
|
115
|
+
assert_equal @count, InvalidProduct.count
|
116
|
+
end
|
117
|
+
|
109
118
|
should "propagate exception" do
|
110
119
|
assert_equal "An error occured.", @exception.message
|
111
120
|
end
|
@@ -6,19 +6,20 @@ class Importer::Adapters::DataMapperAdapterTest < Test::Unit::TestCase
|
|
6
6
|
include DataMapper::Resource
|
7
7
|
include Importer
|
8
8
|
|
9
|
-
property :id, DataMapper::
|
9
|
+
property :id, DataMapper::Property::Serial
|
10
10
|
property :customid, String
|
11
11
|
property :name, String
|
12
12
|
property :description, String
|
13
13
|
property :price, Float
|
14
14
|
|
15
|
-
|
15
|
+
validates_numericality_of :price
|
16
16
|
|
17
17
|
def self.find_on_import(import, attributes)
|
18
18
|
first(:customid => attributes["customid"])
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
DataMapper.finalize
|
22
23
|
DataMapper.auto_migrate!
|
23
24
|
end
|
24
25
|
|
@@ -44,9 +45,10 @@ class Importer::Adapters::DataMapperAdapterTest < Test::Unit::TestCase
|
|
44
45
|
@import = Product.import(fixture_file("products.xml"))
|
45
46
|
end
|
46
47
|
|
47
|
-
|
48
|
+
should "correctly update existing product" do
|
49
|
+
assert_equal "A black ball", @product.reload.name
|
50
|
+
end
|
48
51
|
|
49
|
-
should_change("products count", :by => 1) { Product.count }
|
50
52
|
should "correctly create new product" do
|
51
53
|
product = Product.last
|
52
54
|
|
@@ -95,19 +97,29 @@ class Importer::Adapters::DataMapperAdapterTest < Test::Unit::TestCase
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
100
|
+
DataMapper.finalize
|
101
|
+
|
98
102
|
begin
|
99
103
|
InvalidProduct.import(fixture_file("products.xml"))
|
100
104
|
rescue ::Exception => e
|
101
105
|
@exception = e
|
102
106
|
end
|
107
|
+
|
108
|
+
@count = InvalidProduct.count
|
103
109
|
end
|
104
110
|
|
105
111
|
def teardown
|
106
112
|
undef_class("InvalidProduct")
|
107
113
|
end
|
108
114
|
|
109
|
-
|
110
|
-
|
115
|
+
should "not update exising product" do
|
116
|
+
assert_equal "A pink ball", @product.reload.name
|
117
|
+
end
|
118
|
+
|
119
|
+
should "not create new products" do
|
120
|
+
assert_equal @count, InvalidProduct.count
|
121
|
+
end
|
122
|
+
|
111
123
|
should "propagate exception" do
|
112
124
|
assert_equal "An error occured.", @exception.message
|
113
125
|
end
|
@@ -42,9 +42,10 @@ class Importer::Adapters::MongoMapperAdapterTest < Test::Unit::TestCase
|
|
42
42
|
@import = Product.import(fixture_file("products.xml"))
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
should "correctly update existing product" do
|
46
|
+
assert_equal "A black ball", @product.reload.name
|
47
|
+
end
|
46
48
|
|
47
|
-
should_change("products count", :by => 1) { Product.count }
|
48
49
|
should "correctly create new product" do
|
49
50
|
product = Product.find_by_customid("2")
|
50
51
|
|
@@ -75,7 +76,7 @@ class Importer::Adapters::MongoMapperAdapterTest < Test::Unit::TestCase
|
|
75
76
|
|
76
77
|
assert_equal @invalid_object, invalid_object.data
|
77
78
|
assert_equal 'invalid_object', invalid_object.state
|
78
|
-
assert_equal ["Price
|
79
|
+
assert_equal ["Price is not a number"], invalid_object.validation_errors
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 4
|
8
|
-
- 3
|
9
|
-
version: 0.4.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.4
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- "Micha\xC5\x82 Szajbe"
|
@@ -14,20 +10,16 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
13
|
+
date: 2012-06-05 00:00:00 Z
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: crack
|
22
17
|
prerelease: false
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 1
|
30
|
-
- 6
|
31
23
|
version: 0.1.6
|
32
24
|
type: :runtime
|
33
25
|
version_requirements: *id001
|
@@ -35,147 +27,115 @@ dependencies:
|
|
35
27
|
name: fastercsv
|
36
28
|
prerelease: false
|
37
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
38
31
|
requirements:
|
39
32
|
- - ">="
|
40
33
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 1
|
43
|
-
- 5
|
44
|
-
- 0
|
45
34
|
version: 1.5.0
|
46
35
|
type: :runtime
|
47
36
|
version_requirements: *id002
|
48
37
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
38
|
+
name: activerecord
|
50
39
|
prerelease: false
|
51
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
52
42
|
requirements:
|
53
|
-
- - "
|
43
|
+
- - "="
|
54
44
|
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
version: "0"
|
58
|
-
type: :runtime
|
45
|
+
version: 3.2.5
|
46
|
+
type: :development
|
59
47
|
version_requirements: *id003
|
60
48
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
49
|
+
name: mongo_mapper
|
62
50
|
prerelease: false
|
63
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
64
53
|
requirements:
|
65
|
-
- - "
|
54
|
+
- - "="
|
66
55
|
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
- 0
|
69
|
-
version: "0"
|
56
|
+
version: 0.11.1
|
70
57
|
type: :development
|
71
58
|
version_requirements: *id004
|
72
59
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
60
|
+
name: datamapper
|
74
61
|
prerelease: false
|
75
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
76
64
|
requirements:
|
77
|
-
- - "
|
65
|
+
- - "="
|
78
66
|
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
- 0
|
81
|
-
- 7
|
82
|
-
- 0
|
83
|
-
version: 0.7.0
|
67
|
+
version: "1.2"
|
84
68
|
type: :development
|
85
69
|
version_requirements: *id005
|
86
70
|
- !ruby/object:Gem::Dependency
|
87
|
-
name: dm-
|
71
|
+
name: dm-sqlite-adapter
|
88
72
|
prerelease: false
|
89
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
90
75
|
requirements:
|
91
|
-
- - "
|
76
|
+
- - "="
|
92
77
|
- !ruby/object:Gem::Version
|
93
|
-
|
94
|
-
- 0
|
95
|
-
- 10
|
96
|
-
- 2
|
97
|
-
version: 0.10.2
|
78
|
+
version: "1.2"
|
98
79
|
type: :development
|
99
80
|
version_requirements: *id006
|
100
81
|
- !ruby/object:Gem::Dependency
|
101
|
-
name:
|
82
|
+
name: do_sqlite3
|
102
83
|
prerelease: false
|
103
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
104
86
|
requirements:
|
105
|
-
- - "
|
87
|
+
- - "="
|
106
88
|
- !ruby/object:Gem::Version
|
107
|
-
|
108
|
-
- 0
|
109
|
-
- 10
|
110
|
-
- 2
|
111
|
-
version: 0.10.2
|
89
|
+
version: 0.10.8
|
112
90
|
type: :development
|
113
91
|
version_requirements: *id007
|
114
92
|
- !ruby/object:Gem::Dependency
|
115
|
-
name:
|
93
|
+
name: thoughtbot-shoulda
|
116
94
|
prerelease: false
|
117
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
118
97
|
requirements:
|
119
|
-
- - "
|
98
|
+
- - "="
|
120
99
|
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
- 0
|
123
|
-
- 10
|
124
|
-
- 2
|
125
|
-
version: 0.10.2
|
100
|
+
version: 2.11.1
|
126
101
|
type: :development
|
127
102
|
version_requirements: *id008
|
128
103
|
- !ruby/object:Gem::Dependency
|
129
|
-
name:
|
104
|
+
name: sqlite3-ruby
|
130
105
|
prerelease: false
|
131
106
|
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
132
108
|
requirements:
|
133
|
-
- - "
|
109
|
+
- - "="
|
134
110
|
- !ruby/object:Gem::Version
|
135
|
-
|
136
|
-
- 0
|
137
|
-
- 10
|
138
|
-
- 1
|
139
|
-
- 1
|
140
|
-
version: 0.10.1.1
|
111
|
+
version: 1.3.3
|
141
112
|
type: :development
|
142
113
|
version_requirements: *id009
|
143
114
|
- !ruby/object:Gem::Dependency
|
144
|
-
name:
|
115
|
+
name: rr
|
145
116
|
prerelease: false
|
146
117
|
requirement: &id010 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
147
119
|
requirements:
|
148
|
-
- - "
|
120
|
+
- - "="
|
149
121
|
- !ruby/object:Gem::Version
|
150
|
-
|
151
|
-
- 0
|
152
|
-
version: "0"
|
122
|
+
version: 1.0.4
|
153
123
|
type: :development
|
154
124
|
version_requirements: *id010
|
155
|
-
- !ruby/object:Gem::Dependency
|
156
|
-
name: sqlite3-ruby
|
157
|
-
prerelease: false
|
158
|
-
requirement: &id011 !ruby/object:Gem::Requirement
|
159
|
-
requirements:
|
160
|
-
- - ">="
|
161
|
-
- !ruby/object:Gem::Version
|
162
|
-
segments:
|
163
|
-
- 0
|
164
|
-
version: "0"
|
165
|
-
type: :development
|
166
|
-
version_requirements: *id011
|
167
125
|
description: Define new objects or modifications of existing ones in external file (xml, csv, etc) and import them to your application. Importer will not only import all the objects but also will give you detailed summary of the import process.
|
168
|
-
email:
|
126
|
+
email:
|
127
|
+
- michal.szajbe@gmail.com
|
169
128
|
executables: []
|
170
129
|
|
171
130
|
extensions: []
|
172
131
|
|
173
|
-
extra_rdoc_files:
|
174
|
-
|
175
|
-
- README.rdoc
|
132
|
+
extra_rdoc_files: []
|
133
|
+
|
176
134
|
files:
|
177
135
|
- .document
|
178
136
|
- .gitignore
|
137
|
+
- Gemfile
|
138
|
+
- Gemfile.lock
|
179
139
|
- LICENSE
|
180
140
|
- README.rdoc
|
181
141
|
- Rakefile
|
@@ -191,6 +151,7 @@ files:
|
|
191
151
|
- lib/importer/parser/base.rb
|
192
152
|
- lib/importer/parser/csv.rb
|
193
153
|
- lib/importer/parser/xml.rb
|
154
|
+
- lib/importer/version.rb
|
194
155
|
- rails/init.rb
|
195
156
|
- test/database.yml
|
196
157
|
- test/factories.rb
|
@@ -209,38 +170,42 @@ files:
|
|
209
170
|
- test/importer/parser/csv_test.rb
|
210
171
|
- test/importer/parser/xml_test.rb
|
211
172
|
- test/importer/parser_test.rb
|
212
|
-
has_rdoc: true
|
213
173
|
homepage: http://github.com/szajbus/importer
|
214
174
|
licenses: []
|
215
175
|
|
216
176
|
post_install_message:
|
217
|
-
rdoc_options:
|
218
|
-
|
177
|
+
rdoc_options: []
|
178
|
+
|
219
179
|
require_paths:
|
220
180
|
- lib
|
221
181
|
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
222
183
|
requirements:
|
223
184
|
- - ">="
|
224
185
|
- !ruby/object:Gem::Version
|
225
|
-
segments:
|
226
|
-
- 0
|
227
186
|
version: "0"
|
228
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
none: false
|
229
189
|
requirements:
|
230
190
|
- - ">="
|
231
191
|
- !ruby/object:Gem::Version
|
232
|
-
segments:
|
233
|
-
- 0
|
234
192
|
version: "0"
|
235
193
|
requirements: []
|
236
194
|
|
237
195
|
rubyforge_project:
|
238
|
-
rubygems_version: 1.
|
196
|
+
rubygems_version: 1.8.24
|
239
197
|
signing_key:
|
240
198
|
specification_version: 3
|
241
199
|
summary: Import objects from external files
|
242
200
|
test_files:
|
201
|
+
- test/database.yml
|
243
202
|
- test/factories.rb
|
203
|
+
- test/fixtures/empty.csv
|
204
|
+
- test/fixtures/empty.xml
|
205
|
+
- test/fixtures/product.csv
|
206
|
+
- test/fixtures/product.xml
|
207
|
+
- test/fixtures/products.csv
|
208
|
+
- test/fixtures/products.xml
|
244
209
|
- test/helper.rb
|
245
210
|
- test/importer/adapters/active_record_adapter_test.rb
|
246
211
|
- test/importer/adapters/data_mapper_adapter_test.rb
|