seedomatic 0.5.8 → 0.6.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.
- checksums.yaml +4 -4
- data/lib/seedomatic/seeder.rb +6 -3
- data/lib/seedomatic/version.rb +1 -1
- data/spec/lib/seeder_spec.rb +9 -14
- data/spec/support/my_model.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a16c4b79ede1def8b4ebb5296cbfba2992338dea
|
|
4
|
+
data.tar.gz: 95115a41a7c0e5cbad651a50bdefd533a156fcb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0e996b5e9925063b6de42264f06cce282d335b444fc625ca8a2abf63e72dd18bf918c26b75391dd53ac7447100eb2ae2a1cf5d46817e712986aca686ca9bf15
|
|
7
|
+
data.tar.gz: bb3a49ee1de51d99e4311318ec5745856c648cac064e33d483ade905764bf03f67ca0ba6225b9dde54b08bb48724b092d45efcdb10829c93ccc3df11233b4ac9
|
data/lib/seedomatic/seeder.rb
CHANGED
|
@@ -15,7 +15,7 @@ module SeedOMatic
|
|
|
15
15
|
updated_records = 0
|
|
16
16
|
|
|
17
17
|
items.each do |attrs|
|
|
18
|
-
model = model_class.unscoped.send(create_method,
|
|
18
|
+
model = model_class.unscoped.send(create_method, create_args(attrs))
|
|
19
19
|
|
|
20
20
|
if model.new_record?
|
|
21
21
|
new_records += 1
|
|
@@ -60,11 +60,14 @@ module SeedOMatic
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def create_method
|
|
63
|
-
match_on.empty? ? 'new' : "
|
|
63
|
+
match_on.empty? ? 'new' : "find_or_initialize_by"
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def create_args(item)
|
|
67
|
-
match_on.
|
|
67
|
+
match_on.inject({}) do |result,m|
|
|
68
|
+
result[m] = item[m]
|
|
69
|
+
result
|
|
70
|
+
end
|
|
68
71
|
end
|
|
69
72
|
|
|
70
73
|
def model_class
|
data/lib/seedomatic/version.rb
CHANGED
data/spec/lib/seeder_spec.rb
CHANGED
|
@@ -60,7 +60,7 @@ describe SeedOMatic::Seeder do
|
|
|
60
60
|
let(:match_on) { 'code' }
|
|
61
61
|
|
|
62
62
|
specify {
|
|
63
|
-
MyModel.should_receive(:
|
|
63
|
+
MyModel.should_receive(:find_or_initialize_by).with('code' => 'uniquecode').and_return(MyModel.new)
|
|
64
64
|
subject
|
|
65
65
|
}
|
|
66
66
|
end
|
|
@@ -68,7 +68,7 @@ describe SeedOMatic::Seeder do
|
|
|
68
68
|
let(:match_on) { ['code', 'code_category'] }
|
|
69
69
|
|
|
70
70
|
specify {
|
|
71
|
-
MyModel.should_receive(:
|
|
71
|
+
MyModel.should_receive(:find_or_initialize_by).with('code' => 'uniquecode', 'code_category' => 'more_unique').and_return(MyModel.new)
|
|
72
72
|
subject
|
|
73
73
|
}
|
|
74
74
|
end
|
|
@@ -85,12 +85,12 @@ describe SeedOMatic::Seeder do
|
|
|
85
85
|
|
|
86
86
|
context "one matching field" do
|
|
87
87
|
let(:match_on) { 'code' }
|
|
88
|
-
it { should == '
|
|
88
|
+
it { should == 'find_or_initialize_by' }
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
context "multiple matching fields" do
|
|
92
92
|
let(:match_on) { ['code', 'code_category'] }
|
|
93
|
-
it { should == '
|
|
93
|
+
it { should == 'find_or_initialize_by' }
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
|
|
@@ -102,8 +102,8 @@ describe SeedOMatic::Seeder do
|
|
|
102
102
|
}
|
|
103
103
|
let(:match_on) { 'code' }
|
|
104
104
|
before {
|
|
105
|
-
MyModel.stub(:
|
|
106
|
-
MyModel.stub(:
|
|
105
|
+
MyModel.stub(:find_or_initialize_by).with('code' => 'existing').and_return(existing_mock)
|
|
106
|
+
MyModel.stub(:find_or_initialize_by).with('code' => 'new').and_return(new_mock)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
context "once" do
|
|
@@ -163,22 +163,17 @@ describe SeedOMatic::Seeder do
|
|
|
163
163
|
|
|
164
164
|
context "no matching fields" do
|
|
165
165
|
let(:match_on) { nil }
|
|
166
|
-
it { should ==
|
|
166
|
+
it { should == {} }
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
context "one matching field" do
|
|
170
170
|
let(:match_on) { 'code' }
|
|
171
|
-
it { should ==
|
|
171
|
+
it { should == {'code' => 1} }
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
context "multiple matching fields" do
|
|
175
175
|
let(:match_on) { ['code', 'code_category'] }
|
|
176
|
-
it { should ==
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
context "order sensitivity" do
|
|
180
|
-
let(:match_on) { ['code_category', 'code'] }
|
|
181
|
-
it { should == [2,1] }
|
|
176
|
+
it { should == {'code' => 1, 'code_category' => 2} }
|
|
182
177
|
end
|
|
183
178
|
end
|
|
184
179
|
|
data/spec/support/my_model.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: seedomatic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Brunner
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|