deferring 0.4.1 → 0.7.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
- SHA1:
3
- metadata.gz: 09743f4e4060ead2be2023679342fc743df00ab5
4
- data.tar.gz: 0456cba25010e1592bcd4fbd30be9eda0b5392d0
2
+ SHA256:
3
+ metadata.gz: 35b9b80d6c94a8b980f80cd953565bcf7cf2f8a207de3880904286e617ed30a0
4
+ data.tar.gz: f78c5caa4d9c1a5a446ac504c839bebf21e29a059e57e5739de4ef5842106b63
5
5
  SHA512:
6
- metadata.gz: 1b61a7fc3a401fab399394dc0a3d4c7fe38385fac08028cedf9e55e253859540745adb5a139d6e87615dcee6903eb338bd54bf4b8b499626b5daf5951b3efc6d
7
- data.tar.gz: 98d4e256dcc2370e08ba937152de55cbdf5737dde75641ce0c6aafc3fb1e8fdfa2a9e9a49db8e0d32ba0842fe7d86b0832cadac3408588d735bf176e54c892a5
6
+ metadata.gz: af8785f36ce8551ba95a9f7dab9d28fdfc8cd46bc6a427bddc70007985225ce3edd23daf1c1cdd21f5102d1c3bef0d2a0ae2598752b0fa38318225235db8a9e4
7
+ data.tar.gz: 549c445412012809bdbe613dd028395acc22ef4dc5e26fc803fc2db5734a2f7b26fc4c134693c6fae5147e6bb7d83d7b4afde8eed25719ef57ea47af3232c4d5
@@ -1,29 +1,26 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.3.0
5
- - 2.3.3
6
- - 2.4.0
7
- - ruby-head
4
+ - 2.3.8
5
+ - 2.4.6
6
+ - 2.5.5
7
+ - 2.6.3
8
+ - 2.7.1
8
9
 
9
10
  gemfile:
10
- - gemfiles/rails_40.gemfile
11
- - gemfiles/rails_41.gemfile
12
11
  - gemfiles/rails_42.gemfile
13
12
  - gemfiles/rails_50.gemfile
14
13
  - gemfiles/rails_51.gemfile
14
+ - gemfiles/rails_52.gemfile
15
+ - gemfiles/rails_60.gemfile
15
16
 
16
17
  sudo: false
17
18
 
18
- matrix:
19
- allow_failures:
20
- - rvm: ruby-head
21
- gemfile: gemfiles/rails_40.gemfile
22
- - rvm: ruby-head
23
- gemfile: gemfiles/rails_41.gemfile
24
- - rvm: 2.4.0
25
- gemfile: gemfiles/rails_40.gemfile
26
- - rvm: 2.4.0
27
- gemfile: gemfiles/rails_41.gemfile
28
-
29
19
  script: 'bundle exec rake'
20
+
21
+ matrix:
22
+ exclude:
23
+ - rvm: 2.3.8
24
+ gemfile: gemfiles/rails_60.gemfile
25
+ - rvm: 2.4.6
26
+ gemfile: gemfiles/rails_60.gemfile
data/Appraisals CHANGED
@@ -1,19 +1,24 @@
1
- appraise 'rails-40' do
2
- gem 'activerecord', '4.0.13'
1
+ appraise 'rails-42' do
2
+ gem 'activerecord', '4.2.11.3'
3
+ gem 'sqlite3', '~> 1.3.6'
3
4
  end
4
5
 
5
- appraise 'rails-41' do
6
- gem 'activerecord', '4.1.15'
6
+ appraise 'rails-50' do
7
+ gem 'activerecord', '5.0.7.2'
8
+ gem 'sqlite3', '~> 1.3.6'
7
9
  end
8
10
 
9
- appraise 'rails-42' do
10
- gem 'activerecord', '4.2.8'
11
+ appraise 'rails-51' do
12
+ gem 'activerecord', '5.1.7'
13
+ gem 'sqlite3'
11
14
  end
12
15
 
13
- appraise 'rails-50' do
14
- gem 'activerecord', '5.0.2'
16
+ appraise 'rails-52' do
17
+ gem 'activerecord', '5.2.4.3'
18
+ gem 'sqlite3'
15
19
  end
16
20
 
17
- appraise 'rails-51' do
18
- gem 'activerecord', '5.1.4'
21
+ appraise 'rails-60' do
22
+ gem 'activerecord', '6.0.3.2'
23
+ gem 'sqlite3'
19
24
  end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Robin Roestenburg
