foreigner-matcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +65 -0
- data/foreigner-matcher.gemspec +23 -0
- data/lib/foreigner-matcher.rb +62 -0
- data/lib/foreigner-matcher/version.rb +5 -0
- data/spec/config/database.yml.example +6 -0
- data/spec/foreigner_matcher_spec.rb +13 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/test_models.rb +7 -0
- data/spec/test_models/comment_spec.rb +27 -0
- data/spec/test_models/search_spec.rb +27 -0
- data/spec/test_models/special_user_record_spec.rb +27 -0
- data/spec/test_models/table_without_foreign_key_spec.rb +8 -0
- data/spec/test_models/user_login_spec.rb +27 -0
- data/spec/test_models/user_type_spec.rb +27 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in foreigner-matcher.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "kramdown", "~> 0.13.2"
|
8
|
+
end
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "rspec", "~> 2.5"
|
12
|
+
gem "ruby-debug", "~> 0.10.4"
|
13
|
+
gem "activerecord", ">= 2.3.11"
|
14
|
+
gem "mysql2", "~> 0.2.7"
|
15
|
+
gem "mysql", "~> 2.8.1"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Cameron Dykes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# foreigner-matcher
|
2
|
+
|
3
|
+
RSpec matcher for the [Foreigner gem](https://github.com/matthuhiggins/foreigner).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install foreigner-matcher
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
The matcher can be used in RSpec to ensure an ActiveRecord model has the desired foreign key. The minimum argument is the table name that the subject model should have a foreign key to.
|
12
|
+
|
13
|
+
For example. Given these two models:
|
14
|
+
|
15
|
+
class User < ActiveRecord::Base
|
16
|
+
has_many user_logins
|
17
|
+
end
|
18
|
+
|
19
|
+
class UserLogin < ActiveRecord::Base
|
20
|
+
belongs_to user
|
21
|
+
end
|
22
|
+
|
23
|
+
The spec would look like this:
|
24
|
+
|
25
|
+
describe UserLogin do
|
26
|
+
it { should have_foreign_key_for(:users) }
|
27
|
+
end
|
28
|
+
|
29
|
+
In addition to the table name, you can include any options that add_foreign_key (see [Foreigner](https://github.com/matthuhiggins/foreigner)) accepts. Some more examples using the same models:
|
30
|
+
|
31
|
+
it { should have_foreign_key_for(:users, :dependent => :delete) }
|
32
|
+
it { should have_foreign_key_for(:users, :column => "unique_user_id", :name => "user_logins_unique_user_id_fk") }
|
33
|
+
it { should_not have_foreign_key_for(:users, :dependent => :nullify) }
|
34
|
+
|
35
|
+
**A Note on Table Names**
|
36
|
+
|
37
|
+
These examples will also work passing <tt>:user</tt> as the table name. Why? The example has a <tt>belongs_to</tt> relationship, and my feeling is that it reads better to say "it should have foreign key for user". This is just my taste; use what makes sense to you!
|
38
|
+
|
39
|
+
## Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2011 Cameron Dykes. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
namespace :db do
|
5
|
+
namespace :test do
|
6
|
+
desc "Reset the test database"
|
7
|
+
task :reset do
|
8
|
+
require 'yaml'
|
9
|
+
require 'active_record'
|
10
|
+
|
11
|
+
def print_table_creation(new_table)
|
12
|
+
print "\tCreating #{new_table}..."
|
13
|
+
yield
|
14
|
+
print "done\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_foreign_key_creation(fk_table)
|
18
|
+
print "\tCreating key on #{fk_table}..."
|
19
|
+
yield
|
20
|
+
print "done\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "Establishing connection to test db..."
|
24
|
+
db_config = YAML::load(File.open("#{File.dirname(__FILE__)}/spec/config/database.yml"))
|
25
|
+
ActiveRecord::Base.establish_connection(db_config)
|
26
|
+
conn = ActiveRecord::Base.connection
|
27
|
+
puts "Connected to #{db_config['database']} via a #{db_config['adapter']} connector"
|
28
|
+
|
29
|
+
puts "\nDropping test tables, if they exist"
|
30
|
+
%w( user_logins user_types comments searches special_user_records table_without_foreign_keys users ).each do |test_table|
|
31
|
+
print "\tDropping #{test_table}..."
|
32
|
+
conn.execute("drop table if exists #{test_table}")
|
33
|
+
print "done\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
puts "\nCreating test tables"
|
37
|
+
print_table_creation('users') do
|
38
|
+
conn.create_table(:users) do |t|
|
39
|
+
t.string :username
|
40
|
+
t.string :email, :default => 'nobody@localhost'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
print_table_creation('special_user_records') do
|
44
|
+
conn.create_table(:special_user_records) do |t|
|
45
|
+
t.integer :special_user_id
|
46
|
+
end
|
47
|
+
end
|
48
|
+
[ :user_logins, :user_types, :comments, :searches, :table_without_foreign_keys ].each do |user_table|
|
49
|
+
print_table_creation(user_table) do
|
50
|
+
conn.create_table(user_table) do |t|
|
51
|
+
t.integer :user_id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
require 'foreigner'
|
57
|
+
puts "\nCreating foreign keys"
|
58
|
+
print_foreign_key_creation('user_logins') { conn.add_foreign_key(:user_logins, :users, :dependent => :nullify) }
|
59
|
+
print_foreign_key_creation('user_types') { conn.add_foreign_key(:user_types, :users, :dependent => :restrict) }
|
60
|
+
print_foreign_key_creation('comments') { conn.add_foreign_key(:comments, :users, :dependent => :delete) }
|
61
|
+
print_foreign_key_creation('searches') { conn.add_foreign_key(:searches, :users, :name => "user_search_special_fk", :dependent => :delete) }
|
62
|
+
print_foreign_key_creation('special_user_records') { conn.add_foreign_key(:special_user_records, :users, :column => "special_user_id", :dependent => :delete) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "foreigner-matcher/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "foreigner-matcher"
|
7
|
+
s.version = Foreigner::Matcher::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Cameron Dykes"]
|
10
|
+
s.email = ["yellow5c@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/yellow5/foreigner-matcher"
|
12
|
+
s.summary = %q{Rspec matcher for testing the presence of foreign keys generated by Foreigner}
|
13
|
+
s.description = %q{Adds rspec matcher to verify the presence of foreign keys generated by Foreigner in a table schema}
|
14
|
+
|
15
|
+
s.add_dependency "foreigner", "0.9.1"
|
16
|
+
|
17
|
+
s.rubyforge_project = "foreigner-matcher"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ForeignerMatcher # :nodoc:
|
2
|
+
|
3
|
+
class HaveForeignKeyFor # :nodoc:
|
4
|
+
def initialize(parent, options={})
|
5
|
+
@parent = parent.to_s
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(child)
|
10
|
+
@child = child
|
11
|
+
child_foreign_keys.include? foreign_key_definition
|
12
|
+
end
|
13
|
+
|
14
|
+
def description
|
15
|
+
desc = "have a foreign key for #{@parent}"
|
16
|
+
desc += " with #{@options.inspect}" unless @options.empty?
|
17
|
+
desc
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_for_should
|
21
|
+
"expected #{child_foreign_keys} to include #{foreign_key_definition}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message_for_should_not
|
25
|
+
"expected #{child_foreign_keys} to exclude #{foreign_key_definition}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
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)
|
34
|
+
Foreigner::ConnectionAdapters::ForeignKeyDefinition.new(@child.class.table_name, @parent.pluralize, full_options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def child_foreign_keys
|
38
|
+
@child.connection.foreign_keys(@child.class.table_name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# Ensures that parent table has foreign key
|
45
|
+
#
|
46
|
+
# * <b>parent</b> - The table to check for foreign key
|
47
|
+
# * <b>options</b> - Accepts any option that works with add_foreign_key in Foreigner
|
48
|
+
#
|
49
|
+
# <em>Defaults</em>
|
50
|
+
# :primary_key Column referenced on parent table (default: id)
|
51
|
+
# :column Foreign key column (default: #{@parent.singluarize}_id)
|
52
|
+
# :name Foreign key index name (default: #{@child.class.table_name}_#{@parent.singularize}_id)
|
53
|
+
#
|
54
|
+
# <b>Examples</b>
|
55
|
+
# it { should have_foreign_key_for(:users) }
|
56
|
+
# it { should have_foreign_key_for(:users, :dependent => :delete) }
|
57
|
+
# it { should have_foreign_key_for(:users, :column => "some_column_name", :name => "users_some_column_name_fk") }
|
58
|
+
# it { should_not have_foreign_key_for(:users, :dependent => :nullify) }
|
59
|
+
|
60
|
+
def have_foreign_key_for(parent, options={})
|
61
|
+
ForeignerMatcher::HaveForeignKeyFor.new(parent, options)
|
62
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ForeignerMatcher::HaveForeignKeyFor do
|
4
|
+
describe 'methods' do
|
5
|
+
subject { ForeignerMatcher::HaveForeignKeyFor.new(mock) }
|
6
|
+
|
7
|
+
[ :matches?, :description, :failure_message_for_should, :failure_message_for_should_not ].each do |klass_method|
|
8
|
+
it "should respond to #{klass_method}" do
|
9
|
+
subject.should respond_to(klass_method)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ruby-debug'
|
2
|
+
require 'yaml'
|
3
|
+
require 'active_record'
|
4
|
+
require 'foreigner-matcher'
|
5
|
+
|
6
|
+
# Open a database connection
|
7
|
+
db_config = YAML::load(File.open("#{File.dirname(__FILE__)}/config/database.yml"))
|
8
|
+
ActiveRecord::Base.establish_connection(db_config)
|
9
|
+
|
10
|
+
# Require foreigner after ActiveRecord connection is establisehd.
|
11
|
+
require 'foreigner'
|
12
|
+
|
13
|
+
# Requires supporting files with custom matchers and macros, etc,
|
14
|
+
# in ./support/ and its subdirectories.
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
@@ -0,0 +1,7 @@
|
|
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
|
7
|
+
class TableWithoutForeignKey < ActiveRecord::Base ; end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Comment do
|
4
|
+
describe 'messages' do
|
5
|
+
it "should contain a description" do
|
6
|
+
matcher = have_foreign_key_for(:users, :dependent => :delete)
|
7
|
+
matcher.description.should == "have a foreign key for users with {:dependent=>:delete}"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set failure_message_for_should message" do
|
11
|
+
matcher = have_foreign_key_for(:comments)
|
12
|
+
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
|
+
end
|
15
|
+
|
16
|
+
it "should set failure_message_for_should_not message" do
|
17
|
+
matcher = have_foreign_key_for(:users, :dependent => :delete)
|
18
|
+
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)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'matcher' do
|
24
|
+
it { should have_foreign_key_for(:user, :dependent => :delete) }
|
25
|
+
it { should have_foreign_key_for(:users, :dependent => :delete) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Search do
|
4
|
+
describe 'messages' do
|
5
|
+
it "should contain a description" do
|
6
|
+
matcher = have_foreign_key_for(:users, :name => "user_search_special_fk", :dependent => :delete)
|
7
|
+
matcher.description.should == "have a foreign key for users with {:dependent=>:delete, :name=>\"user_search_special_fk\"}"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set failure_message_for_should message" do
|
11
|
+
matcher = have_foreign_key_for(:searches)
|
12
|
+
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
|
+
end
|
15
|
+
|
16
|
+
it "should set failure_message_for_should_not message" do
|
17
|
+
matcher = have_foreign_key_for(:users, :name => "user_search_special_fk", :dependent => :delete)
|
18
|
+
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)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'matcher' do
|
24
|
+
it { should have_foreign_key_for(:user, :name => "user_search_special_fk", :dependent => :delete) }
|
25
|
+
it { should have_foreign_key_for(:users, :name => "user_search_special_fk", :dependent => :delete) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SpecialUserRecord do
|
4
|
+
describe 'messages' do
|
5
|
+
it "should contain a description" do
|
6
|
+
matcher = have_foreign_key_for(:users, :column => "special_user_id", :name => "special_user_records_special_user_id_fk", :dependent => :delete)
|
7
|
+
matcher.description.should == "have a foreign key for users with {:column=>\"special_user_id\", :dependent=>:delete, :name=>\"special_user_records_special_user_id_fk\"}"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set failure_message_for_should message" do
|
11
|
+
matcher = have_foreign_key_for(:special_user_records)
|
12
|
+
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
|
+
end
|
15
|
+
|
16
|
+
it "should set failure_message_for_should_not message" do
|
17
|
+
matcher = have_foreign_key_for(:users, :column => "special_user_id", :name => "special_user_records_special_user_id_fk", :dependent => :delete)
|
18
|
+
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)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'matcher' do
|
24
|
+
it { should have_foreign_key_for(:user, :column => "special_user_id", :name => "special_user_records_special_user_id_fk", :dependent => :delete) }
|
25
|
+
it { should have_foreign_key_for(:users, :column => "special_user_id", :name => "special_user_records_special_user_id_fk", :dependent => :delete) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UserLogin do
|
4
|
+
describe 'messages' do
|
5
|
+
it "should contain a description" do
|
6
|
+
matcher = have_foreign_key_for(:users, :dependent => :nullify)
|
7
|
+
matcher.description.should == "have a foreign key for users with {:dependent=>:nullify}"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set failure_message_for_should message" do
|
11
|
+
matcher = have_foreign_key_for(:user_logins)
|
12
|
+
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
|
+
end
|
15
|
+
|
16
|
+
it "should set failure_message_for_should_not message" do
|
17
|
+
matcher = have_foreign_key_for(:users, :dependent => :nullify)
|
18
|
+
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)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'matcher' do
|
24
|
+
it { should have_foreign_key_for(:user, :dependent => :nullify) }
|
25
|
+
it { should have_foreign_key_for(:users, :dependent => :nullify) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UserType 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
|
+
matcher = have_foreign_key_for(:user_types)
|
12
|
+
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
|
+
end
|
15
|
+
|
16
|
+
it "should set failure_message_for_should_not message" do
|
17
|
+
matcher = have_foreign_key_for(:users)
|
18
|
+
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')}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'matcher' do
|
24
|
+
it { should have_foreign_key_for(:user) }
|
25
|
+
it { should have_foreign_key_for(:users) }
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreigner-matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Cameron Dykes
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-11 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: foreigner
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 57
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 1
|
34
|
+
version: 0.9.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Adds rspec matcher to verify the presence of foreign keys generated by Foreigner in a table schema
|
38
|
+
email:
|
39
|
+
- yellow5c@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- foreigner-matcher.gemspec
|
53
|
+
- lib/foreigner-matcher.rb
|
54
|
+
- lib/foreigner-matcher/version.rb
|
55
|
+
- spec/config/database.yml.example
|
56
|
+
- spec/foreigner_matcher_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
- spec/support/test_models.rb
|
59
|
+
- spec/test_models/comment_spec.rb
|
60
|
+
- spec/test_models/search_spec.rb
|
61
|
+
- spec/test_models/special_user_record_spec.rb
|
62
|
+
- spec/test_models/table_without_foreign_key_spec.rb
|
63
|
+
- spec/test_models/user_login_spec.rb
|
64
|
+
- spec/test_models/user_type_spec.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: https://github.com/yellow5/foreigner-matcher
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project: foreigner-matcher
|
95
|
+
rubygems_version: 1.5.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Rspec matcher for testing the presence of foreign keys generated by Foreigner
|
99
|
+
test_files:
|
100
|
+
- spec/config/database.yml.example
|
101
|
+
- spec/foreigner_matcher_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/support/test_models.rb
|
104
|
+
- spec/test_models/comment_spec.rb
|
105
|
+
- spec/test_models/search_spec.rb
|
106
|
+
- spec/test_models/special_user_record_spec.rb
|
107
|
+
- spec/test_models/table_without_foreign_key_spec.rb
|
108
|
+
- spec/test_models/user_login_spec.rb
|
109
|
+
- spec/test_models/user_type_spec.rb
|