foreigner 1.7.0 → 1.7.1

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: 7afaa93e891d1a95c671e0703a70c4fbae46eb84
4
- data.tar.gz: 8eb8278d682088f6b57aef3962abb224bc4b8727
3
+ metadata.gz: f53d6f236ea03953ecaa96a130900e955fbb6835
4
+ data.tar.gz: c97abd90d8c7cc6b85868b06d52e6744ad9ff220
5
5
  SHA512:
6
- metadata.gz: 254c861fe2c7299e1157dc186f25e0649a4724095e6eebde0dcf94b223169f08e4ea3730d97cdca6d67308640138c3f2e92bf07b84d87c67b8a30490236e2133
7
- data.tar.gz: a6f39ca36faf91a20d61b76326c47b360891b98adbc3685c02be6d3f52ec070bc74006f84d3d261b0f472462de44e1dd465b2dd7ecea7780ecb6cdfd91fcf60b
6
+ metadata.gz: 215f8987ede00716f3e3335d4db4cb5cb353cdfe599b4b2c40b8e138a491bde1638a03dc51417bb3741733915f1ecdc5480bcb7d983b5582a46f66ff3fa4782e
7
+ data.tar.gz: c21f84ba666b4aabb79ea0e8f42f2e98fb9dbae0cf2a3c94cb296d12e38dafedef66e51920fab8b0a09cda722f5b394b17ae68934899493fd0ae60efd719d3cb
@@ -26,13 +26,13 @@ module Foreigner
26
26
  fk_info.map do |row|
27
27
  options = {column: row['column'], name: row['name'], primary_key: row['primary_key']}
28
28
 
29
- if create_table_info =~ /CONSTRAINT #{quote_column_name(row['name'])} FOREIGN KEY .* REFERENCES .*\)( ON DELETE (CASCADE|SET NULL|RESTRICT))? ?(.*)$/
30
- options[:dependent] = case $2
29
+ if create_table_info =~ /CONSTRAINT #{quote_column_name(row['name'])} FOREIGN KEY .* REFERENCES .*\)(?: ON DELETE (CASCADE|SET NULL|RESTRICT))?(?: (.+?))?,?$/
30
+ options[:dependent] = case $1
31
31
  when 'CASCADE' then :delete
32
32
  when 'SET NULL' then :nullify
33
33
  when 'RESTRICT' then :restrict
34
34
  end
35
- options[:options] = $3 # e.g. ON UPDATE ...
35
+ options[:options] = $2 # e.g. ON UPDATE ...
36
36
  end
37
37
  ForeignKeyDefinition.new(table_name, row['to_table'], options)
38
38
  end
@@ -9,6 +9,45 @@ class Foreigner::Mysql2AdapterTest < Foreigner::UnitTest
9
9
 
10
10
  setup do
11
11
  @adapter = Mysql2Adapter.new
12
+ @adapter.instance_variable_set(:@config, database: 'foo')
13
+ end
14
+
15
+ test 'foreign_keys parsing' do
16
+ @adapter.expects(:select_all).at_least_once.returns([
17
+ {'column' => 'foo_id', 'name' => 'foo_bar_foo_id_fk', 'primary_key' => 'id', 'to_table' => 'foo'}
18
+ ])
19
+
20
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`)\n")
21
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent:nil, options:nil}),
22
+ @adapter.foreign_keys('bar').first
23
+
24
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`),\n")
25
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent:nil, options:nil}),
26
+ @adapter.foreign_keys('bar').first
27
+
28
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) ON DELETE CASCADE\n")
29
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent: :delete, options:nil}),
30
+ @adapter.foreign_keys('bar').first
31
+
32
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) ON DELETE CASCADE,\n")
33
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent: :delete, options:nil}),
34
+ @adapter.foreign_keys('bar').first
35
+
36
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) FOO BAR\n")
37
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent:nil, options:'FOO BAR'}),
38
+ @adapter.foreign_keys('bar').first
39
+
40
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) FOO BAR,\n")
41
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent:nil, options:'FOO BAR'}),
42
+ @adapter.foreign_keys('bar').first
43
+
44
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) ON DELETE CASCADE FOO BAR,\n")
45
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent: :delete, options:'FOO BAR'}),
46
+ @adapter.foreign_keys('bar').first
47
+
48
+ @adapter.expects(:select_one).returns('Create Table' => "CONSTRAINT `foo_bar_foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) ON DELETE CASCADE FOO BAR,\n")
49
+ assert_equal Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('bar', 'foo', {column:"foo_id", name:"foo_bar_foo_id_fk", primary_key:"id", dependent: :delete, options:'FOO BAR'}),
50
+ @adapter.foreign_keys('bar').first
12
51
  end
13
52
 
14
53
  test 'remove_foreign_key_sql by table' do
@@ -31,4 +70,4 @@ class Foreigner::Mysql2AdapterTest < Foreigner::UnitTest
31
70
  @adapter.remove_foreign_key_sql(:suppliers, column: "ship_to_id")
32
71
  )
33
72
  end
34
- end
73
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreigner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Higgins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-29 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord