factory_bot_caching 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee2c7389016a2ff8603325c873649be7baa588db
4
+ data.tar.gz: cd543e1d54989b97354ae0fdea132ed57011336f
5
+ SHA512:
6
+ metadata.gz: 05cb3f44986e110e32f4c4e782c4e6ae44b90e19a71ca28bdc6b4a5988c76cad7cbcac9df1224b88c4cf005959bd2fb33e2e5c46df96b9c2a2993004962d4ab6
7
+ data.tar.gz: 5ca8331d76fe754905ad7954dc458ad0d9eeed19a28df9f132595152e5ceaa9f484e1ce086bb86143759b1642879cadd34602b9fc9258a3bcc5a12b6657e0a7e
@@ -0,0 +1,68 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1
11
+ environment:
12
+ PGHOST: 127.0.0.1
13
+ PGUSER: circleci_postgres
14
+
15
+ # Specify service dependencies here if necessary
16
+ # CircleCI maintains a library of pre-built images
17
+ # documented at https://circleci.com/docs/2.0/circleci-images/
18
+ - image: circleci/postgres:9.4
19
+ environment: # environment variables for database
20
+ POSTGRES_USER: circleci_postgres
21
+ POSTGRES_DB: circleci_postgres
22
+ POSTGRES_PASSWORD: ""
23
+
24
+ working_directory: ~/repo
25
+
26
+ steps:
27
+ - checkout
28
+
29
+ # Download and cache dependencies
30
+ - restore_cache:
31
+ keys:
32
+ - v1-dependencies-{{ checksum "Gemfile" }}-{{ checksum "factory_bot_caching.gemspec" }}
33
+ # fallback to using the latest cache if no exact match is found
34
+ - v1-dependencies-
35
+
36
+ - run:
37
+ name: install dependencies
38
+ command: |
39
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
40
+
41
+ - save_cache:
42
+ paths:
43
+ - ./vendor/bundle
44
+ key: v1-dependencies-{{ checksum "Gemfile" }}-{{ checksum "factory_bot_caching.gemspec" }}
45
+
46
+ - run:
47
+ name: Wait for DB
48
+ command: dockerize -wait tcp://localhost:5432 -timeout 1m
49
+
50
+ # run tests!
51
+ - run:
52
+ name: run tests
53
+ command: |
54
+ mkdir /tmp/test-results
55
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
56
+
57
+ bundle exec rspec --format progress \
58
+ --format RspecJunitFormatter \
59
+ --out /tmp/test-results/rspec.xml \
60
+ --format progress \
61
+ $TEST_FILES
62
+
63
+ # collect reports
64
+ - store_test_results:
65
+ path: /tmp/test-results
66
+ - store_artifacts:
67
+ path: /tmp/test-results
68
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
12
+ /.bundle/
13
+ .ruby-version
14
+ .ruby-gemset
15
+
16
+ # rspec failure tracking
17
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require 'spec_helper'
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2018-07-27
10
+ ### Added
11
+
12
+ - First release
13
+ - Support for caching FactoryGirl factories when using ActiveRecord with Postgresql
14
+ - User defined cache keys
15
+ - Customizable cache timeout
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tim.mertens@avant.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in factory_bot_caching.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-2018 Avant
4
+
5
+ Author Tim Mertens
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # FactoryBotCaching
2
+
3
+ FactoryBotCaching is a gem which implements a caching layer for FactoryGirl with Rails/ActiveRecord.
4
+
5
+ Factory Caching enables you to leverage the flexibility of factories with some of the performance benefits
6
+ of fixtures.
7
+
8
+ ## FactoryGirl / FactoryBot Support
9
+
10
+ * `FactoryBotCaching` `~> 1.0.0` currently only offers built-in support for the `FactoryGirl` gem/namespace.
11
+ * Support for the newer `FactoryBot` namespace is expected in version 2 or earlier.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'factory_bot_caching', :group => :test
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install factory_bot_caching
28
+
29
+ ## Usage
30
+
31
+ ### Configuration
32
+
33
+ FactoryBotCaching is disabled by default. To enable it, add a configuration block like the following to your test
34
+ setup file(s) to enable caching and configure any other options as desired:
35
+
36
+ ```ruby
37
+ # rails_helper.rb
38
+ require 'factory_bot_caching'
39
+
40
+ FactoryBotCaching.configure do |config|
41
+ config.enable_factory_caching # Defaults to factory caching disabled.
42
+ config.cache_timeout = 300 # Optional. Defaults to 900 seconds
43
+ config.custom_cache_key = Proc.new { ::I18n.locale } # Optional. Defaults to nil / no custom caching layer.
44
+ end
45
+ ```
46
+
47
+ #### Configuration Options:
48
+
49
+ ##### enable_factory_caching
50
+
51
+ Turns factory caching on.
52
+
53
+ ##### disable_factory_caching
54
+
55
+ Disables factory caching.
56
+
57
+ ##### cache_timeout
58
+
59
+ The amount of time in seconds after creation that a cached factory record is considered valid to be returned from
60
+ the cache. Defaults to 900 seconds (15 minutes).
61
+
62
+ ##### custom_cache_key
63
+
64
+ The `custom_cache_key` is a Proc that can be executed to generate a value or list/hash of values to use as a custom
65
+ cache key for cached records. By default, no custom caching layer is used.
66
+
67
+ For example, if you have factories which behave differently across locales, you may want to use a `custom_cache_key` which
68
+ adds a caching layer on top of the value returned by `::I18n.locale`.
69
+
70
+ ```ruby
71
+ Proc.new { ::I18n.locale }
72
+ ```
73
+
74
+ This prevents records created in the 'en-GB' locale from being returned in tests run in 'en-US' locale.
75
+
76
+ NOTE: It is not necessary to add a custom cache key for time or date. Changes in date and time by libraries such as
77
+ `TimeCop` are already handled automatically by the built in caching layers and the `cache_timeout` value.
78
+
79
+ ### Setup/Teardown Hooks
80
+
81
+ In addition to configuring/enabling Factory Caching, it is necessary to configure hooks in your test suite to initialize
82
+ at the start of testing and reset cache counters after each test.
83
+
84
+ ### RSpec
85
+
86
+ #### Disable Trasactional Fixtures
87
+
88
+ For factory caching to work correctly, you must ensure that the `rspec-rails` `use_transactional_fixtures` setting is disabled:
89
+
90
+ ```ruby
91
+ RSpec.configure do |config|
92
+ config.use_transactional_fixtures = false
93
+ end
94
+ ```
95
+
96
+ To run tests inside of transactions, we recommend using [DatabaseCleaner](https://rubygems.org/gems/database_cleaner) instead.
97
+
98
+ #### Enable Factory Caching
99
+
100
+ `FactoryBotCaching` provides a setup script for RSpec. This adds the necessary test hooks to an RSpec test suite to set
101
+ up and tear down factory caching in your test suite.
102
+
103
+ In your test setup after requiring FactoryGirl:
104
+
105
+ ```ruby
106
+ # rails_helper.rb
107
+ require 'factory_bot_caching/rspec'
108
+ ```
109
+
110
+ It also adds a metadata filter to exclude specific tests from caching if they always require new records to be created:
111
+
112
+ ```ruby
113
+ RSpec.describe "factory caching metadata" do
114
+ it "runs with caching disabled", :no_factory_caching do
115
+ expect(FactoryBotCaching.enabled?).to be false
116
+ end
117
+
118
+ it "runs with caching disabled" do
119
+ expect(FactoryBotCaching.enabled?).to be true
120
+ end
121
+ end
122
+ ```
123
+
124
+ ### Other Test Frameworks
125
+
126
+ To use Factory Bot Caching in other test frameworks, see `lib/factory_bot_caching/rspec.rb` for the necessary callbacks
127
+ that must be run to use caching.
128
+
129
+ Specifically, you must call `FactoryBotCaching.initialize` before running any tests, and
130
+ `FactoryBotCaching::CacheManager.instance.reset_cache_counter` after each test.
131
+
132
+ Pull requests to add support for other test frameworks are welcome!
133
+
134
+ ## Development
135
+
136
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
137
+
138
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
139
+
140
+ ## Contributing
141
+
142
+ Bug reports and pull requests are welcome on GitHub at https://github.com/avantoss/factory_bot_caching. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
143
+
144
+ ## Roadmap
145
+
146
+ ### v2.0
147
+ * Support FactoryBot
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2017-2018 Avant
4
+ #
5
+ # Author Tim Mertens
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+
25
+ require "bundler/gem_tasks"
26
+ require "rspec/core/rake_task"
27
+
28
+ RSpec::Core::RakeTask.new(:spec)
29
+
30
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "factory_bot_caching"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require_relative 'lib/factory_bot_caching/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "factory_bot_caching"
5
+ spec.version = FactoryBotCaching::VERSION
6
+ spec.authors = ["Tim Mertens"]
7
+ spec.email = ["tim.mertens@filmchicago.org"]
8
+ spec.summary = "A caching mechanism for test suites using Factory Bot/Factory Girl with ActiveRecord."
9
+ spec.description = %q{The factory_bot_caching gem provides a caching mechanism for Factory Bot/Factory Girl to significantly reduce test suite runtimes in factory heavy test suites.}
10
+ spec.license = "MIT"
11
+ spec.homepage = "https://github.com/avantoss/factory_bot_caching"
12
+
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "factory_girl", "~> 4.4"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.6"
25
+ spec.add_development_dependency "activerecord", "~> 4.0"
26
+ spec.add_development_dependency "activesupport", "~> 4.0"
27
+ spec.add_development_dependency "database_cleaner", "~> 1.0"
28
+ spec.add_development_dependency "pg", "~> 0.18"
29
+ spec.add_development_dependency "timecop"
30
+ spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "rspec_junit_formatter"
32
+ end