spec/hyperdrive/resource_spec.rb in hyperdrive-0.0.15 vs spec/hyperdrive/resource_spec.rb in hyperdrive-0.0.16
- old
+ new
@@ -3,10 +3,12 @@
describe Hyperdrive::Resource do
before do
@resource = Hyperdrive::Resource.new(:thing)
@resource.register_param(:name, 'Thing Name')
@resource.register_filter(:parent_id, 'Parent ID', required: true)
+ @resource.register_callback(:before, :get, Proc.new { |env| 'before v1' })
+ @resource.register_callback(:before, :get, Proc.new { |env| 'before v2' }, 'v2')
@resource.register_request_handler(:get, Proc.new { |env| 'v1' })
@resource.register_request_handler(:get, Proc.new { |env| 'v2' }, 'v2')
@media_types = ["application/vnd.hyperdrive.things.v2+hal+json",
"application/vnd.hyperdrive.things.v1+hal+json",
"application/vnd.hyperdrive.things+hal+json",
@@ -83,9 +85,29 @@
@resource.required?(:name, 'GET').must_equal false
end
it "returns false if the filter (or param) is not required" do
@resource.required?(:parent_id, 'DELETE').must_equal false
+ end
+
+ it "registers a before callback" do
+ @resource.callbacks[:before][:get]['v1'].must_be :===, Proc
+ end
+
+ it "auto-registers HEAD before callback when GET before callback is registered" do
+ @resource.callbacks[:before][:head]['v1'].must_be :===, Proc
+ end
+
+ it "returns the specified before callback" do
+ @resource.callback(:before, 'GET').must_be :===, Proc
+ end
+
+ it "returns true if the specified before callback exists" do
+ @resource.has_callback?(:before, 'GET').must_equal true
+ end
+
+ it "returns false if the specified before callback does not exist" do
+ @resource.has_callback?(:before, 'GET', 'v3').must_equal false
end
it "registers a request handler" do
@resource.request_handlers[:get]['v1'].must_be :===, Proc
end