seedomatic 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d14bc3c7282abf61784cf857ce53b3890a0c99b5
4
- data.tar.gz: ac308741f84c8700f338cfbd38f832f1552bfece
3
+ metadata.gz: a16c4b79ede1def8b4ebb5296cbfba2992338dea
4
+ data.tar.gz: 95115a41a7c0e5cbad651a50bdefd533a156fcb0
5
5
  SHA512:
6
- metadata.gz: 994dc21a1ea0fee69afb95d2eca165ea0939ee84a8472c869a73e1006a7b2981cd7f984481d179563983ba299fdfa589f4bc3b612e48bef4f7081a5638d0b7f1
7
- data.tar.gz: 8c52da3a650a20f84bb1416cc207c367e15dd7dfd55202f5c924e53232ec5cf4a4a29b9a2e3c403e7617bbb16b4174a125c0456de9f5d1076ab0fc059577f65c
6
+ metadata.gz: b0e996b5e9925063b6de42264f06cce282d335b444fc625ca8a2abf63e72dd18bf918c26b75391dd53ac7447100eb2ae2a1cf5d46817e712986aca686ca9bf15
7
+ data.tar.gz: bb3a49ee1de51d99e4311318ec5745856c648cac064e33d483ade905764bf03f67ca0ba6225b9dde54b08bb48724b092d45efcdb10829c93ccc3df11233b4ac9
@@ -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, *create_args(attrs))
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' : "find_or_initialize_by_#{match_on.join('_and_')}"
63
+ match_on.empty? ? 'new' : "find_or_initialize_by"
64
64
  end
65
65
 
66
66
  def create_args(item)
67
- match_on.map{|m| item[m] }
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
@@ -1,3 +1,3 @@
1
1
  module Seedomatic
2
- VERSION = "0.5.8"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -60,7 +60,7 @@ describe SeedOMatic::Seeder do
60
60
  let(:match_on) { 'code' }
61
61
 
62
62
  specify {
63
- MyModel.should_receive(:find_or_initialize_by_code).with('uniquecode').and_return(MyModel.new)
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(:find_or_initialize_by_code_and_code_category).with('uniquecode', 'more_unique').and_return(MyModel.new)
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 == 'find_or_initialize_by_code' }
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 == 'find_or_initialize_by_code_and_code_category' }
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(:find_or_initialize_by_code).with('existing').and_return(existing_mock)
106
- MyModel.stub(:find_or_initialize_by_code).with('new').and_return(new_mock)
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 == [1] }
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 == [1,2] }
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
 
@@ -40,6 +40,11 @@ class MyModel
40
40
  self
41
41
  end
42
42
 
43
+ def save
44
+ save!
45
+ true
46
+ end
47
+
43
48
  def new_record?
44
49
  @new_record
45
50
  end
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.5.8
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: 2013-12-24 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec