schema_associations 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 395a9d8c36949f31bba7558d51be3dda54be2bfb
4
- data.tar.gz: c6807a2b495005257d0d749de2216625e5332899
3
+ metadata.gz: 6ab213fbc881aef8d05e0b3714f3a63a5de3bc39
4
+ data.tar.gz: c927672d92cc4b0107a7d81af6471a3dae77b146
5
5
  SHA512:
6
- metadata.gz: d4535711d17dc740000c135b41a42816d3dc5be8c0ad616c292870c43e2948b96132e914fd43a964ac3f6646aeb61e58f78c879b8d06353eafaf8638b12eb568
7
- data.tar.gz: 112912f68d8a1f3b20151ac5799fd7f997d63b32ad2386c9464158105a2292fd9cf7b7bf3df924a838378b32739a135ebb7405daa047a193b75ec8034e7bc685
6
+ metadata.gz: c4a53470cb35f36d599e27ff8387ff123cbfd97932b5ab0361f0da13fe1d861d813e2a56739f823b8e7cda2782bd4298adb3759ace20cccdcf55cad621de7522
7
+ data.tar.gz: d700a6e564e723158fe0ea474820dc54467314dadd90e2fc0c0a4c2dd326b1e3af59d46b39463d451b03457597130ce03b6a4e22d5203188346eb95c32b1824e
data/.gitignore CHANGED
@@ -21,7 +21,7 @@ pkg
21
21
  ## PROJECT::SPECIFIC
22
22
  .rvmrc
23
23
  *.log
24
- *.sqlite3
24
+ tmp/
25
25
  Gemfile.lock
26
26
  gemfiles/*.lock
27
27
  gemfiles/**/*.lock
data/.travis.yml CHANGED
@@ -1,12 +1,22 @@
1
+ # This file was auto-generated by the schema_dev tool, based on the data in
2
+ # ./schema_dev.yml
3
+ # Please do not edit this file; any changes will be overwritten next time
4
+ # schema_dev gets run.
5
+ ---
6
+ sudo: false
1
7
  rvm:
2
- - 1.9.3
3
- - 2.1.2
8
+ - 2.1.5
4
9
  gemfile:
5
- - gemfiles/Gemfile.rails-3.2
6
- - gemfiles/Gemfile.rails-4.0
7
- - gemfiles/Gemfile.rails-4.1
10
+ - gemfiles/activerecord-4.2/Gemfile.mysql2
11
+ - gemfiles/activerecord-4.2/Gemfile.postgresql
12
+ - gemfiles/activerecord-4.2/Gemfile.sqlite3
13
+ env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
14
+ addons:
15
+ postgresql: '9.4'
16
+ before_script: bundle exec rake create_databases
17
+ after_script: bundle exec rake drop_databases
18
+ script: bundle exec rake travis
8
19
  notifications:
9
- recipients:
10
- - michal.lomnicki@gmail.com
11
- - ronen@barzel.org
12
- - toby@ovod-everett.org
20
+ email:
21
+ - toby@ovod-everett.org
22
+ - ronen@barzel.org
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.md CHANGED
@@ -4,9 +4,11 @@ SchemaAssociations is an ActiveRecord extension that keeps your model class
4
4
  definitions simpler and more DRY, by automatically defining associations based
5
5
  on the database schema.
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/schema_associations.png)](http://badge.fury.io/rb/schema_associations)
8
- [![Build Status](https://secure.travis-ci.org/lomba/schema_associations.png)](http://travis-ci.org/lomba/schema_associations)
9
- [![Dependency Status](https://gemnasium.com/lomba/schema_associations.png)](https://gemnasium.com/lomba/schema_associations)
7
+ [![Gem Version](https://badge.fury.io/rb/schema_associations.svg)](http://badge.fury.io/rb/schema_associations)
8
+ [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_associations.svg)](http://travis-ci.org/SchemaPlus/schema_associations)
9
+ [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_associations.svg)](https://coveralls.io/r/SchemaPlus/schema_associations?branch=master)
10
+ [![Dependency Status](https://gemnasium.com/lomba/schema_associations.svg)](https://gemnasium.com/lomba/schema_associations)
11
+
10
12
 
11
13
  ## Overview
12
14
 
@@ -156,7 +158,7 @@ referencing table, suffixed with "as" the relationship name. An example
156
158
  should make this clear...
157
159
 
158
160
  Suppose your company hires interns, and each intern is assigned a manager and
159
- a mentor, who are regular employees.
161
+ a mentor, who are regular employees.
160
162
 
161
163
  create_table :interns do |t|
162
164
  t.integer :manager_id, :references => :employees
@@ -253,7 +255,7 @@ turn off concise names globally or per-model, see [SchemaAssociations::Config](h
253
255
  ### Ordering `has_many` using `position`
254
256
 
255
257
  If the target of a `has_many` association has a column named `position`,
256
- SchemaAssociations will specify `:order => :position` for the association.
258
+ SchemaAssociations will specify `:order => :position` for the association.
257
259
  That is,
258
260
 
259
261
  create_table :comments do |t|
@@ -266,13 +268,13 @@ leads to
266
268
  class Post < ActiveRecord::Base
267
269
  has_many :comments, :order => :position
268
270
  end
269
-
271
+
270
272
  ## Table names and model class names
271
273
 
272
- SchemaAssociations determins the mode class name from the table name using the same convention (and helpers) that ActiveRecord uses. But sometimes you might be doing things differently. For example, in an engine you might have a prefix that goes in front of all table names, and the models might all be in a namespace.
274
+ SchemaAssociations determins the mode class name from the table name using the same convention (and helpers) that ActiveRecord uses. But sometimes you might be doing things differently. For example, in an engine you might have a prefix that goes in front of all table names, and the models might all be in a namespace.
273
275
 
274
276
  To that end, SchemaAssociations lets you configure mappings from a table name prefix to a model class name prefix to use instead. For example, suppose your database had tables:
275
-
277
+
276
278
  hpy_campers
277
279
  hpy_go_lucky
278
280
 
@@ -280,12 +282,12 @@ The default model class names would be
280
282
 
281
283
  HpyCampers
282
284
  HpyGoLucky
283
-
285
+
284
286
  But if instead you wanted
285
287
 
286
288
  Happy::Campers
287
289
  Happy::GoLucky
288
-
290
+
289
291
  You could set up this mapping in `config/initializers/schema_associations.rb`:
290
292
 
291
293
  SchemaPlus.setup do |config|
@@ -294,7 +296,7 @@ You could set up this mapping in `config/initializers/schema_associations.rb`:
294
296
 
295
297
  Tables names that don't start with `hpy_` will continue to use the default determination.
296
298
 
297
- You can set up multiple mappings. E.g. if you're using several engines they can each set up the mapping for their own moduels.
299
+ You can set up multiple mappings. E.g. if you're using several engines they can each set up the mapping for their own moduels.
298
300
 
299
301
  You can set up a mapping from or to the empty string, in order to unconditionally add or remove prefixes from all model class names.
300
302
 
@@ -303,7 +305,7 @@ You can set up a mapping from or to the empty string, in order to unconditionall
303
305
 
304
306
  If you're curious (or dubious) about what associations SchemaAssociations
305
307
  defines, you can check the log file. For every assocation that
306
- SchemaAssociations defines, it generates an info entry such as
308
+ SchemaAssociations defines, it generates a debug entry such as
307
309
 
308
310
  [schema_associations] Post.has_many :comments, :class_name "Comment", :foreign_key "comment_id"
309
311
 
@@ -319,10 +321,17 @@ use cases that you logged).
319
321
 
320
322
  SchemaAssociations is tested on all combinations of:
321
323
 
322
- * Rails 3.2, 4.0, or 4.1
323
- * MRI ruby 1.9.3 or 2.1.2
324
+ <!-- SCHEMA_DEV: MATRIX - begin -->
325
+ <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
326
+ * ruby **2.1.5** with activerecord **4.2**, using **mysql2**, **postgresql** or **sqlite3**
327
+
328
+ <!-- SCHEMA_DEV: MATRIX - end -->
329
+
330
+ Notes:
324
331
 
325
- Note: As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported. As of version 1.2.0, ruby 1.9.2 is no longer supported.
332
+ * As of version 1.2.3, rails < 4.1 and ruby < 2.1 are no longer supported
333
+ * As of version 1.2.0, ruby 1.9.2 is no longer supported.
334
+ * As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported.
326
335
 
327
336
  ## Installation
328
337
 
@@ -336,23 +345,25 @@ or in a Gemfile
336
345
 
337
346
  ## Testing
338
347
 
339
- SchemaAssociations is tested using rspec, sqlite3, and rvm, with some hackery
340
- to test against multiple versions of rails and ruby. To run the full combo of
341
- tests, after you've forked & cloned:
348
+ SchemaAssociations is tested against the matrix of combinations. To run the full combo of
349
+ tests, after you've forked & cloned:
342
350
 
343
351
  $ cd schema_associations
344
- $ ./runspecs --install # do this once to install gem dependencies for all versions (slow)
345
- $ ./runspecs # as many times as you like
352
+ $ schema_dev bundle install
353
+ $ schema_dev rspec
346
354
 
347
- See `./runspecs --help` for more options. In particular, to run rspec on a
348
- specific file or example (rather than running the full suite) you can do, e.g.
349
-
350
- $ ./runspecs [other options] --rspec -- spec/association_spec.rb -e 'base'
355
+ For more info, see [schema_dev](https://github.com/SchemaPlus/schema_dev)
351
356
 
352
357
  Code coverage results will be in coverage/index.html -- it should be at 100% coverage.
353
358
 
354
359
  ## Release notes:
355
360
 
361
+ ### 1.2.3
362
+
363
+ * Use schema_plus_foreign_keys rather than all of schema_plus, to eliminate unneeded dependancies. That limits us to AR >= 4.1 and ruby >= 2.1
364
+ * Fix deprecations
365
+ * Logging is now at `debug` level rather than `info` level
366
+
356
367
  ### 1.2.2
357
368
 
358
369
  * Bug fix (Rails workaround) for STI: propagate associations to subclasses, since Rails might not, depending on the load order.
@@ -373,7 +384,7 @@ Code coverage results will be in coverage/index.html -- it should be at 100% cov
373
384
 
374
385
  ### 1.0.1
375
386
 
376
- * Bug fix: use singular :inverse_of for :belongs_to of a :has_one
387
+ * Bug fix: use singular :inverse_of for :belongs_to of a :has_one
377
388
 
378
389
 
379
390
  ### 1.0.0
@@ -395,7 +406,3 @@ Code coverage results will be in coverage/index.html -- it should be at 100% cov
395
406
  ## License
396
407
 
397
408
  This gem is released under the MIT license.
398
-
399
-
400
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lomba/schema_associations/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
401
-
data/Rakefile CHANGED
@@ -2,9 +2,9 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec) do |spec|
6
- spec.rspec_opts = '-Ispec'
7
- end
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ require 'schema_dev/tasks'
8
8
 
9
9
 
10
10
  task :default => :spec
@@ -18,42 +18,3 @@ Rake::RDocTask.new do |rdoc|
18
18
  rdoc.rdoc_files.include('README*')
19
19
  rdoc.rdoc_files.include('lib/**/*.rb')
20
20
  end
21
-
22
- namespace :postgresql do
23
- desc 'Build the PostgreSQL test databases'
24
- task :build_databases do
25
- %x( createdb -E UTF8 schema_associations_unittest )
26
- end
27
-
28
- desc 'Drop the PostgreSQL test databases'
29
- task :drop_databases do
30
- %x( dropdb schema_associations_unittest )
31
- end
32
-
33
- desc 'Rebuild the PostgreSQL test databases'
34
- task :rebuild_databases => [:drop_databases, :build_databases]
35
- end
36
-
37
- task :build_postgresql_databases => 'postgresql:build_databases'
38
- task :drop_postgresql_databases => 'postgresql:drop_databases'
39
- task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
40
-
41
- MYSQL_DB_USER = 'schema_assoc'
42
- namespace :mysql do
43
- desc 'Build the MySQL test databases'
44
- task :build_databases do
45
- %x( echo "create DATABASE schema_associations_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER})
46
- end
47
-
48
- desc 'Drop the MySQL test databases'
49
- task :drop_databases do
50
- %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop schema_associations_unittest )
51
- end
52
-
53
- desc 'Rebuild the MySQL test databases'
54
- task :rebuild_databases => [:drop_databases, :build_databases]
55
- end
56
-
57
- task :build_mysql_databases => 'mysql:build_databases'
58
- task :drop_mysql_databases => 'mysql:drop_databases'
59
- task :rebuild_mysql_databases => 'mysql:rebuild_databases'
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec :path => File.expand_path('..', __FILE__)
3
3
 
4
- gem "byebug" if RUBY_VERSION > "2"
4
+ File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "activerecord", "~> 4.2.0"
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -1,4 +1,4 @@
1
- require 'schema_plus'
1
+ require 'schema_plus_foreign_keys'
2
2
  require 'valuable'
3
3
 
4
4
  require 'schema_associations/version'
@@ -83,9 +83,9 @@ module SchemaAssociations
83
83
  return unless schema_associations_config.auto_create?
84
84
 
85
85
  reverse_foreign_keys.each do | foreign_key |
86
- if foreign_key.table_name =~ /^#{table_name}_(.*)$/ || foreign_key.table_name =~ /^(.*)_#{table_name}$/
86
+ if foreign_key.from_table =~ /^#{table_name}_(.*)$/ || foreign_key.from_table =~ /^(.*)_#{table_name}$/
87
87
  other_table = $1
88
- if other_table == other_table.pluralize and connection.columns(foreign_key.table_name).any?{|col| col.name == "#{other_table.singularize}_id"}
88
+ if other_table == other_table.pluralize and connection.columns(foreign_key.from_table).any?{|col| col.name == "#{other_table.singularize}_id"}
89
89
  _define_association(:has_and_belongs_to_many, foreign_key, other_table)
90
90
  else
91
91
  _define_association(:has_one_or_many, foreign_key)
@@ -101,12 +101,13 @@ module SchemaAssociations
101
101
  end
102
102
 
103
103
  def _define_association(macro, fk, referencing_table_name = nil) #:nodoc:
104
- return unless fk.column_names.size == 1
104
+ column_names = Array.wrap(fk.column)
105
+ return unless column_names.size == 1
105
106
 
106
- referencing_table_name ||= fk.table_name
107
- column_name = fk.column_names.first
107
+ referencing_table_name ||= fk.from_table
108
+ column_name = column_names.first
108
109
 
109
- references_name = fk.references_table_name.singularize
110
+ references_name = fk.to_table.singularize
110
111
  referencing_name = referencing_table_name.singularize
111
112
 
112
113
  referencing_class_name = _get_class_name(referencing_name)
@@ -120,7 +121,7 @@ module SchemaAssociations
120
121
  case macro
121
122
  when :has_and_belongs_to_many
122
123
  name = names[:has_many]
123
- opts = {:class_name => referencing_class_name, :join_table => fk.table_name, :foreign_key => column_name}
124
+ opts = {:class_name => referencing_class_name, :join_table => fk.from_table, :foreign_key => column_name}
124
125
  when :belongs_to
125
126
  name = names[:belongs_to]
126
127
  opts = {:class_name => references_class_name, :foreign_key => column_name}
@@ -144,31 +145,22 @@ module SchemaAssociations
144
145
  macro = :has_many
145
146
  name = names[:has_many]
146
147
  if connection.columns(referencing_table_name).any?{ |col| col.name == 'position' }
147
- if ::ActiveRecord::VERSION::MAJOR.to_i < 4
148
- opts[:order] = :position
149
- else
150
- scope_block = lambda { order :position }
151
- argstr += "-> { order :position }, "
152
- end
148
+ scope_block = lambda { order :position }
149
+ argstr += "-> { order :position }, "
153
150
  end
154
151
  end
155
152
  end
156
153
  argstr += opts.inspect[1...-1]
157
154
  if (_filter_association(macro, name) && !_method_exists?(name))
158
- if ::ActiveRecord::VERSION::MAJOR.to_i < 4
159
- _create_association(macro, name, argstr, opts.dup)
160
- else
161
- _create_association(macro, name, argstr, scope_block, opts.dup)
162
- end
155
+ _create_association(macro, name, argstr, scope_block, opts.dup)
163
156
  end
164
157
  end
165
158
 
166
159
  def _create_association(macro, name, argstr, *args)
167
- logger.info "[schema_associations] #{self.name || self.table_name.classify}.#{macro} #{name.inspect}, #{argstr}"
160
+ logger.debug "[schema_associations] #{self.name || self.from_table.classify}.#{macro} #{name.inspect}, #{argstr}"
168
161
  send macro, name, *args
169
- case
162
+ case
170
163
  when respond_to?(:subclasses) then subclasses
171
- when respond_to?(:descendants) then descendants
172
164
  end.each do |subclass|
173
165
  subclass.send :_create_association, macro, name, argstr, *args
174
166
  end
@@ -1,4 +1,4 @@
1
- module SchemaAssociations
1
+ module SchemaAssociations
2
2
  class Railtie < Rails::Railtie #:nodoc:
3
3
 
4
4
  initializer 'schema_associations.insert', :after => :load_config_initializers do
@@ -1,3 +1,3 @@
1
1
  module SchemaAssociations
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Ronen Barzel", "Michał Łomnicki"]
10
10
  s.email = ["ronen@barzel.org", "michal.lomnicki@gmail.com"]
11
- s.homepage = "https://github.com/lomba/schema_associations"
11
+ s.homepage = "https://github.com/SchemaPlus/schema_associations"
12
12
  s.summary = "ActiveRecord extension that automatically (DRY) creates associations based on the schema"
13
13
  s.description = "SchemaAssociations extends ActiveRecord to automatically create associations by inspecting the database schema. This is more more DRY than the standard behavior, for which in addition to specifying the foreign key in the migration, you must also specify complementary associations in two model files (e.g. a :belongs_to and a :has_many)."
14
14
 
@@ -19,12 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency("schema_plus", ">= 1.2.0")
22
+ s.add_dependency("schema_plus_foreign_keys", "~> 0.1")
23
23
 
24
+ s.add_development_dependency("schema_dev", "~> 3.5")
24
25
  s.add_development_dependency("rake")
25
26
  s.add_development_dependency("rdoc")
26
27
  s.add_development_dependency("rspec")
27
- s.add_development_dependency("sqlite3")
28
28
  s.add_development_dependency("simplecov")
29
29
  s.add_development_dependency("simplecov-gem-profile")
30
30
  end
data/schema_dev.yml ADDED
@@ -0,0 +1,11 @@
1
+ ruby:
2
+ - 2.1.5
3
+ activerecord:
4
+ - 4.2
5
+ db:
6
+ - mysql2
7
+ - postgresql
8
+ - sqlite3
9
+ notify:
10
+ - toby@ovod-everett.org
11
+ - ronen@barzel.org
@@ -11,7 +11,7 @@ describe ActiveRecord::Base do
11
11
  before(:each) do
12
12
  create_tables(
13
13
  "posts", {}, {},
14
- "comments", {}, { :post_id => {} }
14
+ "comments", {}, { :post_id => {foreign_key: true} }
15
15
  )
16
16
  class Post < ActiveRecord::Base ; end
17
17
  class Comment < ActiveRecord::Base ; end
@@ -72,11 +72,11 @@ describe ActiveRecord::Base do
72
72
  "owners", {}, {},
73
73
  "colors", {}, {},
74
74
  "widgets", {}, {
75
- :owner_id => {},
75
+ :owner_id => { foreign_key: true },
76
76
  },
77
- "parts", {}, { :widget_id => {} },
78
- "manifests", {}, { :widget_id => { :index => {:unique => true}} },
79
- "colors_widgets", {:id => false}, { :widget_id => {}, :color_id => {} }
77
+ "parts", {}, { :widget_id => { foreign_key: true } },
78
+ "manifests", {}, { :widget_id => { foreign_key: true, :index => {:unique => true}} },
79
+ "colors_widgets", {:id => false}, { :widget_id => { foreign_key: true}, :color_id => { foreign_key: true} }
80
80
  )
81
81
  end
82
82
 
@@ -95,70 +95,70 @@ describe ActiveRecord::Base do
95
95
  check_reflections(:owner => true, :colors => true, :parts => true, :manifest => true)
96
96
  end
97
97
 
98
- it "should respect :only" do
98
+ it "should respect :only" do
99
99
  class Widget < ActiveRecord::Base
100
100
  schema_associations :only => :owner
101
101
  end
102
102
  check_reflections(:owner => true, :colors => false, :parts => false, :manifest => false)
103
103
  end
104
104
 
105
- it "should respect :except" do
105
+ it "should respect :except" do
106
106
  class Widget < ActiveRecord::Base
107
107
  schema_associations :except => :owner
108
108
  end
109
109
  check_reflections(:owner => false, :colors => true, :parts => true, :manifest => true)
110
110
  end
111
111
 
112
- it "should respect :only_type :belongs_to" do
112
+ it "should respect :only_type :belongs_to" do
113
113
  class Widget < ActiveRecord::Base
114
114
  schema_associations :only_type => :belongs_to
115
115
  end
116
116
  check_reflections(:owner => true, :colors => false, :parts => false, :manifest => false)
117
117
  end
118
118
 
119
- it "should respect :except_type :belongs_to" do
119
+ it "should respect :except_type :belongs_to" do
120
120
  class Widget < ActiveRecord::Base
121
121
  schema_associations :except_type => :belongs_to
122
122
  end
123
123
  check_reflections(:owner => false, :colors => true, :parts => true, :manifest => true)
124
124
  end
125
125
 
126
- it "should respect :only_type :has_many" do
126
+ it "should respect :only_type :has_many" do
127
127
  class Widget < ActiveRecord::Base
128
128
  schema_associations :only_type => :has_many
129
129
  end
130
130
  check_reflections(:owner => false, :colors => false, :parts => true, :manifest => false)
131
131
  end
132
132
 
133
- it "should respect :except_type :has_many" do
133
+ it "should respect :except_type :has_many" do
134
134
  class Widget < ActiveRecord::Base
135
135
  schema_associations :except_type => :has_many
136
136
  end
137
137
  check_reflections(:owner => true, :colors => true, :parts => false, :manifest => true)
138
138
  end
139
139
 
140
- it "should respect :only_type :has_one" do
140
+ it "should respect :only_type :has_one" do
141
141
  class Widget < ActiveRecord::Base
142
142
  schema_associations :only_type => :has_one
143
143
  end
144
144
  check_reflections(:owner => false, :colors => false, :parts => false, :manifest => true)
145
145
  end
146
146
 
147
- it "should respect :except_type :has_one" do
147
+ it "should respect :except_type :has_one" do
148
148
  class Widget < ActiveRecord::Base
149
149
  schema_associations :except_type => :has_one
150
150
  end
151
151
  check_reflections(:owner => true, :colors => true, :parts => true, :manifest => false)
152
152
  end
153
153
 
154
- it "should respect :only_type :has_and_belongs_to_many" do
154
+ it "should respect :only_type :has_and_belongs_to_many" do
155
155
  class Widget < ActiveRecord::Base
156
156
  schema_associations :only_type => :has_and_belongs_to_many
157
157
  end
158
158
  check_reflections(:owner => false, :colors => true, :parts => false, :manifest => false)
159
159
  end
160
160
 
161
- it "should respect :except_type :has_and_belongs_to_many" do
161
+ it "should respect :except_type :has_and_belongs_to_many" do
162
162
  class Widget < ActiveRecord::Base
163
163
  schema_associations :except_type => :has_and_belongs_to_many
164
164
  end
@@ -172,7 +172,7 @@ describe ActiveRecord::Base do
172
172
  with_associations_auto_create(true) do
173
173
  create_tables(
174
174
  "posts", {}, {},
175
- "comments", {}, { :post_id => {} }
175
+ "comments", {}, { :post_id => {foreign_key: true} }
176
176
  )
177
177
  class Post < ActiveRecord::Base
178
178
  schema_associations :auto_create => false
@@ -188,7 +188,7 @@ describe ActiveRecord::Base do
188
188
  with_associations_auto_create(false) do
189
189
  create_tables(
190
190
  "posts", {}, {},
191
- "comments", {}, { :post_id => {} }
191
+ "comments", {}, { :post_id => {foreign_key: true} }
192
192
  )
193
193
  class Post < ActiveRecord::Base
194
194
  schema_associations :auto_create => true
@@ -203,7 +203,7 @@ describe ActiveRecord::Base do
203
203
  with_associations_auto_create(false) do
204
204
  create_tables(
205
205
  "posts", {}, {},
206
- "comments", {}, { :post_id => {} }
206
+ "comments", {}, { :post_id => {foreign_key: true} }
207
207
  )
208
208
  class Post < ActiveRecord::Base
209
209
  schema_associations
@@ -220,7 +220,7 @@ describe ActiveRecord::Base do
220
220
  before(:each) do
221
221
  create_tables(
222
222
  "posts", {}, {},
223
- "comments", {}, { :post_id => {:index => { :unique => true} } }
223
+ "comments", {}, { :post_id => {foreign_key: true, :index => { :unique => true} } }
224
224
  )
225
225
  class Post < ActiveRecord::Base ; end
226
226
  class Comment < ActiveRecord::Base ; end
@@ -247,7 +247,7 @@ describe ActiveRecord::Base do
247
247
  before(:each) do
248
248
  create_tables(
249
249
  "posts", {}, {},
250
- "comments", {}, { :subject_post_id => { :references => :posts} }
250
+ "comments", {}, { :subject_post_id => { foreign_key: { references: "posts" }} }
251
251
  )
252
252
  class Post < ActiveRecord::Base ; end
253
253
  class Comment < ActiveRecord::Base ; end
@@ -275,7 +275,7 @@ describe ActiveRecord::Base do
275
275
  before(:each) do
276
276
  create_tables(
277
277
  "posts", {}, {},
278
- "comments", {}, { :post_cited => { :references => :posts} }
278
+ "comments", {}, { :post_cited => { foreign_key: {references: "posts" }} }
279
279
  )
280
280
  class Post < ActiveRecord::Base ; end
281
281
  class Comment < ActiveRecord::Base ; end
@@ -303,7 +303,7 @@ describe ActiveRecord::Base do
303
303
  before(:each) do
304
304
  create_tables(
305
305
  "posts", {}, {},
306
- "comments", {}, { :subject => {:references => :posts} }
306
+ "comments", {}, { :subject => {foreign_key: { references: "posts" }} }
307
307
  )
308
308
  class Post < ActiveRecord::Base ; end
309
309
  class Comment < ActiveRecord::Base ; end
@@ -331,7 +331,7 @@ describe ActiveRecord::Base do
331
331
  with_associations_config(:table_prefix_map => { "wooga_" => "Happy"} ) do
332
332
  create_tables(
333
333
  "wooga_posts", {}, {},
334
- "wooga_comments", {}, { :wooga_post_id => { :references => :wooga_posts} }
334
+ "wooga_comments", {}, { :wooga_post_id => { foreign_key: true} }
335
335
  )
336
336
  class HappyPost < ActiveRecord::Base ; self.table_name = 'wooga_posts' ; end
337
337
  class HappyComment < ActiveRecord::Base ; self.table_name = 'wooga_comments' ; end
@@ -345,7 +345,7 @@ describe ActiveRecord::Base do
345
345
  before(:each) do
346
346
  create_tables(
347
347
  "posts", {}, {},
348
- "comments", {}, { :post_id => {} }
348
+ "comments", {}, { :post_id => { foreign_key: true} }
349
349
  )
350
350
  class Post < ActiveRecord::Base ; end
351
351
  class Comment < ActiveRecord::Base ; end
@@ -369,7 +369,7 @@ describe ActiveRecord::Base do
369
369
  before(:each) do
370
370
  create_tables(
371
371
  "posts", {}, {},
372
- "comments", {}, { :post_id => {}, :position => {} }
372
+ "comments", {}, { :post_id => {foreign_key: true}, :position => {} }
373
373
  )
374
374
  class Post < ActiveRecord::Base ; end
375
375
  class Comment < ActiveRecord::Base ; end
@@ -432,7 +432,7 @@ describe ActiveRecord::Base do
432
432
 
433
433
  before(:each) do
434
434
  create_tables(
435
- "nodes", {:foreign_keys => {:auto_index => false}}, { :parent_id => {} }
435
+ "nodes", {}, { :parent_id => { foreign_key: true} }
436
436
  )
437
437
  end
438
438
 
@@ -458,7 +458,7 @@ describe ActiveRecord::Base do
458
458
  def prefix_one
459
459
  create_tables(
460
460
  "posts", {}, {},
461
- "post_comments", {}, { :post_id => {} }
461
+ "post_comments", {}, { :post_id => { foreign_key: true} }
462
462
  )
463
463
  Object.const_set(:Post, Class.new(ActiveRecord::Base))
464
464
  Object.const_set(:PostComment, Class.new(ActiveRecord::Base))
@@ -467,7 +467,7 @@ describe ActiveRecord::Base do
467
467
  def suffix_one
468
468
  create_tables(
469
469
  "posts", {}, {},
470
- "comment_posts", {}, { :post_id => {} }
470
+ "comment_posts", {}, { :post_id => { foreign_key: true} }
471
471
  )
472
472
  Object.const_set(:Post, Class.new(ActiveRecord::Base))
473
473
  Object.const_set(:CommentPost, Class.new(ActiveRecord::Base))
@@ -476,7 +476,7 @@ describe ActiveRecord::Base do
476
476
  def prefix_both
477
477
  create_tables(
478
478
  "blog_page_posts", {}, {},
479
- "blog_page_comments", {}, { :blog_page_post_id => {} }
479
+ "blog_page_comments", {}, { :blog_page_post_id => { foreign_key: true} }
480
480
  )
481
481
  Object.const_set(:BlogPagePost, Class.new(ActiveRecord::Base))
482
482
  Object.const_set(:BlogPageComment, Class.new(ActiveRecord::Base))
@@ -554,7 +554,7 @@ describe ActiveRecord::Base do
554
554
  create_tables(
555
555
  "posts", {}, {},
556
556
  "tags", {}, {},
557
- "posts_tags", {:id => false}, { :post_id => {}, :tag_id => {}}
557
+ "posts_tags", {:id => false}, { :post_id => { foreign_key: true}, :tag_id => { foreign_key: true}}
558
558
  )
559
559
  class Post < ActiveRecord::Base ; end
560
560
  class Tag < ActiveRecord::Base ; end
@@ -572,7 +572,7 @@ describe ActiveRecord::Base do
572
572
  before(:each) do
573
573
  create_tables(
574
574
  "types", {}, {},
575
- "posts", {}, {:type_id => {}}
575
+ "posts", {}, {:type_id => { foreign_key: true}}
576
576
  )
577
577
  end
578
578
  it "should define association normally if no existing method is defined" do
@@ -614,9 +614,9 @@ describe ActiveRecord::Base do
614
614
  before(:each) do
615
615
  create_tables(
616
616
  "posts", {}, {},
617
- "comments", {}, { :post_id => {}, :type => {coltype: :string} },
617
+ "comments", {}, { :post_id => { foreign_key: true}, :type => {coltype: :string} },
618
618
  "citers", {}, {},
619
- "citations", {}, { :comment_id => {}, :citer_id => {}}
619
+ "citations", {}, { :comment_id => { foreign_key: true}, :citer_id => { foreign_key: true}}
620
620
  )
621
621
  class Post < ActiveRecord::Base ; end
622
622
  class Comment < ActiveRecord::Base ; end
@@ -643,7 +643,7 @@ describe ActiveRecord::Base do
643
643
  before(:each) do
644
644
  create_tables(
645
645
  "posts", {}, {},
646
- "comments", {}, { :post_id => {} }
646
+ "comments", {}, { :post_id => { foreign_key: true} }
647
647
  )
648
648
  class Post < ActiveRecord::Base ; end
649
649
  class Comment < ActiveRecord::Base ; end
@@ -676,7 +676,7 @@ describe ActiveRecord::Base do
676
676
  def create_tables(*table_defs)
677
677
  ActiveRecord::Migration.suppress_messages do
678
678
  ActiveRecord::Base.connection.tables.each do |table|
679
- ActiveRecord::Migration.drop_table table
679
+ ActiveRecord::Migration.drop_table table, force: :cascade
680
680
  end
681
681
  table_defs.each_slice(3) do |table_name, opts, columns_with_options|
682
682
  ActiveRecord::Migration.create_table table_name, opts do |t|
Binary file
data/spec/spec_helper.rb CHANGED
@@ -9,9 +9,9 @@ require 'rspec'
9
9
  require 'active_record'
10
10
  require 'schema_associations'
11
11
  require 'logger'
12
- require 'connection'
12
+ require 'schema_dev/rspec'
13
13
 
14
- ActiveRecord::Base.logger = Logger.new(File.open("spec.log", "w"))
14
+ SchemaDev::Rspec::setup_db
15
15
 
16
16
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,38 +9,38 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-18 00:00:00.000000000 Z
12
+ date: 2015-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: schema_plus
15
+ name: schema_plus_foreign_keys
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.2.0
20
+ version: '0.1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 1.2.0
27
+ version: '0.1'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
29
+ name: schema_dev
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: '3.5'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: '3.5'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rdoc
43
+ name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rspec
57
+ name: rdoc
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -68,7 +68,7 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: sqlite3
71
+ name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
@@ -123,24 +123,26 @@ extra_rdoc_files: []
123
123
  files:
124
124
  - ".gitignore"
125
125
  - ".travis.yml"
126
+ - Gemfile
126
127
  - MIT-LICENSE
127
128
  - README.md
128
129
  - Rakefile
129
130
  - gemfiles/Gemfile.base
130
- - gemfiles/Gemfile.rails-3.2
131
- - gemfiles/Gemfile.rails-4.0
132
- - gemfiles/Gemfile.rails-4.1
131
+ - gemfiles/activerecord-4.2/Gemfile.base
132
+ - gemfiles/activerecord-4.2/Gemfile.mysql2
133
+ - gemfiles/activerecord-4.2/Gemfile.postgresql
134
+ - gemfiles/activerecord-4.2/Gemfile.sqlite3
133
135
  - init.rb
134
136
  - lib/schema_associations.rb
135
137
  - lib/schema_associations/active_record/associations.rb
136
138
  - lib/schema_associations/railtie.rb
137
139
  - lib/schema_associations/version.rb
138
- - runspecs
139
140
  - schema_associations.gemspec
141
+ - schema_dev.yml
140
142
  - spec/association_spec.rb
141
- - spec/connection.rb
143
+ - spec/schema_associations.sqlite3
142
144
  - spec/spec_helper.rb
143
- homepage: https://github.com/lomba/schema_associations
145
+ homepage: https://github.com/SchemaPlus/schema_associations
144
146
  licenses: []
145
147
  metadata: {}
146
148
  post_install_message:
@@ -166,6 +168,5 @@ summary: ActiveRecord extension that automatically (DRY) creates associations ba
166
168
  on the schema
167
169
  test_files:
168
170
  - spec/association_spec.rb
169
- - spec/connection.rb
171
+ - spec/schema_associations.sqlite3
170
172
  - spec/spec_helper.rb
171
- has_rdoc:
@@ -1,3 +0,0 @@
1
- eval File.read File.expand_path('../Gemfile.base', __FILE__)
2
-
3
- gem "rails", "~> 3.2.0"
@@ -1,3 +0,0 @@
1
- eval File.read File.expand_path('../Gemfile.base', __FILE__)
2
-
3
- gem "rails", "~> 4.0.0"
@@ -1,3 +0,0 @@
1
- eval File.read File.expand_path('../Gemfile.base', __FILE__)
2
-
3
- gem "rails", "~> 4.1.0"
data/runspecs DELETED
@@ -1,113 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'ostruct'
5
- require 'shellwords'
6
- require 'tempfile'
7
-
8
- RUBY_VERSIONS = %W[1.9.3 2.1.2]
9
- RAILS_VERSIONS = %W[3.2 4.0 4.1]
10
-
11
- o = OpenStruct.new
12
- o.ruby_versions = RUBY_VERSIONS
13
- o.rails_versions = RAILS_VERSIONS
14
-
15
- OptionParser.new do |opts|
16
- opts.banner = "Usage: #{$0} [options]"
17
-
18
- opts.on("-n", "--dry-run", "Do a dry run without executing actions") do |v|
19
- o.dry_run = true
20
- end
21
-
22
- opts.on("--update", "Update gem dependencies") do |v|
23
- o.update = v
24
- end
25
-
26
- opts.on("--install", "Install gem dependencies") do |v|
27
- o.install = v
28
- end
29
-
30
- opts.on("--ruby version", String, "Choose which version(s) of ruby to run. Default is: #{o.ruby_versions.join(' ')}") do |ruby|
31
- o.ruby_versions = ruby.split(' ')
32
- end
33
-
34
- opts.on("--rails version", String, "Choose which version(s) of rails to run. Default is: #{o.rails_versions.join(' ')}") do |rails|
35
- o.rails_versions = rails.split(' ')
36
- end
37
-
38
- opts.on("--quick", "quick run ruby #{RUBY_VERSIONS.last} and rails #{RAILS_VERSIONS.last}") do
39
- o.ruby_versions = [RUBY_VERSIONS.last]
40
- o.rails_versions = [RAILS_VERSIONS.last]
41
- end
42
-
43
- opts.on("--rspec", "run rspec rather than rake") do |v|
44
- o.rspec = v
45
- end
46
-
47
- end.parse!
48
-
49
-
50
- Combo = Struct.new(:ruby, :rails)
51
-
52
- combos = o.ruby_versions.product(o.rails_versions).map{|product| Combo.new(*product)}.select {|combo|
53
- case
54
- when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false # no longer happens, just keeping it as an example
55
- else true
56
- end
57
- }
58
-
59
- if system("which -s rvm")
60
- # using rvm
61
- def ruby_version_selector(ruby)
62
- "rvm #{ruby} do"
63
- end
64
- else
65
- # using rbenv.
66
- #
67
- # because we're running within a ruby program that was launched by
68
- # rbenv, we already have various environment variables set up. need
69
- # strip those out so that the forked shell can run a diifferent ruby
70
- # version than the one we're in now.
71
- ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv/(?!shims)}}.join(':')
72
- ENV['GEM_PATH'] = ENV['GEM_PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv}}.join(':') unless ENV['GEM_PATH'].nil?
73
- ENV['RBENV_DIR'] = nil
74
- ENV['RBENV_HOOK_PATH'] = nil
75
-
76
- def ruby_version_selector(ruby)
77
- @versions ||= `rbenv versions --bare`.split
78
- version = @versions.select{|v| v.start_with? ruby}.last || abort("no ruby version '#{ruby}' installed in rbenv")
79
- "RBENV_VERSION=#{version}"
80
- end
81
- end
82
-
83
- GEMFILES_DIR = File.expand_path('../gemfiles', __FILE__)
84
- errs = []
85
- combos.each_with_index do |combo, n|
86
- ruby = combo.ruby
87
- rails = combo.rails
88
-
89
- cmd = case
90
- when o.update
91
- "bundle update"
92
- when o.install
93
- "bundle install"
94
- when o.rspec
95
- "bundle exec rspec"
96
- else
97
- "bundle exec rake spec"
98
- end
99
-
100
- command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}" #{ruby_version_selector(ruby)} #{cmd} #{Shellwords.join(ARGV)}}
101
-
102
- puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n+1} of #{combos.size}]\n\n#{command}"
103
-
104
- next if o.dry_run
105
-
106
- Tempfile.open('runspecs') do |file|
107
- system("(#{command}) 2>&1 | tee #{file.path}")
108
- file.rewind
109
- errs << "ruby #{ruby}, rails #{rails}" if file.readlines.grep(/(^Failed examples)|(rake aborted)/).any?
110
- end
111
- end
112
- puts errs.any? ? "\n*** #{errs.size} failures:\n\t#{errs.join("\n\t")}" : "\n*** #{combos.size > 1 ? 'all versions' : 'spec'} succeeded ***" unless o.dry_run
113
- exit !errs.any?
data/spec/connection.rb DELETED
@@ -1,11 +0,0 @@
1
-
2
- ActiveRecord::Base.configurations = {
3
- 'schema_associations' => {
4
- :adapter => 'sqlite3',
5
- :database => File.expand_path('schema_associations.sqlite3', File.dirname(__FILE__)),
6
- }
7
-
8
- }
9
-
10
- ActiveRecord::Base.establish_connection :schema_associations
11
- ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"