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

Running test mode on Heroku #11

Closed
jobinthepast opened this issue Sep 21, 2011 · 2 comments
Closed

Running test mode on Heroku #11

jobinthepast opened this issue Sep 21, 2011 · 2 comments

Comments

@jobinthepast
Copy link

I have my app running in Test mode on Heroku. switch_user works well locally with Test mode but causes an exception on Heroku so that the app cannot start

I add config/initializers/switch_user.rb with these changes (to run in Test mode):

 27   config.controller_guard = lambda { |current_user, request| Rails.env.development? || Rails.env.test? }
 28 
 29   # view_guard is a block,
 30   # if it returns true, the switch user select box will be shown,
 31   # else the select box will not be shown
 32   # if you switch from admin to "user", the current_user param is "user"
 33   config.view_guard = lambda { |current_user, request| Rails.env.development? || Rails.env.test? }

And this is the error message on Heroku logs:

2011-09-21T02:32:27+00:00 app[web.1]: /app/config/initializers/switch_user.rb:1:in `<top (required)>': uninitialized constant SwitchUser (NameError)
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/engine.rb:200:in `each'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/engine.rb:200:in `block in <class:Engine>'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `instance_exec'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `run'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/initializable.rb:50:in `block in run_initializers'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `each'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `run_initializers'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/application.rb:134:in `initialize!'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.10/lib/rails/application.rb:77:in `method_missing'
2011-09-21T02:32:27+00:00 app[web.1]:   from /app/config/environment.rb:5:in `<top (required)>'
2011-09-21T02:32:27+00:00 app[web.1]:   from <internal:lib/rubygems/custom_require>:29:in `require'
2011-09-21T02:32:27+00:00 app[web.1]:   from <internal:lib/rubygems/custom_require>:29:in `require'
2011-09-21T02:32:27+00:00 app[web.1]:   from config.ru:3:in `block (3 levels) in <main>'
@chrislwade
Copy link

Your Gemfile probably has something like this (or a variant of it):

group :development, :test do
  gem 'switch_user'
end

Most (all recent unless you change it) Heroku applications are created the following under heroku config:

BUNDLE_WITHOUT              => development:test

Which means, since you have your Heroku instance configured to run with RAILS_ENV=test, that when you deploy bundler doesn't even bother installing switch_user and therefore won't try to load it. Ultimately that means that when your initializer runs, SwitchUser hasn't been defined and you end up with a NameError.

@jobinthepast
Copy link
Author

Hi Chris,

I'm using Cedar stack which heroku config output doesn't contain BUNDLE_WITHOUT configuration as Bamboo.
Anyway, I tried to move switch_user outside the dev/test scopes then it works.

Thanks for your reply,
-Giang

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

2 participants