Skip to content

Commit

Permalink
Fix failing Mongoid tests
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
ches committed Aug 4, 2011
1 parent 919404d commit 55af9f8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -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
14 changes: 6 additions & 8 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -130,15 +129,14 @@ 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)
webrat (0.7.2)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
will_paginate (3.0.pre2)

PLATFORMS
java
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions test/helpers/devise_helper_test.rb
Expand Up @@ -2,13 +2,16 @@

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'
Expand All @@ -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'
Expand All @@ -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

8 changes: 8 additions & 0 deletions test/integration/registerable_test.rb
Expand Up @@ -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'
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/orm/mongoid.rb
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/rails_app/app/active_record/user.rb
Expand Up @@ -3,6 +3,4 @@
class User < ActiveRecord::Base
include Shim
include SharedUser

attr_accessible :username, :email, :password, :password_confirmation, :remember_me
end
5 changes: 0 additions & 5 deletions test/rails_app/app/mongoid/shim.rb
Expand Up @@ -21,9 +21,4 @@ def find_by_email(email)
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
1 change: 1 addition & 0 deletions test/rails_app/lib/shared_user.rb
Expand Up @@ -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
Expand Down

0 comments on commit 55af9f8

Please sign in to comment.