Commit 7f6cc03b0e984d33b3481332941c1d5de7bed318
1 parent
eecc8ff3
Exists in
master
Add timestamp suport for profiles
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
2 changed files
with
48 additions
and
2 deletions
Show diff stats
controllers/colab_integration_plugin_controller.rb
| 1 | 1 | class ColabIntegrationPluginController < ApplicationController |
| 2 | 2 | def index |
| 3 | + timestamp = get_timestamp params[:timestamp] | |
| 4 | + | |
| 5 | + profiles = if timestamp | |
| 6 | + environment.profiles.where("updated_at > ?", timestamp) | |
| 7 | + else | |
| 8 | + environment.profiles | |
| 9 | + end | |
| 10 | + | |
| 3 | 11 | data = { |
| 4 | - "total" => environment.profiles.count, | |
| 12 | + "timestamp" => Time.zone.now.to_s, | |
| 13 | + "total" => profiles.count, | |
| 5 | 14 | "profiles" => [] |
| 6 | 15 | } |
| 7 | 16 | |
| 8 | - environment.profiles.each do |profile| | |
| 17 | + profiles.each do |profile| | |
| 9 | 18 | data["profiles"] << profile.attr_to_hash |
| 10 | 19 | end |
| 11 | 20 | |
| ... | ... | @@ -13,4 +22,14 @@ class ColabIntegrationPluginController < ApplicationController |
| 13 | 22 | |
| 14 | 23 | data.to_json |
| 15 | 24 | end |
| 25 | + | |
| 26 | + private | |
| 27 | + | |
| 28 | + def get_timestamp timestamp | |
| 29 | + begin | |
| 30 | + Time.parse timestamp | |
| 31 | + rescue | |
| 32 | + nil | |
| 33 | + end | |
| 34 | + end | |
| 16 | 35 | end | ... | ... |
test/functional/colab_integration_plugin_controller_test.rb
| ... | ... | @@ -43,6 +43,33 @@ class ColabIntegrationPluginControllerTest < ActionController::TestCase |
| 43 | 43 | person["articles-count"] > 0 |
| 44 | 44 | } |
| 45 | 45 | assert_equal persons_with_article.count, 1 |
| 46 | + assert_nothing_raised do | |
| 47 | + Time.parse environment_data["timestamp"] | |
| 48 | + end | |
| 49 | + end | |
| 50 | + | |
| 51 | + should "return a json with only the last updated profiles" do | |
| 52 | + time = Time.at 0 | |
| 53 | + | |
| 54 | + Profile.destroy_all | |
| 55 | + | |
| 56 | + kingsland = Community.create!(:name => "Kings Land", :identifier => "kings-land") | |
| 57 | + winterfell = Community.create!(:name => "Winterfell", :identifier => "winterfell") | |
| 58 | + | |
| 59 | + get :index, :timestamp => time.to_s | |
| 60 | + | |
| 61 | + environment_data = JSON.parse(@response.body) | |
| 62 | + | |
| 63 | + assert_equal environment_data["total"], 2 | |
| 64 | + | |
| 65 | + winterfell.updated_at = time | |
| 66 | + winterfell.save! | |
| 67 | + | |
| 68 | + get :index, :timestamp => time.to_s | |
| 69 | + | |
| 70 | + environment_data = JSON.parse(@response.body) | |
| 71 | + | |
| 72 | + assert_equal environment_data["total"], 1 | |
| 46 | 73 | end |
| 47 | 74 | |
| 48 | 75 | should "return a hash with activities of the user" do | ... | ... |