Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gigadoc 2
diaspora
Commits
655fe2a9
Unverified
Commit
655fe2a9
authored
Sep 14, 2017
by
Benjamin Neff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup invalid polls without status message
closes #7614
parent
00296ffd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
3 deletions
+40
-3
Changelog.md
Changelog.md
+1
-0
app/models/poll.rb
app/models/poll.rb
+2
-2
app/models/status_message.rb
app/models/status_message.rb
+1
-1
db/migrate/20170914212336_cleanup_invalid_polls.rb
db/migrate/20170914212336_cleanup_invalid_polls.rb
+19
-0
spec/models/status_message_spec.rb
spec/models/status_message_spec.rb
+17
-0
No files found.
Changelog.md
View file @
655fe2a9
...
...
@@ -20,6 +20,7 @@
*
Prevent users from zooming in IE Mobile
[
#7589
](
https://github.com/diaspora/diaspora/pull/7589
)
*
Fix recipient prefill on contacts and profile page
[
#7599
](
https://github.com/diaspora/diaspora/pull/7599
)
*
Display likes and reshares without login
[
#7583
](
https://github.com/diaspora/diaspora/pull/7583
)
*
Fix invalid data in the database for user data export
[
#7614
](
https://github.com/diaspora/diaspora/pull/7614
)
## Features
*
Ask for confirmation when leaving a submittable comment field
[
#7530
](
https://github.com/diaspora/diaspora/pull/7530
)
...
...
app/models/poll.rb
View file @
655fe2a9
...
...
@@ -5,8 +5,8 @@ class Poll < ApplicationRecord
include
Diaspora
::
Fields
::
Guid
belongs_to
:status_message
has_many
:poll_answers
,
->
{
order
'id ASC'
}
has_many
:poll_participations
has_many
:poll_answers
,
->
{
order
"id ASC"
},
dependent: :destroy
has_many
:poll_participations
,
dependent: :destroy
has_one
:author
,
through: :status_message
#forward some requests to status message, because a poll is just attached to a status message and is not sharable itself
...
...
app/models/status_message.rb
View file @
655fe2a9
...
...
@@ -20,7 +20,7 @@ class StatusMessage < Post
has_many
:photos
,
:dependent
=>
:destroy
,
:foreign_key
=>
:status_message_guid
,
:primary_key
=>
:guid
has_one
:location
has_one
:poll
,
autosave:
true
has_one
:poll
,
autosave:
true
,
dependent: :destroy
has_many
:poll_participations
,
through: :poll
attr_accessor
:oembed_url
...
...
db/migrate/20170914212336_cleanup_invalid_polls.rb
0 → 100644
View file @
655fe2a9
class
CleanupInvalidPolls
<
ActiveRecord
::
Migration
[
5.1
]
class
Poll
<
ApplicationRecord
has_many
:poll_answers
,
dependent: :destroy
has_many
:poll_participations
,
dependent: :destroy
end
class
PollAnswer
<
ApplicationRecord
belongs_to
:poll
has_many
:poll_participations
end
class
PollParticipation
<
ApplicationRecord
belongs_to
:poll
belongs_to
:poll_answer
end
def
up
Poll
.
joins
(
"LEFT OUTER JOIN posts ON posts.id = polls.status_message_id"
)
.
where
(
"posts.id IS NULL"
).
destroy_all
end
end
spec/models/status_message_spec.rb
View file @
655fe2a9
...
...
@@ -233,6 +233,23 @@ describe StatusMessage, type: :model do
end
end
describe
"poll"
do
it
"destroys the poll (with all answers and participations) when the status message is destroyed"
do
poll
=
FactoryGirl
.
create
(
:poll_participation
).
poll
status_message
=
poll
.
status_message
poll_id
=
poll
.
id
poll_answers
=
poll
.
poll_answers
.
map
(
&
:id
)
poll_participations
=
poll
.
poll_participations
.
map
(
&
:id
)
status_message
.
destroy
expect
(
Poll
.
where
(
id:
poll_id
)).
not_to
exist
poll_answers
.
each
{
|
id
|
expect
(
PollAnswer
.
where
(
id:
id
)).
not_to
exist
}
poll_participations
.
each
{
|
id
|
expect
(
PollParticipation
.
where
(
id:
id
)).
not_to
exist
}
end
end
describe
"validation"
do
let
(
:status_message
)
{
build
(
:status_message
,
text:
@message_text
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment