RSpec.describe Symphonia::AccountsController do include ActiveJob::TestHelper routes { Symphonia::Engine.routes } let(:regular_user) { FactoryBot.create(:user) } context 'with logged', logged: true do describe '#update' do it 'valid' do put :update, params: { user: { login: Faker::Internet.user_name } } expect(response).to redirect_to account_path end it 'invalid' do put :update, params: { user: { login: '' } } expect(response).to have_http_status :success end end end describe '#resend_activation' do let(:email) { Faker::Internet.email } subject { get :resend_activation, params: { email: email } } it 'non exist user' do is_expected.to redirect_to :login expect(flash[:error]).not_to be :blank end it 'active user' do _user = FactoryBot.create(:user, email: email, status: 'active') is_expected.to redirect_to :login expect(flash[:error]).not_to be :blank end let(:pending_user) { FactoryBot.create(:user, email: email, status: 'pending') } it 'pending user' do token = pending_user.perishable_token.dup expect { get :resend_activation, params: { email: email } }.to have_enqueued_job.on_queue('mailers') expect { pending_user.reload }.to change(pending_user, :perishable_token) expect(flash[:error]).to be_nil expect(flash[:notice]).not_to be :blank end end describe '#activation' do subject { get :activation, params: { activation_code: token } } let(:token) { SecureRandom.hex(3) } let(:pending_user) { FactoryBot.create(:user, status: 'pending') } it 'valid token' do pending_user.update_columns(perishable_token: token) is_expected.to redirect_to :login expect { pending_user.reload }.to change(pending_user, :status).to "active" end it 'invalid token' do is_expected.to redirect_to :login expect(flash[:error]).not_to be :blank end end describe '#lost_password' do it 'with mail' do user = FactoryBot.create(:user, status: 'active') expect { post :lost_password, params: { email: user.email } }.to have_enqueued_job.on_queue('mailers') expect(flash[:error]).to be_nil end it 'with inactive user' do user = FactoryBot.create(:user, status: 'pending') expect { post :lost_password, params: { email: user.email } }.not_to have_enqueued_job.on_queue('mailers') expect(flash[:error]).not_to be :blank end end describe "#reset_password" do subject { FactoryBot.create :user } it "reset" do put :reset_password, params: { id: subject.perishable_token, password: "secret-pass-1" } expect(response).to redirect_to /login/ expect { subject.reload }.to change(subject, :crypted_password) end end end