Permalink
Browse files

Raise more helpful error message on missing gem

Tell people to install `activerecord-session_store` gem when it's not
installed instead ofraising `NameError` on missing
`ActionDispatch::Session::ActiveRecordStore`.
  • Loading branch information...
1 parent 19a3eda commit 1807384c96c553af780e98d25ab4750389233f77 @sikachu sikachu committed Aug 24, 2012
Showing with 26 additions and 0 deletions.
  1. +7 −0 railties/lib/rails/application/configuration.rb
  2. +19 −0 railties/test/application/configuration_test.rb
@@ -125,6 +125,13 @@ def session_store(*args)
case @session_store
when :disabled
nil
+ when :active_record_store
+ begin
+ ActionDispatch::Session::ActiveRecordStore
+ rescue NameError
+ raise "`ActiveRecord::SessionStore` is extracted out of Rails into a gem. " \
+ "Please add `activerecord-session_store` to your Gemfile to use it."
+ end
when Symbol
ActionDispatch::Session.const_get(@session_store.to_s.camelize)
else
@@ -630,5 +630,24 @@ class FooObserver < ActiveRecord::Observer
ActiveRecord::Base
assert defined?(FooObserver)
end
+
+ test "config.session_store with :active_record_store with activerecord-session_store gem" do
+ begin
+ make_basic_app do |app|
+ ActionDispatch::Session::ActiveRecordStore = Class.new(ActionDispatch::Session::CookieStore)
+ app.config.session_store :active_record_store
+ end
+ ensure
+ ActionDispatch::Session.send :remove_const, :ActiveRecordStore
+ end
+ end
+
+ test "config.session_store with :active_record_store without activerecord-session_store gem" do
+ assert_raise RuntimeError, /activerecord-session_store/ do
+ make_basic_app do |app|
+ app.config.session_store :active_record_store
+ end
+ end
+ end
end
end

0 comments on commit 1807384

Please sign in to comment.