diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-08-04 18:44:27 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-08-04 18:44:27 +0300 |
commit | 984367f957c8f8d02fa82b08817e2f2f318c6bff (patch) | |
tree | 6f18804966e10c58473094c94cb8c2a0626d8065 /spec/lib/gitlab/data_builder | |
parent | 80671bf75cdac3f50615253b058fa04da6235a4f (diff) |
Move those builders to their own namespace, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5620#note_13540099
Diffstat (limited to 'spec/lib/gitlab/data_builder')
3 files changed, 205 insertions, 0 deletions
diff --git a/spec/lib/gitlab/data_builder/build_data_builder_spec.rb b/spec/lib/gitlab/data_builder/build_data_builder_spec.rb new file mode 100644 index 00000000000..41b9207df2d --- /dev/null +++ b/spec/lib/gitlab/data_builder/build_data_builder_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Gitlab::DataBuilder::BuildDataBuilder do + let(:build) { create(:ci_build) } + + describe '.build' do + let(:data) do + Gitlab::DataBuilder::BuildDataBuilder.build(build) + end + + it { expect(data).to be_a(Hash) } + it { expect(data[:ref]).to eq(build.ref) } + it { expect(data[:sha]).to eq(build.sha) } + it { expect(data[:tag]).to eq(build.tag) } + it { expect(data[:build_id]).to eq(build.id) } + it { expect(data[:build_status]).to eq(build.status) } + it { expect(data[:build_allow_failure]).to eq(false) } + it { expect(data[:project_id]).to eq(build.project.id) } + it { expect(data[:project_name]).to eq(build.project.name_with_namespace) } + end +end diff --git a/spec/lib/gitlab/data_builder/note_data_builder_spec.rb b/spec/lib/gitlab/data_builder/note_data_builder_spec.rb new file mode 100644 index 00000000000..bc5d6cdc358 --- /dev/null +++ b/spec/lib/gitlab/data_builder/note_data_builder_spec.rb @@ -0,0 +1,131 @@ +require 'spec_helper' + +describe Gitlab::DataBuilder::NoteDataBuilder, lib: true do + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:data) { Gitlab::DataBuilder::NoteDataBuilder.build(note, user) } + let(:fixed_time) { Time.at(1425600000) } # Avoid time precision errors + + before(:each) do + expect(data).to have_key(:object_attributes) + expect(data[:object_attributes]).to have_key(:url) + expect(data[:object_attributes][:url]) + .to eq(Gitlab::UrlBuilder.build(note)) + expect(data[:object_kind]).to eq('note') + expect(data[:user]).to eq(user.hook_attrs) + end + + describe 'When asking for a note on commit' do + let(:note) { create(:note_on_commit, project: project) } + + it 'returns the note and commit-specific data' do + expect(data).to have_key(:commit) + end + + include_examples 'project hook data' + include_examples 'deprecated repository hook data' + end + + describe 'When asking for a note on commit diff' do + let(:note) { create(:diff_note_on_commit, project: project) } + + it 'returns the note and commit-specific data' do + expect(data).to have_key(:commit) + end + + include_examples 'project hook data' + include_examples 'deprecated repository hook data' + end + + describe 'When asking for a note on issue' do + let(:issue) do + create(:issue, created_at: fixed_time, updated_at: fixed_time, + project: project) + end + + let(:note) do + create(:note_on_issue, noteable: issue, project: project) + end + + it 'returns the note and issue-specific data' do + expect(data).to have_key(:issue) + expect(data[:issue].except('updated_at')) + .to eq(issue.reload.hook_attrs.except('updated_at')) + expect(data[:issue]['updated_at']) + .to be > issue.hook_attrs['updated_at'] + end + + include_examples 'project hook data' + include_examples 'deprecated repository hook data' + end + + describe 'When asking for a note on merge request' do + let(:merge_request) do + create(:merge_request, created_at: fixed_time, + updated_at: fixed_time, + source_project: project) + end + + let(:note) do + create(:note_on_merge_request, noteable: merge_request, + project: project) + end + + it 'returns the note and merge request data' do + expect(data).to have_key(:merge_request) + expect(data[:merge_request].except('updated_at')) + .to eq(merge_request.reload.hook_attrs.except('updated_at')) + expect(data[:merge_request]['updated_at']) + .to be > merge_request.hook_attrs['updated_at'] + end + + include_examples 'project hook data' + include_examples 'deprecated repository hook data' + end + + describe 'When asking for a note on merge request diff' do + let(:merge_request) do + create(:merge_request, created_at: fixed_time, updated_at: fixed_time, + source_project: project) + end + + let(:note) do + create(:diff_note_on_merge_request, noteable: merge_request, + project: project) + end + + it 'returns the note and merge request diff data' do + expect(data).to have_key(:merge_request) + expect(data[:merge_request].except('updated_at')) + .to eq(merge_request.reload.hook_attrs.except('updated_at')) + expect(data[:merge_request]['updated_at']) + .to be > merge_request.hook_attrs['updated_at'] + end + + include_examples 'project hook data' + include_examples 'deprecated repository hook data' + end + + describe 'When asking for a note on project snippet' do + let!(:snippet) do + create(:project_snippet, created_at: fixed_time, updated_at: fixed_time, + project: project) + end + + let!(:note) do + create(:note_on_project_snippet, noteable: snippet, + project: project) + end + + it 'returns the note and project snippet data' do + expect(data).to have_key(:snippet) + expect(data[:snippet].except('updated_at')) + .to eq(snippet.reload.hook_attrs.except('updated_at')) + expect(data[:snippet]['updated_at']) + .to be > snippet.hook_attrs['updated_at'] + end + + include_examples 'project hook data' + include_examples 'deprecated repository hook data' + end +end diff --git a/spec/lib/gitlab/data_builder/push_data_builder_spec.rb b/spec/lib/gitlab/data_builder/push_data_builder_spec.rb new file mode 100644 index 00000000000..beb3e0eda7e --- /dev/null +++ b/spec/lib/gitlab/data_builder/push_data_builder_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe Gitlab::DataBuilder::PushDataBuilder, lib: true do + let(:project) { create(:project) } + let(:user) { create(:user) } + + describe '.build_sample' do + let(:data) { described_class.build_sample(project, user) } + + it { expect(data).to be_a(Hash) } + it { expect(data[:before]).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + it { expect(data[:after]).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') } + it { expect(data[:ref]).to eq('refs/heads/master') } + it { expect(data[:commits].size).to eq(3) } + it { expect(data[:total_commits_count]).to eq(3) } + it { expect(data[:commits].first[:added]).to eq(['gitlab-grack']) } + it { expect(data[:commits].first[:modified]).to eq(['.gitmodules']) } + it { expect(data[:commits].first[:removed]).to eq([]) } + + include_examples 'project hook data with deprecateds' + include_examples 'deprecated repository hook data' + end + + describe '.build' do + let(:data) do + described_class.build(project, user, Gitlab::Git::BLANK_SHA, + '8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b', + 'refs/tags/v1.1.0') + end + + it { expect(data).to be_a(Hash) } + it { expect(data[:before]).to eq(Gitlab::Git::BLANK_SHA) } + it { expect(data[:checkout_sha]).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') } + it { expect(data[:after]).to eq('8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b') } + it { expect(data[:ref]).to eq('refs/tags/v1.1.0') } + it { expect(data[:user_id]).to eq(user.id) } + it { expect(data[:user_name]).to eq(user.name) } + it { expect(data[:user_email]).to eq(user.email) } + it { expect(data[:user_avatar]).to eq(user.avatar_url) } + it { expect(data[:project_id]).to eq(project.id) } + it { expect(data[:project]).to be_a(Hash) } + it { expect(data[:commits]).to be_empty } + it { expect(data[:total_commits_count]).to be_zero } + + include_examples 'project hook data with deprecateds' + include_examples 'deprecated repository hook data' + + it 'does not raise an error when given nil commits' do + expect { described_class.build(spy, spy, spy, spy, spy, nil) }. + not_to raise_error + end + end +end |