Make session hash work with more versions of Rack/Rails (#298)
* fix id null and bump version * update session_hash to work with more versions of rack and rails. Co-authored-by: Reza J. Bavaghoush <rzjfr@yahoo.com> Co-authored-by: Russell Osborne <russell.osborne@framebridge.com> Co-authored-by: Sing, Tran Lu Sinh <tran.lu.sinh@moneyforward.vn>
This commit is contained in:
parent
46a582ff8c
commit
6bc9eb8e69
|
@ -1,6 +1,7 @@
|
||||||
AllCops:
|
AllCops:
|
||||||
Exclude:
|
Exclude:
|
||||||
- "spec/dummy/**/*"
|
- "spec/dummy/**/*"
|
||||||
|
SuggestExtensions: false
|
||||||
|
|
||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
Gemspec/RubyVersionGlobalsUsage:
|
Gemspec/RubyVersionGlobalsUsage:
|
||||||
Exclude:
|
Exclude:
|
||||||
- "impressionist.gemspec"
|
- "impressionist.gemspec"
|
||||||
|
Gemspec/RequiredRubyVersion:
|
||||||
|
Exclude:
|
||||||
|
- "impressionist.gemspec"
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
|
|
2
Rakefile
2
Rakefile
|
@ -11,7 +11,7 @@ task default: :spec
|
||||||
Bundler::GemHelper.install_tasks
|
Bundler::GemHelper.install_tasks
|
||||||
|
|
||||||
namespace :impressionist do
|
namespace :impressionist do
|
||||||
require File.dirname(__FILE__) + "/lib/impressionist/bots"
|
require "#{File.dirname(__FILE__)}/lib/impressionist/bots"
|
||||||
|
|
||||||
desc "output the list of bots from http://www.user-agents.org/"
|
desc "output the list of bots from http://www.user-agents.org/"
|
||||||
task :bots do
|
task :bots do
|
||||||
|
|
|
@ -141,26 +141,15 @@ module ImpressionistController
|
||||||
end
|
end
|
||||||
|
|
||||||
def session_hash
|
def session_hash
|
||||||
|
id = session.id || request.session_options[:id]
|
||||||
|
|
||||||
# # careful: request.session_options[:id] encoding in rspec test was ASCII-8BIT
|
if id.respond_to?(:cookie_value)
|
||||||
# # that broke the database query for uniqueness. not sure if this is a testing only issue.
|
id.cookie_value
|
||||||
# str = request.session_options[:id]
|
elsif id.is_a?(Rack::Session::SessionId)
|
||||||
# logger.debug "Encoding: #{str.encoding.inspect}"
|
id.public_id
|
||||||
# # request.session_options[:id].encode("ISO-8859-1")
|
|
||||||
if Rails::VERSION::MAJOR >= 4
|
|
||||||
session["init"] = true
|
|
||||||
id = session.id.to_s
|
|
||||||
else
|
else
|
||||||
id = request.session_options[:id]
|
id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
unless id.is_a? String
|
|
||||||
id = id.cookie_value if Rack::Session::SessionId.const_defined?(:ID_VERSION) && Rack::Session::SessionId::ID_VERSION == 2
|
|
||||||
end
|
|
||||||
|
|
||||||
# id = cookies.session.id
|
|
||||||
# rack 2.0.8 releases new version of session id, id.to_s will raise error!
|
|
||||||
id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_hash
|
def params_hash
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Impressionist
|
||||||
|
|
||||||
|
|
||||||
initializer 'impressionist.controller' do
|
initializer 'impressionist.controller' do
|
||||||
require "impressionist/controllers/mongoid/impressionist_controller.rb" if orm == :mongoid.to_s
|
require "impressionist/controllers/mongoid/impressionist_controller" if orm == :mongoid.to_s
|
||||||
|
|
||||||
ActiveSupport.on_load(:action_controller) do
|
ActiveSupport.on_load(:action_controller) do
|
||||||
include ImpressionistController::InstanceMethods
|
include ImpressionistController::InstanceMethods
|
||||||
|
|
|
@ -9,15 +9,15 @@ describe Impressionist::SetupAssociation do
|
||||||
let(:setup_association) { described_class.new(mock) }
|
let(:setup_association) { described_class.new(mock) }
|
||||||
|
|
||||||
it 'will include when togglable' do
|
it 'will include when togglable' do
|
||||||
expect(mock).to receive(:attr_accessible).with(any_args).and_return(true)
|
allow(mock).to receive(:attr_accessible).with(any_args).and_return(true)
|
||||||
expect(setup_association).to receive(:toggle).and_return(true)
|
allow(setup_association).to receive(:toggle).and_return(true)
|
||||||
|
|
||||||
expect(setup_association).to be_include_attr_acc
|
allow(setup_association).to be_include_attr_acc
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not include if it is not togglable' do
|
it 'will not include if it is not togglable' do
|
||||||
expect(setup_association).to receive(:toggle).and_return(false)
|
allow(setup_association).to receive(:toggle).and_return(false)
|
||||||
expect(setup_association).not_to be_include_attr_acc
|
allow(setup_association).not_to be_include_attr_acc
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when using rails >= 5' do
|
context 'when using rails >= 5' do
|
||||||
|
|
Loading…
Reference in New Issue