Sha256: 57a5555a3874148b8578f54217c5b3054ed228f909a1f5c40fc8e895ab14f790

Contents?: true

Size: 1.69 KB

Versions: 22

Compression:

Stored size: 1.69 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../helpers/resource_test_helper')

class CategoriesGetOneResourceTest < ResourceTestCase

  include DataCatalog

  def app; Categories end
  
  before do
    @category = create_category
  end
  
  after do
    @category.destroy
  end

  context "get /:id" do
    context "anonymous" do
      before do
        get "/#{@category.id}"
      end
    
      use "return 401 because the API key is missing"
    end

    context "incorrect API key" do
      before do
        get "/#{@category.id}", :api_key => BAD_API_KEY
      end
  
      use "return 401 because the API key is invalid"
    end
  end

  %w(basic curator admin).each do |role|
    context "#{role} : get /:fake_id" do
      before do
        get "/#{FAKE_ID}", :api_key => api_key_for(role)
      end
    
      use "return 404 Not Found with empty response body"
    end

    context "#{role} : get /:id" do
      before do
        @source = create_source
        @categorization = create_categorization(
          :source_id   => @source.id,
          :category_id => @category.id
        )
        get "/#{@category.id}", :api_key => api_key_for(role)
      end
      
      after do
        @source.destroy
        @categorization.destroy
      end

      use "return 200 Ok"
      doc_properties %w(name log id created_at updated_at sources)
      
      test "body should have correct sources" do
        expected = [
          {
            "id"    => @source.id,
            "href"  => "/sources/#{@source.id}",
            "title" => @source.title,
            "url"   => @source.url,
          }
        ]
        assert_equal expected, parsed_response_body["sources"]
      end
    end
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sinatra_resource-0.4.8 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.7 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.6 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.5 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.4 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.3 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.2 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.1 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.4.0 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.6 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.5 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.4 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.3 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.2 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.1 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.3.0 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.2.6 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.2.5 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.2.4 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
sinatra_resource-0.2.3 examples/datacatalog/test/resources/categories/categories_get_one_test.rb