superseeder 0.9.3 → 0.9.4

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.
@@ -19,7 +19,7 @@ describe '#seed' do
19
19
  end
20
20
  end
21
21
 
22
- describe 'with no relation' do
22
+ describe 'with plain attributes' do
23
23
  it 'sets the values' do
24
24
  Parking.seed :filename => 'parkings_without_cars.csv'
25
25
  assert_equal %w(South North East West).sort, Parking.all.map(&:name).sort
@@ -53,4 +53,49 @@ describe '#seed' do
53
53
  end
54
54
  end
55
55
 
56
+ describe 'with :update option' do
57
+ it 'does not create any new record' do
58
+ Parking.seed :filename => 'parkings_without_cars.csv'
59
+ Parking.seed :filename => 'parkings_without_cars.csv', :update_by => :name
60
+ assert_equal 4, Parking.count
61
+ end
62
+
63
+ it 'updates the record attributes' do
64
+ Parking.seed :filename => 'parkings_without_cars.csv'
65
+ parking = Parking.all.entries.sample
66
+ size = parking.size
67
+ parking.size = 2000
68
+ parking.save
69
+ Parking.seed :filename => 'parkings_without_cars.csv', :update_by => :name
70
+ assert_equal size, Parking.find(parking.id).size
71
+ end
72
+
73
+ describe 'and relations' do
74
+ before :each do
75
+ Car.seed :filename => 'cars_without_parkings.csv'
76
+ end
77
+
78
+ it 'updates the relations' do
79
+ Parking.seed :filename => 'parkings_with_cars.csv'
80
+ parking = Parking.all.entries.reject{ |p| p.cars.empty? }.sample
81
+ cars = parking.cars.entries
82
+ parking.cars = []
83
+ parking.save
84
+ Parking.seed :filename => 'parkings_with_cars.csv', :update_by => :name
85
+ assert_equal cars.sort, Parking.find(parking.id).cars.sort
86
+ end
87
+
88
+ it 'keeps unknown relations' do
89
+ Parking.seed :filename => 'parkings_with_cars.csv'
90
+ parking = Parking.all.entries.reject{ |p| p.cars.empty? }.sample
91
+ cars = parking.cars.entries
92
+ unknown_car = Car.new :name => 'Mercedes', :parking => parking
93
+ unknown_car.save
94
+ Parking.seed :filename => 'parkings_with_cars.csv', :update_by => :name
95
+ assert_equal cars.push(unknown_car).sort, Parking.find(parking.id).cars.sort
96
+ end
97
+
98
+ end
99
+ end
100
+
56
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superseeder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Milla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-05 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails