diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-13 15:07:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-13 15:07:18 +0300 |
commit | c3eeb6a8d6a4b11f0bc5e5eb1ed43b0726f1ea26 (patch) | |
tree | 7283014bb12ce53b57d2703b229095ad58e6d820 /spec/models | |
parent | 10e15ac3c2798956ff6a43d7b36bdf86c68aa817 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/integrations/telegram_spec.rb | 53 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 45 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/organizations/organization_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 1 |
5 files changed, 93 insertions, 19 deletions
diff --git a/spec/models/integrations/telegram_spec.rb b/spec/models/integrations/telegram_spec.rb new file mode 100644 index 00000000000..c3a66c84f09 --- /dev/null +++ b/spec/models/integrations/telegram_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Integrations::Telegram, feature_category: :integrations do + it_behaves_like "chat integration", "Telegram" do + let(:payload) do + { + text: be_present + } + end + end + + describe 'validations' do + context 'when integration is active' do + before do + subject.active = true + end + + it { is_expected.to validate_presence_of(:token) } + it { is_expected.to validate_presence_of(:room) } + end + + context 'when integration is inactive' do + before do + subject.active = false + end + + it { is_expected.not_to validate_presence_of(:token) } + it { is_expected.not_to validate_presence_of(:room) } + end + end + + describe 'before_validation :set_webhook' do + context 'when token is not present' do + let(:integration) { build(:telegram_integration, token: nil) } + + it 'does not set webhook value' do + expect(integration.webhook).to eq(nil) + expect(integration).not_to be_valid + end + end + + context 'when token is present' do + let(:integration) { create(:telegram_integration) } + + it 'sets webhook value' do + expect(integration).to be_valid + expect(integration.webhook).to eq("https://api.telegram.org/bot123456:ABC-DEF1234/sendMessage") + end + end + end +end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 4bbe0d52486..14d885892ed 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -2111,15 +2111,48 @@ RSpec.describe Issue, feature_category: :team_planning do end describe 'issue_type enum generated methods' do - using RSpec::Parameterized::TableSyntax + describe '#<issue_type>?' do + let_it_be(:issue) { create(:issue, project: reusable_project) } - let_it_be(:issue) { create(:issue, project: reusable_project) } + where(issue_type: WorkItems::Type.base_types.keys) + + with_them do + it 'raises an error if called' do + expect { issue.public_send("#{issue_type}?".to_sym) }.to raise_error( + Issue::ForbiddenColumnUsed, + a_string_matching(/`issue\.#{issue_type}\?` uses the `issue_type` column underneath/) + ) + end + end + end - where(issue_type: WorkItems::Type.base_types.keys) + describe '.<issue_type> scopes' do + where(issue_type: WorkItems::Type.base_types.keys) - with_them do - it 'raises an error if called' do - expect { issue.public_send("#{issue_type}?".to_sym) }.to raise_error(Issue::ForbiddenColumnUsed) + with_them do + it 'raises an error if called' do + expect { Issue.public_send(issue_type.to_sym) }.to raise_error( + Issue::ForbiddenColumnUsed, + a_string_matching(/`Issue\.#{issue_type}` uses the `issue_type` column underneath/) + ) + end + + context 'when called in a production environment' do + before do + stub_rails_env('production') + end + + it 'returns issues scoped by type instead of raising an error' do + issue = create( + :issue, + issue_type: issue_type, + work_item_type: WorkItems::Type.default_by_type(issue_type), + project: reusable_project + ) + + expect(Issue.public_send(issue_type.to_sym)).to contain_exactly(issue) + end + end end end end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index aea7a3b52c9..e1629dd354e 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -15,7 +15,6 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do let(:repository_storage) { 'default' } describe 'associations' do - it { is_expected.to belong_to(:organization).class_name('Organizations::Organization') } it { is_expected.to have_many :projects } it { is_expected.to have_many :project_statistics } it { is_expected.to belong_to :parent } @@ -2746,11 +2745,4 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do end end end - - context 'with loose foreign key on organization_id' do - it_behaves_like 'cleanup by a loose foreign key' do - let!(:parent) { create(:organization) } - let!(:model) { create(:namespace, organization: parent) } - end - end end diff --git a/spec/models/organizations/organization_spec.rb b/spec/models/organizations/organization_spec.rb index ec5aea519f5..cc2262634e3 100644 --- a/spec/models/organizations/organization_spec.rb +++ b/spec/models/organizations/organization_spec.rb @@ -6,11 +6,6 @@ RSpec.describe Organizations::Organization, type: :model, feature_category: :cel let_it_be(:organization) { create(:organization) } let_it_be(:default_organization) { create(:organization, :default) } - describe 'associations' do - it { is_expected.to have_many :namespaces } - it { is_expected.to have_many :groups } - end - describe 'validations' do subject { create(:organization) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 51c87217d9d..2164d5fc787 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -49,6 +49,7 @@ RSpec.describe Project, factory_default: :keep, feature_category: :groups_and_pr it { is_expected.to have_one(:microsoft_teams_integration) } it { is_expected.to have_one(:mattermost_integration) } it { is_expected.to have_one(:hangouts_chat_integration) } + it { is_expected.to have_one(:telegram_integration) } it { is_expected.to have_one(:unify_circuit_integration) } it { is_expected.to have_one(:pumble_integration) } it { is_expected.to have_one(:webex_teams_integration) } |