mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Fix failing Mongoid tests
- attr_accessible not set for test user model, making Serializable tests inaccurate - Mongoid does not `include_root_in_json` by default, so enable this for consistency with AR tests - Mark tests pending for Mongoid < 2.1 that fail there due to known bugs - Add `:mongoid` key for i18n model labels - Remove outdated shim of `update_attribute` that caused mass assignment security to be applied (ugh, that took awhile to find)
This commit is contained in:
@@ -2,13 +2,16 @@ require 'test_helper'
|
||||
|
||||
class DeviseHelperTest < ActionController::IntegrationTest
|
||||
setup do
|
||||
model_labels = { :models => { :user => "utilisateur" } }
|
||||
|
||||
I18n.backend.store_translations :fr,
|
||||
{
|
||||
:errors => { :messages => { :not_saved => {
|
||||
:one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
|
||||
:other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
|
||||
} } },
|
||||
:activerecord => { :models => { :user => "utilisateur" } }
|
||||
:activerecord => model_labels,
|
||||
:mongoid => model_labels
|
||||
}
|
||||
|
||||
I18n.locale = 'fr'
|
||||
@@ -30,6 +33,10 @@ class DeviseHelperTest < ActionController::IntegrationTest
|
||||
end
|
||||
|
||||
test 'test errors.messages.not_saved with multiple errors from i18n' do
|
||||
# Dirty tracking behavior prevents email validations from being applied:
|
||||
# https://github.com/mongoid/mongoid/issues/756
|
||||
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
|
||||
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'invalid_email'
|
||||
@@ -40,4 +47,5 @@ class DeviseHelperTest < ActionController::IntegrationTest
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 2 erreurs"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ class RegistrationTest < ActionController::IntegrationTest
|
||||
end
|
||||
|
||||
test 'a guest user cannot sign up with invalid information' do
|
||||
# Dirty tracking behavior prevents email validations from being applied:
|
||||
# https://github.com/mongoid/mongoid/issues/756
|
||||
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
|
||||
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'invalid_email'
|
||||
@@ -87,6 +91,10 @@ class RegistrationTest < ActionController::IntegrationTest
|
||||
end
|
||||
|
||||
test 'a guest should not sign up with email/password that already exists' do
|
||||
# Dirty tracking behavior prevents email validations from being applied:
|
||||
# https://github.com/mongoid/mongoid/issues/756
|
||||
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
|
||||
|
||||
user = create_user
|
||||
get new_user_registration_path
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
require 'mongoid/version'
|
||||
|
||||
Mongoid.configure do |config|
|
||||
config.master = Mongo::Connection.new('127.0.0.1', 27017).db("devise-test-suite")
|
||||
config.use_utc = true
|
||||
config.include_root_in_json = true
|
||||
end
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
|
||||
@@ -3,6 +3,4 @@ require 'shared_user'
|
||||
class User < ActiveRecord::Base
|
||||
include Shim
|
||||
include SharedUser
|
||||
|
||||
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
|
||||
end
|
||||
|
||||
@@ -21,9 +21,4 @@ module Shim
|
||||
def ==(other)
|
||||
other.is_a?(self.class) && _id == other._id
|
||||
end
|
||||
|
||||
# Mongoid does not have this method in the current beta version (2.0.0.beta.20)
|
||||
def update_attribute(attribute, value)
|
||||
update_attributes(attribute => value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ module SharedUser
|
||||
:trackable, :validatable, :omniauthable
|
||||
|
||||
attr_accessor :other_key
|
||||
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
|
||||
|
||||
# They need to be included after Devise is called.
|
||||
extend ExtendMethods
|
||||
|
||||
Reference in New Issue
Block a user