Skip to content

Commit 32d8cc8

Browse files
committed
Make sure tinyint primary key columns work. Closes #157
1 parent 8bc5d73 commit 32d8cc8

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

test/cases/specific_schema_test_sqlserver.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ class SpecificSchemaTestSqlserver < ActiveRecord::TestCase
4747
@edge_class = SqlServerEdgeSchema
4848
end
4949

50+
context 'with tinyint primary key' do
51+
52+
should 'work with identity inserts and finders' do
53+
record = SqlServerTinyintPk.new :name => '1'
54+
record.id = 1
55+
record.save!
56+
assert_equal record, SqlServerTinyintPk.find(1)
57+
end
58+
59+
end
60+
5061
context 'with natural primary keys' do
5162

5263
should 'work with identity inserts' do

test/cases/sqlserver_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CustomersView < ActiveRecord::Base ; self.table_name = 'customers_view' ;
4040
class StringDefaultsView < ActiveRecord::Base ; self.table_name = 'string_defaults_view' ; end
4141
class StringDefaultsBigView < ActiveRecord::Base ; self.table_name = 'string_defaults_big_view' ; end
4242
class SqlServerNaturalPkData < ActiveRecord::Base ; self.table_name = 'natural_pk_data' ; self.primary_key = 'legacy_id' ; end
43+
class SqlServerTinyintPk < ActiveRecord::Base ; self.table_name = 'tinyint_pk_table' ; end
4344
class SqlServerNaturalPkIntData < ActiveRecord::Base ; self.table_name = 'natural_pk_int_data' ; end
4445
class SqlServerNaturalPkDataSchema < ActiveRecord::Base ; self.table_name = 'test.sql_server_schema_natural_id' ; end
4546
class SqlServerQuotedTable < ActiveRecord::Base ; self.table_name = 'quoted-table' ; end

test/schema/sqlserver_specific_schema.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@
111111
)
112112
NATURALPKINTTABLESQL
113113

114+
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'tinyint_pk_table') DROP TABLE tinyint_pk_table"
115+
execute <<-TINYITPKTABLE
116+
CREATE TABLE tinyint_pk_table(
117+
id tinyint NOT NULL PRIMARY KEY,
118+
name nvarchar(255)
119+
)
120+
TINYITPKTABLE
121+
114122
create_table 'quoted-table', :force => true do |t|
115123
end
116124
execute "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'quoted-view1') DROP VIEW [quoted-view1]"

0 commit comments

Comments
 (0)