Skip to content

Commit

Permalink
moved coerce test service in namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
schmurfy committed Jul 18, 2012
1 parent b5db980 commit 908bc2d
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions spec/grape/validations/coerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,48 @@ class User
attribute :name, String
end

end
class API < Grape::API
default_format :json


class CoerceAPI < Grape::API
default_format :json


params do
requires :int, :coerce => Integer
end
get '/single' do
end

params do
requires :ids, type: Array[Integer]
end
get '/arr' do
end

params do
requires :user, type: CoerceTest::User
end
get '/user' do
end

params do
requires :int, :coerce => Integer
optional :arr, :coerce => Array[Integer]
optional :bool, :coerce => Array[Boolean]
end
get '/coerce' do
{
:int => params[:int].class,
:arr => params[:arr] ? params[:arr][0].class : nil,
:bool => params[:bool] ? (params[:bool][0] == true) && (params[:bool][1] == false) : nil
}
params do
requires :int, :coerce => Integer
end
get '/single' do
end

params do
requires :ids, type: Array[Integer]
end
get '/arr' do
end

params do
requires :user, type: CoerceTest::User
end
get '/user' do
end

params do
requires :int, :coerce => Integer
optional :arr, :coerce => Array[Integer]
optional :bool, :coerce => Array[Boolean]
end
get '/coerce' do
{
:int => params[:int].class,
:arr => params[:arr] ? params[:arr][0].class : nil,
:bool => params[:bool] ? (params[:bool][0] == true) && (params[:bool][1] == false) : nil
}
end
end
end

describe Grape::Validations::CoerceValidator do
def app; @app; end

before do
@app = CoerceAPI
def app
CoerceTest::API
end

it "should return an error on malformed input" do
get '/single', :int => "43a"
last_response.status.should == 400
Expand Down

0 comments on commit 908bc2d

Please sign in to comment.