-
-
Save jarosluv/947d6d30f85554681eb3d1ee9c8e22cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rake" | |
gem "hanami", github: "hanami" | |
gem "minitest" | |
end | |
require "minitest/autorun" | |
require "hanami/controller" | |
FooSchema = Dry::Validation.Schema do | |
configure do | |
def self.messages | |
super.merge( | |
{ en: { errors: { foo?: "WTF?" } } } | |
) | |
end | |
end | |
required(:title).filled | |
validate foo?: %i(title) do |title| | |
false | |
end | |
end | |
class CreateFoo | |
include Hanami::Action | |
params do | |
required(:foo).schema(FooSchema) | |
end | |
def call(params) | |
params.errors | |
halt 400 unless params.valid? | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_controller_action | |
params = Hash[foo: { title: "OK" }] | |
action = CreateFoo.new | |
response = action.call(params) | |
assert_equal 400, response[0] | |
end | |
end |
flash-gordon
commented
Jun 19, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment