Sha256: b0b07140e346673d3a00a945c82fa15d9075f99c372f551ded139e4bc1a2e893

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper.rb'

describe Rack::OAuth2::Server::Token::RefreshToken do

  context "when valid refresh_token is given" do

    before do
      @app = Rack::OAuth2::Server::Token.new(simple_app) do |request, response|
        response.access_token = "access_token"
      end
      @request = Rack::MockRequest.new @app
    end

    it "should return access_token as json response body" do
      response = @request.post("/", :params => {
        :grant_type => "refresh_token",
        :client_id => "valid_client",
        :refresh_token => "valid_refresh_token"
      })
      response.status.should == 200
      response.content_type.should == "application/json"
      response.body.should == {
        :access_token => "access_token"
      }.to_json
    end

  end

  context "when invalid refresh_token is given" do

    before do
      @app = Rack::OAuth2::Server::Token.new(simple_app) do |request, response|
        request.invalid_grant! 'Invalid refresh_token.'
      end
      @request = Rack::MockRequest.new @app
    end

    it "should return error message as json response body" do
      response = @request.post("/", :params => {
        :grant_type => "refresh_token",
        :client_id => "valid_client",
        :refresh_token => "invalid_refresh_token"
      })
      response.status.should == 400
      response.content_type.should == "application/json"
      response.body.should == {
        :error => :invalid_grant,
        :error_description => "Invalid refresh_token."
      }.to_json
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rack-oauth2-0.2.2.1 spec/rack/oauth2/server/token/refresh_token_spec.rb
rack-oauth2-0.2.3 spec/rack/oauth2/server/token/refresh_token_spec.rb
rack-oauth2-0.2.2 spec/rack/oauth2/server/token/refresh_token_spec.rb
rack-oauth2-0.2.1 spec/rack/oauth2/server/token/refresh_token_spec.rb
rack-oauth2-0.2.0 spec/rack/oauth2/server/token/refresh_token_spec.rb