Skip to content

Commit

Permalink
sidekiq with green tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Jan 9, 2013
1 parent 71bd956 commit 9773ccc
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: bundle exec rails s -p $PORT
worker: bundle exec rake sidekiq:start
worker: bundle exec sidekiq -q post_receive,mailer,system_hook,common,default
File renamed without changes.
2 changes: 1 addition & 1 deletion features/steps/admin/admin_active_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class AdminActiveTab < Spinach::FeatureSteps
end

Then 'the active main tab should be Resque' do
ensure_active_main_tab('Resque')
ensure_active_main_tab('Background Jobs')
end
end
2 changes: 2 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require 'rspec'
require 'database_cleaner'
require 'spinach/capybara'
require 'sidekiq/testing/inline'


%w(gitolite_stub stubbed_repository valid_commit).each do |f|
require Rails.root.join('spec', 'support', f)
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/post-receive
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

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

Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/gitlab/check.rake
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ namespace :gitlab do


namespace :resque do
desc "GITLAB | Check the configuration of Resque"
desc "GITLAB | Check the configuration of Sidekiq"
task check: :environment do
warn_user_is_not_gitlab
start_checking "Resque"
Expand All @@ -888,7 +888,7 @@ namespace :gitlab do
def check_resque_running
print "Running? ... "

if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/)
if run_and_match("ps aux | grep -i sidekiq", /sidekiq-[\d\.]+:.+$/)
puts "yes".green
else
puts "no".red
Expand All @@ -899,7 +899,7 @@ namespace :gitlab do
)
for_more_information(
see_installation_guide_section("Install Init Script"),
"see log/resque.log for possible errors"
"see log/sidekiq.log for possible errors"
)
fix_and_rerun
end
Expand Down
25 changes: 6 additions & 19 deletions spec/models/system_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,40 @@
end

it "project_create hook" do
with_resque do
project = create(:project)
end
project = create(:project)
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
end

it "project_destroy hook" do
project = create(:project)
with_resque do
project.destroy
end
project.destroy
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
end

it "user_create hook" do
with_resque do
create(:user)
end
create(:user)
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
end

it "user_destroy hook" do
user = create(:user)
with_resque do
user.destroy
end
user.destroy
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
end

it "project_create hook" do
user = create(:user)
project = create(:project)
with_resque do
project.team << [user, :master]
end
project.team << [user, :master]
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end

it "project_destroy hook" do
user = create(:user)
project = create(:project)
project.team << [user, :master]
with_resque do
project.users_projects.clear
end
project.users_projects.clear
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
end
end

end
16 changes: 8 additions & 8 deletions spec/observers/issue_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
end

it 'sends an email to the assignee' do
Notify.should_receive(:new_issue_email).with(issue.id).
and_return(double(deliver: true))
Notify.should_receive(:new_issue_email).with(issue.id)

subject.after_create(issue)
end
Expand Down Expand Up @@ -71,6 +70,7 @@
context 'a status "closed"' do
it 'note is created if the issue is being closed' do
issue.should_receive(:is_being_closed?).and_return(true)
Notify.should_receive(:issue_status_changed_email).twice
Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')

subject.after_update(issue)
Expand All @@ -85,7 +85,7 @@

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

subject.after_update(issue)
Expand All @@ -104,7 +104,7 @@
issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
issue_without_assignee.stub(:is_being_closed?).and_return(true)
issue_without_assignee.stub(:is_being_reopened?).and_return(false)
Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).once
Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed')

subject.after_update(issue_without_assignee)
Expand All @@ -113,6 +113,7 @@

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

Expand All @@ -128,7 +129,7 @@

it 'notification is delivered if the issue being reopened' do
issue.stub(:is_being_reopened?).and_return(true)
Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).twice
Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')

subject.after_update(issue)
Expand All @@ -147,7 +148,7 @@
issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
issue_without_assignee.stub(:is_being_closed?).and_return(false)
issue_without_assignee.stub(:is_being_reopened?).and_return(true)
Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).once
Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened')

subject.after_update(issue_without_assignee)
Expand All @@ -164,8 +165,7 @@
end

def it_sends_a_reassigned_email_to(recipient)
Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id).
and_return(double(deliver: true))
Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id)
end

def it_does_not_send_a_reassigned_email_to(recipient)
Expand Down
7 changes: 2 additions & 5 deletions spec/observers/merge_request_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
end

it 'sends an email to the assignee' do
Notify.should_receive(:new_merge_request_email).with(mr.id).
and_return(double(deliver: true))

Notify.should_receive(:new_merge_request_email).with(mr.id)
subject.after_create(mr)
end

Expand Down Expand Up @@ -158,8 +156,7 @@
end

def it_sends_a_reassigned_email_to(recipient)
Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id).
and_return(double(deliver: true))
Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id)
end

def it_does_not_send_a_reassigned_email_to(recipient)
Expand Down
23 changes: 13 additions & 10 deletions spec/observers/note_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
subject { NoteObserver.instance }

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

describe '#after_create' do
let(:note) { double :note }
Expand Down Expand Up @@ -45,13 +44,13 @@
note.stub(:id).and_return(42)
author = double :user, id: 1
note.stub(:commit_author).and_return(author)
Notify.should_receive(:note_commit_email).and_return(delivery_success)
Notify.should_receive(:note_commit_email)

subject.after_create(note)
end

it 'does not notify the author of a commit when not flagged to notify the author' do
Notify.should_not_receive(:note_commit_email)
notify.should_not_receive(:note_commit_email)

subject.after_create(note)
end
Expand All @@ -71,45 +70,45 @@
context 'notifies team of a new note on' do
it 'a commit' do
note.stub(:noteable_type).and_return('Commit')
Notify.should_receive(:note_commit_email).twice.and_return(delivery_success)
notify.should_receive(:note_commit_email).twice

subject.send(:notify_team, note)
end

it 'an issue' do
note.stub(:noteable_type).and_return('Issue')
Notify.should_receive(:note_issue_email).twice.and_return(delivery_success)
notify.should_receive(:note_issue_email).twice

subject.send(:notify_team, note)
end

it 'a wiki page' do
note.stub(:noteable_type).and_return('Wiki')
Notify.should_receive(:note_wiki_email).twice.and_return(delivery_success)
notify.should_receive(:note_wiki_email).twice

subject.send(:notify_team, note)
end

it 'a merge request' do
note.stub(:noteable_type).and_return('MergeRequest')
Notify.should_receive(:note_merge_request_email).twice.and_return(delivery_success)
notify.should_receive(:note_merge_request_email).twice

subject.send(:notify_team, note)
end

it 'a wall' do
# Note: wall posts have #noteable_type of nil
note.stub(:noteable_type).and_return(nil)
Notify.should_receive(:note_wall_email).twice.and_return(delivery_success)
notify.should_receive(:note_wall_email).twice

subject.send(:notify_team, note)
end
end

it 'does nothing for a new note on a snippet' do
note.stub(:noteable_type).and_return('Snippet')
note.stub(:noteable_type).and_return('Snippet')

subject.send(:notify_team, note).should be_nil
subject.send(:notify_team, note).should be_nil
end
end

Expand All @@ -125,4 +124,8 @@
subject.send(:team_without_note_author, note).should == team_without_author
end
end

def notify
Notify
end
end
16 changes: 3 additions & 13 deletions spec/observers/user_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@
end

context 'when a new user is created' do
let(:user) { double(:user, id: 42,
password: 'P@ssword!',
name: 'John',
email: '[email protected]',
username: 'root',
create_namespace: true) }
let(:notification) { double :notification }

it 'sends an email' do
notification.should_receive(:deliver)
Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification)

subject.after_create(user)
Notify.should_receive(:new_user_email)
create(:user)
end

it 'trigger logger' do
Gitlab::AppLogger.should_receive(:info)
subject.after_create(user)
create(:user)
end
end
end
6 changes: 2 additions & 4 deletions spec/requests/admin/admin_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it "should call send mail" do
Notify.should_receive(:new_user_email).and_return(stub(deliver: true))
Notify.should_receive(:new_user_email)

User.observers.enable :user_observer do
click_button "Save"
Expand All @@ -50,9 +50,7 @@

it "should send valid email to user with email & password" do
User.observers.enable :user_observer do
with_resque do
click_button "Save"
end
click_button "Save"
user = User.last
email = ActionMailer::Base.deliveries.last
email.subject.should have_content("Account was created")
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'simplecov' unless ENV['CI']


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

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand Down
8 changes: 4 additions & 4 deletions spec/workers/post_receive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

context "as a resque worker" do
it "reponds to #perform" do
PostReceive.should respond_to(:perform)
PostReceive.new.should respond_to(:perform)
end
end

Expand All @@ -15,7 +15,7 @@

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

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

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

it "asks the project to trigger all hooks" do
Expand All @@ -34,7 +34,7 @@
project.should_receive(:update_merge_requests)
project.should_receive(:observe_push)

PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
end
end

Expand Down

0 comments on commit 9773ccc

Please sign in to comment.