Skip to content

Commit

Permalink
Test explicitly specifying the column's primary key type
Browse files Browse the repository at this point in the history
  • Loading branch information
lowjoel committed Aug 21, 2017
1 parent e197b5f commit acec932
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/foreign_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ class Comment < ::ActiveRecord::Base ; end

end

context "explicit foreign key type" do
[:integer, :bigint].each do |primary_key_type|
before(:each) do
define_schema do
create_table :users, :id => primary_key_type, :force => true do |t|
t.string :login
end

create_table :comments, :id => primary_key_type, :force => true do |t|
t.send primary_key_type, :user_id
t.foreign_key :user_id, :users
end
end
end

it "should report foreign key constraints" do
expect(Comment.foreign_keys.collect(&:column).flatten).to eq([ "user_id" ])
end

it "should report reverse foreign key constraints" do
expect(User.reverse_foreign_keys.collect(&:column).flatten).to eq([ "user_id" ])
end
end
end

context "modification" do

before(:each) do
Expand Down

0 comments on commit acec932

Please sign in to comment.