Skip to content

Instantly share code, notes, and snippets.

@masartz masartz/app.rb
Created Oct 17, 2015

Embed
What would you like to do?
sinatra-formkeeper combination-diff
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
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
You can’t perform that action at this time.