sparkfly-foreigner 0.6.0 → 0.7.1

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.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # This Gemfile is here for testing purposes. The Gemfile.lock will contain
4
+ # the exact versions of the gems used to test Foreigner
5
+
6
+ group :test do
7
+ gem 'activerecord'
8
+ gem 'rspec'
9
+ gem 'pg'
10
+ #gem 'mysql2', '0.2.6' # Should be using this instead of mysql gem, but refuses to load
11
+ gem 'mysql'
12
+ gem 'sqlite3'
13
+ end
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.5)
5
+ activesupport (= 3.0.5)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4)
8
+ activerecord (3.0.5)
9
+ activemodel (= 3.0.5)
10
+ activesupport (= 3.0.5)
11
+ arel (~> 2.0.2)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.5)
14
+ arel (2.0.9)
15
+ builder (2.1.2)
16
+ diff-lcs (1.1.2)
17
+ i18n (0.5.0)
18
+ mysql (2.8.1)
19
+ pg (0.11.0)
20
+ rspec (2.5.0)
21
+ rspec-core (~> 2.5.0)
22
+ rspec-expectations (~> 2.5.0)
23
+ rspec-mocks (~> 2.5.0)
24
+ rspec-core (2.5.1)
25
+ rspec-expectations (2.5.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-mocks (2.5.0)
28
+ sqlite3 (1.3.3)
29
+ tzinfo (0.3.27)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ activerecord
36
+ mysql
37
+ pg
38
+ rspec
39
+ sqlite3
@@ -9,10 +9,12 @@ was taken out.
9
9
 
10
10
  h2. Test Coverage
11
11
 
12
- These tests were created and tested against our target platform, Rails 2.3.5. Support for Rails 3 will come in the future
13
- when we actually move our platform to Rails 3. The PostgreSQL 8.3 has the best coverage.
12
+ These tests were created and tested against our target platform, Rails 3. If you are using Rails 2.3.5,
13
+ use sparkfly-foreigner 0.6.0. this currently works with Rails 3.0 beta 3.
14
14
 
15
- PostgreSQL (tested against 8.3.9)
15
+ Rspec coverage was against Rspec 2.0 beta6
16
+
17
+ PostgreSQL (tested against 8.3.9, 8.4.2)
16
18
  - "Schema" tests: do the table migrations actually add referential integrity?
17
19
  - "Schema Extractor" tests: does the foreign_key() method extract out the foreign key from information_schema?
18
20
  - "Semantics" tests: do the add/drop constraints emit proper SQL?
@@ -24,6 +26,7 @@ MySQL (tested against 5.0.90 / Gentoo mysql-5.0.90-r2 hardened x86_64)
24
26
 
25
27
  SQLite3 (tested against 3.6.22 in-memory only)
26
28
  - "Semantics" tests: do the add/drop constraints emit proper SQL?
29
+ - Warning: sqlite3 probably does not actually work when you use it.
27
30
 
28
31
  Schema Dumper
29
32
  - Are we emitting the correct schema.rb syntax for adding foreign key constraints?
@@ -34,6 +37,15 @@ TODO:
34
37
 
35
38
  h2. Usage
36
39
 
40
+ h3. Installation
41
+
42
+ Add this to your Gemfile:
43
+ <pre>
44
+ gem 'sparkfly-foreigner', :require => 'foreigner'
45
+ </pre>
46
+
47
+ h3. Migrations
48
+
37
49
  To specify a different column name you can do the following:
38
50
  <pre>
39
51
  create_table :comments do |t|
@@ -66,7 +78,7 @@ To specify a reference with a foreign key constraint using Rails convention:
66
78
 
67
79
  Read the specs for more example usage.
68
80
 
69
- h2. schema.rb
81
+ h3. schema.rb
70
82
 
71
83
  All of the constrants are updated in schema.rb when you either:
72
84
  <pre>
@@ -76,25 +88,17 @@ All of the constrants are updated in schema.rb when you either:
76
88
  This allows you to see the state of your migratons and
77
89
  take advantage of using <pre>rake db:schema:load</pre>
78
90
 
79
- h2. Installation
80
-
81
- h3. Rails 3
82
-
83
- - Have not tested any of these changes against Rails 3.
84
- - See the matthuhiggins-foreigner or dwilkie-foreigner if you want a Foreigner that plays nice with Rails 3.
85
-
86
- h3. Rails 2.3.5
91
+ h2. Testing
87
92
 
88
- Add the following to environment.rb:
89
- <pre>config.gem "sparkfly-foreigner", :lib => "foreigner"</pre>
90
- Then run:
91
- <pre>sudo rake gems:install</pre>
93
+ You will need rspec 2.0. At the time of this writing, you install it with:
94
+ <pre>
95
+ gem install rspec --pre
96
+ </pre>
92
97
 
93
- h2. Testing
98
+ You will also want to make sure you have Rubygems 1.3.6
94
99
 
95
- You will need rspec and possibly rspec-rails. Run "rake spec" to run all the spec. Make sure
96
- that all of the PostgreSQL and MySQL databases defined in spec/spec_helper.rb are created
97
- before you run those tests.
100
+ Run "rake spec" to run all the spec. Make sure that all of the PostgreSQL and MySQL databases defined in
101
+ spec/spec_helper.rb are created before you run those tests.
98
102
 
99
103
  h2. Copyrights
100
104
 
@@ -103,3 +107,6 @@ Copyright (c) 2010 Ho-Sheng Hsiao, released under the MIT license
103
107
  Modified from code written by David Wilkie and Matt Higgins. See http://github.com/sparkfly/foreigner for details on
104
108
  what got changed from what.
105
109
 
110
+ Contributions:
111
+ - theaboutbox https://github.com/theaboutbox/foreigner
112
+
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
- require 'spec/rake/spectask'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  desc 'Default: run specs.'
7
7
  task :default => :spec
8
8
 
9
9
  desc 'Run the specs'
10
- Spec::Rake::SpecTask.new(:spec) do |t|
11
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
12
- t.spec_files = FileList['spec/**/*_spec.rb']
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ #t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
12
+ #t.spec_files = FileList['spec/**/*_spec.rb']
13
13
  end
14
14
 
15
15
  desc 'Generate documentation for the foreigner plugin.'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.1
@@ -25,11 +25,13 @@ module Foreigner
25
25
  def on_load(&block)
26
26
  if defined?(Rails) && Rails.version >= '3.0'
27
27
  ActiveSupport.on_load :active_record do
28
- unless ActiveRecord::Base.connected?
29
- ActiveRecord::Base.configurations = Rails.application.config.database_configuration
30
- ActiveRecord::Base.establish_connection
28
+ ActiveSupport.on_load :before_initialize do
29
+ unless ActiveRecord::Base.connected?
30
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration
31
+ ActiveRecord::Base.establish_connection
32
+ end
33
+ block.call
31
34
  end
32
- block.call
33
35
  end
34
36
  else
35
37
  yield
@@ -11,10 +11,10 @@ module Foreigner
11
11
 
12
12
  def foreign_keys(table_name)
13
13
  fk_info = select_all %{
14
- SELECT fk.referenced_table_name as 'to_table'
15
- ,fk.referenced_column_name as 'primary_key'
16
- ,fk.column_name as 'column'
17
- ,fk.constraint_name as 'name'
14
+ SELECT fk.referenced_table_name as 'to_table',
15
+ fk.referenced_column_name as 'primary_key',
16
+ fk.column_name as 'column',
17
+ fk.constraint_name as 'name'
18
18
  FROM information_schema.key_column_usage fk
19
19
  WHERE fk.referenced_column_name is not null
20
20
  AND fk.table_schema = '#{@config[:database]}'
@@ -6,18 +6,18 @@ module Foreigner
6
6
 
7
7
  def foreign_keys(table_name)
8
8
  fk_info = select_all %{
9
- SELECT tc.constraint_name as name
10
- ,ccu.table_name as to_table
11
- ,ccu.column_name as primary_key
12
- ,kcu.column_name as column
13
- ,rc.delete_rule as dependency
9
+ SELECT tc.constraint_name as name,
10
+ ccu.table_name as to_table,
11
+ ccu.column_name as primary_key,
12
+ kcu.column_name as column,
13
+ rc.delete_rule as dependency
14
14
  FROM information_schema.table_constraints tc
15
15
  JOIN information_schema.key_column_usage kcu
16
- USING (constraint_catalog, constraint_schema, constraint_name)
16
+ USING (constraint_catalog, constraint_schema, constraint_name)
17
17
  JOIN information_schema.referential_constraints rc
18
- USING (constraint_catalog, constraint_schema, constraint_name)
18
+ USING (constraint_catalog, constraint_schema, constraint_name)
19
19
  JOIN information_schema.constraint_column_usage ccu
20
- USING (constraint_catalog, constraint_schema, constraint_name)
20
+ USING (constraint_catalog, constraint_schema, constraint_name)
21
21
  WHERE tc.constraint_type = 'FOREIGN KEY'
22
22
  AND tc.constraint_catalog = '#{@config[:database]}'
23
23
  AND tc.table_name = '#{table_name}'
@@ -1,4 +1,4 @@
1
- require 'foreigner/connection_adapters/sql_2003'
1
+ require 'foreigner/semantics/sql_2003'
2
2
 
3
3
  module Foreigner
4
4
  module ConnectionAdapters
@@ -15,7 +15,7 @@ module Foreigner
15
15
  end
16
16
 
17
17
  def add_foreign_key(from_table, to_table, options = {})
18
- column = options[:column] || "#{to_table.to_s.singularize}_id"
18
+ column = options[:column] || column_name(to_table)
19
19
  foreign_key_name = foreign_key_name(from_table, column, options)
20
20
  primary_key = options[:primary_key] || "id"
21
21
  reference = sql_for_reference(to_table, primary_key)
@@ -1,5 +1,4 @@
1
-
2
- require 'rubygems'
1
+ require 'rspec'
3
2
 
4
3
  require 'active_support'
5
4
  require 'active_record'
@@ -11,36 +10,17 @@ require "foreigner/connection_adapters/postgresql_adapter"
11
10
  require "foreigner/connection_adapters/mysql_adapter"
12
11
  require "foreigner/connection_adapters/sqlite3_adapter"
13
12
 
14
- require File.expand_path('factory_helper.rb', File.dirname(__FILE__))
15
- require File.expand_path('adapter_helper.rb', File.dirname(__FILE__))
16
-
17
- CONFIGURATIONS = {
18
- :postgresql => {
19
- :adapter => "postgresql",
20
- :username => "root",
21
- :password => "",
22
- :database => "test_foreigner_gem",
23
- :min_messages => "ERROR"
24
- },
25
- :postgresql_admin => {
26
- :adapter => "postgresql",
27
- :username => "root",
28
- :password => "",
29
- :database => "test",
30
- :min_messages => "ERROR"
31
- }, # :postgresql_admin is used to connect in; :postgresql is used to actually test the migrations
32
- :mysql => {
33
- :adapter => 'mysql',
34
- :host => 'localhost',
35
- :username => 'root',
36
- :database => 'foreigner_test'
37
-
38
- },
39
- :sqlite3 => {
40
- :adapter => "sqlite3",
41
- :database => ":memory:"
42
- }
43
- }
13
+
14
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
+
16
+ RSpec.configure do |config|
17
+ config.mock_with :rspec
18
+ config.filter_run :focus => true
19
+ config.filter_run_excluding :external => true
20
+ config.run_all_when_everything_filtered = true
21
+ end
22
+
23
+ # CONFIGURATIONS defined in support/adapter_helper.rb
44
24
 
45
25
  # Turn this on for debugging
46
26
  ActiveRecord::Migration.verbose = false
@@ -1,5 +1,30 @@
1
-
2
- # CONFIGURATIONS is defined in spec_helper
1
+ CONFIGURATIONS = {
2
+ :postgresql => {
3
+ :adapter => "postgresql",
4
+ :username => "root",
5
+ :password => "",
6
+ :database => "test_foreigner_gem",
7
+ :min_messages => "ERROR"
8
+ },
9
+ :postgresql_admin => {
10
+ :adapter => "postgresql",
11
+ :username => "root",
12
+ :password => "",
13
+ :database => "test",
14
+ :min_messages => "ERROR"
15
+ }, # :postgresql_admin is used to connect in; :postgresql is used to actually test the migrations
16
+ :mysql => {
17
+ :adapter => 'mysql',
18
+ :host => 'localhost',
19
+ :username => 'root',
20
+ :database => 'foreigner_test'
21
+
22
+ },
23
+ :sqlite3 => {
24
+ :adapter => "sqlite3",
25
+ :database => ":memory:"
26
+ }
27
+ }
3
28
 
4
29
  module AdapterHelper
5
30
  module AdapterTestHarness
@@ -29,7 +29,9 @@ module MigrationFactory
29
29
  # def self.up
30
30
  # end
31
31
  # end
32
- migration.metaclass.class_eval do
32
+
33
+ # ActiveSupport 3.0 changed the name to singleton_class
34
+ (migration.respond_to?(:singleton_class) ? migration.singleton_class : migration.metaclass).class_eval do
33
35
  define_method(:up, &blk)
34
36
  end
35
37
  migration
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkfly-foreigner
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 1
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 6
8
- - 0
9
- version: 0.6.0
8
+ - 7
9
+ - 1
10
+ version: 0.7.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ho-Sheng Hsiao
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-07 00:00:00 -04:00
18
+ date: 2011-05-05 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -27,7 +28,8 @@ extensions: []
27
28
  extra_rdoc_files:
28
29
  - README.textile
29
30
  files:
30
- - .gitignore
31
+ - Gemfile
32
+ - Gemfile.lock
31
33
  - MIT-LICENSE
32
34
  - README.textile
33
35
  - Rakefile
@@ -40,8 +42,6 @@ files:
40
42
  - lib/foreigner/connection_adapters/sqlite3_adapter.rb
41
43
  - lib/foreigner/schema_dumper.rb
42
44
  - lib/foreigner/semantics/sql_2003.rb
43
- - spec/adapter_helper.rb
44
- - spec/factory_helper.rb
45
45
  - spec/mysql/schema_extractor_spec.rb
46
46
  - spec/mysql/schema_spec.rb
47
47
  - spec/mysql/semantics_spec.rb
@@ -51,46 +51,42 @@ files:
51
51
  - spec/schema_dumper_spec.rb
52
52
  - spec/spec_helper.rb
53
53
  - spec/sqlite3/schema_spec.rb
54
+ - spec/support/adapter_helper.rb
55
+ - spec/support/factory_helper.rb
54
56
  - tasks/foreigner_tasks.rake
55
57
  has_rdoc: true
56
58
  homepage: http://github.com/hosh/foreigner
57
59
  licenses: []
58
60
 
59
61
  post_install_message:
60
- rdoc_options:
61
- - --charset=UTF-8
62
+ rdoc_options: []
63
+
62
64
  require_paths:
63
65
  - lib
64
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
65
68
  requirements:
66
69
  - - ">="
67
70
  - !ruby/object:Gem::Version
71
+ hash: 3
68
72
  segments:
69
73
  - 0
70
74
  version: "0"
71
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
72
77
  requirements:
73
78
  - - ">="
74
79
  - !ruby/object:Gem::Version
80
+ hash: 3
75
81
  segments:
76
82
  - 0
77
83
  version: "0"
78
84
  requirements: []
79
85
 
80
86
  rubyforge_project:
81
- rubygems_version: 1.3.6
87
+ rubygems_version: 1.5.2
82
88
  signing_key:
83
89
  specification_version: 3
84
90
  summary: Foreign keys for Rails migrations for PostgreSQL, MySQL and Sqlite3. Based on dwilkie-foreigner
85
- test_files:
86
- - spec/schema_dumper_spec.rb
87
- - spec/spec_helper.rb
88
- - spec/sqlite3/schema_spec.rb
89
- - spec/postgresql/schema_extractor_spec.rb
90
- - spec/postgresql/schema_spec.rb
91
- - spec/postgresql/semantics_spec.rb
92
- - spec/adapter_helper.rb
93
- - spec/factory_helper.rb
94
- - spec/mysql/schema_extractor_spec.rb
95
- - spec/mysql/schema_spec.rb
96
- - spec/mysql/semantics_spec.rb
91
+ test_files: []
92
+
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- *.swp
2
- *gemspec
3
- pkg/*