diff options
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/approvable_base_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/concerns/atomic_internal_id_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/concerns/awardable_spec.rb | 84 | ||||
-rw-r--r-- | spec/models/concerns/cache_markdown_field_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/concerns/cascading_namespace_setting_attribute_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/concerns/has_integrations_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/concerns/integrations/has_data_fields_spec.rb | 43 | ||||
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/concerns/partitioned_table_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/concerns/prometheus_adapter_spec.rb | 36 |
10 files changed, 151 insertions, 121 deletions
diff --git a/spec/models/concerns/approvable_base_spec.rb b/spec/models/concerns/approvable_base_spec.rb index a9e944cf220..c7ea2631a24 100644 --- a/spec/models/concerns/approvable_base_spec.rb +++ b/spec/models/concerns/approvable_base_spec.rb @@ -59,4 +59,25 @@ RSpec.describe ApprovableBase do end end end + + describe '.not_approved_by_users_with_usernames' do + subject { MergeRequest.not_approved_by_users_with_usernames([user.username, user2.username]) } + + let!(:merge_request2) { create(:merge_request) } + let!(:merge_request3) { create(:merge_request) } + let!(:merge_request4) { create(:merge_request) } + let(:user2) { create(:user) } + let(:user3) { create(:user) } + + before do + create(:approval, merge_request: merge_request, user: user) + create(:approval, merge_request: merge_request2, user: user2) + create(:approval, merge_request: merge_request2, user: user3) + create(:approval, merge_request: merge_request4, user: user3) + end + + it 'has the merge request that is not approved at all and not approved by either user' do + expect(subject).to contain_exactly(merge_request3, merge_request4) + end + end end diff --git a/spec/models/concerns/atomic_internal_id_spec.rb b/spec/models/concerns/atomic_internal_id_spec.rb index 35b0f107676..b803e699b25 100644 --- a/spec/models/concerns/atomic_internal_id_spec.rb +++ b/spec/models/concerns/atomic_internal_id_spec.rb @@ -240,18 +240,12 @@ RSpec.describe AtomicInternalId do end describe '.with_project_iid_supply' do - let(:iid) { 100 } - - it 'wraps generate and track_greatest in a concurrency-safe lock' do - expect_next_instance_of(InternalId::InternalIdGenerator) do |g| - expect(g).to receive(:with_lock).and_call_original - expect(g.record).to receive(:last_value).and_return(iid) - expect(g).to receive(:track_greatest).with(iid + 4) - end - - ::Milestone.with_project_iid_supply(milestone.project) do |supply| - 4.times { supply.next_value } - end + it 'supplies a stream of iid values' do + expect do + ::Milestone.with_project_iid_supply(milestone.project) do |supply| + 4.times { supply.next_value } + end + end.to change { InternalId.find_by(project: milestone.project, usage: :milestones)&.last_value.to_i }.by(4) end end end diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb index b80b6ec95e2..fcd0d0c05f4 100644 --- a/spec/models/concerns/awardable_spec.rb +++ b/spec/models/concerns/awardable_spec.rb @@ -3,64 +3,64 @@ require 'spec_helper' RSpec.describe Awardable do - let!(:issue) { create(:issue) } - let!(:award_emoji) { create(:award_emoji, :downvote, awardable: issue) } + let!(:note) { create(:note) } + let!(:award_emoji) { create(:award_emoji, :downvote, awardable: note) } describe "Associations" do - subject { build(:issue) } + subject { build(:note) } it { is_expected.to have_many(:award_emoji).dependent(:destroy) } end describe "ClassMethods" do - let!(:issue2) { create(:issue) } - let!(:award_emoji2) { create(:award_emoji, awardable: issue2) } + let!(:note2) { create(:note) } + let!(:award_emoji2) { create(:award_emoji, awardable: note2) } describe "orders" do it "orders on upvotes" do - expect(Issue.order_upvotes_desc.to_a).to eq [issue2, issue] + expect(Note.order_upvotes_desc.to_a).to eq [note2, note] end it "orders on downvotes" do - expect(Issue.order_downvotes_desc.to_a).to eq [issue, issue2] + expect(Note.order_downvotes_desc.to_a).to eq [note, note2] end end describe "#awarded" do it "filters by user and emoji name" do - expect(Issue.awarded(award_emoji.user, "thumbsup")).to be_empty - expect(Issue.awarded(award_emoji.user, "thumbsdown")).to eq [issue] - expect(Issue.awarded(award_emoji2.user, "thumbsup")).to eq [issue2] - expect(Issue.awarded(award_emoji2.user, "thumbsdown")).to be_empty + expect(Note.awarded(award_emoji.user, "thumbsup")).to be_empty + expect(Note.awarded(award_emoji.user, "thumbsdown")).to eq [note] + expect(Note.awarded(award_emoji2.user, "thumbsup")).to eq [note2] + expect(Note.awarded(award_emoji2.user, "thumbsdown")).to be_empty end it "filters by user and any emoji" do - issue3 = create(:issue) - create(:award_emoji, awardable: issue3, name: "star", user: award_emoji.user) - create(:award_emoji, awardable: issue3, name: "star", user: award_emoji2.user) + note3 = create(:note) + create(:award_emoji, awardable: note3, name: "star", user: award_emoji.user) + create(:award_emoji, awardable: note3, name: "star", user: award_emoji2.user) - expect(Issue.awarded(award_emoji.user)).to contain_exactly(issue, issue3) - expect(Issue.awarded(award_emoji2.user)).to contain_exactly(issue2, issue3) + expect(Note.awarded(award_emoji.user)).to contain_exactly(note, note3) + expect(Note.awarded(award_emoji2.user)).to contain_exactly(note2, note3) end end describe "#not_awarded" do - it "returns issues not awarded by user" do - expect(Issue.not_awarded(award_emoji.user)).to eq [issue2] - expect(Issue.not_awarded(award_emoji2.user)).to eq [issue] + it "returns notes not awarded by user" do + expect(Note.not_awarded(award_emoji.user)).to eq [note2] + expect(Note.not_awarded(award_emoji2.user)).to eq [note] end end end describe "#upvotes" do it "counts the number of upvotes" do - expect(issue.upvotes).to be 0 + expect(note.upvotes).to be 0 end end describe "#downvotes" do it "counts the number of downvotes" do - expect(issue.downvotes).to be 1 + expect(note.downvotes).to be 1 end end @@ -68,67 +68,67 @@ RSpec.describe Awardable do let(:user) { create(:user) } before do - issue.project.add_guest(user) + note.project.add_guest(user) end it 'is truthy when the user is allowed to award emoji' do - expect(issue.user_can_award?(user)).to be_truthy + expect(note.user_can_award?(user)).to be_truthy end it 'is falsy when the project is archived' do - issue.project.update!(archived: true) + note.project.update!(archived: true) - expect(issue.user_can_award?(user)).to be_falsy + expect(note.user_can_award?(user)).to be_falsy end end describe 'querying award_emoji on an Awardable' do - let(:issue) { create(:issue) } + let(:note) { create(:note) } it 'sorts in ascending fashion' do - create_list(:award_emoji, 3, awardable: issue) + create_list(:award_emoji, 3, awardable: note) - expect(issue.award_emoji).to eq issue.award_emoji.sort_by(&:id) + expect(note.award_emoji).to eq note.award_emoji.sort_by(&:id) end end describe "#grouped_awards" do context 'default award emojis' do - let(:issue_without_downvote) { create(:issue) } - let(:issue_with_downvote) do - issue_with_downvote = create(:issue) - create(:award_emoji, :downvote, awardable: issue_with_downvote) - issue_with_downvote + let(:note_without_downvote) { create(:note) } + let(:note_with_downvote) do + note_with_downvote = create(:note) + create(:award_emoji, :downvote, awardable: note_with_downvote) + note_with_downvote end it "includes unused thumbs buttons by default" do - expect(issue_without_downvote.grouped_awards.keys.sort).to eq %w(thumbsdown thumbsup) + expect(note_without_downvote.grouped_awards.keys.sort).to eq %w(thumbsdown thumbsup) end it "doesn't include unused thumbs buttons when disabled in project" do - issue_without_downvote.project.show_default_award_emojis = false + note_without_downvote.project.show_default_award_emojis = false - expect(issue_without_downvote.grouped_awards.keys.sort).to be_empty + expect(note_without_downvote.grouped_awards.keys.sort).to be_empty end it "includes unused thumbs buttons when enabled in project" do - issue_without_downvote.project.show_default_award_emojis = true + note_without_downvote.project.show_default_award_emojis = true - expect(issue_without_downvote.grouped_awards.keys.sort).to eq %w(thumbsdown thumbsup) + expect(note_without_downvote.grouped_awards.keys.sort).to eq %w(thumbsdown thumbsup) end it "doesn't include unused thumbs buttons in summary" do - expect(issue_without_downvote.grouped_awards(with_thumbs: false).keys).to be_empty + expect(note_without_downvote.grouped_awards(with_thumbs: false).keys).to be_empty end it "includes used thumbs buttons when disabled in project" do - issue_with_downvote.project.show_default_award_emojis = false + note_with_downvote.project.show_default_award_emojis = false - expect(issue_with_downvote.grouped_awards.keys).to eq %w(thumbsdown) + expect(note_with_downvote.grouped_awards.keys).to eq %w(thumbsdown) end it "includes used thumbs buttons in summary" do - expect(issue_with_downvote.grouped_awards(with_thumbs: false).keys).to eq %w(thumbsdown) + expect(note_with_downvote.grouped_awards(with_thumbs: false).keys).to eq %w(thumbsdown) end end end diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb index 33a4c8eac41..1c1efab2889 100644 --- a/spec/models/concerns/cache_markdown_field_spec.rb +++ b/spec/models/concerns/cache_markdown_field_spec.rb @@ -75,7 +75,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do end it 'returns false when the local version was bumped' do - allow(Gitlab::CurrentSettings.current_application_settings).to receive(:local_markdown_version).and_return(2) + stub_application_setting(local_markdown_version: 2) thing.cached_markdown_version = cache_version is_expected.to be_falsy @@ -88,7 +88,7 @@ RSpec.describe CacheMarkdownField, :clean_gitlab_redis_cache do end it 'returns true when the cached version is just right' do - allow(Gitlab::CurrentSettings.current_application_settings).to receive(:local_markdown_version).and_return(2) + stub_application_setting(local_markdown_version: 2) thing.cached_markdown_version = cache_version + 2 is_expected.to be_truthy diff --git a/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb b/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb index 02cd8557231..e8f2b18e662 100644 --- a/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb +++ b/spec/models/concerns/cascading_namespace_setting_attribute_spec.rb @@ -17,18 +17,6 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do describe '#delayed_project_removal' do subject(:delayed_project_removal) { subgroup_settings.delayed_project_removal } - context 'when the feature is disabled' do - before do - stub_feature_flags(cascading_namespace_settings: false) - - group_settings.update!(delayed_project_removal: true) - end - - it 'does not cascade' do - expect(delayed_project_removal).to eq(nil) - end - end - context 'when there is no parent' do context 'and the value is not nil' do before do @@ -192,16 +180,6 @@ RSpec.describe NamespaceSetting, 'CascadingNamespaceSettingAttribute' do end end - context 'when the feature is disabled' do - before do - stub_feature_flags(cascading_namespace_settings: false) - - group_settings.update!(delayed_project_removal: true) - end - - it_behaves_like 'not locked' - end - context 'when attribute is locked by self' do before do subgroup_settings.update!(lock_delayed_project_removal: true) diff --git a/spec/models/concerns/has_integrations_spec.rb b/spec/models/concerns/has_integrations_spec.rb index 6e55a1c8b01..6b3f75bfcfd 100644 --- a/spec/models/concerns/has_integrations_spec.rb +++ b/spec/models/concerns/has_integrations_spec.rb @@ -7,14 +7,14 @@ RSpec.describe HasIntegrations do let_it_be(:project_2) { create(:project) } let_it_be(:project_3) { create(:project) } let_it_be(:project_4) { create(:project) } - let_it_be(:instance_integration) { create(:jira_service, :instance) } + let_it_be(:instance_integration) { create(:jira_integration, :instance) } before do - create(:jira_service, project: project_1, inherit_from_id: instance_integration.id) - create(:jira_service, project: project_2, inherit_from_id: nil) - create(:jira_service, group: create(:group), project: nil, inherit_from_id: nil) - create(:jira_service, project: project_3, inherit_from_id: nil) - create(:slack_service, project: project_4, inherit_from_id: nil) + create(:jira_integration, project: project_1, inherit_from_id: instance_integration.id) + create(:jira_integration, project: project_2, inherit_from_id: nil) + create(:jira_integration, group: create(:group), project: nil, inherit_from_id: nil) + create(:jira_integration, project: project_3, inherit_from_id: nil) + create(:integrations_slack, project: project_4, inherit_from_id: nil) end describe '.with_custom_integration_for' do diff --git a/spec/models/concerns/integrations/has_data_fields_spec.rb b/spec/models/concerns/integrations/has_data_fields_spec.rb index 54e0ac9c5a5..b28fef571c6 100644 --- a/spec/models/concerns/integrations/has_data_fields_spec.rb +++ b/spec/models/concerns/integrations/has_data_fields_spec.rb @@ -84,7 +84,7 @@ RSpec.describe Integrations::HasDataFields do context 'when data are stored in data_fields' do let(:service) do - create(:jira_service, url: url, username: username) + create(:jira_integration, url: url, username: username) end it_behaves_like 'data fields' @@ -111,45 +111,52 @@ RSpec.describe Integrations::HasDataFields do end context 'when data are stored in properties' do - let(:service) { create(:jira_service, :without_properties_callback, properties: properties) } + let(:integration) { create(:jira_integration, :without_properties_callback, properties: properties) } - it_behaves_like 'data fields' + it_behaves_like 'data fields' do + let(:service) { integration } + end describe '{arg}_was?' do it 'returns nil when the property has not been assigned a new value' do - service.username = 'new_username' - service.validate - expect(service.url_was).to be_nil + integration.username = 'new_username' + integration.validate + + expect(integration.url_was).to be_nil end it 'returns initial value when the property has been assigned a different value' do - service.url = 'http://example.com' - service.validate - expect(service.url_was).to eq('http://url.com') + integration.url = 'http://example.com' + integration.validate + + expect(integration.url_was).to eq('http://url.com') end it 'returns initial value when the property has been re-assigned the same value' do - service.url = 'http://url.com' - service.validate - expect(service.url_was).to eq('http://url.com') + integration.url = 'http://url.com' + integration.validate + + expect(integration.url_was).to eq('http://url.com') end end end context 'when data are stored in both properties and data_fields' do - let(:service) do - create(:jira_service, :without_properties_callback, active: false, properties: properties).tap do |integration| + let(:integration) do + create(:jira_integration, :without_properties_callback, active: false, properties: properties).tap do |integration| create(:jira_tracker_data, properties.merge(integration: integration)) end end - it_behaves_like 'data fields' + it_behaves_like 'data fields' do + let(:service) { integration } + end describe '{arg}_was?' do it 'returns nil' do - service.url = 'http://example.com' - service.validate - expect(service.url_was).to be_nil + integration.url = 'http://example.com' + integration.validate + expect(integration.url_was).to be_nil end end end diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 7b100b7a6f3..071e0dcba44 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -535,6 +535,26 @@ RSpec.describe Issuable do merge_request.to_hook_data(user, old_associations: { assignees: [user] }) end end + + context 'incident severity is updated' do + let(:issue) { create(:incident) } + + before do + issue.update!(issuable_severity_attributes: { severity: 'low' }) + expect(Gitlab::HookData::IssuableBuilder) + .to receive(:new).with(issue).and_return(builder) + end + + it 'delegates to Gitlab::HookData::IssuableBuilder#build' do + expect(builder).to receive(:build).with( + user: user, + changes: hash_including( + 'severity' => %w(unknown low) + )) + + issue.to_hook_data(user, old_associations: { severity: 'unknown' }) + end + end end describe '#labels_array' do diff --git a/spec/models/concerns/partitioned_table_spec.rb b/spec/models/concerns/partitioned_table_spec.rb index 3343b273ba2..c37fb81a1cf 100644 --- a/spec/models/concerns/partitioned_table_spec.rb +++ b/spec/models/concerns/partitioned_table_spec.rb @@ -14,6 +14,16 @@ RSpec.describe PartitionedTable do end end + context 'with keyword arguments passed to the strategy' do + subject { my_class.partitioned_by(key, strategy: :monthly, retain_for: 3.months) } + + it 'passes the keyword arguments to the strategy' do + expect(Gitlab::Database::Partitioning::MonthlyStrategy).to receive(:new).with(my_class, key, retain_for: 3.months).and_call_original + + subject + end + end + it 'assigns the MonthlyStrategy as the partitioning strategy' do subject @@ -27,7 +37,7 @@ RSpec.describe PartitionedTable do end it 'registers itself with the PartitionCreator' do - expect(Gitlab::Database::Partitioning::PartitionCreator).to receive(:register).with(my_class) + expect(Gitlab::Database::Partitioning::PartitionManager).to receive(:register).with(my_class) subject end diff --git a/spec/models/concerns/prometheus_adapter_spec.rb b/spec/models/concerns/prometheus_adapter_spec.rb index 235e505c6e9..01c987a1d92 100644 --- a/spec/models/concerns/prometheus_adapter_spec.rb +++ b/spec/models/concerns/prometheus_adapter_spec.rb @@ -7,7 +7,7 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do include ReactiveCachingHelpers let(:project) { create(:prometheus_project) } - let(:service) { project.prometheus_service } + let(:integration) { project.prometheus_integration } let(:described_class) do Class.new do @@ -29,10 +29,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do end context 'with valid data' do - subject { service.query(:validate, query) } + subject { integration.query(:validate, query) } before do - stub_reactive_cache(service, validation_respone, validation_query, query) + stub_reactive_cache(integration, validation_respone, validation_query, query) end it 'returns query data' do @@ -49,10 +49,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do end context 'with valid data' do - subject { service.query(:environment, environment) } + subject { integration.query(:environment, environment) } before do - stub_reactive_cache(service, prometheus_data, environment_query, environment.id) + stub_reactive_cache(integration, prometheus_data, environment_query, environment.id) end it 'returns reactive data' do @@ -66,11 +66,11 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do let(:prometheus_client) { double(:prometheus_client, label_values: nil) } context 'with valid data' do - subject { service.query(:matched_metrics) } + subject { integration.query(:matched_metrics) } before do - allow(service).to receive(:prometheus_client).and_return(prometheus_client) - synchronous_reactive_cache(service) + allow(integration).to receive(:prometheus_client).and_return(prometheus_client) + synchronous_reactive_cache(integration) end it 'returns reactive data' do @@ -89,10 +89,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do end context 'with valid data' do - subject { service.query(:deployment, deployment) } + subject { integration.query(:deployment, deployment) } before do - stub_reactive_cache(service, prometheus_data, deployment_query, deployment.id) + stub_reactive_cache(integration, prometheus_data, deployment_query, deployment.id) end it 'returns reactive data' do @@ -111,10 +111,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do end context 'with valid data' do - subject { service.query(:additional_metrics_environment, environment, *time_window) } + subject { integration.query(:additional_metrics_environment, environment, *time_window) } before do - stub_reactive_cache(service, prometheus_data, additional_metrics_environment_query, environment.id, *time_window) + stub_reactive_cache(integration, prometheus_data, additional_metrics_environment_query, environment.id, *time_window) end it 'returns reactive data' do @@ -128,21 +128,21 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do let(:environment) { create(:environment, slug: 'env-slug') } before do - service.manual_configuration = true - service.active = true + integration.manual_configuration = true + integration.active = true end subject do - service.calculate_reactive_cache(environment_query.name, environment.id) + integration.calculate_reactive_cache(environment_query.name, environment.id) end around do |example| freeze_time { example.run } end - context 'when service is inactive' do + context 'when integration is inactive' do before do - service.active = false + integration.active = false end it { is_expected.to be_nil } @@ -168,7 +168,7 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do end describe '#build_query_args' do - subject { service.build_query_args(*args) } + subject { integration.build_query_args(*args) } context 'when active record models are included' do let(:args) { [double(:environment, id: 12)] } |