Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
diasporg
diaspora
Commits
d0b63485
Unverified
Commit
d0b63485
authored
Aug 05, 2017
by
Benjamin Neff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix belongs_to, it is now `required` by default
parent
eb19c327
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
56 additions
and
69 deletions
+56
-69
app/models/api/openid_connect/authorization.rb
app/models/api/openid_connect/authorization.rb
+1
-2
app/models/api/openid_connect/o_auth_access_token.rb
app/models/api/openid_connect/o_auth_access_token.rb
+0
-1
app/models/api/openid_connect/pairwise_pseudonymous_identifier.rb
...ls/api/openid_connect/pairwise_pseudonymous_identifier.rb
+1
-2
app/models/aspect_visibility.rb
app/models/aspect_visibility.rb
+0
-2
app/models/block.rb
app/models/block.rb
+1
-2
app/models/comment.rb
app/models/comment.rb
+0
-1
app/models/comment_signature.rb
app/models/comment_signature.rb
+0
-1
app/models/contact.rb
app/models/contact.rb
+0
-3
app/models/invitation_code.rb
app/models/invitation_code.rb
+0
-2
app/models/like_signature.rb
app/models/like_signature.rb
+0
-1
app/models/mention.rb
app/models/mention.rb
+0
-2
app/models/message.rb
app/models/message.rb
+0
-1
app/models/person.rb
app/models/person.rb
+2
-2
app/models/photo.rb
app/models/photo.rb
+1
-1
app/models/poll_participation.rb
app/models/poll_participation.rb
+0
-1
app/models/poll_participation_signature.rb
app/models/poll_participation_signature.rb
+0
-1
app/models/post.rb
app/models/post.rb
+2
-2
app/models/report.rb
app/models/report.rb
+2
-2
app/models/reshare.rb
app/models/reshare.rb
+1
-1
app/models/role.rb
app/models/role.rb
+0
-1
app/models/user.rb
app/models/user.rb
+2
-2
lib/diaspora/federation/receive.rb
lib/diaspora/federation/receive.rb
+2
-1
lib/diaspora/fields/target.rb
lib/diaspora/fields/target.rb
+0
-1
lib/diaspora/relayable.rb
lib/diaspora/relayable.rb
+1
-0
spec/models/contact_spec.rb
spec/models/contact_spec.rb
+2
-2
spec/models/location_spec.rb
spec/models/location_spec.rb
+8
-6
spec/models/poll_participation_spec.rb
spec/models/poll_participation_spec.rb
+9
-9
spec/models/poll_spec.rb
spec/models/poll_spec.rb
+15
-16
spec/models/role_spec.rb
spec/models/role_spec.rb
+6
-1
No files found.
app/models/api/openid_connect/authorization.rb
View file @
d0b63485
...
...
@@ -6,8 +6,7 @@ module Api
belongs_to
:user
belongs_to
:o_auth_application
validates
:user
,
presence:
true
,
uniqueness:
{
scope: :o_auth_application
}
validates
:o_auth_application
,
presence:
true
validates
:user
,
uniqueness:
{
scope: :o_auth_application
}
validate
:validate_scope_names
serialize
:scopes
,
JSON
...
...
app/models/api/openid_connect/o_auth_access_token.rb
View file @
d0b63485
...
...
@@ -29,7 +29,6 @@ module Api
before_validation
:setup
,
on: :create
validates
:token
,
presence:
true
,
uniqueness:
true
validates
:authorization
,
presence:
true
scope
:valid
,
->
(
time
)
{
where
(
"expires_at >= ?"
,
time
)
}
...
...
app/models/api/openid_connect/pairwise_pseudonymous_identifier.rb
View file @
d0b63485
...
...
@@ -26,10 +26,9 @@ module Api
class
PairwisePseudonymousIdentifier
<
ApplicationRecord
self
.
table_name
=
"ppid"
belongs_to
:o_auth_application
belongs_to
:o_auth_application
,
optional:
true
belongs_to
:user
validates
:user
,
presence:
true
validates
:identifier
,
presence:
true
,
uniqueness:
{
scope: :user
}
validates
:guid
,
presence:
true
,
uniqueness:
true
...
...
app/models/aspect_visibility.rb
View file @
d0b63485
...
...
@@ -5,10 +5,8 @@
class
AspectVisibility
<
ApplicationRecord
belongs_to
:aspect
validates
:aspect
,
:presence
=>
true
belongs_to
:shareable
,
:polymorphic
=>
true
validates
:shareable
,
:presence
=>
true
validates
:aspect
,
uniqueness:
{
scope:
%i(shareable_id shareable_type)
}
end
app/models/block.rb
View file @
d0b63485
...
...
@@ -4,8 +4,7 @@ class Block < ApplicationRecord
delegate
:name
,
to: :person
,
prefix:
true
validates
:user_id
,
:presence
=>
true
validates
:person_id
,
:presence
=>
true
,
:uniqueness
=>
{
:scope
=>
:user_id
}
validates
:person_id
,
uniqueness:
{
scope: :user_id
}
validate
:not_blocking_yourself
...
...
app/models/comment.rb
View file @
d0b63485
...
...
@@ -26,7 +26,6 @@ class Comment < ApplicationRecord
delegate
:author_name
,
to: :parent
,
prefix:
true
validates
:text
,
:presence
=>
true
,
:length
=>
{
:maximum
=>
65535
}
validates
:parent
,
:presence
=>
true
#should be in relayable (pending on fixing Message)
has_many
:reports
,
as: :item
...
...
app/models/comment_signature.rb
View file @
d0b63485
...
...
@@ -3,5 +3,4 @@ class CommentSignature < ApplicationRecord
self
.
primary_key
=
:comment_id
belongs_to
:comment
validates
:comment
,
presence:
true
end
app/models/contact.rb
View file @
d0b63485
...
...
@@ -6,10 +6,7 @@ class Contact < ApplicationRecord
include
Diaspora
::
Federated
::
Base
belongs_to
:user
validates
:user
,
presence:
true
belongs_to
:person
validates
:person
,
presence:
true
validates
:person_id
,
uniqueness:
{
scope: :user_id
}
...
...
app/models/invitation_code.rb
View file @
d0b63485
class
InvitationCode
<
ApplicationRecord
belongs_to
:user
validates_presence_of
:user
before_create
:generate_token
,
:set_default_invite_count
delegate
:name
,
to: :user
,
prefix:
true
...
...
app/models/like_signature.rb
View file @
d0b63485
...
...
@@ -3,5 +3,4 @@ class LikeSignature < ApplicationRecord
self
.
primary_key
=
:like_id
belongs_to
:like
validates
:like
,
presence:
true
end
app/models/mention.rb
View file @
d0b63485
...
...
@@ -5,8 +5,6 @@
class
Mention
<
ApplicationRecord
belongs_to
:mentions_container
,
polymorphic:
true
belongs_to
:person
validates
:mentions_container
,
presence:
true
validates
:person
,
presence:
true
scope
:local
,
->
{
joins
(
:person
).
where
.
not
(
people:
{
owner_id:
nil
})
...
...
app/models/message.rb
View file @
d0b63485
...
...
@@ -7,7 +7,6 @@ class Message < ApplicationRecord
delegate
:name
,
to: :author
,
prefix:
true
validates
:conversation
,
presence:
true
validates
:text
,
presence:
true
validate
:participant_of_parent_conversation
...
...
app/models/person.rb
View file @
d0b63485
...
...
@@ -44,8 +44,8 @@ class Person < ApplicationRecord
has_many
:roles
belongs_to
:owner
,
:class_name
=>
'User'
belongs_to
:pod
belongs_to
:owner
,
class_name:
"User"
,
optional:
true
belongs_to
:pod
,
optional:
true
has_many
:notification_actors
has_many
:notifications
,
:through
=>
:notification_actors
...
...
app/models/photo.rb
View file @
d0b63485
...
...
@@ -37,7 +37,7 @@ class Photo < ApplicationRecord
mount_uploader
:processed_image
,
ProcessedImage
mount_uploader
:unprocessed_image
,
UnprocessedImage
belongs_to
:status_message
,
:foreign_key
=>
:status_message_guid
,
:primary_key
=>
:guid
belongs_to
:status_message
,
foreign_key: :status_message_guid
,
primary_key: :guid
,
optional:
true
validates_associated
:status_message
delegate
:author_name
,
to: :status_message
,
prefix:
true
...
...
app/models/poll_participation.rb
View file @
d0b63485
...
...
@@ -12,7 +12,6 @@ class PollParticipation < ApplicationRecord
alias_attribute
:parent
,
:poll
validates
:poll_answer
,
presence:
true
validate
:not_already_participated
def
poll_answer_guid
=
(
new_poll_answer_guid
)
...
...
app/models/poll_participation_signature.rb
View file @
d0b63485
...
...
@@ -3,5 +3,4 @@ class PollParticipationSignature < ApplicationRecord
self
.
primary_key
=
:poll_participation_id
belongs_to
:poll_participation
validates
:poll_participation
,
presence:
true
end
app/models/post.rb
View file @
d0b63485
...
...
@@ -24,8 +24,8 @@ class Post < ApplicationRecord
has_many
:reshares
,
class_name:
"Reshare"
,
foreign_key: :root_guid
,
primary_key: :guid
has_many
:resharers
,
class_name:
"Person"
,
through: :reshares
,
source: :author
belongs_to
:o_embed_cache
belongs_to
:open_graph_cache
belongs_to
:o_embed_cache
,
optional:
true
belongs_to
:open_graph_cache
,
optional:
true
validates_uniqueness_of
:id
...
...
app/models/report.rb
View file @
d0b63485
...
...
@@ -9,8 +9,8 @@ class Report < ApplicationRecord
validate
:post_or_comment_does_exist
,
:on
=>
:create
belongs_to
:user
belongs_to
:post
belongs_to
:comment
belongs_to
:post
,
optional:
true
belongs_to
:comment
,
optional:
true
belongs_to
:item
,
polymorphic:
true
after_commit
:send_report_notification
,
:on
=>
:create
...
...
app/models/reshare.rb
View file @
d0b63485
...
...
@@ -3,7 +3,7 @@
# the COPYRIGHT file.
class
Reshare
<
Post
belongs_to
:root
,
:class_name
=>
'Post'
,
:foreign_key
=>
:root_guid
,
:primary_key
=>
:guid
belongs_to
:root
,
class_name:
"Post"
,
foreign_key: :root_guid
,
primary_key: :guid
,
optional:
true
validate
:root_must_be_public
validates_presence_of
:root
,
:on
=>
:create
validates_uniqueness_of
:root_guid
,
:scope
=>
:author_id
...
...
app/models/role.rb
View file @
d0b63485
...
...
@@ -3,7 +3,6 @@
class
Role
<
ApplicationRecord
belongs_to
:person
validates
:person
,
presence:
true
validates
:name
,
uniqueness:
{
scope: :person_id
}
validates
:name
,
inclusion:
{
in:
%w(admin moderator spotlight)
}
...
...
app/models/user.rb
View file @
d0b63485
...
...
@@ -51,8 +51,8 @@ class User < ApplicationRecord
has_many
:aspects
,
->
{
order
(
'order_id ASC'
)
}
belongs_to
:auto_follow_back_aspect
,
:class_name
=>
'Aspect'
belongs_to
:invited_by
,
:class_name
=>
'User'
belongs_to
:auto_follow_back_aspect
,
class_name:
"Aspect"
,
optional:
true
belongs_to
:invited_by
,
class_name:
"User"
,
optional:
true
has_many
:aspect_memberships
,
:through
=>
:aspects
...
...
lib/diaspora/federation/receive.rb
View file @
d0b63485
...
...
@@ -212,7 +212,8 @@ module Diaspora
poll
.
poll_answers
=
entity
.
poll_answers
.
map
do
|
answer
|
PollAnswer
.
new
(
guid:
answer
.
guid
,
answer:
answer
.
answer
answer:
answer
.
answer
,
poll:
poll
)
end
end
...
...
lib/diaspora/fields/target.rb
View file @
d0b63485
...
...
@@ -6,7 +6,6 @@ module Diaspora
belongs_to
:target
,
polymorphic:
true
validates
:target_id
,
uniqueness:
{
scope:
%i(target_type author_id)
}
validates
:target
,
presence:
true
end
end
end
...
...
lib/diaspora/relayable.rb
View file @
d0b63485
...
...
@@ -6,6 +6,7 @@ module Diaspora
module
Relayable
def
self
.
included
(
model
)
model
.
class_eval
do
validates
:parent
,
presence:
true
validates_associated
:parent
validate
:author_is_not_ignored
...
...
spec/models/contact_spec.rb
View file @
d0b63485
...
...
@@ -20,12 +20,12 @@ describe Contact, type: :model do
it
"requires a user"
do
contact
.
valid?
expect
(
contact
.
errors
.
full_messages
).
to
include
"User
can't be blank
"
expect
(
contact
.
errors
.
full_messages
).
to
include
"User
must exist
"
end
it
"requires a person"
do
contact
.
valid?
expect
(
contact
.
errors
.
full_messages
).
to
include
"Person
can't be blank
"
expect
(
contact
.
errors
.
full_messages
).
to
include
"Person
must exist
"
end
it
"validates uniqueness"
do
...
...
spec/models/location_spec.rb
View file @
d0b63485
describe
Location
,
:type
=>
:model
do
describe
'before validation'
do
it
'should create new location when it has coordinates'
do
location
=
Location
.
new
(
coordinates
:'1,2'
)
describe
Location
,
type: :model
do
describe
"before validation"
do
let
(
:status
)
{
FactoryGirl
.
create
(
:status_message
)
}
it
"should create new location when it has coordinates"
do
location
=
Location
.
new
(
coordinates:
"1,2"
,
status_message:
status
)
expect
(
location
.
save
).
to
be
true
end
it
'should not create new location when it does not have coordinates'
do
location
=
Location
.
new
()
it
"should not create new location when it does not have coordinates"
do
location
=
Location
.
new
(
status_message:
status
)
expect
(
location
.
save
).
to
be
false
end
end
...
...
spec/models/poll_participation_spec.rb
View file @
d0b63485
describe
PollParticipation
,
type: :model
do
let
(
:status
)
{
bob
.
post
(
:status_message
,
text:
"hello"
,
to:
bob
.
aspects
.
first
.
id
)
}
let
(
:poll
)
{
Poll
.
new
(
question:
"Who is in charge?"
)
}
before
do
@alices_aspect
=
alice
.
aspects
.
first
@status
=
bob
.
post
(
:status_message
,
:text
=>
"hello"
,
:to
=>
bob
.
aspects
.
first
.
id
)
@poll
=
Poll
.
new
(
:question
=>
'Who is in charge?'
)
@poll
.
poll_answers
.
build
(
:answer
=>
"a"
)
@poll
.
poll_answers
.
build
(
:answer
=>
"b"
)
@status
.
poll
=
@poll
poll
.
poll_answers
.
build
(
answer:
"a"
).
poll
=
poll
poll
.
poll_answers
.
build
(
answer:
"b"
).
poll
=
poll
status
.
poll
=
poll
end
describe
'validation'
do
it
'forbids multiple participations in the same poll'
do
expect
{
2
.
times
do
|
run
|
bob
.
participate_in_poll!
(
@status
,
@
poll
.
poll_answers
.
first
)
bob
.
participate_in_poll!
(
status
,
poll
.
poll_answers
.
first
)
end
}.
to
raise_error
ActiveRecord
::
RecordInvalid
end
it
'allows a one time participation in a poll'
do
expect
{
bob
.
participate_in_poll!
(
@status
,
@
poll
.
poll_answers
.
first
)
bob
.
participate_in_poll!
(
status
,
poll
.
poll_answers
.
first
)
}.
to_not
raise_error
end
end
...
...
@@ -38,6 +38,6 @@ describe PollParticipation, type: :model do
let
(
:remote_object_on_local_parent
)
{
FactoryGirl
.
create
(
:poll_participation
,
poll_answer:
local_parent
.
poll
.
poll_answers
.
first
,
author:
remote_raphael
)
}
let
(
:relayable
)
{
PollParticipation
::
Generator
.
new
(
alice
,
@status
,
@
poll
.
poll_answers
.
first
).
build
}
let
(
:relayable
)
{
PollParticipation
::
Generator
.
new
(
alice
,
status
,
poll
.
poll_answers
.
first
).
build
}
end
end
spec/models/poll_spec.rb
View file @
d0b63485
describe
Poll
,
:type
=>
:model
do
before
do
@poll
=
Poll
.
new
(
:question
=>
"What do you think about apples?"
)
end
describe
Poll
,
type: :model
do
let
(
:status
)
{
FactoryGirl
.
create
(
:status_message
)
}
let
(
:poll
)
{
Poll
.
new
(
question:
"What do you think about apples?"
,
status_message:
status
)
}
describe
'validation'
do
it
'should not create a poll when it has less than two answers'
do
@poll
.
poll_answers
.
build
(
:answer
=>
'1'
)
expect
(
@
poll
).
not_to
be_valid
describe
"validation"
do
it
"should not create a poll when it has less than two answers"
do
poll
.
poll_answers
.
build
(
answer:
"1"
).
poll
=
poll
expect
(
poll
).
not_to
be_valid
end
it
'should create a poll when it has more than two answers'
do
@poll
.
poll_answers
.
build
(
:answer
=>
'1'
)
@poll
.
poll_answers
.
build
(
:answer
=>
'2'
)
expect
(
@
poll
).
to
be_valid
it
"should create a poll when it has more than two answers"
do
poll
.
poll_answers
.
build
(
answer:
"1"
).
poll
=
poll
poll
.
poll_answers
.
build
(
answer:
"2"
).
poll
=
poll
expect
(
poll
).
to
be_valid
end
it
'should not create a poll when question in blank'
do
@poll
.
question
=
' '
@
poll
.
valid?
expect
(
@
poll
.
errors
).
to
have_key
(
:question
)
it
"should not create a poll when question in blank"
do
poll
.
question
=
" "
poll
.
valid?
expect
(
poll
.
errors
).
to
have_key
(
:question
)
end
end
end
spec/models/role_spec.rb
View file @
d0b63485
...
...
@@ -6,7 +6,12 @@ describe Role do
let!
(
:moderator_role
)
{
moderator
.
roles
.
create
(
name:
"moderator"
)
}
describe
"validations"
do
it
{
should
validate_presence_of
(
:person
)
}
it
"validates the presence of the person"
do
role
=
Role
.
new
(
name:
"admin"
)
role
.
valid?
expect
(
role
.
errors
.
full_messages
).
to
include
"Person must exist"
end
it
{
should
validate_uniqueness_of
(
:name
).
scoped_to
(
:person_id
)
}
it
{
should
validate_inclusion_of
(
:name
).
in_array
(
%w(admin spotlight moderator)
)
}
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