Sha256: f6b7147bbd046c39296bc335a0ef17e98b65fac7be665111e71bd55bd4e4da31

Contents?: true

Size: 1.74 KB

Versions: 29

Compression:

Stored size: 1.74 KB

Contents

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

class NotesGetOneResourceTest < ResourceTestCase

  include DataCatalog

  def app; Notes end
  
  before do
    @user = create_user
    @note = create_note(
      :user_id => @user.id
    )
  end

  after do
    @note.destroy
    @user.destroy
  end

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

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

  %w(basic curator).each do |role|
    context "#{role} : get /:fake_id" do
      before do
        get "/#{FAKE_ID}", :api_key => api_key_for(role)
      end
    
      use "return 401 because the API key is unauthorized"
    end
  
    context "#{role} : get /:id" do
      before do
        get "/#{@note.id}", :api_key => api_key_for(role)
      end
      
      use "return 401 because the API key is unauthorized"
    end
  end

  context "owner : get /:id" do
    before do
      get "/#{@note.id}", :api_key => @user._api_key
    end

    use "return 200 Ok"
    doc_properties %w(text user_id id created_at updated_at)
  end

  %w(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
        get "/#{@note.id}", :api_key => api_key_for(role)
      end

      use "return 200 Ok"
      doc_properties %w(text user_id id created_at updated_at)
    end
  end

end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
sinatra_resource-0.4.21 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.20 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.19 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.18 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.17 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.16 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.15 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.14 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.13 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.12 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.11 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.10 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.9 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.8 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.7 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.6 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.5 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.4 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.3 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
sinatra_resource-0.4.2 examples/datacatalog/test/resources/notes/notes_get_one_test.rb