foreigner-matcher 0.2.0 → 0.2.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/.gitignore CHANGED
@@ -7,3 +7,4 @@ doc/*
7
7
  spec/config/database.yml
8
8
  *.swp
9
9
  *.rbc
10
+ .rbx
data/.travis.yml ADDED
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - jruby-18mode
10
+ - jruby-19mode
11
+ env:
12
+ - DB=mysql
13
+ - DB=postgres
14
+ gemfile:
15
+ - Gemfile
16
+ - ci/gemfiles/rspec2_9_rails3_1.gemfile
17
+ - ci/gemfiles/rspec2_9_rails3_0.gemfile
18
+ before_script:
19
+ - ci/script/create_db.sh
20
+ - bundle exec rake db:test:reset --trace
21
+ script: bundle exec rspec -b
data/Gemfile CHANGED
@@ -3,13 +3,20 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in foreigner-matcher.gemspec
4
4
  gemspec
5
5
 
6
- group :development do
7
- gem "kramdown", "~> 0.13.2"
8
- end
9
-
10
6
  group :test do
11
- gem "rspec", "~> 2.6.0"
12
- gem "activerecord", "~> 3.0.0"
13
- gem "railties", "~> 3.0.0"
14
- gem "mysql2", "~> 0.2.7"
7
+ gem "rake"
8
+ gem "rspec", "~> 2.9.0"
9
+ gem "mocha", "~> 0.11.0"
10
+ gem "activerecord", "~> 3.2.0"
11
+ gem "railties", "~> 3.2.0"
12
+
13
+ platforms :ruby do
14
+ gem "mysql2", "~> 0.3.0"
15
+ gem "pg", "~> 0.13.2"
16
+ end
17
+
18
+ platforms :jruby do
19
+ gem "activerecord-jdbcmysql-adapter"
20
+ gem "activerecord-jdbcpostgresql-adapter"
21
+ end
15
22
  end
data/Gemfile.lock CHANGED
@@ -1,74 +1,104 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- foreigner-matcher (0.2.0)
4
+ foreigner-matcher (0.2.1)
5
5
  foreigner (>= 1.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- abstract (1.0.0)
11
- actionpack (3.0.10)
12
- activemodel (= 3.0.10)
13
- activesupport (= 3.0.10)
14
- builder (~> 2.1.2)
15
- erubis (~> 2.6.6)
16
- i18n (~> 0.5.0)
17
- rack (~> 1.2.1)
18
- rack-mount (~> 0.6.14)
19
- rack-test (~> 0.5.7)
20
- tzinfo (~> 0.3.23)
21
- activemodel (3.0.10)
22
- activesupport (= 3.0.10)
23
- builder (~> 2.1.2)
24
- i18n (~> 0.5.0)
25
- activerecord (3.0.10)
26
- activemodel (= 3.0.10)
27
- activesupport (= 3.0.10)
28
- arel (~> 2.0.10)
29
- tzinfo (~> 0.3.23)
30
- activesupport (3.0.10)
31
- arel (2.0.10)
32
- builder (2.1.2)
33
- diff-lcs (1.1.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- foreigner (1.1.1)
10
+ actionpack (3.2.3)
11
+ activemodel (= 3.2.3)
12
+ activesupport (= 3.2.3)
13
+ builder (~> 3.0.0)
14
+ erubis (~> 2.7.0)
15
+ journey (~> 1.0.1)
16
+ rack (~> 1.4.0)
17
+ rack-cache (~> 1.2)
18
+ rack-test (~> 0.6.1)
19
+ sprockets (~> 2.1.2)
20
+ activemodel (3.2.3)
21
+ activesupport (= 3.2.3)
22
+ builder (~> 3.0.0)
23
+ activerecord (3.2.3)
24
+ activemodel (= 3.2.3)
25
+ activesupport (= 3.2.3)
26
+ arel (~> 3.0.2)
27
+ tzinfo (~> 0.3.29)
28
+ activerecord-jdbc-adapter (1.2.2)
29
+ activerecord-jdbcmysql-adapter (1.2.2)
30
+ activerecord-jdbc-adapter (~> 1.2.2)
31
+ jdbc-mysql (~> 5.1.0)
32
+ activerecord-jdbcpostgresql-adapter (1.2.2)
33
+ activerecord-jdbc-adapter (~> 1.2.2)
34
+ jdbc-postgres (>= 9.0, < 9.2)
35
+ activesupport (3.2.3)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.2)
39
+ builder (3.0.0)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.7.0)
42
+ foreigner (1.1.6)
37
43
  activerecord (>= 3.0.0)
38
- i18n (0.5.0)
39
- kramdown (0.13.3)
40
- mysql2 (0.2.13)
41
- rack (1.2.3)
42
- rack-mount (0.6.14)
43
- rack (>= 1.0.0)
44
- rack-test (0.5.7)
44
+ hike (1.2.1)
45
+ i18n (0.6.0)
46
+ jdbc-mysql (5.1.13)
47
+ jdbc-postgres (9.1.901)
48
+ journey (1.0.3)
49
+ json (1.7.0)
50
+ json (1.7.0-java)
51
+ metaclass (0.0.1)
52
+ mocha (0.11.3)
53
+ metaclass (~> 0.0.1)
54
+ multi_json (1.3.4)
55
+ mysql2 (0.3.11)
56
+ pg (0.13.2)
57
+ rack (1.4.1)
58
+ rack-cache (1.2)
59
+ rack (>= 0.4)
60
+ rack-ssl (1.3.2)
61
+ rack
62
+ rack-test (0.6.1)
45
63
  rack (>= 1.0)
46
- railties (3.0.10)
47
- actionpack (= 3.0.10)
48
- activesupport (= 3.0.10)
64
+ railties (3.2.3)
65
+ actionpack (= 3.2.3)
66
+ activesupport (= 3.2.3)
67
+ rack-ssl (~> 1.3.2)
49
68
  rake (>= 0.8.7)
50
69
  rdoc (~> 3.4)
51
- thor (~> 0.14.4)
52
- rake (0.9.2)
53
- rdoc (3.9.3)
54
- rspec (2.6.0)
55
- rspec-core (~> 2.6.0)
56
- rspec-expectations (~> 2.6.0)
57
- rspec-mocks (~> 2.6.0)
58
- rspec-core (2.6.4)
59
- rspec-expectations (2.6.0)
60
- diff-lcs (~> 1.1.2)
61
- rspec-mocks (2.6.0)
70
+ thor (~> 0.14.6)
71
+ rake (0.9.2.2)
72
+ rdoc (3.12)
73
+ json (~> 1.4)
74
+ rspec (2.9.0)
75
+ rspec-core (~> 2.9.0)
76
+ rspec-expectations (~> 2.9.0)
77
+ rspec-mocks (~> 2.9.0)
78
+ rspec-core (2.9.0)
79
+ rspec-expectations (2.9.1)
80
+ diff-lcs (~> 1.1.3)
81
+ rspec-mocks (2.9.0)
82
+ sprockets (2.1.3)
83
+ hike (~> 1.2)
84
+ rack (~> 1.0)
85
+ tilt (~> 1.1, != 1.3.0)
62
86
  thor (0.14.6)
63
- tzinfo (0.3.29)
87
+ tilt (1.3.3)
88
+ tzinfo (0.3.33)
64
89
 
65
90
  PLATFORMS
91
+ java
66
92
  ruby
67
93
 
68
94
  DEPENDENCIES
69
- activerecord (~> 3.0.0)
95
+ activerecord (~> 3.2.0)
96
+ activerecord-jdbcmysql-adapter
97
+ activerecord-jdbcpostgresql-adapter
70
98
  foreigner-matcher!
71
- kramdown (~> 0.13.2)
72
- mysql2 (~> 0.2.7)
73
- railties (~> 3.0.0)
74
- rspec (~> 2.6.0)
99
+ mocha (~> 0.11.0)
100
+ mysql2 (~> 0.3.0)
101
+ pg (~> 0.13.2)
102
+ railties (~> 3.2.0)
103
+ rake
104
+ rspec (~> 2.9.0)
data/README.md CHANGED
@@ -1,20 +1,22 @@
1
1
  # foreigner-matcher
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/yellow5/foreigner-matcher.png?branch=master)](http://travis-ci.org/yellow5/foreigner-matcher)
4
+
3
5
  RSpec matcher for the [Foreigner gem](https://github.com/matthuhiggins/foreigner), inspired by [Remarkable](https://github.com/remarkable/remarkable) ActiveRecord matchers.
4
6
 
5
7
  ## Version Information
6
8
 
7
- Note that the matcher is exactly the same between ~> 0.1 and ~> 0.2; all that changes is the Foreigner dependency. Why, you ask? Foreigner >= 1.0.0 is Rails 3 only!
9
+ Note that the matcher is exactly the same between 0.1.1 and 0.2.0; all that changes is the Foreigner dependency. Why, you ask? Foreigner >= 1.0.0 is Rails 3.x only!
8
10
 
9
- **Rails 3**
11
+ **Rails 3.x**
10
12
 
11
- Foreigner >= 1.0.0 use foreigner-matcher ~> 0.2
13
+ Foreigner >= 1.0.0 use foreigner-matcher ~> 0.2.0
12
14
 
13
- Foreigner ~> 0.9 use foreigner-matcher ~> 0.1
15
+ Foreigner ~> 0.9 use foreigner-matcher ~> 0.1.1
14
16
 
15
17
  **Rails 2.3**
16
18
 
17
- Use foreigner-matcher ~> 0.1
19
+ Use foreigner-matcher ~> 0.1.1
18
20
 
19
21
  ## Installation
20
22
 
@@ -22,7 +24,7 @@ Use foreigner-matcher ~> 0.1
22
24
 
23
25
  For installation with bundler, add the following to the approrpriate group in your Gemfile:
24
26
 
25
- gem "foreigner-matcher", "~> 0.2", :require => nil
27
+ gem "foreigner-matcher", "~> 0.2.0", :require => nil
26
28
 
27
29
  For installation without bundler in Rails 2.3, add the following to your config/environments/test.rb:
28
30
 
@@ -52,6 +54,18 @@ For example. Given these two models:
52
54
  belongs_to user
53
55
  end
54
56
 
57
+ And given this migration for the foreign key:
58
+
59
+ class ChangeUserIdToForeignKeyOnUserLogins < ActiveRecord::Migration
60
+ def self.up
61
+ add_foreign_key :user_logins, :users
62
+ end
63
+
64
+ def self.down
65
+ remove_foreign_key :user_logins, :users
66
+ end
67
+ end
68
+
55
69
  The spec would look like this:
56
70
 
57
71
  describe UserLogin do
@@ -70,10 +84,13 @@ These examples will also work passing <tt>:user</tt> as the table name. Why? The
70
84
 
71
85
  ## My Testing Environment
72
86
 
73
- Specs have been run with [Ruby 1.9.2p290](http://www.ruby-lang.org/), [Ruby Enterprise Edition 2011.03](http://www.rubyenterpriseedition.com/), and [Rubinius](http://rubini.us/) with the following combinations:
87
+ The project is tested on [Travis-CI](https://github.com/travis-ci/travis-ci). The rubies and databases that the matcher is regularly verified with can be seen in [.travis.yml](https://github.com/yellow5/foreigner-matcher/blob/master/.travis.yml)
88
+
89
+ The current gems that are tested:
74
90
 
75
- * ActiveRecord ~> 3.0.0, Rspec ~> 2.6.0, Foreigner >= 1.0.0
76
- * ActiveRecord ~> 2.3.11, Rsepc ~> 1.3.2, Foreigner ~> 0.9.1
91
+ * ActiveRecord ~> 3.2.0, Rspec ~> 2.9.0, Foreigner >= 1.00
92
+ * ActiveRecord ~> 3.1.0, Rspec ~> 2.9.0, Foreigner >= 1.00
93
+ * ActiveRecord ~> 3.0.0, Rspec ~> 2.9.0, Foreigner >= 1.00
77
94
 
78
95
  ## Copyright
79
96
 
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ unless ENV['TRAVIS']
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+ end
3
5
 
4
6
  namespace :db do
5
7
  namespace :test do
@@ -22,13 +24,20 @@ namespace :db do
22
24
  end
23
25
 
24
26
  puts "Establishing connection to test db..."
25
- db_config = YAML::load(File.open("#{File.dirname(__FILE__)}/spec/config/database.yml"))
27
+ db_config_yml = File.dirname(__FILE__)
28
+ db_config_yml << (ENV['TRAVIS'] ? '/ci' : '/spec')
29
+ db_config_yml << '/config/database.yml'
30
+ db_configs = YAML::load(File.open(db_config_yml))
31
+ db_adapter = ENV['DB']
32
+ db_adapter = 'jdbc-' + db_adapter if RUBY_PLATFORM == 'java'
33
+ db_config = db_configs[db_adapter]
34
+ ActiveRecord::Base.configurations = db_configs
26
35
  ActiveRecord::Base.establish_connection(db_config)
27
36
  conn = ActiveRecord::Base.connection
28
37
  puts "Connected to #{db_config['database']} via a #{db_config['adapter']} connector"
29
38
 
30
39
  puts "\nDropping test tables, if they exist"
31
- %w( user_logins user_types comments searches special_user_records table_without_foreign_keys users ).each do |test_table|
40
+ %w( default_options user_logins user_types comments searches special_user_records table_without_foreign_keys users ).each do |test_table|
32
41
  print "\tDropping #{test_table}..."
33
42
  conn.execute("drop table if exists #{test_table}")
34
43
  print "done\n"
@@ -46,7 +55,7 @@ namespace :db do
46
55
  t.integer :special_user_id
47
56
  end
48
57
  end
49
- [ :user_logins, :user_types, :comments, :searches, :table_without_foreign_keys ].each do |user_table|
58
+ [ :default_options, :user_logins, :user_types, :comments, :searches, :table_without_foreign_keys ].each do |user_table|
50
59
  print_table_creation(user_table) do
51
60
  conn.create_table(user_table) do |t|
52
61
  t.integer :user_id
@@ -54,16 +63,37 @@ namespace :db do
54
63
  end
55
64
  end
56
65
 
66
+ # Include ActiveRecordVersionHelpers
67
+ require "#{File.dirname(__FILE__)}/spec/support/active_record_version_helpers.rb"
68
+ include ActiveRecordVersionHelpers
69
+
57
70
  require 'foreigner'
58
- foreigner_railtie = Foreigner::Railtie.new
59
- foreigner_railtie.run_initializers(foreigner_railtie)
71
+ if active_record_version > 3.0
72
+ Foreigner::Railtie.instance.run_initializers
73
+ else
74
+ foreigner_railtie = Foreigner::Railtie.new
75
+ foreigner_railtie.run_initializers(foreigner_railtie)
76
+ end
60
77
 
61
78
  puts "\nCreating foreign keys"
62
- print_foreign_key_creation('user_logins') { conn.add_foreign_key(:user_logins, :users, :dependent => :nullify) }
63
- print_foreign_key_creation('user_types') { conn.add_foreign_key(:user_types, :users, :dependent => :restrict) }
64
- print_foreign_key_creation('comments') { conn.add_foreign_key(:comments, :users, :dependent => :delete) }
65
- print_foreign_key_creation('searches') { conn.add_foreign_key(:searches, :users, :name => "user_search_special_fk", :dependent => :delete) }
66
- print_foreign_key_creation('special_user_records') { conn.add_foreign_key(:special_user_records, :users, :column => "special_user_id", :dependent => :delete) }
79
+ print_foreign_key_creation('default_options') do
80
+ conn.add_foreign_key(:default_options, :users)
81
+ end
82
+ print_foreign_key_creation('user_logins') do
83
+ conn.add_foreign_key(:user_logins, :users, :dependent => :nullify)
84
+ end
85
+ print_foreign_key_creation('user_types') do
86
+ conn.add_foreign_key(:user_types, :users, :dependent => :restrict)
87
+ end
88
+ print_foreign_key_creation('comments') do
89
+ conn.add_foreign_key(:comments, :users, :dependent => :delete)
90
+ end
91
+ print_foreign_key_creation('searches') do
92
+ conn.add_foreign_key(:searches, :users, :name => "user_search_special_fk", :dependent => :delete)
93
+ end
94
+ print_foreign_key_creation('special_user_records') do
95
+ conn.add_foreign_key(:special_user_records, :users, :column => "special_user_id", :dependent => :delete)
96
+ end
67
97
  end
68
98
  end
69
99
  end
@@ -0,0 +1,18 @@
1
+ mysql:
2
+ adapter: mysql2
3
+ database: foreigner-matcher_test
4
+ username: root
5
+ encoding: utf8
6
+ jdbc-mysql:
7
+ adapter: jdbcmysql
8
+ database: foreigner-matcher_test
9
+ username: root
10
+ encoding: utf8
11
+ postgres:
12
+ adapter: postgresql
13
+ database: foreigner-matcher_test
14
+ username: postgres
15
+ jdbc-postgres:
16
+ adapter: jdbcpostgresql
17
+ database: foreigner-matcher_test
18
+ username: postgres
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in foreigner-matcher.gemspec
4
+ gemspec :path => '../../'
5
+
6
+ group :test do
7
+ gem "rake"
8
+ gem "rspec", "~> 2.9.0"
9
+ gem "mocha", "~> 0.11.0"
10
+ gem "activerecord", "~> 3.0.0"
11
+ gem "railties", "~> 3.0.0"
12
+
13
+ platforms :ruby do
14
+ gem "mysql2", "~> 0.2.0"
15
+ gem "pg", "~> 0.13.2"
16
+ end
17
+
18
+ platforms :jruby do
19
+ gem "activerecord-jdbcmysql-adapter"
20
+ gem "activerecord-jdbcpostgresql-adapter"
21
+ end
22
+ end
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: /home/cameron/projects/my_stuff/foreigner-matcher
3
+ specs:
4
+ foreigner-matcher (0.2.1)
5
+ foreigner (>= 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionpack (3.0.12)
12
+ activemodel (= 3.0.12)
13
+ activesupport (= 3.0.12)
14
+ builder (~> 2.1.2)
15
+ erubis (~> 2.6.6)
16
+ i18n (~> 0.5.0)
17
+ rack (~> 1.2.5)
18
+ rack-mount (~> 0.6.14)
19
+ rack-test (~> 0.5.7)
20
+ tzinfo (~> 0.3.23)
21
+ activemodel (3.0.12)
22
+ activesupport (= 3.0.12)
23
+ builder (~> 2.1.2)
24
+ i18n (~> 0.5.0)
25
+ activerecord (3.0.12)
26
+ activemodel (= 3.0.12)
27
+ activesupport (= 3.0.12)
28
+ arel (~> 2.0.10)
29
+ tzinfo (~> 0.3.23)
30
+ activerecord-jdbc-adapter (1.2.2)
31
+ activerecord-jdbcmysql-adapter (1.2.2)
32
+ activerecord-jdbc-adapter (~> 1.2.2)
33
+ jdbc-mysql (~> 5.1.0)
34
+ activerecord-jdbcpostgresql-adapter (1.2.2)
35
+ activerecord-jdbc-adapter (~> 1.2.2)
36
+ jdbc-postgres (>= 9.0, < 9.2)
37
+ activesupport (3.0.12)
38
+ arel (2.0.10)
39
+ builder (2.1.2)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.6.6)
42
+ abstract (>= 1.0.0)
43
+ foreigner (1.1.6)
44
+ activerecord (>= 3.0.0)
45
+ i18n (0.5.0)
46
+ jdbc-mysql (5.1.13)
47
+ jdbc-postgres (9.1.901)
48
+ json (1.7.0)
49
+ json (1.7.0-java)
50
+ metaclass (0.0.1)
51
+ mocha (0.11.3)
52
+ metaclass (~> 0.0.1)
53
+ mysql2 (0.2.18)
54
+ pg (0.13.2)
55
+ rack (1.2.5)
56
+ rack-mount (0.6.14)
57
+ rack (>= 1.0.0)
58
+ rack-test (0.5.7)
59
+ rack (>= 1.0)
60
+ railties (3.0.12)
61
+ actionpack (= 3.0.12)
62
+ activesupport (= 3.0.12)
63
+ rake (>= 0.8.7)
64
+ rdoc (~> 3.4)
65
+ thor (~> 0.14.4)
66
+ rake (0.9.2.2)
67
+ rdoc (3.12)
68
+ json (~> 1.4)
69
+ rspec (2.9.0)
70
+ rspec-core (~> 2.9.0)
71
+ rspec-expectations (~> 2.9.0)
72
+ rspec-mocks (~> 2.9.0)
73
+ rspec-core (2.9.0)
74
+ rspec-expectations (2.9.1)
75
+ diff-lcs (~> 1.1.3)
76
+ rspec-mocks (2.9.0)
77
+ thor (0.14.6)
78
+ tzinfo (0.3.33)
79
+
80
+ PLATFORMS
81
+ java
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ activerecord (~> 3.0.0)
86
+ activerecord-jdbcmysql-adapter
87
+ activerecord-jdbcpostgresql-adapter
88
+ foreigner-matcher!
89
+ mocha (~> 0.11.0)
90
+ mysql2 (~> 0.2.0)
91
+ pg (~> 0.13.2)
92
+ railties (~> 3.0.0)
93
+ rake
94
+ rspec (~> 2.9.0)
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in foreigner-matcher.gemspec
4
+ gemspec :path => '../../'
5
+
6
+ group :test do
7
+ gem "rake"
8
+ gem "rspec", "~> 2.9.0"
9
+ gem "mocha", "~> 0.11.0"
10
+ gem "activerecord", "~> 3.1.0"
11
+ gem "railties", "~> 3.1.0"
12
+
13
+ platforms :ruby do
14
+ gem "mysql2", "~> 0.3.0"
15
+ gem "pg", "~> 0.13.2"
16
+ end
17
+
18
+ platforms :jruby do
19
+ gem "activerecord-jdbcmysql-adapter"
20
+ gem "activerecord-jdbcpostgresql-adapter"
21
+ end
22
+ end
@@ -0,0 +1,106 @@
1
+ PATH
2
+ remote: /home/cameron/projects/my_stuff/foreigner-matcher
3
+ specs:
4
+ foreigner-matcher (0.2.1)
5
+ foreigner (>= 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionpack (3.1.4)
11
+ activemodel (= 3.1.4)
12
+ activesupport (= 3.1.4)
13
+ builder (~> 3.0.0)
14
+ erubis (~> 2.7.0)
15
+ i18n (~> 0.6)
16
+ rack (~> 1.3.6)
17
+ rack-cache (~> 1.1)
18
+ rack-mount (~> 0.8.2)
19
+ rack-test (~> 0.6.1)
20
+ sprockets (~> 2.0.3)
21
+ activemodel (3.1.4)
22
+ activesupport (= 3.1.4)
23
+ builder (~> 3.0.0)
24
+ i18n (~> 0.6)
25
+ activerecord (3.1.4)
26
+ activemodel (= 3.1.4)
27
+ activesupport (= 3.1.4)
28
+ arel (~> 2.2.3)
29
+ tzinfo (~> 0.3.29)
30
+ activerecord-jdbc-adapter (1.2.2)
31
+ activerecord-jdbcmysql-adapter (1.2.2)
32
+ activerecord-jdbc-adapter (~> 1.2.2)
33
+ jdbc-mysql (~> 5.1.0)
34
+ activerecord-jdbcpostgresql-adapter (1.2.2)
35
+ activerecord-jdbc-adapter (~> 1.2.2)
36
+ jdbc-postgres (>= 9.0, < 9.2)
37
+ activesupport (3.1.4)
38
+ multi_json (~> 1.0)
39
+ arel (2.2.3)
40
+ builder (3.0.0)
41
+ diff-lcs (1.1.3)
42
+ erubis (2.7.0)
43
+ foreigner (1.1.6)
44
+ activerecord (>= 3.0.0)
45
+ hike (1.2.1)
46
+ i18n (0.6.0)
47
+ jdbc-mysql (5.1.13)
48
+ jdbc-postgres (9.1.901)
49
+ json (1.7.0)
50
+ json (1.7.0-java)
51
+ metaclass (0.0.1)
52
+ mocha (0.11.3)
53
+ metaclass (~> 0.0.1)
54
+ multi_json (1.3.4)
55
+ mysql2 (0.3.11)
56
+ pg (0.13.2)
57
+ rack (1.3.6)
58
+ rack-cache (1.2)
59
+ rack (>= 0.4)
60
+ rack-mount (0.8.3)
61
+ rack (>= 1.0.0)
62
+ rack-ssl (1.3.2)
63
+ rack
64
+ rack-test (0.6.1)
65
+ rack (>= 1.0)
66
+ railties (3.1.4)
67
+ actionpack (= 3.1.4)
68
+ activesupport (= 3.1.4)
69
+ rack-ssl (~> 1.3.2)
70
+ rake (>= 0.8.7)
71
+ rdoc (~> 3.4)
72
+ thor (~> 0.14.6)
73
+ rake (0.9.2.2)
74
+ rdoc (3.12)
75
+ json (~> 1.4)
76
+ rspec (2.9.0)
77
+ rspec-core (~> 2.9.0)
78
+ rspec-expectations (~> 2.9.0)
79
+ rspec-mocks (~> 2.9.0)
80
+ rspec-core (2.9.0)
81
+ rspec-expectations (2.9.1)
82
+ diff-lcs (~> 1.1.3)
83
+ rspec-mocks (2.9.0)
84
+ sprockets (2.0.4)
85
+ hike (~> 1.2)
86
+ rack (~> 1.0)
87
+ tilt (~> 1.1, != 1.3.0)
88
+ thor (0.14.6)
89
+ tilt (1.3.3)
90
+ tzinfo (0.3.33)
91
+
92
+ PLATFORMS
93
+ java
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ activerecord (~> 3.1.0)
98
+ activerecord-jdbcmysql-adapter
99
+ activerecord-jdbcpostgresql-adapter
100
+ foreigner-matcher!
101
+ mocha (~> 0.11.0)
102
+ mysql2 (~> 0.3.0)
103
+ pg (~> 0.13.2)
104
+ railties (~> 3.1.0)
105
+ rake
106
+ rspec (~> 2.9.0)
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+
3
+ case $DB in
4
+ 'mysql')
5
+ mysql -e 'create database `foreigner-matcher_test`;'
6
+ ;;
7
+ 'postgres')
8
+ psql -c 'create database "foreigner-matcher_test";' -U postgres
9
+ ;;
10
+ esac
@@ -28,9 +28,10 @@ module ForeignerMatcher # :nodoc:
28
28
  private
29
29
 
30
30
  def foreign_key_definition
31
- defaults = { :primary_key => "id", :column => "#{@parent.singularize}_id" }
32
- defaults[:name] = "#{@child.class.table_name}_#{defaults[:column]}_fk"
33
- full_options = defaults.merge(@options)
31
+ defaults = { :primary_key => "id", :column => "#{@parent.singularize}_id" }
32
+ defaults[:name] = "#{@child.class.table_name}_#{defaults[:column]}_fk"
33
+ defaults[:dependent] = nil if postgresql_db?
34
+ full_options = defaults.merge(@options)
34
35
  Foreigner::ConnectionAdapters::ForeignKeyDefinition.new(@child.class.table_name, @parent.pluralize, full_options)
35
36
  end
36
37
 
@@ -50,6 +51,10 @@ module ForeignerMatcher # :nodoc:
50
51
  fks = child_foreign_keys
51
52
  fks.empty? ? 'foreign keys' : fks
52
53
  end
54
+
55
+ def postgresql_db?
56
+ ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
57
+ end
53
58
  end
54
59
 
55
60
  # Ensures that parent table has foreign key
@@ -1,5 +1,5 @@
1
1
  module Foreigner
2
2
  module Matcher
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -5,12 +5,32 @@ require 'rails/railtie'
5
5
  require 'foreigner'
6
6
 
7
7
  # Open a database connection
8
- db_config = YAML::load(File.open("#{File.dirname(__FILE__)}/config/database.yml"))
8
+ db_config_yml = File.dirname(__FILE__)
9
+ db_config_yml << '/../ci' if ENV['TRAVIS']
10
+ db_config_yml << '/config/database.yml'
11
+ db_configs = YAML::load(File.open(db_config_yml))
12
+ db_adapter = ENV['DB']
13
+ db_adapter = 'jdbc-' + db_adapter if RUBY_PLATFORM == 'java'
14
+ db_config = db_configs[db_adapter]
15
+ ActiveRecord::Base.configurations = db_configs
9
16
  ActiveRecord::Base.establish_connection(db_config)
10
17
 
11
- foreigner_railtie = Foreigner::Railtie.new
12
- foreigner_railtie.run_initializers(foreigner_railtie)
13
-
14
18
  # Requires supporting files with custom matchers and macros, etc,
15
19
  # in ./support/ and its subdirectories.
16
20
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
21
+
22
+ include ActiveRecordVersionHelpers
23
+ if active_record_version > 3.0
24
+ Foreigner::Railtie.instance.run_initializers
25
+ else
26
+ foreigner_railtie = Foreigner::Railtie.new
27
+ foreigner_railtie.run_initializers(foreigner_railtie)
28
+ end
29
+
30
+ # Configure rspec options
31
+ RSpec.configure do |config|
32
+ config.mock_framework = :mocha
33
+
34
+ config.include(ConnectionHelpers)
35
+ config.include(ForeignKeyDefinitionHelpers)
36
+ end
@@ -0,0 +1,8 @@
1
+ module ActiveRecordVersionHelpers
2
+ def active_record_version
3
+ [
4
+ ActiveRecord::VERSION::MAJOR,
5
+ ActiveRecord::VERSION::MINOR
6
+ ].join('.').to_f
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module ConnectionHelpers
2
+ def foreign_keys_for(table_name)
3
+ ActiveRecord::Base.connection.foreign_keys(table_name)
4
+ end
5
+
6
+ def postgresql_db?
7
+ ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module ForeignKeyDefinitionHelpers
2
+ def stub_fkd_to_s_with(string_value='ForeignKeyDefinition.tos')
3
+ Foreigner::ConnectionAdapters::ForeignKeyDefinition.any_instance.stubs(:to_s).returns(string_value)
4
+ end
5
+ end
@@ -1,7 +1,8 @@
1
- class User < ActiveRecord::Base ; end
2
- class UserLogin < ActiveRecord::Base ; end
3
- class UserType < ActiveRecord::Base ; end
4
- class Comment < ActiveRecord::Base ; end
5
- class Search < ActiveRecord::Base ; end
6
- class SpecialUserRecord < ActiveRecord::Base ; end
1
+ class User < ActiveRecord::Base ; end
2
+ class DefaultOption < ActiveRecord::Base ; end
3
+ class UserLogin < ActiveRecord::Base ; end
4
+ class UserType < ActiveRecord::Base ; end
5
+ class Comment < ActiveRecord::Base ; end
6
+ class Search < ActiveRecord::Base ; end
7
+ class SpecialUserRecord < ActiveRecord::Base ; end
7
8
  class TableWithoutForeignKey < ActiveRecord::Base ; end
@@ -8,15 +8,17 @@ describe Comment do
8
8
  end
9
9
 
10
10
  it 'should set failure_message_for_should message' do
11
+ stub_fkd_to_s_with('expected fk')
11
12
  matcher = have_foreign_key_for(:comments)
12
13
  matcher.matches?(subject)
13
- matcher.failure_message_for_should.should == "expected #{subject.connection.foreign_keys('comments')} to include #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('comments', 'comments', :primary_key => 'id', :column => 'comment_id', :name => 'comments_comment_id_fk')}"
14
+ matcher.failure_message_for_should.should == "expected #{foreign_keys_for('comments')} to include expected fk"
14
15
  end
15
16
 
16
17
  it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
17
19
  matcher = have_foreign_key_for(:users, :dependent => :delete)
18
20
  matcher.matches?(subject)
19
- matcher.failure_message_for_should_not.should == "expected #{subject.connection.foreign_keys('comments')} to exclude #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('comments', 'users', :primary_key => 'id', :column => 'user_id', :name => 'comments_user_id_fk', :dependent => :delete)}"
21
+ matcher.failure_message_for_should_not.should == "expected #{foreign_keys_for('comments')} to exclude unexpected fk"
20
22
  end
21
23
  end
22
24
 
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe DefaultOption do
4
+ describe 'messages' do
5
+ it 'should contain a description' do
6
+ matcher = have_foreign_key_for(:users)
7
+ matcher.description.should == 'have a foreign key for users'
8
+ end
9
+
10
+ it 'should set failure_message_for_should message' do
11
+ stub_fkd_to_s_with('expected fk')
12
+ matcher = have_foreign_key_for(:default_options)
13
+ matcher.matches?(subject)
14
+ matcher.failure_message_for_should.should == "expected #{foreign_keys_for('default_options')} to include expected fk"
15
+ end
16
+
17
+ it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
19
+ matcher = have_foreign_key_for(:users)
20
+ matcher.matches?(subject)
21
+ matcher.failure_message_for_should_not.should == "expected #{foreign_keys_for('default_options')} to exclude unexpected fk"
22
+ end
23
+ end
24
+
25
+ describe 'matcher' do
26
+ class DefaultOptionTester
27
+ include ConnectionHelpers
28
+ end
29
+
30
+ it { should have_foreign_key_for(:user) }
31
+ it { should have_foreign_key_for(:users) }
32
+
33
+ if DefaultOptionTester.new.postgresql_db?
34
+ context 'with :dependent => nil option' do
35
+ it { should have_foreign_key_for(:user, :dependent => nil) }
36
+ it { should have_foreign_key_for(:users, :dependent => nil) }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -8,15 +8,17 @@ describe Search do
8
8
  end
9
9
 
10
10
  it 'should set failure_message_for_should message' do
11
+ stub_fkd_to_s_with('expected fk')
11
12
  matcher = have_foreign_key_for(:searches)
12
13
  matcher.matches?(subject)
13
- matcher.failure_message_for_should.should == "expected #{subject.connection.foreign_keys('searches')} to include #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('searches', 'searches', :primary_key => 'id', :column => 'search_id', :name => 'searches_search_id_fk')}"
14
+ matcher.failure_message_for_should.should == "expected #{foreign_keys_for('searches')} to include expected fk"
14
15
  end
15
16
 
16
17
  it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
17
19
  matcher = have_foreign_key_for(:users, :name => 'user_search_special_fk', :dependent => :delete)
18
20
  matcher.matches?(subject)
19
- matcher.failure_message_for_should_not.should == "expected #{subject.connection.foreign_keys('searches')} to exclude #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('searches', 'users', :primary_key => 'id', :column => 'user_id', :name => 'user_search_special_fk', :dependent => :delete)}"
21
+ matcher.failure_message_for_should_not.should == "expected #{foreign_keys_for('searches')} to exclude unexpected fk"
20
22
  end
21
23
  end
22
24
 
@@ -8,15 +8,17 @@ describe SpecialUserRecord do
8
8
  end
9
9
 
10
10
  it 'should set failure_message_for_should message' do
11
+ stub_fkd_to_s_with('expected fk')
11
12
  matcher = have_foreign_key_for(:special_user_records)
12
13
  matcher.matches?(subject)
13
- matcher.failure_message_for_should.should == "expected #{subject.connection.foreign_keys('special_user_records')} to include #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('special_user_records', 'special_user_records', :primary_key => 'id', :column => 'special_user_record_id', :name => 'special_user_records_special_user_record_id_fk')}"
14
+ matcher.failure_message_for_should.should == "expected #{foreign_keys_for('special_user_records')} to include expected fk"
14
15
  end
15
16
 
16
17
  it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
17
19
  matcher = have_foreign_key_for(:users, :column => 'special_user_id', :name => 'special_user_records_special_user_id_fk', :dependent => :delete)
18
20
  matcher.matches?(subject)
19
- matcher.failure_message_for_should_not.should == "expected #{subject.connection.foreign_keys('special_user_records')} to exclude #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('special_user_records', 'users', :primary_key => 'id', :column => 'special_user_id', :name => 'special_user_records_special_user_id_fk', :dependent => :delete)}"
21
+ matcher.failure_message_for_should_not.should == "expected #{foreign_keys_for('special_user_records')} to exclude unexpected fk"
20
22
  end
21
23
  end
22
24
 
@@ -9,13 +9,15 @@ describe TableWithoutForeignKey do
9
9
  end
10
10
 
11
11
  it 'should set failure_message_for_should message' do
12
+ stub_fkd_to_s_with('expected fk')
12
13
  matcher.matches?(subject)
13
- matcher.failure_message_for_should.should == "expected foreign keys to include #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('table_without_foreign_keys', 'users', :primary_key => 'id', :column => 'user_id', :name => 'table_without_foreign_keys_user_id_fk')}"
14
+ matcher.failure_message_for_should.should == "expected foreign keys to include expected fk"
14
15
  end
15
16
 
16
17
  it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
17
19
  matcher.matches?(subject)
18
- matcher.failure_message_for_should_not.should == "expected foreign keys to exclude #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('table_without_foreign_keys', 'users', :primary_key => 'id', :column => 'user_id', :name => 'table_without_foreign_keys_user_id_fk')}"
20
+ matcher.failure_message_for_should_not.should == "expected foreign keys to exclude unexpected fk"
19
21
  end
20
22
  end
21
23
 
@@ -8,15 +8,17 @@ describe UserLogin do
8
8
  end
9
9
 
10
10
  it 'should set failure_message_for_should message' do
11
+ stub_fkd_to_s_with('expected fk')
11
12
  matcher = have_foreign_key_for(:user_logins)
12
13
  matcher.matches?(subject)
13
- matcher.failure_message_for_should.should == "expected #{subject.connection.foreign_keys('user_logins')} to include #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('user_logins', 'user_logins', :primary_key => 'id', :column => 'user_login_id', :name => 'user_logins_user_login_id_fk')}"
14
+ matcher.failure_message_for_should.should == "expected #{foreign_keys_for('user_logins')} to include expected fk"
14
15
  end
15
16
 
16
17
  it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
17
19
  matcher = have_foreign_key_for(:users, :dependent => :nullify)
18
20
  matcher.matches?(subject)
19
- matcher.failure_message_for_should_not.should == "expected #{subject.connection.foreign_keys('user_logins')} to exclude #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('user_logins', 'users', :primary_key => 'id', :column => 'user_id', :name => 'user_logins_user_id_fk', :dependent => :nullify)}"
21
+ matcher.failure_message_for_should_not.should == "expected #{foreign_keys_for('user_logins')} to exclude unexpected fk"
20
22
  end
21
23
  end
22
24
 
@@ -8,20 +8,26 @@ describe UserType do
8
8
  end
9
9
 
10
10
  it 'should set failure_message_for_should message' do
11
+ stub_fkd_to_s_with('expected fk')
11
12
  matcher = have_foreign_key_for(:user_types)
12
13
  matcher.matches?(subject)
13
- matcher.failure_message_for_should.should == "expected #{subject.connection.foreign_keys('user_types')} to include #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('user_types', 'user_types', :primary_key => 'id', :column => 'user_type_id', :name => 'user_types_user_type_id_fk')}"
14
+ matcher.failure_message_for_should.should == "expected #{foreign_keys_for('user_types')} to include expected fk"
14
15
  end
15
16
 
16
17
  it 'should set failure_message_for_should_not message' do
18
+ stub_fkd_to_s_with('unexpected fk')
17
19
  matcher = have_foreign_key_for(:users)
18
20
  matcher.matches?(subject)
19
- matcher.failure_message_for_should_not.should == "expected #{subject.connection.foreign_keys('user_types')} to exclude #{Foreigner::ConnectionAdapters::ForeignKeyDefinition.new('user_types', 'users', :primary_key => 'id', :column => 'user_id', :name => 'user_types_user_id_fk')}"
21
+ matcher.failure_message_for_should_not.should == "expected #{foreign_keys_for('user_types')} to exclude unexpected fk"
20
22
  end
21
23
  end
22
24
 
23
25
  describe 'matcher' do
24
- it { should have_foreign_key_for(:user) }
25
- it { should have_foreign_key_for(:users) }
26
+ before do
27
+ @options = postgresql_db? ? { :dependent => :restrict } : {}
28
+ end
29
+
30
+ it { should have_foreign_key_for(:user, @options) }
31
+ it { should have_foreign_key_for(:users, @options) }
26
32
  end
27
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreigner-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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: 2011-08-29 00:00:00.000000000Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreigner
16
- requirement: &24508860 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24508860
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
25
30
  description: Adds rspec matcher to verify the presence of foreign keys generated by
26
31
  Foreigner in a table schema
27
32
  email:
@@ -31,19 +36,30 @@ extensions: []
31
36
  extra_rdoc_files: []
32
37
  files:
33
38
  - .gitignore
39
+ - .travis.yml
34
40
  - Gemfile
35
41
  - Gemfile.lock
36
42
  - LICENSE.txt
37
43
  - README.md
38
44
  - Rakefile
45
+ - ci/config/database.yml
46
+ - ci/gemfiles/rspec2_9_rails3_0.gemfile
47
+ - ci/gemfiles/rspec2_9_rails3_0.gemfile.lock
48
+ - ci/gemfiles/rspec2_9_rails3_1.gemfile
49
+ - ci/gemfiles/rspec2_9_rails3_1.gemfile.lock
50
+ - ci/script/create_db.sh
39
51
  - foreigner-matcher.gemspec
40
52
  - lib/foreigner-matcher.rb
41
53
  - lib/foreigner-matcher/version.rb
42
54
  - spec/config/database.yml.example
43
55
  - spec/foreigner_matcher_spec.rb
44
56
  - spec/spec_helper.rb
57
+ - spec/support/active_record_version_helpers.rb
58
+ - spec/support/connection_helpers.rb
59
+ - spec/support/foreign_key_definition_helpers.rb
45
60
  - spec/support/test_models.rb
46
61
  - spec/test_models/comment_spec.rb
62
+ - spec/test_models/default_option_spec.rb
47
63
  - spec/test_models/search_spec.rb
48
64
  - spec/test_models/special_user_record_spec.rb
49
65
  - spec/test_models/table_without_foreign_key_spec.rb
@@ -69,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
85
  version: '0'
70
86
  requirements: []
71
87
  rubyforge_project: foreigner-matcher
72
- rubygems_version: 1.8.6
88
+ rubygems_version: 1.8.23
73
89
  signing_key:
74
90
  specification_version: 3
75
91
  summary: Rspec matcher for testing the presence of foreign keys generated by Foreigner