seed-fu 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -0
- data/VERSION +1 -1
- data/lib/seed-fu.rb +5 -0
- data/spec/seed_fu_spec.rb +44 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -19,6 +19,16 @@ rescue LoadError
|
|
19
19
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
20
20
|
end
|
21
21
|
|
22
|
+
begin
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new do |t|
|
26
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
rescue LoadError
|
29
|
+
puts "You need RSpec to run the spec suite."
|
30
|
+
end
|
31
|
+
|
22
32
|
|
23
33
|
desc 'Default: run specs.'
|
24
34
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
data/lib/seed-fu.rb
CHANGED
@@ -73,6 +73,11 @@ class ActiveRecord::Base
|
|
73
73
|
def self.seed(*constraints, &block)
|
74
74
|
SeedFu::Seeder.plant(self, *constraints, &block)
|
75
75
|
end
|
76
|
+
|
77
|
+
def self.seed_once(*constraints, &block)
|
78
|
+
constraints << true
|
79
|
+
SeedFu::Seeder.plant(self, *constraints, &block)
|
80
|
+
end
|
76
81
|
|
77
82
|
def self.seed_many(*constraints)
|
78
83
|
seeds = constraints.pop
|
data/spec/seed_fu_spec.rb
CHANGED
@@ -55,6 +55,50 @@ describe SeedFu::Seeder do
|
|
55
55
|
SeededModel.find_by_login("harry").first_name.should == "Harry"
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should update, not create, if constraints are met" do
|
59
|
+
SeededModel.seed(:id) do |s|
|
60
|
+
s.id = 1
|
61
|
+
s.login = "bob"
|
62
|
+
s.first_name = "Bob"
|
63
|
+
s.last_name = "Bobson"
|
64
|
+
s.title = "Peon"
|
65
|
+
end
|
66
|
+
|
67
|
+
SeededModel.seed(:id) do |s|
|
68
|
+
s.id = 1
|
69
|
+
s.login = "bob"
|
70
|
+
s.first_name = "Robert"
|
71
|
+
s.last_name = "Bobson"
|
72
|
+
s.title = "Peon"
|
73
|
+
end
|
74
|
+
|
75
|
+
bob = SeededModel.find_by_id(1)
|
76
|
+
bob.first_name.should == "Robert"
|
77
|
+
bob.last_name.should == "Bobson"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should create but not update with seed_once" do
|
81
|
+
SeededModel.seed_once(:id) do |s|
|
82
|
+
s.id = 1
|
83
|
+
s.login = "bob"
|
84
|
+
s.first_name = "Bob"
|
85
|
+
s.last_name = "Bobson"
|
86
|
+
s.title = "Peon"
|
87
|
+
end
|
88
|
+
|
89
|
+
SeededModel.seed_once(:id) do |s|
|
90
|
+
s.id = 1
|
91
|
+
s.login = "bob"
|
92
|
+
s.first_name = "Robert"
|
93
|
+
s.last_name = "Bobson"
|
94
|
+
s.title = "Peon"
|
95
|
+
end
|
96
|
+
|
97
|
+
bob = SeededModel.find_by_id(1)
|
98
|
+
bob.first_name.should == "Bob"
|
99
|
+
bob.last_name.should == "Bobson"
|
100
|
+
end
|
101
|
+
|
58
102
|
#it "should raise an error if constraints are not unique" do
|
59
103
|
# SeededModel.create(:login => "bob", :first_name => "Bob", :title => "Peon")
|
60
104
|
# SeededModel.create(:login => "bob", :first_name => "Robert", :title => "Manager")
|
@@ -66,7 +110,6 @@ describe SeedFu::Seeder do
|
|
66
110
|
#end
|
67
111
|
|
68
112
|
it "should default to an id constraint"
|
69
|
-
it "should update, not create, if constraints are met"
|
70
113
|
it "should require that all constraints are defined"
|
71
114
|
it "should raise an error if validation fails"
|
72
115
|
it "should retain fields that aren't specifically altered in the seeding"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed-fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-20 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|