confirmations_controller_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
  3. let(:confirmed_at) { nil }
  4. let(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
  5. let(:app) { Fabricate(:application) }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes, application: app) }
  7. let(:scopes) { 'write' }
  8. describe '#create' do
  9. context 'with an oauth token' do
  10. before do
  11. allow(controller).to receive(:doorkeeper_token) { token }
  12. end
  13. context 'from a random app' do
  14. it 'returns http forbidden' do
  15. post :create
  16. expect(response).to have_http_status(:forbidden)
  17. end
  18. end
  19. context 'from an app that created the account' do
  20. before do
  21. user.update(created_by_application: token.application)
  22. end
  23. context 'when the account is already confirmed' do
  24. let(:confirmed_at) { Time.now.utc }
  25. it 'returns http forbidden' do
  26. post :create
  27. expect(response).to have_http_status(:forbidden)
  28. end
  29. context 'but user changed e-mail and has not confirmed it' do
  30. before do
  31. user.update(email: 'foo@bar.com')
  32. end
  33. it 'returns http success' do
  34. post :create
  35. expect(response).to have_http_status(:success)
  36. end
  37. end
  38. end
  39. context 'when the account is unconfirmed' do
  40. it 'returns http success' do
  41. post :create
  42. expect(response).to have_http_status(:success)
  43. end
  44. end
  45. end
  46. end
  47. context 'without an oauth token' do
  48. it 'returns http unauthorized' do
  49. post :create
  50. expect(response).to have_http_status(:unauthorized)
  51. end
  52. end
  53. end
  54. end