summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-05 14:00:21 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-06-13 17:58:15 -0400
commit821fc4b03479a193b055c91b8a655d226bc46c17 (patch)
treea768f6c4cdd039261194bbc36a40b31e61c9934f /spec
parent0b3c97422136683357cdb4433a5ef0aa8858c18d (diff)
downloadgitlab-ce-821fc4b03479a193b055c91b8a655d226bc46c17.tar.gz
Add Profiles::PreferencesController
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/profiles/preferences_controller_spec.rb70
-rw-r--r--spec/features/security/profile_access_spec.rb4
-rw-r--r--spec/routing/routing_spec.rb15
3 files changed, 84 insertions, 5 deletions
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