diff --git a/controllers/colab_integration_plugin_controller.rb b/controllers/colab_integration_plugin_controller.rb index 4da18f1..88812bb 100644 --- a/controllers/colab_integration_plugin_controller.rb +++ b/controllers/colab_integration_plugin_controller.rb @@ -1,11 +1,20 @@ class ColabIntegrationPluginController < ApplicationController def index + timestamp = get_timestamp params[:timestamp] + + profiles = if timestamp + environment.profiles.where("updated_at > ?", timestamp) + else + environment.profiles + end + data = { - "total" => environment.profiles.count, + "timestamp" => Time.zone.now.to_s, + "total" => profiles.count, "profiles" => [] } - environment.profiles.each do |profile| + profiles.each do |profile| data["profiles"] << profile.attr_to_hash end @@ -13,4 +22,14 @@ class ColabIntegrationPluginController < ApplicationController data.to_json end + + private + + def get_timestamp timestamp + begin + Time.parse timestamp + rescue + nil + end + end end diff --git a/test/functional/colab_integration_plugin_controller_test.rb b/test/functional/colab_integration_plugin_controller_test.rb index de84113..e07c2d2 100644 --- a/test/functional/colab_integration_plugin_controller_test.rb +++ b/test/functional/colab_integration_plugin_controller_test.rb @@ -43,6 +43,33 @@ class ColabIntegrationPluginControllerTest < ActionController::TestCase person["articles-count"] > 0 } assert_equal persons_with_article.count, 1 + assert_nothing_raised do + Time.parse environment_data["timestamp"] + end + end + + should "return a json with only the last updated profiles" do + time = Time.at 0 + + Profile.destroy_all + + kingsland = Community.create!(:name => "Kings Land", :identifier => "kings-land") + winterfell = Community.create!(:name => "Winterfell", :identifier => "winterfell") + + get :index, :timestamp => time.to_s + + environment_data = JSON.parse(@response.body) + + assert_equal environment_data["total"], 2 + + winterfell.updated_at = time + winterfell.save! + + get :index, :timestamp => time.to_s + + environment_data = JSON.parse(@response.body) + + assert_equal environment_data["total"], 1 end should "return a hash with activities of the user" do -- libgit2 0.21.2