Commit 14f2a5e86d828daf6b25fe8b7fc68e125848c0e4
1 parent
8a6d7d69
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Fix merge with api
Showing
3 changed files
with
0 additions
and
119 deletions
Show diff stats
Gemfile
| @@ -13,7 +13,6 @@ gem 'daemons', '~> 1.1.5' | @@ -13,7 +13,6 @@ gem 'daemons', '~> 1.1.5' | ||
| 13 | gem 'thin', '~> 1.3.1' | 13 | gem 'thin', '~> 1.3.1' |
| 14 | gem 'nokogiri', '~> 1.5.5' | 14 | gem 'nokogiri', '~> 1.5.5' |
| 15 | gem 'rake', :require => false | 15 | gem 'rake', :require => false |
| 16 | -gem 'grape', '~> 0.2.1' | ||
| 17 | gem 'rest-client', '~> 1.6.7' | 16 | gem 'rest-client', '~> 1.6.7' |
| 18 | gem 'exception_notification', '~> 4.0.1' | 17 | gem 'exception_notification', '~> 4.0.1' |
| 19 | gem 'gettext', '~> 2.2.1', :require => false | 18 | gem 'gettext', '~> 2.2.1', :require => false |
db/migrate/20140407013817_add_private_token_info_to_users.rb
| @@ -1,11 +0,0 @@ | @@ -1,11 +0,0 @@ | ||
| 1 | -class AddPrivateTokenInfoToUsers < ActiveRecord::Migration | ||
| 2 | - def self.up | ||
| 3 | - add_column :users, :private_token, :string | ||
| 4 | - add_column :users, :private_token_generated_at, :datetime | ||
| 5 | - end | ||
| 6 | - | ||
| 7 | - def self.down | ||
| 8 | - remove_column :users, :private_token | ||
| 9 | - remove_column :users, :private_token_generated_at | ||
| 10 | - end | ||
| 11 | -end |
test/unit/api_test.rb
| @@ -1,107 +0,0 @@ | @@ -1,107 +0,0 @@ | ||
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | - | ||
| 3 | -class APITest < ActiveSupport::TestCase | ||
| 4 | - | ||
| 5 | - include Rack::Test::Methods | ||
| 6 | - | ||
| 7 | - def app | ||
| 8 | - API::API | ||
| 9 | - end | ||
| 10 | - | ||
| 11 | - def setup | ||
| 12 | - @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => Environment.default) | ||
| 13 | - @user.activate | ||
| 14 | - | ||
| 15 | - post "/api/v1/login?login=testapi&password=testapi" | ||
| 16 | - json = JSON.parse(last_response.body) | ||
| 17 | - @private_token = json["private_token"] | ||
| 18 | - @params = {:private_token => @private_token} | ||
| 19 | - end | ||
| 20 | - attr_accessor :private_token, :user, :params | ||
| 21 | - | ||
| 22 | - should 'generate private token when login' do | ||
| 23 | - params = {:login => "testapi", :password => "testapi"} | ||
| 24 | - post "/api/v1/login?#{params.to_query}" | ||
| 25 | - json = JSON.parse(last_response.body) | ||
| 26 | - assert !json["private_token"].blank? | ||
| 27 | - end | ||
| 28 | - | ||
| 29 | - should 'return 401 when login fails' do | ||
| 30 | - user.destroy | ||
| 31 | - params = {:login => "testapi", :password => "testapi"} | ||
| 32 | - post "/api/v1/login?#{params.to_query}" | ||
| 33 | - assert_equal 401, last_response.status | ||
| 34 | - end | ||
| 35 | - | ||
| 36 | - should 'register a user' do | ||
| 37 | - params = {:login => "newuserapi", :password => "newuserapi", :email => "newuserapi@email.com" } | ||
| 38 | - post "/api/v1/register?#{params.to_query}" | ||
| 39 | - assert_equal 201, last_response.status | ||
| 40 | - end | ||
| 41 | - | ||
| 42 | - should 'do not register a user without email' do | ||
| 43 | - params = {:login => "newuserapi", :password => "newuserapi", :email => nil } | ||
| 44 | - post "/api/v1/register?#{params.to_query}" | ||
| 45 | - assert_equal 400, last_response.status | ||
| 46 | - end | ||
| 47 | - | ||
| 48 | - should 'do not register a duplicated user' do | ||
| 49 | - params = {:login => "newuserapi", :password => "newuserapi", :email => "newuserapi@email.com" } | ||
| 50 | - post "/api/v1/register?#{params.to_query}" | ||
| 51 | - post "/api/v1/register?#{params.to_query}" | ||
| 52 | - assert_equal 400, last_response.status | ||
| 53 | - end | ||
| 54 | - | ||
| 55 | - should 'list articles' do | ||
| 56 | - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | ||
| 57 | - get "/api/v1/articles/?#{params.to_query}" | ||
| 58 | - json = JSON.parse(last_response.body) | ||
| 59 | - assert_includes json["articles"].map { |a| a["id"] }, article.id | ||
| 60 | - end | ||
| 61 | - | ||
| 62 | - should 'return article by id' do | ||
| 63 | - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | ||
| 64 | - get "/api/v1/articles/#{article.id}?#{params.to_query}" | ||
| 65 | - json = JSON.parse(last_response.body) | ||
| 66 | - assert_equal article.id, json["article"]["id"] | ||
| 67 | - end | ||
| 68 | - | ||
| 69 | - should 'return comments of an article' do | ||
| 70 | - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | ||
| 71 | - article.comments.create!(:body => "some comment", :author => user.person) | ||
| 72 | - article.comments.create!(:body => "another comment", :author => user.person) | ||
| 73 | - | ||
| 74 | - get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | ||
| 75 | - json = JSON.parse(last_response.body) | ||
| 76 | - assert_equal 2, json["comments"].length | ||
| 77 | - end | ||
| 78 | - | ||
| 79 | - should 'list users' do | ||
| 80 | - get "/api/v1/users/?#{params.to_query}" | ||
| 81 | - json = JSON.parse(last_response.body) | ||
| 82 | - assert_includes json["users"].map { |a| a["login"] }, user.login | ||
| 83 | - end | ||
| 84 | - | ||
| 85 | - should 'list user permissions' do | ||
| 86 | - community = fast_create(Community) | ||
| 87 | - community.add_admin(user.person) | ||
| 88 | - get "/api/v1/users/#{user.id}/?#{params.to_query}" | ||
| 89 | - json = JSON.parse(last_response.body) | ||
| 90 | - assert_includes json["user"]["permissions"], community.identifier | ||
| 91 | - end | ||
| 92 | - | ||
| 93 | - should 'list categories' do | ||
| 94 | - category = fast_create(Category) | ||
| 95 | - get "/api/v1/categories/?#{params.to_query}" | ||
| 96 | - json = JSON.parse(last_response.body) | ||
| 97 | - assert_includes json["categories"].map { |c| c["name"] }, category.name | ||
| 98 | - end | ||
| 99 | - | ||
| 100 | - should 'get category by id' do | ||
| 101 | - category = fast_create(Category) | ||
| 102 | - get "/api/v1/categories/#{category.id}/?#{params.to_query}" | ||
| 103 | - json = JSON.parse(last_response.body) | ||
| 104 | - assert_equal category.name, json["category"]["name"] | ||
| 105 | - end | ||
| 106 | - | ||
| 107 | -end |