Commit 40c630fd3bb0b129642c62e1fb8e5ad688c35f53

Authored by Leandro Santos
2 parents f253758a 8b7475ad
Exists in staging and in 1 other branch production

Merge branch 'master' into staging

app/api/helpers.rb
@@ -259,7 +259,7 @@ module Api @@ -259,7 +259,7 @@ module Api
259 def make_timestamp_with_parameters_and_method(object, method_or_relation, params) 259 def make_timestamp_with_parameters_and_method(object, method_or_relation, params)
260 timestamp = nil 260 timestamp = nil
261 if params[:timestamp] 261 if params[:timestamp]
262 - datetime = DateTime.parse(params[:timestamp]) 262 + datetime = DateTime.parse(params[:timestamp]).utc
263 table_name = extract_associated_tablename(object, method_or_relation) 263 table_name = extract_associated_tablename(object, method_or_relation)
264 assoc_class = extract_associated_classname(object, method_or_relation) 264 assoc_class = extract_associated_classname(object, method_or_relation)
265 date_atrr = assoc_class.attribute_names.include?('updated_at') ? 'updated_at' : 'created_at' 265 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,7 +182,24 @@ class ActivitiesTest < ActiveSupport::TestCase
182 assert_not_includes json["activities"].map { |a| a["id"] }, a2.id 182 assert_not_includes json["activities"].map { |a| a["id"] }, a2.id
183 end 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 def create_activity(params = {}) 204 def create_activity(params = {})
188 params[:verb] ||= 'create_article' 205 params[:verb] ||= 'create_article'
test/api/task_test.rb
@@ -157,6 +157,22 @@ class TasksTest < ActiveSupport::TestCase @@ -157,6 +157,22 @@ class TasksTest < ActiveSupport::TestCase
157 assert_not_includes json["tasks"].map { |a| a["id"] }, t2.id 157 assert_not_includes json["tasks"].map { |a| a["id"] }, t2.id
158 end 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 task_actions=%w[finish cancel] 176 task_actions=%w[finish cancel]
161 task_actions_state={"finish"=>"FINISHED","cancel"=>"CANCELLED"} 177 task_actions_state={"finish"=>"FINISHED","cancel"=>"CANCELLED"}
162 task_actions.each do |action| 178 task_actions.each do |action|