2012-10-09 04:14:17 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: events
|
|
|
|
#
|
2012-11-19 13:24:05 -05:00
|
|
|
# id :integer not null, primary key
|
2012-10-09 04:14:17 -04:00
|
|
|
# target_type :string(255)
|
|
|
|
# target_id :integer
|
|
|
|
# title :string(255)
|
|
|
|
# data :text
|
|
|
|
# project_id :integer
|
2014-04-09 08:05:03 -04:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2012-10-09 04:14:17 -04:00
|
|
|
# action :integer
|
|
|
|
# author_id :integer
|
|
|
|
#
|
|
|
|
|
2012-02-28 08:09:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe Event, models: true do
|
2012-02-28 09:01:14 -05:00
|
|
|
describe "Associations" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to belong_to(:target) }
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|
|
|
|
|
2012-03-28 15:53:45 -04:00
|
|
|
describe "Respond to" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to respond_to(:author_name) }
|
|
|
|
it { is_expected.to respond_to(:author_email) }
|
|
|
|
it { is_expected.to respond_to(:issue_title) }
|
|
|
|
it { is_expected.to respond_to(:merge_request_title) }
|
|
|
|
it { is_expected.to respond_to(:commits) }
|
2012-03-28 15:53:45 -04:00
|
|
|
end
|
|
|
|
|
2012-09-14 18:00:59 -04:00
|
|
|
describe "Push event" do
|
|
|
|
before do
|
2012-11-05 22:31:55 -05:00
|
|
|
project = create(:project)
|
2012-03-28 15:53:45 -04:00
|
|
|
@user = project.owner
|
|
|
|
|
2012-09-14 18:00:59 -04:00
|
|
|
data = {
|
2014-11-03 14:35:06 -05:00
|
|
|
before: Gitlab::Git::BLANK_SHA,
|
2012-08-10 18:07:50 -04:00
|
|
|
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
|
|
|
|
ref: "refs/heads/master",
|
|
|
|
user_id: @user.id,
|
|
|
|
user_name: @user.name,
|
|
|
|
repository: {
|
|
|
|
name: project.name,
|
|
|
|
url: "localhost/rubinius",
|
|
|
|
description: "",
|
|
|
|
homepage: "localhost/rubinius",
|
|
|
|
private: true
|
2012-03-28 15:53:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@event = Event.create(
|
2012-08-10 18:07:50 -04:00
|
|
|
project: project,
|
2013-02-13 06:48:16 -05:00
|
|
|
action: Event::PUSHED,
|
2012-08-10 18:07:50 -04:00
|
|
|
data: data,
|
|
|
|
author_id: @user.id
|
2012-03-28 15:53:45 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@event.push?).to be_truthy }
|
|
|
|
it { expect(@event.proper?).to be_truthy }
|
|
|
|
it { expect(@event.tag?).to be_falsey }
|
|
|
|
it { expect(@event.branch_name).to eq("master") }
|
|
|
|
it { expect(@event.author).to eq(@user) }
|
2012-03-28 15:53:45 -04:00
|
|
|
end
|
2015-11-11 11:14:47 -05:00
|
|
|
|
2016-03-17 17:03:10 -04:00
|
|
|
describe '#proper?' do
|
|
|
|
context 'issue event' do
|
|
|
|
let(:project) { create(:empty_project, :public) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:author) { create(:author) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:event) { Event.new(project: project, action: Event::CREATED, target: issue, author_id: author.id) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [member, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for non confidential issues' do
|
|
|
|
let(:issue) { create(:issue, project: project, author: author, assignee: assignee) }
|
|
|
|
|
|
|
|
it { expect(event.proper?(non_member)).to eq true }
|
|
|
|
it { expect(event.proper?(author)).to eq true }
|
|
|
|
it { expect(event.proper?(assignee)).to eq true }
|
|
|
|
it { expect(event.proper?(member)).to eq true }
|
|
|
|
it { expect(event.proper?(admin)).to eq true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for confidential issues' do
|
|
|
|
let(:issue) { create(:issue, :confidential, project: project, author: author, assignee: assignee) }
|
|
|
|
|
|
|
|
it { expect(event.proper?(non_member)).to eq false }
|
|
|
|
it { expect(event.proper?(author)).to eq true }
|
|
|
|
it { expect(event.proper?(assignee)).to eq true }
|
|
|
|
it { expect(event.proper?(member)).to eq true }
|
|
|
|
it { expect(event.proper?(admin)).to eq true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-18 06:25:37 -05:00
|
|
|
describe '.limit_recent' do
|
|
|
|
let!(:event1) { create(:closed_issue_event) }
|
|
|
|
let!(:event2) { create(:closed_issue_event) }
|
|
|
|
|
|
|
|
describe 'without an explicit limit' do
|
|
|
|
subject { Event.limit_recent }
|
|
|
|
|
|
|
|
it { is_expected.to eq([event2, event1]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with an explicit limit' do
|
|
|
|
subject { Event.limit_recent(1) }
|
|
|
|
|
|
|
|
it { is_expected.to eq([event2]) }
|
|
|
|
end
|
|
|
|
end
|
2012-02-28 08:09:23 -05:00
|
|
|
end
|