mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(QENG-2208) Move Sinatra Helpers to own file
This moves the inline Helpers contained in V1.rb to their own file: helpers.rb. In making this change, any API.settings call was removed from the helper method itself and passed through from V1. This also adds tests for hostname shortener and validate date string.
This commit is contained in:
parent
86a3a7a4ba
commit
ab990e2081
4 changed files with 188 additions and 137 deletions
40
spec/vmpooler/api/helpers_spec.rb
Normal file
40
spec/vmpooler/api/helpers_spec.rb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# A class for testing purposes that includes the Helpers.
|
||||
# this is impersonating V1's `helpers do include Helpers end`
|
||||
#
|
||||
# This is the subject used throughout the test file.
|
||||
#
|
||||
class TestHelpers
|
||||
include Vmpooler::API::Helpers
|
||||
end
|
||||
|
||||
describe Vmpooler::API::Helpers do
|
||||
|
||||
subject { TestHelpers.new }
|
||||
|
||||
describe '#hostname_shorten' do
|
||||
[
|
||||
['example.com', 'not-example.com', 'example.com'],
|
||||
['example.com', 'example.com', 'example.com'],
|
||||
['sub.example.com', 'example.com', 'sub'],
|
||||
['example.com', nil, 'example.com']
|
||||
].each do |hostname, domain, expected|
|
||||
it { expect(subject.hostname_shorten(hostname, domain)).to eq expected }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate_date_str' do
|
||||
[
|
||||
['2015-01-01', true],
|
||||
[nil, false],
|
||||
[false, false],
|
||||
[true, false],
|
||||
['01-01-2015', false],
|
||||
['1/1/2015', false]
|
||||
].each do |date, expected|
|
||||
it { expect(subject.validate_date_str(date)).to eq expected }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue