Commit d7b3b82d9b3671a340b41e3449e456bd3b7e9822
Committed by
Rodrigo Souto
1 parent
97791385
Exists in
master
and in
29 other branches
adding helper teste
Showing
3 changed files
with
50 additions
and
5 deletions
Show diff stats
lib/api/helpers.rb
@@ -7,7 +7,7 @@ module API | @@ -7,7 +7,7 @@ module API | ||
7 | end | 7 | end |
8 | 8 | ||
9 | def current_user | 9 | def current_user |
10 | - private_token = params[PRIVATE_TOKEN_PARAM].to_s | 10 | + private_token = params[PRIVATE_TOKEN_PARAM].to_s if params |
11 | @current_user ||= User.find_by_private_token(private_token) | 11 | @current_user ||= User.find_by_private_token(private_token) |
12 | @current_user = nil if !@current_user.nil? && @current_user.private_token_expired? | 12 | @current_user = nil if !@current_user.nil? && @current_user.private_token_expired? |
13 | @current_user | 13 | @current_user |
lib/api/v1/articles.rb
@@ -13,10 +13,7 @@ module API | @@ -13,10 +13,7 @@ module API | ||
13 | # limit - amount of articles returned. The default value is 20 | 13 | # limit - amount of articles returned. The default value is 20 |
14 | # | 14 | # |
15 | # Example Request: | 15 | # Example Request: |
16 | - # GET http://localhost:3000/api/v1/articles?from=2013-04-04-14:41:43&until=2015-04-04-14:41:43&limit=10&private_token=e96fff37c2238fdab074d1dcea8e6317 | ||
17 | -# desc 'Articles.', { | ||
18 | -# :params => API::Entities::Article.documentation | ||
19 | -# } | 16 | + # GET host/api/v1/articles?from=2013-04-04-14:41:43&until=2015-04-04-14:41:43&limit=10&private_token=e96fff37c2238fdab074d1dcea8e6317 |
20 | get do | 17 | get do |
21 | articles = select_filtered_collection_of(environment, 'articles', params) | 18 | articles = select_filtered_collection_of(environment, 'articles', params) |
22 | articles = articles.display_filter(current_user.person, nil) | 19 | articles = articles.display_filter(current_user.person, nil) |
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +require File.dirname(__FILE__) + '/test_helper' | ||
2 | + | ||
3 | +class APITest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + include API::APIHelpers | ||
6 | + | ||
7 | +# def setup | ||
8 | +# login_api | ||
9 | +# end | ||
10 | + | ||
11 | + should 'get the current user' do | ||
12 | + user = create_user('someuser') | ||
13 | +# params = {:private_token => user.private_token} | ||
14 | +# post "/api/v1/login?#{params.to_query}" | ||
15 | +# json = JSON.parse(last_response.body) | ||
16 | + User.expects(:find_by_private_token).returns(user) | ||
17 | + assert_equal user, current_user | ||
18 | +# | ||
19 | +# assert !json["private_token"].blank? | ||
20 | + end | ||
21 | + | ||
22 | +# should 'return 401 when login fails' do | ||
23 | +# user.destroy | ||
24 | +# params = {:login => "testapi", :password => "testapi"} | ||
25 | +# post "/api/v1/login?#{params.to_query}" | ||
26 | +# assert_equal 401, last_response.status | ||
27 | +# end | ||
28 | +# | ||
29 | +# should 'register a user' do | ||
30 | +# params = {:login => "newuserapi", :password => "newuserapi", :email => "newuserapi@email.com" } | ||
31 | +# post "/api/v1/register?#{params.to_query}" | ||
32 | +# assert_equal 201, last_response.status | ||
33 | +# end | ||
34 | +# | ||
35 | +# should 'do not register a user without email' do | ||
36 | +# params = {:login => "newuserapi", :password => "newuserapi", :email => nil } | ||
37 | +# post "/api/v1/register?#{params.to_query}" | ||
38 | +# assert_equal 400, last_response.status | ||
39 | +# end | ||
40 | +# | ||
41 | +# should 'do not register a duplicated user' do | ||
42 | +# params = {:login => "newuserapi", :password => "newuserapi", :email => "newuserapi@email.com" } | ||
43 | +# post "/api/v1/register?#{params.to_query}" | ||
44 | +# post "/api/v1/register?#{params.to_query}" | ||
45 | +# assert_equal 400, last_response.status | ||
46 | +# end | ||
47 | +# | ||
48 | +end |