1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Do not add ActionView::Helpers::DateHelper to all models

This commit is contained in:
José Valim 2012-07-23 15:59:17 +02:00
parent 8bc1096099
commit f4db03d31c
6 changed files with 35 additions and 50 deletions

View file

@ -12,13 +12,6 @@ group :test do
gem "omniauth-openid", "~> 1.0.1"
gem "webrat", "0.7.2", :require => false
gem "mocha", :require => false
platforms :mri_18 do
gem "ruby-debug", ">= 0.10.3"
end
platforms :mri_19 do
gem 'debugger'
end
end
platforms :jruby do

View file

@ -43,14 +43,6 @@ GEM
bson (1.5.1)
bson_ext (1.3.1)
builder (3.0.0)
columnize (0.3.5)
debugger (1.1.4)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1.1)
debugger-ruby_core_source (~> 1.1.3)
debugger-linecache (1.1.2)
debugger-ruby_core_source (>= 1.1.1)
debugger-ruby_core_source (1.1.3)
erubis (2.7.0)
faraday (0.7.5)
addressable (~> 2.2.6)
@ -61,8 +53,6 @@ GEM
i18n (0.6.0)
journey (1.0.4)
json (1.7.3)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@ -122,14 +112,8 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rdoc (3.12)
json (~> 1.4)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-openid (2.1.8)
sprockets (2.1.3)
hike (~> 1.2)
@ -156,7 +140,6 @@ DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
bson_ext (~> 1.3.0)
debugger
devise!
jruby-openssl
mocha
@ -168,6 +151,5 @@ DEPENDENCIES
omniauth-openid (~> 1.0.1)
rails (~> 3.2.6)
rdoc
ruby-debug (>= 0.10.3)
sqlite3
webrat (= 0.7.2)

View file

@ -6,11 +6,12 @@ require 'set'
require 'securerandom'
module Devise
autoload :Delegator, 'devise/delegator'
autoload :FailureApp, 'devise/failure_app'
autoload :OmniAuth, 'devise/omniauth'
autoload :ParamFilter, 'devise/param_filter'
autoload :TestHelpers, 'devise/test_helpers'
autoload :Delegator, 'devise/delegator'
autoload :FailureApp, 'devise/failure_app'
autoload :OmniAuth, 'devise/omniauth'
autoload :ParamFilter, 'devise/param_filter'
autoload :TestHelpers, 'devise/test_helpers'
autoload :TimeInflector, 'devise/time_inflector'
module Controllers
autoload :Helpers, 'devise/controllers/helpers'

View file

@ -121,6 +121,7 @@ module Devise
end
headers
end
protected
# A callback method used to deliver confirmation
@ -158,7 +159,6 @@ module Devise
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
end
# Checks if the user confirmation happens before the token becomes invalid
# Examples:
#
@ -172,26 +172,21 @@ module Devise
# confirmation_period_expired? # will always return false
#
def confirmation_period_expired?
if @confirmation_period_expired.nil?
@confirmation_period_expired = self.class.confirm_within && (Time.now > self.confirmation_sent_at + self.class.confirm_within )
@confirmation_period_expired
else
@confirmation_period_expired
end
self.class.confirm_within && (Time.now > self.confirmation_sent_at + self.class.confirm_within )
end
# Checks whether the record requires any confirmation.
def pending_any_confirmation
@confirmation_period_expired = confirmation_period_expired?
expired = confirmation_period_expired?
if (!confirmed? || pending_reconfirmation?) && !@confirmation_period_expired
if (!confirmed? || pending_reconfirmation?) && !expired
yield
elsif expired
self.errors.add(:email, :confirmation_period_expired,
:period => Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago))
false
else
if @confirmation_period_expired
self.errors.add(:email, :confirmation_period_expired, :period => time_ago_in_words(self.class.confirm_within.ago))
else
self.errors.add(:email, :already_confirmed)
end
self.errors.add(:email, :already_confirmed)
false
end
end

View file

@ -0,0 +1,14 @@
require "active_support/core_ext/module/delegation"
module Devise
class TimeInflector
include ActionView::Helpers::DateHelper
class << self
attr_reader :instance
delegate :time_ago_in_words, :to => :instance
end
@instance = new
end
end

View file

@ -92,12 +92,12 @@ Devise.setup do |config|
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
# A period that the user is allowed to confirm their account before their token
# becomes invalid. For example, if set to 3.days, the user can confirm their account
# within 3 days after the mail was sent, but on the fourth day their account can't be
# confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take before
# confirming their account.
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
# their account within 3 days after the mail was sent, but on the fourth day
# their account can't be confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take
# before confirming their account.
# config.confirm_within = 3.days
# If true, requires any email changes to be confirmed (exactly the same way as