diff --git a/plugins/person_tags/lib/person_tags_plugin.rb b/plugins/person_tags/lib/person_tags_plugin.rb index e39cc39..4ee0858 100644 --- a/plugins/person_tags/lib/person_tags_plugin.rb +++ b/plugins/person_tags/lib/person_tags_plugin.rb @@ -15,4 +15,8 @@ class PersonTagsPlugin < Noosfero::Plugin def profile_editor_extras expanded_template('profile-editor-extras.html.erb').html_safe end + + def self.api_mount_points + [PersonTagsPlugin::API] + end end diff --git a/plugins/person_tags/lib/person_tags_plugin/api.rb b/plugins/person_tags/lib/person_tags_plugin/api.rb new file mode 100644 index 0000000..0fb53cf --- /dev/null +++ b/plugins/person_tags/lib/person_tags_plugin/api.rb @@ -0,0 +1,9 @@ +class PersonTagsPlugin::API < Grape::API + resource :people do + get ':id/tags' do + person = environment.people.visible.find_by(id: params[:id]) + return not_found! if person.blank? + present person.interest_list + end + end +end diff --git a/plugins/person_tags/test/unit/api_test.rb b/plugins/person_tags/test/unit/api_test.rb new file mode 100644 index 0000000..90400cf --- /dev/null +++ b/plugins/person_tags/test/unit/api_test.rb @@ -0,0 +1,27 @@ +require_relative '../test_helper' +require_relative '../../../../test/api/test_helper' + +class APITest < ActiveSupport::TestCase + + def setup + create_and_activate_user + environment.enable_plugin(PersonTagsPlugin) + end + + should 'return tags for a person' do + person = create_user('person').person + person.interest_list.add('linux') + person.save! + person.reload + get "/api/v1/people/#{person.id}/tags?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal ['linux'], json + end + + should 'return empty list if person has no tags' do + person = create_user('person').person + get "/api/v1/people/#{person.id}/tags?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal [], json + end +end -- libgit2 0.21.2