importer 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,37 +0,0 @@
1
- require 'helper'
2
-
3
- class Importer::ImportedObject::ActiveRecordTest < Test::Unit::TestCase
4
- context "given an import" do
5
- setup { @import = Factory(:active_record_import) }
6
-
7
- context "creating a new imported object" do
8
- setup { Factory(:active_record_imported_object, :import => @import, :state => "new_object") }
9
-
10
- should_change("import's new_objects_count", :by => 1) { @import.reload.new_objects_count }
11
- end
12
-
13
- context "with an imported object" do
14
- setup { @imported_object = Factory(:active_record_imported_object, :import => @import, :state => "new_object") }
15
-
16
- context "destroying the imported object" do
17
- setup { @imported_object.destroy }
18
-
19
- should_change("import's new_objects_count", :by => -1) { @import.reload.new_objects_count }
20
- end
21
- end
22
- end
23
-
24
- context "creating new imported object" do
25
- setup { @imported_object = Factory(:active_record_imported_object, :data => { "a" => "b" }, :validation_errors => { "c" => "d" }) }
26
-
27
- should "serialize it's data" do
28
- data = { "a" => "b" }
29
- assert_equal data, @imported_object.data
30
- end
31
-
32
- should "serialize it's validation errors" do
33
- validation_errors = { "c" => "d" }
34
- assert_equal validation_errors, @imported_object.validation_errors
35
- end
36
- end
37
- end
@@ -1,35 +0,0 @@
1
- require 'helper'
2
-
3
- class Importer::ImportedObject::SimpleTest < Test::Unit::TestCase
4
- context "given an import" do
5
- setup { @import = Factory(:simple_import) }
6
-
7
- context "creating a new imported object" do
8
- setup do
9
- imported_object = Importer::ImportedObject::Simple.new(:import => @import)
10
- imported_object.state = "new_object"
11
- imported_object.save
12
- end
13
-
14
- should_change("import's new_objects_count", :by => 1) { @import.new_objects_count }
15
- end
16
-
17
- context "creating new imported object" do
18
- setup do
19
- @imported_object = Importer::ImportedObject::Simple.new(:import => @import)
20
- @imported_object.data = { "a" => "b" }
21
- @imported_object.validation_errors = { "c" => "d" }
22
- end
23
-
24
- should "correctly set/get data" do
25
- data = { "a" => "b" }
26
- assert_equal data, @imported_object.data
27
- end
28
-
29
- should "correctly set/get validation errors" do
30
- validation_errors = { "c" => "d" }
31
- assert_equal validation_errors, @imported_object.validation_errors
32
- end
33
- end
34
- end
35
- end
@@ -1,50 +0,0 @@
1
- require 'helper'
2
-
3
- class ImporterTest < Test::Unit::TestCase
4
- context "" do
5
- setup do
6
- @product = Factory(:product, :customid => "1", :name => "A pink ball", :description => "Round glass ball.", :price => 86)
7
- @import = Importer::Import::ActiveRecord.create
8
- end
9
-
10
- context "importing from an XML file" do
11
- setup do
12
- Product.import(fixture_file("products.xml"), :import => @import)
13
- end
14
-
15
- should_change("product's name", :from => "A pink ball", :to => "A black ball") { @product.reload.name }
16
-
17
- should_change("products count", :by => 1) { Product.count }
18
- should "correctly create new product" do
19
- product = Product.last
20
-
21
- assert_equal "A red hat", product.name
22
- assert_equal "Party hat.", product.description
23
- assert_equal 114, product.price
24
- assert_equal "2", product.customid
25
- end
26
-
27
- should_change("imported objects counts", :by => 3) { Importer::ImportedObject::ActiveRecord.count }
28
-
29
- should_change("import's workflow state", :to => "finished") { @import.reload.workflow_state }
30
- end
31
-
32
- context "when there is exception raised while importing from an XML file" do
33
- setup do
34
- begin
35
- InvalidProduct.import(fixture_file("products.xml"), :import => @import)
36
- rescue ::Exception => e
37
- @exception = e
38
- end
39
- end
40
-
41
- should_not_change("product's name") { @product.reload.name }
42
- should_not_change("products count") { InvalidProduct.count }
43
- should_not_change("imported objects count") { Importer::ImportedObject::ActiveRecord.count }
44
- should_not_change("import's workflow state") { @import.reload.workflow_state }
45
- should "propagate exception" do
46
- assert_equal "An error occured.", @exception.message
47
- end
48
- end
49
- end
50
- end