diff options
author | Fatih Acet <acetfatih@gmail.com> | 2017-05-09 04:15:34 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2017-05-09 04:15:34 +0000 |
commit | 0151325dacebb99d54b6effb1d5842c0c712168c (patch) | |
tree | 767ea3c8cfeedab5a0ce1921d5842b149ea7c0be /spec/serializers | |
parent | 9ada13d343a4736275d2c026ee980abe5c5e5763 (diff) | |
download | gitlab-ce-0151325dacebb99d54b6effb1d5842c0c712168c.tar.gz |
Merge request widget redesign
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/build_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/build_serializer_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/deployment_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/environment_serializer_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/event_entity_spec.rb | 13 | ||||
-rw-r--r-- | spec/serializers/merge_request_basic_serializer_spec.rb | 12 | ||||
-rw-r--r-- | spec/serializers/merge_request_entity_spec.rb | 128 | ||||
-rw-r--r-- | spec/serializers/merge_request_serializer_spec.rb | 37 | ||||
-rw-r--r-- | spec/serializers/pipeline_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 6 | ||||
-rw-r--r-- | spec/serializers/stage_entity_spec.rb | 2 |
11 files changed, 200 insertions, 10 deletions
diff --git a/spec/serializers/build_entity_spec.rb b/spec/serializers/build_entity_spec.rb index 897a28b7305..b5eb84ae43b 100644 --- a/spec/serializers/build_entity_spec.rb +++ b/spec/serializers/build_entity_spec.rb @@ -6,7 +6,7 @@ describe BuildEntity do let(:request) { double('request') } before do - allow(request).to receive(:user).and_return(user) + allow(request).to receive(:current_user).and_return(user) end let(:entity) do diff --git a/spec/serializers/build_serializer_spec.rb b/spec/serializers/build_serializer_spec.rb index 7f1abecfafe..01e2cfed6f8 100644 --- a/spec/serializers/build_serializer_spec.rb +++ b/spec/serializers/build_serializer_spec.rb @@ -4,7 +4,7 @@ describe BuildSerializer do let(:user) { create(:user) } let(:serializer) do - described_class.new(user: user) + described_class.new(current_user: user) end subject { serializer.represent(resource) } diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index 69355bcde42..522c92ce295 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -8,7 +8,7 @@ describe DeploymentEntity do subject { entity.as_json } before do - allow(request).to receive(:user).and_return(user) + allow(request).to receive(:current_user).and_return(user) end it 'exposes internal deployment id' do diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index 1909e6385b5..d2ad6c44702 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -6,7 +6,7 @@ describe EnvironmentSerializer do let(:json) do described_class - .new(user: user, project: project) + .new(current_user: user, project: project) .represent(resource) end diff --git a/spec/serializers/event_entity_spec.rb b/spec/serializers/event_entity_spec.rb new file mode 100644 index 00000000000..bb54597c967 --- /dev/null +++ b/spec/serializers/event_entity_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe EventEntity do + subject { described_class.represent(create(:event)).as_json } + + it 'exposes author' do + expect(subject).to include(:author) + end + + it 'exposes core elements of event' do + expect(subject).to include(:updated_at) + end +end diff --git a/spec/serializers/merge_request_basic_serializer_spec.rb b/spec/serializers/merge_request_basic_serializer_spec.rb new file mode 100644 index 00000000000..4daf5a59d0c --- /dev/null +++ b/spec/serializers/merge_request_basic_serializer_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe MergeRequestBasicSerializer do + let(:resource) { create(:merge_request) } + let(:user) { create(:user) } + + subject { described_class.new.represent(resource) } + + it 'has important MergeRequest attributes' do + expect(subject).to include(:merge_status) + end +end diff --git a/spec/serializers/merge_request_entity_spec.rb b/spec/serializers/merge_request_entity_spec.rb new file mode 100644 index 00000000000..bb6e83ae4bd --- /dev/null +++ b/spec/serializers/merge_request_entity_spec.rb @@ -0,0 +1,128 @@ +require 'spec_helper' + +describe MergeRequestEntity do + let(:project) { create :empty_project } + let(:resource) { create(:merge_request, source_project: project, target_project: project) } + let(:user) { create(:user) } + + let(:request) { double('request', current_user: user) } + + subject do + described_class.new(resource, request: request).as_json + end + + it 'includes author' do + req = double('request') + + author_payload = UserEntity + .represent(resource.author, request: req) + .as_json + + expect(subject[:author]).to eq(author_payload) + end + + it 'includes pipeline' do + req = double('request', current_user: user) + pipeline = build_stubbed(:ci_pipeline) + allow(resource).to receive(:head_pipeline).and_return(pipeline) + + pipeline_payload = PipelineEntity + .represent(pipeline, request: req) + .as_json + + expect(subject[:pipeline]).to eq(pipeline_payload) + end + + it 'includes issues_links' do + issues_links = subject[:issues_links] + + expect(issues_links).to include(:closing, :mentioned_but_not_closing, + :assign_to_closing) + end + + it 'has important MergeRequest attributes' do + expect(subject).to include(:diff_head_sha, :merge_commit_message, + :has_conflicts, :has_ci, :merge_path, + :conflict_resolution_path, + :cancel_merge_when_pipeline_succeeds_path, + :create_issue_to_resolve_discussions_path, + :source_branch_path, :target_branch_commits_path, + :commits_count) + end + + it 'has email_patches_path' do + expect(subject[:email_patches_path]) + .to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}.patch") + end + + it 'has plain_diff_path' do + expect(subject[:plain_diff_path]) + .to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}.diff") + end + + it 'has merge_commit_message_with_description' do + expect(subject[:merge_commit_message_with_description]) + .to eq(resource.merge_commit_message(include_description: true)) + end + + describe 'diff_head_sha' do + before do + allow(resource).to receive(:diff_head_sha) { 'sha' } + end + + context 'when no diff head commit' do + it 'returns nil' do + allow(resource).to receive(:diff_head_commit) { nil } + + expect(subject[:diff_head_sha]).to be_nil + end + end + + context 'when diff head commit present' do + it 'returns diff head commit short id' do + allow(resource).to receive(:diff_head_commit) { double } + + expect(subject[:diff_head_sha]).to eq('sha') + end + end + end + + it 'includes merge_event' do + create(:event, :merged, author: user, project: resource.project, target: resource) + + expect(subject[:merge_event]).to include(:author, :updated_at) + end + + it 'includes closed_event' do + create(:event, :closed, author: user, project: resource.project, target: resource) + + expect(subject[:closed_event]).to include(:author, :updated_at) + end + + describe 'diverged_commits_count' do + context 'when MR open and its diverging' do + it 'returns diverged commits count' do + allow(resource).to receive_messages(open?: true, diverged_from_target_branch?: true, + diverged_commits_count: 10) + + expect(subject[:diverged_commits_count]).to eq(10) + end + end + + context 'when MR is not open' do + it 'returns 0' do + allow(resource).to receive_messages(open?: false) + + expect(subject[:diverged_commits_count]).to be_zero + end + end + + context 'when MR is not diverging' do + it 'returns 0' do + allow(resource).to receive_messages(open?: true, diverged_from_target_branch?: false) + + expect(subject[:diverged_commits_count]).to be_zero + end + end + end +end diff --git a/spec/serializers/merge_request_serializer_spec.rb b/spec/serializers/merge_request_serializer_spec.rb new file mode 100644 index 00000000000..73fbecc153d --- /dev/null +++ b/spec/serializers/merge_request_serializer_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe MergeRequestSerializer do + let(:user) { build_stubbed(:user) } + let(:merge_request) { build_stubbed(:merge_request) } + + let(:serializer) do + described_class.new(current_user: user) + end + + describe '#represent' do + let(:opts) { { basic: basic } } + subject { serializer.represent(merge_request, basic: basic) } + + context 'when basic param is truthy' do + let(:basic) { true } + + it 'calls super class #represent with correct params' do + expect_any_instance_of(BaseSerializer).to receive(:represent) + .with(merge_request, opts, MergeRequestBasicEntity) + + subject + end + end + + context 'when basic param is falsy' do + let(:basic) { false } + + it 'calls super class #represent with correct params' do + expect_any_instance_of(BaseSerializer).to receive(:represent) + .with(merge_request, opts, MergeRequestEntity) + + subject + end + end + end +end diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index 93d5a21419d..d2482ac434b 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -5,7 +5,7 @@ describe PipelineEntity do let(:request) { double('request') } before do - allow(request).to receive(:user).and_return(user) + allow(request).to receive(:current_user).and_return(user) end let(:entity) do @@ -19,7 +19,7 @@ describe PipelineEntity do let(:pipeline) { create(:ci_empty_pipeline) } it 'contains required fields' do - expect(subject).to include :id, :user, :path + expect(subject).to include :id, :user, :path, :coverage expect(subject).to include :ref, :commit expect(subject).to include :updated_at, :created_at end diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index ecde45a6d44..f2426db6d81 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -4,7 +4,7 @@ describe PipelineSerializer do let(:user) { create(:user) } let(:serializer) do - described_class.new(user: user) + described_class.new(current_user: user) end subject { serializer.represent(resource) } @@ -44,7 +44,7 @@ describe PipelineSerializer do end let(:serializer) do - described_class.new(user: user) + described_class.new(current_user: user) .with_pagination(request, response) end @@ -113,7 +113,7 @@ describe PipelineSerializer do it "verifies number of queries" do recorded = ActiveRecord::QueryRecorder.new { subject } - expect(recorded.count).to be_within(1).of(50) + expect(recorded.count).to be_within(1).of(58) expect(recorded.cached_count).to eq(0) end diff --git a/spec/serializers/stage_entity_spec.rb b/spec/serializers/stage_entity_spec.rb index 0412b2d7741..64b3217b809 100644 --- a/spec/serializers/stage_entity_spec.rb +++ b/spec/serializers/stage_entity_spec.rb @@ -14,7 +14,7 @@ describe StageEntity do end before do - allow(request).to receive(:user).and_return(user) + allow(request).to receive(:current_user).and_return(user) create(:ci_build, :success, pipeline: pipeline) end |