describe Symphonia::AccountsController do before(:each) do Symphonia.config[:allow_registrations] = true end context '#register' do it 'GET' do get '/register' expect(response).to have_http_status :success end context 'POST' do it 'pending' do expect { post '/register', params: { user: FactoryBot.attributes_for(:user) } }.to change(Symphonia::User, :count).by 1 expect(response).to have_http_status :redirect expect(Symphonia::User.last.status).to eq 'pending' end it 'self activation' do Symphonia.config[:self_activation_enabled] = true expect { post '/register', params: { user: FactoryBot.attributes_for(:user) } }.to change(Symphonia::User, :count).by 1 expect(response).to have_http_status :redirect expect(Symphonia::User.last.status).to eq 'active' end it 'invalid' do expect { post '/register', params: { user: { login: Faker::Internet.user_name } } }.to change(Symphonia::User, :count).by 0 expect(response).to have_http_status :success end end end context 'pending' do let(:pending_user) { FactoryBot.create(:user, status: 'pending', password: 'heslo123', password_confirmation: 'heslo123')} it '#login' do post symphonia.user_sessions_path, params: { login_session: { login: pending_user.login, password: 'heslo123' }} expect(response).to have_http_status :success expect(Symphonia::User.current.id).not_to eq pending_user.id end end context 'with user', logged: true do it '#new_activation' do get symphonia.new_activation_account_path expect(response).to have_http_status :success end end context '#lost_password' do it 'js' do get symphonia.lost_password_account_path, xhr: true expect(response).to have_http_status :success end it 'html' do get symphonia.lost_password_account_path expect(response).to have_http_status :success end end context '#reset_password' do let(:token) { SecureRandom.hex(3) } let(:password) { SecureRandom.hex(8) } let(:user) { FactoryBot.create(:user, status: 'active') } context 'GET' do it 'valid token' do user.update_columns(perishable_token: token) get symphonia.reset_password_path(id: token) expect(response).to have_http_status :success end it 'invalid token' do user get symphonia.reset_password_path(id: token) expect(response).to have_http_status :not_found end end context 'PUT' do before { FactoryBot.create(:user, status: 'active'); user.update_columns(perishable_token: token) } it 'valid token' do put symphonia.reset_password_account_path(id: token, password: password, password_confirmation: password ) expect(response).to redirect_to symphonia.user_current_path expect(flash[:notice]).not_to be :blank end it 'invalid password' do put symphonia.reset_password_account_path(id: token, password: '12', password_confirmation: '11' ) expect(response).to have_http_status :success expect(flash[:notice]).to be_nil end end end context 'form for user', logged: true do let(:regular_user) { FactoryBot.create(:user) } it '/admin/account' do get '/admin/account' expect(response).to have_http_status :success end end end