Skip to content

Commit beb22f3

Browse files
committed
moved Boolean class definition
reworked spec as a result for scope issues
1 parent 50b8dc8 commit beb22f3

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

lib/grape/validations/coerce.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
Boolean = Virtus::Attribute::Boolean
21

32
module Grape
3+
class API
4+
Boolean = Virtus::Attribute::Boolean
5+
end
6+
47
module Validations
58

69
class CoerceValidator < SingleOptionValidator

spec/grape/validations/coerce_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
require 'spec_helper'
22

3+
class CoerceAPI < Grape::API
4+
default_format :json
5+
6+
params do
7+
requires :int, :coerce => Integer
8+
optional :arr, :coerce => Array[Integer]
9+
optional :bool, :coerce => Array[Boolean]
10+
end
11+
get '/coerce' do
12+
{
13+
:int => params[:int].class,
14+
:arr => params[:arr] ? params[:arr][0].class : nil,
15+
:bool => params[:bool] ? (params[:bool][0] == true) && (params[:bool][1] == false) : nil
16+
}
17+
end
18+
end
19+
320
describe Grape::Validations::CoerceValidator do
421
def app; @app; end
522

623
before do
7-
@app = Class.new(Grape::API) do
8-
default_format :json
9-
10-
params do
11-
requires :int, :coerce => Integer
12-
optional :arr, :coerce => Array[Integer]
13-
optional :bool, :coerce => Array[Boolean]
14-
end
15-
get '/coerce' do
16-
{
17-
:int => params[:int].class,
18-
:arr => params[:arr] ? params[:arr][0].class : nil,
19-
:bool => params[:bool] ? (params[:bool][0] == true) && (params[:bool][1] == false) : nil
20-
}
21-
end
22-
23-
end
24-
24+
@app = CoerceAPI
2525
end
2626

2727
# TOOD: Later when virtus can tell us that an input IS invalid

0 commit comments

Comments
 (0)