Skip to content
This repository has been archived by the owner on Feb 16, 2018. It is now read-only.

Commit

Permalink
Fix HEAD /posts with post_types param
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Stuart committed Dec 22, 2012
1 parent 899d7bc commit f8018fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/tentd/model/permissible_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def fetch_with_permissions(params, current_auth)
end

if params.post_types
params.post_types = params.post_types.split(',').map { |url| URI.unescape(url) }
params.post_types = parse_array_param(params.post_types)
if params.post_types.any?
query << "AND #{table_name}.type_base IN ?"
query_bindings << params.post_types.map { |t| TentType.new(t).base }
Expand Down Expand Up @@ -201,6 +201,10 @@ def get_sort_column(params)
end
end

def parse_array_param(value)
(value.kind_of?(String) ? value.split(',') : value).map { |url| URI.unescape(url) }
end

def mentions_relationship_foreign_key
all_association_reflections.find { |a| a[:name] == :mentions }[:keys].first
end
Expand Down
11 changes: 11 additions & 0 deletions spec/integration/api/posts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def authorize!(*scopes)
end
end

context 'with post_types param' do
it 'should return count of posts' do
with_constants "TentD::API::PER_PAGE" => 1 do
params[:post_types] = ['type-uri-a', 'type-uri-b'].join(',')
head '/posts', params, env
expect(last_response.status).to eq(200)
expect(last_response.headers['Count']).to eql('0')
end
end
end

context 'when read_posts scope authorized' do
let(:authorized_post_types) { ['all'] }
before { authorize!(:read_posts) }
Expand Down

0 comments on commit f8018fc

Please sign in to comment.