Skip to content

Commit 9773ccc

Browse files
committed
sidekiq with green tests
1 parent 71bd956 commit 9773ccc

File tree

14 files changed

+48
-68
lines changed

14 files changed

+48
-68
lines changed

Diff for: Procfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
web: bundle exec rails s -p $PORT
2-
worker: bundle exec rake sidekiq:start
2+
worker: bundle exec sidekiq -q post_receive,mailer,system_hook,common,default
File renamed without changes.

Diff for: features/steps/admin/admin_active_tab.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class AdminActiveTab < Spinach::FeatureSteps
2828
end
2929

3030
Then 'the active main tab should be Resque' do
31-
ensure_active_main_tab('Resque')
31+
ensure_active_main_tab('Background Jobs')
3232
end
3333
end

Diff for: features/support/env.rb

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
require 'rspec'
77
require 'database_cleaner'
88
require 'spinach/capybara'
9+
require 'sidekiq/testing/inline'
10+
911

1012
%w(gitolite_stub stubbed_repository valid_commit).each do |f|
1113
require Rails.root.join('spec', 'support', f)

Diff for: lib/hooks/post-receive

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
# Version 4.1
34
# This file was placed here by GitLab. It makes sure that your pushed commits
45
# will be processed properly.
56

Diff for: lib/tasks/gitlab/check.rake

+3-3
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ namespace :gitlab do
871871

872872

873873
namespace :resque do
874-
desc "GITLAB | Check the configuration of Resque"
874+
desc "GITLAB | Check the configuration of Sidekiq"
875875
task check: :environment do
876876
warn_user_is_not_gitlab
877877
start_checking "Resque"
@@ -888,7 +888,7 @@ namespace :gitlab do
888888
def check_resque_running
889889
print "Running? ... "
890890

891-
if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/)
891+
if run_and_match("ps aux | grep -i sidekiq", /sidekiq-[\d\.]+:.+$/)
892892
puts "yes".green
893893
else
894894
puts "no".red
@@ -899,7 +899,7 @@ namespace :gitlab do
899899
)
900900
for_more_information(
901901
see_installation_guide_section("Install Init Script"),
902-
"see log/resque.log for possible errors"
902+
"see log/sidekiq.log for possible errors"
903903
)
904904
fix_and_rerun
905905
end

Diff for: spec/models/system_hook_spec.rb

+6-19
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,40 @@
2323
end
2424

2525
it "project_create hook" do
26-
with_resque do
27-
project = create(:project)
28-
end
26+
project = create(:project)
2927
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
3028
end
3129

3230
it "project_destroy hook" do
3331
project = create(:project)
34-
with_resque do
35-
project.destroy
36-
end
32+
project.destroy
3733
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
3834
end
3935

4036
it "user_create hook" do
41-
with_resque do
42-
create(:user)
43-
end
37+
create(:user)
4438
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
4539
end
4640

4741
it "user_destroy hook" do
4842
user = create(:user)
49-
with_resque do
50-
user.destroy
51-
end
43+
user.destroy
5244
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
5345
end
5446

5547
it "project_create hook" do
5648
user = create(:user)
5749
project = create(:project)
58-
with_resque do
59-
project.team << [user, :master]
60-
end
50+
project.team << [user, :master]
6151
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
6252
end
6353

6454
it "project_destroy hook" do
6555
user = create(:user)
6656
project = create(:project)
6757
project.team << [user, :master]
68-
with_resque do
69-
project.users_projects.clear
70-
end
58+
project.users_projects.clear
7159
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
7260
end
7361
end
74-
7562
end

Diff for: spec/observers/issue_observer_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
end
2222

2323
it 'sends an email to the assignee' do
24-
Notify.should_receive(:new_issue_email).with(issue.id).
25-
and_return(double(deliver: true))
24+
Notify.should_receive(:new_issue_email).with(issue.id)
2625

2726
subject.after_create(issue)
2827
end
@@ -71,6 +70,7 @@
7170
context 'a status "closed"' do
7271
it 'note is created if the issue is being closed' do
7372
issue.should_receive(:is_being_closed?).and_return(true)
73+
Notify.should_receive(:issue_status_changed_email).twice
7474
Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
7575

7676
subject.after_update(issue)
@@ -85,7 +85,7 @@
8585

8686
it 'notification is delivered if the issue being closed' do
8787
issue.stub(:is_being_closed?).and_return(true)
88-
Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true))
88+
Notify.should_receive(:issue_status_changed_email).twice
8989
Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
9090

9191
subject.after_update(issue)
@@ -104,7 +104,7 @@
104104
issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
105105
issue_without_assignee.stub(:is_being_closed?).and_return(true)
106106
issue_without_assignee.stub(:is_being_reopened?).and_return(false)
107-
Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true))
107+
Notify.should_receive(:issue_status_changed_email).once
108108
Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed')
109109

110110
subject.after_update(issue_without_assignee)
@@ -113,6 +113,7 @@
113113

114114
context 'a status "reopened"' do
115115
it 'note is created if the issue is being reopened' do
116+
Notify.should_receive(:issue_status_changed_email).twice
116117
issue.should_receive(:is_being_reopened?).and_return(true)
117118
Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
118119

@@ -128,7 +129,7 @@
128129

129130
it 'notification is delivered if the issue being reopened' do
130131
issue.stub(:is_being_reopened?).and_return(true)
131-
Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true))
132+
Notify.should_receive(:issue_status_changed_email).twice
132133
Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
133134

134135
subject.after_update(issue)
@@ -147,7 +148,7 @@
147148
issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
148149
issue_without_assignee.stub(:is_being_closed?).and_return(false)
149150
issue_without_assignee.stub(:is_being_reopened?).and_return(true)
150-
Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true))
151+
Notify.should_receive(:issue_status_changed_email).once
151152
Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened')
152153

153154
subject.after_update(issue_without_assignee)
@@ -164,8 +165,7 @@
164165
end
165166

166167
def it_sends_a_reassigned_email_to(recipient)
167-
Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id).
168-
and_return(double(deliver: true))
168+
Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id)
169169
end
170170

171171
def it_does_not_send_a_reassigned_email_to(recipient)

Diff for: spec/observers/merge_request_observer_spec.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
end
2222

2323
it 'sends an email to the assignee' do
24-
Notify.should_receive(:new_merge_request_email).with(mr.id).
25-
and_return(double(deliver: true))
26-
24+
Notify.should_receive(:new_merge_request_email).with(mr.id)
2725
subject.after_create(mr)
2826
end
2927

@@ -158,8 +156,7 @@
158156
end
159157

160158
def it_sends_a_reassigned_email_to(recipient)
161-
Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id).
162-
and_return(double(deliver: true))
159+
Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id)
163160
end
164161

165162
def it_does_not_send_a_reassigned_email_to(recipient)

Diff for: spec/observers/note_observer_spec.rb

+13-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
subject { NoteObserver.instance }
55

66
let(:team_without_author) { (1..2).map { |n| double :user, id: n } }
7-
let(:delivery_success) { double deliver: true }
87

98
describe '#after_create' do
109
let(:note) { double :note }
@@ -45,13 +44,13 @@
4544
note.stub(:id).and_return(42)
4645
author = double :user, id: 1
4746
note.stub(:commit_author).and_return(author)
48-
Notify.should_receive(:note_commit_email).and_return(delivery_success)
47+
Notify.should_receive(:note_commit_email)
4948

5049
subject.after_create(note)
5150
end
5251

5352
it 'does not notify the author of a commit when not flagged to notify the author' do
54-
Notify.should_not_receive(:note_commit_email)
53+
notify.should_not_receive(:note_commit_email)
5554

5655
subject.after_create(note)
5756
end
@@ -71,45 +70,45 @@
7170
context 'notifies team of a new note on' do
7271
it 'a commit' do
7372
note.stub(:noteable_type).and_return('Commit')
74-
Notify.should_receive(:note_commit_email).twice.and_return(delivery_success)
73+
notify.should_receive(:note_commit_email).twice
7574

7675
subject.send(:notify_team, note)
7776
end
7877

7978
it 'an issue' do
8079
note.stub(:noteable_type).and_return('Issue')
81-
Notify.should_receive(:note_issue_email).twice.and_return(delivery_success)
80+
notify.should_receive(:note_issue_email).twice
8281

8382
subject.send(:notify_team, note)
8483
end
8584

8685
it 'a wiki page' do
8786
note.stub(:noteable_type).and_return('Wiki')
88-
Notify.should_receive(:note_wiki_email).twice.and_return(delivery_success)
87+
notify.should_receive(:note_wiki_email).twice
8988

