Sha256: 5521f17681e1a05485b912dbb06a280adefdc5048c0a5654bfa21ec79a88c115

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require "helpers/test_helper"
require "helpers/capybara_helper"

class OauthServiceProviderTest < ActiveSupport::TestCase
  include CapybaraHelper
  self.use_transactional_fixtures = false
  self.use_instantiated_fixtures  = false

  def test_login
    page.reset!
    login

    visit "http://localhost:3000/test"
    assert(parse_json(page)[:hello], "Should be true") 
  end

  def test_logout
    page.reset!
    login

    logout

    visit "http://localhost:3000/test"
    assert_equal(parse_json(page)[:error], "Permission denied", "Permission should be denied")
  end

  def login
    visit "http://localhost:3000/login"
    click_link "Авторизация через YANDEX"
    fill_in "login", with: ENV["TEST_USER_LOGIN"]
    fill_in "passwd", with: ENV["TEST_USER_PASSWORD"]
    click_button "Войти"

    res = parse_json(page)
    assert_equal(res[:api_code], User.find_by(name: ENV["TEST_USER_LOGIN"]).api_code, "API_CODE should be same")
    page.driver.add_headers("API_CODE" => res[:api_code])
  end

  def logout
    visit "http://localhost:3000/login/logout"
    
    assert_equal(nil, User.find_by(name: ENV["TEST_USER_LOGIN"]).api_code, "API_CODE should be nil")
    assert(parse_json(page)[:success], "Logout should be true")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oauth_service-0.0.2 test/oauth_service_provider_test.rb