Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
12e590ed
Commit
12e590ed
authored
6 years ago
by
Shuhei Kitagawa
Committed by
Eugen Rochko
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for report notes controller (#7589)
parent
36e47a31
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
spec/controllers/admin/report_notes_controller_spec.rb
+91
-0
91 additions, 0 deletions
spec/controllers/admin/report_notes_controller_spec.rb
spec/fabricators/report_note_fabricator.rb
+5
-0
5 additions, 0 deletions
spec/fabricators/report_note_fabricator.rb
with
96 additions
and
0 deletions
spec/controllers/admin/report_notes_controller_spec.rb
0 → 100644
+
91
−
0
View file @
12e590ed
require
'rails_helper'
describe
Admin
::
ReportNotesController
do
render_views
let
(
:user
)
{
Fabricate
(
:user
,
admin:
true
)
}
before
do
sign_in
user
,
scope: :user
end
describe
'POST #create'
do
subject
{
post
:create
,
params:
params
}
let
(
:report
)
{
Fabricate
(
:report
,
action_taken:
action_taken
,
action_taken_by_account_id:
account_id
)
}
context
'when parameter is valid'
do
context
'when report is unsolved'
do
let
(
:action_taken
)
{
false
}
let
(
:account_id
)
{
nil
}
context
'when create_and_resolve flag is on'
do
let
(
:params
)
{
{
report_note:
{
content:
'test content'
,
report_id:
report
.
id
},
create_and_resolve:
nil
}
}
it
'creates a report note and resolves report'
do
expect
{
subject
}.
to
change
{
ReportNote
.
count
}.
by
(
1
)
expect
(
report
.
reload
).
to
be_action_taken
expect
(
subject
).
to
redirect_to
admin_reports_path
end
end
context
'when create_and_resolve flag is false'
do
let
(
:params
)
{
{
report_note:
{
content:
'test content'
,
report_id:
report
.
id
}
}
}
it
'creates a report note and does not resolve report'
do
expect
{
subject
}.
to
change
{
ReportNote
.
count
}.
by
(
1
)
expect
(
report
.
reload
).
not_to
be_action_taken
expect
(
subject
).
to
redirect_to
admin_report_path
(
report
)
end
end
end
context
'when report is resolved'
do
let
(
:action_taken
)
{
true
}
let
(
:account_id
)
{
user
.
account
.
id
}
context
'when create_and_unresolve flag is on'
do
let
(
:params
)
{
{
report_note:
{
content:
'test content'
,
report_id:
report
.
id
},
create_and_unresolve:
nil
}
}
it
'creates a report note and unresolves report'
do
expect
{
subject
}.
to
change
{
ReportNote
.
count
}.
by
(
1
)
expect
(
report
.
reload
).
not_to
be_action_taken
expect
(
subject
).
to
redirect_to
admin_report_path
(
report
)
end
end
context
'when create_and_unresolve flag is false'
do
let
(
:params
)
{
{
report_note:
{
content:
'test content'
,
report_id:
report
.
id
}
}
}
it
'creates a report note and does not unresolve report'
do
expect
{
subject
}.
to
change
{
ReportNote
.
count
}.
by
(
1
)
expect
(
report
.
reload
).
to
be_action_taken
expect
(
subject
).
to
redirect_to
admin_report_path
(
report
)
end
end
end
end
context
'when parameter is invalid'
do
let
(
:params
)
{
{
report_note:
{
content:
''
,
report_id:
report
.
id
}
}
}
let
(
:action_taken
)
{
false
}
let
(
:account_id
)
{
nil
}
it
'renders admin/reports/show'
do
expect
(
subject
).
to
render_template
'admin/reports/show'
end
end
end
describe
'DELETE #destroy'
do
subject
{
delete
:destroy
,
params:
{
id:
report_note
.
id
}
}
let!
(
:report_note
)
{
Fabricate
(
:report_note
)
}
it
'deletes note'
do
expect
{
subject
}.
to
change
{
ReportNote
.
count
}.
by
(
-
1
)
expect
(
subject
).
to
redirect_to
admin_report_path
(
report_note
.
report
)
end
end
end
This diff is collapsed.
Click to expand it.
spec/fabricators/report_note_fabricator.rb
0 → 100644
+
5
−
0
View file @
12e590ed
Fabricator
(
:report_note
)
do
report
account
{
Fabricate
(
:account
)
}
content
"Test Content"
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment