Commit 6355e5c5 authored by Robert Speicher's avatar Robert Speicher

Merge branch '6582-extract-ee-model-concerns' into 'master'

Extract ee model concerns specs

Closes #6582

See merge request gitlab-org/gitlab-ee!9979
parents b61e94c5 f4d9876e
# frozen_string_literal: true
require 'spec_helper'
describe EE::Issuable do
describe '.labels_hash' do
let(:feature_label) { create(:label, title: 'Feature') }
let(:second_label) { create(:label, title: 'Second Label') }
let!(:issues) { create_list(:labeled_issue, 3, labels: [feature_label, second_label]) }
let(:issue_id) { issues.first.id }
it 'maps issue ids to labels titles' do
expect(Issue.labels_hash[issue_id]).to include('Feature')
end
it 'works on relations filtered by multiple labels' do
relation = Issue.with_label(['Feature', 'Second Label'])
expect(relation.labels_hash[issue_id]).to include('Feature', 'Second Label')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe EE::PrometheusAdapter, :use_clean_rails_memory_store_caching do
include PrometheusHelpers
include ReactiveCachingHelpers
let(:project) { create(:prometheus_project) }
let(:service) { project.prometheus_service }
let(:described_class) do
Class.new do
include PrometheusAdapter
end
end
let(:environment_query) { Gitlab::Prometheus::Queries::EnvironmentQuery }
describe 'validate_query' do
let(:environment) { build_stubbed(:environment, slug: 'env-slug') }
let(:validation_query) { Gitlab::Prometheus::Queries::ValidateQuery.name }
let(:query) { 'avg(response)' }
let(:validation_respone) { { data: { valid: true } } }
around do |example|
Timecop.freeze { example.run }
end
context 'with valid data' do
subject { service.query(:validate, query) }
before do
stub_reactive_cache(service, validation_respone, validation_query, query)
end
it 'returns query data' do
is_expected.to eq(query: { valid: true })
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe EE::ShaAttribute do
let(:model) { Class.new { include ShaAttribute } }
before do
columns = [
double(:column, name: 'name', type: :text),
double(:column, name: 'sha1', type: :binary)
]
allow(model).to receive(:columns).and_return(columns)
end
describe '#sha_attribute' do
context 'when in non-production' do
before do
allow(Rails.env).to receive(:production?).and_return(false)
end
context 'when Geo database is not configured' do
it 'allows the attribute to be added' do
allow(model).to receive(:table_exists?).and_raise(Geo::TrackingBase::SecondaryNotConfigured.new)
expect(model).not_to receive(:columns)
expect(model).to receive(:attribute)
model.sha_attribute(:name)
end
end
end
end
end
......@@ -533,23 +533,6 @@ describe Issuable do
end
end
describe '.labels_hash' do
let(:feature_label) { create(:label, title: 'Feature') }
let(:second_label) { create(:label, title: 'Second Label') }
let!(:issues) { create_list(:labeled_issue, 3, labels: [feature_label, second_label]) }
let(:issue_id) { issues.first.id }
it 'maps issue ids to labels titles' do
expect(Issue.labels_hash[issue_id]).to include('Feature')
end
it 'works on relations filtered by multiple labels' do
relation = Issue.with_label(['Feature', 'Second Label'])
expect(relation.labels_hash[issue_id]).to include('Feature', 'Second Label')
end
end
describe '#user_notes_count' do
let(:project) { create(:project) }
let(:issue1) { create(:issue, project: project) }
......
......@@ -75,29 +75,6 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
end
end
end
describe 'validate_query' do
let(:environment) { build_stubbed(:environment, slug: 'env-slug') }
let(:validation_query) { Gitlab::Prometheus::Queries::ValidateQuery.name }
let(:query) { 'avg(response)' }
let(:validation_respone) { { data: { valid: true } } }
around do |example|
Timecop.freeze { example.run }
end
context 'with valid data' do
subject { service.query(:validate, query) }
before do
stub_reactive_cache(service, validation_respone, validation_query, query)
end
it 'returns query data' do
is_expected.to eq(query: { valid: true })
end
end
end
end
describe '#calculate_reactive_cache' do
......
......@@ -70,19 +70,6 @@ describe ShaAttribute do
expect { model.sha_attribute(:name) }.to raise_error(ActiveRecord::NoDatabaseError)
end
end
# EE-specific start
context 'when Geo database is not configured' do
it 'allows the attribute to be added' do
allow(model).to receive(:table_exists?).and_raise(Geo::TrackingBase::SecondaryNotConfigured.new)
expect(model).not_to receive(:columns)
expect(model).to receive(:attribute)
model.sha_attribute(:name)
end
end
# EE specific end
end
context 'when in production' do
......
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