Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diaspora
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Milan
diaspora
Commits
e1cdcc68
Commit
e1cdcc68
authored
14 years ago
by
Raphael
Browse files
Options
Downloads
Patches
Plain Diff
Cut 10 seconds off of visible_posts_spec
parent
f9919d1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spec/models/user/visible_posts_spec.rb
+67
-79
67 additions, 79 deletions
spec/models/user/visible_posts_spec.rb
with
67 additions
and
79 deletions
spec/models/user/visible_posts_spec.rb
+
67
−
79
View file @
e1cdcc68
...
@@ -5,115 +5,103 @@
...
@@ -5,115 +5,103 @@
require
'spec_helper'
require
'spec_helper'
describe
User
do
describe
User
do
let!
(
:user
)
{
Factory
(
:user_with_aspect
)
}
let!
(
:first_aspect
)
{
user
.
aspects
.
first
}
let!
(
:second_aspect
)
{
user
.
aspect
(
:name
=>
'losers'
)
}
let!
(
:user2
)
{
Factory
(
:user_with_aspect
)
}
let!
(
:user2
)
{
Factory
(
:user_with_aspect
)
}
let!
(
:user3
)
{
Factory
(
:user_with_aspect
)
}
let!
(
:user4
)
{
Factory
(
:user_with_aspect
)
}
let!
(
:status_message1
)
{
user2
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
user2
.
aspects
.
first
.
id
}
context
'with two posts'
do
let!
(
:status_message2
)
{
user2
.
post
:status_message
,
:message
=>
"hey"
,
:public
=>
true
,
:to
=>
user2
.
aspects
.
first
.
id
}
let!
(
:status_message1
)
{
user2
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
user2
.
aspects
.
first
.
id
}
let!
(
:status_message3
)
{
user2
.
post
:status_message
,
:message
=>
"va"
,
:to
=>
user2
.
aspects
.
first
.
id
}
let!
(
:status_message2
)
{
user2
.
post
:status_message
,
:message
=>
"hey"
,
:public
=>
true
,
:to
=>
user2
.
aspects
.
first
.
id
}
let!
(
:status_message4
)
{
user2
.
post
:status_message
,
:message
=>
"da"
,
:public
=>
true
,
:to
=>
user2
.
aspects
.
first
.
id
}
let!
(
:status_message5
)
{
user3
.
post
:status_message
,
:message
=>
"heyyyy"
,
:to
=>
user3
.
aspects
.
first
.
id
}
let!
(
:status_message6
)
{
user4
.
post
:status_message
,
:message
=>
"yooo"
,
:to
=>
user4
.
aspects
.
first
.
id
}
before
do
friend_users
(
user
,
first_aspect
,
user2
,
user2
.
aspects
.
first
)
friend_users
(
user
,
second_aspect
,
user3
,
user3
.
aspects
.
first
)
end
describe
'#friends_not_in_aspect'
do
it
'finds the people who are not in the given aspect'
do
friend_users
(
user
,
first_aspect
,
user4
,
user4
.
aspects
.
first
)
people
=
user
.
friends_not_in_aspect
(
first_aspect
)
people
.
should
==
[
user3
.
person
]
people2
=
user
.
friends_not_in_aspect
(
second_aspect
)
people2
.
count
.
should
==
2
people2
.
include?
(
user2
.
person
).
should
be
true
people2
.
include?
(
user4
.
person
).
should
be
true
end
end
describe
"#visible_posts"
do
describe
"#visible_posts"
do
it
"queries by person id"
do
it
"queries by person id"
do
user2
.
visible_posts
(
:person_id
=>
user2
.
person
.
id
).
include?
(
status_message1
).
should
==
true
query
=
user2
.
visible_posts
(
:person_id
=>
user2
.
person
.
id
)
user2
.
visible_posts
(
:person_id
=>
user2
.
person
.
id
).
include?
(
status_message2
).
should
==
true
query
.
include?
(
status_message1
).
should
==
true
user2
.
visible_posts
(
:person_id
=>
user2
.
person
.
id
).
include?
(
status_message3
).
should
==
true
query
.
include?
(
status_message2
).
should
==
true
user2
.
visible_posts
(
:person_id
=>
user2
.
person
.
id
).
include?
(
status_message4
).
should
==
true
end
end
it
"selects public posts"
do
user2
.
visible_posts
(
:public
=>
true
).
include?
(
status_message2
).
should
==
true
user2
.
visible_posts
(
:public
=>
true
).
include?
(
status_message4
).
should
==
true
end
it
"selects non public posts"
do
user2
.
visible_posts
(
:public
=>
false
).
include?
(
status_message1
).
should
==
true
user2
.
visible_posts
(
:public
=>
false
).
include?
(
status_message3
).
should
==
true
end
it
"selects by message contents"
do
it
"selects public posts"
do
user2
.
visible_posts
(
:message
=>
"hi"
).
include?
(
status_message1
).
should
==
true
query
=
user2
.
visible_posts
(
:public
=>
true
)
end
query
.
include?
(
status_message2
).
should
==
true
query
.
include?
(
status_message1
).
should
==
false
end
it
"queries by aspect"
do
it
"selects non public posts"
do
friend_users
(
user
,
second_aspect
,
user4
,
user4
.
aspects
.
first
)
query
=
user2
.
visible_posts
(
:public
=>
false
)
query
.
include?
(
status_message1
).
should
==
true
query
.
include?
(
status_message2
).
should
==
false
end
user
.
receive
status_message4
.
to_diaspora_xml
,
user2
.
person
it
"selects by message contents"
do
user
.
receive
status_message5
.
to_diaspora_xml
,
user3
.
person
user
2
.
visible_posts
(
:message
=>
"hi"
).
include?
(
status_message1
).
should
==
true
user
.
receive
status_message6
.
to_diaspora_xml
,
user4
.
person
end
user
.
visible_posts
(
:by_members_of
=>
first_aspect
).
should
=~
[
status_message4
]
context
'with two users'
do
user
.
visible_posts
(
:by_members_of
=>
second_aspect
).
should
=~
[
status_message5
,
status_message6
]
let!
(
:user
)
{
Factory
:user
}
let!
(
:first_aspect
)
{
user
.
aspect
(
:name
=>
'bruisers'
)}
let!
(
:second_aspect
)
{
user
.
aspect
(
:name
=>
'losers'
)}
it
"queries by aspect"
do
friend_users
(
user
,
first_aspect
,
user2
,
user2
.
aspects
.
first
)
user
.
receive
status_message1
.
to_diaspora_xml
,
user2
.
person
user
.
visible_posts
(
:by_members_of
=>
first_aspect
).
should
=~
[
status_message1
]
user
.
visible_posts
(
:by_members_of
=>
second_aspect
).
should
=~
[]
end
it
'#find_visible_post_by_id'
do
user2
.
find_visible_post_by_id
(
status_message1
.
id
).
should
==
status_message1
user
.
find_visible_post_by_id
(
status_message1
.
id
).
should
==
nil
end
end
end
end
end
end
context
'querying'
do
context
'with two users'
do
describe
'#find_visible_post_by_id'
do
let!
(
:user
)
{
Factory
:user
}
it
'should query'
do
let!
(
:first_aspect
)
{
user
.
aspect
(
:name
=>
'bruisers'
)}
user2
.
find_visible_post_by_id
(
status_message1
.
id
).
should
==
status_message1
let!
(
:second_aspect
)
{
user
.
aspect
(
:name
=>
'losers'
)}
user
.
find_visible_post_by_id
(
status_message1
.
id
).
should
==
nil
describe
'#friends_not_in_aspect'
do
it
'finds the people who are not in the given aspect'
do
user4
=
Factory
.
create
(
:user_with_aspect
)
friend_users
(
user
,
first_aspect
,
user4
,
user4
.
aspects
.
first
)
friend_users
(
user
,
second_aspect
,
user2
,
user2
.
aspects
.
first
)
people
=
user
.
friends_not_in_aspect
(
first_aspect
)
people
.
should
==
[
user2
.
person
]
end
end
end
end
describe
'#find_friend_by_id'
do
describe
'#find_friend_by_id'
do
it
'should find
both
friend
s
'
do
it
'should find
a
friend'
do
user
.
reload
friend_users
(
user
,
first_aspect
,
user2
,
user2
.
aspects
.
first
)
user
.
find_friend_by_id
(
user2
.
person
.
id
).
should
==
user2
.
person
user
.
find_friend_by_id
(
user2
.
person
.
id
).
should
==
user2
.
person
user
.
find_friend_by_id
(
user3
.
person
.
id
).
should
==
user3
.
person
end
end
it
'should not find a non-friend'
do
it
'should not find a non-friend'
do
user3
.
find_friend_by_id
(
user4
.
person
.
id
).
should
be
nil
user
=
Factory
:user
user
.
find_friend_by_id
(
user2
.
person
.
id
).
should
be
nil
end
end
end
end
end
end
describe
'#albums_by_aspect'
do
context
'albums'
do
let!
(
:first_aspect
)
{
user2
.
aspect
(
:name
=>
'bruisers'
)}
let!
(
:second_aspect
)
{
user2
.
aspect
(
:name
=>
'losers'
)}
before
do
before
do
user
.
post
:album
,
:name
=>
"Georges"
,
:to
=>
first_aspect
.
id
user
2
.
post
:album
,
:name
=>
"Georges"
,
:to
=>
first_aspect
.
id
user
.
post
:album
,
:name
=>
"Borges"
,
:to
=>
first_aspect
.
id
user
2
.
post
:album
,
:name
=>
"Borges"
,
:to
=>
first_aspect
.
id
user
.
post
:album
,
:name
=>
"Luises"
,
:to
=>
second_aspect
.
id
user
2
.
post
:album
,
:name
=>
"Luises"
,
:to
=>
second_aspect
.
id
user
.
reload
user
2
.
reload
end
end
it
'should find all albums if passed :all'
do
it
'should find all albums if passed :all'
do
user
.
albums_by_aspect
(
:all
).
should
have
(
3
).
albums
user
2
.
albums_by_aspect
(
:all
).
should
have
(
3
).
albums
end
end
it
'should return the right number of albums'
do
it
'should return the right number of albums'
do
user
.
albums_by_aspect
(
first_aspect
.
reload
).
should
have
(
2
).
albums
user
2
.
albums_by_aspect
(
first_aspect
.
reload
).
should
have
(
2
).
albums
user
.
albums_by_aspect
(
second_aspect
.
reload
).
should
have
(
1
).
album
user
2
.
albums_by_aspect
(
second_aspect
.
reload
).
should
have
(
1
).
album
end
end
end
end
end
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