factory_bot-preload 0.1.1 → 0.2.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
  SHA256:
3
- metadata.gz: c28666bc10b8c566588537fd66c1dbb6da80fceec2d7daed97ebdfce7812feb2
4
- data.tar.gz: 06fd411376ef9b383be790d9295c235f01b5c701a16e57bcf2122154572574d0
3
+ metadata.gz: 39d2d0e1d5f714e83e8fd226feb92a7adcb3872238fbc1aa842e112ae51a0eb8
4
+ data.tar.gz: 1bbe73c86fc82e3d3b5edf5e8e32222acc913da99abd651213ac7bcab38550b6
5
5
  SHA512:
6
- metadata.gz: d43388b3b1747bd21b08e175b799fb74347153d1a7492e9ebfc6a8fe44cf1512b5879c5b935924a43bb56ffff5eb5ee0bc808429ad9e23871317da1beb41005f
7
- data.tar.gz: 59333bea58922000db4ae9e65b97bed6231d3c23ebf4b2095c1c510b9dc5c640a96a9673b849cdcc46aa9e2d59905ea03464366b14593fbdd36e31ba3a6d90af
6
+ metadata.gz: 27a676e5d40869959c20c7565019e4aaafcb5985c84fa20773b2e0913486cb5782ef14355eb004c02220fd2e67d6aff52fc7aef5daeff6e5f78b486e9526e415
7
+ data.tar.gz: 48e36c0a1af45a23c53f8f16ad8d7ae548f7dcb93b27724eab6dea94ab873e89358f81b8c0b9656af44de9a115cd13f12c4c31646ad6e8dfa421ab56372785a3
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+
3
+ language: ruby
4
+ sudo: false
5
+ cache: bundler
6
+ before_install:
7
+ - gem install bundler
8
+ before_script:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - "./cc-test-reporter before-build"
12
+ rvm:
13
+ - 2.6.5
14
+ - 2.5.7
15
+ gemfile:
16
+ - gemfiles/6_0.gemfile
17
+ - gemfiles/5_2.gemfile
18
+ notifications:
19
+ email: false
20
+ after_script:
21
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
22
+ env:
23
+ global:
24
+ - secure: Euebw1utbb/4mu9AwgmnNk1cF4flaUVxterXl2yG9STc3oR9e8IczV+r3107CuIu57O6xbi5WarzSgyASSmC/0G9vhT3OaMx0lAY55zy93LaYbkcbcaAYCfbw6h1RHZ1pA3K4SVw/+n+p2jg9xFTTRLUmOHb2vXHH79WAo+Ri9s=
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
  gemspec
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # factory_bot-preload
2
2
 
