diff options
author | Robert Speicher <robert@gitlab.com> | 2016-05-10 20:14:40 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-05-10 20:14:40 +0000 |
commit | 971662e6a4039af98ac02f3f5f25804ba3d5da8f (patch) | |
tree | db5aa8e724e975d66f6d7c322788861858905555 /spec/requests/api/commit_statuses_spec.rb | |
parent | 634f02b0950048ee97c1d92c4f3051aedd121dc5 (diff) | |
parent | 5589dcf8db0daf2235158724f6b18115a9abfa42 (diff) | |
download | gitlab-ce-971662e6a4039af98ac02f3f5f25804ba3d5da8f.tar.gz |
Merge branch 'stanhu/gitlab-ce-add-eager-load-lib' into 'master'
Add eager load paths to help prevent dependency load issues with Sidekiq workers
_Originally opened at !3545 by @stanhu._
- - -
Relevant resources:
- https://github.com/mperham/sidekiq/wiki/FAQ#why-doesnt-sidekiq-autoload-my-rails-application-code
- https://github.com/mperham/sidekiq/issues/1281#issuecomment-27129904
- http://blog.arkency.com/2014/11/dont-forget-about-eager-load-when-extending-autoload
- https://github.com/rails/rails/blob/52ce6ece8c8f74064bb64e0a0b1ddd83092718e1/railties/lib/rails/engine.rb#L472-L479
- https://github.com/rails/rails/blob/v4.2.6/railties/lib/rails/paths.rb
Attempts to address #3661, #11896, #12769, #13521, #14131, #14589, #14759, #14825.
See merge request !3724
Diffstat (limited to 'spec/requests/api/commit_statuses_spec.rb')
-rw-r--r-- | spec/requests/api/commit_statuses_spec.rb | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/spec/requests/api/commit_statuses_spec.rb b/spec/requests/api/commit_statuses_spec.rb new file mode 100644 index 00000000000..633927c8c3e --- /dev/null +++ b/spec/requests/api/commit_statuses_spec.rb @@ -0,0 +1,210 @@ +require 'spec_helper' + +describe API::CommitStatuses, api: true do + include ApiHelpers + + let!(:project) { create(:project) } + let(:commit) { project.repository.commit } + let(:commit_status) { create(:commit_status, commit: ci_commit) } + let(:guest) { create_user(:guest) } + let(:reporter) { create_user(:reporter) } + let(:developer) { create_user(:developer) } + let(:sha) { commit.id } + + + describe "GET /projects/:id/repository/commits/:sha/statuses" do + let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" } + + context 'ci commit exists' do + let!(:master) { project.ci_commits.create(sha: commit.id, ref: 'master') } + let!(:develop) { project.ci_commits.create(sha: commit.id, ref: 'develop') } + + it_behaves_like 'a paginated resources' do + let(:request) { get api(get_url, reporter) } + end + + context "reporter user" do + let(:statuses_id) { json_response.map { |status| status['id'] } } + + def create_status(commit, opts = {}) + create(:commit_status, { commit: commit, ref: commit.ref }.merge(opts)) + end + + let!(:status1) { create_status(master, status: 'running') } + let!(:status2) { create_status(master, name: 'coverage', status: 'pending') } + let!(:status3) { create_status(develop, status: 'running', allow_failure: true) } + let!(:status4) { create_status(master, name: 'coverage', status: 'success') } + let!(:status5) { create_status(develop, name: 'coverage', status: 'success') } + let!(:status6) { create_status(master, status: 'success') } + + context 'latest commit statuses' do + before { get api(get_url, reporter) } + + it 'returns latest commit statuses' do + expect(response.status).to eq(200) + + expect(json_response).to be_an Array + expect(statuses_id).to contain_exactly(status3.id, status4.id, status5.id, status6.id) + json_response.sort_by!{ |status| status['id'] } + expect(json_response.map{ |status| status['allow_failure'] }).to eq([true, false, false, false]) + end + end + + context 'all commit statuses' do + before { get api(get_url, reporter), all: 1 } + + it 'returns all commit statuses' do + expect(response.status).to eq(200) + + expect(json_response).to be_an Array + expect(statuses_id).to contain_exactly(status1.id, status2.id, + status3.id, status4.id, + status5.id, status6.id) + end + end + + context 'latest commit statuses for specific ref' do + before { get api(get_url, reporter), ref: 'develop' } + + it 'returns latest commit statuses for specific ref' do + expect(response.status).to eq(200) + + expect(json_response).to be_an Array + expect(statuses_id).to contain_exactly(status3.id, status5.id) + end + end + + context 'latest commit statues for specific name' do + before { get api(get_url, reporter), name: 'coverage' } + + it 'return latest commit statuses for specific name' do + expect(response.status).to eq(200) + + expect(json_response).to be_an Array + expect(statuses_id).to contain_exactly(status4.id, status5.id) + end + end + end + end + + context 'ci commit does not exist' do + before { get api(get_url, reporter) } + + it 'returns empty array' do + expect(response.status).to eq 200 + expect(json_response).to be_an Array + expect(json_response).to be_empty + end + end + + context "guest user" do + before { get api(get_url, guest) } + + it "should not return project commits" do + expect(response.status).to eq(403) + end + end + + context "unauthorized user" do + before { get api(get_url) } + + it "should not return project commits" do + expect(response.status).to eq(401) + end + end + end + + describe 'POST /projects/:id/statuses/:sha' do + let(:post_url) { "/projects/#{project.id}/statuses/#{sha}" } + + context 'developer user' do + context 'only required parameters' do + before { post api(post_url, developer), state: 'success' } + + it 'creates commit status' do + expect(response.status).to eq(201) + expect(json_response['sha']).to eq(commit.id) + expect(json_response['status']).to eq('success') + expect(json_response['name']).to eq('default') + expect(json_response['ref']).to be_nil + expect(json_response['target_url']).to be_nil + expect(json_response['description']).to be_nil + end + end + + context 'with all optional parameters' do + before do + optional_params = { state: 'success', context: 'coverage', + ref: 'develop', target_url: 'url', description: 'test' } + + post api(post_url, developer), optional_params + end + + it 'creates commit status' do + expect(response.status).to eq(201) + expect(json_response['sha']).to eq(commit.id) + expect(json_response['status']).to eq('success') + expect(json_response['name']).to eq('coverage') + expect(json_response['ref']).to eq('develop') + expect(json_response['target_url']).to eq('url') + expect(json_response['description']).to eq('test') + end + end + + context 'invalid status' do + before { post api(post_url, developer), state: 'invalid' } + + it 'does not create commit status' do + expect(response.status).to eq(400) + end + end + + context 'request without state' do + before { post api(post_url, developer) } + + it 'does not create commit status' do + expect(response.status).to eq(400) + end + end + + context 'invalid commit' do + let(:sha) { 'invalid_sha' } + before { post api(post_url, developer), state: 'running' } + + it 'returns not found error' do + expect(response.status).to eq(404) + end + end + end + + context 'reporter user' do + before { post api(post_url, reporter) } + + it 'should not create commit status' do + expect(response.status).to eq(403) + end + end + + context 'guest user' do + before { post api(post_url, guest) } + + it 'should not create commit status' do + expect(response.status).to eq(403) + end + end + + context 'unauthorized user' do + before { post api(post_url) } + + it 'should not create commit status' do + expect(response.status).to eq(401) + end + end + end + + def create_user(access_level_trait) + user = create(:user) + create(:project_member, access_level_trait, user: user, project: project) + user + end +end |