mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Got another bunch of tests passing on Rails 3. 369 tests, 731 assertions, 33 failures, 53 errors.
This commit is contained in:
parent
766316b5e7
commit
b3e11c5aca
8 changed files with 50 additions and 55 deletions
6
Gemfile
6
Gemfile
|
@ -5,4 +5,8 @@ gem "warden", "0.9.2"
|
|||
gem "sqlite3-ruby", :require => "sqlite3"
|
||||
gem "webrat", "0.7"
|
||||
gem "mocha", :require => false
|
||||
gem "bcrypt-ruby", :require => "bcrypt"
|
||||
gem "bcrypt-ruby", :require => "bcrypt"
|
||||
|
||||
if RUBY_VERSION < '1.9'
|
||||
gem "ruby-debug", ">= 0.10.3"
|
||||
end
|
|
@ -23,25 +23,23 @@ class DeviseMailer < ::ActionMailer::Base
|
|||
mapping = Devise::Mapping.find_by_class(record.class)
|
||||
raise "Invalid devise resource #{record}" unless mapping
|
||||
|
||||
subject translate(mapping, key)
|
||||
from mailer_sender(mapping)
|
||||
recipients record.email
|
||||
sent_on Time.now
|
||||
content_type 'text/html'
|
||||
|
||||
@resource = instance_variable_set("@#{mapping.name}", record)
|
||||
render_with_scope(key, mapping)
|
||||
|
||||
mail(:subject => translate(mapping, key), :from => mailer_sender(mapping),
|
||||
:to => record.email) do |format|
|
||||
format.html { render_with_scope(key, mapping) }
|
||||
end
|
||||
end
|
||||
|
||||
def render_with_scope(key, mapping)
|
||||
if self.class.scoped_views
|
||||
begin
|
||||
render :file => "devise_mailer/#{mapping.as}/#{key}"
|
||||
render :template => "devise_mailer/#{mapping.as}/#{key}"
|
||||
rescue ActionView::MissingTemplate
|
||||
render :file => "devise_mailer/#{key}"
|
||||
render :template => "devise_mailer/#{key}"
|
||||
end
|
||||
else
|
||||
render :file => "devise_mailer/#{key}"
|
||||
render :template => "devise_mailer/#{key}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,18 +1,4 @@
|
|||
module Devise
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name :devise
|
||||
|
||||
config.after_initialize do
|
||||
require "devise/orm/#{Devise.orm}"
|
||||
|
||||
# Adds Warden Manager to Rails middleware stack, configuring default devise
|
||||
# strategy and also the failure app.
|
||||
config.middleware.use Warden::Manager do |config|
|
||||
Devise.configure_warden(config)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
autoload :FailureApp, 'devise/failure_app'
|
||||
autoload :Schema, 'devise/schema'
|
||||
autoload :TestHelpers, 'devise/test_helpers'
|
||||
|
|
|
@ -117,10 +117,10 @@ module Devise
|
|||
begin
|
||||
render :template => "#{controller_name}/#{devise_mapping.as}/#{action}"
|
||||
rescue ActionView::MissingTemplate
|
||||
render action, :controller => controller_name
|
||||
render :template => "#{controller_name}/#{action}"
|
||||
end
|
||||
else
|
||||
render action, :controller => controller_name
|
||||
render :template => "#{controller_name}/#{action}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
require 'devise/rails/routes'
|
||||
require 'devise/rails/warden_compat'
|
||||
require 'devise/rails/warden_compat'
|
||||
|
||||
module Devise
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name :devise
|
||||
|
||||
config.middleware.use Warden::Manager do |config|
|
||||
Devise.configure_warden(config)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
module Warden::Mixins::Common
|
||||
def request
|
||||
@request ||= env['action_controller.rescue.request']
|
||||
@request ||= ActionDispatch::Request.new(env)
|
||||
end
|
||||
|
||||
def reset_session!
|
||||
|
@ -9,7 +9,7 @@ module Warden::Mixins::Common
|
|||
end
|
||||
|
||||
def response
|
||||
@response ||= env['action_controller.rescue.response']
|
||||
@response ||= env['action_controller.instance'].response
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,31 +7,30 @@ class ValidatableTest < ActiveSupport::TestCase
|
|||
user = new_user(:email => nil)
|
||||
assert user.invalid?
|
||||
assert user.errors[:email]
|
||||
assert_equal 'can\'t be blank', user.errors[:email]
|
||||
assert_equal 'can\'t be blank', user.errors[:email].join
|
||||
end
|
||||
|
||||
test 'should require uniqueness of email, allowing blank' do
|
||||
existing_user = create_user
|
||||
|
||||
user = new_user(:email => '')
|
||||
assert user.invalid?
|
||||
assert_not_equal 'has already been taken', user.errors[:email]
|
||||
assert_not_equal 'has already been taken', user.errors[:email].join
|
||||
|
||||
user.email = existing_user.email
|
||||
assert user.invalid?
|
||||
assert user.errors[:email]
|
||||
assert_equal 1, [*user.errors[:email]].size
|
||||
assert_equal 'has already been taken', user.errors[:email]
|
||||
assert_equal 'has already been taken', user.errors[:email].join
|
||||
end
|
||||
|
||||
test 'should require correct email format, allowing blank' do
|
||||
user = new_user(:email => '')
|
||||
assert user.invalid?
|
||||
assert_not_equal 'is invalid', user.errors[:email]
|
||||
assert_not_equal 'is invalid', user.errors[:email].join
|
||||
|
||||
%w(invalid_email_format email@invalid invalid$character@mail.com other@not 123).each do |email|
|
||||
user.email = email
|
||||
assert user.invalid?, 'should be invalid with email ' << email
|
||||
assert user.errors[:email]
|
||||
assert_equal 1, [*user.errors[:email]].size
|
||||
assert_equal 'is invalid', user.errors[:email]
|
||||
assert_equal 'is invalid', user.errors[:email].join
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,63 +38,59 @@ class ValidatableTest < ActiveSupport::TestCase
|
|||
%w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test).each do |email|
|
||||
user = new_user(:email => email)
|
||||
assert user.valid?, 'should be valid with email ' << email
|
||||
assert_nil user.errors[:email]
|
||||
assert_blank user.errors[:email]
|
||||
end
|
||||
end
|
||||
|
||||
test 'should require password to be set when creating a new record' do
|
||||
user = new_user(:password => '', :password_confirmation => '')
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_equal 'can\'t be blank', user.errors[:password]
|
||||
assert_equal 'can\'t be blank', user.errors[:password].join
|
||||
end
|
||||
|
||||
test 'should require confirmation to be set when creating a new record' do
|
||||
user = new_user(:password => 'new_password', :password_confirmation => 'blabla')
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_equal 'doesn\'t match confirmation', user.errors[:password]
|
||||
assert_equal 'doesn\'t match confirmation', user.errors[:password].join
|
||||
end
|
||||
|
||||
test 'should require password when updating/reseting password' do
|
||||
user = create_user
|
||||
|
||||
user.password = ''
|
||||
user.password_confirmation = ''
|
||||
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_equal 'can\'t be blank', user.errors[:password]
|
||||
assert_equal 'can\'t be blank', user.errors[:password].join
|
||||
end
|
||||
|
||||
test 'should require confirmation when updating/reseting password' do
|
||||
user = create_user
|
||||
user.password_confirmation = 'another_password'
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_equal 'doesn\'t match confirmation', user.errors[:password]
|
||||
assert_equal 'doesn\'t match confirmation', user.errors[:password].join
|
||||
end
|
||||
|
||||
test 'should require a password with minimum of 6 characters' do
|
||||
user = new_user(:password => '12345', :password_confirmation => '12345')
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_equal 'is too short (minimum is 6 characters)', user.errors[:password]
|
||||
assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
|
||||
end
|
||||
|
||||
test 'should require a password with maximum of 20 characters long' do
|
||||
user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21)
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_equal 'is too long (maximum is 20 characters)', user.errors[:password]
|
||||
assert_equal 'is too long (maximum is 20 characters)', user.errors[:password].join
|
||||
end
|
||||
|
||||
test 'should not require password length when it\'s not changed' do
|
||||
user = create_user.reload
|
||||
user.password = user.password_confirmation = nil
|
||||
assert user.valid?
|
||||
|
||||
user.password_confirmation = 'confirmation'
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_not user.errors[:password].to_a.include?('is too short (minimum is 6 characters)')
|
||||
assert_not (user.errors[:password].join =~ /is too long/)
|
||||
end
|
||||
|
||||
test 'shuold not be included in objects with invalid API' do
|
||||
|
|
|
@ -15,4 +15,6 @@ Webrat.configure do |config|
|
|||
config.open_error_files = false
|
||||
end
|
||||
|
||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
||||
# Add support to load paths so we can overwrite broken webrat setup
|
||||
$:.unshift File.expand_path('../support', __FILE__)
|
||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
Loading…
Add table
Reference in a new issue