From eb4e23274df28b2ce8d4c584ae1e4d49bfb5540a Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Sat, 7 Apr 2012 15:54:00 -0300 Subject: [PATCH] Ensure ActiveRecord is defined, which is not true when running Mongoid tests. --- test/controllers/sessions_controller_test.rb | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 83ab169d3e..87678b6c06 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -13,22 +13,24 @@ class SessionsControllerTest < ActionController::TestCase assert_equal 200, @response.status assert_template "devise/sessions/new" end - - if ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer) - test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do - request.env["devise.mapping"] = Devise.mappings[:user] + + if defined?(ActiveRecord) + if ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer) + test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do + request.env["devise.mapping"] = Devise.mappings[:user] - ActiveRecord::Base.mass_assignment_sanitizer = :strict - User.class_eval { attr_protected :email } - - begin - assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do - get :new, :user => { :email => "allez viens!" } + ActiveRecord::Base.mass_assignment_sanitizer = :strict + User.class_eval { attr_protected :email } + + begin + assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do + get :new, :user => { :email => "allez viens!" } + end + ensure + ActiveRecord::Base.mass_assignment_sanitizer = :logger + User.class_eval { attr_accessible :email } end - ensure - ActiveRecord::Base.mass_assignment_sanitizer = :logger - User.class_eval { attr_accessible :email } end end end -end +end \ No newline at end of file