1
+ Copyright (c) 2019 Robin Roestenburg
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  Deferring makes it possible to delay saving ActiveRecord associations until the
7
7
  parent object has been saved.
8
8
 
9
- Currently supporting Rails 4.x, 5.0 & 5.1 on MRI Ruby 2.3+.
9
+ Currently supporting Rails 4.2, 5.0, 5.1 & 5.2 on MRI Ruby 2.3+.
10
10
 
11
11
  It is important to note that Deferring does not touch the original `has_many`
12
12
  and `has_and_belongs_to_many` associations. You can use them, without worrying
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'deferring/version'
@@ -21,11 +20,10 @@ Gem::Specification.new do |spec|
21
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
21
  spec.require_paths = ['lib']
23
22
 
24
- spec.add_dependency 'activerecord', '> 4.0'
23
+ spec.add_dependency 'activerecord', ['>= 4.2']
25
24
 
26
25
  spec.add_development_dependency 'bundler', '~> 1.3'
27
26
  spec.add_development_dependency 'rake'
28
27
  spec.add_development_dependency 'rspec'
29
- spec.add_development_dependency 'sqlite3'
30
28
  spec.add_development_dependency 'appraisal'
31
29
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.2.8"
5
+ gem "activerecord", "4.2.11.3"
6
+ gem "sqlite3", "~> 1.3.6"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,64 +1,66 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- deferring (0.4.0)
5
- activerecord (> 4.0)
4
+ deferring (0.7.0)
5
+ activerecord (>= 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (4.2.8)
11
- activesupport (= 4.2.8)
10
+ activemodel (4.2.11.3)
11
+ activesupport (= 4.2.11.3)
12
12
  builder (~> 3.1)
13
- activerecord (4.2.8)
14
- activemodel (= 4.2.8)
15
- activesupport (= 4.2.8)
13
+ activerecord (4.2.11.3)
14
+ activemodel (= 4.2.11.3)
15
+ activesupport (= 4.2.11.3)
16
16
  arel (~> 6.0)
17
- activesupport (4.2.8)
17
+ activesupport (4.2.11.3)
18
18
  i18n (~> 0.7)
19
19
  minitest (~> 5.1)
20
20
  thread_safe (~> 0.3, >= 0.3.4)
21
21
  tzinfo (~> 1.1)
22
- appraisal (2.1.0)
22
+ appraisal (2.3.0)
23
23
  bundler
24
24
  rake
25
25
  thor (>= 0.14.0)
26
26
  arel (6.0.4)
27
- builder (3.2.3)
28
- diff-lcs (1.3)
29
- i18n (0.8.1)
30
- minitest (5.10.1)
31
- rake (12.0.0)
32
- rspec (3.5.0)
33
- rspec-core (~> 3.5.0)
34
- rspec-expectations (~> 3.5.0)
35
- rspec-mocks (~> 3.5.0)
36
- rspec-core (3.5.4)
37
- rspec-support (~> 3.5.0)
38
- rspec-expectations (3.5.0)
27
+ builder (3.2.4)
28
+ concurrent-ruby (1.1.6)
29
+ diff-lcs (1.4.4)
30
+ i18n (0.9.5)
31
+ concurrent-ruby (~> 1.0)
32
+ minitest (5.14.1)
33
+ rake (13.0.1)
34
+ rspec (3.9.0)
35
+ rspec-core (~> 3.9.0)
36
+ rspec-expectations (~> 3.9.0)
37
+ rspec-mocks (~> 3.9.0)
38
+ rspec-core (3.9.2)
39
+ rspec-support (~> 3.9.3)
40
+ rspec-expectations (3.9.2)
39
41
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.5.0)
41
- rspec-mocks (3.5.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-mocks (3.9.1)
42
44
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.5.0)
44
- rspec-support (3.5.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-support (3.9.3)
45
47
  sqlite3 (1.3.13)
46
- thor (0.19.4)
48
+ thor (1.0.1)
47
49
  thread_safe (0.3.6)
48
- tzinfo (1.2.2)
50
+ tzinfo (1.2.7)
49
51
  thread_safe (~> 0.1)
50
52
 
51
53
  PLATFORMS
52
54
  ruby
53
55
 
54
56
  DEPENDENCIES
55
- activerecord (= 4.2.8)
57
+ activerecord (= 4.2.11.3)
56
58
  appraisal
57
59
  bundler (~> 1.3)
58
60
  deferring!
59
61
  rake
60
62
  rspec
61
- sqlite3
63
+ sqlite3 (~> 1.3.6)
62
64
 
63
65
  BUNDLED WITH
64
- 1.13.0
66
+ 1.17.3
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "5.0.2"
5
+ gem "activerecord", "5.0.7.2"
6
+ gem "sqlite3", "~> 1.3.6"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,63 +1,64 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- deferring (0.4.0)
5
- activerecord (> 4.0)
4
+ deferring (0.7.0)
5
+ activerecord (>= 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.0.2)
11
- activesupport (= 5.0.2)
12
- activerecord (5.0.2)
13
- activemodel (= 5.0.2)
14
- activesupport (= 5.0.2)
10
+ activemodel (5.0.7.2)
11
+ activesupport (= 5.0.7.2)
12
+ activerecord (5.0.7.2)
13
+ activemodel (= 5.0.7.2)
14
+ activesupport (= 5.0.7.2)
15
15
  arel (~> 7.0)
16
- activesupport (5.0.2)
16
+ activesupport (5.0.7.2)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
18
+ i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
- appraisal (2.1.0)
21
+ appraisal (2.3.0)
22
22
  bundler
23
23
  rake
24
24
  thor (>= 0.14.0)
25
25
  arel (7.1.4)
26
- concurrent-ruby (1.0.5)
27
- diff-lcs (1.3)
28
- i18n (0.8.1)
29
- minitest (5.10.1)
30
- rake (12.0.0)
31
- rspec (3.5.0)
32
- rspec-core (~> 3.5.0)
33
- rspec-expectations (~> 3.5.0)
34
- rspec-mocks (~> 3.5.0)
35
- rspec-core (3.5.4)
36
- rspec-support (~> 3.5.0)
37
- rspec-expectations (3.5.0)
26
+ concurrent-ruby (1.1.6)
27
+ diff-lcs (1.4.4)
28
+ i18n (1.8.3)
29
+ concurrent-ruby (~> 1.0)
30
+ minitest (5.14.1)
31
+ rake (13.0.1)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.2)
37
+ rspec-support (~> 3.9.3)
38
+ rspec-expectations (3.9.2)
38
39
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.5.0)
40
- rspec-mocks (3.5.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.1)
41
42
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.5.0)
43
- rspec-support (3.5.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.3)
44
45
  sqlite3 (1.3.13)
45
- thor (0.19.4)
46
+ thor (1.0.1)
46
47
  thread_safe (0.3.6)
47
- tzinfo (1.2.2)
48
+ tzinfo (1.2.7)
48
49
  thread_safe (~> 0.1)
49
50
 
50
51
  PLATFORMS
51
52
  ruby
52
53
 
53
54
  DEPENDENCIES
54
- activerecord (= 5.0.2)
55
+ activerecord (= 5.0.7.2)
55
56
  appraisal
56
57
  bundler (~> 1.3)
57
58
  deferring!
58
59
  rake
59
60
  rspec
60
- sqlite3
61
+ sqlite3 (~> 1.3.6)
61
62
 
62
63
  BUNDLED WITH
63
- 1.13.0
64
+ 1.17.3
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "5.1.4"
5
+ gem "activerecord", "5.1.7"
6
+ gem "sqlite3"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -1,58 +1,58 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- deferring (0.4.0)
5
- activerecord (> 4.0)
4
+ deferring (0.7.0)
5
+ activerecord (>= 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.1.4)
11
- activesupport (= 5.1.4)
12
- activerecord (5.1.4)
13
- activemodel (= 5.1.4)
14
- activesupport (= 5.1.4)
10
+ activemodel (5.1.7)
11
+ activesupport (= 5.1.7)
12
+ activerecord (5.1.7)
13
+ activemodel (= 5.1.7)
14
+ activesupport (= 5.1.7)
15
15
  arel (~> 8.0)
16
- activesupport (5.1.4)
16
+ activesupport (5.1.7)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
18
+ i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
- appraisal (2.2.0)
21
+ appraisal (2.3.0)
22
22
  bundler
23
23
  rake
24
24
  thor (>= 0.14.0)
25
25
  arel (8.0.0)
26
- concurrent-ruby (1.0.5)
27
- diff-lcs (1.3)
28
- i18n (0.9.1)
26
+ concurrent-ruby (1.1.6)
27
+ diff-lcs (1.4.4)
28
+ i18n (1.8.3)
29
29
  concurrent-ruby (~> 1.0)
30
- minitest (5.10.3)
31
- rake (12.3.0)
32
- rspec (3.7.0)
33
- rspec-core (~> 3.7.0)
34
- rspec-expectations (~> 3.7.0)
35
- rspec-mocks (~> 3.7.0)
36
- rspec-core (3.7.0)
37
- rspec-support (~> 3.7.0)
38
- rspec-expectations (3.7.0)
30
+ minitest (5.14.1)
31
+ rake (13.0.1)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.2)
37
+ rspec-support (~> 3.9.3)
38
+ rspec-expectations (3.9.2)
39
39
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.7.0)
41
- rspec-mocks (3.7.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.1)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.7.0)
44
- rspec-support (3.7.0)
45
- sqlite3 (1.3.13)
46
- thor (0.20.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.3)
45
+ sqlite3 (1.4.2)
46
+ thor (1.0.1)
47
47
  thread_safe (0.3.6)
48
- tzinfo (1.2.4)
48
+ tzinfo (1.2.7)
49
49
  thread_safe (~> 0.1)
50
50
 
51
51
  PLATFORMS
52
52
  ruby
53
53
 
54
54
  DEPENDENCIES
55
- activerecord (= 5.1.4)
55
+ activerecord (= 5.1.7)
56
56
  appraisal
57
57
  bundler (~> 1.3)
58
58
  deferring!
@@ -61,4 +61,4 @@ DEPENDENCIES
61
61
  sqlite3
62
62
 
63
63
  BUNDLED WITH
