Skip to content

Commit

Permalink
make storage_options set the default on include
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnn committed Oct 3, 2013
1 parent 9deb6e6 commit b3231c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 8 additions & 4 deletions lib/mongoid/sessions.rb
Expand Up @@ -9,8 +9,13 @@ module Sessions
include Options

included do
cattr_accessor :default_collection_name, :storage_options
self.default_collection_name = self.name.collectionize.to_sym
cattr_accessor :default_collection_name do
self.name.collectionize.to_sym
end

cattr_accessor :storage_options, instance_writer: false do
{}
end
end

class << self
Expand Down Expand Up @@ -214,8 +219,7 @@ def session_override
# @since 3.0.0
def store_in(options)
Validators::Storage.validate(self, options)
self.storage_options ||= {}
self.storage_options.merge!(options)
storage_options.merge!(options)
end

private
Expand Down
14 changes: 7 additions & 7 deletions spec/mongoid/sessions_spec.rb
Expand Up @@ -52,7 +52,7 @@
end

after do
Band.storage_options = nil
Band.storage_options = {}
end

context "when called multiple times with different options" do
Expand Down Expand Up @@ -150,7 +150,7 @@
end

after do
Band.storage_options = nil
Band.storage_options = {}
end

context "when overriding with a proc" do
Expand Down Expand Up @@ -231,7 +231,7 @@
end

after do
Band.storage_options = nil
Band.storage_options = {}
end

context "when getting the default" do
Expand All @@ -241,14 +241,14 @@
end

before do
Band.storage_options = nil
Band.storage_options = {}
described_class.clear
Mongoid.load!(file, :test)
Mongoid.sessions[:default][:database] = database_id
end

after do
Band.storage_options = nil
Band.storage_options = {}
end

let!(:band) do
Expand Down Expand Up @@ -404,7 +404,7 @@
end

after do
Band.storage_options = nil
Band.storage_options = {}
end

context "when getting the default" do
Expand All @@ -414,7 +414,7 @@
end

before do
Band.storage_options = nil
Band.storage_options = {}
described_class.clear
Mongoid.load!(file, :test)
Mongoid.sessions[:default][:database] = database_id
Expand Down

0 comments on commit b3231c8

Please sign in to comment.