mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
86 lines
2 KiB
Ruby
86 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'Settings', type: :request do
|
|
describe 'GET /theme' do
|
|
let(:params) { { theme: 'light' } }
|
|
|
|
context 'when user is not signed in' do
|
|
it 'redirects to the sign in page' do
|
|
get '/settings/theme', params: params
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
end
|
|
end
|
|
|
|
context 'when user is signed in' do
|
|
let(:user) { create(:user) }
|
|
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it 'updates the user theme' do
|
|
get '/settings/theme', params: params
|
|
expect(user.reload.theme).to eq('light')
|
|
end
|
|
|
|
it 'redirects to the root path' do
|
|
get '/settings/theme', params: params
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
|
|
context 'when theme is dark' do
|
|
let(:params) { { theme: 'dark' } }
|
|
|
|
it 'updates the user theme' do
|
|
get '/settings/theme', params: params
|
|
expect(user.reload.theme).to eq('dark')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'POST /generate_api_key' do
|
|
context 'when user is not signed in' do
|
|
it 'redirects to the sign in page' do
|
|
post '/settings/generate_api_key'
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
end
|
|
end
|
|
|
|
context 'when user is signed in' do
|
|
let(:user) { create(:user) }
|
|
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it 'generates an API key for the user' do
|
|
expect { post '/settings/generate_api_key' }.to change { user.reload.api_key }
|
|
end
|
|
|
|
it 'redirects back' do
|
|
post '/settings/generate_api_key'
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'PATCH /settings' do
|
|
let(:user) { create(:user) }
|
|
let(:params) { { settings: { 'meters_between_routes' => '1000', 'minutes_between_routes' => '10' } } }
|
|
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it 'updates the user settings' do
|
|
patch '/settings', params: params
|
|
|
|
expect(user.reload.settings).to eq(params[:settings])
|
|
end
|
|
end
|
|
end
|