active_record-mti 0.3.0.pre.rc2 → 0.3.0.pre.rc3

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: d60ec74fdc811ec4b99d12daed96d8d44989026b
4
- data.tar.gz: 5e11732fcfec73c329050915107a088876886b37
3
+ metadata.gz: 2797d1673715b1af2e8d8afc15738a50c40b79c0
4
+ data.tar.gz: d28b1fdf7acd2348659f140f86221f8a6f754113
5
5
  SHA512:
6
- metadata.gz: 62ce99ba9014e671d53c84b1bab0ac37de5dc7ee3317767b27b3dcc8084b6f544b0a1ffe25674a83723b9f8ee8e19d4ccc0fa22ee728df9b21d2186075ee8ecf
7
- data.tar.gz: 8fac323f73f8d83aeb417a28243c711ff3073d58a541179aaa5ccb9f985fe2329917c286368a17b9d50426304eb10d3661352ad6f0b1896ed4106e6e17bfdaa7
6
+ metadata.gz: 0f2678e3004f58eb2ccbb3ba77521f6bed0efe492c657b39c0d19e5ce33081326730591d89c21049d859a4ef4f29a5cd4c38f96961662b658256353f835efe55
7
+ data.tar.gz: 1beed4b499349f31e093332e4e4f505aa9482bd46e47f989ae3aa0be13fc8a897596f9be2613bbf4db19e777ad76c471eafa4d72ea4e3f92d9f890f2cc523637
data/.travis.yml CHANGED
@@ -12,18 +12,18 @@ addons:
12
12
  postgresql: "9.3"
13
13
 
14
14
  rvm:
15
- - 2.0
16
- - 2.1
17
- - 2.2
18
- - 2.3
19
15
  - 2.4
16
+ - 2.3
17
+ - 2.2
18
+ - 2.1
19
+ - 2.0
20
20
 
21
21
  gemfile:
22
- - gemfiles/activerecord-4.0.Gemfile
23
- - gemfiles/activerecord-4.1.Gemfile
24
- - gemfiles/activerecord-4.2.Gemfile
25
- - gemfiles/activerecord-5.0.Gemfile
26
22
  - gemfiles/activerecord-5.1.Gemfile
23
+ - gemfiles/activerecord-5.0.Gemfile
24
+ - gemfiles/activerecord-4.2.Gemfile
25
+ - gemfiles/activerecord-4.1.Gemfile
26
+ - gemfiles/activerecord-4.0.Gemfile
27
27
 
28
28
  matrix:
29
29
  exclude:
data/CHANGELOG.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # ActiveRecord::MTI
2
2
 
3
- ## 0.3.0 _(November 7th 2017)_
3
+ ## 0.3.0 _(Unreleased)_
4
4
  - Greatly improved future-proofing injection strategy.
5
5
  - No longer overwriting (and maintaining) ActiveRecord Calculation sub-routines.
6
6
  - Instead of injecting at `build_select`, we're injecting at `build_arel` with one additional new sub-routine (`build_mti`)
7
7
  - `build_mti` sub-routine detects if an MTI projection is needed based on grouping and selecting from query being built.
8
+ - No longer need to use `uses_mti`
8
9
 
9
10
  ## 0.2.1 _(September 20th 2017)_
10
11
  - More reliable class discrimination
data/Gemfile CHANGED
@@ -17,4 +17,6 @@ group :test do
17
17
 
18
18
  gem 'database_cleaner'
19
19
 
20
+ gem 'combustion'
21
+
20
22
  end
@@ -37,5 +37,6 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'pry-byebug', '~> 3'
38
38
  spec.add_development_dependency 'bundler', '~> 1.3'
39
39
  spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'combustion', '~> 0.7'
40
41
 
41
42
  end
@@ -24,21 +24,6 @@ module ActiveRecord
24
24
  # Rails likes to make breaking changes in it's minor versions (like 4.1 - 4.2) :P
25
25
  mattr_accessor :oid_class
26
26
 
27
- # Cannot assign default inside block because of rails 4.0
28
- self.oid_class =
29
- [
30
- '::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Integer', # 4.0, 4.1
31
- '::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer', # 4.2
32
- '::ActiveRecord::Type::Integer' # 5.0, 5.1
33
- ].find(nil) { |klass|
34
- begin
35
- klass.constantize
36
- true
37
- rescue NameError
38
- false
39
- end
40
- }.constantize
41
-
42
27
  class << self
43
28
  attr_writer :logger
44
29
 
@@ -68,5 +53,29 @@ module ActiveRecord
68
53
  value == true || value == 't' || value == 1 || value == '1'
69
54
  end
70
55
 
