Skip to content

Commit

Permalink
guard against ActiveRecord models with no primary_key (e.g. database …
Browse files Browse the repository at this point in the history
…view backed models)
  • Loading branch information
ablignaut committed Jan 28, 2016
1 parent 89c461d commit f5f8165
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec/active_model/mocks/mocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f5f8165

Please sign in to comment.