[Git][noosfero/noosfero][master] considering timezone in api time filters

Leandro Nunes gitlab at mg.gitlab.com
Wed Jul 27 08:58:57 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
8b7475ad by Leandro Nunes dos Santos at 2016-07-27T08:58:19-03:00
considering timezone in api time filters

- - - - -


3 changed files:

- app/api/helpers.rb
- test/api/activities_test.rb
- test/api/task_test.rb


Changes:

=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -248,7 +248,7 @@ module Api
     def make_timestamp_with_parameters_and_method(object, method_or_relation, params)
       timestamp = nil
       if params[:timestamp]
-        datetime = DateTime.parse(params[:timestamp])
+        datetime = DateTime.parse(params[:timestamp]).utc
         table_name = extract_associated_tablename(object, method_or_relation)
         assoc_class = extract_associated_classname(object, method_or_relation)
         date_atrr = assoc_class.attribute_names.include?('updated_at') ? 'updated_at' : 'created_at'


=====================================
test/api/activities_test.rb
=====================================
--- a/test/api/activities_test.rb
+++ b/test/api/activities_test.rb
@@ -182,7 +182,24 @@ class ActivitiesTest < ActiveSupport::TestCase
     assert_not_includes json["activities"].map { |a| a["id"] }, a2.id
   end
 
+  should 'list activities with timestamp considering timezone' do
+    ActionTracker::Record.destroy_all
+    a1 = create_activity(:target => person)
+    a2 = create_activity(:target => person)
+    a2.updated_at = ActiveSupport::TimeZone.new('Brasilia').now
+    a2.save
+
+    a1.updated_at = ActiveSupport::TimeZone.new('Brasilia').now + 3.hours
+    a1.save!
+
 
+    params[:timestamp] = ActiveSupport::TimeZone.new('Brasilia').now + 1.hours
+    get "/api/v1/profiles/#{person.id}/activities?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+
+    assert_includes json["activities"].map { |a| a["id"] }, a1.id
+    assert_not_includes json["activities"].map { |a| a["id"] }, a2.id
+  end
 
   def create_activity(params = {})
     params[:verb] ||= 'create_article'


=====================================
test/api/task_test.rb
=====================================
--- a/test/api/task_test.rb
+++ b/test/api/task_test.rb
@@ -157,6 +157,22 @@ class TasksTest < ActiveSupport::TestCase
     assert_not_includes json["tasks"].map { |a| a["id"] }, t2.id
   end
 
+  should 'list tasks with timestamp considering timezone' do
+    t1 = create(Task, :requestor => person, :target => person)
+    t2 = create(Task, :requestor => person, :target => person, :created_at => ActiveSupport::TimeZone.new('Brasilia').now)
+
+    t1.created_at = ActiveSupport::TimeZone.new('Brasilia').now + 3.hours
+    t1.save!
+
+
+    params[:timestamp] = ActiveSupport::TimeZone.new('Brasilia').now + 1.hours
+    get "/api/v1/tasks/?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+
+    assert_includes json["tasks"].map { |a| a["id"] }, t1.id
+    assert_not_includes json["tasks"].map { |a| a["id"] }, t2.id
+  end
+
   task_actions=%w[finish cancel]
   task_actions_state={"finish"=>"FINISHED","cancel"=>"CANCELLED"}
   task_actions.each do |action|



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/8b7475adc83779f0a44318ea37c34ae6b16cd033
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160727/dbc9af5b/attachment-0001.html>


More information about the Noosfero-dev mailing list