debian-mirror-gitlab/spec/models/event_spec.rb

85 lines
2.1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
# == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# target_type :string(255)
# target_id :integer
# title :string(255)
# data :text
# project_id :integer
# created_at :datetime
# updated_at :datetime
# action :integer
# author_id :integer
#
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Event, models: true do
2014-09-02 18:07:02 +05:30
describe "Associations" do
2015-04-26 12:48:37 +05:30
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:target) }
2014-09-02 18:07:02 +05:30
end
describe "Respond to" do
2015-04-26 12:48:37 +05:30
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) }
2014-09-02 18:07:02 +05:30
end
describe "Push event" do
before do
project = create(:project)
@user = project.owner
data = {
2015-04-26 12:48:37 +05:30
before: Gitlab::Git::BLANK_SHA,
2014-09-02 18:07:02 +05:30
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
}
}
@event = Event.create(
project: project,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
end
2015-04-26 12:48:37 +05:30
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) }
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
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
2014-09-02 18:07:02 +05:30
end