Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix GET /posts/:id/mentions before_id sorting

  • Loading branch information...
commit 9bbf1fef3ca6bf357d7bc331cf7c2e8e01bc7e8c 1 parent 8750fb8
@jvatic jvatic authored
Showing with 26 additions and 8 deletions.
  1. +16 −2 lib/tentd/model/post.rb
  2. +10 −6 spec/integration/api/posts_spec.rb
View
18 lib/tentd/model/post.rb
@@ -171,7 +171,15 @@ def public_mentions(params = {})
sql_bindings << params[:post_types].split(',').map { |uri| TentType.new(uri).base }
end
- sql << "ORDER BY posts.id"
+ if params.has_key?(:before_id)
+ sort_reversed = true
+ sort_direction = 'DESC'
+ else
+ sort_reversed = false
+ sort_direction = 'ASC'
+ end
+
+ sql << "ORDER BY posts.id #{sort_direction}"
sql << "LIMIT ?"
sql_bindings << [(params[:limit] ? params[:limit].to_i : API::PER_PAGE), API::MAX_PER_PAGE].min
@@ -179,7 +187,13 @@ def public_mentions(params = {})
sql = sql.join(' ')
query = Mention.with_sql(sql, *sql_bindings)
- params[:return_count] ? query.count : query.all
+ if params[:return_count]
+ query.count
+ else
+ res = query.all
+ res.reverse! if sort_reversed
+ res
+ end
end
def latest_version(options = {})
View
16 spec/integration/api/posts_spec.rb
@@ -683,15 +683,19 @@ def authorize!(*scopes)
context 'with params' do
context 'with [:before_id] param' do
it 'should return mentions with id < :before_id' do
+ other2_known_post # create
params = {
- :before_id => other_known_post.public_id
+ :before_id => other2_known_post.public_id
}
- json_get "/posts/#{post.public_id}/mentions", params, env
- expect(last_response.status).to eq(200)
- body = Yajl::Parser.parse(last_response.body)
- expect(body.size).to eql(1)
- expect(body.first['post']).to eql(known_post.public_id)
+ with_constants "TentD::API::MAX_PER_PAGE" => 1 do
+ json_get "/posts/#{post.public_id}/mentions", params, env
+ expect(last_response.status).to eq(200)
+
+ body = Yajl::Parser.parse(last_response.body)
+ expect(body.size).to eql(1)
+ expect(body.first['post']).to eql(other_known_post.public_id)
+ end
end
it 'should return mentions with id < :before_id where entity = :before_id_entity' do
Please sign in to comment.
Something went wrong with that request. Please try again.