diff --git a/lib/quote.rb b/lib/quote.rb index c03aff2..4208fd5 100644 --- a/lib/quote.rb +++ b/lib/quote.rb @@ -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 diff --git a/spec/edge_cases_spec.rb b/spec/edge_cases_spec.rb index 8035d6b..08a5459 100644 --- a/spec/edge_cases_spec.rb +++ b/spec/edge_cases_spec.rb @@ -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