Commit 4fb04c74348ee79d15255aac9df8ab5f75b89a08
Committed by
Rodrigo Souto
1 parent
8e6799ff
Exists in
api_tasks
and in
4 other branches
fixing unit tests
Showing
5 changed files
with
24 additions
and
9 deletions
Show diff stats
lib/noosfero/api/entities.rb
... | ... | @@ -64,6 +64,7 @@ module Noosfero |
64 | 64 | expose :profile, :using => Profile |
65 | 65 | expose :categories, :using => Category |
66 | 66 | expose :image, :using => Image |
67 | + #TODO Apply vote stuff in core and make this test | |
67 | 68 | expose :votes_for |
68 | 69 | expose :votes_against |
69 | 70 | expose :setting | ... | ... |
lib/noosfero/api/helpers.rb
... | ... | @@ -2,10 +2,10 @@ module Noosfero |
2 | 2 | module API |
3 | 3 | module APIHelpers |
4 | 4 | PRIVATE_TOKEN_PARAM = :private_token |
5 | - ALLOWED_PARAMETERS = ['parent_id', 'from', 'until', 'content_type'] | |
5 | + ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type] | |
6 | 6 | |
7 | 7 | def current_user |
8 | - private_token = (params[PRIVATE_TOKEN_PARAM] || headers['Private-Token'] || cookies['_noosfero_api_session']).to_s if params | |
8 | + private_token = (params[PRIVATE_TOKEN_PARAM] || headers['Private-Token']).to_s | |
9 | 9 | @current_user ||= User.find_by_private_token(private_token) |
10 | 10 | @current_user = nil if !@current_user.nil? && @current_user.private_token_expired? |
11 | 11 | @current_user |
... | ... | @@ -53,10 +53,10 @@ module Noosfero |
53 | 53 | def make_conditions_with_parameter(params = {}) |
54 | 54 | parsed_params = parser_params(params) |
55 | 55 | conditions = {} |
56 | - from_date = DateTime.parse(parsed_params.delete('from')) if parsed_params['from'] | |
57 | - until_date = DateTime.parse(parsed_params.delete('until')) if parsed_params['until'] | |
56 | + from_date = DateTime.parse(parsed_params.delete(:from)) if parsed_params[:from] | |
57 | + until_date = DateTime.parse(parsed_params.delete(:until)) if parsed_params[:until] | |
58 | 58 | |
59 | - conditions[:type] = parse_content_type(parsed_params.delete('content_type')) unless parsed_params['content_type'].nil? | |
59 | + conditions[:type] = parse_content_type(parsed_params.delete(:content_type)) unless parsed_params[:content_type].nil? | |
60 | 60 | |
61 | 61 | conditions[:created_at] = period(from_date, until_date) if from_date || until_date |
62 | 62 | conditions.merge!(parsed_params) |
... | ... | @@ -167,7 +167,11 @@ module Noosfero |
167 | 167 | private |
168 | 168 | |
169 | 169 | def parser_params(params) |
170 | - params.select{|k,v| ALLOWED_PARAMETERS.include?(k)} | |
170 | + parsed_params = {} | |
171 | + params.map do |k,v| | |
172 | + parsed_params[k.to_sym] = v if ALLOWED_PARAMETERS.include?(k.to_sym) | |
173 | + end | |
174 | + parsed_params | |
171 | 175 | end |
172 | 176 | |
173 | 177 | def default_limit | ... | ... |
lib/noosfero/api/v1/articles.rb
... | ... | @@ -32,10 +32,13 @@ module Noosfero |
32 | 32 | get ':id/children' do |
33 | 33 | article = find_article(environment.articles, params[:id]) |
34 | 34 | |
35 | + #TODO make tests for this situation | |
35 | 36 | votes_order = params.delete(:order) if params[:order]=='votes_score' |
36 | 37 | articles = select_filtered_collection_of(article, 'children', params) |
37 | 38 | articles = articles.display_filter(current_person, nil) |
38 | 39 | |
40 | + | |
41 | + #TODO make tests for this situation | |
39 | 42 | if votes_order |
40 | 43 | articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').reorder('sum(coalesce(votes.vote, 0)) DESC') |
41 | 44 | end | ... | ... |
test/unit/api/helpers_test.rb
1 | 1 | require File.dirname(__FILE__) + '/test_helper' |
2 | 2 | require File.expand_path(File.dirname(__FILE__) + "/../../../lib/noosfero/api/helpers") |
3 | 3 | |
4 | -class APITest < ActiveSupport::TestCase | |
4 | +class APIHelpersTest < ActiveSupport::TestCase | |
5 | 5 | |
6 | 6 | include Noosfero::API::APIHelpers |
7 | 7 | |
... | ... | @@ -126,11 +126,18 @@ class APITest < ActiveSupport::TestCase |
126 | 126 | assert_not_nil make_conditions_with_parameter(:from => '2010-10-10')[:created_at] |
127 | 127 | end |
128 | 128 | |
129 | + should 'make_conditions_with_parameter return created_at parameter if from period is defined as string' do | |
130 | + assert_not_nil make_conditions_with_parameter('from' => '2010-10-10')[:created_at] | |
131 | + end | |
132 | + | |
129 | 133 | should 'make_conditions_with_parameter return created_at parameter if until period is defined' do |
130 | 134 | assert_not_nil make_conditions_with_parameter(:until => '2010-10-10')[:created_at] |
131 | 135 | end |
132 | 136 | |
133 | -# should 'the beginning of the period be the first existent date if no from date is passsed as parameter' do | |
137 | + should 'make_conditions_with_parameter return created_at parameter if until period is defined as string' do | |
138 | + assert_not_nil make_conditions_with_parameter('until' => '2010-10-10')[:created_at] | |
139 | + end | |
140 | + | |
134 | 141 | should 'make_conditions_with_parameter return created_at as the first existent date as parameter if only until is defined' do |
135 | 142 | assert_equal Time.at(0).to_datetime, make_conditions_with_parameter(:until => '2010-10-10')[:created_at].min |
136 | 143 | end | ... | ... |