Event entity created
Observe issue, merge request, note creation - create event register push event
This commit is contained in:
parent
85954621a3
commit
0a0710a548
16 changed files with 310 additions and 104 deletions
|
@ -32,10 +32,14 @@ end
|
|||
|
||||
Factory.add(:issue, Issue) do |obj|
|
||||
obj.title = Faker::Lorem.sentence
|
||||
obj.author = Factory :user
|
||||
obj.assignee = Factory :user
|
||||
end
|
||||
|
||||
Factory.add(:merge_request, MergeRequest) do |obj|
|
||||
obj.title = Faker::Lorem.sentence
|
||||
obj.author = Factory :user
|
||||
obj.assignee = Factory :user
|
||||
obj.source_branch = "master"
|
||||
obj.target_branch = "master"
|
||||
obj.closed = false
|
||||
|
@ -64,3 +68,8 @@ Factory.add(:wikis, WebHook) do |obj|
|
|||
obj.title = Faker::Lorem.sentence
|
||||
obj.content = Faker::Lorem.sentence
|
||||
end
|
||||
|
||||
Factory.add(:event, Event) do |obj|
|
||||
obj.title = Faker::Lorem.sentence
|
||||
obj.project = Factory(:project)
|
||||
end
|
||||
|
|
44
spec/models/activity_observer_spec.rb
Normal file
44
spec/models/activity_observer_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ActivityObserver do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
def self.it_should_be_valid_event
|
||||
it { @event.should_not be_nil }
|
||||
it { @event.project.should == project }
|
||||
end
|
||||
|
||||
describe "Merge Request created" do
|
||||
before do
|
||||
@merge_request = Factory :merge_request, :project => project
|
||||
@event = Event.last
|
||||
end
|
||||
|
||||
it_should_be_valid_event
|
||||
it { @event.action.should == Event::Created }
|
||||
it { @event.target.should == @merge_request }
|
||||
end
|
||||
|
||||
describe "Issue created" do
|
||||
before do
|
||||
@issue = Factory :issue, :project => project
|
||||
@event = Event.last
|
||||
end
|
||||
|
||||
it_should_be_valid_event
|
||||
it { @event.action.should == Event::Created }
|
||||
it { @event.target.should == @issue }
|
||||
end
|
||||
|
||||
describe "Issue commented" do
|
||||
before do
|
||||
@issue = Factory :issue, :project => project
|
||||
@note = Factory :note, :noteable => @issue, :project => project
|
||||
@event = Event.last
|
||||
end
|
||||
|
||||
it_should_be_valid_event
|
||||
it { @event.action.should == Event::Commented }
|
||||
it { @event.target.should == @note }
|
||||
end
|
||||
end
|
32
spec/models/event_spec.rb
Normal file
32
spec/models/event_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# == 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 not null
|
||||
# updated_at :datetime not null
|
||||
# action :integer
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Event do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:project) }
|
||||
end
|
||||
|
||||
describe "Creation" do
|
||||
before do
|
||||
@event = Factory :event
|
||||
end
|
||||
|
||||
it "should create a valid event" do
|
||||
@event.should be_valid
|
||||
end
|
||||
end
|
||||
end
|
115
spec/models/project_hooks_spec.rb
Normal file
115
spec/models/project_hooks_spec.rb
Normal file
|
@ -0,0 +1,115 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Project, "Hooks" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
describe "Post Receive Event" do
|
||||
it "should create push event" do
|
||||
oldrev, newrev, ref = '00000000000000000000000000000000', 'newrev', 'refs/heads/master'
|
||||
project.observe_push(oldrev, newrev, ref)
|
||||
event = Event.last
|
||||
|
||||
event.should_not be_nil
|
||||
event.project.should == project
|
||||
event.action.should == Event::Pushed
|
||||
event.data == project.web_hook_data(oldrev, newrev, ref)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Web hooks" do
|
||||
context "with no web hooks" do
|
||||
it "raises no errors" do
|
||||
lambda {
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'ref')
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "with web hooks" do
|
||||
before do
|
||||
@webhook = Factory(:web_hook)
|
||||
@webhook_2 = Factory(:web_hook)
|
||||
project.web_hooks << [@webhook, @webhook_2]
|
||||
end
|
||||
|
||||
it "executes multiple web hook" do
|
||||
@webhook.should_receive(:execute).once
|
||||
@webhook_2.should_receive(:execute).once
|
||||
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master')
|
||||
end
|
||||
end
|
||||
|
||||
context "does not execute web hooks" do
|
||||
before do
|
||||
@webhook = Factory(:web_hook)
|
||||
project.web_hooks << [@webhook]
|
||||
end
|
||||
|
||||
it "when pushing a branch for the first time" do
|
||||
@webhook.should_not_receive(:execute)
|
||||
project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master')
|
||||
end
|
||||
|
||||
it "when pushing tags" do
|
||||
@webhook.should_not_receive(:execute)
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0')
|
||||
end
|
||||
end
|
||||
|
||||
context "when pushing new branches" do
|
||||
|
||||
end
|
||||
|
||||
context "when gathering commit data" do
|
||||
before do
|
||||
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
|
||||
@commit = project.fresh_commits(2).first
|
||||
|
||||
# Fill nil/empty attributes
|
||||
project.description = "This is a description"
|
||||
|
||||
@data = project.web_hook_data(@oldrev, @newrev, @ref)
|
||||
end
|
||||
|
||||
subject { @data }
|
||||
|
||||
it { should include(before: @oldrev) }
|
||||
it { should include(after: @newrev) }
|
||||
it { should include(ref: @ref) }
|
||||
|
||||
context "with repository data" do
|
||||
subject { @data[:repository] }
|
||||
|
||||
it { should include(name: project.name) }
|
||||
it { should include(url: project.web_url) }
|
||||
it { should include(description: project.description) }
|
||||
it { should include(homepage: project.web_url) }
|
||||
it { should include(private: project.private?) }
|
||||
end
|
||||
|
||||
context "with commits" do
|
||||
subject { @data[:commits] }
|
||||
|
||||
it { should be_an(Array) }
|
||||
it { should have(1).element }
|
||||
|
||||
context "the commit" do
|
||||
subject { @data[:commits].first }
|
||||
|
||||
it { should include(id: @commit.id) }
|
||||
it { should include(message: @commit.safe_message) }
|
||||
it { should include(timestamp: @commit.date.xmlschema) }
|
||||
it { should include(url: "http://localhost/#{project.code}/commits/#{@commit.id}") }
|
||||
|
||||
context "with a author" do
|
||||
subject { @data[:commits].first[:author] }
|
||||
|
||||
it { should include(name: @commit.author_name) }
|
||||
it { should include(email: @commit.author_email) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Project do
|
||||
describe "Associations" do
|
||||
it { should have_many(:events) }
|
||||
it { should have_many(:users) }
|
||||
it { should have_many(:users_projects) }
|
||||
it { should have_many(:issues) }
|
||||
|
@ -69,106 +70,6 @@ describe Project do
|
|||
end
|
||||
end
|
||||
|
||||
describe "web hooks" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
context "with no web hooks" do
|
||||
it "raises no errors" do
|
||||
lambda {
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'ref')
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "with web hooks" do
|
||||
before do
|
||||
@webhook = Factory(:web_hook)
|
||||
@webhook_2 = Factory(:web_hook)
|
||||
project.web_hooks << [@webhook, @webhook_2]
|
||||
end
|
||||
|
||||
it "executes multiple web hook" do
|
||||
@webhook.should_receive(:execute).once
|
||||
@webhook_2.should_receive(:execute).once
|
||||
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master')
|
||||
end
|
||||
end
|
||||
|
||||
context "does not execute web hooks" do
|
||||
before do
|
||||
@webhook = Factory(:web_hook)
|
||||
project.web_hooks << [@webhook]
|
||||
end
|
||||
|
||||
it "when pushing a branch for the first time" do
|
||||
@webhook.should_not_receive(:execute)
|
||||
project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master')
|
||||
end
|
||||
|
||||
it "when pushing tags" do
|
||||
@webhook.should_not_receive(:execute)
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0')
|
||||
end
|
||||
end
|
||||
|
||||
context "when pushing new branches" do
|
||||
|
||||
end
|
||||
|
||||
context "when gathering commit data" do
|
||||
before do
|
||||
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
|
||||
@commit = project.fresh_commits(2).first
|
||||
|
||||
# Fill nil/empty attributes
|
||||
project.description = "This is a description"
|
||||
|
||||
@data = project.web_hook_data(@oldrev, @newrev, @ref)
|
||||
end
|
||||
|
||||
subject { @data }
|
||||
|
||||
it { should include(before: @oldrev) }
|
||||
it { should include(after: @newrev) }
|
||||
it { should include(ref: @ref) }
|
||||
|
||||
context "with repository data" do
|
||||
subject { @data[:repository] }
|
||||
|
||||
it { should include(name: project.name) }
|
||||
it { should include(url: project.web_url) }
|
||||
it { should include(description: project.description) }
|
||||
it { should include(homepage: project.web_url) }
|
||||
it { should include(private: project.private?) }
|
||||
end
|
||||
|
||||
context "with commits" do
|
||||
subject { @data[:commits] }
|
||||
|
||||
it { should be_an(Array) }
|
||||
it { should have(1).element }
|
||||
|
||||
context "the commit" do
|
||||
subject { @data[:commits].first }
|
||||
|
||||
it { should include(id: @commit.id) }
|
||||
it { should include(message: @commit.safe_message) }
|
||||
it { should include(timestamp: @commit.date.xmlschema) }
|
||||
it { should include(url: "http://localhost/#{project.code}/commits/#{@commit.id}") }
|
||||
|
||||
context "with a author" do
|
||||
subject { @data[:commits].first[:author] }
|
||||
|
||||
it { should include(name: @commit.author_name) }
|
||||
it { should include(email: @commit.author_email) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe "updates" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
|
@ -303,5 +204,6 @@ end
|
|||
# issues_enabled :boolean default(TRUE), not null
|
||||
# wall_enabled :boolean default(TRUE), not null
|
||||
# merge_requests_enabled :boolean default(TRUE), not null
|
||||
# wiki_enabled :boolean default(TRUE), not null
|
||||
#
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ end
|
|||
# project_id :integer not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# repo_access :integer default(0), not null
|
||||
# project_access :integer default(0), not null
|
||||
#
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue