|
5 | 5 | require 'active_support/core_ext/string' |
6 | 6 |
|
7 | 7 | describe AnnotateModels do |
8 | | - def mock_foreign_key(name, from_column, to_table, to_column = 'id') |
| 8 | + def mock_foreign_key(name, from_column, to_table, to_column = 'id', constraints = {}) |
9 | 9 | double("ForeignKeyDefinition", |
10 | 10 | :name => name, |
11 | 11 | :column => from_column, |
12 | 12 | :to_table => to_table, |
13 | 13 | :primary_key => to_column, |
| 14 | + :on_delete => constraints[:on_delete], |
| 15 | + :on_update => constraints[:on_update] |
14 | 16 | ) |
15 | 17 | end |
16 | 18 |
|
@@ -197,6 +199,36 @@ def mock_column(name, type, options={}) |
197 | 199 | EOS |
198 | 200 | end |
199 | 201 |
|
| 202 | + it "should get foreign key info if on_delete/on_update options present" do |
| 203 | + klass = mock_class(:users, :id, [ |
| 204 | + mock_column(:id, :integer), |
| 205 | + mock_column(:foreign_thing_id, :integer), |
| 206 | + ], |
| 207 | + [ |
| 208 | + mock_foreign_key( |
| 209 | + 'fk_rails_02e851e3b7', |
| 210 | + 'foreign_thing_id', |
| 211 | + 'foreign_things', |
| 212 | + 'id', |
| 213 | + on_delete: 'on_delete_value', |
| 214 | + on_update: 'on_update_value' |
| 215 | + ) |
| 216 | + ]) |
| 217 | + expect(AnnotateModels.get_schema_info(klass, "Schema Info", :show_foreign_keys => true)).to eql(<<-EOS) |
| 218 | +# Schema Info |
| 219 | +# |
| 220 | +# Table name: users |
| 221 | +# |
| 222 | +# id :integer not null, primary key |
| 223 | +# foreign_thing_id :integer not null |
| 224 | +# |
| 225 | +# Foreign Keys |
| 226 | +# |
| 227 | +# fk_rails_02e851e3b7 (foreign_thing_id => foreign_things.id) ON DELETE => on_delete_value ON UPDATE => on_update_value |
| 228 | +# |
| 229 | +EOS |
| 230 | + end |
| 231 | + |
200 | 232 | it "should get schema info as RDoc" do |
201 | 233 | klass = mock_class(:users, :id, [ |
202 | 234 | mock_column(:id, :integer), |
@@ -261,7 +293,7 @@ def self.when_called_with(options = {}) |
261 | 293 | # notes :text(55) not null |
262 | 294 | # |
263 | 295 | EOS |
264 | | - |
| 296 | + |
265 | 297 | when_called_with hide_limit_column_types: 'integer,boolean,string,text', returns: |
266 | 298 | <<-EOS.strip_heredoc |
267 | 299 | # Schema Info |
|
0 commit comments