edge_rider 1.0.0 → 1.1.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: da871803b8cefee8834fbb9285c40ac1bb25c1e2
4
- data.tar.gz: 28fb3aca2d1739751bb563bafb004beb03297914
2
+ SHA256:
3
+ metadata.gz: 9c9ae54cb1c626a978a21ae71fb21049cbc411bc41f0f5b2651b0ad021fce5d8
4
+ data.tar.gz: 8d6ac8d94078882641a29e7cf3e6ad3ef72d2e09b6af036ceba87fea9ee67c5f
5
5
  SHA512:
6
- metadata.gz: 8cdca40731ba339f3ecf0f59ac64bc56590aa0b7c1fcbd61c595fb01bb43dbac29335282668599ad057a55b2212ce4f4a1ce0888c2fbdef68873bbfa60475944
7
- data.tar.gz: d257f44a830fe8adab4ce8eb4e56f48b6b1f2b0f615e75aa98fc10e086bf511b9641c01b47714bca43d69ab00fca660249fefc3551a10cc37b605bb275642ee3
6
+ metadata.gz: 58093961cabe247323cccccb9b119fb572b63a6e0d977a5b93774b4dbfeeaf8da30d2bbed48682171db6a99c9ba6f41caf4cfa5969255eabdb1078da8cea3d33
7
+ data.tar.gz: e68386960e037f56bb54605c63a1d8f3beffca8c7348016a9d650a62a65e7568879fb89c4953a2fd65d6c131a9d9c6d61e4707dde2c719be07486bc3add50877
@@ -1 +1 @@
1
- 2.2.4
1
+ 2.5.3
@@ -1,45 +1,37 @@
1
1
  language: ruby
2
2
 
3
- rvm:
4
- - '2.2.4'
5
- - '2.3.1'
6
- - '2.4.1'
7
- - '2.5.3'
8
-
9
- gemfile:
10
- - 'Gemfile.3.2.mysql2'
11
- - 'Gemfile.4.2.mysql2'
12
- - 'Gemfile.4.2.pg'
13
- - 'Gemfile.5.2.mysql2'
14
- - 'Gemfile.5.2.pg'
15
- - 'Gemfile.6.0.pg'
3
+ dist: trusty
16
4
 
17
5
  matrix:
18
- exclude:
19
- # Rails 3.2
20
- - gemfile: 'Gemfile.3.2.mysql2'
21
- rvm: '2.3.1'
22
- - gemfile: 'Gemfile.3.2.mysql2'
23
- rvm: '2.4.1'
24
- - gemfile: 'Gemfile.3.2.mysql2'
25
- rvm: '2.5.3'
26
- # Rails 4.2
27
- - gemfile: 'Gemfile.4.2.mysql2'
28
- rvm: '2.4.1'
29
- - gemfile: 'Gemfile.4.2.pg'
30
- rvm: '2.4.1'
31
- - gemfile: 'Gemfile.4.2.mysql2'
32
- rvm: '2.5.3'
33
- - gemfile: 'Gemfile.4.2.pg'
34
- rvm: '2.5.3'
35
- # Rails 5.2
36
- # Rails 6
37
- - gemfile: 'Gemfile.6.0.pg'
38
- rvm: '2.2.4'
39
- - gemfile: 'Gemfile.6.0.pg'
40
- rvm: '2.3.1'
41
- - gemfile: 'Gemfile.6.0.pg'
42
- rvm: '2.4.1'
6
+ include:
7
+ - rvm: 2.2.4
8
+ gemfile: Gemfile.3.2.mysql2
9
+ - rvm: 2.2.4
10
+ gemfile: Gemfile.4.2.mysql2
11
+ - rvm: 2.3.1
12
+ gemfile: Gemfile.4.2.mysql2
13
+ - rvm: 2.2.4
14
+ gemfile: Gemfile.4.2.pg
15
+ - rvm: 2.3.1
16
+ gemfile: Gemfile.4.2.pg
17
+ - rvm: 2.2.4
18
+ gemfile: Gemfile.5.2.mysql2
19
+ - rvm: 2.3.1
20
+ gemfile: Gemfile.5.2.mysql2
21
+ - rvm: 2.4.1
22
+ gemfile: Gemfile.5.2.mysql2
23
+ - rvm: 2.5.3
24
+ gemfile: Gemfile.5.2.mysql2
25
+ - rvm: 2.2.4
26
+ gemfile: Gemfile.5.2.pg
27
+ - rvm: 2.3.1
28
+ gemfile: Gemfile.5.2.pg
29
+ - rvm: 2.4.1
30
+ gemfile: Gemfile.5.2.pg
31
+ - rvm: 2.5.3
32
+ gemfile: Gemfile.5.2.pg
33
+ - rvm: 2.5.3
34
+ gemfile: Gemfile.6.0.pg
43
35
 
44
36
  services:
45
37
  - mysql
@@ -57,7 +49,3 @@ before_script:
57
49
  - mysql -e 'create database IF NOT EXISTS edge_rider_test;'
58
50
 
59
51
  script: bundle exec rake current_rspec
60
-
61
- notifications:
62
- email:
63
- - fail@makandra.de
@@ -11,6 +11,12 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
11
11
  ### Compatible changes
12
12
  -
13
13
 
14
+ ## 1.1.0
15
+
16
+ ### Compatible changes
17
+ - Add `preload_association` at instance level. Example: `user.preload_associations(:posts)`
18
+ - Add support for polymorphic associations in `traverse_association`.
19
+
14
20
  ## 1.0.0
15
21
 
16
22
  ### Breaking changes
@@ -10,7 +10,8 @@ gem 'rake', '=10.0.4'
10
10
  gem 'database_cleaner'
11
11
  gem 'rspec', '~> 3.4'
12
12
  gem 'has_defaults' # used by test models
13
- gem 'gemika', '>= 0.2.0'
13
+ gem 'gemika'
14
+ gem 'pry-byebug'
14
15
 
15
16
  # Gem under test
16
17
  gem 'edge_rider', path: '.'
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edge_rider (0.3.3)
5
- activerecord
4
+ edge_rider (1.1.0)
5
+ activerecord (>= 3.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -20,14 +20,23 @@ GEM
20
20
  multi_json (~> 1.0)
21
21
  arel (3.0.3)
22
22
  builder (3.0.4)
23
+ byebug (10.0.2)
24
+ coderay (1.1.2)
23
25
  database_cleaner (1.0.1)
24
26
  diff-lcs (1.2.5)
25
- gemika (0.3.2)
27
+ gemika (0.4.0)
26
28
  has_defaults (0.4.4)
27
29
  activerecord
28
30
  i18n (0.6.11)
31
+ method_source (0.9.2)
29
32
  multi_json (1.12.1)
30
33
  mysql2 (0.3.17)
34
+ pry (0.12.2)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.9.0)
37
+ pry-byebug (3.6.0)
38
+ byebug (~> 10.0)
39
+ pry (~> 0.10)
31
40
  rake (10.0.4)
32
41
  rspec (3.5.0)
33
42
  rspec-core (~> 3.5.0)
@@ -51,10 +60,11 @@ DEPENDENCIES
51
60
  activerecord (= 3.2.22)
52
61
  database_cleaner
53
62
  edge_rider!
54
- gemika (>= 0.2.0)
63
+ gemika
55
64
  has_defaults
56
65
  i18n (= 0.6.11)
57
66
  mysql2 (= 0.3.17)
67
+ pry-byebug
58
68
  rake (= 10.0.4)
59
69
  rspec (~> 3.4)
60
70
 
@@ -10,6 +10,7 @@ gem 'database_cleaner'
10
10
  gem 'has_defaults' # used by test models
11
11
  gem 'rspec'
12
12
  gem 'gemika'
13
+ gem 'pry-byebug'
13
14
 
14
15
  # Gem under test
15
16
  gem 'edge_rider', path: '.'
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edge_rider (0.3.3)
5
- activerecord
4
+ edge_rider (1.1.0)
5
+ activerecord (>= 3.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -22,15 +22,24 @@ GEM
22
22
  tzinfo (~> 1.1)
23
23
  arel (6.0.3)
24
24
  builder (3.2.2)
25
+ byebug (10.0.2)
26
+ coderay (1.1.2)
25
27
  database_cleaner (1.0.1)
26
28
  diff-lcs (1.2.5)
27
- gemika (0.3.3)
29
+ gemika (0.4.0)
28
30
  has_defaults (0.4.4)
29
31
  activerecord
30
32
  i18n (0.7.0)
31
33
  json (1.8.3)
34
+ method_source (0.9.2)
32
35
  minitest (5.9.1)
33
36
  mysql2 (0.3.21)
37
+ pry (0.12.2)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-byebug (3.6.0)
41
+ byebug (~> 10.0)
42
+ pry (~> 0.10)
34
43
  rake (11.3.0)
35
44
  rspec (3.5.0)
36
45
  rspec-core (~> 3.5.0)
@@ -59,6 +68,7 @@ DEPENDENCIES
59
68
  gemika
60
69
  has_defaults
61
70
  mysql2 (~> 0.3.17)
71
+ pry-byebug
62
72
  rake
63
73
  rspec
64
74
 
@@ -10,6 +10,7 @@ gem 'database_cleaner'
10
10
  gem 'rspec'
11
11
  gem 'has_defaults' # used by test models
12
12
  gem 'gemika'
13
+ gem 'pry-byebug'
13
14
 
14
15
  # Gem under test
15
16
  gem 'edge_rider', path: '.'
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edge_rider (0.3.3)
5
- activerecord
4
+ edge_rider (1.1.0)
5
+ activerecord (>= 3.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -22,15 +22,24 @@ GEM
22
22
  tzinfo (~> 1.1)
23
23
  arel (6.0.3)
24
24
  builder (3.2.2)
25
+ byebug (10.0.2)
26
+ coderay (1.1.2)
25
27
  database_cleaner (1.5.3)
26
28
  diff-lcs (1.2.5)
27
- gemika (0.3.2)
29
+ gemika (0.4.0)
28
30
  has_defaults (0.4.4)
29
31
  activerecord
30
32
  i18n (0.7.0)
31
33
  json (1.8.3)
34
+ method_source (0.9.2)
32
35
  minitest (5.9.1)
33
36
  pg (0.19.0)
37
+ pry (0.12.2)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-byebug (3.6.0)
41
+ byebug (~> 10.0)
42
+ pry (~> 0.10)
34
43
  rake (11.3.0)
35
44
  rspec (3.5.0)
36
45
  rspec-core (~> 3.5.0)
@@ -59,6 +68,7 @@ DEPENDENCIES
59
68
  gemika
60
69
  has_defaults
61
70
  pg
71
+ pry-byebug
62
72
  rake
63
73
  rspec
64
74
 
@@ -11,6 +11,7 @@ gem 'database_cleaner'
11
11
  gem 'rspec'
12
12
  gem 'has_defaults' # used by test models
13
13
  gem 'gemika'
14
+ gem 'pry-byebug'
14
15
 
15
16
  # Gem under test
16
17
  gem 'edge_rider', path: '.'
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edge_rider (0.3.3)
5
- activerecord
4
+ edge_rider (1.1.0)
5
+ activerecord (>= 3.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -19,16 +19,25 @@ GEM
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
21
  arel (9.0.0)
22
+ byebug (10.0.2)
23
+ coderay (1.1.2)
22
24
  concurrent-ruby (1.1.5)
23
25
  database_cleaner (1.6.1)
24
26
  diff-lcs (1.3)
25
- gemika (0.3.2)
27
+ gemika (0.4.0)
26
28
  has_defaults (0.4.4)
27
29
  activerecord
28
30
  i18n (1.5.1)
29
31
  concurrent-ruby (~> 1.0)
32
+ method_source (0.9.2)
30
33
  minitest (5.11.3)
31
34
  mysql2 (0.4.6)
35
+ pry (0.12.2)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.9.0)
38
+ pry-byebug (3.6.0)
39
+ byebug (~> 10.0)
40
+ pry (~> 0.10)
32
41
  rake (12.0.0)
33
42
  rspec (3.6.0)
34
43
  rspec-core (~> 3.6.0)
@@ -58,6 +67,7 @@ DEPENDENCIES
58
67
  has_defaults
59
68
  i18n (<= 1.5.1)
60
69
  mysql2
70
+ pry-byebug
61
71
  rake
62
72
  rspec
63
73
 
@@ -11,6 +11,7 @@ gem 'database_cleaner'
11
11
  gem 'has_defaults' # used by test models
12
12
  gem 'rspec'
13
13
  gem 'gemika'
14
+ gem 'pry-byebug'
14
15
 
15
16
  # Gem under test
16
17
  gem 'edge_rider', path: '.'
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edge_rider (0.3.3)
5
- activerecord
4
+ edge_rider (1.1.0)
5
+ activerecord (>= 3.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -19,16 +19,25 @@ GEM
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
21
  arel (9.0.0)
22
+ byebug (10.0.2)
23
+ coderay (1.1.2)
22
24
  concurrent-ruby (1.1.5)
23
25
  database_cleaner (1.6.1)
24
26
  diff-lcs (1.3)
25
- gemika (0.3.2)
27
+ gemika (0.4.0)
26
28
  has_defaults (0.4.4)
27
29
  activerecord
28
30
  i18n (1.5.1)
29
31
  concurrent-ruby (~> 1.0)
32
+ method_source (0.9.2)
30
33
  minitest (5.11.3)
31
34
  pg (0.20.0)
35
+ pry (0.12.2)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.9.0)
38
+ pry-byebug (3.6.0)
39
+ byebug (~> 10.0)
40
+ pry (~> 0.10)
32
41
  rake (12.0.0)
33
42
  rspec (3.6.0)
34
43
  rspec-core (~> 3.6.0)
@@ -58,6 +67,7 @@ DEPENDENCIES
58
67
  has_defaults
59
68
  i18n (<= 1.5.1)
60
69
  pg
70
+ pry-byebug
61
71
  rake
62
72
  rspec
63
73
 
@@ -10,6 +10,7 @@ gem 'database_cleaner'
10
10
  gem 'has_defaults' # used by test models
11
11
  gem 'rspec'
12
12
  gem 'gemika'
13
+ gem 'pry-byebug'
13
14
 
14
15
  # Gem under test
15
16
  gem 'edge_rider', path: '.'
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edge_rider (0.3.3)
5
- activerecord
4
+ edge_rider (1.1.0)
5
+ activerecord (>= 3.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -18,16 +18,25 @@ GEM
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
20
  zeitwerk (~> 2.1, >= 2.1.4)
21
+ byebug (10.0.2)
22
+ coderay (1.1.2)
21
23
  concurrent-ruby (1.1.5)
22
24
  database_cleaner (1.7.0)
23
25
  diff-lcs (1.3)
24
- gemika (0.3.4)
26
+ gemika (0.4.0)
25
27
  has_defaults (0.4.4)
26
28
  activerecord
27
29
  i18n (1.6.0)
28
30
  concurrent-ruby (~> 1.0)
31
+ method_source (0.9.2)
29
32
  minitest (5.11.3)
30
33
  pg (1.1.4)
34
+ pry (0.12.2)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.9.0)
37
+ pry-byebug (3.6.0)
38
+ byebug (~> 10.0)
39
+ pry (~> 0.10)
31
40
  rake (12.3.2)
32
41
  rspec (3.8.0)
33
42
  rspec-core (~> 3.8.0)
@@ -57,6 +66,7 @@ DEPENDENCIES
57
66
  gemika
58
67
  has_defaults
59
68
  pg
69
+ pry-byebug
60
70
  rake
61
71
  rspec
62
72
 
data/README.md CHANGED
@@ -151,10 +151,12 @@ It now uses these IDs to return a new relation that has **no joins** and a singl
151
151
 
152
152
  Sometimes you want to fetch associations for records that you already instantiated, e.g. when it has deeply nested associations.
153
153
 
154
- Edge Rider gives your model classes a method `.preload_associations`. The method can be used to preload associations for loaded objects like this:
154
+ Edge Rider gives your model classes and instances a method `preload_associations`. The method can be used to preload associations for loaded objects like this:
155
155
 
156
156
  @user = User.find(params[:id])
157
157
  User.preload_associations [@user], { threads: { posts: :author }, messages: :sender }
158
+ # or
159
+ user.preload_associations { threads: { posts: :author }, messages: :sender }
158
160
 
159
161
  *Implementation note*: Rails 3.0 already has a method [`.preload_associations`](https://apidock.com/rails/ActiveRecord/AssociationPreload/ClassMethods/preload_associations)
160
162
  which Edge Rider merely makes public. Edge Rider ports this method forward to Rails 3.1+.
@@ -16,5 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency('activerecord')
19
+ s.add_dependency('activerecord', '>=3.2')
20
+ s.required_ruby_version = ">= 2.2"
20
21
  end
@@ -1,5 +1,10 @@
1
1
  module EdgeRider
2
2
  module PreloadAssociations
3
+ module PreloadAssociationsInstanceMethod
4
+ def preload_associations(*args)
5
+ self.class.preload_associations([self], *args)
6
+ end
7
+ end
3
8
 
4
9
  def preload_associations(*args)
5
10
  preloader = ActiveRecord::Associations::Preloader
@@ -21,5 +26,7 @@ module EdgeRider
21
26
  ActiveRecord::Base.send(:extend, self)
22
27
  end
23
28
 
29
+ ActiveRecord::Base.send(:include, PreloadAssociationsInstanceMethod)
30
+
24
31
  end
25
32
  end
@@ -8,7 +8,7 @@ module EdgeRider
8
8
 
9
9
  scope = scoped({})
10
10
 
11
- associations.each_with_index do |association, index|
11
+ associations.each do |association|
12
12
 
13
13
  reflection = scope.reflect_on_association(association) or raise UnknownAssociation, "Could not find association: #{self.name}##{association}"
14
14
  foreign_key = reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name
@@ -24,8 +24,12 @@ module EdgeRider
24
24
  if reflection.through_reflection # has_many :through
25
25
  scope = scope.traverse_association(reflection.through_reflection.name, reflection.source_reflection.name)
26
26
  else # has_many or has_one
27
- ids = scope.collect_ids
28
- scope = EdgeRider::Util.exclusive_query(reflection.klass, foreign_key => ids)
27
+ conditions = {}
28
+ # A polymorphic association has a type attribute, e.g. record_type, that needs to be added to condition.
29
+ conditions[reflection.type] = self.name if reflection.type.present?
30
+ conditions[foreign_key] = scope.collect_ids
31
+
32
+ scope = EdgeRider::Util.exclusive_query(reflection.klass, conditions)
29
33
  end
30
34
  else
31
35
  raise UnsupportedAssociation, "Unsupport association type: #{reflection.macro}"
@@ -1,3 +1,3 @@
1
1
  module EdgeRider
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -2,14 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe EdgeRider::PreloadAssociations do
4
4
 
5
- it 'should preload the given named associations so they are no longer fetched lazily' do
6
- forum = Forum.create!
7
- topic = Topic.create!(forum: forum)
8
- post = Post.create!(topic: topic)
9
- Forum.preload_associations([forum], topics: :posts)
10
- Topic.should_not_receive(:new)
11
- Post.should_not_receive(:new)
12
- forum.topics.collect(&:posts)
5
+ describe '.preload_associations' do
6
+ it 'should preload the given named associations so they are no longer fetched lazily' do
7
+ forum = Forum.create!
8
+ topic = Topic.create!(forum: forum)
9
+ post = Post.create!(topic: topic)
10
+
11
+ Forum.preload_associations([forum], topics: :posts)
12
+ Topic.should_not_receive(:new)
13
+ Post.should_not_receive(:new)
14
+ forum.topics.collect(&:posts)
15
+ end
16
+ end
17
+
18
+ describe '#preload_associations' do
19
+ it 'should preload the given named associations so they are no longer fetched lazily' do
20
+ forum = Forum.create!
21
+ topic = Topic.create!(forum: forum)
22
+ post = Post.create!(topic: topic)
23
+
24
+ forum.preload_associations(topics: :posts)
25
+ Topic.should_not_receive(:new)
26
+ Post.should_not_receive(:new)
27
+ forum.topics.collect(&:posts)
28
+ end
13
29
  end
14
30
 
15
31
  end
@@ -123,6 +123,53 @@ describe EdgeRider::TraverseAssociation do
123
123
  traversed_scope.to_a.should =~ [post_3a, post_3b]
124
124
  end
125
125
 
126
+ it 'should traverse to a polymorphic has one association' do
127
+ profile = Profile.create!
128
+ profile_attachment = Attachment.create!(record: profile)
129
+
130
+ # Sanity check that the condition includes both record id and record type
131
+ Attachment.create!(record_id: profile_attachment.id, record_type: 'NonExisting')
132
+
133
+ scope = Profile.scoped(conditions: { id: [profile.id] })
134
+ scope.traverse_association(:attachment).to_a.should =~ [profile_attachment]
135
+ end
136
+
137
+ it 'should traverse to a polymorphic has many association' do
138
+ topic = Topic.create!
139
+ topic_attachment_1 = Attachment.create!(record: topic)
140
+ topic_attachment_2 = Attachment.create!(record: topic)
141
+
142
+ # Sanity check that the condition includes both record id and record type
143
+ Attachment.create!(record_id: topic_attachment_1.id, record_type: 'NonExisting')
144
+
145
+ scope = Topic.scoped(conditions: { id: [topic_attachment_1.id, topic_attachment_2.id] })
146
+ scope.traverse_association(:attachments).to_a.should =~ [topic_attachment_1, topic_attachment_2]
147
+ end
148
+
149
+ it 'should raise an error if you want to traverse from a polymorphic association' do
150
+ profile = Profile.create!
151
+ profile_attachment = Attachment.create!(record: profile)
152
+
153
+ scope = Attachment.scoped(conditions: { id: [profile_attachment.id] })
154
+
155
+ if [4, 3].include?(EdgeRider::Util.active_record_version)
156
+ expect { scope.traverse_association(:record) }.to raise_error(
157
+ NameError,
158
+ 'uninitialized constant Attachment::Record'
159
+ )
160
+ elsif EdgeRider::Util.active_record_version == 5
161
+ expect { scope.traverse_association(:record) }.to raise_error(
162
+ ArgumentError,
163
+ 'Polymorphic association does not support to compute class.'
164
+ )
165
+ else
166
+ expect { scope.traverse_association(:record) }.to raise_error(
167
+ ArgumentError,
168
+ 'Polymorphic associations do not support computing the class.'
169
+ )
170
+ end
171
+ end
172
+
126
173
  end
127
174
 
128
175
  end
@@ -4,6 +4,8 @@ require 'edge_rider'
4
4
  require 'edge_rider/development'
5
5
  require 'database_cleaner'
6
6
  require 'gemika'
7
+ require 'pry'
8
+ require 'byebug'
7
9
 
8
10
  # Requires supporting files with custom matchers and macros, etc in ./support/ and its subdirectories.
9
11
  Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each {|f| require f}
@@ -31,4 +31,9 @@ Gemika::Database.new.rewrite_schema! do
31
31
  t.boolean :trashed
32
32
  end
33
33
 
34
+ create_table :attachments do |t|
35
+ t.string :record_type
36
+ t.integer :record_id
37
+ end
38
+
34
39
  end
@@ -51,6 +51,7 @@ class Profile < ActiveRecord::Base
51
51
  include AllowSettingIdOnCreate
52
52
 
53
53
  belongs_to :user
54
+ has_one :attachment, as: :record
54
55
 
55
56
  has_defaults trashed: false
56
57
 
@@ -67,6 +68,7 @@ class Topic < ActiveRecord::Base
67
68
  has_many :posts
68
69
  belongs_to :author, class_name: 'User'
69
70
  has_many :post_authors, through: :posts
71
+ has_many :attachments, as: :record
70
72
 
71
73
  has_defaults trashed: false
72
74
 
@@ -86,3 +88,10 @@ class User < ActiveRecord::Base
86
88
  has_defaults trashed: false
87
89
 
88
90
  end
91
+
92
+
93
+ class Attachment < ActiveRecord::Base
94
+
95
+ belongs_to :record, polymorphic: true
96
+
97
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edge_rider
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-12 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.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: '0'
26
+ version: '3.2'
27
27
  description: Power tools for ActiveRecord relations (scopes)
28
28
  email: henning.koch@makandra.de
29
29
  executables: []
@@ -86,15 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.2'
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.4.5.1
96
+ rubygems_version: 3.0.6
98
97
  signing_key:
99
98
  specification_version: 4
100
99
  summary: Power tools for ActiveRecord relations (scopes)