Sha256: f6e9a638867a7de9116e4ed4264adc722df9f08c8621f6261289b549a268b4c5

Contents?: true

Size: 1.59 KB

Versions: 27

Compression:

Stored size: 1.59 KB

Contents

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

class UsersGetOneResourceTest < ResourceTestCase

  include DataCatalog

  def app; Users end
  
  before do
    @user = create_user
  end

  after do
    @user.destroy
  end

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

    context "incorrect API key" do
      before do
        get "/#{@user.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
  end

  %w(basic curator).each do |role|
    context "#{role} : get /:id" do
      before do
        get "/#{@user.id}", :api_key => api_key_for(role)
      end
  
      use "return 200 Ok"
      doc_properties %w(name id created_at updated_at)
    end
  end

  context "owner : get /:id" do
    before do
      get "/#{@user.id}", :api_key => @user._api_key
    end
  
    use "return 200 Ok"
    doc_properties %w(name email role _api_key token
      id created_at updated_at)
  end
  
  %w(admin).each do |role|
    context "#{role} : get /:id" do
      before do
        get "/#{@user.id}", :api_key => api_key_for(role)
      end
  
      use "return 200 Ok"
      doc_properties %w(name email role _api_key token
        id created_at updated_at)
    end
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
sinatra_resource-0.4.1 examples/datacatalog/test/resources/users/users_get_one_test.rb
sinatra_resource-0.4.0 examples/datacatalog/test/resources/users/users_get_one_test.rb
sinatra_resource-0.3.6 examples/datacatalog/test/resources/users/users_get_one_test.rb
sinatra_resource-0.3.5 examples/datacatalog/test/resources/users/users_get_one_test.rb
sinatra_resource-0.3.4 examples/datacatalog/test/resources/users/users_get_one_test.rb
sinatra_resource-0.3.3 examples/datacatalog/test/resources/users/users_get_one_test.rb
sinatra_resource-0.3.2 examples/datacatalog/test/resources/users/users_get_one_test.rb