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 | 81 | gem "draper", "~> 0.18.0" |
82 | 82 | |
83 | 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 | 88 | # HTTP requests |
88 | 89 | gem "httparty" |
... | ... | @@ -157,7 +158,6 @@ group :test do |
157 | 158 | gem "simplecov", require: false |
158 | 159 | gem "shoulda-matchers", "1.3.0" |
159 | 160 | gem 'email_spec' |
160 | - gem 'resque_spec' | |
161 | 161 | gem "webmock" |
162 | 162 | gem 'test_after_commit' |
163 | 163 | end | ... | ... |
Gemfile.lock
... | ... | @@ -55,17 +55,6 @@ GIT |
55 | 55 | raphael-rails (2.1.0) |
56 | 56 | |
57 | 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 | 58 | remote: https://github.com/jonleighton/poltergeist.git |
70 | 59 | revision: 5c2e092001074a8cf09f332d3714e9ba150bc8ca |
71 | 60 | ref: 5c2e092001074a8cf09f332d3714e9ba150bc8ca |
... | ... | @@ -132,6 +121,9 @@ GEM |
132 | 121 | carrierwave (0.7.1) |
133 | 122 | activemodel (>= 3.2.0) |
134 | 123 | activesupport (>= 3.2.0) |
124 | + celluloid (0.12.4) | |
125 | + facter (>= 1.6.12) | |
126 | + timers (>= 1.0.0) | |
135 | 127 | charlock_holmes (0.6.9) |
136 | 128 | childprocess (0.3.6) |
137 | 129 | ffi (~> 1.0, >= 1.0.6) |
... | ... | @@ -150,6 +142,7 @@ GEM |
150 | 142 | coffee-script-source (1.4.0) |
151 | 143 | colored (1.2) |
152 | 144 | colorize (0.5.8) |
145 | + connection_pool (1.0.0) | |
153 | 146 | crack (0.3.1) |
154 | 147 | daemons (1.1.9) |
155 | 148 | devise (2.1.2) |
... | ... | @@ -169,6 +162,7 @@ GEM |
169 | 162 | eventmachine (1.0.0) |
170 | 163 | execjs (1.4.0) |
171 | 164 | multi_json (~> 1.0) |
165 | + facter (1.6.17) | |
172 | 166 | factory_girl (4.1.0) |
173 | 167 | activesupport (>= 3.0.0) |
174 | 168 | factory_girl_rails (4.1.0) |
... | ... | @@ -370,11 +364,6 @@ GEM |
370 | 364 | redis (3.0.2) |
371 | 365 | redis-namespace (1.2.1) |
372 | 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 | 367 | rspec (2.12.0) |
379 | 368 | rspec-core (~> 2.12.0) |
380 | 369 | rspec-expectations (~> 2.12.0) |
... | ... | @@ -412,6 +401,12 @@ GEM |
412 | 401 | sexp_processor (4.1.3) |
413 | 402 | shoulda-matchers (1.3.0) |
414 | 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 | 410 | simplecov (0.7.1) |
416 | 411 | multi_json (~> 1.0) |
417 | 412 | simplecov-html (~> 0.7.1) |
... | ... | @@ -421,6 +416,9 @@ GEM |
421 | 416 | rack-protection (~> 1.2) |
422 | 417 | tilt (~> 1.3, >= 1.3.3) |
423 | 418 | six (0.2.0) |
419 | + slim (1.3.6) | |
420 | + temple (~> 0.5.5) | |
421 | + tilt (~> 1.3.3) | |
424 | 422 | slop (3.3.3) |
425 | 423 | spinach (0.5.2) |
426 | 424 | colorize |
... | ... | @@ -435,6 +433,7 @@ GEM |
435 | 433 | rack (~> 1.0) |
436 | 434 | tilt (~> 1.1, != 1.3.0) |
437 | 435 | stamp (0.3.0) |
436 | + temple (0.5.5) | |
438 | 437 | test_after_commit (0.0.1) |
439 | 438 | therubyracer (0.10.2) |
440 | 439 | libv8 (~> 3.3.10) |
... | ... | @@ -444,6 +443,7 @@ GEM |
444 | 443 | rack (>= 1.0.0) |
445 | 444 | thor (0.16.0) |
446 | 445 | tilt (1.3.3) |
446 | + timers (1.0.2) | |
447 | 447 | treetop (1.4.12) |
448 | 448 | polyglot |
449 | 449 | polyglot (>= 0.3.1) |
... | ... | @@ -455,8 +455,6 @@ GEM |
455 | 455 | kgio (~> 2.6) |
456 | 456 | rack |
457 | 457 | raindrops (~> 0.7) |
458 | - vegas (0.1.11) | |
459 | - rack (>= 1.0.0) | |
460 | 458 | virtus (0.5.2) |
461 | 459 | backports (~> 2.6.1) |
462 | 460 | warden (1.2.1) |
... | ... | @@ -534,17 +532,17 @@ DEPENDENCIES |
534 | 532 | rb-fsevent |
535 | 533 | rb-inotify |
536 | 534 | redcarpet (~> 2.2.2) |
537 | - resque! | |
538 | - resque_mailer | |
539 | - resque_spec | |
540 | 535 | rspec-rails |
541 | 536 | sass-rails (~> 3.2.5) |
542 | 537 | sdoc |
543 | 538 | seed-fu |
544 | 539 | settingslogic |
545 | 540 | shoulda-matchers (= 1.3.0) |
541 | + sidekiq (= 2.6.4) | |
546 | 542 | simplecov |
543 | + sinatra | |
547 | 544 | six |
545 | + slim | |
548 | 546 | spinach-rails |
549 | 547 | stamp |
550 | 548 | test_after_commit | ... | ... |
Procfile
app/controllers/admin/dashboard_controller.rb
... | ... | @@ -3,10 +3,6 @@ class Admin::DashboardController < AdminController |
3 | 3 | @projects = Project.order("created_at DESC").limit(10) |
4 | 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 | 6 | rescue Redis::InheritedError |
11 | 7 | @resque_accessible = false |
12 | 8 | end | ... | ... |
app/mailers/notify.rb
app/models/project.rb
... | ... | @@ -251,7 +251,7 @@ class Project < ActiveRecord::Base |
251 | 251 | |
252 | 252 | def send_move_instructions |
253 | 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 | 255 | end |
256 | 256 | end |
257 | 257 | ... | ... |
app/models/system_hook.rb
app/observers/issue_observer.rb
... | ... | @@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer |
3 | 3 | |
4 | 4 | def after_create(issue) |
5 | 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 | 7 | end |
8 | 8 | end |
9 | 9 | |
... | ... | @@ -16,7 +16,7 @@ class IssueObserver < ActiveRecord::Observer |
16 | 16 | if status |
17 | 17 | Note.create_status_change_note(issue, current_user, status) |
18 | 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 | 20 | end |
21 | 21 | end |
22 | 22 | end |
... | ... | @@ -27,7 +27,7 @@ class IssueObserver < ActiveRecord::Observer |
27 | 27 | recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id } |
28 | 28 | |
29 | 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 | 31 | end |
32 | 32 | end |
33 | 33 | end | ... | ... |
app/observers/merge_request_observer.rb
... | ... | @@ -3,7 +3,7 @@ class MergeRequestObserver < ActiveRecord::Observer |
3 | 3 | |
4 | 4 | def after_create(merge_request) |
5 | 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 | 7 | end |
8 | 8 | end |
9 | 9 | |
... | ... | @@ -25,7 +25,7 @@ class MergeRequestObserver < ActiveRecord::Observer |
25 | 25 | recipients_ids.delete current_user.id |
26 | 26 | |
27 | 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 | 29 | end |
30 | 30 | end |
31 | 31 | end | ... | ... |
app/observers/note_observer.rb
... | ... | @@ -11,7 +11,7 @@ class NoteObserver < ActiveRecord::Observer |
11 | 11 | notify_team(note) |
12 | 12 | elsif note.notify_author |
13 | 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 | 15 | else |
16 | 16 | # Otherwise ignore it |
17 | 17 | nil |
... | ... | @@ -26,7 +26,7 @@ class NoteObserver < ActiveRecord::Observer |
26 | 26 | |
27 | 27 | if Notify.respond_to? notify_method |
28 | 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 | 30 | end |
31 | 31 | end |
32 | 32 | end | ... | ... |
app/observers/user_observer.rb
... | ... | @@ -2,7 +2,7 @@ class UserObserver < ActiveRecord::Observer |
2 | 2 | def after_create(user) |
3 | 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 | 6 | end |
7 | 7 | |
8 | 8 | def after_destroy user | ... | ... |
app/observers/users_project_observer.rb
1 | 1 | class UsersProjectObserver < ActiveRecord::Observer |
2 | 2 | def after_commit(users_project) |
3 | 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 | 5 | end |
6 | 6 | |
7 | 7 | def after_create(users_project) | ... | ... |
app/views/admin/dashboard/index.html.haml
1 | 1 | .admin_dash.row |
2 | - .span3 | |
2 | + .span4 | |
3 | 3 | .ui-box |
4 | 4 | %h5.title Projects |
5 | 5 | .data.padded |
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | %h1= Project.count |
8 | 8 | %hr |
9 | 9 | = link_to 'New Project', new_project_path, class: "btn small" |
10 | - .span3 | |
10 | + .span4 | |
11 | 11 | .ui-box |
12 | 12 | %h5.title Groups |
13 | 13 | .data.padded |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | %h1= Group.count |
16 | 16 | %hr |
17 | 17 | = link_to 'New Group', new_admin_group_path, class: "btn small" |
18 | - .span3 | |
18 | + .span4 | |
19 | 19 | .ui-box |
20 | 20 | %h5.title Users |
21 | 21 | .data.padded |
... | ... | @@ -23,25 +23,6 @@ |
23 | 23 | %h1= User.count |
24 | 24 | %hr |
25 | 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 | 27 | .row |
47 | 28 | .span6 | ... | ... |
app/views/admin/resque/show.html.haml
app/views/layouts/admin.html.haml
app/workers/post_receive.rb
1 | 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 | 7 | repo_path.gsub!(Gitlab.config.gitolite.repos_path.to_s, "") |
6 | 8 | repo_path.gsub!(/.git$/, "") |
7 | 9 | repo_path.gsub!(/^\//, "") | ... | ... |
app/workers/system_hook_worker.rb
config/initializers/4_resque.rb
... | ... | @@ -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 @@ |
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 | 3 | Gitlab::Application.routes.draw do |
2 | 4 | # |
3 | 5 | # Search |
... | ... | @@ -8,9 +10,10 @@ Gitlab::Application.routes.draw do |
8 | 10 | require 'api' |
9 | 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 | 18 | # Enable Grack support |
16 | 19 | mount Grack::Bundle.new({ | ... | ... |
features/steps/admin/admin_active_tab.rb
features/support/env.rb
... | ... | @@ -6,6 +6,8 @@ require './config/environment' |
6 | 6 | require 'rspec' |
7 | 7 | require 'database_cleaner' |
8 | 8 | require 'spinach/capybara' |
9 | +require 'sidekiq/testing/inline' | |
10 | + | |
9 | 11 | |
10 | 12 | %w(gitolite_stub stubbed_repository valid_commit).each do |f| |
11 | 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 | 871 | |
872 | 872 | |
873 | 873 | namespace :resque do |
874 | - desc "GITLAB | Check the configuration of Resque" | |
874 | + desc "GITLAB | Check the configuration of Sidekiq" | |
875 | 875 | task check: :environment do |
876 | 876 | warn_user_is_not_gitlab |
877 | 877 | start_checking "Resque" |
... | ... | @@ -888,7 +888,7 @@ namespace :gitlab do |
888 | 888 | def check_resque_running |
889 | 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 | 892 | puts "yes".green |
893 | 893 | else |
894 | 894 | puts "no".red |
... | ... | @@ -899,7 +899,7 @@ namespace :gitlab do |
899 | 899 | ) |
900 | 900 | for_more_information( |
901 | 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 | 904 | fix_and_rerun |
905 | 905 | end | ... | ... |
lib/tasks/resque.rake
... | ... | @@ -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 @@ |
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
resque_dev.sh
spec/models/system_hook_spec.rb
... | ... | @@ -23,41 +23,31 @@ describe SystemHook do |
23 | 23 | end |
24 | 24 | |
25 | 25 | it "project_create hook" do |
26 | - with_resque do | |
27 | - project = create(:project) | |
28 | - end | |
26 | + project = create(:project) | |
29 | 27 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once |
30 | 28 | end |
31 | 29 | |
32 | 30 | it "project_destroy hook" do |
33 | 31 | project = create(:project) |
34 | - with_resque do | |
35 | - project.destroy | |
36 | - end | |
32 | + project.destroy | |
37 | 33 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once |
38 | 34 | end |
39 | 35 | |
40 | 36 | it "user_create hook" do |
41 | - with_resque do | |
42 | - create(:user) | |
43 | - end | |
37 | + create(:user) | |
44 | 38 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once |
45 | 39 | end |
46 | 40 | |
47 | 41 | it "user_destroy hook" do |
48 | 42 | user = create(:user) |
49 | - with_resque do | |
50 | - user.destroy | |
51 | - end | |
43 | + user.destroy | |
52 | 44 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once |
53 | 45 | end |
54 | 46 | |
55 | 47 | it "project_create hook" do |
56 | 48 | user = create(:user) |
57 | 49 | project = create(:project) |
58 | - with_resque do | |
59 | - project.team << [user, :master] | |
60 | - end | |
50 | + project.team << [user, :master] | |
61 | 51 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once |
62 | 52 | end |
63 | 53 | |
... | ... | @@ -65,11 +55,8 @@ describe SystemHook do |
65 | 55 | user = create(:user) |
66 | 56 | project = create(:project) |
67 | 57 | project.team << [user, :master] |
68 | - with_resque do | |
69 | - project.users_projects.clear | |
70 | - end | |
58 | + project.users_projects.clear | |
71 | 59 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once |
72 | 60 | end |
73 | 61 | end |
74 | - | |
75 | 62 | end | ... | ... |
spec/observers/issue_observer_spec.rb
... | ... | @@ -21,8 +21,7 @@ describe IssueObserver do |
21 | 21 | end |
22 | 22 | |
23 | 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 | 26 | subject.after_create(issue) |
28 | 27 | end |
... | ... | @@ -71,6 +70,7 @@ describe IssueObserver do |
71 | 70 | context 'a status "closed"' do |
72 | 71 | it 'note is created if the issue is being closed' do |
73 | 72 | issue.should_receive(:is_being_closed?).and_return(true) |
73 | + Notify.should_receive(:issue_status_changed_email).twice | |
74 | 74 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
75 | 75 | |
76 | 76 | subject.after_update(issue) |
... | ... | @@ -85,7 +85,7 @@ describe IssueObserver do |
85 | 85 | |
86 | 86 | it 'notification is delivered if the issue being closed' do |
87 | 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 | 89 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
90 | 90 | |
91 | 91 | subject.after_update(issue) |
... | ... | @@ -104,7 +104,7 @@ describe IssueObserver do |
104 | 104 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
105 | 105 | issue_without_assignee.stub(:is_being_closed?).and_return(true) |
106 | 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 | 108 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed') |
109 | 109 | |
110 | 110 | subject.after_update(issue_without_assignee) |
... | ... | @@ -113,6 +113,7 @@ describe IssueObserver do |
113 | 113 | |
114 | 114 | context 'a status "reopened"' do |
115 | 115 | it 'note is created if the issue is being reopened' do |
116 | + Notify.should_receive(:issue_status_changed_email).twice | |
116 | 117 | issue.should_receive(:is_being_reopened?).and_return(true) |
117 | 118 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
118 | 119 | |
... | ... | @@ -128,7 +129,7 @@ describe IssueObserver do |
128 | 129 | |
129 | 130 | it 'notification is delivered if the issue being reopened' do |
130 | 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 | 133 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
133 | 134 | |
134 | 135 | subject.after_update(issue) |
... | ... | @@ -147,7 +148,7 @@ describe IssueObserver do |
147 | 148 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
148 | 149 | issue_without_assignee.stub(:is_being_closed?).and_return(false) |
149 | 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 | 152 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened') |
152 | 153 | |
153 | 154 | subject.after_update(issue_without_assignee) |
... | ... | @@ -164,8 +165,7 @@ describe IssueObserver do |
164 | 165 | end |
165 | 166 | |
166 | 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 | 169 | end |
170 | 170 | |
171 | 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 | 21 | end |
22 | 22 | |
23 | 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 | 25 | subject.after_create(mr) |
28 | 26 | end |
29 | 27 | |
... | ... | @@ -158,8 +156,7 @@ describe MergeRequestObserver do |
158 | 156 | end |
159 | 157 | |
160 | 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 | 160 | end |
164 | 161 | |
165 | 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 | 4 | subject { NoteObserver.instance } |
5 | 5 | |
6 | 6 | let(:team_without_author) { (1..2).map { |n| double :user, id: n } } |
7 | - let(:delivery_success) { double deliver: true } | |
8 | 7 | |
9 | 8 | describe '#after_create' do |
10 | 9 | let(:note) { double :note } |
... | ... | @@ -45,13 +44,13 @@ describe NoteObserver do |
45 | 44 | note.stub(:id).and_return(42) |
46 | 45 | author = double :user, id: 1 |
47 | 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 | 49 | subject.after_create(note) |
51 | 50 | end |
52 | 51 | |
53 | 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 | 55 | subject.after_create(note) |
57 | 56 | end |
... | ... | @@ -71,28 +70,28 @@ describe NoteObserver do |
71 | 70 | context 'notifies team of a new note on' do |
72 | 71 | it 'a commit' do |
73 | 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 | 75 | subject.send(:notify_team, note) |
77 | 76 | end |
78 | 77 | |
79 | 78 | it 'an issue' do |
80 | 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 | 82 | subject.send(:notify_team, note) |
84 | 83 | end |
85 | 84 | |
86 | 85 | it 'a wiki page' do |
87 | 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 | 89 | subject.send(:notify_team, note) |
91 | 90 | end |
92 | 91 | |
93 | 92 | it 'a merge request' do |
94 | 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 | 96 | subject.send(:notify_team, note) |
98 | 97 | end |
... | ... | @@ -100,16 +99,16 @@ describe NoteObserver do |
100 | 99 | it 'a wall' do |
101 | 100 | # Note: wall posts have #noteable_type of nil |
102 | 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 | 104 | subject.send(:notify_team, note) |
106 | 105 | end |
107 | 106 | end |
108 | 107 | |
109 | 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 | 112 | end |
114 | 113 | end |
115 | 114 | |
... | ... | @@ -125,4 +124,8 @@ describe NoteObserver do |
125 | 124 | subject.send(:team_without_note_author, note).should == team_without_author |
126 | 125 | end |
127 | 126 | end |
127 | + | |
128 | + def notify | |
129 | + Notify | |
130 | + end | |
128 | 131 | end | ... | ... |
spec/observers/user_observer_spec.rb
... | ... | @@ -10,24 +10,14 @@ describe UserObserver do |
10 | 10 | end |
11 | 11 | |
12 | 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 | 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 | 16 | end |
27 | 17 | |
28 | 18 | it 'trigger logger' do |
29 | 19 | Gitlab::AppLogger.should_receive(:info) |
30 | - subject.after_create(user) | |
20 | + create(:user) | |
31 | 21 | end |
32 | 22 | end |
33 | 23 | end | ... | ... |
spec/requests/admin/admin_users_spec.rb
... | ... | @@ -41,7 +41,7 @@ describe "Admin::Users" do |
41 | 41 | end |
42 | 42 | |
43 | 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 | 46 | User.observers.enable :user_observer do |
47 | 47 | click_button "Save" |
... | ... | @@ -50,9 +50,7 @@ describe "Admin::Users" do |
50 | 50 | |
51 | 51 | it "should send valid email to user with email & password" do |
52 | 52 | User.observers.enable :user_observer do |
53 | - with_resque do | |
54 | - click_button "Save" | |
55 | - end | |
53 | + click_button "Save" | |
56 | 54 | user = User.last |
57 | 55 | email = ActionMailer::Base.deliveries.last |
58 | 56 | email.subject.should have_content("Account was created") | ... | ... |
spec/spec_helper.rb
1 | 1 | require 'simplecov' unless ENV['CI'] |
2 | 2 | |
3 | + | |
3 | 4 | # This file is copied to spec/ when you run 'rails generate rspec:install' |
4 | 5 | ENV["RAILS_ENV"] ||= 'test' |
5 | 6 | require File.expand_path("../../config/environment", __FILE__) |
... | ... | @@ -8,6 +9,7 @@ require 'capybara/rails' |
8 | 9 | require 'capybara/rspec' |
9 | 10 | require 'webmock/rspec' |
10 | 11 | require 'email_spec' |
12 | +require 'sidekiq/testing/inline' | |
11 | 13 | |
12 | 14 | # Requires supporting ruby files with custom matchers and macros, etc, |
13 | 15 | # in spec/support/ and its subdirectories. | ... | ... |
spec/workers/post_receive_spec.rb
... | ... | @@ -4,7 +4,7 @@ describe PostReceive do |
4 | 4 | |
5 | 5 | context "as a resque worker" do |
6 | 6 | it "reponds to #perform" do |
7 | - PostReceive.should respond_to(:perform) | |
7 | + PostReceive.new.should respond_to(:perform) | |
8 | 8 | end |
9 | 9 | end |
10 | 10 | |
... | ... | @@ -15,7 +15,7 @@ describe PostReceive do |
15 | 15 | |
16 | 16 | it "fetches the correct project" do |
17 | 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 | 19 | end |
20 | 20 | |
21 | 21 | it "does not run if the author is not in the project" do |
... | ... | @@ -24,7 +24,7 @@ describe PostReceive do |
24 | 24 | project.should_not_receive(:observe_push) |
25 | 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 | 28 | end |
29 | 29 | |
30 | 30 | it "asks the project to trigger all hooks" do |
... | ... | @@ -34,7 +34,7 @@ describe PostReceive do |
34 | 34 | project.should_receive(:update_merge_requests) |
35 | 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 | 38 | end |
39 | 39 | end |
40 | 40 | ... | ... |