Merge branch 'master' into deploy_keys
Conflicts: app/models/project.rb
This commit is contained in:
commit
f8ad4d2b42
35 changed files with 556 additions and 90 deletions
|
@ -55,3 +55,7 @@ Factory.add(:key, Key) do |obj|
|
|||
obj.title = "Example key"
|
||||
obj.key = File.read(File.join(Rails.root, "db", "pkey.example"))
|
||||
end
|
||||
|
||||
Factory.add(:web_hook, WebHook) do |obj|
|
||||
obj.url = Faker::Internet.url
|
||||
end
|
||||
|
|
67
spec/helpers/commit_helper_spec.rb
Normal file
67
spec/helpers/commit_helper_spec.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require "spec_helper"
|
||||
include Haml::Helpers
|
||||
|
||||
describe CommitsHelper do
|
||||
|
||||
before do
|
||||
@project = Factory :project
|
||||
@other_project = Factory :project, :path => "OtherPath", :code => "OtherCode"
|
||||
@fake_user = Factory :user
|
||||
@valid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project
|
||||
@invalid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @other_project
|
||||
end
|
||||
|
||||
it "should provides return message untouched if no issue number present" do
|
||||
message = "Dummy message without issue number"
|
||||
|
||||
commit_msg_with_link_to_issues(@project, message).should eql message
|
||||
end
|
||||
|
||||
it "should returns message handled by preserve" do
|
||||
message = "My brand new
|
||||
Commit on multiple
|
||||
lines !"
|
||||
|
||||
#\n are converted to 
 as specified in preserve_rspec
|
||||
expected = "My brand new
 Commit on multiple
 lines !"
