Skip to content

Commit f5f8165

Browse files
committed
guard against ActiveRecord models with no primary_key (e.g. database view backed models)
1 parent 89c461d commit f5f8165

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/rspec/active_model/mocks/mocks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def connection
238238
def stub_model(model_class, stubs={})
239239
model_class.new.tap do |m|
240240
m.extend ActiveModelStubExtensions
241-
if defined?(ActiveRecord) && model_class < ActiveRecord::Base
241+
if defined?(ActiveRecord) && model_class < ActiveRecord::Base && model_class.primary_key
242242
m.extend ActiveRecordStubExtensions
243243
primary_key = model_class.primary_key.to_sym
244244
stubs = {primary_key => next_id}.merge(stubs)

0 commit comments

Comments
 (0)