1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05: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:
Ches Martin 2011-08-05 01:38:42 +07:00
parent 919404df53
commit 55af9f8a40
8 changed files with 29 additions and 18 deletions

View file

@ -28,7 +28,7 @@ platforms :ruby do
group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "2.0.1"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
end

View file

@ -43,7 +43,7 @@ GEM
addressable (2.2.4)
arel (2.0.9)
bcrypt-ruby (2.1.4)
bson (1.3.0)
bson (1.3.1)
bson_ext (1.3.0)
builder (2.1.2)
columnize (0.3.2)
@ -63,13 +63,12 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
mocha (0.9.12)
mongo (1.3.0)
bson (>= 1.3.0)
mongoid (2.0.1)
mongo (1.3.1)
bson (>= 1.3.1)
mongoid (2.1.4)
activemodel (~> 3.0)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
multi_json (0.0.5)
multipart-post (1.1.0)
nokogiri (1.4.3.1)
@ -130,7 +129,7 @@ GEM
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)
tzinfo (0.3.29)
warden (1.0.4)
rack (>= 1.0)
weakling (0.0.4-java)
@ -138,7 +137,6 @@ GEM
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
will_paginate (3.0.pre2)
PLATFORMS
java
@ -150,7 +148,7 @@ DEPENDENCIES
devise!
mocha
mongo (~> 1.3.0)
mongoid (= 2.0.1)
mongoid (~> 2.0)
oa-oauth (~> 0.2.0)
oa-openid (~> 0.2.0)
rails (~> 3.0.7)

View file

@ -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'
@ -41,3 +48,4 @@ class DeviseHelperTest < ActionController::IntegrationTest
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 2 erreurs"
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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