Skip to content

Commit 42c8e81

Browse files
committed
Added test case for duplicate entries in schema.rb
1 parent dfb79b2 commit 42c8e81

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
135135
assert_line :name, type: "string", limit: nil, default: nil, collation: nil
136136
end
137137

138+
it "dumps field with unique key constraints only once" do
139+
output = generate_schema_for_table "unique_key_dumped_table"
140+
141+
_(output.scan('t.integer "unique_field"').length).must_equal(1)
142+
end
143+
138144
private
139145

140146
def generate_schema_for_table(*table_names)

test/schema/sqlserver_specific_schema.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,14 @@
277277
field_2 int NOT NULL PRIMARY KEY,
278278
)
279279
SCHEMATESTMULTIPLESCHEMA
280+
281+
execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'unique_key_dumped_table') DROP TABLE unique_key_dumped_table"
282+
execute <<-SQLSERVERUNIQUEKEYS
283+
CREATE TABLE unique_key_dumped_table (
284+
id int IDENTITY(1,1) NOT NULL,
285+
unique_field int DEFAULT 0 NOT NULL,
286+
CONSTRAINT IX_UNIQUE_KEY UNIQUE (unique_field),
287+
CONSTRAINT PK_UNIQUE_KEY PRIMARY KEY (id)
288+
);
289+
SQLSERVERUNIQUEKEYS
280290
end

0 commit comments

Comments
 (0)