64
- 1.13.0
64
+ 1.17.3
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.0.13"
5
+ gem "activerecord", "5.2.4.3"
6
+ gem "sqlite3"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ deferring (0.7.0)
5
+ activerecord (>= 4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.4.3)
11
+ activesupport (= 5.2.4.3)
12
+ activerecord (5.2.4.3)
13
+ activemodel (= 5.2.4.3)
14
+ activesupport (= 5.2.4.3)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.4.3)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (9.0.0)
26
+ concurrent-ruby (1.1.6)
27
+ diff-lcs (1.4.4)
28
+ i18n (1.8.3)
29
+ concurrent-ruby (~> 1.0)
30
+ minitest (5.14.1)
31
+ rake (13.0.1)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.2)
37
+ rspec-support (~> 3.9.3)
38
+ rspec-expectations (3.9.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.3)
45
+ sqlite3 (1.4.2)
46
+ thor (1.0.1)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.7)
49
+ thread_safe (~> 0.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activerecord (= 5.2.4.3)
56
+ appraisal
57
+ bundler (~> 1.3)
58
+ deferring!
59
+ rake
60
+ rspec
61
+ sqlite3
62
+
63
+ BUNDLED WITH
64
+ 1.17.3
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.1.15"
5
+ gem "activerecord", "6.0.3.2"
6
+ gem "sqlite3"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ deferring (0.7.0)
5
+ activerecord (>= 4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.0.3.2)
11
+ activesupport (= 6.0.3.2)
12
+ activerecord (6.0.3.2)
13
+ activemodel (= 6.0.3.2)
14
+ activesupport (= 6.0.3.2)
15
+ activesupport (6.0.3.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ concurrent-ruby (1.1.6)
26
+ diff-lcs (1.4.4)
27
+ i18n (1.8.3)
28
+ concurrent-ruby (~> 1.0)
29
+ minitest (5.14.1)
30
+ rake (13.0.1)
31
+ rspec (3.9.0)
32
+ rspec-core (~> 3.9.0)
33
+ rspec-expectations (~> 3.9.0)
34
+ rspec-mocks (~> 3.9.0)
35
+ rspec-core (3.9.2)
36
+ rspec-support (~> 3.9.3)
37
+ rspec-expectations (3.9.2)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-mocks (3.9.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-support (3.9.3)
44
+ sqlite3 (1.4.2)
45
+ thor (1.0.1)
46
+ thread_safe (0.3.6)
47
+ tzinfo (1.2.7)
48
+ thread_safe (~> 0.1)
49
+ zeitwerk (2.3.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activerecord (= 6.0.3.2)
56
+ appraisal
57
+ bundler (~> 1.3)
58
+ deferring!
59
+ rake
60
+ rspec
61
+ sqlite3
62
+
63
+ BUNDLED WITH
64
+ 1.17.3
@@ -26,14 +26,14 @@ module Deferring
26
26
  alias_method :pretty_inspect, :inspect
27
27
 
28
28
  delegate :to_s, :to_a, :inspect, :==, # methods undefined by SimpleDelegator
29
- :is_a?, :as_json, to: :objects
29
+ :as_json, to: :objects
30
30
 
31
31
  def each(&block)
32
32
  objects.each(&block)
33
33
  end
34
34
 
35
35
  # TODO: Add explanation about :first/:last loaded? problem.
36
- [:first, :last].each do |method|
36
+ [:first, :last, :empty?, :size].each do |method|
37
37
  define_method method do
38
38
  unless objects_loaded?
39
39
  original_association.send(method)
@@ -46,7 +46,8 @@ module Deferring
46
46
  # Delegates methods from Ruby's Array module to the object in the deferred
47
47
  # association.
48
48
  delegate :[]=, :[], :clear, :select!, :reject!, :flatten, :flatten!, :sort!,
49
- :keep_if, :delete_if, :sort_by!, :empty?, :size, :length,
49
+ :keep_if, :delete_if, :sort_by!, :length,
50
+ :each_index,
50
51
  to: :objects
51
52
 
52
53
  # Delegates Ruby's Enumerable#find method to the original association.
@@ -57,6 +58,14 @@ module Deferring
57
58
  original_association.find(*args)
58
59
  end
59
60
 
61
+ # Delegates Ruby's Enumerable#count method to the original association.
62
+ #
63
+ # The delegation has to be explicit in this case, because the inclusion of
64
+ # Enumerable also defines the count-method on DeferredAssociation.
65
+ def count(*args)
66
+ original_association.count(*args)
67
+ end
68
+
60
69
  # Delegates Ruby's Enumerable#select method to the original association when
61
70
  # no block has been given. Rails' select-method does not accept a block, so
62
71
  # we know that in that case the select-method has to be called on our
@@ -64,9 +73,9 @@ module Deferring
64
73
  #
65
74
  # The delegation has to be explicit in this case, because the inclusion of
66
75
  # Enumerable also defines the select-method on DeferredAssociation.
67
- def select(value = Proc.new)
76
+ def select(value = nil, &block)
68
77
  if block_given?
69
- objects.select { |*block_args| value.call(*block_args) }
78
+ objects.select { |*block_args| block.call(*block_args) }
70
79
  else
71
80
  original_association.select(value)
72
81
  end
@@ -131,7 +140,7 @@ module Deferring
131
140
  def destroy(*records)
132
141
  records.flatten.compact.uniq.each do |record|
133
142
  record = record.to_i if record.is_a? String
134
- record = objects.detect { |o| o.id == record } if record.is_a? Fixnum
143
+ record = objects.detect { |o| o.id == record } if record.is_a? Integer
135
144
 
136
145
  run_deferring_callbacks(:unlink, record) {
137
146
  objects.delete(record)
@@ -1,3 +1,3 @@
1
1
  module Deferring
2
- VERSION = '0.4.1'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -377,6 +377,19 @@ RSpec.describe 'deferred has_and_belongs_to_many associations' do
377
377
  end
378
378
  end
379
379
 
380
+ describe 'supports methods from Ruby Array' do
381
+ describe '#each_index' do
382
+ it 'returns the index of each element in the association' do
383
+ bob.teams << dba << support
384
+ bob.save!
385
+
386
+ result = []
387
+ bob.teams.each_index { |i| result << i }
388
+ expect(result).to eq([0, 1])
389
+ end
390
+ end
391
+ end
392
+
380
393
  describe 'enumerable methods that conflict with ActiveRecord' do
381
394
  describe '#select' do
382
395
  before do
@@ -359,6 +359,58 @@ RSpec.describe 'deferred has_many associations' do
359
359
  people = Person.all
360
360
  expect(people[1].issues.loaded?).to be_falsey
361
361
  end
362
+
363
+ describe 'count' do
364
+ it 'should not load the association' do
365
+ person = Person.where(name: 'Bob').first
366
+ expect(person.issues.count).to eq(2)
367
+ expect(person.issues.loaded?).to be_falsey
368
+ end
369
+
370
+ it 'should execute a count(*) query, even if the association has already been loaded' do
371
+ person = Person.where(name: 'Bob').first
372
+ expect { person.issues.count }.to query(1) { |sql| expect(sql).to include('SELECT COUNT(*) FROM "issues"') }
373
+ expect { person.issues.to_a }.to query(1)
374
+ expect(person.issues.loaded?).to be_truthy
375
+ expect { person.issues.to_a }.to query(0)
376
+ expect { person.issues.count }.to query(1) { |sql| expect(sql).to include('SELECT COUNT(*) FROM "issues"') }
377
+ end
378
+ end
379
+
380
+ describe 'size' do
381
+ it 'should not load the association' do
382
+ person = Person.where(name: 'Bob').first
383
+ expect(person.issues.size).to eq(2)
384
+ expect { person.issues.size }.to query(1) { |sql| expect(sql).to include('SELECT COUNT(*) FROM "issues"') }
385
+ expect(person.issues.loaded?).to be_falsey
386
+ end
387
+
388
+ it 'should not execute query when the association has already been loaded' do
389
+ person = Person.where(name: 'Bob').first
390
+ expect { person.issues.size }.to query(1) { |sql| expect(sql).to include('SELECT COUNT(*) FROM "issues"') }
391
+ expect { person.issues.to_a }.to query(1)
392
+ expect(person.issues.loaded?).to be_truthy
393
+ expect { person.issues.to_a }.to query(0)
394
+ expect { person.issues.size }.to query(0)
395
+ end
396
+ end
397
+
398
+ describe 'empty?' do
399
+ it 'should not load the association' do
400
+ person = Person.where(name: 'Bob').first
401
+ expect(person.issues.empty?).to be_falsey
402
+ expect(person.issues.loaded?).to be_falsey
403
+ end
404
+
405
+ it 'should not execute query when the association has already been loaded' do
406
+ person = Person.where(name: 'Bob').first
407
+ expect { person.issues.empty? }.to query(1) { |sql| expect(sql).to include('SELECT 1') }
408
+ expect { person.issues.to_a }.to query(1)
409
+ expect(person.issues.loaded?).to be_truthy
410
+ expect { person.issues.to_a }.to query(0)
411
+ expect { person.issues.empty? }.to query(0)
412
+ end
413
+ end
362
414
  end # preloading associations
363
415
 
364
416
  describe 'active record api' do
@@ -5,6 +5,7 @@ require 'support/models/team'
5
5
  require 'support/models/issue'
6
6
  require 'support/models/address'
7
7
  require 'support/models/non_validated_issue'
8
+ require 'support/matchers/query_matcher'
8
9
 
9
10
  RSpec.configure do |config|
10
11
  config.disable_monkey_patching!
@@ -18,6 +19,8 @@ RSpec.configure do |config|
18
19
  # --seed 1234
19
20
  config.order = 'random'
20
21
 
22
+ config.include(Deferring::Matchers)
23
+
21
24
  # Rollback all the database changes after each spec, poor man's
22
25
  # DatabaseCleaner :-)
23
26
  config.around do |example|
@@ -0,0 +1,127 @@
1
+ module Deferring
2
+ module Matchers
3
+
4
+ class ArQuery #:nodoc:
5
+ cattr_accessor :executed
6
+
7
+ @@recording_queries = false
8
+ def self.recording_queries?
9
+ @@recording_queries
10
+ end
11
+
12
+ def initialize(expected, &block)
13
+ @expected = expected
14
+ @block = block
15
+ end
16
+
17
+ def matches?(given_proc)
18
+ @eval_block = false
19
+ @eval_error = nil
20
+ ArQuery.executed = []
21
+ @@recording_queries = true
22
+
23
+ given_proc.call
24
+
25
+ if @expected.is_a?(Integer)
26
+ @actual = ArQuery.executed.length
27
+ @matched = @actual == @expected
28
+ else
29
+ @actual = ArQuery.executed.detect { |sql| @expected === sql }
30
+ @matched = !@actual.nil?
31
+ end
32
+
33
+ eval_block if @block && @matched && !negative_expectation?
34
+
35
+ ensure
36
+ ArQuery.executed = nil
37
+ @@recording_queries = false
38
+ return @matched && @eval_error.nil?
39
+ end
40
+
41
+ def eval_block
42
+ @eval_block = true
43
+ begin
44
+ @block[ArQuery.executed]
45
+ rescue => err
46
+ @eval_error = err
47
+ end
48
+ end
49
+
50
+ def supports_block_expectations?
51
+ true
52
+ end
53
+
54
+ def failure_message
55
+ if @eval_error
56
+ @eval_error.message
57
+ elsif @expected.is_a?(Integer)
58
+ "expected #{@expected}, got #{@actual}"
59
+ else
60
+ "expected to execute a query with pattern #{@expected.inspect}, but it wasn't"
61
+ end
62
+ end
63
+
64
+ def failure_message_when_negated
65
+ if @expected.is_a?(Integer)
66
+ "did not expect #{@expected}"
67
+ else
68
+ "did not expect to execute a query with pattern #{@expected.inspect}, but it was executed"
69
+ end
70
+ end
71
+
72
+ def description
73
+ if @expected.is_a?(Integer)
74
+ @expected == 1 ? 'execute 1 query' : "execute #{@expected} queries"
75
+ else
76
+ "execute query with pattern #{@expected.inspect}"
77
+ end
78
+ end
79
+
80
+ def negative_expectation?
81
+ @negative_expectation ||= !caller.first(3).find { |s| s =~ /should_not/ }.nil?
82
+ end
83
+ end
84
+
85
+ def query(expected = 1, &block)
86
+ ArQuery.new(expected, &block)
87
+ end
88
+ end
89
+ end
90
+
91
+ # For Rails 6.0
92
+ module ActiveRecord
93
+ module ConnectionAdapters
94
+ module SQLite3
95
+ module DatabaseStatements
96
+ [:exec_query, :exec, :execute].each do |method|
97
+ if respond_to?(method)
98
+ define_method("#{method}_with_query_record") do |sql, *args|
99
+ Deferring::Matchers::ArQuery.executed << sql if Deferring::Matchers::ArQuery.recording_queries?
100
+ send("#{method}_without_query_record", sql, *args)
101
+ end
102
+
103
+ alias_method :"#{method}_without_query_record", method
104
+ alias_method method, :"#{method}_with_query_record"
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ # For previous versions of Rails
113
+ module ActiveRecord
114
+ module ConnectionAdapters
115
+ class SQLite3Adapter
116
+ [:exec_query, :exec, :execute].each do |method|
117
+ define_method("#{method}_with_query_record") do |sql, *args|
118
+ Deferring::Matchers::ArQuery.executed << sql if Deferring::Matchers::ArQuery.recording_queries?
119
+ send("#{method}_without_query_record", sql, *args)
120
+ end
121
+
122
+ alias_method :"#{method}_without_query_record", method
123
+ alias_method method, :"#{method}_with_query_record"
124
+ end
125
+ end
126
+ end
127
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deferring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Roestenburg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: sqlite3
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: appraisal
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -111,16 +97,16 @@ files:
111
97
  - README.md
112
98
  - Rakefile
113
99
  - deferring.gemspec
114
- - gemfiles/rails_40.gemfile
115
- - gemfiles/rails_40.gemfile.lock
116
- - gemfiles/rails_41.gemfile
117
- - gemfiles/rails_41.gemfile.lock
118
100
  - gemfiles/rails_42.gemfile
119
101
  - gemfiles/rails_42.gemfile.lock
120
102
  - gemfiles/rails_50.gemfile
121
103
  - gemfiles/rails_50.gemfile.lock
122
104
  - gemfiles/rails_51.gemfile
123
105
  - gemfiles/rails_51.gemfile.lock
106
+ - gemfiles/rails_52.gemfile
107
+ - gemfiles/rails_52.gemfile.lock
108
+ - gemfiles/rails_60.gemfile
109
+ - gemfiles/rails_60.gemfile.lock
124
110
  - lib/deferring.rb
125
111
  - lib/deferring/deferred_association.rb
126
112
  - lib/deferring/deferred_callback_listener.rb
@@ -130,6 +116,7 @@ files:
130
116
  - spec/lib/deferring_nested_attributes_spec.rb
131
117
  - spec/spec_helper.rb
132
118
  - spec/support/active_record.rb
119
+ - spec/support/matchers/query_matcher.rb
133
120
  - spec/support/models/address.rb
134
121
  - spec/support/models/issue.rb
135
122
  - spec/support/models/non_validated_issue.rb
@@ -155,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
142
  version: '0'
156
143
  requirements: []
157
144
  rubyforge_project:
158
- rubygems_version: 2.5.1
145
+ rubygems_version: 2.7.6.2
159
146
  signing_key:
160
147
  specification_version: 4
161
148
  summary: Defer saving ActiveRecord associations until parent is saved
@@ -165,9 +152,9 @@ test_files:
165
152
  - spec/lib/deferring_nested_attributes_spec.rb
166
153
  - spec/spec_helper.rb
167
154
  - spec/support/active_record.rb
155
+ - spec/support/matchers/query_matcher.rb
168
156
  - spec/support/models/address.rb
169
157
  - spec/support/models/issue.rb
170
158
  - spec/support/models/non_validated_issue.rb
171
159
  - spec/support/models/person.rb
172
160
  - spec/support/models/team.rb
173
- has_rdoc:
@@ -1,67 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- deferring (0.4.0)
5
- activerecord (> 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.0.13)
11
- activesupport (= 4.0.13)
12
- builder (~> 3.1.0)
13
- activerecord (4.0.13)
14
- activemodel (= 4.0.13)
15
- activerecord-deprecated_finders (~> 1.0.2)
16
- activesupport (= 4.0.13)
17
- arel (~> 4.0.0)
18
- activerecord-deprecated_finders (1.0.4)
19
- activesupport (4.0.13)
20
- i18n (~> 0.6, >= 0.6.9)
21
- minitest (~> 4.2)
22
- multi_json (~> 1.3)
23
- thread_safe (~> 0.1)
24
- tzinfo (~> 0.3.37)
25
- appraisal (2.1.0)
26
- bundler
27
- rake
28
- thor (>= 0.14.0)
29
- arel (4.0.2)
30
- builder (3.1.4)
31
- diff-lcs (1.3)
32
- i18n (0.8.1)
33
- minitest (4.7.5)
34
- multi_json (1.12.1)
35
- rake (12.0.0)
36
- rspec (3.5.0)
37
- rspec-core (~> 3.5.0)
38
- rspec-expectations (~> 3.5.0)
39
- rspec-mocks (~> 3.5.0)
40
- rspec-core (3.5.4)
41
- rspec-support (~> 3.5.0)
42
- rspec-expectations (3.5.0)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.5.0)
45
- rspec-mocks (3.5.0)
46
- diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.5.0)
48
- rspec-support (3.5.0)
49
- sqlite3 (1.3.13)
50
- thor (0.19.4)
51
- thread_safe (0.3.6)
52
- tzinfo (0.3.52)
53
-
54
- PLATFORMS
55
- ruby
56
-
57
- DEPENDENCIES
58
- activerecord (= 4.0.13)
59
- appraisal
60
- bundler (~> 1.3)
61
- deferring!
62
- rake
63
- rspec
64
- sqlite3
65
-
66
- BUNDLED WITH
67
- 1.13.0
@@ -1,66 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- deferring (0.4.0)
5
- activerecord (> 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.1.15)
11
- activesupport (= 4.1.15)
12
- builder (~> 3.1)
13
- activerecord (4.1.15)
14
- activemodel (= 4.1.15)
15
- activesupport (= 4.1.15)
16
- arel (~> 5.0.0)
17
- activesupport (4.1.15)
18
- i18n (~> 0.6, >= 0.6.9)
19
- json (~> 1.7, >= 1.7.7)
20
- minitest (~> 5.1)
21
- thread_safe (~> 0.1)
22
- tzinfo (~> 1.1)
23
- appraisal (2.1.0)
24
- bundler
25
- rake
26
- thor (>= 0.14.0)
27
- arel (5.0.1.20140414130214)
28
- builder (3.2.3)
29
- diff-lcs (1.3)
30
- i18n (0.8.1)
31
- json (1.8.6)
32
- minitest (5.10.1)
33
- rake (12.0.0)
34
- rspec (3.5.0)
35
- rspec-core (~> 3.5.0)
36
- rspec-expectations (~> 3.5.0)
37
- rspec-mocks (~> 3.5.0)
38
- rspec-core (3.5.4)
39
- rspec-support (~> 3.5.0)
40
- rspec-expectations (3.5.0)
41
- diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.5.0)
43
- rspec-mocks (3.5.0)
44
- diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.5.0)
46
- rspec-support (3.5.0)
47
- sqlite3 (1.3.13)
48
- thor (0.19.4)
49
- thread_safe (0.3.6)
50
- tzinfo (1.2.2)
51
- thread_safe (~> 0.1)
52
-
53
- PLATFORMS
54
- ruby
55
-
56
- DEPENDENCIES
57
- activerecord (= 4.1.15)
58
- appraisal
59
- bundler (~> 1.3)
60
- deferring!
61
- rake
62
- rspec
63
- sqlite3
64
-
65
- BUNDLED WITH
66
- 1.13.0