Commit 471ea73a authored by Robert Speicher's avatar Robert Speicher

Add Profiles::PreferencesController

cherry-picked
parent 41aead60
class Profiles::PreferencesController < Profiles::ApplicationController
before_action :user
def show
end
def update
if @user.update_attributes(preferences_params)
flash[:notice] = 'Preferences saved.'
else
# TODO (rspeicher): There's no validation on these values, so can it fail?
end
respond_to do |format|
format.html { redirect_to profile_preferences_path }
format.js
end
end
private
def user
@user = current_user
end
def preferences_params
params.require(:user).permit(:color_scheme_id, :theme_id)
end
end
...@@ -38,11 +38,12 @@ ...@@ -38,11 +38,12 @@
%span %span
SSH Keys SSH Keys
%span.count= current_user.keys.count %span.count= current_user.keys.count
= nav_link(path: 'profiles#design') do = nav_link(controller: :preferences) do
= link_to design_profile_path, title: 'Design', data: {placement: 'right'} do = link_to profile_preferences_path, title: 'Preferences', data: {placement: 'right'} do
-# TODO (rspeicher): Better icon?
= icon('image fw') = icon('image fw')
%span %span
Design Preferences
= nav_link(path: 'profiles#history') do = nav_link(path: 'profiles#history') do
= link_to history_profile_path, title: 'History', data: {placement: 'right'} do = link_to history_profile_path, title: 'History', data: {placement: 'right'} do
= icon('history fw') = icon('history fw')
......
...@@ -222,6 +222,7 @@ Gitlab::Application.routes.draw do ...@@ -222,6 +222,7 @@ Gitlab::Application.routes.draw do
put :reset put :reset
end end
end end
resource :preferences, only: [:show, :update]
resources :keys resources :keys
resources :emails, only: [:index, :create, :destroy] resources :emails, only: [:index, :create, :destroy]
resource :avatar, only: [:destroy] resource :avatar, only: [:destroy]
......
...@@ -18,9 +18,9 @@ Feature: Profile Active Tab ...@@ -18,9 +18,9 @@ Feature: Profile Active Tab
Then the active main tab should be SSH Keys Then the active main tab should be SSH Keys
And no other main tabs should be active And no other main tabs should be active
Scenario: On Profile Design Scenario: On Profile Preferences
Given I visit profile design page Given I visit profile preferences page
Then the active main tab should be Design Then the active main tab should be Preferences
And no other main tabs should be active And no other main tabs should be active
Scenario: On Profile History Scenario: On Profile History
......
...@@ -15,8 +15,8 @@ class Spinach::Features::ProfileActiveTab < Spinach::FeatureSteps ...@@ -15,8 +15,8 @@ class Spinach::Features::ProfileActiveTab < Spinach::FeatureSteps
ensure_active_main_tab('SSH Keys') ensure_active_main_tab('SSH Keys')
end end
step 'the active main tab should be Design' do step 'the active main tab should be Preferences' do
ensure_active_main_tab('Design') ensure_active_main_tab('Preferences')
end end
step 'the active main tab should be History' do step 'the active main tab should be History' do
......
...@@ -123,8 +123,8 @@ module SharedPaths ...@@ -123,8 +123,8 @@ module SharedPaths
visit profile_keys_path visit profile_keys_path
end end
step 'I visit profile design page' do step 'I visit profile preferences page' do
visit design_profile_path visit profile_preferences_path
end end
step 'I visit profile history page' do step 'I visit profile history page' do
......
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',
theme_id: '1'
)
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',
theme_id: '2'
}.with_indifferent_access
expect(user).to receive(:update_attributes).with(prefs)
go params: prefs
end
end
context 'on unsuccessful update' do
# TODO (rspeicher): Can this happen?
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
...@@ -36,8 +36,8 @@ describe "Profile access", feature: true do ...@@ -36,8 +36,8 @@ describe "Profile access", feature: true do
it { is_expected.to be_denied_for :visitor } it { is_expected.to be_denied_for :visitor }
end end
describe "GET /profile/design" do describe "GET /profile/preferences" do
subject { design_profile_path } subject { profile_preferences_path }
it { is_expected.to be_allowed_for @u1 } it { is_expected.to be_allowed_for @u1 }
it { is_expected.to be_allowed_for :admin } it { is_expected.to be_allowed_for :admin }
......
...@@ -102,7 +102,6 @@ end ...@@ -102,7 +102,6 @@ end
# profile_token GET /profile/token(.:format) profile#token # profile_token GET /profile/token(.:format) profile#token
# profile_reset_private_token PUT /profile/reset_private_token(.:format) profile#reset_private_token # profile_reset_private_token PUT /profile/reset_private_token(.:format) profile#reset_private_token
# profile GET /profile(.:format) profile#show # profile GET /profile(.:format) profile#show
# profile_design GET /profile/design(.:format) profile#design
# profile_update PUT /profile/update(.:format) profile#update # profile_update PUT /profile/update(.:format) profile#update
describe ProfilesController, "routing" do describe ProfilesController, "routing" do
it "to #account" do it "to #account" do
...@@ -120,9 +119,19 @@ describe ProfilesController, "routing" do ...@@ -120,9 +119,19 @@ describe ProfilesController, "routing" do
it "to #show" do it "to #show" do
expect(get("/profile")).to route_to('profiles#show') expect(get("/profile")).to route_to('profiles#show')
end end
end
# profile_preferences GET /profile/preferences(.:format) profiles/preferences#show
# PATCH /profile/preferences(.:format) profiles/preferences#update
# PUT /profile/preferences(.:format) profiles/preferences#update
describe Profiles::PreferencesController, 'routing' do
it 'to #show' do
expect(get('/profile/preferences')).to route_to('profiles/preferences#show')
end
it "to #design" do it 'to #update' do
expect(get("/profile/design")).to route_to('profiles#design') expect(put('/profile/preferences')).to route_to('profiles/preferences#update')
expect(patch('/profile/preferences')).to route_to('profiles/preferences#update')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment