This fixes failing tests when the timezone is different than utc

There were several problems:
* Time.now returns the systems time, not the users time
* fixtures do not translate dates from timezone to utc, but stores the
  date verbatim
* calling a controller will set the timezone to the preference of the
  current_user. So it could be changed while you do not realize this. I
  fixed the failing test, but problems could be elsewhere
This commit is contained in:
Reinier Balt 2015-08-04 23:08:13 +02:00
parent 0b44fe3f08
commit e58379e81f
27 changed files with 221 additions and 214 deletions

View file

@ -1,8 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
Time.now.utc.to_s(:db)
# Please note that dates in yml are not converted to utc timezone like
# rails does automatically in models or controllers! Convert to utc manually!
<%
def today
Time.zone.now.utc.to_s(:db)
end
%>

View file

@ -1,16 +1,19 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
Time.now.utc.to_s(:db)
# Please note that dates in yml are not converted to utc timezone like
# rails does automatically in models or controllers! Convert to utc manually!
<%
def today
Time.zone.now.utc.to_s(:db)
end
def next_week
1.week.from_now.utc.to_s(:db)
def next_week
1.week.from_now.utc.to_s(:db)
end
def last_week
1.week.ago.utc.to_s(:db)
end
def last_week
1.week.ago.utc.to_s(:db)
end
%>
first_notes:

View file

@ -1,7 +1,10 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# Please note that dates in yml are not converted to utc timezone like
# rails does automatically in models or controllers! Convert to utc manually!
<%
def today
Time.zone.now.beginning_of_day.to_s(:db)
def today
Time.zone.now.utc.beginning_of_day.to_s(:db)
end
%>

View file

@ -1,26 +1,29 @@
# Please note that dates in yml are not converted to utc timezone like
# rails does automatically in models or controllers! Convert to utc manually!
<%
def today
Time.zone.now.beginning_of_day.to_s(:db)
Time.zone.now.utc.beginning_of_day.to_s(:db)
end
def next_week
1.week.from_now.beginning_of_day.to_s(:db)
1.week.from_now.utc.beginning_of_day.to_s(:db)
end
def last_week
1.week.ago.beginning_of_day.to_s(:db)
1.week.ago.utc.beginning_of_day.to_s(:db)
end
def two_weeks_ago
2.weeks.ago.beginning_of_day.to_s(:db)
2.weeks.ago.utc.beginning_of_day.to_s(:db)
end
def two_weeks_hence
2.weeks.from_now.beginning_of_day.to_s(:db)
2.weeks.from_now.utc.beginning_of_day.to_s(:db)
end
def way_back
Time.zone.local(2008,1,1).to_s(:db)
Time.zone.local(2008,1,1).utc.to_s(:db)
end
%>

View file

@ -1,17 +1,27 @@
# please note that dates in yml are not converted to utc timezone like
# rails does automatically in models or controllers! Convert to utc manually!
<%
def today
Time.zone.now.utc.beginning_of_day.to_s(:db)
end
%>
foo:
id: 1
name: foo
created_at: <%= Time.now.utc.to_s(:db) %>
updated_at: <%= Time.now.utc.to_s(:db) %>
created_at: <%= today %>
updated_at: <%= today %>
bar:
id: 2
name: bar
created_at: <%= Time.now.utc.to_s(:db) %>
updated_at: <%= Time.now.utc.to_s(:db) %>
created_at: <%= today %>
updated_at: <%= today %>
baz:
id: 3
name: baz
created_at: <%= Time.now.utc.to_s(:db) %>
updated_at: <%= Time.now.utc.to_s(:db) %>
created_at: <%= today %>
updated_at: <%= today %>

View file

@ -1,26 +1,27 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
Time.zone = SITE_CONFIG['time_zone']
# Please note that dates in yml are not converted to utc timezone like
# rails does automatically in models or controllers! Convert to utc manually!
def today
Time.zone.now.beginning_of_day.to_s(:db)
<%
def today
Time.zone.now.utc.beginning_of_day.to_s(:db)
end
def next_week
1.week.from_now.beginning_of_day.to_s(:db)
end
def next_week
1.week.from_now.utc.beginning_of_day.to_s(:db)
end
def last_week
1.week.ago.beginning_of_day.to_s(:db)
def last_week
1.week.ago.utc.beginning_of_day.to_s(:db)
end
def two_weeks_ago
2.weeks.ago.beginning_of_day.to_s(:db)
2.weeks.ago.utc.beginning_of_day.to_s(:db)
end
def two_weeks_hence
2.weeks.from_now.beginning_of_day.to_s(:db)
2.weeks.from_now.utc.beginning_of_day.to_s(:db)
end
%>
@ -192,7 +193,7 @@ call_stock_broker:
due: ~
completed_at: ~
user_id: 1
select_delorean_model:
id: 15
context_id: 6
@ -254,4 +255,3 @@ email_broker:
description: Ask about better stocks
notes: ~
state: pending