You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe Auth::RegistrationsController, type: :controller do
  3. render_views
  4. describe 'GET #new' do
  5. before do
  6. Setting.open_registrations = true
  7. request.env["devise.mapping"] = Devise.mappings[:user]
  8. end
  9. it 'returns http success' do
  10. get :new
  11. expect(response).to have_http_status(:success)
  12. end
  13. end
  14. describe 'POST #create' do
  15. let(:accept_language) { Rails.application.config.i18n.available_locales.sample.to_s }
  16. before do
  17. Setting.open_registrations = true
  18. request.env["devise.mapping"] = Devise.mappings[:user]
  19. request.headers["Accept-Language"] = accept_language
  20. post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678' } }
  21. end
  22. it 'redirects to login page' do
  23. expect(response).to redirect_to new_user_session_path
  24. end
  25. it 'creates user' do
  26. user = User.find_by(email: 'test@example.com')
  27. expect(user).to_not be_nil
  28. expect(user.locale).to eq(accept_language)
  29. end
  30. end
  31. describe 'DELETE #destroy' do
  32. let(:user) { Fabricate(:user) }
  33. before do
  34. request.env['devise.mapping'] = Devise.mappings[:user]
  35. sign_in(user, scope: :user)
  36. delete :destroy
  37. end
  38. it 'returns http not found' do
  39. expect(response).to have_http_status(:not_found)
  40. end
  41. it 'does not delete user' do
  42. expect(User.find(user.id)).to_not be_nil
  43. end
  44. end
  45. end