Skip to content

Commit

Permalink
- Fixes #142
Browse files Browse the repository at this point in the history
- The goal of #126 was to lazily require the 'session.rb' file as
  otherwise, we'd load `Active::Record` base too prematurely during
  the boot process.

  This change had the negative effect of breakin apps that were
  setting configuration on the `Session` **before** the hook was
  getting triggered, thus ending up with a "uninitialized constant"
  error.

  This patches move the `session_class` assignment when loading then
  `session.rb` file as well as autoloading the
  `AR::SessionStore::Session` constant so that application referencing
  it too early will still work.
  • Loading branch information
Edouard-chin committed Mar 12, 2019
1 parent d7a918c commit 588d83d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/active_record/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

module ActiveRecord
module SessionStore
autoload :Session, 'active_record/session_store/session'

module ClassMethods # :nodoc:
mattr_accessor :serializer

Expand Down Expand Up @@ -111,7 +113,6 @@ def self.dump(value)

ActiveSupport.on_load(:active_record) do
require 'active_record/session_store/session'
ActionDispatch::Session::ActiveRecordStore.session_class = ActiveRecord::SessionStore::Session
end

require 'active_record/session_store/sql_bypass'
Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/session_store/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ def raise_on_session_data_overflow!
end
end
end

ActionDispatch::Session::ActiveRecordStore.session_class = ActiveRecord::SessionStore::Session

0 comments on commit 588d83d

Please sign in to comment.