From d1a011bc784f4f3761c91968c83517e6769dcccb Mon Sep 17 00:00:00 2001 From: Matheus Sales Date: Fri, 27 Oct 2023 18:44:02 -0300 Subject: [PATCH] fix: Adjust specs for primary_key check --- .../active_record/have_db_column_matcher_spec.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb index 13e564d00..04db4d3c6 100644 --- a/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb @@ -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 @@ -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