populator 0.2.2 → 0.2.3
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.
- data/CHANGELOG +10 -4
- data/Rakefile +1 -1
- data/TODO +0 -3
- data/lib/populator/record.rb +12 -4
- data/populator.gemspec +3 -3
- data/spec/database.yml +7 -2
- data/spec/populator/record_spec.rb +17 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
-
|
1
|
+
0.2.3 (September 2nd, 2008)
|
2
|
+
|
3
|
+
* support single table inhertance by setting inheritance_column to class name
|
4
|
+
|
5
|
+
* support custom primary_key in model if they don't use "id"
|
6
|
+
|
7
|
+
0.2.2 (September 1st, 2008)
|
2
8
|
|
3
9
|
* performance improvements
|
4
10
|
|
5
11
|
* improving inline documentation
|
6
12
|
|
7
|
-
|
13
|
+
0.2.1 (August 30th, 2008)
|
8
14
|
|
9
15
|
* wrap sqlite inserts in transaction to improve performance
|
10
16
|
|
11
17
|
* default created_at/on and updated_at/on columns to current time
|
12
18
|
|
13
|
-
|
19
|
+
0.2.0 (August 30th, 2008)
|
14
20
|
|
15
21
|
* adding :per_query option to limit how many inserts are made per query
|
16
22
|
|
@@ -20,6 +26,6 @@
|
|
20
26
|
|
21
27
|
* adding Populator.words to fetch some random words
|
22
28
|
|
23
|
-
|
29
|
+
0.1.0 (August 27th, 2008)
|
24
30
|
|
25
31
|
* initial release
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('populator', '0.2.
|
5
|
+
Echoe.new('populator', '0.2.3') do |p|
|
6
6
|
p.summary = "Mass populate an Active Record database."
|
7
7
|
p.description = "Mass populate an Active Record database."
|
8
8
|
p.url = "http://github.com/ryanb/populator"
|
data/TODO
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
Features
|
2
|
-
- get single table inheritance working.
|
3
2
|
|
4
3
|
Possible
|
5
|
-
- iterate through array instead of selecting at random to ensure all values are chosen
|
6
|
-
- if hash is passed, apply given value that number of times: { 'foo' => 3, 'bar' => 2 }
|
7
4
|
- randomly fill every column if no block is passed to populate
|
8
5
|
- add random_foo method to record for randomly generating content
|
9
6
|
|
data/lib/populator/record.rb
CHANGED
@@ -10,15 +10,18 @@ module Populator
|
|
10
10
|
# * <tt>updated_at</tt> - defaults to current time
|
11
11
|
# * <tt>created_on</tt> - defaults to current date
|
12
12
|
# * <tt>updated_on</tt> - defaults to current date
|
13
|
+
# * <tt>type</tt> - defaults to class name (for STI)
|
13
14
|
def initialize(model_class, id)
|
14
|
-
@attributes = {
|
15
|
+
@attributes = { model_class.primary_key.to_sym => id }
|
15
16
|
@columns = model_class.column_names
|
16
17
|
@columns.each do |column|
|
17
|
-
|
18
|
+
case column
|
19
|
+
when 'created_at', 'updated_at'
|
18
20
|
@attributes[column.to_sym] = Time.now
|
19
|
-
|
20
|
-
if column == 'created_on' || column == 'updated_on'
|
21
|
+
when 'created_on', 'updated_on'
|
21
22
|
@attributes[column.to_sym] = Date.today
|
23
|
+
when model_class.inheritance_column
|
24
|
+
@attributes[column.to_sym] = model_class.to_s
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -28,6 +31,11 @@ module Populator
|
|
28
31
|
@attributes[:id]
|
29
32
|
end
|
30
33
|
|
34
|
+
# override type since method_missing won't catch this column name
|
35
|
+
def type
|
36
|
+
@attributes[:type]
|
37
|
+
end
|
38
|
+
|
31
39
|
# Return values for all columns inside an array.
|
32
40
|
def attribute_values
|
33
41
|
@columns.map do |column|
|
data/populator.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Populator-0.2.
|
2
|
+
# Gem::Specification for Populator-0.2.3
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
--- !ruby/object:Gem::Specification
|
6
6
|
name: populator
|
7
7
|
version: !ruby/object:Gem::Version
|
8
|
-
version: 0.2.
|
8
|
+
version: 0.2.3
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Ryan Bates
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
|
15
|
-
date: 2008-09-
|
15
|
+
date: 2008-09-02 00:00:00 -07:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
data/spec/database.yml
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# you can add and remove entries to support different databases in tests.
|
2
|
-
|
3
1
|
sqlite3:
|
4
2
|
adapter: sqlite3
|
5
3
|
database: spec/test.sqlite3
|
@@ -11,3 +9,10 @@ mysql:
|
|
11
9
|
username: populator
|
12
10
|
password:
|
13
11
|
host: localhost
|
12
|
+
|
13
|
+
postgresql:
|
14
|
+
adapter: postgresql
|
15
|
+
database: populator_test
|
16
|
+
username: populator
|
17
|
+
password: populator
|
18
|
+
host: localhost
|
@@ -41,4 +41,21 @@ describe Populator::Record do
|
|
41
41
|
record.created_on.should == Date.today
|
42
42
|
record.updated_on.should == Date.today
|
43
43
|
end
|
44
|
+
|
45
|
+
it "should use custom primary_key for auto-increment if specified" do
|
46
|
+
Product.stubs(:primary_key).returns('foo')
|
47
|
+
Product.stubs(:column_names).returns(['foo', 'name'])
|
48
|
+
Populator::Record.new(Product, 123).foo.should == 123
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should default type to class name" do
|
52
|
+
Product.stubs(:column_names).returns(['id', 'type'])
|
53
|
+
Populator::Record.new(Product, 1).type.should == 'Product'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should default specified inheritance_column to class name" do
|
57
|
+
Product.stubs(:inheritance_column).returns('foo')
|
58
|
+
Product.stubs(:column_names).returns(['id', 'foo'])
|
59
|
+
Populator::Record.new(Product, 1).foo.should == 'Product'
|
60
|
+
end
|
44
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: populator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|