Methods
- setup
- tear_down
- test_columns
- test_indexes
- test_migrated_schema
- test_primary_key
- x_test_add_column
- x_test_add_index
- x_test_change_column
- x_test_change_column_default
- x_test_create_table
- x_test_drop_table
- x_test_indexes
- x_test_remove_column
- x_test_remove_index
- x_test_rename_column
- x_test_rename_table
- x_test_tables
Public Instance methods
[ show source ]
# File test/kb_schema_test.rb, line 5 5: def setup 6: # recreate_kb_database(false) 7: @adapter = ActiveRecord::Base.connection 8: end
[ show source ]
# File test/kb_schema_test.rb, line 10
10: def tear_down
11: end
[ show source ]
# File test/kb_schema_test.rb, line 126
126: def test_columns
127: columns = Book.columns
128:
129: assert_equal 4, columns.size
130: assert_equal ["id", "name", "published", "publisher_id"], columns.map {|col| col.name }
131: assert_equal [:integer, :string, :date, :integer ], columns.map {|col| col.type }
132: assert_equal [true, false, false, true ], columns.map {|col| col.null }
133: assert_equal [nil, nil, nil, nil ], columns.map {|col| col.default }
134:
135: assert !columns[0].text?
136: assert columns[1].text?
137: assert !columns[2].text?
138: assert !columns[3].text?
139:
140: assert columns.all? { |col| col.default.nil? }
141:
142: assert columns[0].number?
143: assert !columns[1].number?
144: assert !columns[2].number?
145: assert columns[3].number?
146: end
[ show source ]
# File test/kb_schema_test.rb, line 148
148: def test_indexes
149: @adapter.create_table "index_tests", :force => true do |t|
150: t.column "indy_1", :integer
151: t.column "indy_2", :string
152: t.column "indy_3", :text
153: end
154: assert_nothing_raised { @adapter.add_index "index_tests", ["indy_1"], :name => "names_are_of_no_consequence" }
155: assert_nothing_raised { @adapter.add_index "index_tests", ["indy_2", "indy_3"], :name => "names_are_of_no_consequence_2" }
156: indices = @adapter.indexes("index_tests")
157: assert_equal 2, indices.size
158: assert_equal [["indy_1"], ["indy_2", "indy_3"]], indices.map{|ind| ind.columns}.sort
159: assert_equal ["index_tests_indy_1_index", "index_tests_indy_2_index"], indices.map{|ind| ind.name}.sort
160: end
[ show source ]
# File test/kb_schema_test.rb, line 13
13: def test_migrated_schema
14: # load the schme.rb file and migration files
15: recreate_kb_database(true)
16:
17: # check that all tables are in:
18: assert_equal [:authors, :authors_books, :books, :date_and_time_tests, :errata, :nil_tests, :pages, :primary_key_tests, :publishers, :schema_info],
19: $db.tables.sort_by{|t| t.to_s }
20: assert_equal $db.tables.map{|t| t.to_s}, @adapter.tables
21:
22: # check books table
23: assert_equal [:recno, :name, :published, :publisher_id], $db.get_table(:books).field_names
24: assert_equal [:Integer, :String, :Date, :Integer ], $db.get_table(:books).field_types
25: assert_equal [nil, "Index->1", nil, nil ], $db.get_table(:books).field_indexes
26: assert_equal [false, true, true, false ], $db.get_table(:books).field_requireds
27: assert_equal [nil, nil, nil, nil ], $db.get_table(:books).field_defaults
28: assert_equal [{}, {}, {}, {} ], $db.get_table(:books).field_extras
29:
30: # check authors table
31: assert_equal [:recno, :name ], $db.get_table(:authors).field_names
32: assert_equal [:Integer, :String ], $db.get_table(:authors).field_types
33: assert_equal [nil, "Index->1"], $db.get_table(:authors).field_indexes
34: assert_equal [false, true ], $db.get_table(:authors).field_requireds
35: assert_equal [nil, nil ], $db.get_table(:authors).field_defaults
36: assert_equal [{}, {} ], $db.get_table(:authors).field_extras
37:
38: # check authors_books table
39: assert_equal [:recno, :author_id, :book_id], $db.get_table(:authors_books).field_names
40: assert_equal [:Integer, :Integer, :Integer], $db.get_table(:authors_books).field_types
41: assert_equal [nil, nil, nil ], $db.get_table(:authors_books).field_indexes
42: assert_equal [false, false, false ], $db.get_table(:authors_books).field_requireds
43: assert_equal [nil, nil, nil ], $db.get_table(:authors_books).field_defaults
44: assert_equal [{}, {}, {} ], $db.get_table(:authors_books).field_extras
45:
46: # check pages table
47: assert_equal [:recno, :book_id, :page_num, :content], $db.get_table(:pages).field_names
48: assert_equal [:Integer, :Integer, :Integer, :String ], $db.get_table(:pages).field_types
49: assert_equal [nil, nil, nil, nil ], $db.get_table(:pages).field_indexes
50: assert_equal [false, false, false, false ], $db.get_table(:pages).field_requireds
51: assert_equal [nil, nil, nil, nil ], $db.get_table(:pages).field_defaults
52: assert_equal [{}, {}, {}, {} ], $db.get_table(:pages).field_extras
53:
54: # check publishers table
55: assert_equal [:recno, :name, :address], $db.get_table(:publishers).field_names
56: assert_equal [:Integer, :String, :String ], $db.get_table(:publishers).field_types
57: assert_equal [nil, "Index->1", nil ], $db.get_table(:publishers).field_indexes
58: assert_equal [false, false, false ], $db.get_table(:publishers).field_requireds
59: assert_equal [nil, nil, nil ], $db.get_table(:publishers).field_defaults
60: assert_equal [{}, {}, {} ], $db.get_table(:publishers).field_extras
61:
62: # check errata table
63: assert_equal [:recno, :book_id, :contents], $db.get_table(:errata).field_names
64: assert_equal [:Integer, :Integer, :String ], $db.get_table(:errata).field_types
65: assert_equal [nil, nil, nil ], $db.get_table(:errata).field_indexes
66: assert_equal [false, false, false ], $db.get_table(:errata).field_requireds
67: assert_equal [nil, nil, nil ], $db.get_table(:errata).field_defaults
68: assert_equal [{}, {}, {} ], $db.get_table(:errata).field_extras
69: end
[ show source ]
# File test/kb_schema_test.rb, line 162
162: def test_primary_key
163: pak = PrimaryKeyTest.create :name => 'first'
164: assert_equal 1, pak.id
165: assert_equal 1, pak.pk
166:
167: end
[ show source ]
# File test/kb_schema_test.rb, line 94
94: def x_test_add_column
95: flunk
96: end
[ show source ]
# File test/kb_schema_test.rb, line 114
114: def x_test_add_index
115: flunk
116: end
[ show source ]
# File test/kb_schema_test.rb, line 98
98: def x_test_change_column
99: flunk
100: end
[ show source ]
# File test/kb_schema_test.rb, line 102
102: def x_test_change_column_default
103: flunk
104: end
[ show source ]
# File test/kb_schema_test.rb, line 71
71: def x_test_create_table
72: flunk
73: end
[ show source ]
# File test/kb_schema_test.rb, line 90
90: def x_test_drop_table
91: flunk
92: end
[ show source ]
# File test/kb_schema_test.rb, line 79
79: def x_test_indexes
80: breakpoint
81: i = ActiveRecord::ConnectionAdapters::IndexDefinition.new(:authors, '1', true, [:name])
82: assert_equal [i], Author.indexes
83: i = ActiveRecord::ConnectionAdapters::IndexDefinition.new(:books, '1', true, [:name])
84: assert_equal [i], Book.indexes
85: assert_equal [], Page.indexes
86: i = ActiveRecord::ConnectionAdapters::IndexDefinition.new(:publishers, '1', true, [:name])
87: assert_equal [], Publisher.indexes
88: end
[ show source ]
# File test/kb_schema_test.rb, line 110
110: def x_test_remove_column
111: flunk
112: end
[ show source ]
# File test/kb_schema_test.rb, line 118
118: def x_test_remove_index
119: flunk
120: end
[ show source ]
# File test/kb_schema_test.rb, line 106
106: def x_test_rename_column
107: flunk
108: end
[ show source ]
# File test/kb_schema_test.rb, line 75
75: def x_test_rename_table
76: flunk
77: end
[ show source ]
# File test/kb_schema_test.rb, line 122
122: def x_test_tables
123: flunk
124: end