activerecord-deprecated_finders 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -8
- data/lib/active_record/deprecated_finders/base.rb +5 -2
- data/lib/active_record/deprecated_finders/collection_proxy.rb +6 -2
- data/lib/active_record/deprecated_finders/relation.rb +1 -1
- data/lib/active_record/deprecated_finders/version.rb +1 -1
- metadata +16 -45
- data/.gitignore +0 -17
- data/.travis.yml +0 -16
- data/Gemfile +0 -5
- data/Rakefile +0 -28
- data/activerecord-deprecated_finders.gemspec +0 -21
- data/activerecord-deprecated_finders.gemspec.erb +0 -21
- data/test/associations_test.rb +0 -91
- data/test/calculate_test.rb +0 -15
- data/test/default_scope_test.rb +0 -35
- data/test/dynamic_methods_test.rb +0 -133
- data/test/find_in_batches_test.rb +0 -18
- data/test/finder_options_test.rb +0 -80
- data/test/finder_test.rb +0 -69
- data/test/helper.rb +0 -68
- data/test/scope_test.rb +0 -17
- data/test/scoped_test.rb +0 -15
- data/test/update_all_test.rb +0 -24
- data/test/with_scope_test.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80989752f57c371b971193ef427719e10babd8a0
|
4
|
+
data.tar.gz: e335a3bd0f13928bd81d41bb164ee372a8be6d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1659767eb1eadb3171ea22b191d9d433db31455d3804fd6988f135eff9dc811ab94e3b4b01e44b2b19b9cc0ec4646f20f8407c15b2910316bda313a373e9a8
|
7
|
+
data.tar.gz: f25253cf446d0f207b3e46b08adc440a781c91b56677e0abbf2546a68b7d970f75c1a3716ca8970e1c9ecd1f5af8965d503649471c0dd2e945ad1695d62d2ed0
|
data/README.md
CHANGED
@@ -1,15 +1,59 @@
|
|
1
1
|
# Active Record Deprecated Finders
|
2
2
|
|
3
|
-
This gem
|
4
|
-
|
3
|
+
This gem is a dependency of Rails 4.0 to provide deprecated finder
|
4
|
+
functionality.
|
5
|
+
|
6
|
+
It will be removed as a dependency in Rails 4.1, but users can manually include
|
7
|
+
it in their Gemfile and it will continue to be maintained until Rails 5.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'activerecord-deprecated_finders', require: 'active_record/deprecated_finders'
|
11
|
+
```
|
5
12
|
|
6
|
-
|
13
|
+
This gem is used to extract and deprecate old-style finder option hashes in
|
14
|
+
Active Record:
|
15
|
+
|
16
|
+
```ruby
|
7
17
|
Post.find(:all, conditions: { published_on: 2.weeks.ago }, limit: 5)
|
8
18
|
```
|
9
19
|
|
10
|
-
|
11
|
-
|
20
|
+
as well as the following dynamic finders:
|
21
|
+
|
22
|
+
* `find_all_by_...`
|
23
|
+
* `find_last_by_...`
|
24
|
+
* `scoped_by_...`
|
25
|
+
* `find_or_initialize_by_...`
|
26
|
+
* `find_or_create_by_...`
|
27
|
+
|
28
|
+
Note that `find(primary_key)`, `find_by...`, and `find_by...!` are not
|
29
|
+
deprecated.
|
30
|
+
|
31
|
+
To avoid reliance on this gem, you'll need to migrate your finder usage.
|
32
|
+
|
33
|
+
To migrate dynamic finders to Rails 4.1+:
|
34
|
+
|
35
|
+
* `find_all_by_...` should become `where(...)`.
|
36
|
+
* `find_last_by_...` should become `where(...).last`.
|
37
|
+
* `scoped_by_...` should become `where(...)`.
|
38
|
+
* `find_or_initialize_by_...` should become `find_or_initialize_by(...)`.
|
39
|
+
* `find_or_create_by_...` should become `find_or_create_by(...)`.
|
40
|
+
|
41
|
+
To migrate old-style finder option hashes and for additional information,
|
42
|
+
please refer to:
|
43
|
+
|
44
|
+
* [ActiveRecord::FinderMethods][findermethods],
|
45
|
+
[ActiveRecord::Relation][relation], and
|
46
|
+
[ActiveRecord::QueryMethods][querymethods] docs.
|
47
|
+
* Rails Guide: Upgrading Ruby on Rails ([stable][stableguide] /
|
48
|
+
[edge][edgeguide]).
|
12
49
|
|
13
|
-
|
14
|
-
|
15
|
-
|
50
|
+
[findermethods]:
|
51
|
+
http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html
|
52
|
+
[relation]:
|
53
|
+
http://api.rubyonrails.org/classes/ActiveRecord/Relation.html
|
54
|
+
[querymethods]:
|
55
|
+
http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html
|
56
|
+
[stableguide]:
|
57
|
+
http://guides.rubyonrails.org/upgrading_ruby_on_rails.html
|
58
|
+
[edgeguide]:
|
59
|
+
http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html
|
@@ -43,7 +43,7 @@ module ActiveRecord
|
|
43
43
|
end
|
44
44
|
|
45
45
|
if result.is_a?(Hash)
|
46
|
-
@klass.
|
46
|
+
@klass.all.apply_finder_options(result, true)
|
47
47
|
else
|
48
48
|
result
|
49
49
|
end
|
@@ -92,7 +92,10 @@ module ActiveRecord
|
|
92
92
|
|
93
93
|
scope.assert_valid_keys([ :find, :create ])
|
94
94
|
relation = construct_finder_arel(scope[:find] || {})
|
95
|
-
|
95
|
+
|
96
|
+
if relation.respond_to?(:default_scoped=)
|
97
|
+
relation.default_scoped = true unless action == :overwrite
|
98
|
+
end
|
96
99
|
|
97
100
|
if previous_scope && previous_scope.create_with_value && scope[:create]
|
98
101
|
scope_for_create = if action == :merge
|
@@ -29,8 +29,12 @@ module ActiveRecord
|
|
29
29
|
# Ensure this get included first
|
30
30
|
include ActiveRecord::Delegation::ClassSpecificRelation
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
unless ActiveRecord::VERSION::MAJOR == 4 &&
|
33
|
+
ActiveRecord::VERSION::MINOR == 2 &&
|
34
|
+
ActiveRecord::VERSION::TINY > 1
|
35
|
+
# Now override the method_missing definition
|
36
|
+
include InterceptDynamicInstantiators
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
metadata
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-deprecated_finders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Leighton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 4.0.0.beta
|
34
|
-
- - <
|
34
|
+
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '5'
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 4.0.0.beta
|
44
|
-
- - <
|
44
|
+
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '1.3'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - ~>
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '1.3'
|
61
61
|
description: Deprecated finder APIs extracted from Active Record.
|
@@ -65,14 +65,8 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
-
- .gitignore
|
69
|
-
- .travis.yml
|
70
|
-
- Gemfile
|
71
68
|
- LICENSE
|
72
69
|
- README.md
|
73
|
-
- Rakefile
|
74
|
-
- activerecord-deprecated_finders.gemspec
|
75
|
-
- activerecord-deprecated_finders.gemspec.erb
|
76
70
|
- lib/active_record/deprecated_finders.rb
|
77
71
|
- lib/active_record/deprecated_finders/association_builder.rb
|
78
72
|
- lib/active_record/deprecated_finders/base.rb
|
@@ -80,20 +74,9 @@ files:
|
|
80
74
|
- lib/active_record/deprecated_finders/dynamic_matchers.rb
|
81
75
|
- lib/active_record/deprecated_finders/relation.rb
|
82
76
|
- lib/active_record/deprecated_finders/version.rb
|
83
|
-
- test/associations_test.rb
|
84
|
-
- test/calculate_test.rb
|
85
|
-
- test/default_scope_test.rb
|
86
|
-
- test/dynamic_methods_test.rb
|
87
|
-
- test/find_in_batches_test.rb
|
88
|
-
- test/finder_options_test.rb
|
89
|
-
- test/finder_test.rb
|
90
|
-
- test/helper.rb
|
91
|
-
- test/scope_test.rb
|
92
|
-
- test/scoped_test.rb
|
93
|
-
- test/update_all_test.rb
|
94
|
-
- test/with_scope_test.rb
|
95
77
|
homepage: https://github.com/rails/activerecord-deprecated_finders
|
96
|
-
licenses:
|
78
|
+
licenses:
|
79
|
+
- MIT
|
97
80
|
metadata: {}
|
98
81
|
post_install_message:
|
99
82
|
rdoc_options: []
|
@@ -101,30 +84,18 @@ require_paths:
|
|
101
84
|
- lib
|
102
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
86
|
requirements:
|
104
|
-
- -
|
87
|
+
- - ">="
|
105
88
|
- !ruby/object:Gem::Version
|
106
89
|
version: '0'
|
107
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
91
|
requirements:
|
109
|
-
- -
|
92
|
+
- - ">="
|
110
93
|
- !ruby/object:Gem::Version
|
111
94
|
version: '0'
|
112
95
|
requirements: []
|
113
96
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.4.5
|
115
98
|
signing_key:
|
116
99
|
specification_version: 4
|
117
100
|
summary: This gem contains deprecated finder APIs extracted from Active Record.
|
118
|
-
test_files:
|
119
|
-
- test/associations_test.rb
|
120
|
-
- test/calculate_test.rb
|
121
|
-
- test/default_scope_test.rb
|
122
|
-
- test/dynamic_methods_test.rb
|
123
|
-
- test/find_in_batches_test.rb
|
124
|
-
- test/finder_options_test.rb
|
125
|
-
- test/finder_test.rb
|
126
|
-
- test/helper.rb
|
127
|
-
- test/scope_test.rb
|
128
|
-
- test/scoped_test.rb
|
129
|
-
- test/update_all_test.rb
|
130
|
-
- test/with_scope_test.rb
|
101
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 1.9.3
|
4
|
-
- 2.0.0
|
5
|
-
gemfile:
|
6
|
-
- gemfiles/Gemfile-edge
|
7
|
-
- Gemfile
|
8
|
-
notifications:
|
9
|
-
email: false
|
10
|
-
campfire:
|
11
|
-
on_success: change
|
12
|
-
on_failure: always
|
13
|
-
rooms:
|
14
|
-
- secure: "DwWWfmRXWSYoelIo3W6H99FrLM2V9ugFoAu+xBo42n2pNV44lU+8T9O+zWkV\nwD3Lz+7URB/5IRPcEel/KYaRYNJl71YUBgtlcvjM7Xl/7YGLYFAcPT2RXfKA\nctvckk/5NehmSawnLhhvMz2gKtIx/fIwCVqxUnRqqYE0eEQaONA="
|
15
|
-
before_install:
|
16
|
-
- gem install bundler
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
Rake::TestTask.new do |t|
|
6
|
-
t.libs = ["test"]
|
7
|
-
t.pattern = "test/**/*_test.rb"
|
8
|
-
t.ruby_opts = ['-w']
|
9
|
-
end
|
10
|
-
|
11
|
-
task :default => :test
|
12
|
-
|
13
|
-
specname = "activerecord-deprecated_finders.gemspec"
|
14
|
-
deps = `git ls-files`.split("\n") - [specname]
|
15
|
-
|
16
|
-
task :gemspec => specname
|
17
|
-
|
18
|
-
file specname => deps do
|
19
|
-
files = `git ls-files`.split("\n") - Dir["gemfiles/*"]
|
20
|
-
test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
-
executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
-
|
23
|
-
require 'erb'
|
24
|
-
|
25
|
-
File.open specname, 'w:utf-8' do |f|
|
26
|
-
f.write ERB.new(File.read("#{specname}.erb")).result(binding)
|
27
|
-
end
|
28
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/active_record/deprecated_finders/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Jon Leighton"]
|
6
|
-
gem.email = ["j@jonathanleighton.com"]
|
7
|
-
gem.description = %q{Deprecated finder APIs extracted from Active Record.}
|
8
|
-
gem.summary = %q{This gem contains deprecated finder APIs extracted from Active Record.}
|
9
|
-
gem.homepage = "https://github.com/rails/activerecord-deprecated_finders"
|
10
|
-
|
11
|
-
gem.files = [".gitignore",".travis.yml","Gemfile","LICENSE","README.md","Rakefile","activerecord-deprecated_finders.gemspec","activerecord-deprecated_finders.gemspec.erb","lib/active_record/deprecated_finders.rb","lib/active_record/deprecated_finders/association_builder.rb","lib/active_record/deprecated_finders/base.rb","lib/active_record/deprecated_finders/collection_proxy.rb","lib/active_record/deprecated_finders/dynamic_matchers.rb","lib/active_record/deprecated_finders/relation.rb","lib/active_record/deprecated_finders/version.rb","test/associations_test.rb","test/calculate_test.rb","test/default_scope_test.rb","test/dynamic_methods_test.rb","test/find_in_batches_test.rb","test/finder_options_test.rb","test/finder_test.rb","test/helper.rb","test/scope_test.rb","test/scoped_test.rb","test/update_all_test.rb","test/with_scope_test.rb"]
|
12
|
-
gem.test_files = ["test/associations_test.rb","test/calculate_test.rb","test/default_scope_test.rb","test/dynamic_methods_test.rb","test/find_in_batches_test.rb","test/finder_options_test.rb","test/finder_test.rb","test/helper.rb","test/scope_test.rb","test/scoped_test.rb","test/update_all_test.rb","test/with_scope_test.rb"]
|
13
|
-
gem.executables = []
|
14
|
-
gem.name = "activerecord-deprecated_finders"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = ActiveRecord::DeprecatedFinders::VERSION
|
17
|
-
|
18
|
-
gem.add_development_dependency 'minitest', '>= 3'
|
19
|
-
gem.add_development_dependency 'activerecord', '>= 4.0.0.beta', '< 5'
|
20
|
-
gem.add_development_dependency 'sqlite3', '~> 1.3'
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/active_record/deprecated_finders/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Jon Leighton"]
|
6
|
-
gem.email = ["j@jonathanleighton.com"]
|
7
|
-
gem.description = %q{Deprecated finder APIs extracted from Active Record.}
|
8
|
-
gem.summary = %q{This gem contains deprecated finder APIs extracted from Active Record.}
|
9
|
-
gem.homepage = "https://github.com/rails/activerecord-deprecated_finders"
|
10
|
-
|
11
|
-
gem.files = [<%= files.map(&:inspect).join ',' %>]
|
12
|
-
gem.test_files = [<%= test_files.map(&:inspect).join ',' %>]
|
13
|
-
gem.executables = [<%= executables.map(&:inspect).join ',' %>]
|
14
|
-
gem.name = "activerecord-deprecated_finders"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = ActiveRecord::DeprecatedFinders::VERSION
|
17
|
-
|
18
|
-
gem.add_development_dependency 'minitest', '>= 3'
|
19
|
-
gem.add_development_dependency 'activerecord', '>= 4.0.0.beta', '< 5'
|
20
|
-
gem.add_development_dependency 'sqlite3', '~> 1.3'
|
21
|
-
end
|
data/test/associations_test.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'associations' do
|
4
|
-
before do
|
5
|
-
@klass = Class.new(ActiveRecord::Base)
|
6
|
-
def @klass.name; 'Post'; end
|
7
|
-
@klass.table_name = 'posts'
|
8
|
-
Appointment.delete_all
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should respect find_by_anything method defined on the base class' do
|
12
|
-
physician = Physician.create!
|
13
|
-
|
14
|
-
ActiveSupport::Deprecation.silence do
|
15
|
-
assert_equal [], physician.patients.find_by_custom_name
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'find_or_create_by on has_many through should work' do
|
20
|
-
physician = Physician.create!
|
21
|
-
ActiveSupport::Deprecation.silence do
|
22
|
-
physician.patients.find_or_create_by_name('Tim')
|
23
|
-
end
|
24
|
-
assert_equal 1, Appointment.count
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'find_or_create_by with bang on has_many through should work' do
|
28
|
-
physician = Physician.create!
|
29
|
-
ActiveSupport::Deprecation.silence do
|
30
|
-
physician.patients.find_or_create_by_name!('Tim')
|
31
|
-
end
|
32
|
-
assert_equal 1, Appointment.count
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'find_or_create_by on has_many should work' do
|
36
|
-
physician = Physician.create!
|
37
|
-
ActiveSupport::Deprecation.silence do
|
38
|
-
appointment = physician.appointments.find_or_create_by_status(status: 'active', week_day: 'sunday')
|
39
|
-
assert_equal appointment, physician.appointments.find_or_create_by_status(status: 'active', week_day: 'sunday')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'translates hash scope options into scopes' do
|
44
|
-
assert_deprecated do
|
45
|
-
@klass.has_many :comments, readonly: 'a', order: 'b', limit: 'c', group: 'd', having: 'e',
|
46
|
-
offset: 'f', select: 'g', uniq: 'h', include: 'i', conditions: 'j'
|
47
|
-
end
|
48
|
-
|
49
|
-
scope = @klass.new.comments
|
50
|
-
|
51
|
-
scope.readonly_value.must_equal 'a'
|
52
|
-
scope.order_values.must_equal ['b']
|
53
|
-
scope.limit_value.must_equal 'c'
|
54
|
-
scope.group_values.must_equal ['d']
|
55
|
-
scope.having_values.must_equal ['e']
|
56
|
-
scope.offset_value.must_equal 'f'
|
57
|
-
scope.select_values.must_equal ['g']
|
58
|
-
scope.uniq_value.must_equal 'h'
|
59
|
-
scope.includes_values.must_equal ['i']
|
60
|
-
scope.where_values.must_include 'j'
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'supports proc where values' do
|
64
|
-
ActiveSupport::Deprecation.silence do
|
65
|
-
@klass.has_many :comments, conditions: proc { 'omg' }
|
66
|
-
end
|
67
|
-
@klass.new.comments.where_values.must_include 'omg'
|
68
|
-
@klass.joins(:comments).to_sql.must_include 'omg'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'supports proc where values which access the owner' do
|
72
|
-
ActiveSupport::Deprecation.silence do
|
73
|
-
@klass.has_many :comments, conditions: proc { title }
|
74
|
-
end
|
75
|
-
@klass.new(title: 'omg').comments.where_values.must_include 'omg'
|
76
|
-
end
|
77
|
-
|
78
|
-
it "allows a declaration with a scope with no options" do
|
79
|
-
ActiveSupport::Deprecation.silence do
|
80
|
-
@klass.has_many :comments, -> { limit 5 }
|
81
|
-
end
|
82
|
-
scope = @klass.new.comments
|
83
|
-
scope.limit_value.must_equal 5
|
84
|
-
end
|
85
|
-
|
86
|
-
it "raises an ArgumentError when declaration uses both scope and deprecated options" do
|
87
|
-
assert_raises(ArgumentError) do
|
88
|
-
@klass.has_many :comments, -> { limit 5 }, :order=>'b'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/test/calculate_test.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'calculate' do
|
4
|
-
after do
|
5
|
-
Post.destroy_all
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'supports finder options' do
|
9
|
-
Post.create id: 1
|
10
|
-
Post.create id: 2, title: 'foo'
|
11
|
-
Post.create id: 3, title: 'foo'
|
12
|
-
|
13
|
-
assert_deprecated { Post.calculate(:sum, :id, conditions: { title: 'foo' }) }.must_equal 5
|
14
|
-
end
|
15
|
-
end
|
data/test/default_scope_test.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'default scope' do
|
4
|
-
before do
|
5
|
-
Post.create(id: 1, title: 'foo lol')
|
6
|
-
Post.create(id: 2, title: 'foo omg')
|
7
|
-
Post.create(id: 3)
|
8
|
-
|
9
|
-
@klass = Class.new(Post)
|
10
|
-
@klass.table_name = 'posts'
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
Post.delete_all
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'works with a finder hash' do
|
18
|
-
assert_deprecated { @klass.default_scope conditions: { id: 1 } }
|
19
|
-
@klass.all.map(&:id).must_equal [1]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'works with a finder hash and a scope' do
|
23
|
-
@klass.default_scope { @klass.where("title like '%foo%'") }
|
24
|
-
ActiveSupport::Deprecation.silence do
|
25
|
-
@klass.default_scope conditions: "title like '%omg%'"
|
26
|
-
end
|
27
|
-
|
28
|
-
@klass.all.map(&:id).must_equal [2]
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'works with a block that returns a hash' do
|
32
|
-
@klass.default_scope { { conditions: { id: 1 } } }
|
33
|
-
assert_deprecated { @klass.all.to_a }.map(&:id).must_equal [1]
|
34
|
-
end
|
35
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'dynamic_methods' do
|
4
|
-
before do
|
5
|
-
@posts = [
|
6
|
-
Post.create(title: 'foo', category: '1'),
|
7
|
-
Post.create(title: 'bar', category: '1'),
|
8
|
-
Post.create(title: 'bar', category: '2')
|
9
|
-
]
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
Post.delete_all
|
14
|
-
Comment.delete_all
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'supports find_all_by' do
|
18
|
-
assert_deprecated do
|
19
|
-
Post.find_all_by_title('bar').must_equal [@posts[1], @posts[2]]
|
20
|
-
Post.find_all_by_title_and_category('bar', '2').must_equal [@posts[2]]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'supports find_all_by with finder options' do
|
25
|
-
assert_deprecated do
|
26
|
-
Post.find_all_by_title('bar', conditions: { category: '1' }).must_equal [@posts[1]]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'supports find_last_by' do
|
31
|
-
assert_deprecated do
|
32
|
-
Post.find_last_by_title('foo').must_equal @posts[0]
|
33
|
-
Post.find_last_by_title('bar').must_equal @posts[2]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'supports find_last_by with finder options' do
|
38
|
-
assert_deprecated do
|
39
|
-
Post.find_last_by_title('bar', conditions: { category: '1' }).must_equal @posts[1]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'supports scoped_by' do
|
44
|
-
scope = assert_deprecated { Post.scoped_by_title('bar') }
|
45
|
-
scope.is_a?(ActiveRecord::Relation).must_equal true
|
46
|
-
scope.to_a.must_equal [@posts[1], @posts[2]]
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'supports find_or_initialize_by' do
|
50
|
-
assert_deprecated { Post.find_or_initialize_by_title_and_category('bar', '1').must_equal @posts[1] }
|
51
|
-
|
52
|
-
post = assert_deprecated { Post.find_or_initialize_by_title_and_category('bar', '3') }
|
53
|
-
post.new_record?.must_equal true
|
54
|
-
post.title.must_equal 'bar'
|
55
|
-
post.category.must_equal '3'
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'supports find_or_create_by' do
|
59
|
-
assert_deprecated { Post.find_or_create_by_title_and_category('bar', '1').must_equal @posts[1] }
|
60
|
-
|
61
|
-
post = assert_deprecated { Post.find_or_create_by_title_and_category('bar', '3') }
|
62
|
-
post.new_record?.must_equal false
|
63
|
-
post.title.must_equal 'bar'
|
64
|
-
post.category.must_equal '3'
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'supports find_or_create_by!' do
|
68
|
-
assert_deprecated { Post.find_or_create_by_title_and_category!('bar', '1').must_equal @posts[1] }
|
69
|
-
|
70
|
-
post = assert_deprecated { Post.find_or_create_by_title_and_category!('bar', '3') }
|
71
|
-
post.new_record?.must_equal false
|
72
|
-
post.title.must_equal 'bar'
|
73
|
-
post.category.must_equal '3'
|
74
|
-
|
75
|
-
klass = Class.new(ActiveRecord::Base)
|
76
|
-
def klass.name; 'Post'; end
|
77
|
-
klass.table_name = 'posts'
|
78
|
-
klass.validates_presence_of :category
|
79
|
-
|
80
|
-
lambda {
|
81
|
-
ActiveSupport::Deprecation.silence { klass.find_or_create_by_title!('z') }
|
82
|
-
}.must_raise ActiveRecord::RecordInvalid
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'supports find_by with finder options' do
|
86
|
-
assert_deprecated do
|
87
|
-
Post.find_by_title('bar', conditions: { category: '2' }).must_equal @posts[2]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'supports find_by! with finder options' do
|
92
|
-
assert_deprecated do
|
93
|
-
Post.find_by_title!('bar', conditions: { category: '2' }).must_equal @posts[2]
|
94
|
-
end
|
95
|
-
|
96
|
-
lambda {
|
97
|
-
assert_deprecated { Post.find_by_title!('bar', conditions: { category: '3' }) }
|
98
|
-
}.must_raise ActiveRecord::RecordNotFound
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'supports find_by with a block' do
|
102
|
-
assert_deprecated do
|
103
|
-
Post.find_by_title('foo') { |r| [r, 'block'] }.must_equal [@posts[0], 'block']
|
104
|
-
Post.find_by_title('baz') { |r| [r, 'block'] }.must_equal nil
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'supports find_by! with a block' do
|
109
|
-
assert_deprecated do
|
110
|
-
Post.find_by_title!('foo') { |r| [r, 'block'] }.must_equal [@posts[0], 'block']
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'adds to an association when find_or_initialize_by is called' do
|
115
|
-
post = @posts.first
|
116
|
-
comment = ActiveSupport::Deprecation.silence { post.comments.find_or_initialize_by_title('omg') }
|
117
|
-
post.comments.must_equal [comment]
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'adds to an association when find_or_create_by is called' do
|
121
|
-
post = @posts.first
|
122
|
-
post.comments.load_target
|
123
|
-
|
124
|
-
comment = ActiveSupport::Deprecation.silence { post.comments.find_or_create_by_title('omg') }
|
125
|
-
post.comments.must_equal [comment]
|
126
|
-
post.reload.comments.must_equal [comment]
|
127
|
-
end
|
128
|
-
|
129
|
-
it "doesn't mess with method_missing for non-find_or_{initialize|create}_by methods" do
|
130
|
-
post = @posts.first
|
131
|
-
post.comments.lol.must_equal 'lol'
|
132
|
-
end
|
133
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'find_in_batches' do
|
4
|
-
after do
|
5
|
-
Post.destroy_all
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'accepts finder options' do
|
9
|
-
foo = Post.create title: 'foo'
|
10
|
-
Post.create title: 'bar'
|
11
|
-
|
12
|
-
assert_deprecated do
|
13
|
-
Post.find_in_batches(conditions: "title = 'foo'") do |records|
|
14
|
-
records.must_equal [foo]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/test/finder_options_test.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'apply_finder_options' do
|
4
|
-
before do
|
5
|
-
@deprecation_behavior = ActiveSupport::Deprecation.behavior
|
6
|
-
ActiveSupport::Deprecation.behavior = :silence
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
ActiveSupport::Deprecation.behavior = @deprecation_behavior
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'is deprecated' do
|
14
|
-
assert_deprecated { Post.scoped.apply_finder_options(:conditions => 'foo') }
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'supports :conditions' do
|
18
|
-
scope = Post.scoped.apply_finder_options(:conditions => 'foo')
|
19
|
-
scope.where_values.must_equal ['foo']
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'supports :include' do
|
23
|
-
scope = Post.scoped.apply_finder_options(:include => :foo)
|
24
|
-
scope.includes_values.must_equal [:foo]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'supports :joins' do
|
28
|
-
scope = Post.scoped.apply_finder_options(:joins => :foo)
|
29
|
-
scope.joins_values.must_equal [:foo]
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'supports :limit' do
|
33
|
-
scope = Post.scoped.apply_finder_options(:limit => 5)
|
34
|
-
scope.limit_value.must_equal 5
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'supports :offset' do
|
38
|
-
scope = Post.scoped.apply_finder_options(:offset => 5)
|
39
|
-
scope.offset_value.must_equal 5
|
40
|
-
end
|
41
|
-
|
42
|
-
it "does not support :references (as it's new in 4.0)" do
|
43
|
-
lambda { Post.scoped.apply_finder_options(references: :foo) }.must_raise ArgumentError
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'supports :order' do
|
47
|
-
scope = Post.scoped.apply_finder_options(:order => 'foo')
|
48
|
-
scope.order_values.must_equal ['foo']
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'supports :select' do
|
52
|
-
scope = Post.scoped.apply_finder_options(:select => :foo)
|
53
|
-
scope.select_values.must_equal [:foo]
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'supports :readonly' do
|
57
|
-
scope = Post.scoped.apply_finder_options(:readonly => :foo)
|
58
|
-
scope.readonly_value.must_equal :foo
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'supports :group' do
|
62
|
-
scope = Post.scoped.apply_finder_options(:group => :foo)
|
63
|
-
scope.group_values.must_equal [:foo]
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'supports :having' do
|
67
|
-
scope = Post.scoped.apply_finder_options(:having => :foo)
|
68
|
-
scope.having_values.must_equal [:foo]
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'supports :from' do
|
72
|
-
scope = Post.scoped.apply_finder_options(:from => :foo)
|
73
|
-
scope.from_value.must_equal [:foo, nil]
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'supports :lock' do
|
77
|
-
scope = Post.scoped.apply_finder_options(:lock => true)
|
78
|
-
scope.lock_value.must_equal true
|
79
|
-
end
|
80
|
-
end
|
data/test/finder_test.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'finders' do
|
4
|
-
before do
|
5
|
-
@posts = 3.times.map { |i| Post.create id: i + 1 }
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
Post.delete_all
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'supports find(:all) with no options' do
|
13
|
-
assert_deprecated { Post.find(:all) }.must_equal @posts
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'supports find(:all) with options' do
|
17
|
-
assert_deprecated { Post.find(:all, conditions: 'id >= 2') }.must_equal [@posts[1], @posts[2]]
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'supports all with options' do
|
21
|
-
assert_deprecated { Post.all(conditions: 'id >= 2') }.must_equal [@posts[1], @posts[2]]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns an array from all when there are options' do
|
25
|
-
posts = ActiveSupport::Deprecation.silence { Post.all(conditions: 'id >= 2') }
|
26
|
-
posts.class.must_equal Array
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns a relation from all when there are no options' do
|
30
|
-
posts = Post.all
|
31
|
-
posts.is_a?(ActiveRecord::Relation).must_equal true
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'deprecates #all on a relation' do
|
35
|
-
relation = Post.where('id >= 2')
|
36
|
-
assert_deprecated { relation.all }.must_equal [@posts[1], @posts[2]]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'supports find(:first) with no options' do
|
40
|
-
assert_deprecated { Post.order(:id).find(:first) }.must_equal @posts.first
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'supports find(:first) with options' do
|
44
|
-
assert_deprecated { Post.order(:id).find(:first, conditions: 'id >= 2') }.must_equal @posts[1]
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'supports first with options' do
|
48
|
-
assert_deprecated { Post.order(:id).first(conditions: 'id >= 2') }.must_equal @posts[1]
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'supports find(:last) with no options' do
|
52
|
-
assert_deprecated { Post.order(:id).find(:last) }.must_equal @posts.last
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'supports find(:last) with options' do
|
56
|
-
assert_deprecated { Post.order(:id).find(:last, conditions: 'id <= 2') }.must_equal @posts[1]
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'supports last with options' do
|
60
|
-
assert_deprecated { Post.order(:id).last(conditions: 'id <= 2') }.must_equal @posts[1]
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'support find(1) etc with options' do
|
64
|
-
assert_deprecated do
|
65
|
-
Post.find(1, conditions: '1=1').must_equal Post.find(1)
|
66
|
-
lambda { Post.find(1, conditions: '0=1') }.must_raise(ActiveRecord::RecordNotFound)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'minitest/spec'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'active_record'
|
5
|
-
require 'active_record/deprecated_finders'
|
6
|
-
|
7
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
8
|
-
|
9
|
-
ActiveRecord::Schema.verbose = false
|
10
|
-
ActiveRecord::Schema.define do
|
11
|
-
create_table :posts do |t|
|
12
|
-
t.string :title
|
13
|
-
t.string :category
|
14
|
-
end
|
15
|
-
|
16
|
-
create_table :comments do |t|
|
17
|
-
t.string :title
|
18
|
-
t.references :post
|
19
|
-
end
|
20
|
-
|
21
|
-
create_table :appointments do |t|
|
22
|
-
t.integer :physician_id
|
23
|
-
t.integer :patient_id
|
24
|
-
t.string :week_day
|
25
|
-
t.string :status
|
26
|
-
end
|
27
|
-
|
28
|
-
create_table :physicians do |t|
|
29
|
-
t.string :name
|
30
|
-
end
|
31
|
-
|
32
|
-
create_table :patients do |t|
|
33
|
-
t.string :name
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Post < ActiveRecord::Base
|
38
|
-
has_many :comments
|
39
|
-
end
|
40
|
-
|
41
|
-
class Comment < ActiveRecord::Base
|
42
|
-
def self.lol
|
43
|
-
"lol"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Appointment < ActiveRecord::Base
|
48
|
-
belongs_to :physician
|
49
|
-
belongs_to :patient
|
50
|
-
end
|
51
|
-
|
52
|
-
class Patient < ActiveRecord::Base
|
53
|
-
def self.find_by_custom_name
|
54
|
-
[]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class Physician < ActiveRecord::Base
|
59
|
-
has_many :appointments
|
60
|
-
has_many :patients, through: :appointments
|
61
|
-
end
|
62
|
-
|
63
|
-
require 'active_support/testing/deprecation'
|
64
|
-
ActiveSupport::Deprecation.debug = true
|
65
|
-
|
66
|
-
class MiniTest::Spec
|
67
|
-
include ActiveSupport::Testing::Deprecation
|
68
|
-
end
|
data/test/scope_test.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'scope' do
|
4
|
-
before do
|
5
|
-
@klass = Class.new(ActiveRecord::Base)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'supports a finder hash' do
|
9
|
-
assert_deprecated { @klass.scope :foo, conditions: :foo }
|
10
|
-
@klass.foo.where_values.must_equal [:foo]
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'supports a finder hash inside a callable' do
|
14
|
-
@klass.scope :foo, ->(v) { { conditions: v } }
|
15
|
-
assert_deprecated { @klass.foo(:bar) }.where_values.must_equal [:bar]
|
16
|
-
end
|
17
|
-
end
|
data/test/scoped_test.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'scoped' do
|
4
|
-
it 'accepts a deprecated conditions option' do
|
5
|
-
assert_deprecated { Post.scoped(conditions: :foo) }.where_values.must_equal [:foo]
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'accepts a deprecated include option' do
|
9
|
-
assert_deprecated { Post.scoped(include: :foo) }.includes_values.must_equal [:foo]
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'is deprecated' do
|
13
|
-
assert_deprecated { Post.scoped }
|
14
|
-
end
|
15
|
-
end
|
data/test/update_all_test.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'update_all' do
|
4
|
-
after do
|
5
|
-
Post.destroy_all
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'supports conditions' do
|
9
|
-
foo = Post.create title: 'foo'
|
10
|
-
bar = Post.create title: 'bar'
|
11
|
-
|
12
|
-
assert_deprecated { Post.update_all({ title: 'omg' }, title: 'foo') }
|
13
|
-
|
14
|
-
foo.reload.title.must_equal 'omg'
|
15
|
-
bar.reload.title.must_equal 'bar'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'supports limit and order' do
|
19
|
-
posts = 3.times.map { Post.create }
|
20
|
-
assert_deprecated { Post.update_all({ title: 'omg' }, nil, limit: 2, order: :id) }
|
21
|
-
|
22
|
-
posts.each(&:reload).map(&:title).must_equal ['omg', 'omg', nil]
|
23
|
-
end
|
24
|
-
end
|
data/test/with_scope_test.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'with_scope' do
|
4
|
-
before do
|
5
|
-
Post.create(id: 1, title: 'foo')
|
6
|
-
Post.create(id: 2, title: 'bar')
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Post.delete_all
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'applies a scoping' do
|
14
|
-
assert_deprecated do
|
15
|
-
Post.with_scope(find: { conditions: { title: 'foo' } }) do
|
16
|
-
assert_equal [1], Post.all.map(&:id)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'applies an exclusive scoping' do
|
22
|
-
ActiveSupport::Deprecation.silence do
|
23
|
-
Post.with_scope(find: { conditions: { title: 'foo' } }) do
|
24
|
-
Post.send(:with_exclusive_scope, find: { conditions: { title: 'bar' } }) do
|
25
|
-
assert_equal [2], Post.all.map(&:id)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'gives a deprecation for #with_exclusive_scope' do
|
32
|
-
assert_deprecated do
|
33
|
-
Post.send(:with_exclusive_scope) {}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|