9089
subject.send(:notify_team, note)
9190
end
9291

9392
it 'a merge request' do
9493
note.stub(:noteable_type).and_return('MergeRequest')
95-
Notify.should_receive(:note_merge_request_email).twice.and_return(delivery_success)
94+
notify.should_receive(:note_merge_request_email).twice
9695

9796
subject.send(:notify_team, note)
9897
end
9998

10099
it 'a wall' do
101100
# Note: wall posts have #noteable_type of nil
102101
note.stub(:noteable_type).and_return(nil)
103-
Notify.should_receive(:note_wall_email).twice.and_return(delivery_success)
102+
notify.should_receive(:note_wall_email).twice
104103

105104
subject.send(:notify_team, note)
106105
end
107106
end
108107

109108
it 'does nothing for a new note on a snippet' do
110-
note.stub(:noteable_type).and_return('Snippet')
109+
note.stub(:noteable_type).and_return('Snippet')
111110

112-
subject.send(:notify_team, note).should be_nil
111+
subject.send(:notify_team, note).should be_nil
113112
end
114113
end
115114

@@ -125,4 +124,8 @@
125124
subject.send(:team_without_note_author, note).should == team_without_author
126125
end
127126
end
127+
128+
def notify
129+
Notify
130+
end
128131
end

Diff for: spec/observers/user_observer_spec.rb

+3-13
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,14 @@
1010
end
1111

1212
context 'when a new user is created' do
13-
let(:user) { double(:user, id: 42,
14-
password: 'P@ssword!',
15-
name: 'John',
16-
17-
username: 'root',
18-
create_namespace: true) }
19-
let(:notification) { double :notification }
20-
2113
it 'sends an email' do
22-
notification.should_receive(:deliver)
23-
Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification)
24-
25-
subject.after_create(user)
14+
Notify.should_receive(:new_user_email)
15+
create(:user)
2616
end
2717

2818
it 'trigger logger' do
2919
Gitlab::AppLogger.should_receive(:info)
30-
subject.after_create(user)
20+
create(:user)
3121
end
3222
end
3323
end

Diff for: spec/requests/admin/admin_users_spec.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
end
4242

4343
it "should call send mail" do
44-
Notify.should_receive(:new_user_email).and_return(stub(deliver: true))
44+
Notify.should_receive(:new_user_email)
4545

4646
User.observers.enable :user_observer do
4747
click_button "Save"
@@ -50,9 +50,7 @@
5050

5151
it "should send valid email to user with email & password" do
5252
User.observers.enable :user_observer do
53-
with_resque do
54-
click_button "Save"
55-
end
53+
click_button "Save"
5654
user = User.last
5755
email = ActionMailer::Base.deliveries.last
5856
email.subject.should have_content("Account was created")

Diff for: spec/spec_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'simplecov' unless ENV['CI']
22

3+
34
# This file is copied to spec/ when you run 'rails generate rspec:install'
45
ENV["RAILS_ENV"] ||= 'test'
56
require File.expand_path("../../config/environment", __FILE__)
@@ -8,6 +9,7 @@
89
require 'capybara/rspec'
910
require 'webmock/rspec'
1011
require 'email_spec'
12+
require 'sidekiq/testing/inline'
1113

1214
# Requires supporting ruby files with custom matchers and macros, etc,
1315
# in spec/support/ and its subdirectories.

Diff for: spec/workers/post_receive_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
context "as a resque worker" do
66
it "reponds to #perform" do
7-
PostReceive.should respond_to(:perform)
7+
PostReceive.new.should respond_to(:perform)
88
end
99
end
1010

@@ -15,7 +15,7 @@
1515

1616
it "fetches the correct project" do
1717
Project.should_receive(:find_with_namespace).with(project.path_with_namespace).and_return(project)
18-
PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
18+
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
1919
end
2020

2121
it "does not run if the author is not in the project" do
@@ -24,7 +24,7 @@
2424
project.should_not_receive(:observe_push)
2525
project.should_not_receive(:execute_hooks)
2626

27-
PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false
27+
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false
2828
end
2929

3030
it "asks the project to trigger all hooks" do
@@ -34,7 +34,7 @@
3434
project.should_receive(:update_merge_requests)
3535
project.should_receive(:observe_push)
3636

37-
PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
37+
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
3838
end
3939
end
4040

0 commit comments

Comments
 (0)