Skip to content

Commit

Permalink
fix: Adjust specs for primary_key check
Browse files Browse the repository at this point in the history
  • Loading branch information
matsales28 committed Oct 27, 2023
1 parent d2b2d55 commit d1a011b
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@

context 'with primary option' do
it 'accepts a column that is primary' do
expect(with_table(:custom_id, :integer, primary: true)).
to have_db_column(:id).with_options(primary: true)
expect(with_table_custom_primary_key(:custom_id)).
to have_db_column(:custom_id).with_options(primary: true)
end

it 'rejects a column that is not primary' do
expect(with_table(:whatever, :integer, primary: false)).
expect(with_table(:whatever, :integer, {})).
not_to have_db_column(:whatever).with_options(primary: true)
end
end
Expand Down Expand Up @@ -161,9 +161,16 @@ def model(options = {})
end

def with_table(column_name, column_type, options)
create_table 'employees' do |table|
create_table 'employees', id: false do |table|
table.__send__(column_type, column_name, **options)
end
define_model_class('Employee').new
end

def with_table_custom_primary_key(column_name, options = {})
create_table 'employees', id: false do |table|
table.__send__(:primary_key, column_name, **options)
end
define_model_class('Employee').new
end
end

0 comments on commit d1a011b

Please sign in to comment.