Set default date at run time

Fixes #11
This commit is contained in:
Hakan Ensari 2015-09-15 12:02:49 +01:00
parent b35d1e4420
commit be1dcce266
2 changed files with 12 additions and 1 deletions

View File

@ -8,7 +8,7 @@ class Quote
values do
attribute :base, String, default: DEFAULT_BASE
attribute :date, Date, default: Currency.current_date
attribute :date, Date, default: proc { Currency.current_date }
end
def rates

View File

@ -6,6 +6,7 @@ describe 'the API' do
include Rack::Test::Methods
let(:app) { Sinatra::Application }
let(:json) { Yajl::Parser.new.parse last_response.body }
it 'handles unfound pages' do
get '/foo'
@ -31,4 +32,14 @@ describe 'the API' do
get '/latest?base=USD?callback=?'
last_response.must_be :unprocessable?
end
it 'returns fresh dates' do
Currency.db.transaction do
new_date = Currency.current_date + 1
Currency.create(date: new_date, iso_code: 'FOO', rate: 1)
get '/latest'
json['date'].must_equal new_date.to_s
raise Sequel::Rollback
end
end
end