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
d6e9809b
Commit
d6e9809b
authored
Oct 15, 2011
by
Maxwell Salzberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MS SM finished tag stream refactor
parent
2dda1609
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
235 additions
and
85 deletions
+235
-85
app/controllers/api/v0/users_controller.rb
app/controllers/api/v0/users_controller.rb
+9
-0
app/helpers/comments_helper.rb
app/helpers/comments_helper.rb
+0
-11
app/helpers/interim_stream_hackiness_helper.rb
app/helpers/interim_stream_hackiness_helper.rb
+22
-0
app/models/api/v0/serializers/user.rb
app/models/api/v0/serializers/user.rb
+19
-0
app/views/shared/_publisher.html.haml
app/views/shared/_publisher.html.haml
+1
-1
features/api.feature
features/api.feature
+11
-0
lib/stream/base.rb
lib/stream/base.rb
+5
-0
lib/stream/tag.rb
lib/stream/tag.rb
+53
-0
spec/controllers/api/v0/users_controller_spec.rb
spec/controllers/api/v0/users_controller_spec.rb
+23
-0
spec/controllers/tags_controller_spec.rb
spec/controllers/tags_controller_spec.rb
+10
-73
spec/lib/stream/tag_spec.rb
spec/lib/stream/tag_spec.rb
+82
-0
No files found.
app/controllers/api/v0/users_controller.rb
0 → 100644
View file @
d6e9809b
class
Api::V0::UsersController
<
ApplicationController
def
show
if
user
=
User
.
find_by_username
(
params
[
:username
])
render
:json
=>
Api
::
V0
::
Serializers
::
User
.
new
(
user
)
else
head
:not_found
end
end
end
app/helpers/comments_helper.rb
View file @
d6e9809b
...
@@ -30,15 +30,4 @@ module CommentsHelper
...
@@ -30,15 +30,4 @@ module CommentsHelper
nil
nil
end
end
end
end
def
commenting_disabled?
(
post
)
return
true
unless
user_signed_in?
if
defined?
(
@commenting_disabled
)
@commenting_disabled
elsif
defined?
(
@stream
)
!
@stream
.
can_comment?
(
post
)
else
false
end
end
end
end
app/helpers/interim_stream_hackiness_helper.rb
0 → 100644
View file @
d6e9809b
module
InterimStreamHackinessHelper
def
commenting_disabled?
(
post
)
return
true
unless
user_signed_in?
if
defined?
(
@commenting_disabled
)
@commenting_disabled
elsif
defined?
(
@stream
)
!
@stream
.
can_comment?
(
post
)
else
false
end
end
def
publisher_prefill_text
if
params
[
:prefill
].
present?
params
[
:prefill
]
elsif
defined?
(
@stream
)
@stream
.
publisher_prefill_text
else
nil
end
end
end
app/models/api/v0/serializers/user.rb
0 → 100644
View file @
d6e9809b
class
Api::V0::Serializers::User
attr_accessor
:user
def
initialize
(
user
)
@user
=
user
@person
=
user
.
person
@profile
=
@person
.
profile
end
def
as_json
(
opts
=
{})
{
"diaspora_id"
=>
@person
.
diaspora_handle
,
"first_name"
=>
@profile
.
first_name
,
"last_name"
=>
@profile
.
last_name
,
"image_url"
=>
@profile
.
image_url
,
"searchable"
=>
@profile
.
searchable
}
end
end
app/views/shared/_publisher.html.haml
View file @
d6e9809b
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
#publisher_textarea_wrapper
#publisher_textarea_wrapper
=
link_to
(
image_tag
(
'deletelabel.png'
),
"#"
,
:id
=>
"hide_publisher"
,
:title
=>
t
(
'.discard_post'
))
=
link_to
(
image_tag
(
'deletelabel.png'
),
"#"
,
:id
=>
"hide_publisher"
,
:title
=>
t
(
'.discard_post'
))
%ul
#photodropzone
%ul
#photodropzone
=
status
.
text_area
:fake_text
,
:rows
=>
2
,
:value
=>
h
(
p
arams
[
:prefill
]
),
:tabindex
=>
1
,
:placeholder
=>
t
(
'.whats_on_your_mind'
)
=
status
.
text_area
:fake_text
,
:rows
=>
2
,
:value
=>
h
(
p
ublisher_prefill_text
),
:tabindex
=>
1
,
:placeholder
=>
t
(
'.whats_on_your_mind'
)
=
status
.
hidden_field
:text
,
:value
=>
''
,
:class
=>
'clear_on_submit'
=
status
.
hidden_field
:text
,
:value
=>
''
,
:class
=>
'clear_on_submit'
#file-upload
{
:title
=>
t
(
'.upload_photos'
)}
#file-upload
{
:title
=>
t
(
'.upload_photos'
)}
...
...
features/api.feature
0 → 100644
View file @
d6e9809b
Feature
:
API
In order to use a client application
as an epic developer
I need to get user's info
Scenario
:
Getting a users public profile
Given
a user named
"Maxwell S"
with email
"maxwell@example.com"
And
I send and accept JSON
When
I send a GET request to
"/api/v0/users/maxwell_s"
Then
the response status should be
"200"
And
the JSON response should have
"first_name"
with the text
"Maxwell"
lib/stream/base.rb
View file @
d6e9809b
...
@@ -39,6 +39,11 @@ class Stream::Base
...
@@ -39,6 +39,11 @@ class Stream::Base
[]
[]
end
end
# @return [String]
def
publisher_prefill_text
''
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def
people
def
people
people_ids
=
posts
.
map
{
|
x
|
x
.
author_id
}
people_ids
=
posts
.
map
{
|
x
|
x
.
author_id
}
...
...
lib/stream/tag.rb
0 → 100644
View file @
d6e9809b
class
Stream::Tag
<
Stream
::
Base
attr_accessor
:tag_name
,
:people_page
def
initialize
(
user
,
tag_name
,
opts
=
{})
super
(
user
,
opts
)
self
.
tag_name
=
tag_name
@people_page
=
opts
[
:page
]
||
1
end
def
tag
@tag
||=
ActsAsTaggableOn
::
Tag
.
find_by_name
(
tag_name
)
end
def
tag_follow_count
@tag_follow_count
||=
tag
.
try
(
:followed_count
).
to_i
end
def
display_tag_name
@display_tag_name
||=
"#
#{
tag_name
}
"
end
def
people
@people
||=
Person
.
profile_tagged_with
(
tag_name
).
paginate
(
:page
=>
people_page
,
:per_page
=>
15
)
end
def
people_count
@people_count
||=
Person
.
profile_tagged_with
(
tag_name
).
count
end
def
posts
@posts
||=
construct_post_query
end
def
publisher_prefill_text
display_tag_name
+
' '
end
def
tag_name
=
(
tag_name
)
@tag_name
=
tag_name
.
downcase
.
gsub
(
'#'
,
''
)
end
private
def
construct_post_query
posts
=
StatusMessage
if
user
.
present?
posts
=
posts
.
owned_or_visible_by_user
(
user
)
else
posts
=
posts
.
all_public
end
posts
.
tagged_with
(
tag_name
).
for_a_stream
(
max_time
,
'created_at'
)
end
end
spec/controllers/api/v0/users_controller_spec.rb
0 → 100644
View file @
d6e9809b
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require
'spec_helper'
describe
Api
::
V0
::
UsersController
do
describe
'#show'
do
it
'succeeds'
do
get
:show
,
:username
=>
'alice'
response
.
should
be_success
end
it
"404s if there's no such user"
do
get
:show
,
:username
=>
"*****"
response
.
should
be_not_found
end
it
"returns the public profile data"
do
get
:show
,
:username
=>
'alice'
parsed_json
=
JSON
.
parse
(
response
.
body
)
parsed_json
.
keys
.
should
=~
%w( diaspora_id first_name last_name image_url searchable )
end
end
end
spec/controllers/tags_controller_spec.rb
View file @
d6e9809b
...
@@ -41,89 +41,26 @@ describe TagsController do
...
@@ -41,89 +41,26 @@ describe TagsController do
sign_in
:user
,
alice
sign_in
:user
,
alice
end
end
it
'displays your own post'
do
it
'assigns a Stream::Tag object with the current_user'
do
my_post
=
alice
.
post
(
:status_message
,
:text
=>
"#what"
,
:to
=>
'all'
)
get
:show
,
:name
=>
'yes'
get
:show
,
:name
=>
'what'
assigns
[
:stream
].
user
.
should
==
alice
assigns
(
:posts
).
should
==
[
my_post
]
response
.
status
.
should
==
200
end
it
"displays a friend's post"
do
other_post
=
bob
.
post
(
:status_message
,
:text
=>
"#hello"
,
:to
=>
'all'
)
get
:show
,
:name
=>
'hello'
assigns
(
:posts
).
should
==
[
other_post
]
response
.
status
.
should
==
200
end
it
'displays a public post'
do
other_post
=
eve
.
post
(
:status_message
,
:text
=>
"#hello"
,
:public
=>
true
,
:to
=>
'all'
)
get
:show
,
:name
=>
'hello'
assigns
(
:posts
).
should
==
[
other_post
]
response
.
status
.
should
==
200
end
end
it
'displays a public post that was sent to no one'
do
it
'succeeds'
do
stranger
=
Factory
(
:user_with_aspect
)
stranger_post
=
stranger
.
post
(
:status_message
,
:text
=>
"#hello"
,
:public
=>
true
,
:to
=>
'all'
)
get
:show
,
:name
=>
'hello'
assigns
(
:posts
).
should
==
[
stranger_post
]
end
it
'displays a post with a comment containing the tag search'
do
pending
"toooo slow"
bob
.
post
(
:status_message
,
:text
=>
"other post y'all"
,
:to
=>
'all'
)
other_post
=
bob
.
post
(
:status_message
,
:text
=>
"sup y'all"
,
:to
=>
'all'
)
Factory
(
:comment
,
:text
=>
"#hello"
,
:post
=>
other_post
)
get
:show
,
:name
=>
'hello'
assigns
(
:posts
).
should
==
[
other_post
]
response
.
status
.
should
==
200
end
it
'succeeds without posts'
do
get
:show
,
:name
=>
'hellyes'
get
:show
,
:name
=>
'hellyes'
response
.
status
.
should
==
200
response
.
status
.
should
==
200
end
end
end
end
context
"not signed in"
do
context
"not signed in"
do
context
"when there are people to display"
do
it
'assigns a Stream::Tag object with no user'
do
before
do
get
:show
,
:name
=>
'yes'
alice
.
profile
.
tag_string
=
"#whatevs"
assigns
[
:stream
].
user
.
should
be_nil
alice
.
profile
.
build_tags
alice
.
profile
.
save!
get
:show
,
:name
=>
"whatevs"
end
it
"succeeds"
do
response
.
should
be_success
end
it
"assigns the right set of people"
do
assigns
(
:people
).
should
==
[
alice
.
person
]
end
end
end
context
"when there are posts to display"
do
it
'succeeds'
do
before
do
get
:show
,
:name
=>
'hellyes'
@post
=
alice
.
post
(
:status_message
,
:text
=>
"#what"
,
:public
=>
true
,
:to
=>
'all'
)
response
.
status
.
should
==
200
alice
.
post
(
:status_message
,
:text
=>
"#hello"
,
:public
=>
true
,
:to
=>
'all'
)
end
it
"succeeds"
do
get
:show
,
:name
=>
'what'
response
.
should
be_success
end
it
"assigns the right set of posts"
do
get
:show
,
:name
=>
'what'
assigns
[
:posts
].
should
==
[
@post
]
end
it
'succeeds with comments'
do
alice
.
comment
(
'what WHAT!'
,
:post
=>
@post
)
get
:show
,
:name
=>
'what'
response
.
should
be_success
end
end
end
end
end
end
end
...
...
spec/lib/stream/tag_spec.rb
0 → 100644
View file @
d6e9809b
require
'spec_helper'
require
File
.
join
(
Rails
.
root
,
'spec'
,
'shared_behaviors'
,
'stream'
)
describe
Stream
::
Tag
do
context
'with a user'
do
before
do
@stream
=
Stream
::
Tag
.
new
(
alice
,
"what"
)
bob
.
post
(
:status_message
,
:text
=>
"#not_what"
,
:to
=>
'all'
)
end
it
'displays your own post'
do
my_post
=
alice
.
post
(
:status_message
,
:text
=>
"#what"
,
:to
=>
'all'
)
@stream
.
posts
.
should
==
[
my_post
]
end
it
"displays a friend's post"
do
other_post
=
bob
.
post
(
:status_message
,
:text
=>
"#what"
,
:to
=>
'all'
)
@stream
.
posts
.
should
==
[
other_post
]
end
it
'displays a public post'
do
other_post
=
eve
.
post
(
:status_message
,
:text
=>
"#what"
,
:public
=>
true
,
:to
=>
'all'
)
@stream
.
posts
.
should
==
[
other_post
]
end
it
'displays a public post that was sent to no one'
do
stranger
=
Factory
(
:user_with_aspect
)
stranger_post
=
stranger
.
post
(
:status_message
,
:text
=>
"#what"
,
:public
=>
true
,
:to
=>
'all'
)
@stream
.
posts
.
should
==
[
stranger_post
]
end
it
'displays a post with a comment containing the tag search'
do
pending
"toooo slow"
other_post
=
bob
.
post
(
:status_message
,
:text
=>
"sup y'all"
,
:to
=>
'all'
)
Factory
(
:comment
,
:text
=>
"#what"
,
:post
=>
other_post
)
@stream
.
posts
.
should
==
[
other_post
]
end
end
context
'without a user'
do
before
do
@post
=
alice
.
post
(
:status_message
,
:text
=>
"#what"
,
:public
=>
true
,
:to
=>
'all'
)
alice
.
post
(
:status_message
,
:text
=>
"#tagwhat"
,
:public
=>
true
,
:to
=>
'all'
)
alice
.
post
(
:status_message
,
:text
=>
"#what"
,
:public
=>
false
,
:to
=>
'all'
)
end
it
"displays only public posts with the tag"
do
stream
=
Stream
::
Tag
.
new
(
nil
,
"what"
)
stream
.
posts
.
should
==
[
@post
]
end
end
describe
'people'
do
it
"assigns the right set of people"
do
stream
=
Stream
::
Tag
.
new
(
bob
,
"whatevs"
)
alice
.
profile
.
tag_string
=
"#whatevs"
alice
.
profile
.
build_tags
alice
.
profile
.
save!
stream
.
people
.
should
==
[
alice
.
person
]
end
end
describe
'shared behaviors'
do
before
do
@stream
=
Stream
::
Tag
.
new
(
Factory
(
:user
),
"test"
)
end
it_should_behave_like
'it is a stream'
end
describe
'#tag_name='
do
it
'downcases the tag'
do
stream
=
Stream
::
Tag
.
new
(
nil
,
"WHAT"
)
stream
.
tag_name
.
should
==
'what'
end
it
'removes #es'
do
stream
=
Stream
::
Tag
.
new
(
nil
,
"#WHAT"
)
stream
.
tag_name
.
should
==
'what'
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