rails-force-reload 1.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 +7 -0
- data/.gitignore +24 -0
- data/.travis.yml +16 -0
- data/Appraisals +12 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +105 -0
- data/Rakefile +35 -0
- data/Vagrantfile +46 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/gemfiles/activerecord50.gemfile +7 -0
- data/gemfiles/activerecord51.gemfile +7 -0
- data/gemfiles/activerecord52.gemfile +7 -0
- data/lib/rails-force-reload.rb +7 -0
- data/lib/rails-force-reload/rails-force-reload.rb +30 -0
- data/lib/rails-force-reload/version.rb +3 -0
- data/provision.sh +61 -0
- data/rails-force-reload.gemspec +36 -0
- data/test/cases/rails-force-reload-test.rb +44 -0
- data/test/fixtures/active_record.rb +47 -0
- data/test/test_helper.rb +19 -0
- metadata +207 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de14a7c0d70e46344cbc5b23566100ad25ebbbf624a524631e484847b9302ef4
|
4
|
+
data.tar.gz: 17b71dc145a8530960978de595c9ed9f04b8784f9eb72bdd251ff71457721070
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1c45e50f149bbeda87a0158b99c3686e850fbcd5ba3ccb1361dc3b5fb2b309759d620160595edbcfaeaa91cb29305b67609fa2eabf4b9cdf456ef0a40704c3d
|
7
|
+
data.tar.gz: 32220c05a27be92ccf516a1749e89ae23bdfdffb46ad75aba82baddfb8314ff1539016243a49106451aec270de3d3cf16dd2e8ff1451f21b074a4b62b19c8cf9
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
/Gemfile.lock
|
2
|
+
/*.gem
|
3
|
+
|
4
|
+
/gemfiles/.bundle/
|
5
|
+
/gemfiles/*.gemfile.lock
|
6
|
+
|
7
|
+
/.bundle/
|
8
|
+
/.yardoc
|
9
|
+
/_yardoc/
|
10
|
+
/coverage/
|
11
|
+
/doc/
|
12
|
+
/pkg/
|
13
|
+
/tmp/
|
14
|
+
/log
|
15
|
+
|
16
|
+
# Ignore pow environment settings
|
17
|
+
.powenv
|
18
|
+
|
19
|
+
# Ignore Byebug command history file.
|
20
|
+
.byebug_history
|
21
|
+
|
22
|
+
# Vagrant stuff
|
23
|
+
*-cloudimg-console.log
|
24
|
+
/.vagrant
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Frank Koehl
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Rails `force_reload`
|
2
|
+
|
3
|
+
[](https://coveralls.io/github/BattleBrisket/rails-force-reload?branch=master)
|
4
|
+
|
5
|
+
Starting in v5.0, Rails removed the `force_reload` option from ActiveRecord association readers. This gem adds that functionality back in.
|
6
|
+
|
7
|
+
```
|
8
|
+
# Collection association (has_many)
|
9
|
+
|
10
|
+
@user.posts(true)
|
11
|
+
# or @user.posts.reload
|
12
|
+
|
13
|
+
# Singular association (has_one)
|
14
|
+
|
15
|
+
@user.profile(true)
|
16
|
+
# or @user.reload.profile
|
17
|
+
# or @user.reload_profile
|
18
|
+
# See "Background" below for detail on the syntactical difference between these
|
19
|
+
```
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Gemfile
|
23
|
+
```
|
24
|
+
gem 'rails-force-reload'
|
25
|
+
```
|
26
|
+
|
27
|
+
Command line
|
28
|
+
```
|
29
|
+
gem install 'rails-force-reload'
|
30
|
+
```
|
31
|
+
|
32
|
+
## Compatibility
|
33
|
+
|
34
|
+
- Ruby 2.2.2 or greater (tested against 2.2, 2.3, 2.4, and 2.5 lines)
|
35
|
+
- Rails 5.0 or greater (tested against 5.0, 5.1 and 5.2 lines)
|
36
|
+
|
37
|
+
Tests are borrowed nearly verbatim from Rails source code.
|
38
|
+
|
39
|
+
## Background
|
40
|
+
|
41
|
+
The decision to deprecate the `@parent.association(true)` syntax was intended to simplify the API (one way to reload associations), and better honor the Principle of Least Surprise ("what's this `true` mean here?"). See the [original Groups thread](https://groups.google.com/forum/#!topic/rubyonrails-core/6ZPPg1ZmjQA/discussion) and [initial pull request](https://github.com/rails/rails/pull/20888) for further context.
|
42
|
+
|
43
|
+
We agree with the spirit of the decision, but it came with tradeoffs.
|
44
|
+
|
45
|
+
"Reload-only" syntax limits readability, specifically when conditionally reloading a given association. GitHub user [@heaven](https://github.com/heaven) offered a succinct example (in the [commit removing the functionality](https://github.com/rails/rails/commit/09cac8c67afdc4b2a1c6ae07931ddc082629b277#commitcomment-23704911), no less)
|
46
|
+
|
47
|
+
> That was pretty much useful #association(self.persisted?).
|
48
|
+
>
|
49
|
+
> It was:
|
50
|
+
>
|
51
|
+
> `record.tags(record.persisted?).map(&:name)`
|
52
|
+
>
|
53
|
+
> It becomes:
|
54
|
+
>
|
55
|
+
> `(record.persisted? ? record.tags.reload : record.tags).map(&:name)`
|
56
|
+
|
57
|
+
The first example is clearly more succinct and readily absorbed.
|
58
|
+
|
59
|
+
Reload syntax also breaks expectations when dealing with a _singular_ association (`Foo.has_one :bar`) versus a _collection_ association (`Foo.has_many :bars`).
|
60
|
+
|
61
|
+
The `reload` call comes _after_ a collection...
|
62
|
+
|
63
|
+
```
|
64
|
+
@user.posts.reload
|
65
|
+
```
|
66
|
+
|
67
|
+
but _before_ a singular
|
68
|
+
|
69
|
+
```
|
70
|
+
@user.reload.profile
|
71
|
+
```
|
72
|
+
|
73
|
+
In addition, the behavior on a singular association is not a one-for-one match with the `force_reload` syntax. Since we are reloading the parent, we also throw away any unsaved changes and existing existing caches. To compensate, a new `reload_<association>` dynamic method [was introduced](https://github.com/rails/rails/pull/27133). Our above example would be rewritten as such:
|
74
|
+
|
75
|
+
```
|
76
|
+
@user.reload_profile
|
77
|
+
```
|
78
|
+
|
79
|
+
This is the recommended way to handle singular associations, given the side effects of reloading the parent, however both methods will technically work.
|
80
|
+
|
81
|
+
[DHH expressed satisfaction](https://groups.google.com/d/msg/rubyonrails-core/6ZPPg1ZmjQA/kTT-GKwew10J) with divergent handling to `has_one` vs `has_many` associations. Obviously, we (politely!) disagree with this assessment.
|
82
|
+
|
83
|
+
The "reload before/after" syntax, coupled with the introduction of a dynamic magic method to recover lost functionality would seem to be a net loss, when compared with the consistency of `@parent.association(true)`
|
84
|
+
|
85
|
+
Looking at the meta, Singular and Collection associations behave differently, but are grouped and handled collectively, both within the Rails core and Rails-powered applications. The close relationship warrants maintaining parity where possible. This is obviously a matter of opinion, but was a factor of consideration.
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.
|
90
|
+
|
91
|
+
We use the [appraisal](https://github.com/thoughtbot/appraisal) gem to help us generate the individual Gemfiles for each ActiveRecord version and to run the tests locally against each generated Gemfile. The `bundle exec rake appraisal test` command actually runs our test suite against all Rails versions in our `Appraisal` file. If you want to run the tests for a specific Rails version, use `rake -T` for a list.
|
92
|
+
|
93
|
+
```shell
|
94
|
+
$ bundle exec appraisal activerecord52 rake test
|
95
|
+
```
|
96
|
+
|
97
|
+
We provide a [Vagrant](https://www.vagrantup.com) box to spin up the entire gem in a clean environment. Doing so will avoid the need to prefix all commands with `bundle exec`
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/battlebrisket/rails-force-reload.
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'appraisal'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
require 'rails-force-reload/version'
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.test_files = FileList['test/**/*test.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :test
|
14
|
+
|
15
|
+
namespace :gem do
|
16
|
+
desc "Connect to RubyGems.org account"
|
17
|
+
task :auth do
|
18
|
+
sh "curl -u battlebrisket https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Build the gem according to gemspec"
|
22
|
+
task :build do
|
23
|
+
sh "gem build rails-force-reload.gemspec"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Push the gem to RubyGems.org"
|
27
|
+
task :push do
|
28
|
+
sh "gem push rails-force-reload-#{RailsForceReload::VERSION}.gem"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task :publish do
|
33
|
+
Rake::Task["gem:build"].invoke
|
34
|
+
Rake::Task["gem:push"].invoke
|
35
|
+
end
|
data/Vagrantfile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
NAME = "rails-force-reload"
|
5
|
+
FQDN = "#{NAME}.example.com"
|
6
|
+
|
7
|
+
Vagrant.configure("2") do |config|
|
8
|
+
config.vm.box = "bento/ubuntu-16.04"
|
9
|
+
|
10
|
+
# Use the normal insecure key
|
11
|
+
# https://github.com/mitchellh/vagrant/issues/2608
|
12
|
+
config.ssh.insert_key = false
|
13
|
+
|
14
|
+
config.vm.provider :virtualbox do |vb|
|
15
|
+
vb.customize ["modifyvm", :id,
|
16
|
+
# Basics.
|
17
|
+
"--name", NAME,
|
18
|
+
"--memory", 4096,
|
19
|
+
# I/O APIC must be enabled to support a multi-core guest.
|
20
|
+
"--cpus", 4,
|
21
|
+
"--ioapic", "on",
|
22
|
+
# Enable native host virtualization features (yields better performance).
|
23
|
+
"--pae", "on",
|
24
|
+
"--hwvirtex", "on",
|
25
|
+
"--largepages", "on",
|
26
|
+
"--vtxvpid", "on",
|
27
|
+
# This causes the virtual machine to proxy DNS requests through the host
|
28
|
+
# via NAT. Without this, the default resolver on the guest will introduce
|
29
|
+
# a 5 second latency on every HTTP request... which is a real downer.
|
30
|
+
"--natdnshostresolver1", "on"
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
config.vm.hostname = FQDN
|
35
|
+
config.vm.provision :shell, path: "provision.sh"
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# DONT FORGET!
|
40
|
+
#
|
41
|
+
# Force update VirtualBox Guest Additions
|
42
|
+
# Run the following command inside same directory as Vagrantfile
|
43
|
+
# Must be done once on your dev system
|
44
|
+
#
|
45
|
+
# vagrant plugin install vagrant-vbguest
|
46
|
+
#
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'active_record'
|
5
|
+
require 'rails-force-reload'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
require "pry"
|
12
|
+
Pry.start
|
13
|
+
|
14
|
+
# require "irb"
|
15
|
+
# IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module RailsForceReload
|
4
|
+
|
5
|
+
module DefineReaders
|
6
|
+
# this method changed in 5.2.0 to strip arguments
|
7
|
+
# See commit 39f6c6c641f0c92c532e0c3747d1536af657920f
|
8
|
+
def define_readers(mixin, name)
|
9
|
+
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
10
|
+
def #{name}(*args)
|
11
|
+
association(:#{name}).reader(*args)
|
12
|
+
end
|
13
|
+
CODE
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
ActiveRecord::Associations::Builder::Association.singleton_class.prepend(DefineReaders)
|
18
|
+
|
19
|
+
module Reader
|
20
|
+
def reader(force_reload = false)
|
21
|
+
klass.uncached { reload } if force_reload && klass
|
22
|
+
super()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveRecord::Associations::SingularAssociation.send(:prepend, Reader)
|
27
|
+
ActiveRecord::Associations::CollectionAssociation.send(:prepend, Reader)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
data/provision.sh
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Shell user settings.
|
4
|
+
USER_NAME=vagrant
|
5
|
+
USER_HOME=/home/$USER_NAME
|
6
|
+
DEFAULT_RUBY='2.5.1'
|
7
|
+
|
8
|
+
###############################################################################
|
9
|
+
# Functions
|
10
|
+
###############################################################################
|
11
|
+
# DRY wrapper for sudo commands.
|
12
|
+
as_user() {
|
13
|
+
echo "$USER_NAME:~$ > ${*}"
|
14
|
+
su -l $USER_NAME -c "$*"
|
15
|
+
}
|
16
|
+
|
17
|
+
###############################################################################
|
18
|
+
# Base System
|
19
|
+
###############################################################################
|
20
|
+
apt-get -y update
|
21
|
+
apt-get -yfV dist-upgrade
|
22
|
+
|
23
|
+
###############################################################################
|
24
|
+
# rbenv & ruby-build, and Rubies
|
25
|
+
# From https://github.com/sstephenson/rbenv
|
26
|
+
# and https://github.com/sstephenson/ruby-build
|
27
|
+
###############################################################################
|
28
|
+
|
29
|
+
# Install dependencies.
|
30
|
+
apt-get install -yfV \
|
31
|
+
build-essential \
|
32
|
+
curl \
|
33
|
+
git-core \
|
34
|
+
libcurl4-openssl-dev \
|
35
|
+
libreadline-dev \
|
36
|
+
libsqlite3-dev \
|
37
|
+
libssl-dev \
|
38
|
+
libxml2-dev \
|
39
|
+
libxslt1-dev \
|
40
|
+
libyaml-dev \
|
41
|
+
python-software-properties \
|
42
|
+
sqlite3 \
|
43
|
+
zlib1g-dev \
|
44
|
+
|
45
|
+
# Install rbenv and ruby-build.
|
46
|
+
as_user "git clone https://github.com/sstephenson/rbenv.git $USER_HOME/.rbenv"
|
47
|
+
as_user "git clone https://github.com/sstephenson/ruby-build.git $USER_HOME/.rbenv/plugins/ruby-build"
|
48
|
+
|
49
|
+
# Setup bash to use rbenv for $USER_NAME.
|
50
|
+
truncate -s 0 $USER_HOME/.bashrc
|
51
|
+
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $USER_HOME/.bashrc
|
52
|
+
echo 'eval "$(rbenv init -)"' >> $USER_HOME/.bashrc
|
53
|
+
echo 'cd /vagrant' >> $USER_HOME/.bashrc
|
54
|
+
|
55
|
+
echo 'gem: --no-document' > $USER_HOME/.gemrc
|
56
|
+
|
57
|
+
# Install the requested version of Ruby, with Bundler.
|
58
|
+
as_user "rbenv install -s $DEFAULT_RUBY"
|
59
|
+
as_user "rbenv global $DEFAULT_RUBY"
|
60
|
+
as_user "RBENV_VERSION=$DEFAULT_RUBY gem install bundler"
|
61
|
+
as_user "cd /vagrant && bin/setup"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require "rails-force-reload/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
|
7
|
+
s.name = "rails-force-reload"
|
8
|
+
s.version = RailsForceReload::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Frank Koehl"]
|
11
|
+
s.email = ["fkoehl@gmail.com"]
|
12
|
+
s.summary = "Restore force_reload argument on ActiveRecord collection associations"
|
13
|
+
s.description = <<-EOF
|
14
|
+
Starting in v5.0, Rails removed the `force_reload` option from ActiveRecord association readers. This gem adds that functionality back in.
|
15
|
+
EOF
|
16
|
+
s.homepage = "https://github.com/battlebrisket/rails-force-reload"
|
17
|
+
s.license = "MIT"
|
18
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
s.test_files = Dir["test/**/*"]
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'activerecord', '>= 5.0', '< 6.0'
|
23
|
+
|
24
|
+
s.add_development_dependency 'activerecord', '>= 5.0', '< 6.0'
|
25
|
+
s.add_development_dependency 'minitest'
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
s.add_development_dependency "appraisal"
|
28
|
+
s.add_development_dependency 'pry-byebug', '>= 0'
|
29
|
+
s.add_development_dependency 'coveralls'
|
30
|
+
s.add_development_dependency 'sqlite3'
|
31
|
+
s.add_development_dependency "activesupport"
|
32
|
+
|
33
|
+
# Rails 5.0 onward requires Ruby 2.2.2
|
34
|
+
s.required_ruby_version = '>= 2.2.2'
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRailsForceReload < RFRTestCase
|
4
|
+
|
5
|
+
test "force_reload on CollectionAssociation" do
|
6
|
+
firm = Firm.new("name" => "A New Firm, Inc")
|
7
|
+
firm.save
|
8
|
+
firm.clients.each {} # forcing to load all clients
|
9
|
+
assert firm.clients.empty?, "New firm shouldn't have client objects"
|
10
|
+
assert_equal 0, firm.clients.size, "New firm should have 0 clients"
|
11
|
+
|
12
|
+
client = Client.new("name" => "TheClient.com", "firm_id" => firm.id)
|
13
|
+
client.save
|
14
|
+
|
15
|
+
assert firm.clients.empty?, "New firm should have cached no client objects"
|
16
|
+
assert_equal 0, firm.clients.size, "New firm should have cached 0 clients count"
|
17
|
+
|
18
|
+
assert !firm.clients(true).empty?, "New firm should have reloaded client objects"
|
19
|
+
assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count"
|
20
|
+
end
|
21
|
+
|
22
|
+
test "force_reload on SingularAssociation" do
|
23
|
+
firm = Firm.new("name" => "A New Firm, Inc")
|
24
|
+
firm.save
|
25
|
+
firm.user # forcing to load user
|
26
|
+
assert_nil firm.user, "New firm shouldn't have user object"
|
27
|
+
|
28
|
+
user = User.new("name" => "Joe Blow", "firm_id" => firm.id)
|
29
|
+
user.save
|
30
|
+
|
31
|
+
assert_nil firm.user, "New firm should have cached no user objects"
|
32
|
+
|
33
|
+
refute_nil firm.user(true), "New firm should have reloaded user object"
|
34
|
+
assert_instance_of User, firm.user(true), "New firm should now hold a User object"
|
35
|
+
end
|
36
|
+
|
37
|
+
test "reload command (still) returns association" do
|
38
|
+
firm = Firm.create!("name" => "A New Firm, Inc")
|
39
|
+
assert_nothing_raised do
|
40
|
+
assert_equal firm.clients, firm.clients.reload.reload
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fixtures
|
2
|
+
module ActiveRecord
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def setup_schema
|
7
|
+
::ActiveRecord::Base.class_eval do
|
8
|
+
connection.instance_eval do
|
9
|
+
|
10
|
+
create_table :firms, force: true do |t|
|
11
|
+
t.string :name
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :clients, force: true do |t|
|
16
|
+
t.integer :firm_id
|
17
|
+
t.string :name
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :users, force: true do |t|
|
22
|
+
t.integer :firm_id
|
23
|
+
t.string :name
|
24
|
+
t.timestamps
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Firm < ::ActiveRecord::Base
|
32
|
+
has_many :clients
|
33
|
+
has_one :user
|
34
|
+
end
|
35
|
+
|
36
|
+
class Client < ::ActiveRecord::Base
|
37
|
+
belongs_to :firm
|
38
|
+
end
|
39
|
+
|
40
|
+
class User < ::ActiveRecord::Base
|
41
|
+
belongs_to :firm
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler'; Bundler.require :development, :test
|
2
|
+
require "active_support/test_case"
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
require 'rails-force-reload'
|
7
|
+
require 'fixtures/active_record'
|
8
|
+
|
9
|
+
class RFRTestCase < ActiveSupport::TestCase
|
10
|
+
|
11
|
+
include Fixtures::ActiveRecord
|
12
|
+
|
13
|
+
def setup
|
14
|
+
setup_schema
|
15
|
+
Firm.connection
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-force-reload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frank Koehl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activerecord
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '6.0'
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '5.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '6.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: minitest
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: appraisal
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: pry-byebug
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: coveralls
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: sqlite3
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: activesupport
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
description: " Starting in v5.0, Rails removed the `force_reload` option from ActiveRecord
|
152
|
+
association readers. This gem adds that functionality back in.\n"
|
153
|
+
email:
|
154
|
+
- fkoehl@gmail.com
|
155
|
+
executables: []
|
156
|
+
extensions: []
|
157
|
+
extra_rdoc_files: []
|
158
|
+
files:
|
159
|
+
- ".gitignore"
|
160
|
+
- ".travis.yml"
|
161
|
+
- Appraisals
|
162
|
+
- Gemfile
|
163
|
+
- LICENSE
|
164
|
+
- README.md
|
165
|
+
- Rakefile
|
166
|
+
- Vagrantfile
|
167
|
+
- bin/console
|
168
|
+
- bin/setup
|
169
|
+
- gemfiles/activerecord50.gemfile
|
170
|
+
- gemfiles/activerecord51.gemfile
|
171
|
+
- gemfiles/activerecord52.gemfile
|
172
|
+
- lib/rails-force-reload.rb
|
173
|
+
- lib/rails-force-reload/rails-force-reload.rb
|
174
|
+
- lib/rails-force-reload/version.rb
|
175
|
+
- provision.sh
|
176
|
+
- rails-force-reload.gemspec
|
177
|
+
- test/cases/rails-force-reload-test.rb
|
178
|
+
- test/fixtures/active_record.rb
|
179
|
+
- test/test_helper.rb
|
180
|
+
homepage: https://github.com/battlebrisket/rails-force-reload
|
181
|
+
licenses:
|
182
|
+
- MIT
|
183
|
+
metadata: {}
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
require_paths:
|
187
|
+
- lib
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: 2.2.2
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
requirements: []
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 2.7.6
|
201
|
+
signing_key:
|
202
|
+
specification_version: 4
|
203
|
+
summary: Restore force_reload argument on ActiveRecord collection associations
|
204
|
+
test_files:
|
205
|
+
- test/cases/rails-force-reload-test.rb
|
206
|
+
- test/fixtures/active_record.rb
|
207
|
+
- test/test_helper.rb
|