polymorphic_integer_type 2.1.1 → 2.2.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 +5 -5
- data/.gitignore +2 -0
- data/lib/polymorphic_integer_type/polymorphic_array_value_extension.rb +20 -0
- data/lib/polymorphic_integer_type/version.rb +1 -1
- data/lib/polymorphic_integer_type.rb +1 -0
- data/polymorphic_integer_type.gemspec +3 -3
- data/spec/polymorphic_integer_type_spec.rb +16 -5
- data/spec/spec_helper.rb +1 -0
- data/spec/support/configuration.rb +2 -2
- data/spec/support/database.yml +1 -1
- data/spec/support/migrations/1_create_link_table.rb +1 -1
- data/spec/support/migrations/2_create_animal_table.rb +1 -1
- data/spec/support/migrations/3_create_person_table.rb +1 -1
- data/spec/support/migrations/4_create_food_table.rb +1 -1
- data/spec/support/migrations/5_create_drink_table.rb +1 -1
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a821ba758df6177c1f89d6f147bedd24e5a96874b65e9bff7c348b04f5a60013
|
4
|
+
data.tar.gz: 23f8a6196d1523ef46d58af66612646a910744e511f959ff783af977e8ea56a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a4e980b7f71e2fd78f030fcd8053cb12923775075e1f9425ee999c24e65d017b30e248bfa484e5a1df7ee300afdf71c1ea03c8260663b475fc477431f81536e
|
7
|
+
data.tar.gz: 5e7be692212675c3f346d10b18328d9b35a0fc5bfc68fbfe19dfea1e0be112ad8d9410b6429b2986b212d64cf94e8825d2aa27d1aed29197625cdf8d45b5e81b
|
data/.gitignore
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module PolymorphicIntegerType
|
2
|
+
module PolymorphicArrayValueExtension
|
3
|
+
def type_to_ids_mapping
|
4
|
+
super.tap do |result|
|
5
|
+
association = @associated_table.send(:association)
|
6
|
+
klass = association.active_record
|
7
|
+
name = association.name
|
8
|
+
|
9
|
+
if klass.respond_to?("#{name}_type_mapping")
|
10
|
+
result.transform_keys! do |key|
|
11
|
+
klass.send("#{name}_type_mapping").key(key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
result
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::PredicateBuilder::PolymorphicArrayValue.prepend(PolymorphicIntegerType::PolymorphicArrayValueExtension)
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.add_dependency "activerecord"
|
22
|
+
spec.add_development_dependency "bundler"
|
22
23
|
spec.add_development_dependency "rake"
|
23
24
|
spec.add_development_dependency "rspec"
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "mysql2", "0.3.16"
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
26
|
spec.add_development_dependency "byebug"
|
27
27
|
end
|
@@ -24,6 +24,17 @@ describe PolymorphicIntegerType do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
context "when querying the associations" do
|
28
|
+
let(:source) { cat }
|
29
|
+
let(:target) { nil }
|
30
|
+
it "properly finds the object with a where" do
|
31
|
+
expect(Link.where(source: source, id: link.id).first).to eql link
|
32
|
+
end
|
33
|
+
it "properly finds the object with a find_by" do
|
34
|
+
expect(Link.find_by(source: source, id: link.id)).to eql link
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
27
38
|
shared_examples "proper source" do
|
28
39
|
it "should have the proper id, type and object for the source" do
|
29
40
|
expect(link.source_id).to eql source.id
|
@@ -47,12 +58,12 @@ describe PolymorphicIntegerType do
|
|
47
58
|
|
48
59
|
context "and the link is accessed through the associations" do
|
49
60
|
before { link }
|
50
|
-
|
61
|
+
|
51
62
|
it "should have the proper source" do
|
52
63
|
expect(source.source_links[0].source).to eql source
|
53
64
|
end
|
54
65
|
end
|
55
|
-
|
66
|
+
|
56
67
|
end
|
57
68
|
context "When a link is given polymorphic record" do
|
58
69
|
let(:link) { Link.create(source: source) }
|
@@ -137,7 +148,7 @@ describe PolymorphicIntegerType do
|
|
137
148
|
|
138
149
|
|
139
150
|
end
|
140
|
-
|
151
|
+
|
141
152
|
context "when the association is an STI table" do
|
142
153
|
let(:link) { Link.create(source: source, target: whiskey) }
|
143
154
|
let(:source) { Dog.create(name: "Bela", kind: "Dog", owner: owner) }
|
@@ -147,7 +158,7 @@ describe PolymorphicIntegerType do
|
|
147
158
|
expect(link.source).to eql source
|
148
159
|
end
|
149
160
|
end
|
150
|
-
|
161
|
+
|
151
162
|
context "when mapping is given inline in the belongs_to model" do
|
152
163
|
class InlineLink < ActiveRecord::Base
|
153
164
|
include PolymorphicIntegerType::Extensions
|
@@ -187,7 +198,7 @@ describe PolymorphicIntegerType do
|
|
187
198
|
include_examples "proper target"
|
188
199
|
|
189
200
|
it "creates foreign_type mapping method" do
|
190
|
-
expect(Link.source_type_mapping).to eq({
|
201
|
+
expect(Link.source_type_mapping).to eq({1 => "Person", 2 => "Animal"})
|
191
202
|
expect(InlineLink.source_type_mapping).to eq({10 => "Person", 11 => "InlineAnimal"})
|
192
203
|
end
|
193
204
|
|
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,7 @@ RSpec.configure do |config|
|
|
13
13
|
config.before(:suite) do
|
14
14
|
database_config = YAML.load(File.open("#{File.dirname(__FILE__)}/support/database.yml"))
|
15
15
|
ActiveRecord::Base.establish_connection(database_config)
|
16
|
+
ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations").migrate
|
16
17
|
end
|
17
18
|
|
18
19
|
config.around do |example|
|
data/spec/support/database.yml
CHANGED
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymorphic_integer_type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle d'Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '0'
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,33 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: byebug
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/polymorphic_integer_type.rb
|
112
112
|
- lib/polymorphic_integer_type/extensions.rb
|
113
113
|
- lib/polymorphic_integer_type/mapping.rb
|
114
|
+
- lib/polymorphic_integer_type/polymorphic_array_value_extension.rb
|
114
115
|
- lib/polymorphic_integer_type/version.rb
|
115
116
|
- polymorphic_integer_type.gemspec
|
116
117
|
- spec/polymorphic_integer_type_spec.rb
|
@@ -147,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
- !ruby/object:Gem::Version
|
148
149
|
version: '0'
|
149
150
|
requirements: []
|
150
|
-
|
151
|
-
rubygems_version: 2.6.14
|
151
|
+
rubygems_version: 3.0.3
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: Use integers rather than strings for the _type field
|