inheritance_integer_type 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -12
- data/inheritance_integer_type.gemspec +3 -3
- data/lib/inheritance_integer_type/extensions.rb +21 -1
- data/lib/inheritance_integer_type/version.rb +1 -1
- data/spec/inheritance_integer_type_spec.rb +38 -60
- data/spec/spec_helper.rb +0 -2
- data/spec/support/active_record.rb +1 -1
- data/spec/support/base.rb +5 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a916703b732e9a89a88946d16cf6a29c9674fd0
|
4
|
+
data.tar.gz: 8dcd46dded61c5168d8e964659887bb33768d343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bcf51124af5f9e4ebcf75b30dea1cff9f3e207da988b9b3dea327917e82367541c5ae6f4e852c07251e641f6bf79b316113c1cf01dff492794db13427105838
|
7
|
+
data.tar.gz: 6abd3fc1aebc455713a8127adb040179abc993b73d2ffdf7433444f60d28fa8a367a183436bb334c9dd9509b7c140695bf4b7a3efb904f7bf9a9c95c94d1c487
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
inheritance_integer_type (0.
|
4
|
+
inheritance_integer_type (0.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -19,17 +19,15 @@ GEM
|
|
19
19
|
multi_json (~> 1.0)
|
20
20
|
arel (3.0.3)
|
21
21
|
builder (3.0.4)
|
22
|
-
|
23
|
-
debugger (1.6.8)
|
24
|
-
columnize (>= 0.3.1)
|
25
|
-
debugger-linecache (~> 1.2.0)
|
26
|
-
debugger-ruby_core_source (~> 1.3.5)
|
27
|
-
debugger-linecache (1.2.0)
|
28
|
-
debugger-ruby_core_source (1.3.5)
|
22
|
+
coderay (1.1.2)
|
29
23
|
diff-lcs (1.2.5)
|
30
24
|
i18n (0.6.9)
|
25
|
+
method_source (0.9.0)
|
31
26
|
multi_json (1.10.1)
|
32
|
-
|
27
|
+
mysql2 (0.3.18)
|
28
|
+
pry (0.11.3)
|
29
|
+
coderay (~> 1.1.0)
|
30
|
+
method_source (~> 0.9.0)
|
33
31
|
rake (10.3.2)
|
34
32
|
rspec (3.0.0)
|
35
33
|
rspec-core (~> 3.0.0)
|
@@ -49,10 +47,13 @@ PLATFORMS
|
|
49
47
|
ruby
|
50
48
|
|
51
49
|
DEPENDENCIES
|
52
|
-
activerecord
|
50
|
+
activerecord
|
53
51
|
bundler (~> 1.6)
|
54
|
-
debugger
|
55
52
|
inheritance_integer_type!
|
56
|
-
|
53
|
+
mysql2 (= 0.3.18)
|
54
|
+
pry
|
57
55
|
rake
|
58
56
|
rspec
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.16.1
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
|
-
spec.add_development_dependency "activerecord"
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "activerecord"
|
25
|
+
spec.add_development_dependency "mysql2", "0.3.18"
|
26
|
+
spec.add_development_dependency "pry"
|
27
27
|
end
|
@@ -9,7 +9,27 @@ module InheritanceIntegerType
|
|
9
9
|
|
10
10
|
def find_sti_class(type_name)
|
11
11
|
lookup = self._inheritance_mapping[type_name.to_i]
|
12
|
-
|
12
|
+
if lookup
|
13
|
+
if ActiveRecord::VERSION::MAJOR < 5
|
14
|
+
super(lookup)
|
15
|
+
else
|
16
|
+
begin
|
17
|
+
if store_full_sti_class
|
18
|
+
ActiveSupport::Dependencies.constantize(lookup)
|
19
|
+
else
|
20
|
+
compute_type(lookup)
|
21
|
+
end
|
22
|
+
rescue NameError
|
23
|
+
raise SubclassNotFound,
|
24
|
+
"The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " +
|
25
|
+
"This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
|
26
|
+
"Please rename this column if you didn't intend it to be used for storing the inheritance class " +
|
27
|
+
"or overwrite #{name}.inheritance_column to use another column for that information."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
13
33
|
end
|
14
34
|
|
15
35
|
def sti_name_with_integer_types
|
@@ -1,81 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'pry'
|
3
3
|
describe InheritanceIntegerType do
|
4
|
+
[3,5].each do |major_version|
|
5
|
+
let(:base) { Base.create(name: "Hello") }
|
6
|
+
let(:left) { LeftChild.create(name: "Hello") }
|
7
|
+
let(:deep) { DeepChild.create(name: "Hello") }
|
4
8
|
|
5
|
-
|
6
|
-
let(:left) { LeftChild.create(name: "Hello") }
|
7
|
-
let(:deep) { DeepChild.create(name: "Hello") }
|
9
|
+
before { allow(ActiveRecord::VERSION).to receive(:MAJOR).and_return(major_version) }
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
describe "The parent" do
|
12
|
+
subject { base }
|
13
|
+
it { is_expected.to be_persisted }
|
14
|
+
it "has no type" do
|
15
|
+
expect(subject.type).to be_nil
|
16
|
+
end
|
17
|
+
it { is_expected.to eql Base.first }
|
14
18
|
end
|
15
|
-
it { is_expected.to eql Base.first }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "The inherited classes" do
|
19
|
-
subject { left }
|
20
|
-
it { is_expected.to be_persisted }
|
21
|
-
it { is_expected.to eql LeftChild.first }
|
22
|
-
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "Belongs to associations" do
|
31
|
-
|
32
|
-
let(:belong) { BelongsTo.create(base: base, left_child: left) }
|
33
|
-
subject { belong }
|
34
|
-
|
35
|
-
it "properly assocaites the base class" do
|
36
|
-
expect(subject.base).to eql base
|
20
|
+
describe "The inherited classes" do
|
21
|
+
subject { left }
|
22
|
+
it { is_expected.to be_persisted }
|
23
|
+
it { is_expected.to eql LeftChild.first }
|
37
24
|
end
|
38
25
|
|
39
|
-
|
40
|
-
|
26
|
+
describe "The deep inherited classes" do
|
27
|
+
subject { deep }
|
28
|
+
it { is_expected.to be_persisted }
|
29
|
+
it { is_expected.to eql DeepChild.first }
|
41
30
|
end
|
42
31
|
|
32
|
+
describe "Belongs to associations" do
|
43
33
|
|
44
|
-
|
34
|
+
let(:belong) { BelongsTo.create(base: base, left_child: left) }
|
35
|
+
subject { belong }
|
45
36
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
[base, left, deep].each{|a| a.update_attributes(other: other) }
|
50
|
-
end
|
51
|
-
subject { other }
|
52
|
-
it "properly finds the classes through the association" do
|
53
|
-
expect(other.bases).to match_array [base, left, deep]
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
37
|
+
it "properly assocaites the base class" do
|
38
|
+
expect(subject.base).to eql base
|
39
|
+
end
|
57
40
|
|
58
|
-
|
41
|
+
it "properly assocaites the children class" do
|
42
|
+
expect(subject.left_child).to eql left
|
43
|
+
end
|
59
44
|
|
60
|
-
let(:old_style) { OldStyle.create }
|
61
|
-
let(:inherited_old_style) { InheritOldStyle.create }
|
62
45
|
|
63
|
-
context "on the base class" do
|
64
|
-
subject { old_style }
|
65
|
-
it "has no type" do
|
66
|
-
expect(subject.type).to be_nil
|
67
|
-
end
|
68
|
-
it { is_expected.to eql OldStyle.first }
|
69
46
|
end
|
70
47
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
48
|
+
describe "Has many associations" do
|
49
|
+
let(:other) { Other.create }
|
50
|
+
before do
|
51
|
+
[base, left, deep].each{|a| a.update_attributes(other: other) }
|
52
|
+
end
|
53
|
+
subject { other }
|
54
|
+
it "properly finds the classes through the association" do
|
55
|
+
expect(other.bases).to match_array [base, left, deep]
|
75
56
|
end
|
76
|
-
it { is_expected.to eql InheritOldStyle.first }
|
77
57
|
end
|
78
|
-
|
79
58
|
end
|
80
|
-
|
81
59
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/base.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inheritance_integer_type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2018-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,32 +56,32 @@ dependencies:
|
|
56
56
|
name: activerecord
|
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: mysql2
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.3.18
|
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:
|
82
|
+
version: 0.3.18
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|