summaryrefslogtreecommitdiff
path: root/spec/models/issue_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/issue_spec.rb')
-rw-r--r--spec/models/issue_spec.rb72
1 files changed, 60 insertions, 12 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index edb93ecf4b6..441446bae60 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -128,6 +128,24 @@ RSpec.describe Issue do
end
end
+ context 'order by upvotes' do
+ let!(:issue) { create(:issue) }
+ let!(:issue2) { create(:issue) }
+ let!(:award_emoji) { create(:award_emoji, :upvote, awardable: issue2) }
+
+ describe '.order_upvotes_desc' do
+ it 'orders on upvotes' do
+ expect(described_class.order_upvotes_desc.to_a).to eq [issue2, issue]
+ end
+ end
+
+ describe '.order_upvotes_asc' do
+ it 'orders on upvotes' do
+ expect(described_class.order_upvotes_asc.to_a).to eq [issue, issue2]
+ end
+ end
+ end
+
describe '.with_alert_management_alerts' do
subject { described_class.with_alert_management_alerts }
@@ -1051,23 +1069,53 @@ RSpec.describe Issue do
describe '#check_for_spam?' do
using RSpec::Parameterized::TableSyntax
-
- where(:visibility_level, :confidential, :new_attributes, :check_for_spam?) do
- Gitlab::VisibilityLevel::PUBLIC | false | { description: 'woo' } | true
- Gitlab::VisibilityLevel::PUBLIC | false | { title: 'woo' } | true
- Gitlab::VisibilityLevel::PUBLIC | true | { confidential: false } | true
- Gitlab::VisibilityLevel::PUBLIC | true | { description: 'woo' } | false
- Gitlab::VisibilityLevel::PUBLIC | false | { title: 'woo', confidential: true } | false
- Gitlab::VisibilityLevel::PUBLIC | false | { description: 'original description' } | false
- Gitlab::VisibilityLevel::INTERNAL | false | { description: 'woo' } | false
- Gitlab::VisibilityLevel::PRIVATE | false | { description: 'woo' } | false
+ let_it_be(:support_bot) { ::User.support_bot }
+
+ where(:support_bot?, :visibility_level, :confidential, :new_attributes, :check_for_spam?) do
+ ### non-support-bot cases
+ # spammable attributes changing
+ false | Gitlab::VisibilityLevel::PUBLIC | false | { description: 'new' } | true
+ false | Gitlab::VisibilityLevel::PUBLIC | false | { title: 'new' } | true
+ # confidential to non-confidential
+ false | Gitlab::VisibilityLevel::PUBLIC | true | { confidential: false } | true
+ # non-confidential to confidential
+ false | Gitlab::VisibilityLevel::PUBLIC | false | { confidential: true } | false
+ # spammable attributes changing on confidential
+ false | Gitlab::VisibilityLevel::PUBLIC | true | { description: 'new' } | false
+ # spammable attributes changing while changing to confidential
+ false | Gitlab::VisibilityLevel::PUBLIC | false | { title: 'new', confidential: true } | false
+ # spammable attribute not changing
+ false | Gitlab::VisibilityLevel::PUBLIC | false | { description: 'original description' } | false
+ # non-spammable attribute changing
+ false | Gitlab::VisibilityLevel::PUBLIC | false | { weight: 3 } | false
+ # spammable attributes changing on non-public
+ false | Gitlab::VisibilityLevel::INTERNAL | false | { description: 'new' } | false
+ false | Gitlab::VisibilityLevel::PRIVATE | false | { description: 'new' } | false
+
+ ### support-bot cases
+ # confidential to non-confidential
+ true | Gitlab::VisibilityLevel::PUBLIC | true | { confidential: false } | true
+ # non-confidential to confidential
+ true | Gitlab::VisibilityLevel::PUBLIC | false | { confidential: true } | false
+ # spammable attributes changing on confidential
+ true | Gitlab::VisibilityLevel::PUBLIC | true | { description: 'new' } | true
+ # spammable attributes changing while changing to confidential
+ true | Gitlab::VisibilityLevel::PUBLIC | false | { title: 'new', confidential: true } | true
+ # spammable attributes changing on non-public
+ true | Gitlab::VisibilityLevel::INTERNAL | false | { description: 'new' } | true
+ true | Gitlab::VisibilityLevel::PRIVATE | false | { title: 'new' } | true
+ # spammable attribute not changing
+ true | Gitlab::VisibilityLevel::PUBLIC | false | { description: 'original description' } | false
+ # non-spammable attribute changing
+ true | Gitlab::VisibilityLevel::PRIVATE | true | { weight: 3 } | false
end
with_them do
- it 'checks for spam on issues that can be seen anonymously' do
+ it 'checks for spam when necessary' do
+ author = support_bot? ? support_bot : user
project = reusable_project
project.update!(visibility_level: visibility_level)
- issue = create(:issue, project: project, confidential: confidential, description: 'original description')
+ issue = create(:issue, project: project, confidential: confidential, description: 'original description', author: author)
issue.assign_attributes(new_attributes)