factory_girl-seeds 1.0.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in factory_girl-seeds.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexander Balashov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ [![Code Climate](https://codeclimate.com/github/evrone/factory_girl-seeds.png)](https://codeclimate.com/github/evrone/factory_girl-seeds)
2
+
3
+ # FactoryGirl Seeds
4
+
5
+ Make your test suite run time upto 2x faster and even more! factory_girl is a very usefull gem
6
+ for creating records in your DB easily but also is very sloooow. This small repo helps fix that problem.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ group :test do
13
+ gem 'factory_girl-seeds', github: 'evrone/factory_girl-seeds'
14
+ end
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ Create records before test suite:
23
+
24
+ ```ruby
25
+ FactoryGirl::SeedGenerator.create(:user, name: "John Appleseed")
26
+ ```
27
+
28
+ And then use in other factory definitions
29
+
30
+ ```ruby
31
+ FactoryGirl.define do
32
+ factory :post do
33
+ title "Demo"
34
+ user { seed(:user) }
35
+ end
36
+ end
37
+ ```
38
+
39
+ or in specs
40
+
41
+ ```ruby
42
+ @user = seed(:user)
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'factory_girl-seeds/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "factory_girl-seeds"
8
+ gem.version = FactoryGirl::Seeds::VERSION
9
+ gem.authors = ["Alexander Balashov"]
10
+ gem.email = ["technoforest@gmail.com"]
11
+ gem.description = %q{Preseed reusable data for factory girl}
12
+ gem.summary = %q{Make your test suite run time upto 2x faster and even more!}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,45 @@
1
+ module FactoryGirl
2
+ class SeedGenerator
3
+ @ids = {}
4
+ @classes = {}
5
+
6
+ def self.create(factory_name, attributes = nil)
7
+ raise "attributes must be a hash" if attributes && !attributes.is_a?(Hash)
8
+
9
+ model = FactoryGirl.create(factory_name, attributes)
10
+ @ids[factory_name] = model.id
11
+ @classes[factory_name] = model.class
12
+
13
+ model
14
+ end
15
+
16
+ def self.[](factory_name)
17
+ seed_id = @ids[factory_name]
18
+
19
+ if seed_id
20
+ seed_class = @classes[factory_name]
21
+ seed_class.find_by_id(seed_id) || create(factory_name)
22
+ else
23
+ create(factory_name)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ module FactoryGirl
30
+ module Syntax
31
+ module SeedMethods
32
+ def seed(factory_name)
33
+ if Rails.env.test?
34
+ FactoryGirl::SeedGenerator[factory_name]
35
+ else
36
+ FactoryGirl.create(factory_name)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ FactoryGirl::Syntax::Methods.send(:include, FactoryGirl::Syntax::SeedMethods)
44
+ FactoryGirl::SyntaxRunner.send(:include, FactoryGirl::Syntax::SeedMethods)
45
+ FactoryGirl.send(:include, FactoryGirl::Syntax::SeedMethods)
@@ -0,0 +1,5 @@
1
+ module FactoryGirl
2
+ module Seeds
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "factory_girl-seeds/version"
2
+ require "factory_girl-seeds/seeds"
3
+
4
+ module FactoryGirl
5
+ module Seeds
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factory_girl-seeds
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Balashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Preseed reusable data for factory girl
15
+ email:
16
+ - technoforest@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - factory_girl-seeds.gemspec
27
+ - lib/factory_girl-seeds.rb
28
+ - lib/factory_girl-seeds/seeds.rb
29
+ - lib/factory_girl-seeds/version.rb
30
+ homepage: ''
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.10
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Make your test suite run time upto 2x faster and even more!
54
+ test_files: []
55
+ has_rdoc: