factory_girl-seeds 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +24 -1
- data/Rakefile +8 -0
- data/factory_girl-seeds.gemspec +9 -0
- data/lib/factory_girl-seeds/seeds.rb +9 -9
- data/lib/factory_girl-seeds/version.rb +1 -1
- data/spec/factory_girl-seeds/seeds_spec.rb +35 -0
- data/spec/spec_helper.rb +30 -0
- metadata +84 -13
- data/seed.jpg +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b563bf21ba4d7df949d669ab8bad089a9d2a18be
|
4
|
+
data.tar.gz: d9ebcc2dd3ef507a72806a8b97f11fff03cab289
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fef7f21aae1e3fe8c37bdd5d76eba41a334ede23b6159610d57275e3b35558b60fa2d81177d273a70cc79ebfab46b68f58a08ea80bc5c3f9316133a5cac42ef1
|
7
|
+
data.tar.gz: 3d15b6d69dbdad070932cc38dca06db77d3348d65a541ad7a0fb58e2eb8f391f9b9381d2b9156b66473904b275ee7393e56e08549b190ecd6ff89c066ce0689b
|
data/README.md
CHANGED
@@ -8,6 +8,29 @@ This tiny gem helps fix that problem by reusing data preloaded before running te
|
|
8
8
|
|
9
9
|
![](seed.jpg)
|
10
10
|
|
11
|
+
## Benchmark
|
12
|
+
|
13
|
+
Without seeds:
|
14
|
+
|
15
|
+
```
|
16
|
+
Finished in 4 minutes 38.7 seconds
|
17
|
+
1402 examples, 0 failures, 0 pending
|
18
|
+
```
|
19
|
+
|
20
|
+
With seeds:
|
21
|
+
|
22
|
+
```
|
23
|
+
Finished in 2 minutes 40.6 seconds
|
24
|
+
1402 examples, 0 failures, 0 pending
|
25
|
+
```
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
>> (2.minutes + 40.6.seconds) / (4.minutes + 38.7.seconds)
|
29
|
+
=> 0.5762468604233943
|
30
|
+
```
|
31
|
+
|
32
|
+
So it is just about 58% of time before seeds optimization :)
|
33
|
+
|
11
34
|
## Installation
|
12
35
|
|
13
36
|
Add this line to your application's Gemfile:
|
@@ -23,7 +46,7 @@ end
|
|
23
46
|
### 1. Create records before test suite
|
24
47
|
|
25
48
|
```ruby
|
26
|
-
FactoryGirl::SeedGenerator.create(:user, name: "
|
49
|
+
FactoryGirl::SeedGenerator.create(:user, name: "Carlos Castaneda")
|
27
50
|
```
|
28
51
|
|
29
52
|
For example if you are using rspec then add this to ```config.before(:suite)```.
|
data/Rakefile
CHANGED
data/factory_girl-seeds.gemspec
CHANGED
@@ -13,7 +13,16 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.homepage = "https://github.com/evrone/factory_girl-seeds"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.files -= ["seed.jpg"]
|
17
|
+
|
16
18
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
20
|
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.add_dependency "factory_girl"
|
23
|
+
|
24
|
+
gem.add_development_dependency "rake"
|
25
|
+
gem.add_development_dependency "rspec"
|
26
|
+
gem.add_development_dependency "activerecord"
|
27
|
+
gem.add_development_dependency "sqlite3"
|
19
28
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
+
require 'factory_girl'
|
2
|
+
|
1
3
|
module FactoryGirl
|
2
4
|
class SeedGenerator
|
3
5
|
@ids = {}
|
4
6
|
@classes = {}
|
5
7
|
|
6
|
-
def self.create(factory_name, attributes
|
7
|
-
|
8
|
-
|
9
|
-
model = FactoryGirl.create(factory_name, attributes)
|
8
|
+
def self.create(factory_name, *attributes)
|
9
|
+
model = FactoryGirl.create(factory_name, *attributes)
|
10
10
|
@ids[factory_name] = model.id
|
11
11
|
@classes[factory_name] = model.class
|
12
12
|
|
@@ -18,7 +18,7 @@ module FactoryGirl
|
|
18
18
|
|
19
19
|
if seed_id
|
20
20
|
seed_class = @classes[factory_name]
|
21
|
-
seed_class.
|
21
|
+
seed_class.where(id: seed_id).first || create(factory_name)
|
22
22
|
else
|
23
23
|
create(factory_name)
|
24
24
|
end
|
@@ -30,10 +30,10 @@ module FactoryGirl
|
|
30
30
|
module Syntax
|
31
31
|
module SeedMethods
|
32
32
|
def seed(factory_name)
|
33
|
-
if Rails.env.test?
|
34
|
-
FactoryGirl::SeedGenerator[factory_name]
|
35
|
-
else
|
33
|
+
if defined?(Rails) && !Rails.env.test?
|
36
34
|
FactoryGirl.create(factory_name)
|
35
|
+
else
|
36
|
+
FactoryGirl::SeedGenerator[factory_name]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -42,4 +42,4 @@ end
|
|
42
42
|
|
43
43
|
FactoryGirl::Syntax::Methods.send(:include, FactoryGirl::Syntax::SeedMethods)
|
44
44
|
FactoryGirl::SyntaxRunner.send(:include, FactoryGirl::Syntax::SeedMethods)
|
45
|
-
FactoryGirl.send(:
|
45
|
+
FactoryGirl.send(:extend, FactoryGirl::Syntax::SeedMethods)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FactoryGirl::SeedGenerator do
|
4
|
+
let(:klass) { FactoryGirl::SeedGenerator }
|
5
|
+
it do
|
6
|
+
seeded = seed(:user)
|
7
|
+
expect(seeded).to eq(seed(:user))
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "create" do
|
11
|
+
it "seeds with custom attributes" do
|
12
|
+
seed = klass.create(:user, name: 'John')
|
13
|
+
expect(seed.name).to eql 'John'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "seeds with traits" do
|
17
|
+
seed = klass.create(:user, :david)
|
18
|
+
expect(seed.name).to eql 'David'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "seeds with attributes and traits" do
|
22
|
+
seed = klass.create(:user, :david, nickname: 'Goliath')
|
23
|
+
expect(seed.name).to eql 'David'
|
24
|
+
expect(seed.name).to eql 'Goliath'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe FactoryGirl do
|
30
|
+
describe ".seed" do
|
31
|
+
it do
|
32
|
+
expect(FactoryGirl.seed(:user)).to be
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'factory_girl'
|
2
|
+
require 'active_record'
|
3
|
+
require 'factory_girl-seeds'
|
4
|
+
|
5
|
+
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
6
|
+
ActiveRecord::Base.establish_connection('test')
|
7
|
+
|
8
|
+
ActiveRecord::Migration.verbose = false
|
9
|
+
ActiveRecord::Schema.define(version: 0) do
|
10
|
+
create_table "users", force: true do |t|
|
11
|
+
t.string "name"
|
12
|
+
t.string "nickname"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class User < ActiveRecord::Base;end
|
17
|
+
|
18
|
+
FactoryGirl.define do
|
19
|
+
factory :user do
|
20
|
+
name "AB"
|
21
|
+
|
22
|
+
trait :david do
|
23
|
+
name 'David'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
config.include FactoryGirl::Syntax::Methods
|
30
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl-seeds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alexander Balashov
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: factory_girl
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
14
83
|
description: Preseed reusable data for factory girl
|
15
84
|
email:
|
16
85
|
- technoforest@gmail.com
|
@@ -18,7 +87,7 @@ executables: []
|
|
18
87
|
extensions: []
|
19
88
|
extra_rdoc_files: []
|
20
89
|
files:
|
21
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
22
91
|
- Gemfile
|
23
92
|
- LICENSE.txt
|
24
93
|
- README.md
|
@@ -27,29 +96,31 @@ files:
|
|
27
96
|
- lib/factory_girl-seeds.rb
|
28
97
|
- lib/factory_girl-seeds/seeds.rb
|
29
98
|
- lib/factory_girl-seeds/version.rb
|
30
|
-
-
|
99
|
+
- spec/factory_girl-seeds/seeds_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
31
101
|
homepage: https://github.com/evrone/factory_girl-seeds
|
32
102
|
licenses: []
|
103
|
+
metadata: {}
|
33
104
|
post_install_message:
|
34
105
|
rdoc_options: []
|
35
106
|
require_paths:
|
36
107
|
- lib
|
37
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
109
|
requirements:
|
40
|
-
- -
|
110
|
+
- - ">="
|
41
111
|
- !ruby/object:Gem::Version
|
42
112
|
version: '0'
|
43
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
114
|
requirements:
|
46
|
-
- -
|
115
|
+
- - ">="
|
47
116
|
- !ruby/object:Gem::Version
|
48
117
|
version: '0'
|
49
118
|
requirements: []
|
50
119
|
rubyforge_project:
|
51
|
-
rubygems_version:
|
120
|
+
rubygems_version: 2.2.2
|
52
121
|
signing_key:
|
53
|
-
specification_version:
|
122
|
+
specification_version: 4
|
54
123
|
summary: Make your test suite run time upto 2x faster and even more!
|
55
|
-
test_files:
|
124
|
+
test_files:
|
125
|
+
- spec/factory_girl-seeds/seeds_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
data/seed.jpg
DELETED
Binary file
|