any_instance stub disappears after first update of ar object #196

Closed
kbaum opened this Issue Nov 16, 2012 · 5 comments

2 participants

@kbaum

I am using acts_as_geocoder for some of my objects and by default within rspec i am mocking this out with:

Space.any_instance.stub(:attach_geocode).and_return(stubbed_geocode) 

The issue is, after upgrading from rspec-mocks 2.7 to 2.12.0, my attach_geocode stub is disappearing after any AR object gets updated. So, on the second update, i get this:

Failures:

  1) caching the space details page when space page should reset cache when space suite is updated 
     Failure/Error: space.save!
     NoMethodError:
       undefined method `attach_geocode' for #<Space:0x007ffeac2c7768>
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activemodel-3.2.9/lib/active_model/attribute_methods.rb:404:in `method_missing'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/attribute_methods.rb:149:in `method_missing'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/bundler/gems/rspec-mocks-c1af6e8e0e9b/lib/rspec/mocks/proxy.rb:143:in `message_received'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/bundler/gems/rspec-mocks-c1af6e8e0e9b/lib/rspec/mocks/method_double.rb:136:in `attach_geocode'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:471:in `_run__4493693780847961508__save__3484547177069364424__callbacks'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/callbacks.rb:264:in `create_or_update'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/persistence.rb:104:in `save!'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/validations.rb:56:in `save!'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/transactions.rb:264:in `block in save!'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/test_after_commit-0.0.1/lib/test_after_commit.rb:25:in `block in transaction_with_transactional_fixtures'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/test_after_commit-0.0.1/lib/test_after_commit.rb:23:in `transaction_with_transactional_fixtures'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/transactions.rb:208:in `transaction'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/newrelic_rpm-3.3.0/lib/new_relic/agent/method_tracer.rb:491:in `block in transaction_with_trace_ActiveRecord_self_name_transaction'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/newrelic_rpm-3.3.0/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/newrelic_rpm-3.3.0/lib/new_relic/agent/method_tracer.rb:486:in `transaction_with_trace_ActiveRecord_self_name_transaction'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
     # /Users/karl/.rvm/gems/ruby-1.9.3-p286-falcon@viewthespace/gems/activerecord-3.2.9/lib/active_record/transactions.rb:264:in `save!'
     # ./spec/acceptance/space_caching_spec.rb:32:in `block (4 levels) in <top (required)

To be honest, i tried to reproduce this with a new rails 3.2.9 and rspec 2.12.0 project and i was unable.

thx!

-karl

@alindeman

Without code that I can run to reproduce this, I'm not sure how I can help. Would you mind spending some time to get this down to a test case? Thanks!

@kbaum

Makes sense. I had spent all morning with it trying to reproduce in a fresh rails project so out of desperation, i decided to put an issue out there. Will have back at it.

thx!

@kbaum

I am unable to reproduce the problem in a plain rails project. Thinking maybe i need to change my strategy to stepping through the code. While stepping through the rspec-mocks code this morning, here is what i noticed.

Within rspec/mocks/proxy.rb, the method_double[method_name].stubs is an empty array after the update of the AR object has been called

https://gist.github.com/4089248

Any advice on a way to figure out where it is getting emptied? Perhaps a breakpoint i can put somewhere in the code to catch where the stubs is getting emptied?

thx!

-karl

@alindeman

Unfortunately I'm not sure offhand.

@kbaum

@taqtiqa-mark Doesn't look like it ended up being the same issue.

@alindeman alindeman closed this Dec 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment