mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Remove Rails 3.0 only code.
This commit is contained in:
parent
c3f864f2b6
commit
7c11564613
5 changed files with 3 additions and 128 deletions
|
@ -418,11 +418,6 @@ module Devise
|
|||
end
|
||||
end
|
||||
|
||||
# Returns true if Rails version is bigger than 3.0.x
|
||||
def self.rack_session?
|
||||
Rails::VERSION::STRING[0,3] != "3.0"
|
||||
end
|
||||
|
||||
# Regenerates url helpers considering Devise.mapping
|
||||
def self.regenerate_helpers!
|
||||
Devise::Controllers::UrlHelpers.remove_helpers!
|
||||
|
|
|
@ -34,87 +34,4 @@ class Warden::SessionSerializer
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Devise.rack_session?
|
||||
# We cannot use Rails Indifferent Hash because it messes up the flash object.
|
||||
class Devise::IndifferentHash < Hash
|
||||
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
||||
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
||||
|
||||
def [](key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
regular_writer(convert_key(key), value)
|
||||
end
|
||||
|
||||
alias_method :store, :[]=
|
||||
|
||||
def update(other_hash)
|
||||
other_hash.each_pair { |key, value| regular_writer(convert_key(key), value) }
|
||||
self
|
||||
end
|
||||
|
||||
alias_method :merge!, :update
|
||||
|
||||
def key?(key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
alias_method :include?, :key?
|
||||
alias_method :has_key?, :key?
|
||||
alias_method :member?, :key?
|
||||
|
||||
def fetch(key, *extras)
|
||||
super(convert_key(key), *extras)
|
||||
end
|
||||
|
||||
def values_at(*indices)
|
||||
indices.collect {|key| self[convert_key(key)]}
|
||||
end
|
||||
|
||||
def merge(hash)
|
||||
self.dup.update(hash)
|
||||
end
|
||||
|
||||
def delete(key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def stringify_keys!; self end
|
||||
def stringify_keys; dup end
|
||||
|
||||
undef :symbolize_keys!
|
||||
def symbolize_keys; to_hash.symbolize_keys end
|
||||
|
||||
def to_options!; self end
|
||||
def to_hash; Hash.new.update(self) end
|
||||
|
||||
protected
|
||||
|
||||
def convert_key(key)
|
||||
key.kind_of?(Symbol) ? key.to_s : key
|
||||
end
|
||||
end
|
||||
|
||||
class ActionDispatch::Request
|
||||
def reset_session
|
||||
session.destroy if session && session.respond_to?(:destroy)
|
||||
self.session = {}
|
||||
@env['action_dispatch.request.flash_hash'] = nil
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Manager.after_set_user :event => [:set_user, :authentication] do |record, warden, options|
|
||||
if options[:scope] && warden.authenticated?(options[:scope])
|
||||
request, flash = warden.request, warden.env['action_dispatch.request.flash_hash']
|
||||
backup = request.session.to_hash
|
||||
backup.delete("session_id")
|
||||
request.reset_session
|
||||
warden.env['action_dispatch.request.flash_hash'] = flash
|
||||
request.session = Devise::IndifferentHash.new.update(backup)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,5 @@
|
|||
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
<% if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 -%>
|
||||
def change
|
||||
<% else -%>
|
||||
def self.up
|
||||
<% end -%>
|
||||
create_table(:<%= table_name %>) do |t|
|
||||
<%= migration_data -%>
|
||||
|
||||
|
@ -20,10 +16,4 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|||
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
||||
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
||||
end
|
||||
|
||||
<% unless ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 -%>
|
||||
def self.down
|
||||
drop_table :<%= table_name %>
|
||||
end
|
||||
<% end -%>
|
||||
end
|
||||
|
|
|
@ -8,20 +8,10 @@ if DEVISE_ORM == :active_record
|
|||
destination File.expand_path("../../tmp", __FILE__)
|
||||
setup :prepare_destination
|
||||
|
||||
test "all files are properly created" do
|
||||
with_rails_version :MAJOR => 3, :MINOR => 0 do
|
||||
run_generator %w(monster)
|
||||
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
|
||||
assert_migration "db/migrate/devise_create_monsters.rb", /def self\.up/
|
||||
end
|
||||
end
|
||||
|
||||
test "all files are properly created with rails31 migration syntax" do
|
||||
with_rails_version :MAJOR => 3, :MINOR => 1 do
|
||||
run_generator %w(monster)
|
||||
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
|
||||
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
|
||||
end
|
||||
run_generator %w(monster)
|
||||
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
|
||||
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
|
||||
end
|
||||
|
||||
test "update model migration when model exists" do
|
||||
|
|
|
@ -67,21 +67,4 @@ class ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def with_rails_version(constants)
|
||||
saved_constants = {}
|
||||
|
||||
constants.each do |constant, val|
|
||||
saved_constants[constant] = ::Rails::VERSION.const_get constant
|
||||
Kernel::silence_warnings { ::Rails::VERSION.const_set(constant, val) }
|
||||
end
|
||||
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
constants.each do |constant, val|
|
||||
Kernel::silence_warnings { ::Rails::VERSION.const_set(constant, saved_constants[constant]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue