inheritance_integer_type 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a8dfac2f20647d7ae593cd3c4703585cc3206f
4
- data.tar.gz: b3740e25777985015bfc3e69bfd1bce1694045ff
3
+ metadata.gz: 9a916703b732e9a89a88946d16cf6a29c9674fd0
4
+ data.tar.gz: 8dcd46dded61c5168d8e964659887bb33768d343
5
5
  SHA512:
6
- metadata.gz: 9645040244a4a1fdef44d79362ef075e356fdfa2648f36f794045d229b3e1ffc49deef651e52e65fc2c5f0cc7bcbf8e4a49b3dd405aea92685a7091c6368522a
7
- data.tar.gz: 30bd7e83d396df14f7901e992a9d61dc557b95d79109a414fb9253a43009fd680d8a6b595a22c7172a0a36edfa321ef0ab3d56c63896ea539f3e060dd35bdec8
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.0.1)
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
- columnize (0.8.9)
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
- mysql (2.8.1)
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 (= 3.2.11)
50
+ activerecord
53
51
  bundler (~> 1.6)
54
- debugger
55
52
  inheritance_integer_type!
56
- mysql (= 2.8.1)
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", "3.2.11"
25
- spec.add_development_dependency "mysql", "2.8.1"
26
- spec.add_development_dependency "debugger"
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
- lookup ? super(lookup) : super
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,3 +1,3 @@
1
1
  module InheritanceIntegerType
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,81 +1,59 @@
1
1
  require 'spec_helper'
2
- require 'debugger'
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
- let(:base) { Base.create(name: "Hello") }
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
- describe "The parent" do
10
- subject { base }
11
- it { is_expected.to be_persisted }
12
- it "has no type" do
13
- expect(subject.type).to be_nil
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
- describe "The deep inherited classes" do
25
- subject { deep }
26
- it { is_expected.to be_persisted }
27
- it { is_expected.to eql DeepChild.first }
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
- it "properly assocaites the children class" do
40
- expect(subject.left_child).to eql left
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
- end
34
+ let(:belong) { BelongsTo.create(base: base, left_child: left) }
35
+ subject { belong }
45
36
 
46
- describe "Has many associations" do
47
- let(:other) { Other.create }
48
- before do
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
- describe "Old style inheritance" do
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
- context "on the inherited class" do
72
- subject { inherited_old_style }
73
- it "has the string type" do
74
- expect(inherited_old_style.type).to eql "InheritOldStyle"
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
@@ -6,8 +6,6 @@ require 'support/right_child'
6
6
  require 'support/deep_child'
7
7
  require 'support/other'
8
8
  require 'support/belongs_to'
9
- require 'support/old_style'
10
- require 'support/inherit_old_style'
11
9
 
12
10
  RSpec.configure do |config|
13
11
 
@@ -2,7 +2,7 @@ require 'active_record'
2
2
  Dir["#{File.dirname(__FILE__)}/migrations/*.rb"].each {|f| require f}
3
3
 
4
4
  config = {
5
- :adapter => "mysql",
5
+ :adapter => "mysql2",
6
6
  :host => "localhost",
7
7
  :database => "inheritance_integer_type_test",
8
8
  :username => "iit",
data/spec/support/base.rb CHANGED
@@ -4,4 +4,9 @@ class Base < ActiveRecord::Base
4
4
  has_many :belongs_to
5
5
  belongs_to :other
6
6
 
7
+ self._inheritance_mapping = {
8
+ 1 => "LeftChild",
9
+ 2 => "RightChild",
10
+ 3 => "DeepChild",
11
+ }
7
12
  end
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.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: 2017-05-08 00:00:00.000000000 Z
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: 3.2.11
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: 3.2.11
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: mysql
70
+ name: mysql2
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 2.8.1
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: 2.8.1
82
+ version: 0.3.18
83
83
  - !ruby/object:Gem::Dependency
84
- name: debugger
84
+ name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="