schema_plus 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/gemfiles/rails-4.1/Gemfile.base +1 -1
- data/lib/schema_plus/active_record/column_options_handler.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/column.rb +1 -1
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/table_definition.rb +2 -0
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +2 -2
- data/schema_plus.gemspec +3 -3
- data/spec/column_default_spec.rb +156 -0
- data/spec/column_spec.rb +20 -20
- data/spec/connection_spec.rb +1 -1
- data/spec/foreign_key_definition_spec.rb +3 -3
- data/spec/foreign_key_spec.rb +14 -12
- data/spec/index_definition_spec.rb +23 -23
- data/spec/index_spec.rb +34 -34
- data/spec/migration_spec.rb +132 -120
- data/spec/named_schemas_spec.rb +15 -15
- data/spec/schema_dumper_spec.rb +36 -36
- data/spec/schema_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/matchers/have_index.rb +20 -13
- data/spec/support/matchers/reference.rb +3 -3
- data/spec/views_spec.rb +17 -17
- metadata +9 -15
- data/spec/column_definition_spec.rb +0 -212
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98695abbf9f44e746dda323f7312d0b206b74b33
|
4
|
+
data.tar.gz: f9402bff3980025c1f6a1b6e052f9ec1cf0f2bfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ac7c8fb9f854adb5bd455b19e93427829dffab2ceccbf59044116f1bdee8783acb5d98ede537a9af118e1d44a7872e306700e8ae9f4153c4d523ba7c4da4803
|
7
|
+
data.tar.gz: 521da3cda682a2ab9dc0126a093c3f6b21e5a49a19d7dded7662a5c7d8729671f9a71aa672e01150d4078cf2b076d20974a7a41e825a4616f7c5fae3386bcb72
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## Change Log
|
4
4
|
|
5
|
+
### 1.5.3
|
6
|
+
|
7
|
+
* No longer limited to rails 4.1.1 (issue #159)
|
8
|
+
* Bug fix: multiple competing indexes created for `t.references... index: :unique` (issue #157)
|
9
|
+
* Now works with rspec 3 (thanks to [@robababa](https://github.com/robababa) (issue #160)
|
10
|
+
* Improvements to ./runspecs (thanks to [@robababa](https://github.com/robababa) (issue #162)
|
11
|
+
|
5
12
|
### 1.5.2
|
6
13
|
|
7
14
|
* For now, pin to rspec 2.* and limit rails to 4.1.1 (issue #158)
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ For added rails DRYness see also the gems
|
|
17
17
|
|
18
18
|
SchemaPlus supports all combinations of:
|
19
19
|
|
20
|
-
* Rails/ActiveRecord 3.2, 4.0, and 4.1
|
20
|
+
* Rails/ActiveRecord 3.2, 4.0, and 4.1
|
21
21
|
* PostgreSQL, MySQL (using mysql2 gem; mysql gem only supported with Rails
|
22
22
|
3.2), or SQLite3 (using sqlite3 >= 3.7.7 which has foreign key support)
|
23
23
|
* MRI Ruby 1.9.3, 2.0.0, or 2.1.0
|
@@ -14,6 +14,7 @@ module SchemaPlus::ActiveRecord
|
|
14
14
|
|
15
15
|
# create index if requested explicity or implicitly due to auto_index
|
16
16
|
index = column_options[:index]
|
17
|
+
index = column_options[:_index] if column_options.include? :_index
|
17
18
|
if index.nil? and fk_args && config.foreign_keys.auto_index?
|
18
19
|
index = { :name => auto_index_name(table_name, column_name) }
|
19
20
|
end
|
@@ -55,7 +55,7 @@ module SchemaPlus
|
|
55
55
|
# The default as_jon includes all instance variables. but
|
56
56
|
# @model can't be dumped (it contains circular references)
|
57
57
|
def as_json(options=nil)
|
58
|
-
instance_values.except "model"
|
58
|
+
instance_values.except "model", "adapter"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -11,6 +11,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
11
11
|
|
12
12
|
def add_reference_with_schema_plus(table_name, ref_name, options = {}) #:nodoc:
|
13
13
|
options[:references] = nil if options[:polymorphic]
|
14
|
+
options[:_index] = options.delete(:index) unless options[:polymorphic] # usurp index creation from AR
|
14
15
|
add_reference_without_schema_plus(table_name, ref_name, options)
|
15
16
|
end
|
16
17
|
|
@@ -109,6 +109,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
109
109
|
def references_with_schema_plus(*args) #:nodoc:
|
110
110
|
options = args.extract_options!
|
111
111
|
options[:references] = nil if options[:polymorphic]
|
112
|
+
options[:_index] = options.delete(:index) unless options[:polymorphic] # usurp index creation from AR
|
112
113
|
args << options
|
113
114
|
references_without_schema_plus(*args)
|
114
115
|
end
|
@@ -118,6 +119,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
118
119
|
def belongs_to_with_schema_plus(*args) #:nodoc:
|
119
120
|
options = args.extract_options!
|
120
121
|
options[:references] = nil if options[:polymorphic]
|
122
|
+
options[:_index] = options.delete(:index) unless options[:polymorphic] # usurp index creation from AR
|
121
123
|
args << options
|
122
124
|
belongs_to_without_schema_plus(*args)
|
123
125
|
end
|
data/lib/schema_plus/version.rb
CHANGED
data/runspecs
CHANGED
@@ -89,8 +89,8 @@ else
|
|
89
89
|
# rbenv, we already have various environment variables set up. need
|
90
90
|
# strip those out so that the forked shell can run a diifferent ruby
|
91
91
|
# version than the one we're in now.
|
92
|
-
ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{
|
93
|
-
ENV['GEM_PATH'] = ENV['GEM_PATH'].split(':').reject{|dir| dir =~ %r{
|
92
|
+
ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv/(?!shims)}}.join(':')
|
93
|
+
ENV['GEM_PATH'] = ENV['GEM_PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv}}.join(':') unless ENV['GEM_PATH'].nil?
|
94
94
|
ENV['RBENV_DIR'] = nil
|
95
95
|
ENV['RBENV_HOOK_PATH'] = nil
|
96
96
|
|
data/schema_plus.gemspec
CHANGED
@@ -21,13 +21,13 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_dependency("activerecord", ">= 3.2"
|
24
|
+
s.add_dependency("activerecord", ">= 3.2")
|
25
25
|
s.add_dependency("valuable")
|
26
26
|
|
27
27
|
s.add_development_dependency("rake")
|
28
|
-
s.add_development_dependency("rspec", "
|
28
|
+
s.add_development_dependency("rspec", "~> 3.0.0")
|
29
29
|
s.add_development_dependency("rdoc")
|
30
30
|
s.add_development_dependency("simplecov")
|
31
|
-
s.add_development_dependency("simplecov-gem-
|
31
|
+
s.add_development_dependency("simplecov-gem-profile")
|
32
32
|
end
|
33
33
|
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe "Column definition" do
|
5
|
+
before(:each) do
|
6
|
+
define_schema(:auto_create => true) do
|
7
|
+
create_table :models, :force => true do |t|
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class Model < ::ActiveRecord::Base ; end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject {
|
14
|
+
Model.connection.execute("INSERT INTO models (dummy) values (1)")
|
15
|
+
Model.last.reload.test_column
|
16
|
+
}
|
17
|
+
|
18
|
+
context "text columns" do
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@nowish = /(#{Time.now.utc.to_s.sub(/:[^:]+$/, '')}|#{Time.now.to_s.sub(/:[^:]+$/,'')}).*/
|
22
|
+
end
|
23
|
+
|
24
|
+
context "just default passed" do
|
25
|
+
before(:each) do
|
26
|
+
define_test_column(:string, :default => "2011-12-11 00:00:00")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should use the normal default" do
|
30
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "just default passed in hash" do
|
35
|
+
before(:each) do
|
36
|
+
define_test_column(:string, :default => { :value => "2011-12-11 00:00:00" })
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use the normal default" do
|
40
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "default passed with no nulls" do
|
45
|
+
before(:each) do
|
46
|
+
define_test_column(:string, :default => "2011-12-11 00:00:00", null: false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should use the normal default" do
|
50
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "default passed in hash with no nulls" do
|
55
|
+
before(:each) do
|
56
|
+
define_test_column(:string, :default => { :value => "2011-12-11 00:00:00" }, null: false)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should use the normal default" do
|
60
|
+
is_expected.to eq "2011-12-11 00:00:00"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "default function passed as :now" do
|
65
|
+
before(:each) do
|
66
|
+
begin
|
67
|
+
define_test_column(:string, :default => :now)
|
68
|
+
rescue ArgumentError => e
|
69
|
+
@raised_argument_error = e
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if SchemaPlusHelpers.mysql?
|
74
|
+
it "should raise an error" do
|
75
|
+
expect(@raised_argument_error).to be_a ArgumentError
|
76
|
+
end
|
77
|
+
else
|
78
|
+
it "should use NOW() as the default" do
|
79
|
+
is_expected.to match @nowish
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "default function passed as now with no nulls" do
|
85
|
+
before(:each) do
|
86
|
+
begin
|
87
|
+
define_test_column(:string, :default => :now, null: false)
|
88
|
+
rescue ArgumentError => e
|
89
|
+
@raised_argument_error = e
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if SchemaPlusHelpers.mysql?
|
94
|
+
it "should raise an error" do
|
95
|
+
expect(@raised_argument_error).to be_a ArgumentError
|
96
|
+
end
|
97
|
+
else
|
98
|
+
it "should use NOW() as the default" do
|
99
|
+
is_expected.to match @nowish
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "valid expr passed as default" do
|
105
|
+
if SchemaPlusHelpers.mysql?
|
106
|
+
it "raises an error" do
|
107
|
+
expect {
|
108
|
+
define_test_column(:string, :default => { :expr => "(replace('THIS IS A TEST', 'TEST', 'DOG'))" })
|
109
|
+
}.to raise_error ArgumentError
|
110
|
+
end
|
111
|
+
else
|
112
|
+
it "uses the expression" do
|
113
|
+
define_test_column(:string, :default => { :expr => "(replace('THIS IS A TEST', 'TEST', 'DOG'))" })
|
114
|
+
is_expected.to eq "THIS IS A DOG"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
context "boolean column" do
|
122
|
+
|
123
|
+
context "passed as boolean false" do
|
124
|
+
before(:each) do
|
125
|
+
define_test_column :boolean, :default => false
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should give the default as false" do
|
129
|
+
is_expected.to eq false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "passed as boolean true" do
|
134
|
+
before(:each) do
|
135
|
+
define_test_column :boolean, :default => true
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should give the default as true" do
|
139
|
+
is_expected.to eq true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def define_test_column(type, *args)
|
147
|
+
ActiveRecord::Migration.suppress_messages do
|
148
|
+
ActiveRecord::Migration.create_table Model.table_name, :force => true do |t|
|
149
|
+
t.send type, :test_column, *args
|
150
|
+
t.integer :dummy
|
151
|
+
end
|
152
|
+
end
|
153
|
+
Model.reset_column_information
|
154
|
+
@column = Model.columns.first()
|
155
|
+
end
|
156
|
+
end
|
data/spec/column_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe "Column" do
|
|
14
14
|
@login = User.columns.find{|column| column.name == "login"}
|
15
15
|
end
|
16
16
|
it "works properly" do
|
17
|
-
JSON.parse(@login.to_json).
|
17
|
+
expect(JSON.parse(@login.to_json)).to include("name" => "login", "type" => "string")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -28,12 +28,12 @@ describe "Column" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should report not unique" do
|
31
|
-
@login.
|
31
|
+
expect(@login).not_to be_unique
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should report nil unique scope" do
|
35
35
|
create_table(User, :login => { :index => true})
|
36
|
-
@login.unique_scope.
|
36
|
+
expect(@login.unique_scope).to be_nil
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -44,11 +44,11 @@ describe "Column" do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should report unique" do
|
47
|
-
@login.
|
47
|
+
expect(@login).to be_unique
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should report an empty unique scope" do
|
51
|
-
@login.unique_scope.
|
51
|
+
expect(@login.unique_scope).to eq([])
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -62,15 +62,15 @@ describe "Column" do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should report unique for each" do
|
65
|
-
@first.
|
66
|
-
@middle.
|
67
|
-
@last.
|
65
|
+
expect(@first).to be_unique
|
66
|
+
expect(@middle).to be_unique
|
67
|
+
expect(@last).to be_unique
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should report unique scope for each" do
|
71
|
-
@first.unique_scope.
|
72
|
-
@middle.unique_scope.
|
73
|
-
@last.unique_scope.
|
71
|
+
expect(@first.unique_scope).to match_array(%W[middle last])
|
72
|
+
expect(@middle.unique_scope).to match_array(%W[first last])
|
73
|
+
expect(@last.unique_scope).to match_array(%W[first middle])
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -80,17 +80,17 @@ describe "Column" do
|
|
80
80
|
|
81
81
|
it "not required if the column can be null" do
|
82
82
|
create_table(User, :login => { :null => true})
|
83
|
-
User.columns.find{|column| column.name == "login"}.required_on.
|
83
|
+
expect(User.columns.find{|column| column.name == "login"}.required_on).to be_nil
|
84
84
|
end
|
85
85
|
|
86
86
|
it "must have a value on :save if there's no default" do
|
87
87
|
create_table(User, :login => { :null => false })
|
88
|
-
User.columns.find{|column| column.name == "login"}.required_on.
|
88
|
+
expect(User.columns.find{|column| column.name == "login"}.required_on).to eq(:save)
|
89
89
|
end
|
90
90
|
|
91
91
|
it "must have a value on :update if there's default" do
|
92
92
|
create_table(User, :login => { :null => false, :default => "foo" })
|
93
|
-
User.columns.find{|column| column.name == "login"}.required_on.
|
93
|
+
expect(User.columns.find{|column| column.name == "login"}.required_on).to eq(:update)
|
94
94
|
end
|
95
95
|
|
96
96
|
end
|
@@ -113,19 +113,19 @@ describe "Column" do
|
|
113
113
|
|
114
114
|
it "creating a record should respect default expression" do
|
115
115
|
User.create!(:alpha => ActiveRecord::DB_DEFAULT, :beta => "hello")
|
116
|
-
User.last.alpha.
|
117
|
-
User.last.beta.
|
116
|
+
expect(User.last.alpha).to eq("gabba")
|
117
|
+
expect(User.last.beta).to eq("hello")
|
118
118
|
end
|
119
119
|
|
120
120
|
it "updating a record should respect default expression" do
|
121
121
|
u = User.create!(:alpha => "hey", :beta => "hello")
|
122
122
|
u.reload
|
123
|
-
u.alpha.
|
124
|
-
u.beta.
|
123
|
+
expect(u.alpha).to eq("hey")
|
124
|
+
expect(u.beta).to eq("hello")
|
125
125
|
u.update_attributes(:alpha => ActiveRecord::DB_DEFAULT, :beta => "goodbye")
|
126
126
|
u.reload
|
127
|
-
u.alpha.
|
128
|
-
u.beta.
|
127
|
+
expect(u.alpha).to eq("gabba")
|
128
|
+
expect(u.beta).to eq("goodbye")
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
data/spec/connection_spec.rb
CHANGED
@@ -5,17 +5,17 @@ describe "Foreign Key definition" do
|
|
5
5
|
let(:definition) { SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id) }
|
6
6
|
|
7
7
|
it "dumps to sql with quoted values" do
|
8
|
-
definition.to_sql.
|
8
|
+
expect(definition.to_sql).to eq(%Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')})})
|
9
9
|
end
|
10
10
|
|
11
11
|
it "dumps to sql with deferrable values" do
|
12
12
|
deferred_definition = SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id, nil, nil, true)
|
13
|
-
deferred_definition.to_sql.
|
13
|
+
expect(deferred_definition.to_sql).to eq(%Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')}) DEFERRABLE})
|
14
14
|
end
|
15
15
|
|
16
16
|
it "dumps to sql with initially deferrable values" do
|
17
17
|
initially_deferred_definition = SchemaPlus::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new("posts_user_fkey", :posts, :user, :users, :id, nil, nil, :initially_deferred)
|
18
|
-
initially_deferred_definition.to_sql.
|
18
|
+
expect(initially_deferred_definition.to_sql).to eq(%Q{CONSTRAINT posts_user_fkey FOREIGN KEY (#{quote_column_name('user')}) REFERENCES #{quote_table_name('users')} (#{quote_column_name('id')}) DEFERRABLE INITIALLY DEFERRED})
|
19
19
|
end
|
20
20
|
|
21
21
|
def quote_table_name(table)
|
data/spec/foreign_key_spec.rb
CHANGED
@@ -20,11 +20,11 @@ describe "Foreign Key" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should report foreign key constraints" do
|
23
|
-
Comment.foreign_keys.collect(&:column_names).flatten.
|
23
|
+
expect(Comment.foreign_keys.collect(&:column_names).flatten).to eq([ "user_id" ])
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should report reverse foreign key constraints" do
|
27
|
-
User.reverse_foreign_keys.collect(&:column_names).flatten.
|
27
|
+
expect(User.reverse_foreign_keys.collect(&:column_names).flatten).to eq([ "user_id" ])
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -32,7 +32,9 @@ describe "Foreign Key" do
|
|
32
32
|
if ::ActiveRecord::VERSION::MAJOR.to_i >= 4
|
33
33
|
context "with modifications to SQL generated by upstream visit_TableDefinition" do
|
34
34
|
before(:each) do
|
35
|
-
ActiveRecord::Base.connection.class.const_get(:SchemaCreation)
|
35
|
+
allow_any_instance_of(ActiveRecord::Base.connection.class.const_get(:SchemaCreation))
|
36
|
+
.to receive(:visit_TableDefinition_without_schema_plus)
|
37
|
+
.and_return('this is unexpected')
|
36
38
|
end
|
37
39
|
|
38
40
|
it "raises an exception when attempting to create a table" do
|
@@ -105,23 +107,23 @@ describe "Foreign Key" do
|
|
105
107
|
end
|
106
108
|
|
107
109
|
it "references users(id)" do
|
108
|
-
Post.
|
110
|
+
expect(Post).to reference(:users, :id).on(:author_id)
|
109
111
|
end
|
110
112
|
|
111
113
|
it "cascades on update" do
|
112
|
-
Post.
|
114
|
+
expect(Post).to reference(:users).on_update(:cascade)
|
113
115
|
end
|
114
116
|
|
115
117
|
it "restricts on delete" do
|
116
|
-
Post.
|
118
|
+
expect(Post).to reference(:users).on_delete(:restrict)
|
117
119
|
end
|
118
120
|
|
119
121
|
it "is available in Post.foreign_keys" do
|
120
|
-
Post.foreign_keys.collect(&:column_names).
|
122
|
+
expect(Post.foreign_keys.collect(&:column_names)).to include(%w[author_id])
|
121
123
|
end
|
122
124
|
|
123
125
|
it "is available in User.reverse_foreign_keys" do
|
124
|
-
User.reverse_foreign_keys.collect(&:column_names).
|
126
|
+
expect(User.reverse_foreign_keys.collect(&:column_names)).to include(%w[author_id])
|
125
127
|
end
|
126
128
|
|
127
129
|
end
|
@@ -139,15 +141,15 @@ describe "Foreign Key" do
|
|
139
141
|
end
|
140
142
|
|
141
143
|
it "doesn't reference posts(id)" do
|
142
|
-
Comment.
|
144
|
+
expect(Comment).not_to reference(:posts).on(:post_id)
|
143
145
|
end
|
144
146
|
|
145
147
|
it "is no longer available in Post.foreign_keys" do
|
146
|
-
Comment.foreign_keys.collect(&:column_names).
|
148
|
+
expect(Comment.foreign_keys.collect(&:column_names)).not_to include(%w[post_id])
|
147
149
|
end
|
148
150
|
|
149
151
|
it "is no longer available in User.reverse_foreign_keys" do
|
150
|
-
Post.reverse_foreign_keys.collect(&:column_names).
|
152
|
+
expect(Post.reverse_foreign_keys.collect(&:column_names)).not_to include(%w[post_id])
|
151
153
|
end
|
152
154
|
|
153
155
|
end
|
@@ -158,7 +160,7 @@ describe "Foreign Key" do
|
|
158
160
|
|
159
161
|
it "should remove foreign keys" do
|
160
162
|
remove_foreign_key(:comments, foreign_key_name)
|
161
|
-
Post.reverse_foreign_keys.collect { |fk| fk.column_names == %w[post_id] && fk.table_name == "comments" }.
|
163
|
+
expect(Post.reverse_foreign_keys.collect { |fk| fk.column_names == %w[post_id] && fk.table_name == "comments" }).to be_empty
|
162
164
|
end
|
163
165
|
|
164
166
|
end
|