diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-07-17 19:35:39 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-07-17 19:35:39 +0530 |
commit | fd8ab8781488923c034200b83278d10dd8c90ba6 (patch) | |
tree | 7dcdb41067649f44cfdb7b6557c74d73bd43a7b2 | |
parent | 75c51b034189aebf4fe2446ee82a85b28779f95b (diff) | |
download | rails-fd8ab8781488923c034200b83278d10dd8c90ba6.tar.gz rails-fd8ab8781488923c034200b83278d10dd8c90ba6.tar.bz2 rails-fd8ab8781488923c034200b83278d10dd8c90ba6.zip |
Refactor the existing session_store to use keyword args and raise early when set to activerecord session store
- Use keyword args as it is possible to use them now.
- The error message for activerecord-session_store gem was added in 1807384.
- But it was added for a code path which gets called when we try to
**access** the session store, not when we **set** it.
- So the test expecting the exception started failing because now the
session store is set via railtie again **after** setting it first with
:active_record_store in the test.
- As the error is not raised while setting the store to
:active_record_store, the store gets overwritten by railtie and when
we access it via `session_store` while building the default middleware
stack, the exception is not raised.
- This commit moves the code for raising the exception to the path where
we try to set the store.
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 4c871c8227..9b93415c83 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -165,26 +165,31 @@ module Rails self.generators.colorize_logging = val end - def session_store(*args) - if args.empty? - case @session_store - when :disabled - nil - when :active_record_store + def session_store(new_session_store = nil, **options) + if new_session_store + + if new_session_store == :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 + end + + @session_store = new_session_store + @session_options = options || {} + else + case @session_store + when :disabled + nil + when :active_record_store + ActionDispatch::Session::ActiveRecordStore when Symbol ActionDispatch::Session.const_get(@session_store.to_s.camelize) else @session_store end - else - @session_store = args.shift - @session_options = args.shift || {} end end |