Sha256: 3bfd26d2592d79597fc35ce2a09e86819878219dd3a4fc64b00b06f3613ad07f

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

require "test_helper"

describe "Posts Integration" do

  before do
    Post.destroy_all
    @posts = create_list(:post, 10)
  end

  after do
    Post.destroy_all
  end

  it "gets posts API with param=v1" do
    response = get(posts_path(:format => :json, :api_version => 'v1'))
    assert response.ok?
    json = JSON.parse(response.body)
    json['posts'].length.must_equal 10
    json['api_version'].must_equal 'v1'
    json['posts'].length.must_equal 10
  end

  it "gets posts API with param=v1_1" do
    response = get(posts_path(:format => :json, :api_version => 'v1_1'))
    assert response.ok?
    json = JSON.parse(response.body)
    json['posts'].length.must_equal 10
    json['api_version'].must_equal 'v1_1'
    json['posts'].length.must_equal 10
  end

  it "gets posts API with empty api_version param" do
    response = get(posts_path(:format => :json))
    assert response.ok?
    json = JSON.parse(response.body)
    json['posts'].length.must_equal 10
    json['api_version'].must_equal 'v1_1'
    json['posts'].length.must_equal 10
  end

  it "gets posts API with header" do
    response = get(posts_path(:format => :json), {}, { 'HTTP_X_API_VERSION' => 'v1' })
    assert response.ok?
    json = JSON.parse(response.body)
    json['posts'].length.must_equal 10
    json['api_version'].must_equal 'v1'
    json['posts'].length.must_equal 10
  end

  it "get an API error " do
    response = get(error_path(:format => :json))
    json = JSON.parse(response.body)
    json['status_code'].must_equal 400
    json['status_description'].must_equal 'Bad Request'
    json['message'].must_equal 'Deliberate Error'
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
api_versioning-0.0.8 test/integration/posts_integration_test.rb
api_versioning-0.0.7 test/integration/posts_integration_test.rb
api_versioning-0.0.6 test/integration/posts_integration_test.rb
api_versioning-0.0.5 test/integration/posts_integration_test.rb
api_versioning-0.0.4 test/integration/posts_integration_test.rb
api_versioning-0.0.3 test/integration/posts_integration_test.rb
api_versioning-0.0.2 test/integration/posts_integration_test.rb
api_versioning-0.0.1 test/integration/posts_integration_test.rb