Commit 73dc8efa9fc6be1b75af534ec91947f012bd9b8c

Authored by Caio Almeida
1 parent e6f99d39
Exists in fix_sign_up_form

Ticket #116: Expose event information in API

plugins/recent_activities/lib/ext/entities.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require_dependency 'api/entities'
  2 +
  3 +module Api
  4 + module Entities
  5 + class Activity
  6 + expose :label
  7 + expose :start_date do |activity|
  8 + activity.target.start_date if activity.target.is_a?(Event)
  9 + end
  10 + end
  11 + end
  12 +end
... ...
plugins/recent_activities/test/unit/recent_activities_block_test.rb
... ... @@ -68,6 +68,31 @@ class RecentActivitiesBlockViewTest < ActionView::TestCase
68 68 block = RecentActivitiesPlugin::ActivitiesBlock.new
69 69 block.stubs(:owner).returns(profile)
70 70  
  71 + api_activity = block.api_content['activities'].last
71 72 assert_equal [a.id], block.api_content['activities'].map{ |a| a[:id] }
  73 + assert_not_nil api_activity[:label]
  74 + assert_nil api_activity[:start_date]
  75 + end
  76 +
  77 + should 'return event information in api_content' do
  78 + person = fast_create(Person)
  79 + event = build(Event, { name: 'Event', start_date: DateTime.new(2020, 1, 1) })
  80 + event.profile = person
  81 + event.save!
  82 + activity = create_activity(person, event)
  83 +
  84 + block = RecentActivitiesPlugin::ActivitiesBlock.new
  85 + block.stubs(:owner).returns(person)
  86 +
  87 + api_activity = block.api_content['activities'].last
  88 + assert_not_nil api_activity[:start_date]
  89 + end
  90 +
  91 + protected
  92 +
  93 + def create_activity(person, target)
  94 + activity = ActionTracker::Record.create! verb: :leave_scrap, user: person, target: target
  95 + ProfileActivity.create! profile_id: target.id, activity: activity
  96 + activity.reload
72 97 end
73 98 end
... ...