Skip to content

Commit f4be968

Browse files
committed
Tests for the previous commit.
The tests from http://github.com/adzap/sqlserver_adapter_mods/ are rspec, so rather than introduce another test dependency for the adapter, I stole a test from AR that was only being run for the MySQL adapter to test the same thing.
1 parent 38bbb6c commit f4be968

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/cases/adapter_test_sqlserver.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,31 @@ def test_should_create_bigints_when_limit_is_greateer_than_4
129129

130130
# NOTE: The existing schema_dumper_test doesn't test the limits of <4 limit things
131131
# for adapaters that aren't mysql, sqlite or postgres. We should.
132+
# It also only tests non-standard id dumping for mysql. We'll do that too.
132133
class SchemaDumperForSqlServerTest < ActiveRecord::TestCase
133-
def test_schema_dump_includes_limit_constraint_for_integer_columns
134+
def standard_dump(ignore_tables = [])
134135
stream = StringIO.new
135-
136-
ActiveRecord::SchemaDumper.ignore_tables = [/^(?!integer_limits)/]
136+
ActiveRecord::SchemaDumper.ignore_tables = [*ignore_tables]
137137
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
138-
output = stream.string
138+
stream.string
139+
end
140+
141+
def test_schema_dump_includes_limit_constraint_for_integer_columns
142+
output = standard_dump(/^(?!integer_limits)/)
139143
assert_match %r{c_int_1.*:limit => 2}, output
140144
assert_match %r{c_int_2.*:limit => 2}, output
141145
assert_match %r{c_int_3.*}, output
142146
assert_match %r{c_int_4.*}, output
143147
assert_no_match %r{c_int_3.*:limit}, output
144148
assert_no_match %r{c_int_4.*:limit}, output
145149
end
150+
151+
def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
152+
output = standard_dump
153+
match = output.match(%r{create_table "movies"(.*)do})
154+
assert_not_nil(match, "nonstandardpk table not found")
155+
assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
156+
end
146157
end
147158

148159
class StringDefaultsTest < ActiveRecord::TestCase

0 commit comments

Comments
 (0)