public
Fork of vigetlabs/foreign_key_migrations
Description: A gem/plugin for ActiveRecord that lets you define foreign keys in migrations.
Clone URL: git://github.com/crnixon/foreign_key_migrations.git
added test for symbols

git-svn-id: 
http://svn.extendviget.com/lab/trunk/plugins/foreign_key_migrations@530 
e959a6d6-1924-0410-92b3-a6fa492f4c66
cnixon (author)
Fri Feb 08 13:48:32 -0800 2008
commit  9672d65c656de8750f0fd46e40d24d8d6b844ac5
tree    7951c68f0daf09a5db90a9141320e992358f91ed
parent  8b21fcb1c849a9cae387c780971cb7ec6b9d57c9
...
12
13
14
15
 
16
17
 
18
19
20
21
 
22
23
24
25
 
26
27
28
...
32
33
34
35
36
37
38
 
 
 
 
39
40
41
...
12
13
14
 
15
16
 
17
18
19
20
 
21
22
23
24
 
25
26
27
28
...
32
33
34
 
 
 
 
35
36
37
38
39
 
40
0
@@ -12,17 +12,17 @@ ActiveRecord::Base.establish_connection(:adapter => 'mysql',
0
                                         :database => MYSQL_DB
0
                                         )
0
 
0
-describe 'Mysql Adapter' do
0
+class MysqlAdapterTest < Test::Unit::TestCase
0
 
0
- before do
0
+ def setup
0
     TestDB.up
0
   end
0
   
0
- after do
0
+ def teardown
0
     TestDB.down
0
   end
0
 
0
- it 'should add a foreign key' do
0
+ def test_should_add_a_foreign_key
0
     db = ActiveRecord::Base.connection
0
     db.add_foreign_key(:on => {:table => :widgets, :column => :factory_id},
0
                        :references => {:table => :factories, :column => :id})
0
@@ -32,10 +32,9 @@ describe 'Mysql Adapter' do
0
                   "WHERE constraint_schema = 'test' AND " +
0
                   "constraint_name = 'fk_widgets_factory_id_factories_id'")[0]
0
 
0
- key['TABLE_NAME'].should.equal 'widgets'
0
- key['COLUMN_NAME'].should.equal 'factory_id'
0
- key['REFERENCED_TABLE_NAME'].should.equal 'factories'
0
- key['REFERENCED_COLUMN_NAME'].should.equal 'id'
0
+ assert_equal key['TABLE_NAME'], 'widgets'
0
+ assert_equal key['COLUMN_NAME'], 'factory_id'
0
+ assert_equal key['REFERENCED_TABLE_NAME'], 'factories'
0
+ assert_equal key['REFERENCED_COLUMN_NAME'], 'id'
0
   end
0
-
0
 end
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 require File.join(File.dirname(__FILE__), '../lib/foreign_key_migrations')
0
-require 'bacon'
0
+require 'test/unit'
0
 require 'mocha'
0
 
0
 ActiveRecord::Migration.verbose = false
...
49
50
51
 
 
 
 
 
 
52
 
 
 
 
53
54
55
...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -49,7 +49,17 @@ class AddDropForeignKeyTest < Test::Unit::TestCase
0
     assert(@adapter.add_foreign_key(
0
       :on => 'employees', :references => 'departments'))
0
   end
0
+
0
+ def test_add_foreign_key_data_with_table_names_only_should_work_with_symbols
0
+ @adapter.expects(:execute).once \
0
+ .with("ALTER TABLE employees ADD CONSTRAINT " +
0
+ "fk_employees_department_id_departments_id FOREIGN KEY (department_id) " +
0
+ "REFERENCES departments(id)").returns(true)
0
     
0
+ assert(@adapter.add_foreign_key(:on => :employees, :references => :departments))
0
+ end
0
+
0
+
0
   def test_delete_foreign_key_should_work_with_full_data
0
     @adapter.expects(:execute).once.with(
0
       "ALTER TABLE employees DROP FOREIGN KEY " +

Comments

    No one has commented yet.