foreigner-matcher 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,16 +6,22 @@ RSpec matcher for the [Foreigner gem](https://github.com/matthuhiggins/foreigner
6
6
 
7
7
  For installation with bundler, add the following to the approrpriate group in your Gemfile:
8
8
 
9
- gem "foreigner-matcher"
9
+ gem "foreigner-matcher", :require => nil
10
10
 
11
11
  For installation without bundler in Rails 2.3, add the following to your config/environments/test.rb:
12
12
 
13
- config.gem "foreigner-matcher"
13
+ config.gem "foreigner-matcher", :require => nil
14
14
 
15
15
  To install the gem the old fashioned way:
16
16
 
17
17
  gem install foreigner-matcher
18
18
 
19
+ In spec\_helper.rb:
20
+
21
+ require 'foreigner-matcher'
22
+
23
+ Note that the entry in spec\_helper.rb must follow any <tt>require</tt> for RSpec libraries.
24
+
19
25
  ## Usage
20
26
 
21
27
  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.
@@ -36,7 +42,7 @@ The spec would look like this:
36
42
  it { should have_foreign_key_for(:users) }
37
43
  end
38
44
 
39
- 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:
45
+ In addition to the table name, you can include any options that <tt>add\_foreign\_key</tt> (see [Foreigner](https://github.com/matthuhiggins/foreigner)) accepts. Some more examples using the same models:
40
46
 
41
47
  it { should have_foreign_key_for(:users, :dependent => :delete) }
42
48
  it { should have_foreign_key_for(:users, :column => "unique_user_id", :name => "user_logins_unique_user_id_fk") }
@@ -44,7 +50,7 @@ In addition to the table name, you can include any options that add_foreign_key
44
50
 
45
51
  **A Note on Table Names**
46
52
 
47
- 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!
53
+ 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 &quot;it should have foreign key for user&quot;. This is just my taste; use what makes sense to you!
48
54
 
49
55
  ## My Testing Environment
50
56
 
@@ -1,5 +1,5 @@
1
1
  module Foreigner
2
2
  module Matcher
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -52,24 +52,34 @@ module ForeignerMatcher # :nodoc:
52
52
  end
53
53
  end
54
54
 
55
- end
55
+ # Ensures that parent table has foreign key
56
+ #
57
+ # * <b>parent</b> - The table to check for foreign key
58
+ # * <b>options</b> - Accepts any option that works with add_foreign_key in Foreigner
59
+ #
60
+ # <em>Defaults</em>
61
+ # :primary_key Column referenced on parent table (default: id)
62
+ # :column Foreign key column (default: #{@parent.singluarize}_id)
63
+ # :name Foreign key index name (default: #{@child.class.table_name}_#{@parent.singularize}_id)
64
+ #
65
+ # <b>Examples</b>
66
+ # it { should have_foreign_key_for(:users) }
67
+ # it { should have_foreign_key_for(:users, :dependent => :delete) }
68
+ # it { should have_foreign_key_for(:users, :column => "some_column_name", :name => "users_some_column_name_fk") }
69
+ # it { should_not have_foreign_key_for(:users, :dependent => :nullify) }
56
70
 
57
- # Ensures that parent table has foreign key
58
- #
59
- # * <b>parent</b> - The table to check for foreign key
60
- # * <b>options</b> - Accepts any option that works with add_foreign_key in Foreigner
61
- #
62
- # <em>Defaults</em>
63
- # :primary_key Column referenced on parent table (default: id)
64
- # :column Foreign key column (default: #{@parent.singluarize}_id)
65
- # :name Foreign key index name (default: #{@child.class.table_name}_#{@parent.singularize}_id)
66
- #
67
- # <b>Examples</b>
68
- # it { should have_foreign_key_for(:users) }
69
- # it { should have_foreign_key_for(:users, :dependent => :delete) }
70
- # it { should have_foreign_key_for(:users, :column => "some_column_name", :name => "users_some_column_name_fk") }
71
- # it { should_not have_foreign_key_for(:users, :dependent => :nullify) }
71
+ def have_foreign_key_for(parent, options={})
72
+ ForeignerMatcher::HaveForeignKeyFor.new(parent, options)
73
+ end
72
74
 
73
- def have_foreign_key_for(parent, options={})
74
- ForeignerMatcher::HaveForeignKeyFor.new(parent, options)
75
+ end
76
+
77
+ if defined?(RSpec)
78
+ RSpec::Matchers.send :include, ForeignerMatcher
79
+ elsif defined?(Spec)
80
+ Spec::Runner.configure do |config|
81
+ config.include(ForeignerMatcher)
82
+ end
83
+ else
84
+ raise LoadError, 'RSpec/Spec must be loaded so I can be mixed in'
75
85
  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.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-17 00:00:00.000000000 -05:00
12
+ date: 2011-06-18 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: foreigner
17
- requirement: &14843940 !ruby/object:Gem::Requirement
17
+ requirement: &9035980 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 0.9.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *14843940
25
+ version_requirements: *9035980
26
26
  description: Adds rspec matcher to verify the presence of foreign keys generated by
27
27
  Foreigner in a table schema
28
28
  email: