foreigner 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,11 +50,11 @@ If the column is named article_id instead of post_id, use the :column option:
50
50
 
51
51
  add_foreign_key(:comments, :posts, :column => 'article_id')
52
52
 
53
- Lastly, a name can be specified for the foreign key constraint:
53
+ A name can be specified for the foreign key constraint:
54
54
 
55
55
  add_foreign_key(:comments, :posts, :name => 'comment_article_foreign_key')
56
56
 
57
- == Create/Change Table Shorthand
57
+ == Change Table Shorthand
58
58
 
59
59
  Foreigner adds extra behavior to change_table, which lets you define foreign keys using shorthand.
60
60
 
@@ -51,6 +51,8 @@ module Foreigner
51
51
  # [:dependent]
52
52
  # If set to <tt>:delete</tt>, the associated records in from_table are deleted when records in to_table table are deleted.
53
53
  # If set to <tt>:nullify</tt>, the foreign key column is set to +NULL+.
54
+ # [:options]
55
+ # Any extra options you want appended to the foreign key definition.
54
56
  def add_foreign_key(from_table, to_table, options = {})
55
57
  end
56
58
 
@@ -17,6 +17,7 @@ module Foreigner
17
17
  "FOREIGN KEY (#{quote_column_name(column)}) " +
18
18
  "REFERENCES #{quote_table_name(ActiveRecord::Migrator.proper_table_name(to_table))}(#{primary_key})"
19
19
  sql << " #{dependency}" if dependency.present?
20
+ sql << " #{options[:options]}" if options[:options]
20
21
 
21
22
  execute(sql)
22
23
  end
@@ -1,8 +1,5 @@
1
- require 'test/unit'
2
1
  require 'rubygems'
3
- require 'active_support'
4
- require 'active_support/test_case'
5
- require 'active_record'
6
- require 'active_record/test_case'
7
- require 'active_record/connection_adapters/mysql_adapter'
2
+ require 'test/unit'
3
+ require 'rails/all'
4
+
8
5
  require 'foreigner'
@@ -1,7 +1,8 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'helper'
2
+ require 'foreigner/connection_adapters/mysql_adapter'
2
3
 
3
4
  class MysqlAdapterTest < ActiveRecord::TestCase
4
- include Foreigner::MysqlAdapter
5
+ include Foreigner::ConnectionAdapters::MysqlAdapter
5
6
 
6
7
  def test_add_without_options
7
8
  assert_equal(
@@ -54,6 +55,14 @@ class MysqlAdapterTest < ActiveRecord::TestCase
54
55
  add_foreign_key(:employees, :companies, :dependent => :restrict)
55
56
  )
56
57
  end
58
+
59
+ def test_add_with_options
60
+ assert_equal(
61
+ "ALTER TABLE `employees` ADD CONSTRAINT `employees_company_id_fk` FOREIGN KEY (`company_id`) REFERENCES `companies`(id) " +
62
+ "on delete foo",
63
+ add_foreign_key(:employees, :companies, :options => 'on delete foo')
64
+ )
65
+ end
57
66
 
58
67
  def test_remove_by_table
59
68
  assert_equal(
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreigner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 9
9
- - 0
10
- version: 0.9.0
8
+ - 1
9
+ version: 0.9.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Matthew Higgins
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-21 00:00:00 -07:00
17
+ date: 2010-10-23 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -54,7 +53,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
53
  requirements:
55
54
  - - ">="
56
55
  - !ruby/object:Gem::Version
57
- hash: 59
58
56
  segments:
59
57
  - 1
60
58
  - 8
@@ -65,7 +63,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
63
  requirements:
66
64
  - - ">="
67
65
  - !ruby/object:Gem::Version
68
- hash: 17
69
66
  segments:
70
67
  - 1
71
68
  - 3