From f5f8165bf62e8becf31c8f14af26c74504e96467 Mon Sep 17 00:00:00 2001 From: ablignaut Date: Wed, 6 May 2015 16:31:03 +0200 Subject: [PATCH] guard against ActiveRecord models with no primary_key (e.g. database view backed models) --- lib/rspec/active_model/mocks/mocks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/active_model/mocks/mocks.rb b/lib/rspec/active_model/mocks/mocks.rb index fab2637..8b09610 100644 --- a/lib/rspec/active_model/mocks/mocks.rb +++ b/lib/rspec/active_model/mocks/mocks.rb @@ -238,7 +238,7 @@ def connection def stub_model(model_class, stubs={}) model_class.new.tap do |m| m.extend ActiveModelStubExtensions - if defined?(ActiveRecord) && model_class < ActiveRecord::Base + if defined?(ActiveRecord) && model_class < ActiveRecord::Base && model_class.primary_key m.extend ActiveRecordStubExtensions primary_key = model_class.primary_key.to_sym stubs = {primary_key => next_id}.merge(stubs)