Commit 51907eef authored by Sean McGivern's avatar Sean McGivern

Merge branch '4813-fix-ee-projects-destroy_service_spec' into 'master'

Reset column information after the schema is migrated in MigrationsHelpers.schema_migrate_up!

Closes #4813

See merge request gitlab-org/gitlab-ee!4397
parents fb3005fe 14213733
...@@ -105,10 +105,6 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -105,10 +105,6 @@ class ApplicationSetting < ActiveRecord::Base
presence: true, presence: true,
numericality: { only_integer: true, greater_than: 0 } numericality: { only_integer: true, greater_than: 0 }
validates :repository_size_limit,
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :max_artifacts_size, validates :max_artifacts_size,
presence: true, presence: true,
numericality: { only_integer: true, greater_than: 0 } numericality: { only_integer: true, greater_than: 0 }
...@@ -119,14 +115,6 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -119,14 +115,6 @@ class ApplicationSetting < ActiveRecord::Base
presence: true, presence: true,
numericality: { only_integer: true, greater_than: 0 } numericality: { only_integer: true, greater_than: 0 }
validates :elasticsearch_url,
presence: { message: "can't be blank when indexing is enabled" },
if: :elasticsearch_indexing?
validates :elasticsearch_aws_region,
presence: { message: "can't be blank when using aws hosted elasticsearch" },
if: ->(setting) { setting.elasticsearch_indexing? && setting.elasticsearch_aws? }
validates :repository_storages, presence: true validates :repository_storages, presence: true
validate :check_repository_storages validate :check_repository_storages
...@@ -343,11 +331,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -343,11 +331,7 @@ class ApplicationSetting < ActiveRecord::Base
usage_ping_enabled: Settings.gitlab['usage_ping_enabled'], usage_ping_enabled: Settings.gitlab['usage_ping_enabled'],
gitaly_timeout_fast: 10, gitaly_timeout_fast: 10,
gitaly_timeout_medium: 30, gitaly_timeout_medium: 30,
gitaly_timeout_default: 55, gitaly_timeout_default: 55
slack_app_enabled: false,
slack_app_id: nil,
slack_app_secret: nil,
slack_app_verification_token: nil
} }
end end
...@@ -363,36 +347,6 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -363,36 +347,6 @@ class ApplicationSetting < ActiveRecord::Base
end end
end end
def elasticsearch_indexing
License.feature_available?(:elastic_search) && super
end
alias_method :elasticsearch_indexing?, :elasticsearch_indexing
def elasticsearch_search
License.feature_available?(:elastic_search) && super
end
alias_method :elasticsearch_search?, :elasticsearch_search
def elasticsearch_url
read_attribute(:elasticsearch_url).split(',').map(&:strip)
end
def elasticsearch_url=(values)
cleaned = values.split(',').map {|url| url.strip.gsub(%r{/*\z}, '') }
write_attribute(:elasticsearch_url, cleaned.join(','))
end
def elasticsearch_config
{
url: elasticsearch_url,
aws: elasticsearch_aws,
aws_access_key: elasticsearch_aws_access_key,
aws_secret_access_key: elasticsearch_aws_secret_access_key,
aws_region: elasticsearch_aws_region
}
end
def home_page_url_column_exists? def home_page_url_column_exists?
ActiveRecord::Base.connection.column_exists?(:application_settings, :home_page_url) ActiveRecord::Base.connection.column_exists?(:application_settings, :home_page_url)
end end
......
...@@ -27,21 +27,40 @@ module EE ...@@ -27,21 +27,40 @@ module EE
numericality: { allow_nil: true, only_integer: true, greater_than: 0 } numericality: { allow_nil: true, only_integer: true, greater_than: 0 }
validate :mirror_capacity_threshold_less_than validate :mirror_capacity_threshold_less_than
validates :repository_size_limit,
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :elasticsearch_url,
presence: { message: "can't be blank when indexing is enabled" },
if: ->(setting) { setting.elasticsearch_indexing? }
validates :elasticsearch_aws_region,
presence: { message: "can't be blank when using aws hosted elasticsearch" },
if: ->(setting) { setting.elasticsearch_indexing? && setting.elasticsearch_aws? }
end end
module ClassMethods module ClassMethods
extend ::Gitlab::Utils::Override
override :defaults
def defaults def defaults
super.merge( super.merge(
allow_group_owners_to_manage_ldap: true,
default_project_creation: ::EE::Gitlab::Access::DEVELOPER_MASTER_PROJECT_ACCESS, default_project_creation: ::EE::Gitlab::Access::DEVELOPER_MASTER_PROJECT_ACCESS,
elasticsearch_url: ENV['ELASTIC_URL'] || 'http://localhost:9200',
elasticsearch_aws: false, elasticsearch_aws: false,
elasticsearch_aws_region: ENV['ELASTIC_REGION'] || 'us-east-1', elasticsearch_aws_region: ENV['ELASTIC_REGION'] || 'us-east-1',
repository_size_limit: 0, elasticsearch_url: ENV['ELASTIC_URL'] || 'http://localhost:9200',
mirror_max_delay: Settings.gitlab['mirror_max_delay'],
mirror_max_capacity: Settings.gitlab['mirror_max_capacity'],
mirror_capacity_threshold: Settings.gitlab['mirror_capacity_threshold'], mirror_capacity_threshold: Settings.gitlab['mirror_capacity_threshold'],
allow_group_owners_to_manage_ldap: true, mirror_max_capacity: Settings.gitlab['mirror_max_capacity'],
mirror_available: true mirror_max_delay: Settings.gitlab['mirror_max_delay'],
mirror_available: true,
repository_size_limit: 0,
slack_app_enabled: false,
slack_app_id: nil,
slack_app_secret: nil,
slack_app_verification_token: nil
) )
end end
end end
...@@ -50,6 +69,40 @@ module EE ...@@ -50,6 +69,40 @@ module EE
check_namespace_plan? && ::Gitlab.dev_env_or_com? check_namespace_plan? && ::Gitlab.dev_env_or_com?
end end
def elasticsearch_indexing
return false unless elasticsearch_indexing_column_exists?
License.feature_available?(:elastic_search) && super
end
alias_method :elasticsearch_indexing?, :elasticsearch_indexing
def elasticsearch_search
return false unless elasticsearch_search_column_exists?
License.feature_available?(:elastic_search) && super
end
alias_method :elasticsearch_search?, :elasticsearch_search
def elasticsearch_url
read_attribute(:elasticsearch_url).split(',').map(&:strip)
end
def elasticsearch_url=(values)
cleaned = values.split(',').map {|url| url.strip.gsub(%r{/*\z}, '') }
write_attribute(:elasticsearch_url, cleaned.join(','))
end
def elasticsearch_config
{
url: elasticsearch_url,
aws: elasticsearch_aws,
aws_access_key: elasticsearch_aws_access_key,
aws_secret_access_key: elasticsearch_aws_secret_access_key,
aws_region: elasticsearch_aws_region
}
end
private private
def mirror_max_delay_in_minutes def mirror_max_delay_in_minutes
...@@ -63,5 +116,13 @@ module EE ...@@ -63,5 +116,13 @@ module EE
errors.add(:mirror_capacity_threshold, "Project's mirror capacity threshold can't be higher than it's maximum capacity") errors.add(:mirror_capacity_threshold, "Project's mirror capacity threshold can't be higher than it's maximum capacity")
end end
end end
def elasticsearch_indexing_column_exists?
ActiveRecord::Base.connection.column_exists?(:application_settings, :elasticsearch_indexing)
end
def elasticsearch_search_column_exists?
ActiveRecord::Base.connection.column_exists?(:application_settings, :elasticsearch_search)
end
end end
end end
require Rails.root.join('spec', 'support', 'stub_configuration') require_dependency Rails.root.join('spec', 'support', 'stub_configuration')
class Spinach::Features::GlobalSearch < Spinach::FeatureSteps class Spinach::Features::GlobalSearch < Spinach::FeatureSteps
include SharedAuthentication include SharedAuthentication
...@@ -8,7 +8,7 @@ class Spinach::Features::GlobalSearch < Spinach::FeatureSteps ...@@ -8,7 +8,7 @@ class Spinach::Features::GlobalSearch < Spinach::FeatureSteps
include StubConfiguration include StubConfiguration
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
...@@ -16,7 +16,7 @@ class Spinach::Features::GlobalSearch < Spinach::FeatureSteps ...@@ -16,7 +16,7 @@ class Spinach::Features::GlobalSearch < Spinach::FeatureSteps
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
step 'project has all data available for the search' do step 'project has all data available for the search' do
......
...@@ -6,7 +6,7 @@ class Spinach::Features::ProjectSearch < Spinach::FeatureSteps ...@@ -6,7 +6,7 @@ class Spinach::Features::ProjectSearch < Spinach::FeatureSteps
include StubConfiguration include StubConfiguration
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
...@@ -14,7 +14,7 @@ class Spinach::Features::ProjectSearch < Spinach::FeatureSteps ...@@ -14,7 +14,7 @@ class Spinach::Features::ProjectSearch < Spinach::FeatureSteps
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
step 'project has all data available for the search' do step 'project has all data available for the search' do
......
...@@ -6,7 +6,7 @@ class Spinach::Features::SnippetsSearch < Spinach::FeatureSteps ...@@ -6,7 +6,7 @@ class Spinach::Features::SnippetsSearch < Spinach::FeatureSteps
include StubConfiguration include StubConfiguration
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
...@@ -14,7 +14,7 @@ class Spinach::Features::SnippetsSearch < Spinach::FeatureSteps ...@@ -14,7 +14,7 @@ class Spinach::Features::SnippetsSearch < Spinach::FeatureSteps
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
step 'there is a snippet "index" with "php rocks" string' do step 'there is a snippet "index" with "php rocks" string' do
......
...@@ -25,7 +25,7 @@ module SharedElastic ...@@ -25,7 +25,7 @@ module SharedElastic
end end
step 'Elasticsearch is enabled' do step 'Elasticsearch is enabled' do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end end
def select_filter(name) def select_filter(name)
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe Issue, elastic: true do describe Issue, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
let(:project) { create :project } let(:project) { create :project }
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe MergeRequest, elastic: true do describe MergeRequest, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "searches merge requests" do it "searches merge requests" do
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe Milestone, elastic: true do describe Milestone, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "searches milestones" do it "searches milestones" do
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe Note, elastic: true do describe Note, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "searches notes" do it "searches notes" do
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe Project, elastic: true do describe Project, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "finds projects" do it "finds projects" do
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe ProjectWiki, elastic: true do describe ProjectWiki, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "searches wiki page" do it "searches wiki page" do
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe Repository, elastic: true do describe Repository, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
def index!(project) def index!(project)
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
describe Snippet, elastic: true do describe Snippet, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
context 'searching snippets by code' do context 'searching snippets by code' do
......
# coding: utf-8
require 'spec_helper' require 'spec_helper'
describe PostReceive do describe PostReceive do
...@@ -46,7 +47,7 @@ describe PostReceive do ...@@ -46,7 +47,7 @@ describe PostReceive do
end end
it 'triggers wiki index update when ElasticSearch is enabled' do it 'triggers wiki index update when ElasticSearch is enabled' do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
expect_any_instance_of(ProjectWiki).to receive(:index_blobs) expect_any_instance_of(ProjectWiki).to receive(:index_blobs)
......
module EE
module StubConfiguration
def stub_ee_application_setting(messages)
add_predicates(messages)
# Stubbing both of these because we're not yet consistent with how we access
# current application settings
allow_any_instance_of(EE::ApplicationSetting).to receive_messages(to_settings(messages))
allow(::Gitlab::CurrentSettings.current_application_settings)
.to receive_messages(to_settings(messages))
# Ensure that we don't use the Markdown cache when stubbing these values
allow_any_instance_of(EE::ApplicationSetting).to receive(:cached_html_up_to_date?).and_return(false)
end
end
end
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
# This module is monkey-patched in config/initializers/elastic_client_setup.rb # This module is monkey-patched in config/initializers/elastic_client_setup.rb
describe "Monkey-patches to ::Elasticsearch::Model::Client" do describe "Monkey-patches to ::Elasticsearch::Model::Client" do
before do before do
stub_application_setting(elasticsearch_url: ['http://localhost:9200']) stub_ee_application_setting(elasticsearch_url: ['http://localhost:9200'])
end end
it 'uses the same client instance for all subclasses' do it 'uses the same client instance for all subclasses' do
......
...@@ -11,7 +11,7 @@ describe 'GlobalSearch' do ...@@ -11,7 +11,7 @@ describe 'GlobalSearch' do
let(:guest) { create :user } let(:guest) { create :user }
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
project.add_developer(member) project.add_developer(member)
...@@ -21,7 +21,7 @@ describe 'GlobalSearch' do ...@@ -21,7 +21,7 @@ describe 'GlobalSearch' do
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
context "Respect feature visibility levels" do context "Respect feature visibility levels" do
......
...@@ -5,7 +5,7 @@ feature 'Global elastic search' do ...@@ -5,7 +5,7 @@ feature 'Global elastic search' do
let(:project) { create(:project, :repository, namespace: user.namespace) } let(:project) { create(:project, :repository, namespace: user.namespace) }
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
project.add_master(user) project.add_master(user)
...@@ -14,7 +14,7 @@ feature 'Global elastic search' do ...@@ -14,7 +14,7 @@ feature 'Global elastic search' do
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
describe 'I search through the issues and I see pagination' do describe 'I search through the issues and I see pagination' do
......
...@@ -15,7 +15,7 @@ feature 'Group elastic search', :js do ...@@ -15,7 +15,7 @@ feature 'Group elastic search', :js do
end end
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
project.add_master(user) project.add_master(user)
...@@ -26,7 +26,7 @@ feature 'Group elastic search', :js do ...@@ -26,7 +26,7 @@ feature 'Group elastic search', :js do
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
describe 'issue search' do describe 'issue search' do
......
...@@ -8,13 +8,13 @@ describe SearchHelper do ...@@ -8,13 +8,13 @@ describe SearchHelper do
describe '#parse_search_result_from_elastic' do describe '#parse_search_result_from_elastic' do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "returns parsed result" do it "returns parsed result" do
......
...@@ -15,10 +15,6 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m ...@@ -15,10 +15,6 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m
.to receive(:commits_count=).and_return(nil) .to receive(:commits_count=).and_return(nil)
end end
after do
[Project, MergeRequest, MergeRequestDiff].each(&:reset_column_information)
end
def diffs_to_hashes(diffs) def diffs_to_hashes(diffs)
diffs.as_json(only: Gitlab::Git::Diff::SERIALIZE_KEYS).map(&:with_indifferent_access) diffs.as_json(only: Gitlab::Git::Diff::SERIALIZE_KEYS).map(&:with_indifferent_access)
end end
......
...@@ -7,10 +7,6 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData, ...@@ -7,10 +7,6 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData,
.to receive(:commits_count=).and_return(nil) .to receive(:commits_count=).and_return(nil)
end end
after do
[Project, MergeRequest, MergeRequestDiff].each(&:reset_column_information)
end
describe '#perform' do describe '#perform' do
let(:mr_with_event) { create(:merge_request) } let(:mr_with_event) { create(:merge_request) }
let!(:merged_event) { create(:event, :merged, target: mr_with_event) } let!(:merged_event) { create(:event, :merged, target: mr_with_event) }
......
...@@ -5,7 +5,7 @@ describe Gitlab::Elastic::Indexer do ...@@ -5,7 +5,7 @@ describe Gitlab::Elastic::Indexer do
before do before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'true') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'true')
stub_application_setting(elasticsearch_url: ['http://localhost:9200']) stub_ee_application_setting(elasticsearch_url: ['http://localhost:9200'])
end end
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
...@@ -88,7 +88,7 @@ describe Gitlab::Elastic::Indexer do ...@@ -88,7 +88,7 @@ describe Gitlab::Elastic::Indexer do
context 'experimental indexer enabled' do context 'experimental indexer enabled' do
before do before do
stub_application_setting(elasticsearch_experimental_indexer: true) stub_ee_application_setting(elasticsearch_experimental_indexer: true)
end end
it 'uses the normal indexer when not present' do it 'uses the normal indexer when not present' do
......
...@@ -6,13 +6,13 @@ describe Gitlab::Elastic::ProjectSearchResults do ...@@ -6,13 +6,13 @@ describe Gitlab::Elastic::ProjectSearchResults do
let(:query) { 'hello world' } let(:query) { 'hello world' }
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
describe 'initialize with empty ref' do describe 'initialize with empty ref' do
......
# coding: utf-8
require 'spec_helper' require 'spec_helper'
describe Gitlab::Elastic::SearchResults do describe Gitlab::Elastic::SearchResults do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
let(:user) { create(:user) } let(:user) { create(:user) }
......
...@@ -21,7 +21,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do ...@@ -21,7 +21,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events[event] = true events[event] = true
end end
user = build(:user).becomes(user_class).tap(&:save!) user = user_class.create!(email: "user-#{SecureRandom.hex}@example.org", username: "user-#{SecureRandom.hex}", encrypted_password: '12345678')
create_params = { user_id: user.id, level: params[:level], events: events } create_params = { user_id: user.id, level: params[:level], events: events }
notification_setting = described_class::NotificationSetting.create(create_params) notification_setting = described_class::NotificationSetting.create(create_params)
...@@ -37,7 +37,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do ...@@ -37,7 +37,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events[event] = true events[event] = true
end end
user = build(:user).becomes(user_class).tap(&:save!) user = user_class.create!(email: "user-#{SecureRandom.hex}@example.org", username: "user-#{SecureRandom.hex}", encrypted_password: '12345678')
create_params = events.merge(user_id: user.id, level: params[:level]) create_params = events.merge(user_id: user.id, level: params[:level])
notification_setting = described_class::NotificationSetting.create(create_params) notification_setting = described_class::NotificationSetting.create(create_params)
......
...@@ -19,10 +19,6 @@ describe RemoveEmptyForkNetworks, :migration do ...@@ -19,10 +19,6 @@ describe RemoveEmptyForkNetworks, :migration do
deleted_project.destroy! deleted_project.destroy!
end end
after do
Upload.reset_column_information
end
it 'deletes only the fork network without members' do it 'deletes only the fork network without members' do
expect(fork_networks.count).to eq(2) expect(fork_networks.count).to eq(2)
......
...@@ -1825,7 +1825,7 @@ describe Project do ...@@ -1825,7 +1825,7 @@ describe Project do
context 'elasticsearch indexing disabled' do context 'elasticsearch indexing disabled' do
before do before do
stub_application_setting(elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_indexing: false)
end end
it 'does not index the repository' do it 'does not index the repository' do
...@@ -1841,7 +1841,7 @@ describe Project do ...@@ -1841,7 +1841,7 @@ describe Project do
let(:project) { create(:project, :import_started, import_type: :github) } let(:project) { create(:project, :import_started, import_type: :github) }
before do before do
stub_application_setting(elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_indexing: true)
end end
context 'no index status' do context 'no index status' do
......
...@@ -1777,13 +1777,13 @@ describe Repository do ...@@ -1777,13 +1777,13 @@ describe Repository do
describe "Elastic search", :elastic do describe "Elastic search", :elastic do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
describe "class method find_commits_by_message_with_elastic" do describe "class method find_commits_by_message_with_elastic" do
......
...@@ -205,11 +205,11 @@ describe GitPushService do ...@@ -205,11 +205,11 @@ describe GitPushService do
describe "ES indexing" do describe "ES indexing" do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end end
after do after do
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "does not trigger indexer when push to non-default branch" do it "does not trigger indexer when push to non-default branch" do
......
...@@ -40,7 +40,7 @@ describe Search::GroupService do ...@@ -40,7 +40,7 @@ describe Search::GroupService do
describe 'elasticsearch' do describe 'elasticsearch' do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index Gitlab::Elastic::Helper.create_empty_index
# Ensure these are present when the index is refreshed # Ensure these are present when the index is refreshed
......
...@@ -15,18 +15,22 @@ module MigrationsHelpers ...@@ -15,18 +15,22 @@ module MigrationsHelpers
ActiveRecord::Migrator.migrations(migrations_paths) ActiveRecord::Migrator.migrations(migrations_paths)
end end
def reset_column_in_migration_models def clear_schema_cache!
ActiveRecord::Base.connection_pool.connections.each do |conn| ActiveRecord::Base.connection_pool.connections.each do |conn|
conn.schema_cache.clear! conn.schema_cache.clear!
end end
end
described_class.constants.sort.each do |name| def reset_column_in_all_models
const = described_class.const_get(name) clear_schema_cache!
if const.is_a?(Class) && const < ActiveRecord::Base # Reset column information for the most offending classes **after** we
const.reset_column_information # migrated the schema up, otherwise, column information could be outdated
end ActiveRecord::Base.descendants.each { |klass| klass.reset_column_information }
end
# Without that, we get errors because of missing attributes, e.g.
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
ApplicationSetting.define_attribute_methods
end end
def previous_migration def previous_migration
...@@ -45,7 +49,7 @@ module MigrationsHelpers ...@@ -45,7 +49,7 @@ module MigrationsHelpers
migration_schema_version) migration_schema_version)
end end
reset_column_in_migration_models reset_column_in_all_models
end end
def schema_migrate_up! def schema_migrate_up!
...@@ -53,7 +57,7 @@ module MigrationsHelpers ...@@ -53,7 +57,7 @@ module MigrationsHelpers
ActiveRecord::Migrator.migrate(migrations_paths) ActiveRecord::Migrator.migrate(migrations_paths)
end end
reset_column_in_migration_models reset_column_in_all_models
end end
def disable_migrations_output def disable_migrations_output
......
require_dependency Rails.root.join('spec', 'ee', 'support', 'stub_configuration')
module StubConfiguration module StubConfiguration
prepend EE::StubConfiguration
def stub_application_setting(messages) def stub_application_setting(messages)
add_predicates(messages) add_predicates(messages)
......
...@@ -7,7 +7,7 @@ describe ElasticCommitIndexerWorker do ...@@ -7,7 +7,7 @@ describe ElasticCommitIndexerWorker do
describe '#perform' do describe '#perform' do
before do before do
stub_application_setting(elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_indexing: true)
end end
it 'runs indexer' do it 'runs indexer' do
...@@ -17,7 +17,7 @@ describe ElasticCommitIndexerWorker do ...@@ -17,7 +17,7 @@ describe ElasticCommitIndexerWorker do
end end
it 'returns true if ES disabled' do it 'returns true if ES disabled' do
stub_application_setting(elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_indexing: false)
expect_any_instance_of(Gitlab::Elastic::Indexer).not_to receive(:run) expect_any_instance_of(Gitlab::Elastic::Indexer).not_to receive(:run)
......
...@@ -4,7 +4,7 @@ describe ElasticIndexerWorker, elastic: true do ...@@ -4,7 +4,7 @@ describe ElasticIndexerWorker, elastic: true do
subject { described_class.new } subject { described_class.new }
before do before do
stub_application_setting(elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_indexing: true)
Elasticsearch::Model.client = Elasticsearch::Model.client =
Gitlab::Elastic::Client.build(Gitlab::CurrentSettings.elasticsearch_config) Gitlab::Elastic::Client.build(Gitlab::CurrentSettings.elasticsearch_config)
...@@ -17,7 +17,7 @@ describe ElasticIndexerWorker, elastic: true do ...@@ -17,7 +17,7 @@ describe ElasticIndexerWorker, elastic: true do
end end
it 'returns true if ES disabled' do it 'returns true if ES disabled' do
stub_application_setting(elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_indexing: false)
expect_any_instance_of(Elasticsearch::Model).not_to receive(:__elasticsearch__) expect_any_instance_of(Elasticsearch::Model).not_to receive(:__elasticsearch__)
......
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