2015-06-05 14:00:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Profiles::PreferencesController do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
allow(subject).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET show' do
|
|
|
|
it 'renders' do
|
|
|
|
get :show
|
|
|
|
expect(response).to render_template :show
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns user' do
|
|
|
|
get :show
|
|
|
|
expect(assigns[:user]).to eq user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH update' do
|
|
|
|
def go(params: {}, format: :js)
|
|
|
|
params.reverse_merge!(
|
|
|
|
color_scheme_id: '1',
|
2017-09-11 11:44:42 -04:00
|
|
|
dashboard: 'stars',
|
|
|
|
theme_id: '1'
|
2015-06-05 14:00:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
patch :update, user: params, format: format
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on successful update' do
|
|
|
|
it 'sets the flash' do
|
|
|
|
go
|
|
|
|
expect(flash[:notice]).to eq 'Preferences saved.'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "changes the user's preferences" do
|
|
|
|
prefs = {
|
|
|
|
color_scheme_id: '1',
|
2017-09-11 11:44:42 -04:00
|
|
|
dashboard: 'stars',
|
|
|
|
theme_id: '2'
|
2015-06-05 14:00:21 -04:00
|
|
|
}.with_indifferent_access
|
|
|
|
|
2017-06-15 09:24:37 -04:00
|
|
|
expect(user).to receive(:assign_attributes).with(prefs)
|
|
|
|
expect(user).to receive(:save)
|
2015-06-05 14:00:21 -04:00
|
|
|
|
|
|
|
go params: prefs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-10 18:19:06 -04:00
|
|
|
context 'on failed update' do
|
|
|
|
it 'sets the flash' do
|
2017-06-15 09:24:37 -04:00
|
|
|
expect(user).to receive(:save).and_return(false)
|
2015-06-10 18:19:06 -04:00
|
|
|
|
|
|
|
go
|
|
|
|
|
|
|
|
expect(flash[:alert]).to eq('Failed to save preferences.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on invalid dashboard setting' do
|
|
|
|
it 'sets the flash' do
|
2015-06-22 14:41:00 -04:00
|
|
|
prefs = { dashboard: 'invalid' }
|
2015-06-10 18:19:06 -04:00
|
|
|
|
|
|
|
go params: prefs
|
|
|
|
|
|
|
|
expect(flash[:alert]).to match(/\AFailed to save preferences \(.+\)\.\z/)
|
|
|
|
end
|
2015-06-05 14:00:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'as js' do
|
|
|
|
it 'renders' do
|
|
|
|
go
|
|
|
|
expect(response).to render_template :update
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as html' do
|
|
|
|
it 'redirects' do
|
|
|
|
go format: :html
|
|
|
|
expect(response).to redirect_to(profile_preferences_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|