1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Use User and Admin orm_adapter adapter in tests to support other ORMs (neo4j, in this case)

This commit is contained in:
Brian Underwood 2014-06-04 21:59:30 -07:00
parent 65d7d1ba55
commit 2174e4675e
3 changed files with 19 additions and 16 deletions

View file

@ -17,7 +17,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_current_url "/admin_area/home" assert_current_url "/admin_area/home"
admin = Admin.order(:id).last admin = AdminAdapter.find_first(order: [:id, :desc])
assert_equal admin.email, 'new_user@test.com' assert_equal admin.email, 'new_user@test.com'
end end
@ -56,7 +56,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_not warden.authenticated?(:user) assert_not warden.authenticated?(:user)
user = User.order(:id).last user = UserAdapter.find_first(order: [:id, :desc])
assert_equal user.email, 'new_user@test.com' assert_equal user.email, 'new_user@test.com'
assert_not user.confirmed? assert_not user.confirmed?
end end
@ -103,7 +103,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_contain Devise.rails4? ? assert_contain Devise.rails4? ?
"Password confirmation doesn't match Password" : "Password doesn't match confirmation" "Password confirmation doesn't match Password" : "Password doesn't match confirmation"
assert_contain "2 errors prohibited" assert_contain "2 errors prohibited"
assert_nil User.first assert_nil UserAdapter.find_first
assert_not warden.authenticated?(:user) assert_not warden.authenticated?(:user)
end end
@ -151,7 +151,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_current_url '/' assert_current_url '/'
assert_contain 'Your account has been updated successfully.' assert_contain 'Your account has been updated successfully.'
assert_equal "user.new@example.com", User.first.email assert_equal "user.new@example.com", UserAdapter.find_first.email
end end
test 'a signed in user should still be able to use the website after changing their password' do test 'a signed in user should still be able to use the website after changing their password' do
@ -180,7 +180,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_contain 'user@test.com' assert_contain 'user@test.com'
assert_have_selector 'form input[value="user.new@example.com"]' assert_have_selector 'form input[value="user.new@example.com"]'
assert_equal "user@test.com", User.first.email assert_equal "user@test.com", UserAdapter.find_first.email
end end
test 'a signed in user should be able to edit their password' do test 'a signed in user should be able to edit their password' do
@ -195,7 +195,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_current_url '/' assert_current_url '/'
assert_contain 'Your account has been updated successfully.' assert_contain 'Your account has been updated successfully.'
assert User.first.valid_password?('pass1234') assert UserAdapter.find_first.valid_password?('pass1234')
end end
test 'a signed in user should not be able to edit their password with invalid confirmation' do test 'a signed in user should not be able to edit their password with invalid confirmation' do
@ -209,7 +209,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_contain Devise.rails4? ? assert_contain Devise.rails4? ?
"Password confirmation doesn't match Password" : "Password doesn't match confirmation" "Password confirmation doesn't match Password" : "Password doesn't match confirmation"
assert_not User.first.valid_password?('pas123') assert_not UserAdapter.find_first.valid_password?('pas123')
end end
test 'a signed in user should be able to cancel their account' do test 'a signed in user should be able to cancel their account' do
@ -219,7 +219,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
click_button "Cancel my account" click_button "Cancel my account"
assert_contain "Bye! Your account has been successfully cancelled. We hope to see you again soon." assert_contain "Bye! Your account has been successfully cancelled. We hope to see you again soon."
assert User.all.empty? assert UserAdapter.find_all.empty?
end end
test 'a user should be able to cancel sign up by deleting data in the session' do test 'a user should be able to cancel sign up by deleting data in the session' do
@ -253,7 +253,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
admin = Admin.order(:id).last admin = AdminAdapter.find_first(order: [:id, :desc])
assert_equal admin.email, 'new_user@test.com' assert_equal admin.email, 'new_user@test.com'
end end
@ -262,7 +262,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
user = User.order(:id).last user = UserAdapter.find_first(order: [:id, :desc])
assert_equal user.email, 'new_user@test.com' assert_equal user.email, 'new_user@test.com'
end end
@ -290,7 +290,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
sign_in_as_user sign_in_as_user
delete user_registration_path(format: 'xml') delete user_registration_path(format: 'xml')
assert_response :success assert_response :success
assert_equal User.count, 0 assert_equal UserAdapter.find_all.size, 0
end end
end end
@ -305,7 +305,7 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
assert_current_url '/admin_area/home' assert_current_url '/admin_area/home'
assert_contain 'but we need to verify your new email address' assert_contain 'but we need to verify your new email address'
assert_equal 'admin.new@example.com', Admin.first.unconfirmed_email assert_equal 'admin.new@example.com', AdminAdapter.find_first.unconfirmed_email
get edit_admin_registration_path get edit_admin_registration_path
assert_contain 'Currently waiting confirmation for: admin.new@example.com' assert_contain 'Currently waiting confirmation for: admin.new@example.com'
@ -323,7 +323,7 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
assert_current_url '/admin_area/home' assert_current_url '/admin_area/home'
assert_contain 'Your account has been updated successfully.' assert_contain 'Your account has been updated successfully.'
assert Admin.first.valid_password?('pas123') assert AdminAdapter.find_first.valid_password?('pas123')
end end
test 'a signed in admin should not see a reconfirmation message if they did not change their email, despite having an unconfirmed email' do test 'a signed in admin should not see a reconfirmation message if they did not change their email, despite having an unconfirmed email' do
@ -343,7 +343,7 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
assert_current_url '/admin_area/home' assert_current_url '/admin_area/home'
assert_contain 'Your account has been updated successfully.' assert_contain 'Your account has been updated successfully.'
assert_equal "admin.new@example.com", Admin.first.unconfirmed_email assert_equal "admin.new@example.com", AdminAdapter.find_first.unconfirmed_email
assert Admin.first.valid_password?('pas123') assert AdminAdapter.find_first.valid_password?('pas123')
end end
end end

View file

@ -6,7 +6,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end end
def sign_in_facebook def sign_in_facebook
user = User.find_by_email('user@test.com') user = UserAdapter.find_first(email: 'user@test.com')
user.remember_me = true user.remember_me = true
sign_in user sign_in user
render text: "" render text: ""

View file

@ -8,6 +8,9 @@ require "rails_app/config/environment"
require "rails/test_help" require "rails/test_help"
require "orm/#{DEVISE_ORM}" require "orm/#{DEVISE_ORM}"
AdminAdapter = Admin.to_adapter unless Admin.is_a?(OrmAdapter::Base)
UserAdapter = User.to_adapter unless User.is_a?(OrmAdapter::Base)
I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__) I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__)
require 'mocha/setup' require 'mocha/setup'