pat / combustion

Simple, elegant testing for Rails Engines
MIT License
708 stars 51 forks source link

Errors when Combustion is loading jquery-rails #50

Closed bricker closed 11 years ago

bricker commented 11 years ago

Sorry about throwing a bunch of code at you...

spec_helper.rb:

ENV["RAILS_ENV"] ||= 'test'
require 'bundler/setup'

require 'combustion'
Combustion.initialize! :active_record, :action_controller, :action_view

require 'rspec/rails'

RSpec.configure do |config|
  #...
end

Gemfile:

source "https://rubygems.org"

group :test do
  gem "sqlite3"
  gem "combustion"

  gem 'rails', '~> 3.2.13'
  gem 'activerecord', '~> 3.2.13'
  gem 'actionpack', '~> 3.2.13'

  gem "rspec-rails"
  gem "factory_girl"
end

gemspec

gemspec:

  s.add_dependency "rails", "~> 3.2.1"
  s.add_dependency "paperclip", "~> 3.4.1"
  s.add_dependency "thinking-sphinx", "~> 2.0.14"
  s.add_dependency "resque", "~> 1.23.0"

  s.add_dependency "bootstrap-sass", "~> 2.3.1"
  s.add_dependency 'sass-rails',   '~> 3.2.3'
  s.add_dependency 'coffee-rails', '~> 3.2.1'
  s.add_dependency "eco", '~> 1.0.0'
  s.add_dependency "jquery-rails", "~> 2.2.1"
  s.add_dependency "simple_form", "~> 2.1.0"
  s.add_dependency "kaminari", "~> 0.14.1"

And I have some requires at the top of my engine.rb:

require 'rails'

# This was necessary for some reason, I guess it was using an 
# older version of rake that didn't have the "namespace" method, 
# and was failing when trying to load "tasks.rb" in thinking sphinx
require 'rake' 

require 'resque'
require 'thinking_sphinx'
require 'paperclip'

require 'jquery-rails'
require 'coffee-rails'
require 'sass-rails'
require 'eco'
require 'bootstrap-sass'

require 'simple_form'
require 'kaminari'

So basically when I run bundle exec rake, I get:

...gems/jquery-rails-2.2.1/lib/jquery/rails/railtie.rb:17:in `block in <class:Railtie>': uninitialized constant Jquery::Rails::Railtie::PROTOTYPE_JS (NameError)

If I remove require 'jquery-rails' from engine.rb, the tests run fine but then my app won't load (sprockets complains, "can't find file 'jquery'").

pat commented 11 years ago

Hi Bryan

I realise this ticket's been sitting around for a little while. I'm not entirely sure what the cause is, but jquery/rails does define Jquery::Rails::PROTOTYPE_JS (though not Jquery::Rails::Railtie::PROTOTYPE_JS - but wouldn't Ruby's constant hierarchy pick up on that?). It's a little odd, and there's been no patches to the jquery-rails gem's source code nor any issues logged that would indicate others are seeing this problem elsewhere.

I don't suppose you've made any progress on this since logging the issue?

bricker commented 11 years ago

To work around this, I added jquery-rails to my app's Gemfile, and removed it from the engine all together. Not really a solution but I can run the tests and the app now.

pat commented 11 years ago

Ah, good to know you got a solution figured out. I'm going to close this, but if anyone hits the same issue and wants to discuss how to work through it, feel free to comment here.

joostlubach commented 10 years ago

I don't know if it's useful, but I've found out why it happens. The gem 'jquery-rails' uses a 'before configuration' block to initialize some things. Normally, in application.rb, all railties are loaded before your <ProjectName>::Application class is created, so that these before configuration blocks are run at the right time.

Combustion seems to create class Combustion::Application immediately when file 'combustion' is required, which means that any subsequent 'before configuration' blocks are run immediately when they are defined. In the case of jquery-rails, this is too soon, as this constant has not been set yet.

My workaround was to use the following:

require 'rails'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'sprockets/railtie'
require 'jquery/rails'

require 'combustion'
Combustion.initialize!