Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
diaspora
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Gigadoc 2
diaspora
Commits
44b616ed
Unverified
Commit
44b616ed
authored
Feb 18, 2017
by
Steffen van Bergerem
Committed by
Benjamin Neff
Feb 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reshare service
parent
e74b524e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
+131
-0
app/services/reshare_service.rb
app/services/reshare_service.rb
+24
-0
spec/services/reshare_service.rb
spec/services/reshare_service.rb
+107
-0
No files found.
app/services/reshare_service.rb
0 → 100644
View file @
44b616ed
class
ReshareService
def
initialize
(
user
=
nil
)
@user
=
user
end
def
create
(
post_id
)
post
=
post_service
.
find!
(
post_id
)
post
=
post
.
absolute_root
if
post
.
is_a?
Reshare
user
.
reshare!
(
post
)
end
def
find_for_post
(
post_id
)
reshares
=
post_service
.
find!
(
post_id
).
reshares
user
?
reshares
.
order
(
"author_id =
#{
user
.
person
.
id
}
DESC"
)
:
reshares
end
private
attr_reader
:user
def
post_service
@post_service
||=
PostService
.
new
(
user
)
end
end
spec/services/reshare_service.rb
0 → 100644
View file @
44b616ed
describe
ReshareService
do
let
(
:post
)
{
alice
.
post
(
:status_message
,
text:
"hello"
,
public:
true
)
}
describe
"#create"
do
it
"doesn't create a reshare of my own post"
do
expect
{
ReshareService
.
new
(
alice
).
create
(
post
.
id
)
}.
not_to
raise_error
end
it
"creates a reshare of a post of a contact"
do
expect
{
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
}.
not_to
raise_error
end
it
"attaches the reshare to the post"
do
reshare
=
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
expect
(
post
.
reshares
.
first
.
id
).
to
eq
(
reshare
.
id
)
end
it
"reshares the original post when called with a reshare"
do
reshare
=
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
reshare2
=
ReshareService
.
new
(
eve
).
create
(
reshare
.
id
)
expect
(
post
.
reshares
.
map
(
&
:id
)).
to
include
(
reshare2
.
id
)
end
it
"fails if the post does not exist"
do
expect
{
ReshareService
.
new
(
bob
).
create
(
"unknown id"
)
}.
to
raise_error
ActiveRecord
::
RecordNotFound
end
it
"fails if the post is not public"
do
post
=
alice
.
post
(
:status_message
,
text:
"hello"
,
to:
alice
.
aspects
.
first
)
expect
{
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordInvalid
end
it
"fails if the user already reshared the post"
do
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
expect
{
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordInvalid
end
it
"fails if the user already reshared the original post"
do
reshare
=
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
expect
{
ReshareService
.
new
(
bob
).
create
(
reshare
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordInvalid
end
end
describe
"#find_for_post"
do
context
"with user"
do
it
"returns reshares for a public post"
do
reshare
=
ReshareService
.
new
(
bob
).
create
(
post
.
id
)
expect
(
ReshareService
.
new
(
eve
).
find_for_post
(
post
.
id
)).
to
include
(
reshare
)
end
it
"returns reshares for a visible private post"
do
post
=
alice
.
post
(
:status_message
,
text:
"hello"
,
to:
alice
.
aspects
.
first
)
expect
(
ReshareService
.
new
(
bob
).
find_for_post
(
post
.
id
)).
to
be_empty
end
it
"doesn't return reshares for a private post the user can not see"
do
post
=
alice
.
post
(
:status_message
,
text:
"hello"
,
to:
alice
.
aspects
.
first
)
expect
{
ReshareService
.
new
(
eve
).
find_for_post
(
post
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordNotFound
end
it
"returns the user's reshare first"
do
[
alice
,
bob
,
eve
].
map
{
|
user
|
ReshareService
.
new
(
user
).
create
(
post
.
id
)
}
[
alice
,
bob
,
eve
].
each
do
|
user
|
expect
(
ReshareService
.
new
(
user
).
find_for_post
(
post
.
id
).
first
.
author
.
id
).
to
be
user
.
person
.
id
end
end
end
context
"without user"
do
it
"returns reshares for a public post"
do
reshare
=
ReshareService
.
new
(
alice
).
create
(
post
.
id
)
expect
(
ReshareService
.
new
.
find_for_post
(
post
.
id
)).
to
include
(
reshare
)
end
it
"doesn't return reshares a for private post"
do
post
=
alice
.
post
(
:status_message
,
text:
"hello"
,
to:
alice
.
aspects
.
first
)
expect
{
ReshareService
.
new
.
find_for_post
(
post
.
id
)
}.
to
raise_error
Diaspora
::
NonPublic
end
end
it
"returns all reshares of a post"
do
reshares
=
[
alice
,
bob
,
eve
].
map
{
|
user
|
ReshareService
.
new
(
user
).
create
(
post
.
id
)
}
expect
(
ReshareService
.
new
.
find_for_post
(
post
.
id
)).
to
match_array
(
reshares
)
end
end
end
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