Permalink
Browse files

Fix GET /posts/:id/versions since_version sorting

  • Loading branch information...
1 parent 9bbf1fe commit bc95ca97cd0456540a719e54312a66808dd079ab Jesse Stuart committed Dec 23, 2012
Showing with 16 additions and 7 deletions.
  1. +4 −0 lib/tentd/model/permissible_post_version.rb
  2. +12 −7 spec/integration/api/posts_spec.rb
@@ -31,6 +31,10 @@ def slice_params(params)
private
+ def sort_reversed?(params)
+ params.since_version && params.order.to_s.downcase != 'asc'
+ end
+
def build_common_fetch_post_versions_query(params, query, query_conditions, query_bindings)
if params.since_version
query_conditions << "#{table_name}.version > ?"
@@ -455,15 +455,20 @@ def authorize!(*scopes)
context 'with params' do
context '[:since_version]' do
it 'should return versions > :since_version' do
- latest_post_version = post.create_version!
+ since_post_version = post.latest_version
+ post_version = post.create_version!
+ other_post_version = post.create_version!
- params = { :since_version => post_version.version }
- get "/posts/#{post.public_id}/versions", params, env
- expect(last_response.status).to eql(200)
+ params = { :since_version => since_post_version.version }
- body = Yajl::Parser.parse(last_response.body)
- expect(body.size).to eql(1)
- expect(body.first['version']).to eql(latest_post_version.version)
+ with_constants "TentD::API::MAX_PER_PAGE" => 1 do
+ get "/posts/#{post.public_id}/versions", params, env
+ expect(last_response.status).to eql(200)
+
+ body = Yajl::Parser.parse(last_response.body)
+ expect(body.size).to eql(1)
+ expect(body.first['version']).to eql(post_version.version)
+ end
end
end

0 comments on commit bc95ca9

Please sign in to comment.