Commit c9998be9ebadbb1838eb133b150990c87eeca008

Authored by Evandro Junior
1 parent f0c82e2f

All tests from login_captcha test are passing finally!

test/unit/api/login_captcha_test.rb
@@ -3,14 +3,10 @@ require File.dirname(__FILE__) + '/test_helper' @@ -3,14 +3,10 @@ require File.dirname(__FILE__) + '/test_helper'
3 class LoginCaptchaTest < ActiveSupport::TestCase 3 class LoginCaptchaTest < ActiveSupport::TestCase
4 4
5 def setup() 5 def setup()
  6 + @url = "/api/v1/login-captcha"
6 OutcomeCaptcha.outcome_captcha_test = true 7 OutcomeCaptcha.outcome_captcha_test = true
7 end 8 end
8 9
9 - def create_article(name)  
10 - person = fast_create(Person, :environment_id => @environment.id)  
11 - fast_create(Article, :profile_id => person.id, :name => name)  
12 - end  
13 -  
14 should 'not perform a vote without authentication' do 10 should 'not perform a vote without authentication' do
15 article = create_article('Article 1') 11 article = create_article('Article 1')
16 params = {} 12 params = {}
@@ -26,7 +22,6 @@ class LoginCaptchaTest &lt; ActiveSupport::TestCase @@ -26,7 +22,6 @@ class LoginCaptchaTest &lt; ActiveSupport::TestCase
26 assert_not_nil @private_token 22 assert_not_nil @private_token
27 end 23 end
28 24
29 -  
30 should 'perform a vote in an article identified by id' do 25 should 'perform a vote in an article identified by id' do
31 login_with_captcha 26 login_with_captcha
32 article = create_article('Article 1') 27 article = create_article('Article 1')
@@ -69,9 +64,11 @@ class LoginCaptchaTest &lt; ActiveSupport::TestCase @@ -69,9 +64,11 @@ class LoginCaptchaTest &lt; ActiveSupport::TestCase
69 end 64 end
70 65
71 should 'not generate private token when login without captcha' do 66 should 'not generate private token when login without captcha' do
  67 + OutcomeCaptcha.outcome_captcha_test = false
72 params = {} 68 params = {}
73 post "#{@url}#{params.to_query}" 69 post "#{@url}#{params.to_query}"
74 json = JSON.parse(last_response.body) 70 json = JSON.parse(last_response.body)
  71 + assert_equal last_response.status, 403
75 assert json["private_token"].blank? 72 assert json["private_token"].blank?
76 end 73 end
77 74
test/unit/api/test_helper.rb
@@ -36,8 +36,15 @@ class ActiveSupport::TestCase @@ -36,8 +36,15 @@ class ActiveSupport::TestCase
36 end 36 end
37 37
38 def do_login_captcha_from_api 38 def do_login_captcha_from_api
39 - #JSON.parse("")  
40 - "sasadasdaasdasdadadsadassadas" 39 + post "/api/v1/login-captcha"
  40 + json = JSON.parse(last_response.body)
  41 + json
  42 + end
  43 +
  44 + def create_article(name)
  45 + @environment = Environment.default
  46 + person = fast_create(Person, :environment_id => @environment.id)
  47 + fast_create(Article, :profile_id => person.id, :name => name)
41 end 48 end
42 49
43 def login_api 50 def login_api