From 07ff874f572a947d7730787492a604dd3f44d496 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 29 Apr 2016 18:06:22 -0300 Subject: Let users set notification levels in projects which they are not members --- .../notification_settings_controller_spec.rb | 14 +++++++++ spec/controllers/projects_controller_spec.rb | 35 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/notification_settings_controller_spec.rb b/spec/controllers/projects/notification_settings_controller_spec.rb index 4908b545648..c5d17d97ec9 100644 --- a/spec/controllers/projects/notification_settings_controller_spec.rb +++ b/spec/controllers/projects/notification_settings_controller_spec.rb @@ -34,5 +34,19 @@ describe Projects::NotificationSettingsController do expect(response.status).to eq 200 end end + + context 'not authorized' do + let(:private_project) { create(:project, :private) } + before { sign_in(user) } + + it 'returns 404' do + put :update, + namespace_id: private_project.namespace.to_param, + project_id: private_project.to_param, + notification_setting: { level: :participating } + + expect(response.status).to eq(404) + end + end end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 069cd917e5a..685fe9ffe0b 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -8,10 +8,43 @@ describe ProjectsController do let(:txt) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') } describe "GET show" do + context "user not project member" do + before { sign_in(user) } + + context "user does not have access to project" do + let(:private_project) { create(:project, :private) } + + it "does not initialize notification setting" do + get :show, namespace_id: private_project.namespace.path, id: private_project.path + expect(assigns(:notification_setting)).to be_nil + end + end + + context "user has access to project" do + context "and does not have notification setting" do + it "initializes notification as disabled" do + get :show, namespace_id: public_project.namespace.path, id: public_project.path + expect(assigns(:notification_setting).level).to eq("disabled") + end + end + + context "and has notification setting" do + before do + setting = user.notification_settings_for(public_project) + setting.level = :global + setting.save + end + + it "shows current notification setting" do + get :show, namespace_id: public_project.namespace.path, id: public_project.path + expect(assigns(:notification_setting).level).to eq("global") + end + end + end + end context "rendering default project view" do render_views - it "renders the activity view" do allow(controller).to receive(:current_user).and_return(user) allow(user).to receive(:project_view).and_return('activity') -- cgit v1.2.1 From 6fb9bf87c4f202dee9815c10cad9486a1077cc99 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 19 May 2016 19:20:06 -0400 Subject: Use the right default notification settings for non members --- spec/controllers/projects_controller_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 685fe9ffe0b..91b46c4d65c 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -24,20 +24,20 @@ describe ProjectsController do context "and does not have notification setting" do it "initializes notification as disabled" do get :show, namespace_id: public_project.namespace.path, id: public_project.path - expect(assigns(:notification_setting).level).to eq("disabled") + expect(assigns(:notification_setting).level).to eq("global") end end context "and has notification setting" do before do setting = user.notification_settings_for(public_project) - setting.level = :global + setting.level = :watch setting.save end it "shows current notification setting" do get :show, namespace_id: public_project.namespace.path, id: public_project.path - expect(assigns(:notification_setting).level).to eq("global") + expect(assigns(:notification_setting).level).to eq("watch") end end end @@ -45,6 +45,7 @@ describe ProjectsController do context "rendering default project view" do render_views + it "renders the activity view" do allow(controller).to receive(:current_user).and_return(user) allow(user).to receive(:project_view).and_return('activity') -- cgit v1.2.1 From 3ba72f69af69d9fb2c46cb6c25d571f92ffd2ee1 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 23 May 2016 14:16:35 -0400 Subject: Enable Style/SpaceAroundKeyword cop and fix offenses --- spec/controllers/projects/group_links_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb index 40bd83af861..1bd1fc5189e 100644 --- a/spec/controllers/projects/group_links_controller_spec.rb +++ b/spec/controllers/projects/group_links_controller_spec.rb @@ -28,7 +28,7 @@ describe Projects::GroupLinksController do expect(group.shared_projects).to include project end - it 'redirects to project group links page'do + it 'redirects to project group links page' do expect(response).to redirect_to( namespace_project_group_links_path(project.namespace, project) ) -- cgit v1.2.1