aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb')
-rw-r--r--activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb31
1 files changed, 29 insertions, 2 deletions
diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
index 14f4997d5b..1357719422 100644
--- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
+++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -361,21 +361,48 @@ module ActiveRecord
end
class Barcode < ActiveRecord::Base
+ self.primary_key = "code"
end
- def test_existing_records_have_custom_primary_key
+ def test_copy_table_with_existing_records_have_custom_primary_key
connection = Barcode.connection
connection.create_table(:barcodes, primary_key: "code", id: :string, limit: 42, force: true) do |t|
t.text :other_attr
end
code = "214fe0c2-dd47-46df-b53b-66090b3c1d40"
- Barcode.create! code: code, other_attr: "xxx"
+ Barcode.create!(code: code, other_attr: "xxx")
connection.change_table "barcodes" do |t|
connection.remove_column("barcodes", "other_attr")
end
assert_equal code, Barcode.first.id
+ ensure
+ Barcode.reset_column_information
+ end
+
+ def test_copy_table_with_composite_primary_keys
+ connection = Barcode.connection
+ connection.create_table(:barcodes, primary_key: ["region", "code"], force: true) do |t|
+ t.string :region
+ t.string :code
+ t.text :other_attr
+ end
+ region = "US"
+ code = "214fe0c2-dd47-46df-b53b-66090b3c1d40"
+ Barcode.create!(region: region, code: code, other_attr: "xxx")
+
+ connection.change_table "barcodes" do |t|
+ connection.remove_column("barcodes", "other_attr")
+ end
+
+ assert_equal ["region", "code"], connection.primary_keys("barcodes")
+
+ barcode = Barcode.first
+ assert_equal region, barcode.region
+ assert_equal code, barcode.code
+ ensure
+ Barcode.reset_column_information
end
def test_supports_extensions