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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Milan
diaspora
Commits
7b5ac656
Unverified
Commit
7b5ac656
authored
Aug 18, 2016
by
Steffen van Bergerem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix conversations autoSuggest showing non-mutual contacts
parent
0a1a7b16
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
7 deletions
+44
-7
app/controllers/conversations_controller.rb
app/controllers/conversations_controller.rb
+1
-1
app/models/contact.rb
app/models/contact.rb
+2
-0
spec/controllers/conversations_controller_spec.rb
spec/controllers/conversations_controller_spec.rb
+5
-2
spec/models/contact_spec.rb
spec/models/contact_spec.rb
+36
-4
No files found.
app/controllers/conversations_controller.rb
View file @
7b5ac656
...
...
@@ -104,7 +104,7 @@ class ConversationsController < ApplicationController
private
def
contacts_data
current_user
.
contacts
.
sharing
.
joins
(
person: :profile
)
current_user
.
contacts
.
mutual
.
joins
(
person: :profile
)
.
pluck
(
*
%w(contacts.id profiles.first_name profiles.last_name people.diaspora_handle)
)
.
map
{
|
contact_id
,
*
name_attrs
|
{
value:
contact_id
,
name:
ERB
::
Util
.
h
(
Person
.
name_from_attrs
(
*
name_attrs
))
}
...
...
app/models/contact.rb
View file @
7b5ac656
...
...
@@ -33,6 +33,8 @@ class Contact < ActiveRecord::Base
# contact.receiving is true when contact.user is sharing with contact.person
scope
:receiving
,
->
{
where
(
receiving:
true
)
}
scope
:mutual
,
->
{
sharing
.
receiving
}
scope
:for_a_stream
,
->
{
includes
(
:aspects
,
person: :profile
).
order
(
"profiles.last_name ASC"
)
}
scope
:only_sharing
,
->
{
sharing
.
where
(
receiving:
false
)
}
...
...
spec/controllers/conversations_controller_spec.rb
View file @
7b5ac656
...
...
@@ -23,10 +23,13 @@ describe ConversationsController, :type => :controller do
end
it
"assigns a json list of contacts that are sharing with the person"
do
sharing_user
=
FactoryGirl
.
create
(
:user_with_aspect
)
sharing_user
.
share_with
(
alice
.
person
,
sharing_user
.
aspects
.
first
)
get
:new
,
:modal
=>
true
expect
(
assigns
(
:contacts_json
)).
to
include
(
alice
.
contacts
.
where
(
:sharing
=>
true
).
first
.
person
.
name
)
expect
(
assigns
(
:contacts_json
)).
to
include
(
alice
.
contacts
.
where
(
sharing:
true
,
receiving:
true
).
first
.
person
.
name
)
alice
.
contacts
<<
Contact
.
new
(
:person_id
=>
eve
.
person
.
id
,
:user_id
=>
alice
.
id
,
:sharing
=>
false
,
:receiving
=>
true
)
expect
(
assigns
(
:contacts_json
)).
not_to
include
(
alice
.
contacts
.
where
(
:sharing
=>
false
).
first
.
person
.
name
)
expect
(
assigns
(
:contacts_json
)).
not_to
include
(
alice
.
contacts
.
where
(
sharing:
false
).
first
.
person
.
name
)
expect
(
assigns
(
:contacts_json
)).
not_to
include
(
alice
.
contacts
.
where
(
receiving:
false
).
first
.
person
.
name
)
end
it
"assigns a contact if passed a contact id"
do
...
...
spec/models/contact_spec.rb
View file @
7b5ac656
...
...
@@ -85,10 +85,15 @@ describe Contact, type: :model do
it
"returns contacts with sharing true"
do
expect
{
alice
.
contacts
.
create!
(
sharing:
true
,
person:
FactoryGirl
.
create
(
:person
))
alice
.
contacts
.
create!
(
sharing:
false
,
person:
FactoryGirl
.
create
(
:person
))
}.
to
change
{
Contact
.
sharing
.
count
}.
by
(
1
)
expect
{
alice
.
contacts
.
create!
(
sharing:
false
,
person:
FactoryGirl
.
create
(
:person
))
}.
to
change
{
Contact
.
sharing
.
count
}.
by
(
0
)
end
end
...
...
@@ -96,23 +101,50 @@ describe Contact, type: :model do
it
"returns contacts with sharing true"
do
expect
{
alice
.
contacts
.
create!
(
receiving:
true
,
person:
FactoryGirl
.
build
(
:person
))
}.
to
change
{
Contact
.
receiving
.
count
}.
by
(
1
)
expect
{
alice
.
contacts
.
create!
(
receiving:
false
,
person:
FactoryGirl
.
build
(
:person
))
}.
to
change
{
Contact
.
receiving
.
count
}.
by
(
0
)
end
end
describe
"mutual"
do
it
"returns contacts with sharing true and receiving true"
do
expect
{
alice
.
contacts
.
create!
(
receiving:
true
,
sharing:
true
,
person:
FactoryGirl
.
build
(
:person
))
}.
to
change
{
Contact
.
mutual
.
count
}.
by
(
1
)
expect
{
alice
.
contacts
.
create!
(
receiving:
false
,
sharing:
true
,
person:
FactoryGirl
.
build
(
:person
))
alice
.
contacts
.
create!
(
receiving:
true
,
sharing:
false
,
person:
FactoryGirl
.
build
(
:person
))
}.
to
change
{
Contact
.
mutual
.
count
}.
by
(
0
)
end
end
describe
"only_sharing"
do
it
"returns contacts with sharing true and receiving false"
do
expect
{
alice
.
contacts
.
create!
(
receiving:
true
,
sharing:
true
,
person:
FactoryGirl
.
build
(
:person
))
alice
.
contacts
.
create!
(
receiving:
false
,
sharing:
true
,
person:
FactoryGirl
.
build
(
:person
))
alice
.
contacts
.
create!
(
receiving:
false
,
sharing:
true
,
person:
FactoryGirl
.
build
(
:person
))
alice
.
contacts
.
create!
(
receiving:
true
,
sharing:
false
,
person:
FactoryGirl
.
build
(
:person
))
}.
to
change
{
Contact
.
receiv
ing
.
count
Contact
.
only_shar
ing
.
count
}.
by
(
2
)
expect
{
alice
.
contacts
.
create!
(
receiving:
true
,
sharing:
true
,
person:
FactoryGirl
.
build
(
:person
))
alice
.
contacts
.
create!
(
receiving:
true
,
sharing:
false
,
person:
FactoryGirl
.
build
(
:person
))
}.
to
change
{
Contact
.
only_sharing
.
count
}.
by
(
0
)
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