diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-06-05 14:00:21 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-06-13 17:58:15 -0400 |
commit | 821fc4b03479a193b055c91b8a655d226bc46c17 (patch) | |
tree | a768f6c4cdd039261194bbc36a40b31e61c9934f | |
parent | 0b3c97422136683357cdb4433a5ef0aa8858c18d (diff) | |
download | gitlab-ce-821fc4b03479a193b055c91b8a655d226bc46c17.tar.gz |
Add Profiles::PreferencesController
-rw-r--r-- | app/controllers/profiles/preferences_controller.rb | 29 | ||||
-rw-r--r-- | app/views/layouts/nav/_profile.html.haml | 7 | ||||
-rw-r--r-- | app/views/profiles/preferences/show.html.haml | 1 | ||||
-rw-r--r-- | app/views/profiles/preferences/update.js.erb | 1 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | features/profile/active_tab.feature | 6 | ||||
-rw-r--r-- | features/steps/profile/active_tab.rb | 4 | ||||
-rw-r--r-- | features/steps/shared/paths.rb | 4 | ||||
-rw-r--r-- | spec/controllers/profiles/preferences_controller_spec.rb | 70 | ||||
-rw-r--r-- | spec/features/security/profile_access_spec.rb | 4 | ||||
-rw-r--r-- | spec/routing/routing_spec.rb | 15 |
11 files changed, 127 insertions, 15 deletions
diff --git a/app/controllers/profiles/preferences_controller.rb b/app/controllers/profiles/preferences_controller.rb new file mode 100644 index 00000000000..897e6fe074d --- /dev/null +++ b/app/controllers/profiles/preferences_controller.rb @@ -0,0 +1,29 @@ +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 diff --git a/app/views/layouts/nav/_profile.html.haml b/app/views/layouts/nav/_profile.html.haml index ac37fd4c1c1..121665bd536 100644 --- a/app/views/layouts/nav/_profile.html.haml +++ b/app/views/layouts/nav/_profile.html.haml @@ -38,11 +38,12 @@ %span SSH Keys %span.count= current_user.keys.count - = nav_link(path: 'profiles#design') do - = link_to design_profile_path, title: 'Design', data: {placement: 'right'} do + = nav_link(controller: :preferences) do + = link_to profile_preferences_path, title: 'Preferences', data: {placement: 'right'} do + -# TODO (rspeicher): Better icon? = icon('image fw') %span - Design + Preferences = nav_link(path: 'profiles#history') do = link_to history_profile_path, title: 'History', data: {placement: 'right'} do = icon('history fw') diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml new file mode 100644 index 00000000000..1333ed77b7e --- /dev/null +++ b/app/views/profiles/preferences/show.html.haml @@ -0,0 +1 @@ +TODO diff --git a/app/views/profiles/preferences/update.js.erb b/app/views/profiles/preferences/update.js.erb new file mode 100644 index 00000000000..70b786d12ed --- /dev/null +++ b/app/views/profiles/preferences/update.js.erb @@ -0,0 +1 @@ +// TODO diff --git a/config/routes.rb b/config/routes.rb index f4a104664f3..9b1a746f548 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -222,6 +222,7 @@ Gitlab::Application.routes.draw do put :reset end end + resource :preferences, only: [:show, :update] resources :keys resources :emails, only: [:index, :create, :destroy] resource :avatar, only: [:destroy] diff --git a/features/profile/active_tab.feature b/features/profile/active_tab.feature index 7801ae5b8ca..1fa4ac88ddc 100644 --- a/features/profile/active_tab.feature +++ b/features/profile/active_tab.feature @@ -18,9 +18,9 @@ Feature: Profile Active Tab Then the active main tab should be SSH Keys And no other main tabs should be active - Scenario: On Profile Design - Given I visit profile design page - Then the active main tab should be Design + Scenario: On Profile Preferences + Given I visit profile preferences page + Then the active main tab should be Preferences And no other main tabs should be active Scenario: On Profile History diff --git a/features/steps/profile/active_tab.rb b/features/steps/profile/active_tab.rb index 8595ee876a4..79e3b55f6e1 100644 --- a/features/steps/profile/active_tab.rb +++ b/features/steps/profile/active_tab.rb @@ -15,8 +15,8 @@ class Spinach::Features::ProfileActiveTab < Spinach::FeatureSteps ensure_active_main_tab('SSH Keys') end - step 'the active main tab should be Design' do - ensure_active_main_tab('Design') + step 'the active main tab should be Preferences' do + ensure_active_main_tab('Preferences') end step 'the active main tab should be History' do diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb index 09ae7e3a305..3bd0d60281c 100644 --- a/features/steps/shared/paths.rb +++ b/features/steps/shared/paths.rb @@ -123,8 +123,8 @@ module SharedPaths visit profile_keys_path end - step 'I visit profile design page' do - visit design_profile_path + step 'I visit profile preferences page' do + visit profile_preferences_path end step 'I visit profile history page' do diff --git a/spec/controllers/profiles/preferences_controller_spec.rb b/spec/controllers/profiles/preferences_controller_spec.rb new file mode 100644 index 00000000000..87503b1ed4d --- /dev/null +++ b/spec/controllers/profiles/preferences_controller_spec.rb @@ -0,0 +1,70 @@ +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 diff --git a/spec/features/security/profile_access_spec.rb b/spec/features/security/profile_access_spec.rb index 2512a9c0e3d..2b09771851e 100644 --- a/spec/features/security/profile_access_spec.rb +++ b/spec/features/security/profile_access_spec.rb @@ -36,8 +36,8 @@ describe "Profile access", feature: true do it { is_expected.to be_denied_for :visitor } end - describe "GET /profile/design" do - subject { design_profile_path } + describe "GET /profile/preferences" do + subject { profile_preferences_path } it { is_expected.to be_allowed_for @u1 } it { is_expected.to be_allowed_for :admin } diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index 953c8dd8ddc..199851be482 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -102,7 +102,6 @@ end # profile_token GET /profile/token(.:format) profile#token # profile_reset_private_token PUT /profile/reset_private_token(.:format) profile#reset_private_token # profile GET /profile(.:format) profile#show -# profile_design GET /profile/design(.:format) profile#design # profile_update PUT /profile/update(.:format) profile#update describe ProfilesController, "routing" do it "to #account" do @@ -120,9 +119,19 @@ describe ProfilesController, "routing" do it "to #show" do expect(get("/profile")).to route_to('profiles#show') 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 - expect(get("/profile/design")).to route_to('profiles#design') + it 'to #update' do + expect(put('/profile/preferences')).to route_to('profiles/preferences#update') + expect(patch('/profile/preferences')).to route_to('profiles/preferences#update') end end |