Skip to content

Commit 6757f0b

Browse files
committed
Fix presence validator when param value is false
1 parent 10895a8 commit 6757f0b

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

lib/request_params_validation/definitions/param.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'request_params_validation/params'
2-
require 'request_params_validation/exceptions/definitions_errors'
32

43
module RequestParamsValidation
54
module Definitions

lib/request_params_validation/engine.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class Engine < ::Rails::Engine
66
isolate_namespace RequestParamsValidation
77

88
initializer 'request_params_validation.load_definitions' do
9-
RequestParamsValidation::Definitions.load_all
9+
Definitions.load_all
1010
end
1111

1212
initializer 'request_params_validation.add_helpers' do
1313
ActiveSupport.on_load :action_controller do
14-
include RequestParamsValidation::Helpers
14+
include Helpers
1515
end
1616
end
1717
end

lib/request_params_validation/params/validators/presence.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Presence
55
def validate_presence!
66
not_present = param.allow_blank ? value.nil? : value.blank?
77

8-
raise_error(:on_missing_parameter) if not_present
8+
raise_error(:on_missing_parameter) if not_present && value != false
99
end
1010
end
1111
end

request_params_validation.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Gem::Specification.new do |spec|
88
spec.version = RequestParamsValidation::VERSION
99
spec.authors = 'Felipe Fava'
1010
spec.email = 'felipefava5@gmail.com'
11-
spec.homepage = "https://github.com/felipefava/request_params_validation"
11+
spec.homepage = 'https://github.com/felipefava/request_params_validation'
1212
spec.license = 'MIT'
1313

1414
spec.summary = 'Validates rails request params'
1515
spec.description = 'It validates request params outside your controller logic in order to ' \
1616
'get a clean and nice code, and also helping with the documentation of ' \
1717
'the operations.'
1818

19-
spec.files = Dir["{lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
19+
spec.files = Dir['{lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
2020

2121
spec.add_dependency 'rails', '>= 3'
2222
end

spec/request_params_validation/validators/presence.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
expect(response.body).to eq(build_error_response(:missing_param, param_key: :key))
3636
end
3737

38+
context 'when parameter value is false' do
39+
let(:key_value) { false }
40+
41+
it { expect(response).to have_http_status(200) }
42+
end
43+
3844
describe 'custom exception for presence validations' do
3945
class CustomExceptionOnPresenceValidation < StandardError
4046
def initialize(_options)

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# is tagged with `:focus`, all examples get run. RSpec also provides
3535
# aliases for `it`, `describe`, and `context` that include `:focus`
3636
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
37-
# config.filter_run_when_matching :focus
37+
config.filter_run_when_matching :focus
3838

3939
# Allows RSpec to persist some state between runs in order to support
4040
# the `--only-failures` and `--next-failure` CLI options. We recommend

0 commit comments

Comments
 (0)