foreigner 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -31,7 +31,7 @@ For example, given the following model:
31
31
  end
32
32
 
33
33
  class Post < ActiveRecord::Base
34
- has_many :comments, :dependent => :delete_all
34
+ has_many :comments, dependent: :delete_all
35
35
  end
36
36
 
37
37
  You should add a foreign key in your migration:
@@ -40,15 +40,15 @@ You should add a foreign key in your migration:
40
40
 
41
41
  The :dependent option can be moved from the has_many definition to the foreign key:
42
42
 
43
- add_foreign_key(:comments, :posts, :dependent => :delete)
43
+ add_foreign_key(:comments, :posts, dependent: :delete)
44
44
 
45
45
  If the column is named article_id instead of post_id, use the :column option:
46
46
 
47
- add_foreign_key(:comments, :posts, :column => 'article_id')
47
+ add_foreign_key(:comments, :posts, column: 'article_id')
48
48
 
49
49
  A name can be specified for the foreign key constraint:
50
50
 
51
- add_foreign_key(:comments, :posts, :name => 'comment_article_foreign_key')
51
+ add_foreign_key(:comments, :posts, name: 'comment_article_foreign_key')
52
52
 
53
53
  == Change Table Methods
54
54
 
@@ -57,7 +57,7 @@ Foreigner adds extra methods to change_table.
57
57
  Add a missing foreign key to comments:
58
58
 
59
59
  change_table :comments do |t|
60
- t.foreign_key :posts, :dependent => :delete
60
+ t.foreign_key :posts, dependent: :delete
61
61
  end
62
62
 
63
63
  Remove an unwanted foreign key:
@@ -66,6 +66,10 @@ Remove an unwanted foreign key:
66
66
  t.remove_foreign_key :users
67
67
  end
68
68
 
69
+ == Finding Missing Foreign Keys
70
+
71
+ Use {Immigrant}[https://github.com/jenseng/immigrant] to generate a migration that includes all missing foreign keys.
72
+
69
73
  == License
70
74
 
71
75
  Copyright (c) 2012 Matthew Higgins, released under the MIT license
data/lib/foreigner.rb CHANGED
@@ -26,6 +26,7 @@ Foreigner::Adapter.register 'mysql2', 'foreigner/connection_adapters/mysql2_adap
26
26
  Foreigner::Adapter.register 'jdbcmysql', 'foreigner/connection_adapters/mysql2_adapter'
27
27
  Foreigner::Adapter.register 'postgresql', 'foreigner/connection_adapters/postgresql_adapter'
28
28
  Foreigner::Adapter.register 'jdbcpostgresql', 'foreigner/connection_adapters/postgresql_adapter'
29
+ Foreigner::Adapter.register 'sqlite3', 'foreigner/connection_adapters/noop_adapter'
29
30
 
30
31
  require 'foreigner/loader'
31
32
  require 'foreigner/railtie' if defined?(Rails)
@@ -11,11 +11,14 @@ module Foreigner
11
11
  def load!
12
12
  if registered.key?(configured_name)
13
13
  require registered[configured_name]
14
+ else
15
+ p "Database adapter #{configured_name} not supported. Use:\n" +
16
+ "Foreigner::Adapter.register '#{configured_name}', 'path/to/adapter'"
14
17
  end
15
18
  end
16
19
 
17
20
  def configured_name
18
- ActiveRecord::Base.connection_pool.spec.config[:adapter]
21
+ @configured_name ||= ActiveRecord::Base.connection_pool.spec.config[:adapter]
19
22
  end
20
23
  end
21
24
  end
@@ -22,11 +22,11 @@ module Foreigner
22
22
  # ====== Creating a simple foreign key
23
23
  # t.foreign_key(:people)
24
24
  # ====== Defining the column
25
- # t.foreign_key(:people, :column => :sender_id)
25
+ # t.foreign_key(:people, column: :sender_id)
26
26
  # ====== Creating a named foreign key
27
- # t.foreign_key(:people, :column => :sender_id, :name => 'sender_foreign_key')
27
+ # t.foreign_key(:people, column: :sender_id, name: 'sender_foreign_key')
28
28
  # ====== Defining the column of the +to_table+.
29
- # t.foreign_key(:people, :column => :sender_id, :primary_key => :person_id)
29
+ # t.foreign_key(:people, column: :sender_id, primary_key: :person_id)
30
30
  def foreign_key(to_table, options = {})
31
31
  @base.add_foreign_key(@table_name, to_table, options)
32
32
  end
@@ -40,11 +40,11 @@ module Foreigner
40
40
  # end
41
41
  # ====== Remove the foreign key named accounts_branch_id_fk in the accounts table.
42
42
  # change_table :accounts do |t|
43
- # t.remove_foreign_key :column => :branch_id
43
+ # t.remove_foreign_key column: :branch_id
44
44
  # end
45
45
  # ====== Remove the foreign key named party_foreign_key in the accounts table.
46
46
  # change_table :accounts do |t|
47
- # t.remove_index :name => :party_foreign_key
47
+ # t.remove_index name: :party_foreign_key
48
48
  # end
49
49
  def remove_foreign_key(options)
50
50
  @base.remove_foreign_key(@table_name, options)
@@ -26,13 +26,13 @@ module Foreigner
26
26
  # `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
27
27
  #
28
28
  # ====== Creating a named foreign key
29
- # add_foreign_key(:comments, :posts, :name => 'comments_belongs_to_posts')
29
+ # add_foreign_key(:comments, :posts, name: 'comments_belongs_to_posts')
30
30
  # generates
31
31
  # ALTER TABLE `comments` ADD CONSTRAINT
32
32
  # `comments_belongs_to_posts` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
33
33
  #
34
34
  # ====== Creating a cascading foreign_key on a custom column
35
- # add_foreign_key(:people, :people, :column => 'best_friend_id', :dependent => :nullify)
35
+ # add_foreign_key(:people, :people, column: 'best_friend_id', dependent: :nullify)
36
36
  # generates
37
37
  # ALTER TABLE `people` ADD CONSTRAINT
38
38
  # `people_best_friend_id_fk` FOREIGN KEY (`best_friend_id`) REFERENCES `people` (`id`)
@@ -62,9 +62,9 @@ module Foreigner
62
62
  # ====== Remove the suppliers_company_id_fk in the suppliers table.
63
63
  # remove_foreign_key :suppliers, :companies
64
64
  # ====== Remove the foreign key named accounts_branch_id_fk in the accounts table.
65
- # remove_foreign_key :accounts, :column => :branch_id
65
+ # remove_foreign_key :accounts, column: :branch_id
66
66
  # ====== Remove the foreign key named party_foreign_key in the accounts table.
67
- # remove_foreign_key :accounts, :name => :party_foreign_key
67
+ # remove_foreign_key :accounts, name: :party_foreign_key
68
68
  def remove_foreign_key(from_table, options)
69
69
  end
70
70
 
@@ -0,0 +1,7 @@
1
+ module Foreigner
2
+ module ConnectionAdapters
3
+ module NoopAdapter
4
+ # Used mainly for sqlite3
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ class Foreigner::AdapterTest < ActiveSupport::TestCase
4
+ test "load" do
5
+ Foreigner::Adapter.register 'foo', 'bar'
6
+ Foreigner::Adapter.expects(:configured_name).at_least_once.returns('foo')
7
+ Foreigner::Adapter.expects(:require).with('bar')
8
+
9
+ Foreigner::Adapter.load!
10
+ end
11
+ end
File without changes
data/test/helper.rb CHANGED
@@ -3,6 +3,7 @@ Bundler.require(:default)
3
3
 
4
4
  require 'test/unit'
5
5
  require 'active_record'
6
+ require 'mocha'
6
7
 
7
8
  # Foreigner::Adapter.registered.values.each do |file_name|
8
9
  # require file_name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreigner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70302659050020 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70302659050020
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activerecord
27
- requirement: &70302659074460 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: 3.1.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70302659074460
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.1.0
36
46
  description: Adds helpers to migrations and dumps foreign keys to schema.rb
37
47
  email: developer@matthewhiggins.com
38
48
  executables: []
@@ -49,6 +59,7 @@ files:
49
59
  - lib/foreigner/connection_adapters/abstract/schema_statements.rb
50
60
  - lib/foreigner/connection_adapters/mysql2_adapter.rb
51
61
  - lib/foreigner/connection_adapters/mysql_adapter.rb
62
+ - lib/foreigner/connection_adapters/noop_adapter.rb
52
63
  - lib/foreigner/connection_adapters/postgresql_adapter.rb
53
64
  - lib/foreigner/connection_adapters/sql2003.rb
54
65
  - lib/foreigner/loader.rb
@@ -56,13 +67,14 @@ files:
56
67
  - lib/foreigner/railtie.rb
57
68
  - lib/foreigner/schema_dumper.rb
58
69
  - lib/foreigner.rb
70
+ - test/foreigner/adapter_test.rb
71
+ - test/foreigner/connection_adapters/mysql2_adapter_test.rb
72
+ - test/foreigner/connection_adapters/mysql_adapter_test.rb
73
+ - test/foreigner/connection_adapters/postgresql_adapter_test.rb
74
+ - test/foreigner/connection_adapters/sql2003_test.rb
75
+ - test/foreigner/migration/command_recorder_test.rb
76
+ - test/foreigner/schema_dumper_test.rb
59
77
  - test/helper.rb
60
- - test/unit/command_recorder_test.rb
61
- - test/unit/mysql2_adapter_test.rb
62
- - test/unit/mysql_adapter_test.rb
63
- - test/unit/postgresql_adapter_test.rb
64
- - test/unit/schema_dumper_test.rb
65
- - test/unit/sql2003_test.rb
66
78
  homepage: http://github.com/matthuhiggins/foreigner
67
79
  licenses: []
68
80
  post_install_message:
@@ -83,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
95
  version: 1.3.5
84
96
  requirements: []
85
97
  rubyforge_project: foreigner
86
- rubygems_version: 1.8.17
98
+ rubygems_version: 1.8.24
87
99
  signing_key:
88
100
  specification_version: 3
89
101
  summary: Foreign Keys for Rails