importer 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
data/importer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{importer}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Micha\305\202 Szajbe"]
12
- s.date = %q{2010-03-20}
12
+ s.date = %q{2010-03-25}
13
13
  s.description = %q{Define new objects or modifications of existing ones in XML file and import them to your application.}
14
14
  s.email = %q{michal.szajbe@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -52,7 +52,6 @@ Gem::Specification.new do |s|
52
52
  "test/importer/import/simple_test.rb",
53
53
  "test/importer/imported_object/active_record_test.rb",
54
54
  "test/importer/imported_object/simple_test.rb",
55
- "test/importer/imported_object_test.rb",
56
55
  "test/importer/parser/csv_test.rb",
57
56
  "test/importer/parser/xml_test.rb",
58
57
  "test/importer/parser_test.rb",
@@ -70,7 +69,6 @@ Gem::Specification.new do |s|
70
69
  "test/importer/import/simple_test.rb",
71
70
  "test/importer/imported_object/active_record_test.rb",
72
71
  "test/importer/imported_object/simple_test.rb",
73
- "test/importer/imported_object_test.rb",
74
72
  "test/importer/parser/csv_test.rb",
75
73
  "test/importer/parser/xml_test.rb",
76
74
  "test/importer/parser_test.rb",
data/lib/importer.rb CHANGED
@@ -53,10 +53,8 @@ module Importer
53
53
  transaction do
54
54
  import.start!
55
55
 
56
- imported_object_klass = Importer::ImportedObject.get_klass(import)
57
-
58
56
  data.each do |attributes|
59
- imported_object = imported_object_klass.new(:import => import)
57
+ imported_object = import.build_imported_object
60
58
 
61
59
  if object = find_on_import(import, attributes)
62
60
  imported_object.state = "existing_object"
@@ -31,7 +31,11 @@ module Importer
31
31
  named_scope :started, :conditions => { :workflow_state => "started" }
32
32
  named_scope :finished, :conditions => { :workflow_state => "finished" }
33
33
 
34
- has_many :imported_objects, :class_name => "Importer::ImportedObject::ActiveRecord"
34
+ has_many :imported_objects, :class_name => "Importer::ImportedObject::ActiveRecord", :foreign_key => "import_id"
35
+
36
+ def build_imported_object
37
+ imported_objects.build(:import => self)
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -52,6 +52,10 @@ module Importer
52
52
  end
53
53
 
54
54
  alias_method :save!, :save
55
+
56
+ def build_imported_object
57
+ Importer::ImportedObject::Simple.new(:import => self)
58
+ end
55
59
  end
56
60
  end
57
61
  end
@@ -1,7 +1,5 @@
1
1
  module Importer
2
2
  module ImportedObject
3
- def self.get_klass(import)
4
- import.class.to_s.sub("Importer::Import", "Importer::ImportedObject").constantize
5
- end
3
+
6
4
  end
7
5
  end
@@ -24,4 +24,13 @@ class Importer::Import::ActiveRecordTest < Test::Unit::TestCase
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ context "an import" do
29
+ setup { @import = Factory(:active_record_import) }
30
+
31
+ should "correctly build imported object" do
32
+ imported_object = @import.build_imported_object
33
+ assert_equal @import, imported_object.import
34
+ end
35
+ end
27
36
  end
@@ -24,4 +24,13 @@ class Importer::Import::SimpleTest < Test::Unit::TestCase
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ context "an import" do
29
+ setup { @import = Factory(:simple_import) }
30
+
31
+ should "correctly build imported object" do
32
+ imported_object = @import.build_imported_object
33
+ assert_equal @import, imported_object.import
34
+ end
35
+ end
27
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Micha\xC5\x82 Szajbe"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-20 00:00:00 +01:00
12
+ date: 2010-03-25 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -137,7 +137,6 @@ files:
137
137
  - test/importer/import/simple_test.rb
138
138
  - test/importer/imported_object/active_record_test.rb
139
139
  - test/importer/imported_object/simple_test.rb
140
- - test/importer/imported_object_test.rb
141
140
  - test/importer/parser/csv_test.rb
142
141
  - test/importer/parser/xml_test.rb
143
142
  - test/importer/parser_test.rb
@@ -177,7 +176,6 @@ test_files:
177
176
  - test/importer/import/simple_test.rb
178
177
  - test/importer/imported_object/active_record_test.rb
179
178
  - test/importer/imported_object/simple_test.rb
180
- - test/importer/imported_object_test.rb
181
179
  - test/importer/parser/csv_test.rb
182
180
  - test/importer/parser/xml_test.rb
183
181
  - test/importer/parser_test.rb
@@ -1,13 +0,0 @@
1
- require 'helper'
2
-
3
- class Importer::ImportedObjectTest < Test::Unit::TestCase
4
- should "return ActiveRecord imported object for ActiveRecord import" do
5
- import = Factory(:active_record_import)
6
- assert_equal Importer::ImportedObject::ActiveRecord, Importer::ImportedObject.get_klass(import)
7
- end
8
-
9
- should "return Simple imported object for Simple import" do
10
- import = Factory(:simple_import)
11
- assert_equal Importer::ImportedObject::Simple, Importer::ImportedObject.get_klass(import)
12
- end
13
- end