2015-03-05 13:38:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::DataBuilder::Note do
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-03-05 13:38:23 -05:00
|
|
|
let(:user) { create(:user) }
|
2016-08-12 03:16:14 -04:00
|
|
|
let(:data) { described_class.build(note, user) }
|
2015-03-05 13:38:23 -05:00
|
|
|
let(:fixed_time) { Time.at(1425600000) } # Avoid time precision errors
|
|
|
|
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2015-03-05 13:38:23 -05:00
|
|
|
expect(data).to have_key(:object_attributes)
|
|
|
|
expect(data[:object_attributes]).to have_key(:url)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:object_attributes][:url])
|
|
|
|
.to eq(Gitlab::UrlBuilder.build(note))
|
2015-03-05 13:38:23 -05:00
|
|
|
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
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
let(:note) { create(:note_on_commit, project: project) }
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
it 'returns the note and commit-specific data' do
|
|
|
|
expect(data).to have_key(:commit)
|
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on commit diff' do
|
2016-06-20 13:20:39 -04:00
|
|
|
let(:note) { create(:diff_note_on_commit, project: project) }
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
it 'returns the note and commit-specific data' do
|
|
|
|
expect(data).to have_key(:commit)
|
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on issue' do
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:issue) do
|
|
|
|
create(:issue, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-05-18 13:38:52 -04:00
|
|
|
create(:note_on_issue, noteable: issue, project: project)
|
2016-04-26 07:52:18 -04:00
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
it 'returns the note and issue-specific data' do
|
|
|
|
expect(data).to have_key(:issue)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:issue].except('updated_at'))
|
2016-05-18 13:38:52 -04:00
|
|
|
.to eq(issue.reload.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:issue]['updated_at'])
|
|
|
|
.to be > issue.hook_attrs['updated_at']
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request' do
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, created_at: fixed_time,
|
|
|
|
updated_at: fixed_time,
|
|
|
|
source_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-05-18 13:38:52 -04:00
|
|
|
create(:note_on_merge_request, noteable: merge_request,
|
2016-04-26 07:52:18 -04:00
|
|
|
project: project)
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
it 'returns the note and merge request data' do
|
|
|
|
expect(data).to have_key(:merge_request)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request].except('updated_at'))
|
2016-05-18 13:38:52 -04:00
|
|
|
.to eq(merge_request.reload.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request]['updated_at'])
|
|
|
|
.to be > merge_request.hook_attrs['updated_at']
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request diff' do
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
source_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-06-20 13:20:39 -04:00
|
|
|
create(:diff_note_on_merge_request, noteable: merge_request,
|
2016-04-26 07:52:18 -04:00
|
|
|
project: project)
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
it 'returns the note and merge request diff data' do
|
|
|
|
expect(data).to have_key(:merge_request)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request].except('updated_at'))
|
2016-05-18 13:38:52 -04:00
|
|
|
.to eq(merge_request.reload.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request]['updated_at'])
|
|
|
|
.to be > merge_request.hook_attrs['updated_at']
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on project snippet' do
|
2016-04-26 07:52:18 -04:00
|
|
|
let!(:snippet) do
|
|
|
|
create(:project_snippet, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:note) do
|
2016-05-18 13:38:52 -04:00
|
|
|
create(:note_on_project_snippet, noteable: snippet,
|
2016-04-26 07:52:18 -04:00
|
|
|
project: project)
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
|
|
|
it 'returns the note and project snippet data' do
|
|
|
|
expect(data).to have_key(:snippet)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:snippet].except('updated_at'))
|
2016-05-18 13:38:52 -04:00
|
|
|
.to eq(snippet.reload.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:snippet]['updated_at'])
|
|
|
|
.to be > snippet.hook_attrs['updated_at']
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
end
|