|
||||
|
||||
commit_msg_with_link_to_issues(@project, message).should eql expected
|
||||
end
|
||||
|
||||
it "should returns empty string if message undefined" do
|
||||
commit_msg_with_link_to_issues(@project, nil).should eql ''
|
||||
end
|
||||
|
||||
it "should returns link_to issue for one valid issue in message" do
|
||||
issue_id = @valid_issue.id
|
||||
message = "One commit message ##{issue_id}"
|
||||
expected = "One commit message <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"
|
||||
|
||||
commit_msg_with_link_to_issues(@project, message).should eql expected
|
||||
end
|
||||
|
||||
it "should returns message untouched for one invalid issue in message" do
|
||||
issue_id = @invalid_issue.id
|
||||
message = "One commit message ##{issue_id}"
|
||||
|
||||
commit_msg_with_link_to_issues(@project, message).should eql message
|
||||
end
|
||||
|
||||
it "should handle multiple issue references in commit message" do
|
||||
issue_id = @valid_issue.id
|
||||
invalid_issue_id = @invalid_issue.id
|
||||
|
||||
message = "One big commit message with a valid issue ##{issue_id} and an invalid one ##{invalid_issue_id}.
|
||||
We reference valid ##{issue_id} multiple times (##{issue_id}) as the invalid ##{invalid_issue_id} is also
|
||||
referenced another time (##{invalid_issue_id})"
|
||||
|
||||
expected = "One big commit message with a valid issue <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"+
|
||||
" and an invalid one ##{invalid_issue_id}.
 "+
|
||||
"We reference valid <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a> multiple times "+
|
||||
"(<a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>) "+
|
||||
"as the invalid ##{invalid_issue_id} is also
 referenced another time (##{invalid_issue_id})"
|
||||
|
||||
commit_msg_with_link_to_issues(@project, message).should eql expected
|
||||
end
|
||||
|
||||
end
|
|
@ -7,6 +7,7 @@ describe Project do
|
|||
it { should have_many(:issues) }
|
||||
it { should have_many(:notes) }
|
||||
it { should have_many(:snippets) }
|
||||
it { should have_many(:web_hooks).dependent(:destroy) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
|
@ -33,6 +34,7 @@ describe Project do
|
|||
it { should respond_to(:repo) }
|
||||
it { should respond_to(:tags) }
|
||||
it { should respond_to(:commit) }
|
||||
it { should respond_to(:commits_between) }
|
||||
end
|
||||
|
||||
it "should not allow 'gitolite-admin' as repo name" do
|
||||
|
@ -50,6 +52,11 @@ describe Project do
|
|||
project.path_to_repo.should == File.join(Rails.root, "tmp", "tests", "somewhere")
|
||||
end
|
||||
|
||||
it "returns the full web URL for this repo" do
|
||||
project = Project.new(:code => "somewhere")
|
||||
project.web_url.should == "#{GIT_HOST['host']}/somewhere"
|
||||
end
|
||||
|
||||
describe :valid_repo? do
|
||||
it "should be valid repo" do
|
||||
project = Factory :project
|
||||
|
@ -62,6 +69,106 @@ 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 }
|
||||
|
||||
|
@ -107,6 +214,21 @@ describe Project do
|
|||
it { project.fresh_commits.last.id.should == "0dac878dbfe0b9c6104a87d65fe999149a8d862c" }
|
||||
end
|
||||
|
||||
describe "commits_between" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
subject do
|
||||
commits = project.commits_between("a6d1d4aca0c85816ddfd27d93773f43a31395033",
|
||||
"2fb376f61875b58bceee0492e270e9c805294b1a")
|
||||
commits.map { |c| c.id }
|
||||
end
|
||||
|
||||
it { should have(2).elements }
|
||||
it { should include("2fb376f61875b58bceee0492e270e9c805294b1a") }
|
||||
it { should include("4571e226fbcd7be1af16e9fa1e13b7ac003bebdf") }
|
||||
it { should_not include("a6d1d4aca0c85816ddfd27d93773f43a31395033") }
|
||||
end
|
||||
|
||||
describe "Git methods" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
|
|
54
spec/models/web_hook_spec.rb
Normal file
54
spec/models/web_hook_spec.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe WebHook do
|
||||
describe "Associations" do
|
||||
it { should belong_to :project }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { should validate_presence_of(:url) }
|
||||
|
||||
context "url format" do
|
||||
it { should allow_value("http://example.com").for(:url) }
|
||||
it { should allow_value("https://excample.com").for(:url) }
|
||||
it { should allow_value("http://test.com/api").for(:url) }
|
||||
it { should allow_value("http://test.com/api?key=abc").for(:url) }
|
||||
it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) }
|
||||
|
||||
it { should_not allow_value("example.com").for(:url) }
|
||||
it { should_not allow_value("ftp://example.com").for(:url) }
|
||||
it { should_not allow_value("herp-and-derp").for(:url) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "execute" do
|
||||
before(:each) do
|
||||
@webhook = Factory :web_hook
|
||||
@project = Factory :project
|
||||
@project.web_hooks << [@webhook]
|
||||
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'}
|
||||
|
||||
WebMock.stub_request(:post, @webhook.url)
|
||||
end
|
||||
|
||||
it "POSTs to the web hook URL" do
|
||||
@webhook.execute(@data)
|
||||
WebMock.should have_requested(:post, @webhook.url).once
|
||||
end
|
||||
|
||||
it "POSTs the data as JSON" do
|
||||
json = @data.to_json
|
||||
|
||||
@webhook.execute(@data)
|
||||
WebMock.should have_requested(:post, @webhook.url).with(body: json).once
|
||||
end
|
||||
|
||||
it "catches exceptions" do
|
||||
WebHook.should_receive(:post).and_raise("Some HTTP Post error")
|
||||
|
||||
lambda {
|
||||
@webhook.execute(@data)
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Dashboard" do
|
||||
before { login_as :user }
|
||||
before do
|
||||
@project = Factory :project
|
||||
@user = User.create(:email => "test917@mail.com",
|
||||
:name => "John Smith",
|
||||
:password => "123456",
|
||||
:password_confirmation => "123456")
|
||||
@project.add_access(@user, :read, :write)
|
||||
login_with(@user)
|
||||
end
|
||||
|
||||
describe "GET /dashboard" do
|
||||
before do
|
||||
@project = Factory :project
|
||||
@project.add_access(@user, :read, :write)
|
||||
visit dashboard_path
|
||||
end
|
||||
|
||||
|
@ -20,12 +26,14 @@ describe "Dashboard" do
|
|||
end
|
||||
end
|
||||
|
||||
it "should have news feed" do
|
||||
within "#news-feed" do
|
||||
page.should have_content("commit")
|
||||
page.should have_content(@project.commit.author.name)
|
||||
page.should have_content(@project.commit.safe_message)
|
||||
end
|
||||
end
|
||||
# Temporary disabled cause of travis
|
||||
# TODO: fix or rewrite
|
||||
#it "should have news feed" do
|
||||
#within "#news-feed" do
|
||||
#page.should have_content("commit")
|
||||
#page.should have_content(@project.commit.author.name)
|
||||
#page.should have_content(@project.commit.safe_message)
|
||||
#end
|
||||
#end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,37 +1,36 @@
|
|||
require 'spec_helper'
|
||||
require 'benchmark'
|
||||
|
||||
describe "Projects" do
|
||||
before { login_as :user }
|
||||
|
||||
describe "GET /projects/tree" do
|
||||
describe "head" do
|
||||
before do
|
||||
@project = Factory :project
|
||||
@project.add_access(@user, :read)
|
||||
|
||||
end
|
||||
|
||||
it "should be fast" do
|
||||
time = Benchmark.realtime do
|
||||
visit tree_project_ref_path(@project, @project.root_ref)
|
||||
end
|
||||
(time < 1.0).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe ValidCommit::ID do
|
||||
before do
|
||||
@project = Factory :project
|
||||
@project.add_access(@user, :read)
|
||||
end
|
||||
|
||||
it "should be fast" do
|
||||
time = Benchmark.realtime do
|
||||
visit tree_project_ref_path(@project, ValidCommit::ID)
|
||||
end
|
||||
(time < 1.0).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#require 'spec_helper'
|
||||
#require 'benchmark'
|
||||
#
|
||||
#describe "Projects" do
|
||||
# before { login_as :user }
|
||||
#
|
||||
# describe "GET /projects/tree" do
|
||||
# describe "head" do
|
||||
# before do
|
||||
# @project = Factory :project
|
||||
# @project.add_access(@user, :read)
|
||||
# end
|
||||
#
|
||||
# it "should be fast" do
|
||||
# time = Benchmark.realtime do
|
||||
# visit tree_project_ref_path(@project, @project.root_ref)
|
||||
# end
|
||||
# (time < 1.0).should be_true
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# describe ValidCommit::ID do
|
||||
# before do
|
||||
# @project = Factory :project
|
||||
# @project.add_access(@user, :read)
|
||||
# end
|
||||
#
|
||||
# it "should be fast" do
|
||||
# time = Benchmark.realtime do
|
||||
# visit tree_project_ref_path(@project, ValidCommit::ID)
|
||||
# end
|
||||
# (time < 1.0).should be_true
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#end
|
||||
|
|
|
@ -8,6 +8,7 @@ require 'rspec/rails'
|
|||
require 'capybara/rails'
|
||||
require 'capybara/rspec'
|
||||
require 'capybara/dsl'
|
||||
require 'webmock/rspec'
|
||||
require 'factories'
|
||||
require 'monkeypatch'
|
||||
|
||||
|
@ -48,6 +49,8 @@ RSpec.configure do |config|
|
|||
end
|
||||
|
||||
DatabaseCleaner.start
|
||||
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
end
|
||||
|
||||
config.after do
|
||||
|
|
26
spec/workers/post_receive_spec.rb
Normal file
26
spec/workers/post_receive_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PostReceive do
|
||||
|
||||
context "as a resque worker" do
|
||||
it "reponds to #perform" do
|
||||
PostReceive.should respond_to(:perform)
|
||||
end
|
||||
end
|
||||
|
||||
context "web hooks" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
it "it retrieves the correct project" do
|
||||
Project.should_receive(:find_by_path).with(project.path)
|
||||
PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master')
|
||||
end
|
||||
|
||||
it "asks the project to execute web hooks" do
|
||||
Project.stub(find_by_path: project)
|
||||
project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master')
|
||||
|
||||
PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue