Commit 216d5e2c authored by Izaak Alpert's avatar Izaak Alpert

Fix intermittently failing notification_service test

Change-Id: Ic23cb46901f8adc77943bf3cc79566587364e22a
parent 5d56da6b
...@@ -3,6 +3,7 @@ require 'spec_helper' ...@@ -3,6 +3,7 @@ require 'spec_helper'
describe API::API do describe API::API do
include ApiHelpers include ApiHelpers
before(:each) { enable_observers } before(:each) { enable_observers }
after(:each) {disable_observers}
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
......
...@@ -2,7 +2,6 @@ require 'spec_helper' ...@@ -2,7 +2,6 @@ require 'spec_helper'
describe NotificationService do describe NotificationService do
let(:notification) { NotificationService.new } let(:notification) { NotificationService.new }
describe 'Keys' do describe 'Keys' do
describe :new_key do describe :new_key do
let(:key) { create(:personal_key) } let(:key) { create(:personal_key) }
......
...@@ -34,43 +34,19 @@ module TestEnv ...@@ -34,43 +34,19 @@ module TestEnv
setup_test_repos(opts) if opts[:repos] == true setup_test_repos(opts) if opts[:repos] == true
end end
def testing_path def enable_observers
Rails.root.join('tmp', 'test-git-base-path') ActiveRecord::Base.observers.enable(:all)
end
def seed_repo_path
Rails.root.join('tmp', 'repositories', 'gitlabhq')
end
def seed_satellite_path
Rails.root.join('tmp', 'satellite', 'gitlabhq')
end
def satellite_path
"#{testing_path()}/satellite"
end end
def repo(namespace, name) def disable_observers
unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) ActiveRecord::Base.observers.disable(:all)
repo = File.join(testing_path(), "#{namespace.path}/#{name}.git")
else
repo = File.join(testing_path(), "#{name}.git")
end
end end
def satellite(namespace, name) def disable_mailer
unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) NotificationService.any_instance.stub(mailer: double.as_null_object)
satellite_repo = File.join(satellite_path, namespace.path, name)
else
satellite_repo = File.join(satellite_path, name)
end
end end
def enable_mailer
NotificationService.any_instance.unstub(:mailer)
def setup_test_repos(opts ={})
create_repo(nil, 'gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('')
create_repo(nil, 'source_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('source_')
create_repo(nil, 'target_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('target_')
end end
def setup_stubs() def setup_stubs()
...@@ -110,19 +86,6 @@ module TestEnv ...@@ -110,19 +86,6 @@ module TestEnv
) )
end end
def clear_test_repo_dir
setup_stubs
# Use tmp dir for FS manipulations
repos_path = testing_path()
# Remove tmp/test-git-base-path
FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path
# Recreate tmp/test-git-base-path
FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path
#Since much more is happening in satellites
FileUtils.mkdir_p Gitlab.config.satellites.path
end
def clear_repo_dir(namespace, name) def clear_repo_dir(namespace, name)
setup_stubs setup_stubs
#Clean any .wiki.git that may have been created #Clean any .wiki.git that may have been created
...@@ -139,6 +102,60 @@ module TestEnv ...@@ -139,6 +102,60 @@ module TestEnv
create_satellite(repo, namespace, name) create_satellite(repo, namespace, name)
end end
private
def testing_path
Rails.root.join('tmp', 'test-git-base-path')
end
def seed_repo_path
Rails.root.join('tmp', 'repositories', 'gitlabhq')
end
def seed_satellite_path
Rails.root.join('tmp', 'satellite', 'gitlabhq')
end
def satellite_path
"#{testing_path()}/satellite"
end
def repo(namespace, name)
unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?)
repo = File.join(testing_path(), "#{namespace.path}/#{name}.git")
else
repo = File.join(testing_path(), "#{name}.git")
end
end
def satellite(namespace, name)
unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?)
satellite_repo = File.join(satellite_path, namespace.path, name)
else
satellite_repo = File.join(satellite_path, name)
end
end
def setup_test_repos(opts ={})
create_repo(nil, 'gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('')
create_repo(nil, 'source_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('source_')
create_repo(nil, 'target_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('target_')
end
def clear_test_repo_dir
setup_stubs
# Use tmp dir for FS manipulations
repos_path = testing_path()
# Remove tmp/test-git-base-path
FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path
# Recreate tmp/test-git-base-path
FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path
#Since much more is happening in satellites
FileUtils.mkdir_p Gitlab.config.satellites.path
end
# Create a testing satellite, and clone the source repo into it # Create a testing satellite, and clone the source repo into it
def create_satellite(source_repo, namespace, satellite_name) def create_satellite(source_repo, namespace, satellite_name)
satellite_repo = satellite(namespace, satellite_name) satellite_repo = satellite(namespace, satellite_name)
...@@ -152,15 +169,5 @@ module TestEnv ...@@ -152,15 +169,5 @@ module TestEnv
system(command) system(command)
end end
def enable_observers
ActiveRecord::Base.observers.enable(:all)
end
def disable_observers
ActiveRecord::Base.observers.disable(:all)
end
def disable_mailer
NotificationService.any_instance.stub(mailer: double.as_null_object)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment