Commit 66ecfa77e5105c8a8151db899e3d3a09dba3024e
Exists in
master
and in
4 other branches
Merge branch 'sidekiq'
Showing
36 changed files
with
147 additions
and
196 deletions
Show diff stats
Gemfile
@@ -81,8 +81,9 @@ gem "acts-as-taggable-on", "2.3.3" | @@ -81,8 +81,9 @@ gem "acts-as-taggable-on", "2.3.3" | ||
81 | gem "draper", "~> 0.18.0" | 81 | gem "draper", "~> 0.18.0" |
82 | 82 | ||
83 | # Background jobs | 83 | # Background jobs |
84 | -gem "resque", git: "https://github.com/gitlabhq/resque.git", ref: "9ef4700306dd946a3ac000612428967ce0c32213" | ||
85 | -gem 'resque_mailer' | 84 | +gem 'slim' |
85 | +gem 'sinatra', :require => nil | ||
86 | +gem 'sidekiq', '2.6.4' | ||
86 | 87 | ||
87 | # HTTP requests | 88 | # HTTP requests |
88 | gem "httparty" | 89 | gem "httparty" |
@@ -157,7 +158,6 @@ group :test do | @@ -157,7 +158,6 @@ group :test do | ||
157 | gem "simplecov", require: false | 158 | gem "simplecov", require: false |
158 | gem "shoulda-matchers", "1.3.0" | 159 | gem "shoulda-matchers", "1.3.0" |
159 | gem 'email_spec' | 160 | gem 'email_spec' |
160 | - gem 'resque_spec' | ||
161 | gem "webmock" | 161 | gem "webmock" |
162 | gem 'test_after_commit' | 162 | gem 'test_after_commit' |
163 | end | 163 | end |
Gemfile.lock
@@ -55,17 +55,6 @@ GIT | @@ -55,17 +55,6 @@ GIT | ||
55 | raphael-rails (2.1.0) | 55 | raphael-rails (2.1.0) |
56 | 56 | ||
57 | GIT | 57 | GIT |
58 | - remote: https://github.com/gitlabhq/resque.git | ||
59 | - revision: 9ef4700306dd946a3ac000612428967ce0c32213 | ||
60 | - ref: 9ef4700306dd946a3ac000612428967ce0c32213 | ||
61 | - specs: | ||
62 | - resque (2.0.0.pre.1) | ||
63 | - json | ||
64 | - redis-namespace (~> 1.0) | ||
65 | - sinatra (>= 0.9.2) | ||
66 | - vegas (~> 0.1.2) | ||
67 | - | ||
68 | -GIT | ||
69 | remote: https://github.com/jonleighton/poltergeist.git | 58 | remote: https://github.com/jonleighton/poltergeist.git |
70 | revision: 5c2e092001074a8cf09f332d3714e9ba150bc8ca | 59 | revision: 5c2e092001074a8cf09f332d3714e9ba150bc8ca |
71 | ref: 5c2e092001074a8cf09f332d3714e9ba150bc8ca | 60 | ref: 5c2e092001074a8cf09f332d3714e9ba150bc8ca |
@@ -132,6 +121,9 @@ GEM | @@ -132,6 +121,9 @@ GEM | ||
132 | carrierwave (0.7.1) | 121 | carrierwave (0.7.1) |
133 | activemodel (>= 3.2.0) | 122 | activemodel (>= 3.2.0) |
134 | activesupport (>= 3.2.0) | 123 | activesupport (>= 3.2.0) |
124 | + celluloid (0.12.4) | ||
125 | + facter (>= 1.6.12) | ||
126 | + timers (>= 1.0.0) | ||
135 | charlock_holmes (0.6.9) | 127 | charlock_holmes (0.6.9) |
136 | childprocess (0.3.6) | 128 | childprocess (0.3.6) |
137 | ffi (~> 1.0, >= 1.0.6) | 129 | ffi (~> 1.0, >= 1.0.6) |
@@ -150,6 +142,7 @@ GEM | @@ -150,6 +142,7 @@ GEM | ||
150 | coffee-script-source (1.4.0) | 142 | coffee-script-source (1.4.0) |
151 | colored (1.2) | 143 | colored (1.2) |
152 | colorize (0.5.8) | 144 | colorize (0.5.8) |
145 | + connection_pool (1.0.0) | ||
153 | crack (0.3.1) | 146 | crack (0.3.1) |
154 | daemons (1.1.9) | 147 | daemons (1.1.9) |
155 | devise (2.1.2) | 148 | devise (2.1.2) |
@@ -169,6 +162,7 @@ GEM | @@ -169,6 +162,7 @@ GEM | ||
169 | eventmachine (1.0.0) | 162 | eventmachine (1.0.0) |
170 | execjs (1.4.0) | 163 | execjs (1.4.0) |
171 | multi_json (~> 1.0) | 164 | multi_json (~> 1.0) |
165 | + facter (1.6.17) | ||
172 | factory_girl (4.1.0) | 166 | factory_girl (4.1.0) |
173 | activesupport (>= 3.0.0) | 167 | activesupport (>= 3.0.0) |
174 | factory_girl_rails (4.1.0) | 168 | factory_girl_rails (4.1.0) |
@@ -370,11 +364,6 @@ GEM | @@ -370,11 +364,6 @@ GEM | ||
370 | redis (3.0.2) | 364 | redis (3.0.2) |
371 | redis-namespace (1.2.1) | 365 | redis-namespace (1.2.1) |
372 | redis (~> 3.0.0) | 366 | redis (~> 3.0.0) |
373 | - resque_mailer (2.1.0) | ||
374 | - actionmailer (~> 3.0) | ||
375 | - resque_spec (0.12.5) | ||
376 | - resque (>= 1.19.0) | ||
377 | - rspec (>= 2.5.0) | ||
378 | rspec (2.12.0) | 367 | rspec (2.12.0) |
379 | rspec-core (~> 2.12.0) | 368 | rspec-core (~> 2.12.0) |
380 | rspec-expectations (~> 2.12.0) | 369 | rspec-expectations (~> 2.12.0) |
@@ -412,6 +401,12 @@ GEM | @@ -412,6 +401,12 @@ GEM | ||
412 | sexp_processor (4.1.3) | 401 | sexp_processor (4.1.3) |
413 | shoulda-matchers (1.3.0) | 402 | shoulda-matchers (1.3.0) |
414 | activesupport (>= 3.0.0) | 403 | activesupport (>= 3.0.0) |
404 | + sidekiq (2.6.4) | ||
405 | + celluloid (~> 0.12.0) | ||
406 | + connection_pool (~> 1.0) | ||
407 | + multi_json (~> 1) | ||
408 | + redis (~> 3) | ||
409 | + redis-namespace | ||
415 | simplecov (0.7.1) | 410 | simplecov (0.7.1) |
416 | multi_json (~> 1.0) | 411 | multi_json (~> 1.0) |
417 | simplecov-html (~> 0.7.1) | 412 | simplecov-html (~> 0.7.1) |
@@ -421,6 +416,9 @@ GEM | @@ -421,6 +416,9 @@ GEM | ||
421 | rack-protection (~> 1.2) | 416 | rack-protection (~> 1.2) |
422 | tilt (~> 1.3, >= 1.3.3) | 417 | tilt (~> 1.3, >= 1.3.3) |
423 | six (0.2.0) | 418 | six (0.2.0) |
419 | + slim (1.3.6) | ||
420 | + temple (~> 0.5.5) | ||
421 | + tilt (~> 1.3.3) | ||
424 | slop (3.3.3) | 422 | slop (3.3.3) |
425 | spinach (0.5.2) | 423 | spinach (0.5.2) |
426 | colorize | 424 | colorize |
@@ -435,6 +433,7 @@ GEM | @@ -435,6 +433,7 @@ GEM | ||
435 | rack (~> 1.0) | 433 | rack (~> 1.0) |
436 | tilt (~> 1.1, != 1.3.0) | 434 | tilt (~> 1.1, != 1.3.0) |
437 | stamp (0.3.0) | 435 | stamp (0.3.0) |
436 | + temple (0.5.5) | ||
438 | test_after_commit (0.0.1) | 437 | test_after_commit (0.0.1) |
439 | therubyracer (0.10.2) | 438 | therubyracer (0.10.2) |
440 | libv8 (~> 3.3.10) | 439 | libv8 (~> 3.3.10) |
@@ -444,6 +443,7 @@ GEM | @@ -444,6 +443,7 @@ GEM | ||
444 | rack (>= 1.0.0) | 443 | rack (>= 1.0.0) |
445 | thor (0.16.0) | 444 | thor (0.16.0) |
446 | tilt (1.3.3) | 445 | tilt (1.3.3) |
446 | + timers (1.0.2) | ||
447 | treetop (1.4.12) | 447 | treetop (1.4.12) |
448 | polyglot | 448 | polyglot |
449 | polyglot (>= 0.3.1) | 449 | polyglot (>= 0.3.1) |
@@ -455,8 +455,6 @@ GEM | @@ -455,8 +455,6 @@ GEM | ||
455 | kgio (~> 2.6) | 455 | kgio (~> 2.6) |
456 | rack | 456 | rack |
457 | raindrops (~> 0.7) | 457 | raindrops (~> 0.7) |
458 | - vegas (0.1.11) | ||
459 | - rack (>= 1.0.0) | ||
460 | virtus (0.5.2) | 458 | virtus (0.5.2) |
461 | backports (~> 2.6.1) | 459 | backports (~> 2.6.1) |
462 | warden (1.2.1) | 460 | warden (1.2.1) |
@@ -534,17 +532,17 @@ DEPENDENCIES | @@ -534,17 +532,17 @@ DEPENDENCIES | ||
534 | rb-fsevent | 532 | rb-fsevent |
535 | rb-inotify | 533 | rb-inotify |
536 | redcarpet (~> 2.2.2) | 534 | redcarpet (~> 2.2.2) |
537 | - resque! | ||
538 | - resque_mailer | ||
539 | - resque_spec | ||
540 | rspec-rails | 535 | rspec-rails |
541 | sass-rails (~> 3.2.5) | 536 | sass-rails (~> 3.2.5) |
542 | sdoc | 537 | sdoc |
543 | seed-fu | 538 | seed-fu |
544 | settingslogic | 539 | settingslogic |
545 | shoulda-matchers (= 1.3.0) | 540 | shoulda-matchers (= 1.3.0) |
541 | + sidekiq (= 2.6.4) | ||
546 | simplecov | 542 | simplecov |
543 | + sinatra | ||
547 | six | 544 | six |
545 | + slim | ||
548 | spinach-rails | 546 | spinach-rails |
549 | stamp | 547 | stamp |
550 | test_after_commit | 548 | test_after_commit |
Procfile
app/controllers/admin/dashboard_controller.rb
@@ -3,10 +3,6 @@ class Admin::DashboardController < AdminController | @@ -3,10 +3,6 @@ class Admin::DashboardController < AdminController | ||
3 | @projects = Project.order("created_at DESC").limit(10) | 3 | @projects = Project.order("created_at DESC").limit(10) |
4 | @users = User.order("created_at DESC").limit(10) | 4 | @users = User.order("created_at DESC").limit(10) |
5 | 5 | ||
6 | - @resque_accessible = true | ||
7 | - @workers = Resque.workers | ||
8 | - @pending_jobs = Resque.size(:post_receive) | ||
9 | - | ||
10 | rescue Redis::InheritedError | 6 | rescue Redis::InheritedError |
11 | @resque_accessible = false | 7 | @resque_accessible = false |
12 | end | 8 | end |
app/mailers/notify.rb
app/models/project.rb
@@ -251,7 +251,7 @@ class Project < ActiveRecord::Base | @@ -251,7 +251,7 @@ class Project < ActiveRecord::Base | ||
251 | 251 | ||
252 | def send_move_instructions | 252 | def send_move_instructions |
253 | self.users_projects.each do |member| | 253 | self.users_projects.each do |member| |
254 | - Notify.project_was_moved_email(member.id).deliver | 254 | + Notify.delay.project_was_moved_email(member.id) |
255 | end | 255 | end |
256 | end | 256 | end |
257 | 257 |
app/models/system_hook.rb
@@ -19,6 +19,6 @@ class SystemHook < WebHook | @@ -19,6 +19,6 @@ class SystemHook < WebHook | ||
19 | end | 19 | end |
20 | 20 | ||
21 | def async_execute(data) | 21 | def async_execute(data) |
22 | - Resque.enqueue(SystemHookWorker, id, data) | 22 | + Sidekiq::Client.enqueue(SystemHookWorker, id, data) |
23 | end | 23 | end |
24 | end | 24 | end |
app/observers/issue_observer.rb
@@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer | @@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer | ||
3 | 3 | ||
4 | def after_create(issue) | 4 | def after_create(issue) |
5 | if issue.assignee && issue.assignee != current_user | 5 | if issue.assignee && issue.assignee != current_user |
6 | - Notify.new_issue_email(issue.id).deliver | 6 | + Notify.delay.new_issue_email(issue.id) |
7 | end | 7 | end |
8 | end | 8 | end |
9 | 9 | ||
@@ -16,7 +16,7 @@ class IssueObserver < ActiveRecord::Observer | @@ -16,7 +16,7 @@ class IssueObserver < ActiveRecord::Observer | ||
16 | if status | 16 | if status |
17 | Note.create_status_change_note(issue, current_user, status) | 17 | Note.create_status_change_note(issue, current_user, status) |
18 | [issue.author, issue.assignee].compact.each do |recipient| | 18 | [issue.author, issue.assignee].compact.each do |recipient| |
19 | - Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user.id).deliver | 19 | + Notify.delay.issue_status_changed_email(recipient.id, issue.id, status, current_user.id) |
20 | end | 20 | end |
21 | end | 21 | end |
22 | end | 22 | end |
@@ -27,7 +27,7 @@ class IssueObserver < ActiveRecord::Observer | @@ -27,7 +27,7 @@ class IssueObserver < ActiveRecord::Observer | ||
27 | recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id } | 27 | recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id } |
28 | 28 | ||
29 | recipient_ids.each do |recipient_id| | 29 | recipient_ids.each do |recipient_id| |
30 | - Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver | 30 | + Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was) |
31 | end | 31 | end |
32 | end | 32 | end |
33 | end | 33 | end |
app/observers/merge_request_observer.rb
@@ -3,7 +3,7 @@ class MergeRequestObserver < ActiveRecord::Observer | @@ -3,7 +3,7 @@ class MergeRequestObserver < ActiveRecord::Observer | ||
3 | 3 | ||
4 | def after_create(merge_request) | 4 | def after_create(merge_request) |
5 | if merge_request.assignee && merge_request.assignee != current_user | 5 | if merge_request.assignee && merge_request.assignee != current_user |
6 | - Notify.new_merge_request_email(merge_request.id).deliver | 6 | + Notify.delay.new_merge_request_email(merge_request.id) |
7 | end | 7 | end |
8 | end | 8 | end |
9 | 9 | ||
@@ -25,7 +25,7 @@ class MergeRequestObserver < ActiveRecord::Observer | @@ -25,7 +25,7 @@ class MergeRequestObserver < ActiveRecord::Observer | ||
25 | recipients_ids.delete current_user.id | 25 | recipients_ids.delete current_user.id |
26 | 26 | ||
27 | recipients_ids.each do |recipient_id| | 27 | recipients_ids.each do |recipient_id| |
28 | - Notify.reassigned_merge_request_email(recipient_id, merge_request.id, merge_request.assignee_id_was).deliver | 28 | + Notify.delay.reassigned_merge_request_email(recipient_id, merge_request.id, merge_request.assignee_id_was) |
29 | end | 29 | end |
30 | end | 30 | end |
31 | end | 31 | end |
app/observers/note_observer.rb
@@ -11,7 +11,7 @@ class NoteObserver < ActiveRecord::Observer | @@ -11,7 +11,7 @@ class NoteObserver < ActiveRecord::Observer | ||
11 | notify_team(note) | 11 | notify_team(note) |
12 | elsif note.notify_author | 12 | elsif note.notify_author |
13 | # Notify only author of resource | 13 | # Notify only author of resource |
14 | - Notify.note_commit_email(note.commit_author.id, note.id).deliver | 14 | + Notify.delay.note_commit_email(note.commit_author.id, note.id) |
15 | else | 15 | else |
16 | # Otherwise ignore it | 16 | # Otherwise ignore it |
17 | nil | 17 | nil |
@@ -26,7 +26,7 @@ class NoteObserver < ActiveRecord::Observer | @@ -26,7 +26,7 @@ class NoteObserver < ActiveRecord::Observer | ||
26 | 26 | ||
27 | if Notify.respond_to? notify_method | 27 | if Notify.respond_to? notify_method |
28 | team_without_note_author(note).map do |u| | 28 | team_without_note_author(note).map do |u| |
29 | - Notify.send(notify_method, u.id, note.id).deliver | 29 | + Notify.delay.send(notify_method, u.id, note.id) |
30 | end | 30 | end |
31 | end | 31 | end |
32 | end | 32 | end |
app/observers/user_observer.rb
@@ -2,7 +2,7 @@ class UserObserver < ActiveRecord::Observer | @@ -2,7 +2,7 @@ class UserObserver < ActiveRecord::Observer | ||
2 | def after_create(user) | 2 | def after_create(user) |
3 | log_info("User \"#{user.name}\" (#{user.email}) was created") | 3 | log_info("User \"#{user.name}\" (#{user.email}) was created") |
4 | 4 | ||
5 | - Notify.new_user_email(user.id, user.password).deliver | 5 | + Notify.delay.new_user_email(user.id, user.password) |
6 | end | 6 | end |
7 | 7 | ||
8 | def after_destroy user | 8 | def after_destroy user |
app/observers/users_project_observer.rb
1 | class UsersProjectObserver < ActiveRecord::Observer | 1 | class UsersProjectObserver < ActiveRecord::Observer |
2 | def after_commit(users_project) | 2 | def after_commit(users_project) |
3 | return if users_project.destroyed? | 3 | return if users_project.destroyed? |
4 | - Notify.project_access_granted_email(users_project.id).deliver | 4 | + Notify.delay.project_access_granted_email(users_project.id) |
5 | end | 5 | end |
6 | 6 | ||
7 | def after_create(users_project) | 7 | def after_create(users_project) |
app/views/admin/dashboard/index.html.haml
1 | .admin_dash.row | 1 | .admin_dash.row |
2 | - .span3 | 2 | + .span4 |
3 | .ui-box | 3 | .ui-box |
4 | %h5.title Projects | 4 | %h5.title Projects |
5 | .data.padded | 5 | .data.padded |
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | %h1= Project.count | 7 | %h1= Project.count |
8 | %hr | 8 | %hr |
9 | = link_to 'New Project', new_project_path, class: "btn small" | 9 | = link_to 'New Project', new_project_path, class: "btn small" |
10 | - .span3 | 10 | + .span4 |
11 | .ui-box | 11 | .ui-box |
12 | %h5.title Groups | 12 | %h5.title Groups |
13 | .data.padded | 13 | .data.padded |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | %h1= Group.count | 15 | %h1= Group.count |
16 | %hr | 16 | %hr |
17 | = link_to 'New Group', new_admin_group_path, class: "btn small" | 17 | = link_to 'New Group', new_admin_group_path, class: "btn small" |
18 | - .span3 | 18 | + .span4 |
19 | .ui-box | 19 | .ui-box |
20 | %h5.title Users | 20 | %h5.title Users |
21 | .data.padded | 21 | .data.padded |
@@ -23,25 +23,6 @@ | @@ -23,25 +23,6 @@ | ||
23 | %h1= User.count | 23 | %h1= User.count |
24 | %hr | 24 | %hr |
25 | = link_to 'New User', new_admin_user_path, class: "btn small" | 25 | = link_to 'New User', new_admin_user_path, class: "btn small" |
26 | - .span3 | ||
27 | - .ui-box | ||
28 | - %h5.title | ||
29 | - Resque Workers | ||
30 | - .data.padded | ||
31 | - - if @resque_accessible | ||
32 | - = link_to admin_resque_path do | ||
33 | - %h1{class: @workers.present? ? "cgreen" : "cred"} | ||
34 | - = @workers.count | ||
35 | - %hr | ||
36 | - %p | ||
37 | - %strong{class: @pending_jobs > 0 ? "cred" : "cgreen"} | ||
38 | - #{@pending_jobs} post receive jobs waiting | ||
39 | - - else | ||
40 | - = link_to admin_resque_path do | ||
41 | - %h1.cdark ? | ||
42 | - %hr | ||
43 | - %p | ||
44 | - %strong Resque status unknown | ||
45 | 26 | ||
46 | .row | 27 | .row |
47 | .span6 | 28 | .span6 |
app/views/admin/resque/show.html.haml
app/views/layouts/admin.html.haml
@@ -19,6 +19,6 @@ | @@ -19,6 +19,6 @@ | ||
19 | = nav_link(controller: :hooks) do | 19 | = nav_link(controller: :hooks) do |
20 | = link_to "Hooks", admin_hooks_path | 20 | = link_to "Hooks", admin_hooks_path |
21 | = nav_link(controller: :resque) do | 21 | = nav_link(controller: :resque) do |
22 | - = link_to "Resque", admin_resque_path | 22 | + = link_to "Background Jobs", admin_resque_path |
23 | 23 | ||
24 | .content= yield | 24 | .content= yield |
app/workers/post_receive.rb
1 | class PostReceive | 1 | class PostReceive |
2 | - @queue = :post_receive | 2 | + include Sidekiq::Worker |
3 | 3 | ||
4 | - def self.perform(repo_path, oldrev, newrev, ref, identifier) | 4 | + sidekiq_options queue: :post_receive |
5 | + | ||
6 | + def perform(repo_path, oldrev, newrev, ref, identifier) | ||
5 | repo_path.gsub!(Gitlab.config.gitolite.repos_path.to_s, "") | 7 | repo_path.gsub!(Gitlab.config.gitolite.repos_path.to_s, "") |
6 | repo_path.gsub!(/.git$/, "") | 8 | repo_path.gsub!(/.git$/, "") |
7 | repo_path.gsub!(/^\//, "") | 9 | repo_path.gsub!(/^\//, "") |
app/workers/system_hook_worker.rb
1 | class SystemHookWorker | 1 | class SystemHookWorker |
2 | - @queue = :system_hook | 2 | + include Sidekiq::Worker |
3 | 3 | ||
4 | - def self.perform(hook_id, data) | 4 | + sidekiq_options queue: :system_hook |
5 | + | ||
6 | + def perform(hook_id, data) | ||
5 | SystemHook.find(hook_id).execute data | 7 | SystemHook.find(hook_id).execute data |
6 | end | 8 | end |
7 | end | 9 | end |
config/initializers/4_resque.rb
@@ -1,29 +0,0 @@ | @@ -1,29 +0,0 @@ | ||
1 | -# Custom Redis configuration | ||
2 | -config_file = Rails.root.join('config', 'resque.yml') | ||
3 | - | ||
4 | -if File.exists?(config_file) | ||
5 | - resque_config = YAML.load_file(config_file) | ||
6 | - Resque.redis = resque_config[Rails.env] | ||
7 | -end | ||
8 | -Resque.redis.namespace = 'resque:gitlab' | ||
9 | -Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } | ||
10 | - | ||
11 | -# Authentication | ||
12 | -require 'resque/server' | ||
13 | -class ResqueAuthentication | ||
14 | - def initialize(app) | ||
15 | - @app = app | ||
16 | - end | ||
17 | - | ||
18 | - def call(env) | ||
19 | - account = env['warden'].authenticate!(:database_authenticatable, :rememberable, scope: :user) | ||
20 | - raise "Access denied" if !account.admin? | ||
21 | - @app.call(env) | ||
22 | - end | ||
23 | -end | ||
24 | - | ||
25 | -Resque::Server.use ResqueAuthentication | ||
26 | - | ||
27 | -# Mailer | ||
28 | -Resque::Mailer.excluded_environments = [] | ||
29 | - |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +# Custom Redis configuration | ||
2 | +config_file = Rails.root.join('config', 'resque.yml') | ||
3 | + | ||
4 | +resque_url = if File.exists?(config_file) | ||
5 | + YAML.load_file(config_file)[Rails.env] | ||
6 | + else | ||
7 | + "localhost:6379" | ||
8 | + end | ||
9 | + | ||
10 | +Sidekiq.configure_server do |config| | ||
11 | + config.redis = { | ||
12 | + url: "redis://#{resque_url}", | ||
13 | + namespace: 'resque:gitlab' | ||
14 | + } | ||
15 | +end | ||
16 | + | ||
17 | +Sidekiq.configure_client do |config| | ||
18 | + config.redis = { | ||
19 | + url: "redis://#{resque_url}", | ||
20 | + namespace: 'resque:gitlab' | ||
21 | + } | ||
22 | +end |
config/routes.rb
1 | +require 'sidekiq/web' | ||
2 | + | ||
1 | Gitlab::Application.routes.draw do | 3 | Gitlab::Application.routes.draw do |
2 | # | 4 | # |
3 | # Search | 5 | # Search |
@@ -8,9 +10,10 @@ Gitlab::Application.routes.draw do | @@ -8,9 +10,10 @@ Gitlab::Application.routes.draw do | ||
8 | require 'api' | 10 | require 'api' |
9 | mount Gitlab::API => '/api' | 11 | mount Gitlab::API => '/api' |
10 | 12 | ||
11 | - # Optionally, enable Resque here | ||
12 | - require 'resque/server' | ||
13 | - mount Resque::Server => '/info/resque', as: 'resque' | 13 | + constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } |
14 | + constraints constraint do | ||
15 | + mount Sidekiq::Web, at: "/admin/sidekiq", as: :sidekiq | ||
16 | + end | ||
14 | 17 | ||
15 | # Enable Grack support | 18 | # Enable Grack support |
16 | mount Grack::Bundle.new({ | 19 | mount Grack::Bundle.new({ |
features/steps/admin/admin_active_tab.rb
@@ -28,6 +28,6 @@ class AdminActiveTab < Spinach::FeatureSteps | @@ -28,6 +28,6 @@ class AdminActiveTab < Spinach::FeatureSteps | ||
28 | end | 28 | end |
29 | 29 | ||
30 | Then 'the active main tab should be Resque' do | 30 | Then 'the active main tab should be Resque' do |
31 | - ensure_active_main_tab('Resque') | 31 | + ensure_active_main_tab('Background Jobs') |
32 | end | 32 | end |
33 | end | 33 | end |
features/support/env.rb
@@ -6,6 +6,8 @@ require './config/environment' | @@ -6,6 +6,8 @@ require './config/environment' | ||
6 | require 'rspec' | 6 | require 'rspec' |
7 | require 'database_cleaner' | 7 | require 'database_cleaner' |
8 | require 'spinach/capybara' | 8 | require 'spinach/capybara' |
9 | +require 'sidekiq/testing/inline' | ||
10 | + | ||
9 | 11 | ||
10 | %w(gitolite_stub stubbed_repository valid_commit).each do |f| | 12 | %w(gitolite_stub stubbed_repository valid_commit).each do |f| |
11 | require Rails.root.join('spec', 'support', f) | 13 | require Rails.root.join('spec', 'support', f) |
lib/hooks/post-receive
lib/tasks/gitlab/check.rake
@@ -871,7 +871,7 @@ namespace :gitlab do | @@ -871,7 +871,7 @@ namespace :gitlab do | ||
871 | 871 | ||
872 | 872 | ||
873 | namespace :resque do | 873 | namespace :resque do |
874 | - desc "GITLAB | Check the configuration of Resque" | 874 | + desc "GITLAB | Check the configuration of Sidekiq" |
875 | task check: :environment do | 875 | task check: :environment do |
876 | warn_user_is_not_gitlab | 876 | warn_user_is_not_gitlab |
877 | start_checking "Resque" | 877 | start_checking "Resque" |
@@ -888,7 +888,7 @@ namespace :gitlab do | @@ -888,7 +888,7 @@ namespace :gitlab do | ||
888 | def check_resque_running | 888 | def check_resque_running |
889 | print "Running? ... " | 889 | print "Running? ... " |
890 | 890 | ||
891 | - if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/) | 891 | + if run_and_match("ps aux | grep -i sidekiq", /sidekiq-[\d\.]+:.+$/) |
892 | puts "yes".green | 892 | puts "yes".green |
893 | else | 893 | else |
894 | puts "no".red | 894 | puts "no".red |
@@ -899,7 +899,7 @@ namespace :gitlab do | @@ -899,7 +899,7 @@ namespace :gitlab do | ||
899 | ) | 899 | ) |
900 | for_more_information( | 900 | for_more_information( |
901 | see_installation_guide_section("Install Init Script"), | 901 | see_installation_guide_section("Install Init Script"), |
902 | - "see log/resque.log for possible errors" | 902 | + "see log/sidekiq.log for possible errors" |
903 | ) | 903 | ) |
904 | fix_and_rerun | 904 | fix_and_rerun |
905 | end | 905 | end |
lib/tasks/resque.rake
@@ -1,23 +0,0 @@ | @@ -1,23 +0,0 @@ | ||
1 | -require 'resque/tasks' | ||
2 | - | ||
3 | -namespace :resque do | ||
4 | - task setup: :environment do | ||
5 | - Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } | ||
6 | - end | ||
7 | - | ||
8 | - desc "Resque | kill all workers (using -QUIT), god will take care of them" | ||
9 | - task :stop_workers => :environment do | ||
10 | - pids = Array.new | ||
11 | - | ||
12 | - Resque.workers.each do |worker| | ||
13 | - pids << worker.to_s.split(/:/).second | ||
14 | - end | ||
15 | - | ||
16 | - if pids.size > 0 | ||
17 | - system("kill -QUIT #{pids.join(' ')}") | ||
18 | - end | ||
19 | - end | ||
20 | -end | ||
21 | - | ||
22 | -desc "Alias for resque:work (To run workers on Heroku)" | ||
23 | -task "jobs:work" => "resque:work" |
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +namespace :sidekiq do | ||
2 | + desc "GITLAB | Stop sidekiq" | ||
3 | + task :stop do | ||
4 | + run "bundle exec sidekiqctl stop #{pidfile}" | ||
5 | + end | ||
6 | + | ||
7 | + desc "GITLAB | Start sidekiq" | ||
8 | + task :start do | ||
9 | + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{rails_env} -P #{pidfile} >> #{root_path}/log/sidekiq.log 2>&1 &" | ||
10 | + end | ||
11 | + | ||
12 | + def root_path | ||
13 | + @root_path ||= File.join(File.expand_path(File.dirname(__FILE__)), "../..") | ||
14 | + end | ||
15 | + | ||
16 | + def pidfile | ||
17 | + "#{root_path}/tmp/pids/sidekiq.pid" | ||
18 | + end | ||
19 | + | ||
20 | + def rails_env | ||
21 | + ENV['RAILS_ENV'] || "production" | ||
22 | + end | ||
23 | +end |
resque.sh
@@ -1,2 +0,0 @@ | @@ -1,2 +0,0 @@ | ||
1 | -mkdir -p tmp/pids | ||
2 | -nohup bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid > ./log/resque.stdout.log 2>./log/resque.stderr.log & | ||
3 | \ No newline at end of file | 0 | \ No newline at end of file |
resque_dev.sh
spec/models/system_hook_spec.rb
@@ -23,41 +23,31 @@ describe SystemHook do | @@ -23,41 +23,31 @@ describe SystemHook do | ||
23 | end | 23 | end |
24 | 24 | ||
25 | it "project_create hook" do | 25 | it "project_create hook" do |
26 | - with_resque do | ||
27 | - project = create(:project) | ||
28 | - end | 26 | + project = create(:project) |
29 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once | 27 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once |
30 | end | 28 | end |
31 | 29 | ||
32 | it "project_destroy hook" do | 30 | it "project_destroy hook" do |
33 | project = create(:project) | 31 | project = create(:project) |
34 | - with_resque do | ||
35 | - project.destroy | ||
36 | - end | 32 | + project.destroy |
37 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once | 33 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once |
38 | end | 34 | end |
39 | 35 | ||
40 | it "user_create hook" do | 36 | it "user_create hook" do |
41 | - with_resque do | ||
42 | - create(:user) | ||
43 | - end | 37 | + create(:user) |
44 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once | 38 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once |
45 | end | 39 | end |
46 | 40 | ||
47 | it "user_destroy hook" do | 41 | it "user_destroy hook" do |
48 | user = create(:user) | 42 | user = create(:user) |
49 | - with_resque do | ||
50 | - user.destroy | ||
51 | - end | 43 | + user.destroy |
52 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once | 44 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once |
53 | end | 45 | end |
54 | 46 | ||
55 | it "project_create hook" do | 47 | it "project_create hook" do |
56 | user = create(:user) | 48 | user = create(:user) |
57 | project = create(:project) | 49 | project = create(:project) |
58 | - with_resque do | ||
59 | - project.team << [user, :master] | ||
60 | - end | 50 | + project.team << [user, :master] |
61 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once | 51 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once |
62 | end | 52 | end |
63 | 53 | ||
@@ -65,11 +55,8 @@ describe SystemHook do | @@ -65,11 +55,8 @@ describe SystemHook do | ||
65 | user = create(:user) | 55 | user = create(:user) |
66 | project = create(:project) | 56 | project = create(:project) |
67 | project.team << [user, :master] | 57 | project.team << [user, :master] |
68 | - with_resque do | ||
69 | - project.users_projects.clear | ||
70 | - end | 58 | + project.users_projects.clear |
71 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once | 59 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once |
72 | end | 60 | end |
73 | end | 61 | end |
74 | - | ||
75 | end | 62 | end |
spec/observers/issue_observer_spec.rb
@@ -21,8 +21,7 @@ describe IssueObserver do | @@ -21,8 +21,7 @@ describe IssueObserver do | ||
21 | end | 21 | end |
22 | 22 | ||
23 | it 'sends an email to the assignee' do | 23 | 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) |
26 | 25 | ||
27 | subject.after_create(issue) | 26 | subject.after_create(issue) |
28 | end | 27 | end |
@@ -71,6 +70,7 @@ describe IssueObserver do | @@ -71,6 +70,7 @@ describe IssueObserver do | ||
71 | context 'a status "closed"' do | 70 | context 'a status "closed"' do |
72 | it 'note is created if the issue is being closed' do | 71 | it 'note is created if the issue is being closed' do |
73 | issue.should_receive(:is_being_closed?).and_return(true) | 72 | issue.should_receive(:is_being_closed?).and_return(true) |
73 | + Notify.should_receive(:issue_status_changed_email).twice | ||
74 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') | 74 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
75 | 75 | ||
76 | subject.after_update(issue) | 76 | subject.after_update(issue) |
@@ -85,7 +85,7 @@ describe IssueObserver do | @@ -85,7 +85,7 @@ describe IssueObserver do | ||
85 | 85 | ||
86 | it 'notification is delivered if the issue being closed' do | 86 | it 'notification is delivered if the issue being closed' do |
87 | issue.stub(:is_being_closed?).and_return(true) | 87 | 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 |
89 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') | 89 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
90 | 90 | ||
91 | subject.after_update(issue) | 91 | subject.after_update(issue) |
@@ -104,7 +104,7 @@ describe IssueObserver do | @@ -104,7 +104,7 @@ describe IssueObserver do | ||
104 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) | 104 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
105 | issue_without_assignee.stub(:is_being_closed?).and_return(true) | 105 | issue_without_assignee.stub(:is_being_closed?).and_return(true) |
106 | issue_without_assignee.stub(:is_being_reopened?).and_return(false) | 106 | 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 |
108 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed') | 108 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed') |
109 | 109 | ||
110 | subject.after_update(issue_without_assignee) | 110 | subject.after_update(issue_without_assignee) |
@@ -113,6 +113,7 @@ describe IssueObserver do | @@ -113,6 +113,7 @@ describe IssueObserver do | ||
113 | 113 | ||
114 | context 'a status "reopened"' do | 114 | context 'a status "reopened"' do |
115 | it 'note is created if the issue is being reopened' do | 115 | it 'note is created if the issue is being reopened' do |
116 | + Notify.should_receive(:issue_status_changed_email).twice | ||
116 | issue.should_receive(:is_being_reopened?).and_return(true) | 117 | issue.should_receive(:is_being_reopened?).and_return(true) |
117 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') | 118 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
118 | 119 | ||
@@ -128,7 +129,7 @@ describe IssueObserver do | @@ -128,7 +129,7 @@ describe IssueObserver do | ||
128 | 129 | ||
129 | it 'notification is delivered if the issue being reopened' do | 130 | it 'notification is delivered if the issue being reopened' do |
130 | issue.stub(:is_being_reopened?).and_return(true) | 131 | 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 |
132 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') | 133 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
133 | 134 | ||
134 | subject.after_update(issue) | 135 | subject.after_update(issue) |
@@ -147,7 +148,7 @@ describe IssueObserver do | @@ -147,7 +148,7 @@ describe IssueObserver do | ||
147 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) | 148 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
148 | issue_without_assignee.stub(:is_being_closed?).and_return(false) | 149 | issue_without_assignee.stub(:is_being_closed?).and_return(false) |
149 | issue_without_assignee.stub(:is_being_reopened?).and_return(true) | 150 | 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 |
151 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened') | 152 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened') |
152 | 153 | ||
153 | subject.after_update(issue_without_assignee) | 154 | subject.after_update(issue_without_assignee) |
@@ -164,8 +165,7 @@ describe IssueObserver do | @@ -164,8 +165,7 @@ describe IssueObserver do | ||
164 | end | 165 | end |
165 | 166 | ||
166 | def it_sends_a_reassigned_email_to(recipient) | 167 | 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) |
169 | end | 169 | end |
170 | 170 | ||
171 | def it_does_not_send_a_reassigned_email_to(recipient) | 171 | def it_does_not_send_a_reassigned_email_to(recipient) |
spec/observers/merge_request_observer_spec.rb
@@ -21,9 +21,7 @@ describe MergeRequestObserver do | @@ -21,9 +21,7 @@ describe MergeRequestObserver do | ||
21 | end | 21 | end |
22 | 22 | ||
23 | it 'sends an email to the assignee' do | 23 | 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) |
27 | subject.after_create(mr) | 25 | subject.after_create(mr) |
28 | end | 26 | end |
29 | 27 | ||
@@ -158,8 +156,7 @@ describe MergeRequestObserver do | @@ -158,8 +156,7 @@ describe MergeRequestObserver do | ||
158 | end | 156 | end |
159 | 157 | ||
160 | def it_sends_a_reassigned_email_to(recipient) | 158 | 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) |
163 | end | 160 | end |
164 | 161 | ||
165 | def it_does_not_send_a_reassigned_email_to(recipient) | 162 | def it_does_not_send_a_reassigned_email_to(recipient) |
spec/observers/note_observer_spec.rb
@@ -4,7 +4,6 @@ describe NoteObserver do | @@ -4,7 +4,6 @@ describe NoteObserver do | ||
4 | subject { NoteObserver.instance } | 4 | subject { NoteObserver.instance } |
5 | 5 | ||
6 | let(:team_without_author) { (1..2).map { |n| double :user, id: n } } | 6 | let(:team_without_author) { (1..2).map { |n| double :user, id: n } } |
7 | - let(:delivery_success) { double deliver: true } | ||
8 | 7 | ||
9 | describe '#after_create' do | 8 | describe '#after_create' do |
10 | let(:note) { double :note } | 9 | let(:note) { double :note } |
@@ -45,13 +44,13 @@ describe NoteObserver do | @@ -45,13 +44,13 @@ describe NoteObserver do | ||
45 | note.stub(:id).and_return(42) | 44 | note.stub(:id).and_return(42) |
46 | author = double :user, id: 1 | 45 | author = double :user, id: 1 |
47 | note.stub(:commit_author).and_return(author) | 46 | 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) |
49 | 48 | ||
50 | subject.after_create(note) | 49 | subject.after_create(note) |
51 | end | 50 | end |
52 | 51 | ||
53 | it 'does not notify the author of a commit when not flagged to notify the author' do | 52 | 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) |
55 | 54 | ||
56 | subject.after_create(note) | 55 | subject.after_create(note) |
57 | end | 56 | end |
@@ -71,28 +70,28 @@ describe NoteObserver do | @@ -71,28 +70,28 @@ describe NoteObserver do | ||
71 | context 'notifies team of a new note on' do | 70 | context 'notifies team of a new note on' do |
72 | it 'a commit' do | 71 | it 'a commit' do |
73 | note.stub(:noteable_type).and_return('Commit') | 72 | 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 |
75 | 74 | ||
76 | subject.send(:notify_team, note) | 75 | subject.send(:notify_team, note) |
77 | end | 76 | end |
78 | 77 | ||
79 | it 'an issue' do | 78 | it 'an issue' do |
80 | note.stub(:noteable_type).and_return('Issue') | 79 | 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 |
82 | 81 | ||
83 | subject.send(:notify_team, note) | 82 | subject.send(:notify_team, note) |
84 | end | 83 | end |
85 | 84 | ||
86 | it 'a wiki page' do | 85 | it 'a wiki page' do |
87 | note.stub(:noteable_type).and_return('Wiki') | 86 | 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 |
89 | 88 | ||
90 | subject.send(:notify_team, note) | 89 | subject.send(:notify_team, note) |
91 | end | 90 | end |
92 | 91 | ||
93 | it 'a merge request' do | 92 | it 'a merge request' do |
94 | note.stub(:noteable_type).and_return('MergeRequest') | 93 | 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 |
96 | 95 | ||
97 | subject.send(:notify_team, note) | 96 | subject.send(:notify_team, note) |
98 | end | 97 | end |
@@ -100,16 +99,16 @@ describe NoteObserver do | @@ -100,16 +99,16 @@ describe NoteObserver do | ||
100 | it 'a wall' do | 99 | it 'a wall' do |
101 | # Note: wall posts have #noteable_type of nil | 100 | # Note: wall posts have #noteable_type of nil |
102 | note.stub(:noteable_type).and_return(nil) | 101 | 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 |
104 | 103 | ||
105 | subject.send(:notify_team, note) | 104 | subject.send(:notify_team, note) |
106 | end | 105 | end |
107 | end | 106 | end |
108 | 107 | ||
109 | it 'does nothing for a new note on a snippet' do | 108 | 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') |
111 | 110 | ||
112 | - subject.send(:notify_team, note).should be_nil | 111 | + subject.send(:notify_team, note).should be_nil |
113 | end | 112 | end |
114 | end | 113 | end |
115 | 114 | ||
@@ -125,4 +124,8 @@ describe NoteObserver do | @@ -125,4 +124,8 @@ describe NoteObserver do | ||
125 | subject.send(:team_without_note_author, note).should == team_without_author | 124 | subject.send(:team_without_note_author, note).should == team_without_author |
126 | end | 125 | end |
127 | end | 126 | end |
127 | + | ||
128 | + def notify | ||
129 | + Notify | ||
130 | + end | ||
128 | end | 131 | end |
spec/observers/user_observer_spec.rb
@@ -10,24 +10,14 @@ describe UserObserver do | @@ -10,24 +10,14 @@ describe UserObserver do | ||
10 | end | 10 | end |
11 | 11 | ||
12 | context 'when a new user is created' do | 12 | context 'when a new user is created' do |
13 | - let(:user) { double(:user, id: 42, | ||
14 | - password: 'P@ssword!', | ||
15 | - name: 'John', | ||
16 | - email: 'u@mail.local', | ||
17 | - username: 'root', | ||
18 | - create_namespace: true) } | ||
19 | - let(:notification) { double :notification } | ||
20 | - | ||
21 | it 'sends an email' do | 13 | 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) | ||
26 | end | 16 | end |
27 | 17 | ||
28 | it 'trigger logger' do | 18 | it 'trigger logger' do |
29 | Gitlab::AppLogger.should_receive(:info) | 19 | Gitlab::AppLogger.should_receive(:info) |
30 | - subject.after_create(user) | 20 | + create(:user) |
31 | end | 21 | end |
32 | end | 22 | end |
33 | end | 23 | end |
spec/requests/admin/admin_users_spec.rb
@@ -41,7 +41,7 @@ describe "Admin::Users" do | @@ -41,7 +41,7 @@ describe "Admin::Users" do | ||
41 | end | 41 | end |
42 | 42 | ||
43 | it "should call send mail" do | 43 | 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) |
45 | 45 | ||
46 | User.observers.enable :user_observer do | 46 | User.observers.enable :user_observer do |
47 | click_button "Save" | 47 | click_button "Save" |
@@ -50,9 +50,7 @@ describe "Admin::Users" do | @@ -50,9 +50,7 @@ describe "Admin::Users" do | ||
50 | 50 | ||
51 | it "should send valid email to user with email & password" do | 51 | it "should send valid email to user with email & password" do |
52 | User.observers.enable :user_observer do | 52 | User.observers.enable :user_observer do |
53 | - with_resque do | ||
54 | - click_button "Save" | ||
55 | - end | 53 | + click_button "Save" |
56 | user = User.last | 54 | user = User.last |
57 | email = ActionMailer::Base.deliveries.last | 55 | email = ActionMailer::Base.deliveries.last |
58 | email.subject.should have_content("Account was created") | 56 | email.subject.should have_content("Account was created") |
spec/spec_helper.rb
1 | require 'simplecov' unless ENV['CI'] | 1 | require 'simplecov' unless ENV['CI'] |
2 | 2 | ||
3 | + | ||
3 | # This file is copied to spec/ when you run 'rails generate rspec:install' | 4 | # This file is copied to spec/ when you run 'rails generate rspec:install' |
4 | ENV["RAILS_ENV"] ||= 'test' | 5 | ENV["RAILS_ENV"] ||= 'test' |
5 | require File.expand_path("../../config/environment", __FILE__) | 6 | require File.expand_path("../../config/environment", __FILE__) |
@@ -8,6 +9,7 @@ require 'capybara/rails' | @@ -8,6 +9,7 @@ require 'capybara/rails' | ||
8 | require 'capybara/rspec' | 9 | require 'capybara/rspec' |
9 | require 'webmock/rspec' | 10 | require 'webmock/rspec' |
10 | require 'email_spec' | 11 | require 'email_spec' |
12 | +require 'sidekiq/testing/inline' | ||
11 | 13 | ||
12 | # Requires supporting ruby files with custom matchers and macros, etc, | 14 | # Requires supporting ruby files with custom matchers and macros, etc, |
13 | # in spec/support/ and its subdirectories. | 15 | # in spec/support/ and its subdirectories. |
spec/workers/post_receive_spec.rb
@@ -4,7 +4,7 @@ describe PostReceive do | @@ -4,7 +4,7 @@ describe PostReceive do | ||
4 | 4 | ||
5 | context "as a resque worker" do | 5 | context "as a resque worker" do |
6 | it "reponds to #perform" do | 6 | it "reponds to #perform" do |
7 | - PostReceive.should respond_to(:perform) | 7 | + PostReceive.new.should respond_to(:perform) |
8 | end | 8 | end |
9 | end | 9 | end |
10 | 10 | ||
@@ -15,7 +15,7 @@ describe PostReceive do | @@ -15,7 +15,7 @@ describe PostReceive do | ||
15 | 15 | ||
16 | it "fetches the correct project" do | 16 | it "fetches the correct project" do |
17 | Project.should_receive(:find_with_namespace).with(project.path_with_namespace).and_return(project) | 17 | 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) |
19 | end | 19 | end |
20 | 20 | ||
21 | it "does not run if the author is not in the project" do | 21 | it "does not run if the author is not in the project" do |
@@ -24,7 +24,7 @@ describe PostReceive do | @@ -24,7 +24,7 @@ describe PostReceive do | ||
24 | project.should_not_receive(:observe_push) | 24 | project.should_not_receive(:observe_push) |
25 | project.should_not_receive(:execute_hooks) | 25 | project.should_not_receive(:execute_hooks) |
26 | 26 | ||
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 |
28 | end | 28 | end |
29 | 29 | ||
30 | it "asks the project to trigger all hooks" do | 30 | it "asks the project to trigger all hooks" do |
@@ -34,7 +34,7 @@ describe PostReceive do | @@ -34,7 +34,7 @@ describe PostReceive do | ||
34 | project.should_receive(:update_merge_requests) | 34 | project.should_receive(:update_merge_requests) |
35 | project.should_receive(:observe_push) | 35 | project.should_receive(:observe_push) |
36 | 36 | ||
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) |
38 | end | 38 | end |
39 | end | 39 | end |
40 | 40 |