Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoid models not reloading with trap_method #205

Open
k504866430 opened this issue Aug 1, 2012 · 3 comments
Open

Mongoid models not reloading with trap_method #205

k504866430 opened this issue Aug 1, 2012 · 3 comments

Comments

@k504866430
Copy link

My gems-

mongoid (3.0.0.rc)
spork (1.0.0rc3)
rspec-rails (2.11.0) 

The documentation at https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujitsu does not work for me. The following is my config-

#spec_helper.rb
Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require "rails/mongoid"
  require "rails/application"
  require 'capybara/rspec'
  Spork.trap_class_method(Rails::Mongoid, :load_models)
  require File.expand_path("../../config/environment", __FILE__)
....
end

spork starts fine-

$ spork
Using RSpec, Unknown
Loading Spork.prefork block...
WARNING: Cucumber-rails required outside of env.rb.  The rest of loading is being defered until env.rb is called.
  To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
Loading configuration for 'test'.

[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.


[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Mongoid::Spacial::Document instead. (called from include at /Users/kruttikagarwal/Documents/workspace-rails/tappedin/app/models/need.rb:3)
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Mongoid::Spacial::Document instead. (called from include at /Users/kruttikagarwal/Documents/workspace-rails/tappedin/app/models/address.rb:3)
/Users/kruttikagarwal/.rvm/gems/ruby-1.9.3-p0@rails327/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
Spork is ready and listening on 8989!

Rspec also runs fine-

$ rspec ./spec/models/aspect_spec.rb:6 --drb
$ rspec ./spec/models/aspect_spec.rb:6 --drb
Run options: include {:locations=>{"./spec/models/aspect_spec.rb"=>[6]}}
F

Failures:

  1) Aspect 
     Failure/Error: it {should have_and_belong_to_many :questions}
       Expected Aspect to reference and referenced in many "questions", got no association named questions
     # ./spec/models/aspect_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.13289 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/models/aspect_spec.rb:6 # Aspect 

but when I update the aspect.rb mongoid model, it does get reloaded when I run rpsec again. I continue to get outdated error.

Wasn't trap_method designed to do that?

$ bundle list
Gems included by the bundle:
  * actionmailer (3.2.7)
  * actionpack (3.2.7)
  * activeadmin (0.4.4)
  * activemodel (3.2.7)
  * activerecord (3.2.7)
  * activeresource (3.2.7)
  * activesupport (3.2.7)
  * addressable (2.2.8)
  * arel (3.0.2)
  * backbone-on-rails (0.9.2.1)
  * bcrypt-ruby (3.0.1)
  * bourbon (2.1.1)
  * builder (3.0.0)
  * bundler (1.2.0.rc)
  * capybara (1.1.2)
  * carrierwave (0.6.2)
  * carrierwave-mongoid (0.1.0)
  * childprocess (0.3.4)
  * choice (0.1.6)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.3.3)
  * columnize (0.3.6)
  * cucumber (1.2.1)
  * cucumber-rails (1.3.0)
  * daemons (1.1.8)
  * database_cleaner (0.8.0)
  * debugger (1.2.0)
  * debugger-linecache (1.1.2)
  * debugger-ruby_core_source (1.1.3)
  * devise (2.1.2)
  * diff-lcs (1.1.3)
  * eco (1.0.0)
  * eco-source (1.1.0.rc.1)
  * ejs (1.0.0)
  * erubis (2.7.0)
  * eventbrite-client (0.1.4)
  * eventmachine (0.12.10)
  * excon (0.13.4)
  * execjs (1.4.0)
  * factory_girl (3.5.0)
  * factory_girl_rails (3.5.0)
  * fakeweb (1.3.0)
  * faraday (0.8.1)
  * fastercsv (1.5.5)
  * ffi (1.1.1)
  * fog (1.3.1)
  * formatador (0.2.3)
  * formtastic (2.1.1)
  * gherkin (2.11.1)
  * google-spreadsheet-ruby (0.3.0)
  * google_drive (0.3.1)
  * guard (1.2.3)
  * guard-cucumber (1.2.0)
  * guard-jasmine (1.5.1)
  * guard-rspec (1.2.0)
  * guard-spork (1.1.0)
  * haml (3.1.6)
  * haml-rails (0.3.4)
  * has_scope (0.5.1)
  * hashie (1.2.0)
  * heroku (2.26.3)
  * heroku-api (0.2.1)
  * hike (1.2.1)
  * httparty (0.8.3)
  * httpauth (0.1)
  * i18n (0.6.0)
  * inherited_resources (1.3.1)
  * jasminerice (0.0.9)
  * journey (1.0.4)
  * jquery-rails (2.0.2)
  * json (1.7.4)
  * jwt (0.1.5)
  * kaminari (0.13.0)
  * launchy (2.1.0)
  * libwebsocket (0.1.5)
  * linkedin (0.3.7)
  * listen (0.4.7)
  * log4r (1.1.10)
  * mail (2.4.4)
  * marionette-rails (0.9.3)
  * meta_search (1.1.3)
  * mime-types (1.19)
  * mongoid (3.0.0.rc)
  * mongoid-ancestry (0.3.0.rc)
  * mongoid-rspec (1.4.6)
  * mongoid_spacial (0.2.16)
  * moped (1.0.1)
  * multi_json (1.3.6)
  * multi_xml (0.5.1)
  * multipart-post (1.1.5)
  * nested_form (0.2.2)
  * net-scp (1.0.4)
  * net-ssh (2.5.2)
  * netrc (0.7.5)
  * nokogiri (1.5.5)
  * oauth (0.4.6)
  * oauth2 (0.8.0)
  * omniauth (1.1.0)
  * omniauth-eventbrite (0.0.3)
  * omniauth-facebook (1.4.0)
  * omniauth-foursquare (0.0.7)
  * omniauth-linkedin (0.0.6)
  * omniauth-oauth (1.0.1)
  * omniauth-oauth2 (1.0.3)
  * omniauth-openid (1.0.1)
  * omniauth-twitter (0.0.12)
  * origin (1.0.4)
  * orm_adapter (0.4.0)
  * polyamorous (0.5.0)
  * polyglot (0.3.3)
  * rabl (0.7.0)
  * rack (1.4.1)
  * rack-cache (1.2)
  * rack-openid (1.3.1)
  * rack-ssl (1.3.2)
  * rack-test (0.6.1)
  * rails (3.2.7)
  * rails_simple_config (0.0.4)
  * railties (3.2.7)
  * rake (0.9.2.2)
  * rb-fchange (0.0.5)
  * rb-fsevent (0.9.1)
  * rb-inotify (0.8.8)
  * rdoc (3.12)
  * responders (0.9.2)
  * rest-client (1.6.7)
  * rmagick (2.13.1)
  * roo (1.10.1)
  * rspec (2.11.0)
  * rspec-core (2.11.1)
  * rspec-expectations (2.11.2)
  * rspec-mocks (2.11.1)
  * rspec-rails (2.11.0)
  * ruby-hmac (0.4.0)
  * ruby-ole (1.2.11.4)
  * ruby-openid (2.2.0)
  * rubyzip (0.9.9)
  * sass (3.1.20)
  * sass-rails (3.2.5)
  * selenium-webdriver (2.25.0)
  * shoulda (3.1.1)
  * shoulda-context (1.0.0)
  * shoulda-matchers (1.2.0)
  * spork (1.0.0rc3)
  * spreadsheet (0.7.3)
  * sprockets (2.1.3)
  * thin (1.4.1)
  * thor (0.15.4)
  * tilt (1.3.3)
  * todonotes (0.1.0)
  * treetop (1.4.10)
  * tzinfo (0.3.33)
  * uglifier (1.2.6)
  * vcr (2.2.4)
  * warden (1.2.1)
  * xpath (0.1.4)
  * yajl-ruby (1.1.0)
@hosamaly
Copy link

I haven't seen this issue with Rails 3.2.8, Mongoid 3.0.6, Mongoid-RSpec 1.5.4, RSpec 2.11.0 (rspec-core 2.11.1) and Spork 1.0.0rc3. Are you still having this issue?

@k504866430
Copy link
Author

Lemme check that and I will get back to you. To get around the issue, I did the following-

# spec_helper.rb
Spork.each_run do
  # This code will be run each time you run your specs.
  FactoryGirl.reload
  # reload all the models
  Dir["#{Rails.root}/app/models/**/*.rb", "#{Rails.root}/app/services/**/*.rb", "#{Rails.root}/app/admin/**/*.rb","#{Rails.root}/app/mailers/**/*.rb"].each do |model|
    load model
  end

end

@jesseclark
Copy link

This started happening to my tests as well after I upgraded to spork 1.0.0rc3 without realizing that the rails integration stuff had been moved to a new gem.

After switching to gem 'spork-rails' everything is fine again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants