aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Goce <carlosgoce@gmail.com>2015-01-23 18:49:44 +0100
committerCarlos Goce <carlosgoce@gmail.com>2015-01-23 18:49:44 +0100
commitcaa0a9f01c4f3a8ca85a0ce4e335c71235006432 (patch)
tree8cdc9e25b2c91180da630cfcfd1799ac6c50ed92
parent03f5e6ba6e23a7d5c748414637a637edfc670a13 (diff)
downloadpdf-calendars-caa0a9f01c4f3a8ca85a0ce4e335c71235006432.tar.gz
pdf-calendars-caa0a9f01c4f3a8ca85a0ce4e335c71235006432.tar.bz2
pdf-calendars-caa0a9f01c4f3a8ca85a0ce4e335c71235006432.zip
Add a pending test. Day names are not localized
-rw-r--r--lib/carlosgoce/calendar.rb9
-rw-r--r--spec/calendar_spec.rb16
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/carlosgoce/calendar.rb b/lib/carlosgoce/calendar.rb
index e06b61b..d51df90 100644
--- a/lib/carlosgoce/calendar.rb
+++ b/lib/carlosgoce/calendar.rb
@@ -16,6 +16,15 @@ module CarlosGoce
h[month] = Hash.new.tap {|m|
m[:days] = (1..Time.days_in_month(month, @year)).to_a
m[:name] = I18n.t('date.month_names')[month].downcase
+
+ # todo: Need improvement. Not too performant...
+ # todo: Maby it should be moved to it's own class too to keep things simple
+ m[:days_names] = Array.new.tap {|a|
+ m[:days].each do |d|
+ t = Time.new @year, month, d
+ a << t.strftime('%A').downcase
+ end
+ }
}
end
}
diff --git a/spec/calendar_spec.rb b/spec/calendar_spec.rb
index e37e18d..fc78cc0 100644
--- a/spec/calendar_spec.rb
+++ b/spec/calendar_spec.rb
@@ -7,10 +7,11 @@ I18n.backend.load_translations
describe 'Calendar' do
before(:each) do
- @calendar = CarlosGoce::Calendar.new
+ @calendar = CarlosGoce::Calendar.new 2015
end
it 'should be initialized with the current year' do
+ @calendar = CarlosGoce::Calendar.new
expect(@calendar.year).to eq Date.today.year
end
@@ -26,9 +27,20 @@ describe 'Calendar' do
end
it 'return the numbers of available days for each month' do
- @calendar = CarlosGoce::Calendar.new 2015
expect(@calendar.to_h[1][:days]).to eq (1..31).to_a
end
+ it 'return the days as names' do
+ expect(@calendar.to_h[1][:days_names].first).to eq 'thursday'
+ expect(@calendar.to_h[1][:days_names].count).to eq 31
+ end
+
+ it 'return the day names localized',
+ :pending => "Not working!!! Months are localized, why days aren't?" do
+ skip 'Is not working, the names are localized so why days are not?'
+ I18n.locale = 'es'
+ expect(@calendar.to_h[1][:days_names].first).to eq 'jueves'
+ end
+
end
end \ No newline at end of file