diff --git a/lib/frank/lorem.rb b/lib/frank/lorem.rb index a162620..470b58c 100644 --- a/lib/frank/lorem.rb +++ b/lib/frank/lorem.rb @@ -45,11 +45,11 @@ def paragraphs(total, replacement = nil) end end - def date(fmt = '%a %b %d, %Y', replacement = nil) + def date(fmt = '%a %b %d, %Y', range = 1950..2010, replacement = nil) if Frank.exporting? && replacement replacement else - y = rand(20) + 1990 + y = rand(range.last - range.first) + range.first m = rand(12) + 1 d = rand(31) + 1 Time.local(y,m,d).strftime(fmt) diff --git a/spec/template/dynamic/lorem_test.haml b/spec/template/dynamic/lorem_test.haml index 8f406ca..cbc50e8 100644 --- a/spec/template/dynamic/lorem_test.haml +++ b/spec/template/dynamic/lorem_test.haml @@ -1,7 +1,7 @@ %p.words= lorem.words 3, 'replace-this' %p.sentences= lorem.sentences 2, 'replace-this' %p.paragraphs= lorem.paragraphs 1, 'replace-this' -%p.date= lorem.date '%Y-%m-%d', 'replace-this' +%p.date= lorem.date '%Y-%m-%d', 1910..1919, 'replace-this' %p.name= lorem.name 'replace-this' %p.email= lorem.email 'replace-this' %img{:src => lorem.image('400x300')} diff --git a/spec/template_helpers_spec.rb b/spec/template_helpers_spec.rb index eaa9ea7..ab141f5 100644 --- a/spec/template_helpers_spec.rb +++ b/spec/template_helpers_spec.rb @@ -65,6 +65,12 @@ def app template.should =~ reg end + it 'render haml with lorem date between 1910 and 1919' do + template = @app.render('lorem_test.haml') + reg = /

191(\d{1})-\d{2}-\d{2}<\/p>/m + template.should =~ reg + end + it 'render image url using imager' do template = @app.render('lorem_test.haml') reg1 = //