Skip to content

Commit

Permalink
Do not add ActionView::Helpers::DateHelper to all models
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jul 23, 2012
1 parent 8bc1096 commit f4db03d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 50 deletions.
7 changes: 0 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -156,7 +140,6 @@ DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
bson_ext (~> 1.3.0)
debugger
devise!
jruby-openssl
mocha
Expand All @@ -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)
11 changes: 6 additions & 5 deletions lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
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'
Expand Down
23 changes: 9 additions & 14 deletions lib/devise/models/confirmable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def headers_for(action)
end
headers
end

protected

# A callback method used to deliver confirmation
Expand Down Expand Up @@ -158,7 +159,6 @@ def confirmation_period_valid?
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:
#
Expand All @@ -172,26 +172,21 @@ def confirmation_period_valid?
# 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
Expand Down
14 changes: 14 additions & 0 deletions lib/devise/time_inflector.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions lib/generators/templates/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
# 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
Expand Down

0 comments on commit f4db03d

Please sign in to comment.