56
+ private
57
+
58
+ mattr_accessor :oid_class_candidates
59
+
60
+ # Cannot assign default inside block because of rails 4.0
61
+ self.oid_class_candidates = [
62
+ '::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Integer', # 4.0, 4.1
63
+ '::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer', # 4.2
64
+ '::ActiveRecord::Type::Integer' # 5.0, 5.1
65
+ ]
66
+
67
+ def self.find_oid_class
68
+ oid_class_candidates.find(nil) { |klass|
69
+ begin
70
+ klass.constantize
71
+ true
72
+ rescue NameError
73
+ false
74
+ end
75
+ }.constantize
76
+ end
77
+
78
+ self.oid_class = self.find_oid_class
79
+
71
80
  end
72
81
  end
@@ -22,7 +22,6 @@ module ActiveRecord
22
22
  end
23
23
 
24
24
  def uses_mti(*args)
25
- # ActiveRecord::MTI.logger.
26
25
  warn "DEPRECATED - `uses_mti` is no longer needed (nor has any effect)"
27
26
  end
28
27
 
@@ -117,7 +116,9 @@ module ActiveRecord
117
116
  if self.respond_to? :attribute
118
117
  self.attribute :tableoid, ActiveRecord::MTI.oid_class.new
119
118
  else
120
- columns.unshift ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('tableoid', nil, ActiveRecord::MTI.oid_class.new, "oid", false)
119
+ new_column = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new('tableoid', nil, ActiveRecord::MTI.oid_class.new, "oid", false)
120
+ columns.unshift new_column
121
+ columns_hash['tableoid'] = new_column
121
122
  end
122
123
  end
123
124
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module MTI
3
- VERSION = '0.3.0-rc2'
3
+ VERSION = '0.3.0-rc3'
4
4
  end
5
5
  end
@@ -10,6 +10,10 @@ describe ActiveRecord::MTI::Inheritance do
10
10
  expect(Admin.using_multi_table_inheritance?).to eq(true)
11
11
  end
12
12
 
13
+ it "warns of deprication when using old `uses_mti`" do
14
+ expect { Admin.uses_mti }.to output("DEPRECATED - `uses_mti` is no longer needed (nor has any effect)\n").to_stderr
15
+ end
16
+
13
17
  context 'class definition' do
14
18
 
15
19
  describe 'for classes that use MTI' do
@@ -10,6 +10,15 @@ describe ActiveRecord::MTI do
10
10
  end
11
11
  end
12
12
 
13
+ it "root has the right value" do
14
+ expect(ActiveRecord::MTI.root).not_to be_nil
15
+ end
16
+
17
+ it "recovers if oid class candidate is not constantizable" do
18
+ ActiveRecord::MTI.oid_class_candidates.unshift("IDontExist")
19
+ expect(ActiveRecord::MTI.find_oid_class).not_to be_nil
20
+ end
21
+
13
22
  end
14
23
 
15
24
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
2
 
3
3
  require 'database_cleaner'
4
+ require 'combustion'
4
5
 
5
6
  require 'simplecov'
6
7
  SimpleCov.start do
@@ -8,26 +9,8 @@ SimpleCov.start do
8
9
  add_filter 'spec'
9
10
  end
10
11
 
11
- require 'active_record/mti'
12
-
13
- ActiveRecord::MTI.load
14
-
15
- db_config = {
16
- adapter: 'postgresql', database: 'active_record-mti-test'
17
- }
18
-
19
- db_config_admin = db_config.merge({ database: 'postgres', schema_search_path: 'public' })
20
-
21
- ActiveRecord::Base.establish_connection db_config_admin
22
- ActiveRecord::Base.connection.drop_database(db_config[:database])
23
- ActiveRecord::Base.connection.create_database(db_config[:database])
24
- ActiveRecord::Base.establish_connection db_config
25
-
26
- load File.dirname(__FILE__) + '/schema.rb'
27
-
28
- Dir[ActiveRecord::MTI.root.join('spec', 'support', '**', '**.rb')].each do |f|
29
- require f
30
- end
12
+ Combustion.path = 'spec/support/rails'
13
+ Combustion.initialize! :active_record
31
14
 
32
15
  RSpec.configure do |config|
33
16
  config.order = 'random'
@@ -0,0 +1,3 @@
1
+ class Admin < User
2
+ self.table_name = 'admins'
3
+ end
@@ -0,0 +1,4 @@
1
+ class Comment < ::ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :post
4
+ end
@@ -0,0 +1,4 @@
1
+ class Post < ::ActiveRecord::Base
2
+ belongs_to :user
3
+ has_many :comments
4
+ end
@@ -0,0 +1,7 @@
1
+ module Transportation
2
+ module Military
3
+ class Vehicle < ::Transportation::Vehicle
4
+ self.inheritance_column = 'type'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Transportation
2
+ class Truck < Vehicle
3
+ self.table_name = 'vehicles/trucks'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Transportation
2
+ class Vehicle < ::ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ class User < ::ActiveRecord::Base
2
+
3
+ has_many :posts
4
+ has_many :comments
5
+
6
+ end
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: active_record-mti-test
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ #
3
+ end
@@ -1,4 +1,8 @@
1
1
  ActiveRecord::Schema.define do
2
+
3
+ enable_extension 'pgcrypto'
4
+ enable_extension "uuid-ossp"
5
+
2
6
  self.verbose = false
3
7
 
4
8
  create_table :users, schema: :public, force: true do |t|
@@ -14,12 +18,17 @@ ActiveRecord::Schema.define do
14
18
  t.integer :god_powers
15
19
  end
16
20
 
17
- create_table :posts, force: true do |t|
21
+ create_table :posts, id: :bigserial, force: true do |t|
18
22
  t.integer :user_id
19
23
  t.string :title
20
24
  t.timestamps null: false
21
25
  end
22
26
 
27
+ create_table :post_tags, id: :bigserial, default: nil, primary_key: :post_id, force: true do |t|
28
+ t.string :title
29
+ t.timestamps null: false
30
+ end
31
+
23
32
  create_table :comments, force: true do |t|
24
33
  t.integer :user_id
25
34
  t.integer :post_id
@@ -0,0 +1 @@
1
+ *.log
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-mti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre.rc2
4
+ version: 0.3.0.pre.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-23 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: combustion
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.7'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.7'
89
103
  description: Gives ActiveRecord support for PostgreSQL's native inherited tables
90
104
  email:
91
105
  - dale@twilightcoders.net
@@ -126,9 +140,19 @@ files:
126
140
  - spec/active_record/mti/schema_dumper_spec.rb
127
141
  - spec/active_record/mti_spec.rb
128
142
  - spec/active_record/sti/inheritance_spec.rb
129
- - spec/schema.rb
130
143
  - spec/spec_helper.rb
131
- - spec/support/models.rb
144
+ - spec/support/rails/app/models/admin.rb
145
+ - spec/support/rails/app/models/comment.rb
146
+ - spec/support/rails/app/models/post.rb
147
+ - spec/support/rails/app/models/transportation/military/vehicle.rb
148
+ - spec/support/rails/app/models/transportation/truck.rb
149
+ - spec/support/rails/app/models/transportation/vehicle.rb
150
+ - spec/support/rails/app/models/user.rb
151
+ - spec/support/rails/config/database.yml
152
+ - spec/support/rails/config/routes.rb
153
+ - spec/support/rails/db/schema.rb
154
+ - spec/support/rails/log/.gitignore
155
+ - spec/support/rails/public/favicon.ico
132
156
  homepage: https://github.com/twilightcoders/active_record-mti
133
157
  licenses:
134
158
  - MIT
@@ -162,6 +186,16 @@ test_files:
162
186
  - spec/active_record/mti/schema_dumper_spec.rb
163
187
  - spec/active_record/mti_spec.rb
164
188
  - spec/active_record/sti/inheritance_spec.rb
165
- - spec/schema.rb
166
189
  - spec/spec_helper.rb
167
- - spec/support/models.rb
190
+ - spec/support/rails/app/models/admin.rb
191
+ - spec/support/rails/app/models/comment.rb
192
+ - spec/support/rails/app/models/post.rb
193
+ - spec/support/rails/app/models/transportation/military/vehicle.rb
194
+ - spec/support/rails/app/models/transportation/truck.rb
195
+ - spec/support/rails/app/models/transportation/vehicle.rb
196
+ - spec/support/rails/app/models/user.rb
197
+ - spec/support/rails/config/database.yml
198
+ - spec/support/rails/config/routes.rb
199
+ - spec/support/rails/db/schema.rb
200
+ - spec/support/rails/log/.gitignore
201
+ - spec/support/rails/public/favicon.ico
@@ -1,38 +0,0 @@
1
- require 'active_record'
2
-
3
- class Comment < ::ActiveRecord::Base
4
- belongs_to :user
5
- belongs_to :post
6
-
7
- end
8
-
9
- class Post < ::ActiveRecord::Base
10
- belongs_to :user
11
- has_many :comments
12
- end
13
-
14
- class User < ::ActiveRecord::Base
15
-
16
- has_many :posts
17
- has_many :comments
18
-
19
- end
20
-
21
- class Admin < User
22
- self.table_name = 'admins'
23
- end
24
-
25
- module Transportation
26
- class Vehicle < ::ActiveRecord::Base
27
- end
28
-
29
- class Truck < Vehicle
30
- self.table_name = 'vehicles/trucks'
31
- end
32
-
33
- module Military
34
- class Vehicle < ::Transportation::Vehicle
35
- self.inheritance_column = 'type'
36
- end
37
- end
38
- end