Use a Struct for passing parameters around
This helps avoid bugs due to mispelled param names
This commit is contained in:
@@ -8,10 +8,10 @@ class Aviator::Test
|
||||
|
||||
it 'raises an error when a required param is not provided' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
requires_param :someparamname
|
||||
required_param :someparamname
|
||||
end
|
||||
|
||||
initializer = lambda { klass.new({}) }
|
||||
initializer = lambda { klass.new }
|
||||
initializer.must_raise ArgumentError
|
||||
|
||||
error = initializer.call rescue $!
|
||||
@@ -23,147 +23,151 @@ class Aviator::Test
|
||||
|
||||
it 'does not raise any error when the required param is provided' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
requires_param :someparamname
|
||||
required_param :someparamname
|
||||
end
|
||||
|
||||
obj = klass.new({ someparamname: 'someparamvalue' })
|
||||
# obj = klass.new({ someparamname: 'someparamvalue' })
|
||||
|
||||
obj = klass.new do |params|
|
||||
params.someparamname = 'something'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe '::anonymous?' do
|
||||
|
||||
|
||||
it 'is false by default' do
|
||||
klass = Class.new(Aviator::Request)
|
||||
|
||||
|
||||
klass.anonymous?.must_equal false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it 'returns true if specified as such' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
anonymous
|
||||
end
|
||||
|
||||
|
||||
klass.anonymous?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '#anonymous?' do
|
||||
|
||||
|
||||
it 'is false by default' do
|
||||
klass = Class.new(Aviator::Request)
|
||||
|
||||
|
||||
klass.new.anonymous?.must_equal false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it 'returns true if specified as such' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
anonymous
|
||||
end
|
||||
|
||||
|
||||
klass.new.anonymous?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '::api_version' do
|
||||
|
||||
|
||||
it 'returns the api version' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
api_version :v2
|
||||
end
|
||||
|
||||
|
||||
klass.api_version.must_equal :v2
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '#api_version' do
|
||||
|
||||
|
||||
it 'returns the api version' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
api_version :v2
|
||||
end
|
||||
|
||||
|
||||
klass.new.api_version.must_equal :v2
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '::body?' do
|
||||
|
||||
|
||||
it 'returns false if the body method is not defined' do
|
||||
klass = Class.new(Aviator::Request)
|
||||
|
||||
|
||||
klass.body?.must_equal false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it 'returns true if the body method is defined' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
def body; end
|
||||
end
|
||||
|
||||
|
||||
klass.body?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '#body?' do
|
||||
|
||||
|
||||
it 'returns false if the body method is not defined' do
|
||||
klass = Class.new(Aviator::Request)
|
||||
|
||||
|
||||
klass.new.body?.must_equal false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it 'returns true if the body method is defined' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
def body; end
|
||||
end
|
||||
|
||||
|
||||
klass.new.body?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '::endpoint_type' do
|
||||
|
||||
|
||||
it 'returns the endpoint type' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
endpoint_type :public
|
||||
end
|
||||
|
||||
|
||||
klass.endpoint_type.must_equal :public
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '#endpoint_type' do
|
||||
|
||||
|
||||
it 'returns the endpoint type' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
endpoint_type :public
|
||||
end
|
||||
|
||||
|
||||
klass.new.endpoint_type.must_equal :public
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '::http_method' do
|
||||
|
||||
it 'returns the http method if it is defined' do
|
||||
@@ -189,16 +193,16 @@ class Aviator::Test
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe '::path?' do
|
||||
|
||||
|
||||
it 'returns false if the path method is not defined' do
|
||||
klass = Class.new(Aviator::Request)
|
||||
|
||||
|
||||
klass.path?.must_equal false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it 'returns true if the path method is defined' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
def path; end
|
||||
@@ -206,19 +210,19 @@ class Aviator::Test
|
||||
|
||||
klass.path?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
describe '#path?' do
|
||||
|
||||
|
||||
it 'returns false if the path method is not defined' do
|
||||
klass = Class.new(Aviator::Request)
|
||||
|
||||
|
||||
klass.new.path?.must_equal false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it 'returns true if the path method is defined' do
|
||||
klass = Class.new(Aviator::Request) do
|
||||
def path; end
|
||||
@@ -226,14 +230,14 @@ class Aviator::Test
|
||||
|
||||
klass.new.path?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe '::requires_param' do
|
||||
|
||||
|
||||
describe '::required_param' do
|
||||
|
||||
it 'is a private class method' do
|
||||
private_method = lambda { Aviator::Request.requires_param }
|
||||
private_method = lambda { Aviator::Request.required_param }
|
||||
private_method.must_raise NoMethodError
|
||||
|
||||
error = private_method.call rescue $!
|
||||
|
||||
Reference in New Issue
Block a user