3
+ [![Travis-CI](https://travis-ci.org/fnando/factory_bot-preload.svg)](https://travis-ci.org/fnando/factory_bot-preload)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/factory_bot-preload/badges/gpa.svg)](https://codeclimate.com/github/fnando/factory_bot-preload)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/factory_bot-preload/badges/coverage.svg)](https://codeclimate.com/github/fnando/factory_bot-preload/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/factory_bot-preload.svg)](https://rubygems.org/gems/factory_bot-preload)
7
+ [![Gem](https://img.shields.io/gem/dt/factory_bot-preload.svg)](https://rubygems.org/gems/factory_bot-preload)
8
+
3
9
  We all love Rails fixtures because they're fast, but we hate to deal with YAML/CSV/SQL files. Here enters [factory_bot](https://rubygems.org/gems/factory_bot) (FB).
4
10
 
5
11
  Now, you can easily create records by using predefined factories. The problem is that hitting the database everytime to create records is pretty slow. And believe me, you'll feel the pain when you have lots of tests/specs.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  case ENV["TEST_FRAMEWORK"]
@@ -5,7 +7,7 @@ when "rspec"
5
7
  require "rspec/core/rake_task"
6
8
  RSpec::Core::RakeTask.new
7
9
 
8
- task :default => :spec
10
+ task default: :spec
9
11
  when "minitest"
10
12
  require "rake/testtask"
11
13
 
@@ -17,7 +19,7 @@ when "minitest"
17
19
  t.warning = false
18
20
  end
19
21
 
20
- task :default => :test
22
+ task default: :test
21
23
  else
22
24
  task :default do
23
25
  system "TEST_FRAMEWORK=rspec bundle exec rake spec"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "./lib/factory_bot/preload/version"
2
4
 
3
5
  Gem::Specification.new do |s|
@@ -7,7 +9,7 @@ Gem::Specification.new do |s|
7
9
  s.authors = ["Nando Vieira"]
8
10
  s.email = ["fnando.vieira@gmail.com"]
9
11
  s.homepage = "http://rubygems.org/gems/factory_bot-preload"
10
- s.summary = "Preload factories (Factory Bot) just like fixtures. It will be easy and, probably, faster!"
12
+ s.summary = "Preload factories (Factory Bot) just like fixtures. It will be easier and, probably, faster!"
11
13
  s.description = s.summary
12
14
 
13
15
  s.files = `git ls-files`.split("\n")
@@ -24,5 +26,8 @@ Gem::Specification.new do |s|
24
26
  s.add_development_dependency "rails"
25
27
  s.add_development_dependency "rake"
26
28
  s.add_development_dependency "rspec-rails"
27
- s.add_development_dependency "sqlite3", "~> 1.3.6"
29
+ s.add_development_dependency "rubocop"
30
+ s.add_development_dependency "rubocop-fnando"
31
+ s.add_development_dependency "simplecov"
32
+ s.add_development_dependency "sqlite3", "~> 1.4"
28
33
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+ gem "rails", "~> 5.2.0"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+ gem "rails", "~> 6.0.0"
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "factory_bot/preload"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "factory_bot"
2
4
  require "active_record"
3
5
 
@@ -54,7 +56,7 @@ module FactoryBot
54
56
  raise "Couldn't find #{clean_with} clean type"
55
57
  end
56
58
 
57
- names = active_record.descendants.select(&:table_exists?).map(&:table_name).uniq if names.empty?
59
+ names = active_record_names if names.empty?
58
60
 
59
61
  connection.disable_referential_integrity do
60
62
  names.each do |table|
@@ -63,6 +65,11 @@ module FactoryBot
63
65
  end
64
66
  end
65
67
 
68
+ def self.active_record_names
69
+ names = active_record.descendants.collect(&:table_name).uniq.compact
70
+ names.reject {|name| name == "schema_migrations" }
71
+ end
72
+
66
73
  def self.reload_factories
67
74
  factories.each do |class_name, group|
68
75
  group.each do |name, _factory|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FactoryBot
2
4
  def self.preload(&block)
3
5
  Preload.preloaders << block
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FactoryBot
2
4
  module Preload
3
5
  module Helpers
@@ -33,9 +35,7 @@ module FactoryBot
33
35
  end
34
36
  end
35
37
 
36
- private
37
-
38
- def factory_get(name, model)
38
+ private def factory_get(name, model)
39
39
  factory = Preload.factories[model.name][name]
40
40
 
41
41
  if factory.blank? && Preload.factories[model.name].key?(name)
@@ -43,12 +43,14 @@ module FactoryBot
43
43
  Preload.factories[model.name][name] = factory
44
44
  end
45
45
 
46
- raise "Couldn't find #{name.inspect} factory for #{model.name.inspect} model" unless factory
46
+ unless factory
47
+ raise "Couldn't find #{name.inspect} factory for #{model.name.inspect} model"
48
+ end
47
49
 
48
50
  factory
49
51
  end
50
52
 
51
- def factory_set(name, &block)
53
+ private def factory_set(name, &block)
52
54
  record = instance_eval(&block)
53
55
  Preload.factories[record.class.name] ||= {}
54
56
  Preload.factories[record.class.name][name.to_sym] = record
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "minitest"
2
4
  require "factory_bot/syntax/methods"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rspec/core"
2
4
  require "factory_bot/syntax/methods"
3
5
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FactoryBot
2
4
  module Preload
3
5
  module Version
4
6
  MAJOR = 0
5
- MINOR = 1
6
- PATCH = 1
7
+ MINOR = 2
8
+ PATCH = 0
7
9
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
10
  end
9
11
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
5
+
1
6
  ENV["RAILS_ENV"] = "test"
2
7
  ENV["BUNDLE_GEMFILE"] = File.dirname(__FILE__) + "/../Gemfile"
3
8
  ENV["DATABASE_URL"] = "sqlite3::memory:"
4
9
 
5
10
  require "bundler/setup"
6
- require "rails/all"
11
+
12
+ require "rails"
13
+ require "active_model/railtie"
14
+ require "active_record/railtie"
15
+ require "action_controller/railtie"
16
+ require "action_view/railtie"
17
+ require "rails/test_unit/railtie"
7
18
 
8
19
  module RSpec
9
20
  class Application < ::Rails::Application
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Category < ActiveRecord::Base
2
4
  has_and_belongs_to_many :users
3
5
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Preload < ActiveRecord::Base
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Skill < ActiveRecord::Base
2
4
  belongs_to :user
3
- end
5
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ActiveRecord::Base
2
4
  has_many :skills
3
5
  has_and_belongs_to_many :categories
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::Schema.define(version: 0) do
2
4
  begin
3
5
  drop_table :users
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  sequence(:email) {|n| "john#{n}@doe.com" }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class PreloadTest < ActiveSupport::TestCase
@@ -49,7 +51,10 @@ class PreloadTest < ActiveSupport::TestCase
49
51
 
50
52
  test "raises error for missing clean type" do
51
53
  FactoryBot::Preload.clean_with = :invalid
52
- assert_raises(%[Couldn't find invalid clean type]) { FactoryBot::Preload.clean }
54
+
55
+ assert_raises(%[Couldn't find invalid clean type]) do
56
+ FactoryBot::Preload.clean
57
+ end
53
58
  end
54
59
 
55
60
  test "association uses preloaded record" do
@@ -75,7 +80,8 @@ class PreloadTest < ActiveSupport::TestCase
75
80
  end
76
81
 
77
82
  test "includes helpers into factory_bot" do
78
- assert_includes FactoryBot::SyntaxRunner.included_modules, FactoryBot::Preload::Helpers
83
+ assert_includes FactoryBot::SyntaxRunner.included_modules,
84
+ FactoryBot::Preload::Helpers
79
85
  end
80
86
 
81
87
  test "freezes object" do
data/test/test_helper.rb CHANGED
@@ -1,12 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
5
+
1
6
  ENV["RAILS_ENV"] = "test"
2
7
  ENV["BUNDLE_GEMFILE"] = File.dirname(__FILE__) + "/../Gemfile"
3
8
  ENV["DATABASE_URL"] = "sqlite3::memory:"
4
9
 
5
10
  require "bundler/setup"
6
- require "rails/all"
11
+
12
+ require "rails"
13
+ require "active_model/railtie"
14
+ require "active_record/railtie"
15
+ require "action_controller/railtie"
16
+ require "action_view/railtie"
17
+ require "rails/test_unit/railtie"
18
+
7
19
  require "minitest/utils"
8
20
 
9
21
  class SampleApplication < ::Rails::Application
22
+ config.api = true
10
23
  config.root = __dir__ + "/../spec/support/app"
11
24
  config.active_support.deprecation = :log
12
25
  config.eager_load = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_bot-preload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -122,22 +122,64 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-fnando
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
125
167
  - !ruby/object:Gem::Dependency
126
168
  name: sqlite3
127
169
  requirement: !ruby/object:Gem::Requirement
128
170
  requirements:
129
171
  - - "~>"
130
172
  - !ruby/object:Gem::Version
131
- version: 1.3.6
173
+ version: '1.4'
132
174
  type: :development
133
175
  prerelease: false
134
176
  version_requirements: !ruby/object:Gem::Requirement
135
177
  requirements:
136
178
  - - "~>"
137
179
  - !ruby/object:Gem::Version
138
- version: 1.3.6
139
- description: Preload factories (Factory Bot) just like fixtures. It will be easy and,
140
- probably, faster!
180
+ version: '1.4'
181
+ description: Preload factories (Factory Bot) just like fixtures. It will be easier
182
+ and, probably, faster!
141
183
  email:
142
184
  - fnando.vieira@gmail.com
143
185
  executables: []
@@ -146,10 +188,14 @@ extra_rdoc_files: []
146
188
  files:
147
189
  - ".gitignore"
148
190
  - ".rspec"
191
+ - ".rubocop.yml"
192
+ - ".travis.yml"
149
193
  - Gemfile
150
194
  - README.md
151
195
  - Rakefile
152
196
  - factory_bot-preload.gemspec
197
+ - gemfiles/5_2.gemfile
198
+ - gemfiles/6_0.gemfile
153
199
  - lib/factory_bot-preload.rb
154
200
  - lib/factory_bot/preload.rb
155
201
  - lib/factory_bot/preload/extension.rb
@@ -189,7 +235,7 @@ requirements: []
189
235
  rubygems_version: 3.0.3
190
236
  signing_key:
191
237
  specification_version: 4
192
- summary: Preload factories (Factory Bot) just like fixtures. It will be easy and,
238
+ summary: Preload factories (Factory Bot) just like fixtures. It will be easier and,
193
239
  probably, faster!
194
240
  test_files:
195
241
  - spec/factory_bot/preload_spec.rb