inheritance_integer_type 0.0.1
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 +15 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +117 -0
- data/Rakefile +2 -0
- data/inheritance_integer_type.gemspec +27 -0
- data/lib/inheritance_integer_type.rb +6 -0
- data/lib/inheritance_integer_type/extensions.rb +34 -0
- data/lib/inheritance_integer_type/version.rb +3 -0
- data/spec/inheritance_integer_type_spec.rb +81 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/spec_helper~ +27 -0
- data/spec/support/active_record.rb +11 -0
- data/spec/support/base.rb +7 -0
- data/spec/support/belongs_to.rb +6 -0
- data/spec/support/deep_child.rb +3 -0
- data/spec/support/left_child.rb +7 -0
- data/spec/support/migrations/1_create_base_table.rb +11 -0
- data/spec/support/migrations/2_create_belong_to_table.rb +10 -0
- data/spec/support/migrations/3_create_other_table.rb +8 -0
- data/spec/support/other.rb +5 -0
- data/spec/support/right_child.rb +5 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDJkZTE1NmZlZjFkMDgwMDIxM2VmZjA4MWZlZWZlYTA1MTA4NzU0NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzI5Y2M0Nzc3MTUzMWRiYjE3MDA4ZTVkNWY4Zjk1Y2FhM2RlYzI4ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NWE1YjE5ODZlOWUxNzY1NzllNTc2NTdlMWFlZDAzMDE0ZGI0ZWQxODhjYWRl
|
10
|
+
ZmZhOTkwN2UwMTdmYmU1Nzc2MjhmYTc1NmRjMjdhODAzNjVhNjVhZGU5ZTdm
|
11
|
+
OTk0MTA4ODZjNDU2MmQzZDE4ZTA3NDA3NjQ0NDViMzhhZTY0ZTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGY3NDBjZDRjZWI5NzQ5NmQ1NDEzMjFjNDZlNDdmYjZlY2FiMTY0Zjc1YTMz
|
14
|
+
NjE3MmUwY2Q5OTg2NjBkNjJiNzIxNDUzZTRmOGRkY2Q0NGJlMzA1NGNkODU4
|
15
|
+
NWQ3MDAwNGE3OTIwZmEzMzMwMjdiMmE1MzU3ZDUzZWNhNDAyMDE=
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
*~
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
inheritance_integer_type (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (3.2.11)
|
10
|
+
activesupport (= 3.2.11)
|
11
|
+
builder (~> 3.0.0)
|
12
|
+
activerecord (3.2.11)
|
13
|
+
activemodel (= 3.2.11)
|
14
|
+
activesupport (= 3.2.11)
|
15
|
+
arel (~> 3.0.2)
|
16
|
+
tzinfo (~> 0.3.29)
|
17
|
+
activesupport (3.2.11)
|
18
|
+
i18n (~> 0.6)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
arel (3.0.3)
|
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)
|
29
|
+
diff-lcs (1.2.5)
|
30
|
+
i18n (0.6.9)
|
31
|
+
multi_json (1.10.1)
|
32
|
+
mysql (2.8.1)
|
33
|
+
rake (10.3.2)
|
34
|
+
rspec (3.0.0)
|
35
|
+
rspec-core (~> 3.0.0)
|
36
|
+
rspec-expectations (~> 3.0.0)
|
37
|
+
rspec-mocks (~> 3.0.0)
|
38
|
+
rspec-core (3.0.0)
|
39
|
+
rspec-support (~> 3.0.0)
|
40
|
+
rspec-expectations (3.0.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.0.0)
|
43
|
+
rspec-mocks (3.0.1)
|
44
|
+
rspec-support (~> 3.0.0)
|
45
|
+
rspec-support (3.0.0)
|
46
|
+
tzinfo (0.3.39)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
activerecord (= 3.2.11)
|
53
|
+
bundler (~> 1.6)
|
54
|
+
debugger
|
55
|
+
inheritance_integer_type!
|
56
|
+
mysql (= 2.8.1)
|
57
|
+
rake
|
58
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Kyle d'Oliveira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# InheritanceIntegerType
|
2
|
+
|
3
|
+
Easy for to set the 'type' fields in the DB to be an int (or tinyint) instead of a string. Much better for HD space and Ram, especially if they column in indexed
|
4
|
+
|
5
|
+
The example provided by the docs shows something like this
|
6
|
+
```ruby
|
7
|
+
class Company < ActiveRecord::Base; end
|
8
|
+
class Firm < Company; end
|
9
|
+
class Client < Company; end
|
10
|
+
class PriorityClient < Client; end
|
11
|
+
```
|
12
|
+
|
13
|
+
With a migration that looks something like:
|
14
|
+
```ruby
|
15
|
+
class CreatePictures < ActiveRecord::Migration
|
16
|
+
def change
|
17
|
+
create_table :pictures do |t|
|
18
|
+
t.string :name
|
19
|
+
t.string :type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
The problem with this approach is that `type` is a string (and by default it is 255 characters). This is a little ridiculous. For comparison, if we had a state machine with X states, would we describe the states with strings `"State1", "State2", etc` or would we just enumerate the state column and make it an integer? This gem will allow us to use an integer for the `type` column.
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
gem 'inheritance_integer_type'
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install inheritance_integer_type
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
The gem is pretty straightforward to use.
|
44
|
+
|
45
|
+
First, set the integer_inheritance value on each of the subclasses.
|
46
|
+
```ruby
|
47
|
+
class Firm < ActiveRecord::Base
|
48
|
+
self.integer_inheritance = 1
|
49
|
+
end
|
50
|
+
|
51
|
+
class Client < ActiveRecord::Base
|
52
|
+
self.integer_inheritance = 2
|
53
|
+
end
|
54
|
+
|
55
|
+
class PriorityClient < ActiveRecord::Base
|
56
|
+
self.integer_inheritance = 3
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
Note: The mapping here can start from whatever integer you wish, but I would advise not using 0. The reason being that if you had a new class, for instance `PriorityFirm`, but forgot to include set the mapping, it would effectively get `to_i` called on it and stored in the database. `"Priority".to_i == 0`, so if your mapping included 0, this would create a weird bug.
|
62
|
+
|
63
|
+
If you want to convert a polymorphic association that is already a string, you'll need to set up a migration. (Assuming SQL for the time being, but this should be pretty straightforward.)
|
64
|
+
```ruby
|
65
|
+
class PictureToPolymorphicIntegerType < ActiveRecord::Migration
|
66
|
+
|
67
|
+
def up
|
68
|
+
change_table :companies do |t|
|
69
|
+
t.integer :new_type
|
70
|
+
end
|
71
|
+
|
72
|
+
execute <<-SQL
|
73
|
+
UPDATE companies
|
74
|
+
SET new_type = CASE type
|
75
|
+
WHEN 'Firm' THEN 1
|
76
|
+
WHEN 'Client' THEN 2
|
77
|
+
WHEN 'PriorityClient' THEN 3
|
78
|
+
END
|
79
|
+
SQL
|
80
|
+
|
81
|
+
change_table :companies, :bulk => true do |t|
|
82
|
+
t.remove :type
|
83
|
+
t.rename :new_type, :type
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def down
|
88
|
+
change_table :companies do |t|
|
89
|
+
t.string :new_type
|
90
|
+
end
|
91
|
+
|
92
|
+
execute <<-SQL
|
93
|
+
UPDATE companies
|
94
|
+
SET new_type = CASE imageable_type
|
95
|
+
WHEN 1 THEN 'Firm'
|
96
|
+
WHEN 2 THEN 'Client'
|
97
|
+
WHEN 3 THEN 'PriorityClient'
|
98
|
+
END
|
99
|
+
SQL
|
100
|
+
|
101
|
+
change_table :companies, :bulk => true do |t|
|
102
|
+
t.remove :type
|
103
|
+
t.rename :new_type, :type
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
Lastly, you will need to be careful of any place where you are doing raw SQL queries with the string (`type = 'Firm'`). They should use the integer instead.
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
1. Fork it ( https://github.com/[my-github-username]/inheritance_integer_type/fork )
|
114
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
115
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
116
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
117
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'inheritance_integer_type/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "inheritance_integer_type"
|
8
|
+
spec.version = InheritanceIntegerType::VERSION
|
9
|
+
spec.authors = ["Kyle d'Oliveira"]
|
10
|
+
spec.email = ["kyle@goclio.com"]
|
11
|
+
spec.summary = %q{Allow the type field in teh DB to be an integer rather than a string}
|
12
|
+
spec.description = %q{Use integers rather than strings for the type fields for single table inheritance}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
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"
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module InheritanceIntegerType
|
2
|
+
module Extensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def integer_inheritance=(val)
|
7
|
+
self._inheritance_mapping[val] = sti_name_without_integer_types
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_sti_class(type_name)
|
11
|
+
lookup = self._inheritance_mapping[type_name.to_i]
|
12
|
+
lookup ? super(lookup) : super
|
13
|
+
end
|
14
|
+
|
15
|
+
def sti_name_with_integer_types
|
16
|
+
klass = sti_name_without_integer_types
|
17
|
+
self._inheritance_mapping.key(klass) || klass
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
included do
|
24
|
+
class_eval {
|
25
|
+
cattr_accessor :_inheritance_mapping
|
26
|
+
self._inheritance_mapping = {}
|
27
|
+
class << self
|
28
|
+
alias_method_chain :sti_name, :integer_types
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'debugger'
|
3
|
+
describe InheritanceIntegerType do
|
4
|
+
|
5
|
+
let(:base) { Base.create(name: "Hello") }
|
6
|
+
let(:left) { LeftChild.create(name: "Hello") }
|
7
|
+
let(:deep) { DeepChild.create(name: "Hello") }
|
8
|
+
|
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
|
14
|
+
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
|
+
|
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
|
37
|
+
end
|
38
|
+
|
39
|
+
it "properly assocaites the children class" do
|
40
|
+
expect(subject.left_child).to eql left
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
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
|
57
|
+
|
58
|
+
describe "Old style inheritance" do
|
59
|
+
|
60
|
+
let(:old_style) { OldStyle.create }
|
61
|
+
let(:inherited_old_style) { InheritOldStyle.create }
|
62
|
+
|
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
|
+
end
|
70
|
+
|
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"
|
75
|
+
end
|
76
|
+
it { is_expected.to eql InheritOldStyle.first }
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'support/active_record'
|
2
|
+
require 'inheritance_integer_type'
|
3
|
+
require 'support/base'
|
4
|
+
require 'support/left_child'
|
5
|
+
require 'support/right_child'
|
6
|
+
require 'support/deep_child'
|
7
|
+
require 'support/other'
|
8
|
+
require 'support/belongs_to'
|
9
|
+
require 'support/old_style'
|
10
|
+
require 'support/inherit_old_style'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
config.before(:suite) do
|
15
|
+
ActiveRecord::Migrator.up "#{File.dirname(__FILE__)}/support/migrations"
|
16
|
+
end
|
17
|
+
|
18
|
+
# No need to return the run the down migration after the test
|
19
|
+
# but useful while in development
|
20
|
+
# config.after(:suite) do
|
21
|
+
# ActiveRecord::Migrator.down "#{File.dirname(__FILE__)}/support/migrations"
|
22
|
+
# end
|
23
|
+
|
24
|
+
|
25
|
+
config.around do |example|
|
26
|
+
ActiveRecord::Base.transaction do
|
27
|
+
example.run
|
28
|
+
raise ActiveRecord::Rollback
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/spec/spec_helper~
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'support/active_record'
|
2
|
+
require 'inheritance_integer_type'
|
3
|
+
require 'support/configuration'
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
|
9
|
+
config.before(:suite) do
|
10
|
+
ActiveRecord::Migrator.up "#{File.dirname(__FILE__)}/support/migrations"
|
11
|
+
end
|
12
|
+
|
13
|
+
# No need to return the run the down migration after the test
|
14
|
+
# but useful while in development
|
15
|
+
# config.after(:suite) do
|
16
|
+
# ActiveRecord::Migrator.down "#{File.dirname(__FILE__)}/support/migrations"
|
17
|
+
# end
|
18
|
+
|
19
|
+
|
20
|
+
config.around do |example|
|
21
|
+
ActiveRecord::Base.transaction do
|
22
|
+
example.run
|
23
|
+
raise ActiveRecord::Rollback
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
Dir["#{File.dirname(__FILE__)}/migrations/*.rb"].each {|f| require f}
|
3
|
+
|
4
|
+
config = {
|
5
|
+
:adapter => "mysql",
|
6
|
+
:host => "localhost",
|
7
|
+
:database => "inheritance_integer_type_test",
|
8
|
+
:username => "iit",
|
9
|
+
:password => ""
|
10
|
+
}
|
11
|
+
ActiveRecord::Base.establish_connection(config)
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inheritance_integer_type
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle d'Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.11
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.11
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mysql
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.8.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.8.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: debugger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Use integers rather than strings for the type fields for single table
|
98
|
+
inheritance
|
99
|
+
email:
|
100
|
+
- kyle@goclio.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- inheritance_integer_type.gemspec
|
113
|
+
- lib/inheritance_integer_type.rb
|
114
|
+
- lib/inheritance_integer_type/extensions.rb
|
115
|
+
- lib/inheritance_integer_type/version.rb
|
116
|
+
- spec/inheritance_integer_type_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/spec_helper~
|
119
|
+
- spec/support/active_record.rb
|
120
|
+
- spec/support/base.rb
|
121
|
+
- spec/support/belongs_to.rb
|
122
|
+
- spec/support/deep_child.rb
|
123
|
+
- spec/support/left_child.rb
|
124
|
+
- spec/support/migrations/1_create_base_table.rb
|
125
|
+
- spec/support/migrations/2_create_belong_to_table.rb
|
126
|
+
- spec/support/migrations/3_create_other_table.rb
|
127
|
+
- spec/support/other.rb
|
128
|
+
- spec/support/right_child.rb
|
129
|
+
homepage: ''
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.2.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Allow the type field in teh DB to be an integer rather than a string
|
153
|
+
test_files:
|
154
|
+
- spec/inheritance_integer_type_spec.rb
|
155
|
+
- spec/spec_helper.rb
|
156
|
+
- spec/spec_helper~
|
157
|
+
- spec/support/active_record.rb
|
158
|
+
- spec/support/base.rb
|
159
|
+
- spec/support/belongs_to.rb
|
160
|
+
- spec/support/deep_child.rb
|
161
|
+
- spec/support/left_child.rb
|
162
|
+
- spec/support/migrations/1_create_base_table.rb
|
163
|
+
- spec/support/migrations/2_create_belong_to_table.rb
|
164
|
+
- spec/support/migrations/3_create_other_table.rb
|
165
|
+
- spec/support/other.rb
|
166
|
+
- spec/support/right_child.rb
|