Created
October 17, 2015 13:31
-
-
Save masartz/424a1d5ac9db68aa1348 to your computer and use it in GitHub Desktop.
sinatra-formkeeper combination-diff
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
require 'sinatra/base' | |
require 'sinatra/formkeeper' | |
class MainApp < Sinatra::Base | |
register Sinatra::FormKeeper | |
post '/input' do | |
form do | |
filters :strip | |
field :username, :present => true, :length => 4..12 | |
field :old_password, :present => true, :length => 8..16 | |
field :new_password, :present => true, :length => 8..16 | |
diff :different_password, ['old_password', 'new_password'] | |
end | |
if form.failed? | |
'input failed' | |
else | |
'input success ' + form[:username] | |
end | |
end | |
end |
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
require File.dirname(__FILE__) + '/spec_helper' | |
describe 'Main' do | |
include Rack::Test::Methods | |
context 'post to /input' do | |
context '(old|new)_password are different' do | |
valid_param = { | |
username: 'valid_name', | |
old_password: 'password_old', | |
new_password: 'password_new', | |
} | |
it 'success response' do | |
post '/input', valid_param | |
expect(last_response.body).to eq 'input success valid_name' | |
end | |
end | |
context '(old|new)_password are same' do | |
invalid_param = { | |
username: 'valid_name', | |
old_password: ' password_same', | |
new_password: 'password_same ', | |
} | |
it 'failed response' do | |
post '/input', invalid_param | |
expect(last_response.body).to eq 'input failed' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment