Sha256: 9e00270fa8aa2b1d4ef28871b361cd56828ea11f30bb22a4e97068b444161d80

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
test = File.expand_path("#{File.dirname(__FILE__)}/../test")
$:.unshift(lib)
$:.unshift(test)

require 'test/unit'
require 'active_resource'
require 'active_resource/http_mock'
require 'activeresource-response'
require "fixtures/country"


class ActiveResourceResponseTest < Test::Unit::TestCase


  def setup

    @country = {:country => {:id => 1, :name => "Ukraine", :iso=>"UA"}}
    ActiveResource::HttpMock.respond_to do |mock|
      mock.get "/countries.json", {}, [@country].to_json, 200, {"X-total"=>'1'}
      mock.get "/countries/1.json", {}, @country.to_json, 200, {"X-total"=>'1', 'Set-Cookie'=>['path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT, foo=bar, bar=foo']}
      mock.get "/countries/1/count.json", {}, {:count => 1155}.to_json, 200, {"X-total"=>'1'}


    end


  end


  def test_methods_appeared
    countries = Country.all
    assert countries.respond_to?(:http)
    assert countries.http.respond_to?(:cookies)
    assert countries.http.respond_to?(:headers)
  end

  def test_get_headers_from_all
    countries = Country.all
    assert_kind_of Country, countries.first
    assert_equal "UA", countries.first.iso

    assert_equal countries.http['X-total'].to_i, 1
    assert_equal countries.http.headers[:x_total].to_i, 1

  end


  def test_get_headers_from_custom_methods
    count = Country.find(1).get("count")
    assert_equal count.to_i, 1155
    assert_equal Country.connection.http_response['X-total'].to_i, 1
    assert_equal Country.connection.http_response.headers[:x_total].to_i, 1

  end


  def test_get_headers_from_find
    country = Country.find(1)
    assert_equal country.http['X-total'].to_i, 1
    assert_equal country.http.headers[:x_total].to_i, 1

  end


  def test_get_cookies
    country = Country.find(1)
    assert_equal country.http.cookies['foo'] ,  'bar'
    assert_equal country.http.cookies['bar'] ,  'foo'
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeresource-response-0.2.0 test/active_resource_response_test.rb