Commit 8b7475adc83779f0a44318ea37c34ae6b16cd033

Authored by Leandro Santos
1 parent a2bdbbc6
Exists in fix_sign_up_form

considering timezone in api time filters

app/api/helpers.rb
... ... @@ -248,7 +248,7 @@ module Api
248 248 def make_timestamp_with_parameters_and_method(object, method_or_relation, params)
249 249 timestamp = nil
250 250 if params[:timestamp]
251   - datetime = DateTime.parse(params[:timestamp])
  251 + datetime = DateTime.parse(params[:timestamp]).utc
252 252 table_name = extract_associated_tablename(object, method_or_relation)
253 253 assoc_class = extract_associated_classname(object, method_or_relation)
254 254 date_atrr = assoc_class.attribute_names.include?('updated_at') ? 'updated_at' : 'created_at'
... ...
test/api/activities_test.rb
... ... @@ -182,7 +182,24 @@ class ActivitiesTest < ActiveSupport::TestCase
182 182 assert_not_includes json["activities"].map { |a| a["id"] }, a2.id
183 183 end
184 184  
  185 + should 'list activities with timestamp considering timezone' do
  186 + ActionTracker::Record.destroy_all
  187 + a1 = create_activity(:target => person)
  188 + a2 = create_activity(:target => person)
  189 + a2.updated_at = ActiveSupport::TimeZone.new('Brasilia').now
  190 + a2.save
  191 +
  192 + a1.updated_at = ActiveSupport::TimeZone.new('Brasilia').now + 3.hours
  193 + a1.save!
  194 +
185 195  
  196 + params[:timestamp] = ActiveSupport::TimeZone.new('Brasilia').now + 1.hours
  197 + get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
  198 + json = JSON.parse(last_response.body)
  199 +
  200 + assert_includes json["activities"].map { |a| a["id"] }, a1.id
  201 + assert_not_includes json["activities"].map { |a| a["id"] }, a2.id
  202 + end
186 203  
187 204 def create_activity(params = {})
188 205 params[:verb] ||= 'create_article'
... ...
test/api/task_test.rb
... ... @@ -157,6 +157,22 @@ class TasksTest < ActiveSupport::TestCase
157 157 assert_not_includes json["tasks"].map { |a| a["id"] }, t2.id
158 158 end
159 159  
  160 + should 'list tasks with timestamp considering timezone' do
  161 + t1 = create(Task, :requestor => person, :target => person)
  162 + t2 = create(Task, :requestor => person, :target => person, :created_at => ActiveSupport::TimeZone.new('Brasilia').now)
  163 +
  164 + t1.created_at = ActiveSupport::TimeZone.new('Brasilia').now + 3.hours
  165 + t1.save!
  166 +
  167 +
  168 + params[:timestamp] = ActiveSupport::TimeZone.new('Brasilia').now + 1.hours
  169 + get "/api/v1/tasks/?#{params.to_query}"
  170 + json = JSON.parse(last_response.body)
  171 +
  172 + assert_includes json["tasks"].map { |a| a["id"] }, t1.id
  173 + assert_not_includes json["tasks"].map { |a| a["id"] }, t2.id
  174 + end
  175 +
160 176 task_actions=%w[finish cancel]
161 177 task_actions_state={"finish"=>"FINISHED","cancel"=>"CANCELLED"}
162 178 task_actions.each do |action|
... ...