From 601f50c6421f135b52f737a3b59baa32e6a8f1fd Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 27 Mar 2017 11:22:43 +0200 Subject: Add endpoint that returns a list of deployments that happened within last 8.hours add index created_at --- .../projects/deployments_controller_spec.rb | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 spec/controllers/projects/deployments_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb new file mode 100644 index 00000000000..97a9fb8ae61 --- /dev/null +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe Projects::DeploymentsController do + include ApiHelpers + + let(:user) { create(:user) } + let(:project) { create(:empty_project) } + let(:environment) { create(:environment, name: 'production', project: project) } + let(:deployment) { create(:deployment, project: project, environment: environment) } + + before do + project.team << [user, :master] + + sign_in(user) + end + + describe 'GET #index' do + it 'returns list of deployments withing last 8 hours' do + create(:deployment, environment: environment, created_at: 9.hours.ago) + create(:deployment, environment: environment, created_at: 7.hours.ago) + create(:deployment, environment: environment) + + get :index, environment_params + + expect(response).to be_ok + + expect(json_response['deployments'].count).to eq(2) + end + + it 'returns a list with deployments information' do + deployment = create(:deployment, environment: environment) + + get :index, environment_params + expect(response).to be_ok + + deployments = json_response['deployments'] + deployment_info = deployments.first.with_indifferent_access + created_at = deployment_info.delete(:created_at).to_time.utc + + expect(deployments.count).to eq(1) + expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag) + expect(deployment).to have_attributes(deployment_info) + expect(deployment.created_at).to be_within(1.second).of(created_at) + end + end + + def environment_params(opts={}) + opts.reverse_merge(namespace_id: project.namespace, project_id: project, environment_id: environment.id) + end +end -- cgit v1.2.1 From 73203873438d666427228ffdbfe835ea4ffddaa6 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 28 Mar 2017 12:48:53 +0200 Subject: Use DeploymentSerializer to create deployment json --- spec/controllers/projects/deployments_controller_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb index 97a9fb8ae61..b0d543177cc 100644 --- a/spec/controllers/projects/deployments_controller_spec.rb +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -28,19 +28,16 @@ describe Projects::DeploymentsController do end it 'returns a list with deployments information' do - deployment = create(:deployment, environment: environment) + create(:deployment, environment: environment) get :index, environment_params expect(response).to be_ok deployments = json_response['deployments'] deployment_info = deployments.first.with_indifferent_access - created_at = deployment_info.delete(:created_at).to_time.utc expect(deployments.count).to eq(1) - expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag) - expect(deployment).to have_attributes(deployment_info) - expect(deployment.created_at).to be_within(1.second).of(created_at) + expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag, :created_at) end end -- cgit v1.2.1 From d3e794e26f806fe491269a74e76c39669433c0fe Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 28 Mar 2017 14:56:30 +0200 Subject: Optionally filter by deployment time --- spec/controllers/projects/deployments_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb index b0d543177cc..7b7f16e14da 100644 --- a/spec/controllers/projects/deployments_controller_spec.rb +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -20,7 +20,7 @@ describe Projects::DeploymentsController do create(:deployment, environment: environment, created_at: 7.hours.ago) create(:deployment, environment: environment) - get :index, environment_params + get :index, environment_params(:after => 8.hours.ago) expect(response).to be_ok -- cgit v1.2.1 From 5e2219db48719af5ca971f9222fffa7bd66cb6d8 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 28 Mar 2017 15:54:02 +0200 Subject: Fix unreversible migration, and small rubocop warnings --- spec/controllers/projects/deployments_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb index 7b7f16e14da..fbe510fb539 100644 --- a/spec/controllers/projects/deployments_controller_spec.rb +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -20,7 +20,7 @@ describe Projects::DeploymentsController do create(:deployment, environment: environment, created_at: 7.hours.ago) create(:deployment, environment: environment) - get :index, environment_params(:after => 8.hours.ago) + get :index, environment_params(after: 8.hours.ago) expect(response).to be_ok @@ -41,7 +41,7 @@ describe Projects::DeploymentsController do end end - def environment_params(opts={}) + def environment_params(opts = {}) opts.reverse_merge(namespace_id: project.namespace, project_id: project, environment_id: environment.id) end end -- cgit v1.2.1 From 5bf0441fd9cda2dcc3c3ef1ce3084df5ed87602d Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 24 Apr 2017 19:55:07 +0200 Subject: Cleanup deploymentsd controller spec and use schema validation to test the output --- spec/controllers/projects/deployments_controller_spec.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb index fbe510fb539..89692b601b2 100644 --- a/spec/controllers/projects/deployments_controller_spec.rb +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -6,16 +6,15 @@ describe Projects::DeploymentsController do let(:user) { create(:user) } let(:project) { create(:empty_project) } let(:environment) { create(:environment, name: 'production', project: project) } - let(:deployment) { create(:deployment, project: project, environment: environment) } before do - project.team << [user, :master] + project.add_master(user) sign_in(user) end describe 'GET #index' do - it 'returns list of deployments withing last 8 hours' do + it 'returns list of deployments from last 8 hours' do create(:deployment, environment: environment, created_at: 9.hours.ago) create(:deployment, environment: environment, created_at: 7.hours.ago) create(:deployment, environment: environment) @@ -31,13 +30,9 @@ describe Projects::DeploymentsController do create(:deployment, environment: environment) get :index, environment_params - expect(response).to be_ok - - deployments = json_response['deployments'] - deployment_info = deployments.first.with_indifferent_access - expect(deployments.count).to eq(1) - expect(deployment_info).to include(:id, :iid, :sha, :ref, :tag, :created_at) + expect(response).to be_ok + expect(response).to match_response_schema('deployments') end end -- cgit v1.2.1 From 480fcb5533e59151a6e9ae11baef59ebab64cc6c Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 26 Apr 2017 11:32:21 +0100 Subject: Added controller specs --- spec/controllers/groups/milestones_controller_spec.rb | 12 ++++++++++++ spec/controllers/projects/milestones_controller_spec.rb | 5 +++++ 2 files changed, 17 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index 6e4b5f78e33..7cf2996ffd0 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -6,6 +6,16 @@ describe Groups::MilestonesController do let(:project2) { create(:empty_project, group: group) } let(:user) { create(:user) } let(:title) { '肯定不是中文的问题' } + let(:milestone) do + project_milestone = create(:milestone, project: project) + + GroupMilestone.build( + group, + [project], + project_milestone.title + ) + end + let(:milestone_path) { group_milestone_path(group, milestone.safe_title, title: milestone.title) } before do sign_in(user) @@ -14,6 +24,8 @@ describe Groups::MilestonesController do controller.instance_variable_set(:@group, group) end + it_behaves_like 'milestone tabs' + describe "#create" do it "creates group milestone with Chinese title" do post :create, diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index 47e61c3cea8..6f500468f95 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -7,6 +7,7 @@ describe Projects::MilestonesController do let(:issue) { create(:issue, project: project, milestone: milestone) } let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) } + let(:milestone_path) { namespace_project_milestone_path } before do sign_in(user) @@ -14,6 +15,8 @@ describe Projects::MilestonesController do controller.instance_variable_set(:@project, project) end + it_behaves_like 'milestone tabs' + describe "#show" do render_views @@ -49,4 +52,6 @@ describe Projects::MilestonesController do expect(last_note).to eq('removed milestone') end end + + end -- cgit v1.2.1 From 4b812d979eafa244c9e6b014448bf09bf1b458fd Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 26 Apr 2017 12:22:09 +0100 Subject: Fixed failing specs --- spec/controllers/projects/milestones_controller_spec.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index 6f500468f95..84a61b2784e 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -52,6 +52,4 @@ describe Projects::MilestonesController do expect(last_note).to eq('removed milestone') end end - - end -- cgit v1.2.1 From 5069682d8ed892705ec1a933554cc4060e5691af Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 25 Apr 2017 13:28:55 +0100 Subject: Enable RSpec/FilePath cop - Ignore JS fixtures - Ignore qa directory - Rewrite concern specs to put concern name first --- spec/controllers/blob_controller_spec.rb | 67 ---------- .../personal_access_tokens_controller_spec.rb | 56 ++++++++ .../profiles/personal_access_tokens_spec.rb | 56 -------- spec/controllers/projects/blob_controller_spec.rb | 51 ++++++++ spec/controllers/projects/todo_controller_spec.rb | 144 --------------------- spec/controllers/projects/todos_controller_spec.rb | 144 +++++++++++++++++++++ 6 files changed, 251 insertions(+), 267 deletions(-) delete mode 100644 spec/controllers/blob_controller_spec.rb create mode 100644 spec/controllers/profiles/personal_access_tokens_controller_spec.rb delete mode 100644 spec/controllers/profiles/personal_access_tokens_spec.rb delete mode 100644 spec/controllers/projects/todo_controller_spec.rb create mode 100644 spec/controllers/projects/todos_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/blob_controller_spec.rb b/spec/controllers/blob_controller_spec.rb deleted file mode 100644 index 44e011fd3a8..00000000000 --- a/spec/controllers/blob_controller_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'spec_helper' - -describe Projects::BlobController do - let(:project) { create(:project, :repository) } - let(:user) { create(:user) } - - before do - sign_in(user) - - project.team << [user, :master] - - allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz']) - allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0']) - controller.instance_variable_set(:@project, project) - end - - describe "GET show" do - render_views - - before do - get(:show, - namespace_id: project.namespace, - project_id: project, - id: id) - end - - context "valid branch, valid file" do - let(:id) { 'master/README.md' } - it { is_expected.to respond_with(:success) } - end - - context "valid branch, invalid file" do - let(:id) { 'master/invalid-path.rb' } - it { is_expected.to respond_with(:not_found) } - end - - context "invalid branch, valid file" do - let(:id) { 'invalid-branch/README.md' } - it { is_expected.to respond_with(:not_found) } - end - - context "binary file" do - let(:id) { 'binary-encoding/encoding/binary-1.bin' } - it { is_expected.to respond_with(:success) } - end - end - - describe 'GET show with tree path' do - render_views - - before do - get(:show, - namespace_id: project.namespace, - project_id: project, - id: id) - controller.instance_variable_set(:@blob, nil) - end - - context 'redirect to tree' do - let(:id) { 'markdown/doc' } - it 'redirects' do - expect(subject). - to redirect_to("/#{project.path_with_namespace}/tree/markdown/doc") - end - end - end -end diff --git a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb new file mode 100644 index 00000000000..98a43e278b2 --- /dev/null +++ b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Profiles::PersonalAccessTokensController do + let(:user) { create(:user) } + let(:token_attributes) { attributes_for(:personal_access_token) } + + before { sign_in(user) } + + describe '#create' do + def created_token + PersonalAccessToken.order(:created_at).last + end + + it "allows creation of a token with scopes" do + name = 'My PAT' + scopes = %w[api read_user] + + post :create, personal_access_token: token_attributes.merge(scopes: scopes, name: name) + + expect(created_token).not_to be_nil + expect(created_token.name).to eq(name) + expect(created_token.scopes).to eq(scopes) + expect(PersonalAccessToken.active).to include(created_token) + end + + it "allows creation of a token with an expiry date" do + expires_at = 5.days.from_now.to_date + + post :create, personal_access_token: token_attributes.merge(expires_at: expires_at) + + expect(created_token).not_to be_nil + expect(created_token.expires_at).to eq(expires_at) + end + end + + describe '#index' do + let!(:active_personal_access_token) { create(:personal_access_token, user: user) } + let!(:inactive_personal_access_token) { create(:personal_access_token, :revoked, user: user) } + let!(:impersonation_personal_access_token) { create(:personal_access_token, :impersonation, user: user) } + + before { get :index } + + it "retrieves active personal access tokens" do + expect(assigns(:active_personal_access_tokens)).to include(active_personal_access_token) + end + + it "retrieves inactive personal access tokens" do + expect(assigns(:inactive_personal_access_tokens)).to include(inactive_personal_access_token) + end + + it "does not retrieve impersonation personal access tokens" do + expect(assigns(:active_personal_access_tokens)).not_to include(impersonation_personal_access_token) + expect(assigns(:inactive_personal_access_tokens)).not_to include(impersonation_personal_access_token) + end + end +end diff --git a/spec/controllers/profiles/personal_access_tokens_spec.rb b/spec/controllers/profiles/personal_access_tokens_spec.rb deleted file mode 100644 index 98a43e278b2..00000000000 --- a/spec/controllers/profiles/personal_access_tokens_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'spec_helper' - -describe Profiles::PersonalAccessTokensController do - let(:user) { create(:user) } - let(:token_attributes) { attributes_for(:personal_access_token) } - - before { sign_in(user) } - - describe '#create' do - def created_token - PersonalAccessToken.order(:created_at).last - end - - it "allows creation of a token with scopes" do - name = 'My PAT' - scopes = %w[api read_user] - - post :create, personal_access_token: token_attributes.merge(scopes: scopes, name: name) - - expect(created_token).not_to be_nil - expect(created_token.name).to eq(name) - expect(created_token.scopes).to eq(scopes) - expect(PersonalAccessToken.active).to include(created_token) - end - - it "allows creation of a token with an expiry date" do - expires_at = 5.days.from_now.to_date - - post :create, personal_access_token: token_attributes.merge(expires_at: expires_at) - - expect(created_token).not_to be_nil - expect(created_token.expires_at).to eq(expires_at) - end - end - - describe '#index' do - let!(:active_personal_access_token) { create(:personal_access_token, user: user) } - let!(:inactive_personal_access_token) { create(:personal_access_token, :revoked, user: user) } - let!(:impersonation_personal_access_token) { create(:personal_access_token, :impersonation, user: user) } - - before { get :index } - - it "retrieves active personal access tokens" do - expect(assigns(:active_personal_access_tokens)).to include(active_personal_access_token) - end - - it "retrieves inactive personal access tokens" do - expect(assigns(:inactive_personal_access_tokens)).to include(inactive_personal_access_token) - end - - it "does not retrieve impersonation personal access tokens" do - expect(assigns(:active_personal_access_tokens)).not_to include(impersonation_personal_access_token) - expect(assigns(:inactive_personal_access_tokens)).not_to include(impersonation_personal_access_token) - end - end -end diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 0fd09d156c4..3b3caa9d3e6 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -3,6 +3,57 @@ require 'rails_helper' describe Projects::BlobController do let(:project) { create(:project, :public, :repository) } + describe "GET show" do + render_views + + context 'with file path' do + before do + get(:show, + namespace_id: project.namespace, + project_id: project, + id: id) + end + + context "valid branch, valid file" do + let(:id) { 'master/README.md' } + it { is_expected.to respond_with(:success) } + end + + context "valid branch, invalid file" do + let(:id) { 'master/invalid-path.rb' } + it { is_expected.to respond_with(:not_found) } + end + + context "invalid branch, valid file" do + let(:id) { 'invalid-branch/README.md' } + it { is_expected.to respond_with(:not_found) } + end + + context "binary file" do + let(:id) { 'binary-encoding/encoding/binary-1.bin' } + it { is_expected.to respond_with(:success) } + end + end + + context 'with tree path' do + before do + get(:show, + namespace_id: project.namespace, + project_id: project, + id: id) + controller.instance_variable_set(:@blob, nil) + end + + context 'redirect to tree' do + let(:id) { 'markdown/doc' } + it 'redirects' do + expect(subject). + to redirect_to("/#{project.path_with_namespace}/tree/markdown/doc") + end + end + end + end + describe 'GET diff' do let(:user) { create(:user) } diff --git a/spec/controllers/projects/todo_controller_spec.rb b/spec/controllers/projects/todo_controller_spec.rb deleted file mode 100644 index c5a4153d991..00000000000 --- a/spec/controllers/projects/todo_controller_spec.rb +++ /dev/null @@ -1,144 +0,0 @@ -require('spec_helper') - -describe Projects::TodosController do - let(:user) { create(:user) } - let(:project) { create(:empty_project) } - let(:issue) { create(:issue, project: project) } - let(:merge_request) { create(:merge_request, source_project: project) } - - context 'Issues' do - describe 'POST create' do - def go - post :create, - namespace_id: project.namespace, - project_id: project, - issuable_id: issue.id, - issuable_type: 'issue', - format: 'html' - end - - context 'when authorized' do - before do - sign_in(user) - project.team << [user, :developer] - end - - it 'creates todo for issue' do - expect do - go - end.to change { user.todos.count }.by(1) - - expect(response).to have_http_status(200) - end - - it 'returns todo path and pending count' do - go - - expect(response).to have_http_status(200) - expect(json_response['count']).to eq 1 - expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/) - end - end - - context 'when not authorized for project' do - it 'does not create todo for issue that user has no access to' do - sign_in(user) - expect do - go - end.to change { user.todos.count }.by(0) - - expect(response).to have_http_status(404) - end - - it 'does not create todo for issue when user not logged in' do - expect do - go - end.to change { user.todos.count }.by(0) - - expect(response).to have_http_status(302) - end - end - - context 'when not authorized for issue' do - before do - project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) - project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE) - sign_in(user) - end - - it "doesn't create todo" do - expect{ go }.not_to change { user.todos.count } - expect(response).to have_http_status(404) - end - end - end - end - - context 'Merge Requests' do - describe 'POST create' do - def go - post :create, - namespace_id: project.namespace, - project_id: project, - issuable_id: merge_request.id, - issuable_type: 'merge_request', - format: 'html' - end - - context 'when authorized' do - before do - sign_in(user) - project.team << [user, :developer] - end - - it 'creates todo for merge request' do - expect do - go - end.to change { user.todos.count }.by(1) - - expect(response).to have_http_status(200) - end - - it 'returns todo path and pending count' do - go - - expect(response).to have_http_status(200) - expect(json_response['count']).to eq 1 - expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/) - end - end - - context 'when not authorized for project' do - it 'does not create todo for merge request user has no access to' do - sign_in(user) - expect do - go - end.to change { user.todos.count }.by(0) - - expect(response).to have_http_status(404) - end - - it 'does not create todo for merge request user has no access to' do - expect do - go - end.to change { user.todos.count }.by(0) - - expect(response).to have_http_status(302) - end - end - - context 'when not authorized for merge_request' do - before do - project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) - project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE) - sign_in(user) - end - - it "doesn't create todo" do - expect{ go }.not_to change { user.todos.count } - expect(response).to have_http_status(404) - end - end - end - end -end diff --git a/spec/controllers/projects/todos_controller_spec.rb b/spec/controllers/projects/todos_controller_spec.rb new file mode 100644 index 00000000000..c5a4153d991 --- /dev/null +++ b/spec/controllers/projects/todos_controller_spec.rb @@ -0,0 +1,144 @@ +require('spec_helper') + +describe Projects::TodosController do + let(:user) { create(:user) } + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:merge_request) { create(:merge_request, source_project: project) } + + context 'Issues' do + describe 'POST create' do + def go + post :create, + namespace_id: project.namespace, + project_id: project, + issuable_id: issue.id, + issuable_type: 'issue', + format: 'html' + end + + context 'when authorized' do + before do + sign_in(user) + project.team << [user, :developer] + end + + it 'creates todo for issue' do + expect do + go + end.to change { user.todos.count }.by(1) + + expect(response).to have_http_status(200) + end + + it 'returns todo path and pending count' do + go + + expect(response).to have_http_status(200) + expect(json_response['count']).to eq 1 + expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/) + end + end + + context 'when not authorized for project' do + it 'does not create todo for issue that user has no access to' do + sign_in(user) + expect do + go + end.to change { user.todos.count }.by(0) + + expect(response).to have_http_status(404) + end + + it 'does not create todo for issue when user not logged in' do + expect do + go + end.to change { user.todos.count }.by(0) + + expect(response).to have_http_status(302) + end + end + + context 'when not authorized for issue' do + before do + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE) + sign_in(user) + end + + it "doesn't create todo" do + expect{ go }.not_to change { user.todos.count } + expect(response).to have_http_status(404) + end + end + end + end + + context 'Merge Requests' do + describe 'POST create' do + def go + post :create, + namespace_id: project.namespace, + project_id: project, + issuable_id: merge_request.id, + issuable_type: 'merge_request', + format: 'html' + end + + context 'when authorized' do + before do + sign_in(user) + project.team << [user, :developer] + end + + it 'creates todo for merge request' do + expect do + go + end.to change { user.todos.count }.by(1) + + expect(response).to have_http_status(200) + end + + it 'returns todo path and pending count' do + go + + expect(response).to have_http_status(200) + expect(json_response['count']).to eq 1 + expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/) + end + end + + context 'when not authorized for project' do + it 'does not create todo for merge request user has no access to' do + sign_in(user) + expect do + go + end.to change { user.todos.count }.by(0) + + expect(response).to have_http_status(404) + end + + it 'does not create todo for merge request user has no access to' do + expect do + go + end.to change { user.todos.count }.by(0) + + expect(response).to have_http_status(302) + end + end + + context 'when not authorized for merge_request' do + before do + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE) + sign_in(user) + end + + it "doesn't create todo" do + expect{ go }.not_to change { user.todos.count } + expect(response).to have_http_status(404) + end + end + end + end +end -- cgit v1.2.1 From c277b2c34d4ce03ad60511982fa16a22afbade06 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 28 Apr 2017 15:45:18 +0300 Subject: Add tests for Oauth::AuthorizationsController Signed-off-by: Dmitriy Zaporozhets --- .../oauth/authorizations_controller_spec.rb | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/controllers/oauth/authorizations_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/oauth/authorizations_controller_spec.rb b/spec/controllers/oauth/authorizations_controller_spec.rb new file mode 100644 index 00000000000..d321bfcea9d --- /dev/null +++ b/spec/controllers/oauth/authorizations_controller_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Oauth::AuthorizationsController do + let(:user) { create(:user) } + + let(:doorkeeper) do + Doorkeeper::Application.create( + name: "MyApp", + redirect_uri: 'http://example.com', + scopes: "") + end + + let(:params) do + { + response_type: "code", + client_id: doorkeeper.uid, + redirect_uri: doorkeeper.redirect_uri, + state: 'state' + } + end + + before do + sign_in(user) + end + + describe 'GET #new' do + context 'without valid params' do + it 'returns 200 code and renders error view' do + get :new + + expect(response).to have_http_status(200) + expect(response).to render_template('doorkeeper/authorizations/error') + end + end + + context 'with valid params' do + it 'returns 200 code and renders view' do + get :new, params + + expect(response).to have_http_status(200) + expect(response).to render_template('doorkeeper/authorizations/new') + end + + it 'deletes session.user_return_to and redirects when skip authorization' do + request.session['user_return_to'] = 'http://example.com' + allow(controller).to receive(:skip_authorization?).and_return(true) + + get :new, params + + expect(request.session['user_return_to']).to be_nil + expect(response).to have_http_status(302) + end + end + end +end -- cgit v1.2.1 From 2b3fc5e624bd0c8b9e1c68bf2b3741d8898cf0b0 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sun, 30 Apr 2017 12:15:20 -0500 Subject: Add download button to project snippets --- spec/controllers/snippets_controller_spec.rb | 180 +++++++++++++-------------- 1 file changed, 87 insertions(+), 93 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/snippets_controller_spec.rb b/spec/controllers/snippets_controller_spec.rb index 234f3edd3d8..41cd5bdcdd8 100644 --- a/spec/controllers/snippets_controller_spec.rb +++ b/spec/controllers/snippets_controller_spec.rb @@ -350,144 +350,138 @@ describe SnippetsController do end end - %w(raw download).each do |action| - describe "GET #{action}" do - context 'when the personal snippet is private' do - let(:personal_snippet) { create(:personal_snippet, :private, author: user) } + describe "GET #raw" do + context 'when the personal snippet is private' do + let(:personal_snippet) { create(:personal_snippet, :private, author: user) } - context 'when signed in' do - before do - sign_in(user) - end + context 'when signed in' do + before do + sign_in(user) + end - context 'when signed in user is not the author' do - let(:other_author) { create(:author) } - let(:other_personal_snippet) { create(:personal_snippet, :private, author: other_author) } + context 'when signed in user is not the author' do + let(:other_author) { create(:author) } + let(:other_personal_snippet) { create(:personal_snippet, :private, author: other_author) } - it 'responds with status 404' do - get action, id: other_personal_snippet.to_param + it 'responds with status 404' do + get :raw, id: other_personal_snippet.to_param - expect(response).to have_http_status(404) - end + expect(response).to have_http_status(404) end + end - context 'when signed in user is the author' do - before { get action, id: personal_snippet.to_param } + context 'when signed in user is the author' do + before { get :raw, id: personal_snippet.to_param } - it 'responds with status 200' do - expect(assigns(:snippet)).to eq(personal_snippet) - expect(response).to have_http_status(200) - end + it 'responds with status 200' do + expect(assigns(:snippet)).to eq(personal_snippet) + expect(response).to have_http_status(200) + end - it 'has expected headers' do - expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8') + it 'has expected headers' do + expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8') - if action == :download - expect(response.header['Content-Disposition']).to match(/attachment/) - elsif action == :raw - expect(response.header['Content-Disposition']).to match(/inline/) - end - end + expect(response.header['Content-Disposition']).to match(/inline/) end end + end - context 'when not signed in' do - it 'redirects to the sign in page' do - get action, id: personal_snippet.to_param + context 'when not signed in' do + it 'redirects to the sign in page' do + get :raw, id: personal_snippet.to_param - expect(response).to redirect_to(new_user_session_path) - end + expect(response).to redirect_to(new_user_session_path) end end + end - context 'when the personal snippet is internal' do - let(:personal_snippet) { create(:personal_snippet, :internal, author: user) } + context 'when the personal snippet is internal' do + let(:personal_snippet) { create(:personal_snippet, :internal, author: user) } - context 'when signed in' do - before do - sign_in(user) - end + context 'when signed in' do + before do + sign_in(user) + end - it 'responds with status 200' do - get action, id: personal_snippet.to_param + it 'responds with status 200' do + get :raw, id: personal_snippet.to_param - expect(assigns(:snippet)).to eq(personal_snippet) - expect(response).to have_http_status(200) - end + expect(assigns(:snippet)).to eq(personal_snippet) + expect(response).to have_http_status(200) end + end - context 'when not signed in' do - it 'redirects to the sign in page' do - get action, id: personal_snippet.to_param + context 'when not signed in' do + it 'redirects to the sign in page' do + get :raw, id: personal_snippet.to_param - expect(response).to redirect_to(new_user_session_path) - end + expect(response).to redirect_to(new_user_session_path) end end + end - context 'when the personal snippet is public' do - let(:personal_snippet) { create(:personal_snippet, :public, author: user) } + context 'when the personal snippet is public' do + let(:personal_snippet) { create(:personal_snippet, :public, author: user) } - context 'when signed in' do - before do - sign_in(user) - end + context 'when signed in' do + before do + sign_in(user) + end - it 'responds with status 200' do - get action, id: personal_snippet.to_param + it 'responds with status 200' do + get :raw, id: personal_snippet.to_param - expect(assigns(:snippet)).to eq(personal_snippet) - expect(response).to have_http_status(200) - end + expect(assigns(:snippet)).to eq(personal_snippet) + expect(response).to have_http_status(200) + end - context 'CRLF line ending' do - let(:personal_snippet) do - create(:personal_snippet, :public, author: user, content: "first line\r\nsecond line\r\nthird line") - end + context 'CRLF line ending' do + let(:personal_snippet) do + create(:personal_snippet, :public, author: user, content: "first line\r\nsecond line\r\nthird line") + end - it 'returns LF line endings by default' do - get action, id: personal_snippet.to_param + it 'returns LF line endings by default' do + get :raw, id: personal_snippet.to_param - expect(response.body).to eq("first line\nsecond line\nthird line") - end + expect(response.body).to eq("first line\nsecond line\nthird line") + end - it 'does not convert line endings when parameter present' do - get action, id: personal_snippet.to_param, line_ending: :raw + it 'does not convert line endings when parameter present' do + get :raw, id: personal_snippet.to_param, line_ending: :raw - expect(response.body).to eq("first line\r\nsecond line\r\nthird line") - end + expect(response.body).to eq("first line\r\nsecond line\r\nthird line") end end + end - context 'when not signed in' do - it 'responds with status 200' do - get action, id: personal_snippet.to_param + context 'when not signed in' do + it 'responds with status 200' do + get :raw, id: personal_snippet.to_param - expect(assigns(:snippet)).to eq(personal_snippet) - expect(response).to have_http_status(200) - end + expect(assigns(:snippet)).to eq(personal_snippet) + expect(response).to have_http_status(200) end end + end - context 'when the personal snippet does not exist' do - context 'when signed in' do - before do - sign_in(user) - end + context 'when the personal snippet does not exist' do + context 'when signed in' do + before do + sign_in(user) + end - it 'responds with status 404' do - get action, id: 'doesntexist' + it 'responds with status 404' do + get :raw, id: 'doesntexist' - expect(response).to have_http_status(404) - end + expect(response).to have_http_status(404) end + end - context 'when not signed in' do - it 'responds with status 404' do - get action, id: 'doesntexist' + context 'when not signed in' do + it 'responds with status 404' do + get :raw, id: 'doesntexist' - expect(response).to have_http_status(404) - end + expect(response).to have_http_status(404) end end end -- cgit v1.2.1 From d49768296ce596bbbbdf8412c362d9999ce822a4 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 1 May 2017 11:13:33 -0400 Subject: Auto-correct `RSpec/DescribedClass` violations --- spec/controllers/application_controller_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 760f33b09c1..1bf0533ca24 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -4,7 +4,7 @@ describe ApplicationController do let(:user) { create(:user) } describe '#check_password_expiration' do - let(:controller) { ApplicationController.new } + let(:controller) { described_class.new } it 'redirects if the user is over their password expiry' do user.password_expires_at = Time.new(2002) @@ -34,7 +34,7 @@ describe ApplicationController do describe "#authenticate_user_from_token!" do describe "authenticating a user from a private token" do - controller(ApplicationController) do + controller(described_class) do def index render text: "authenticated" end @@ -66,7 +66,7 @@ describe ApplicationController do end describe "authenticating a user from a personal access token" do - controller(ApplicationController) do + controller(described_class) do def index render text: 'authenticated' end @@ -115,7 +115,7 @@ describe ApplicationController do end context 'two-factor authentication' do - let(:controller) { ApplicationController.new } + let(:controller) { described_class.new } describe '#check_two_factor_requirement' do subject { controller.send :check_two_factor_requirement } -- cgit v1.2.1 From 8c3a03c1b9bf5c80571c9dc07ba258fa10dd61c8 Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Thu, 27 Apr 2017 12:41:26 +0200 Subject: Display comments for personal snippets --- spec/controllers/projects/notes_controller_spec.rb | 41 +++++ spec/controllers/snippets/notes_controller_spec.rb | 196 +++++++++++++++++++++ 2 files changed, 237 insertions(+) create mode 100644 spec/controllers/snippets/notes_controller_spec.rb (limited to 'spec/controllers') diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index f140eaef5d5..45f4cf9180d 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -167,6 +167,47 @@ describe Projects::NotesController do end end + describe 'DELETE destroy' do + let(:request_params) do + { + namespace_id: project.namespace, + project_id: project, + id: note, + format: :js + } + end + + context 'user is the author of a note' do + before do + sign_in(note.author) + project.team << [note.author, :developer] + end + + it "returns status 200 for html" do + delete :destroy, request_params + + expect(response).to have_http_status(200) + end + + it "deletes the note" do + expect { delete :destroy, request_params }.to change { Note.count }.from(1).to(0) + end + end + + context 'user is not the author of a note' do + before do + sign_in(user) + project.team << [user, :developer] + end + + it "returns status 404" do + delete :destroy, request_params + + expect(response).to have_http_status(404) + end + end + end + describe 'POST toggle_award_emoji' do before do sign_in(user) diff --git a/spec/controllers/snippets/notes_controller_spec.rb b/spec/controllers/snippets/notes_controller_spec.rb new file mode 100644 index 00000000000..1c494b8c7ab --- /dev/null +++ b/spec/controllers/snippets/notes_controller_spec.rb @@ -0,0 +1,196 @@ +require 'spec_helper' + +describe Snippets::NotesController do + let(:user) { create(:user) } + + let(:private_snippet) { create(:personal_snippet, :private) } + let(:internal_snippet) { create(:personal_snippet, :internal) } + let(:public_snippet) { create(:personal_snippet, :public) } + + let(:note_on_private) { create(:note_on_personal_snippet, noteable: private_snippet) } + let(:note_on_internal) { create(:note_on_personal_snippet, noteable: internal_snippet) } + let(:note_on_public) { create(:note_on_personal_snippet, noteable: public_snippet) } + + describe 'GET index' do + context 'when a snippet is public' do + before do + note_on_public + + get :index, { snippet_id: public_snippet } + end + + it "returns status 200" do + expect(response).to have_http_status(200) + end + + it "returns not empty array of notes" do + expect(JSON.parse(response.body)["notes"].empty?).to be_falsey + end + end + + context 'when a snippet is internal' do + before do + note_on_internal + end + + context 'when user not logged in' do + it "returns status 404" do + get :index, { snippet_id: internal_snippet } + + expect(response).to have_http_status(404) + end + end + + context 'when user logged in' do + before do + sign_in(user) + end + + it "returns status 200" do + get :index, { snippet_id: internal_snippet } + + expect(response).to have_http_status(200) + end + end + end + + context 'when a snippet is private' do + before do + note_on_private + end + + context 'when user not logged in' do + it "returns status 404" do + get :index, { snippet_id: private_snippet } + + expect(response).to have_http_status(404) + end + end + + context 'when user other than author logged in' do + before do + sign_in(user) + end + + it "returns status 404" do + get :index, { snippet_id: private_snippet } + + expect(response).to have_http_status(404) + end + end + + context 'when author logged in' do + before do + note_on_private + + sign_in(private_snippet.author) + end + + it "returns status 200" do + get :index, { snippet_id: private_snippet } + + expect(response).to have_http_status(200) + end + + it "returns 1 note" do + get :index, { snippet_id: private_snippet } + + expect(JSON.parse(response.body)['notes'].count).to eq(1) + end + end + end + + context 'dont show non visible notes' do + before do + note_on_public + + sign_in(user) + + expect_any_instance_of(Note).to receive(:cross_reference_not_visible_for?).and_return(true) + end + + it "does not return any note" do + get :index, { snippet_id: public_snippet } + + expect(JSON.parse(response.body)['notes'].count).to eq(0) + end + end + end + + describe 'DELETE destroy' do + let(:request_params) do + { + snippet_id: public_snippet, + id: note_on_public, + format: :js + } + end + + context 'when user is the author of a note' do + before do + sign_in(note_on_public.author) + end + + it "returns status 200" do + delete :destroy, request_params + + expect(response).to have_http_status(200) + end + + it "deletes the note" do + expect{ delete :destroy, request_params }.to change{ Note.count }.from(1).to(0) + end + + context 'system note' do + before do + expect_any_instance_of(Note).to receive(:system?).and_return(true) + end + + it "does not delete the note" do + expect{ delete :destroy, request_params }.not_to change{ Note.count } + end + end + end + + context 'when user is not the author of a note' do + before do + sign_in(user) + + note_on_public + end + + it "returns status 404" do + delete :destroy, request_params + + expect(response).to have_http_status(404) + end + + it "does not update the note" do + expect{ delete :destroy, request_params }.not_to change{ Note.count } + end + end + end + + describe 'POST toggle_award_emoji' do + let(:note) { create(:note_on_personal_snippet, noteable: public_snippet) } + before do + sign_in(user) + end + + subject { post(:toggle_award_emoji, snippet_id: public_snippet, id: note.id, name: "thumbsup") } + + it "toggles the award emoji" do + expect { subject }.to change { note.award_emoji.count }.by(1) + + expect(response).to have_http_status(200) + end + + it "removes the already awarded emoji when it exists" do + note.toggle_award_emoji('thumbsup', user) # create award emoji before + + expect { subject }.to change { AwardEmoji.count }.by(-1) + + expect(response).to have_http_status(200) + end + end +end -- cgit v1.2.1