Skip to content

Loading…

Error "undefined method `reflect_on_association'" when using Spork and ActiveRecord assocations with :inverse_of #112

Open
tobico opened this Issue · 0 comments

1 participant

@tobico

I'm trying to use Spork to speed up running my Rails tests, but every test is failing on the same one line of code in ActiveRecord, and these same tests work fine if I run them without Spork.

This is the line of code (activerecord-3.0.7/lib/active_record/reflection.rb:266) that's identified as the cause of the failure - I don't think this would be called at all if I weren't using the new :inverse_of feature in most of my ActiveRecord associations.

264      def inverse_of
265        if has_inverse?
266          @inverse_of ||= klass.reflect_on_association(options[:inverse_of])
267        end
268      end

And here's a full backtrace for one failure:

  1) DivisionsController with administrator#show should return division
     Failure/Error: @tournament = Factory(:tournament)
     NoMethodError:
       undefined method `reflect_on_association' for Division:Class
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/reflection.rb:266:in `inverse_of'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/reflection.rb:243:in `check_validity_of_inverse!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/reflection.rb:238:in `check_validity!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/associations/association_proxy.rb:61:in `initialize'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/associations/association_collection.rb:23:in `initialize'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/associations/has_many_association.rb:11:in `initialize'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/associations.rb:1483:in `new'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/associations.rb:1483:in `block in collection_reader_method'
     # ./app/models/tournament.rb:314:in `create_divisions'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:440:in `_run_create_callbacks'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/callbacks.rb:277:in `create'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/persistence.rb:246:in `create_or_update'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/callbacks.rb:273:in `block in create_or_update'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:451:in `_run_save_callbacks'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/callbacks.rb:273:in `create_or_update'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/persistence.rb:56:in `save!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/validations.rb:49:in `save!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:245:in `block in save!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:207:in `transaction'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/transactions.rb:245:in `save!'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/proxy/create.rb:6:in `result'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:330:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:273:in `create'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:304:in `default_strategy'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/factory_girl-1.3.3/lib/factory_girl.rb:20:in `Factory'
     # ./spec/controllers/divisions_controller_spec.rb:13:in `block (4 levels) in '
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `instance_eval'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `run_in'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `block in run_all'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `each'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `run_all'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:110:in `run_hook'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `block in eval_before_eachs'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `each'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:144:in `run_before_each'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:48:in `block (2 levels) in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:106:in `with_around_hooks'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:46:in `block in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:99:in `block in with_pending_capture'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `catch'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `with_pending_capture'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:45:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:262:in `block in run_examples'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `map'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `run_examples'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:232:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `block in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `map'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `block in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `map'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `map'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/reporter.rb:12:in `report'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:24:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/monkey/spork/test_framework/rspec.rb:4:in `run_tests'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/run_strategy/forking.rb:13:in `block in run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/forker.rb:21:in `block in initialize'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/forker.rb:18:in `fork'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/forker.rb:18:in `initialize'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/run_strategy/forking.rb:9:in `new'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/run_strategy/forking.rb:9:in `run'
     # /Users/tobico/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc7/lib/spork/server.rb:48:in `run'
     # /Users/tobico/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
     # /Users/tobico/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
     # /Users/tobico/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
     # /Users/tobico/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
     # /Users/tobico/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.