Sha256: fcf268295c39260e0366432a4670d37cc72d1de841f3ba5da18b66d929f0f1e2

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Hyperdrive::DSL::Resource do
  before do
    hyperdrive do
      resource(:thing) do
        name 'Thing Resource'
        description 'Thing Description'
        param :name, 'Thing Name'
        filter :parent_id, "Parent ID"
        before do
          'before'
        end
        request(:get) do
          'ok'
        end
      end
    end
  end

  after do
    hyperdrive.send(:reset!)
  end

  it "sets the name of the resource" do
    hyperdrive.resources[:thing].name.must_equal 'Thing Resource'
  end

  it "sets the description of the resource" do
    hyperdrive.resources[:thing].description.must_equal 'Thing Description'
  end

  it "registers a param for the resource" do
    hyperdrive.resources[:thing].params[:name].description.must_equal "Thing Name"
  end

  it "registers a filter for the resource" do
    hyperdrive.resources[:thing].filters[:parent_id].description.must_equal "Parent ID"
  end

  it "registers requests handlers" do
    hyperdrive.resources[:thing].request_handlers[:get]['v1'].must_be :===, Proc
  end

  it "throws an error if request method is unknown" do
    bad_resource = -> { hyperdrive { resource(:thing) { request(:verb) } } }
   bad_resource.must_raise Hyperdrive::Errors::DSL::UnknownArgument
  end

  it "registers a before request callback" do
    hyperdrive.resources[:thing].callbacks[:before][:get]['v1'].must_be :===, Proc
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.24 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.23 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.22 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.21 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.20 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.19 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.18 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.17 spec/hyperdrive/dsl/resource_spec.rb
hyperdrive-0.0.16 spec/hyperdrive/dsl/resource_spec.rb