Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-25 23:21:38 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-25 23:21:38 +0400
commit7bab81b199936597e1c762278bd16167de073342 (patch)
treebd8511dad295c698fb4d87ea08a2fa060b6bcdee /spec
parent9611640e3891e222a08d9a7ba1a7cc9d73c4e641 (diff)
Move git post push logic to service
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_hooks_spec.rb128
-rw-r--r--spec/models/project_spec.rb3
-rw-r--r--spec/services/git_push_service.rb111
3 files changed, 111 insertions, 131 deletions
diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb
deleted file mode 100644
index 65205538213..00000000000
--- a/spec/models/project_hooks_spec.rb
+++ /dev/null
@@ -1,128 +0,0 @@
-require 'spec_helper'
-
-describe Project, "Hooks" do
- let(:project) { create(:project) }
-
- before do
- @key = create(:key, user: project.owner)
- @user = @key.user
- @key_id = @key.identifier
- end
-
- describe "Post Receive Event" do
- it "should create push event" do
- oldrev, newrev, ref = '00000000000000000000000000000000', 'newrev', 'refs/heads/master'
- data = project.post_receive_data(oldrev, newrev, ref, @user)
-
- project.observe_push(data)
- event = Event.last
-
- event.should_not be_nil
- event.project.should == project
- event.action.should == Event::PUSHED
- event.data.should == data
- end
- end
-
- describe "Project hooks" do
- context "with no web hooks" do
- it "raises no errors" do
- lambda {
- project.execute_hooks({})
- }.should_not raise_error
- end
- end
-
- context "with web hooks" do
- before do
- @project_hook = create(:project_hook)
- @project_hook_2 = create(:project_hook)
- project.hooks << [@project_hook, @project_hook_2]
-
- stub_request(:post, @project_hook.url)
- stub_request(:post, @project_hook_2.url)
- end
-
- it "executes multiple web hook" do
- @project_hook.should_receive(:async_execute).once
- @project_hook_2.should_receive(:async_execute).once
-
- project.trigger_post_receive('oldrev', 'newrev', 'refs/heads/master', @user)
- end
- end
-
- context "does not execute web hooks" do
- before do
- @project_hook = create(:project_hook)
- project.hooks << [@project_hook]
- end
-
- it "when pushing a branch for the first time" do
- @project_hook.should_not_receive(:execute)
- project.trigger_post_receive('00000000000000000000000000000000', 'newrev', 'refs/heads/master', @user)
- end
-
- it "when pushing tags" do
- @project_hook.should_not_receive(:execute)
- project.trigger_post_receive('oldrev', 'newrev', 'refs/tags/v1.0.0', @user)
- end
- end
-
- context "when pushing new branches" do
-
- end
-
- context "when gathering commit data" do
- before do
- @oldrev, @newrev, @ref = project.repository.fresh_commits(2).last.sha,
- project.repository.fresh_commits(2).first.sha, 'refs/heads/master'
- @commit = project.repository.fresh_commits(2).first
-
- # Fill nil/empty attributes
- project.description = "This is a description"
-
- @data = project.post_receive_data(@oldrev, @newrev, @ref, @user)
- end
-
- subject { @data }
-
- it { should include(before: @oldrev) }
- it { should include(after: @newrev) }
- it { should include(ref: @ref) }
- it { should include(user_id: project.owner.id) }
- it { should include(user_name: project.owner.name) }
-
- context "with repository data" do
- subject { @data[:repository] }
-
- it { should include(name: project.name) }
- it { should include(url: project.url_to_repo) }
- it { should include(description: project.description) }
- it { should include(homepage: project.web_url) }
- 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: "#{Gitlab.config.gitlab.url}/#{project.code}/commit/#{@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
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 5c27f363401..48432eac147 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -72,11 +72,8 @@ describe Project do
it { should respond_to(:url_to_repo) }
it { should respond_to(:repo_exists?) }
it { should respond_to(:satellite) }
- it { should respond_to(:observe_push) }
it { should respond_to(:update_merge_requests) }
it { should respond_to(:execute_hooks) }
- it { should respond_to(:post_receive_data) }
- it { should respond_to(:trigger_post_receive) }
it { should respond_to(:transfer) }
it { should respond_to(:name_with_namespace) }
it { should respond_to(:namespace_owner) }
diff --git a/spec/services/git_push_service.rb b/spec/services/git_push_service.rb
new file mode 100644
index 00000000000..9fc5fd62531
--- /dev/null
+++ b/spec/services/git_push_service.rb
@@ -0,0 +1,111 @@
+require 'spec_helper'
+
+describe GitPushService do
+ let (:user) { create :user }
+ let (:project) { create :project }
+ let (:service) { GitPushService.new }
+
+ before do
+ @oldrev = 'b98a310def241a6fd9c9a9a3e7934c48e498fe81'
+ @newrev = 'b19a04f53caeebf4fe5ec2327cb83e9253dc91bb'
+ @ref = 'refs/heads/master'
+ end
+
+ describe "Git Push Data" do
+ before do
+ service.execute(project, user, @oldrev, @newrev, @ref)
+ @push_data = service.push_data
+ @commit = project.repository.commit(@newrev)
+ end
+
+ subject { @push_data }
+
+ it { should include(before: @oldrev) }
+ it { should include(after: @newrev) }
+ it { should include(ref: @ref) }
+ it { should include(user_id: user.id) }
+ it { should include(user_name: user.name) }
+
+ context "with repository data" do
+ subject { @push_data[:repository] }
+
+ it { should include(name: project.name) }
+ it { should include(url: project.url_to_repo) }
+ it { should include(description: project.description) }
+ it { should include(homepage: project.web_url) }
+ end
+
+ context "with commits" do
+ subject { @push_data[:commits] }
+
+ it { should be_an(Array) }
+ it { should have(1).element }
+
+ context "the commit" do
+ subject { @push_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: "#{Gitlab.config.gitlab.url}/#{project.code}/commit/#{@commit.id}") }
+
+ context "with a author" do
+ subject { @push_data[:commits].first[:author] }
+
+ it { should include(name: @commit.author_name) }
+ it { should include(email: @commit.author_email) }
+ end
+ end
+ end
+ end
+
+ describe "Push Event" do
+ before do
+ service.execute(project, user, @oldrev, @newrev, @ref)
+ @event = Event.last
+ end
+
+ it { @event.should_not be_nil }
+ it { @event.project.should == project }
+ it { @event.action.should == Event::PUSHED }
+ it { @event.data.should == service.push_data }
+ end
+
+ describe "Web Hooks" do
+ context "with web hooks" do
+ before do
+ @project_hook = create(:project_hook)
+ @project_hook_2 = create(:project_hook)
+ project.hooks << [@project_hook, @project_hook_2]
+
+ stub_request(:post, @project_hook.url)
+ stub_request(:post, @project_hook_2.url)
+ end
+
+ it "executes multiple web hook" do
+ @project_hook.should_receive(:async_execute).once
+ @project_hook_2.should_receive(:async_execute).once
+
+ service.execute(project, user, @oldrev, @newrev, @ref)
+ end
+ end
+
+ context "does not execute web hooks" do
+ before do
+ @project_hook = create(:project_hook)
+ project.hooks << [@project_hook]
+ end
+
+ it "when pushing a branch for the first time" do
+ @project_hook.should_not_receive(:execute)
+ service.execute(project, user, '00000000000000000000000000000000', 'newrev', 'refs/heads/master')
+ end
+
+ it "when pushing tags" do
+ @project_hook.should_not_receive(:execute)
+ service.execute(project, user, 'newrev', 'newrev', 'refs/tags/v1.0.0')
+ end
+ end
+ end
+end
+