Commit a1afc1637bb164e76c45f8e4aa8f416423e298d0

Authored by Daniela Feitosa
2 parents c3e667f9 785b56ad

Merge branch 'field-of-interest' into 'master'

Person can set fields of interest (person_tags plugin)

This merge request adds a `person_tags` plugins that allows people to set fields of interest in form of free tags. This plugin adds a field to the edit profile form and adds an API endpoint to retrieve the tags of a given person. Tests included.

See merge request !956
plugins/person_tags/features/person_tags.feature 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +Feature: person tags
  2 +
  3 +Background:
  4 + Given the following users
  5 + | login |
  6 + | joao |
  7 + And I am logged in as "joao"
  8 + And "PersonTags" plugin is enabled
  9 +
  10 +Scenario: add tags to person
  11 + Given I am on joao's control panel
  12 + And I follow "Edit Profile"
  13 + When I fill in "profile_data_interest_list" with "linux,debian"
  14 + And I press "Save"
  15 + And I go to joao's control panel
  16 + And I follow "Edit Profile"
  17 + Then the "profile_data_interest_list" field should contain "linux"
  18 + And the "profile_data_interest_list" field should contain "debian"
... ...
plugins/person_tags/lib/ext/person.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +require_dependency 'person'
  2 +
  3 +class Person
  4 + attr_accessible :interest_list
  5 +
  6 + acts_as_taggable_on :interests
  7 + N_('Fields of interest')
  8 +end
... ...
plugins/person_tags/lib/person_tags_plugin.rb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +class PersonTagsPlugin < Noosfero::Plugin
  2 +
  3 + include ActionView::Helpers::TagHelper
  4 + include ActionView::Helpers::FormTagHelper
  5 + include FormsHelper
  6 +
  7 + def self.plugin_name
  8 + "PersonTagsPlugin"
  9 + end
  10 +
  11 + def self.plugin_description
  12 + _("People can define tags that describe their interests.")
  13 + end
  14 +
  15 + def profile_editor_extras
  16 + expanded_template('profile-editor-extras.html.erb').html_safe
  17 + end
  18 +
  19 + def self.api_mount_points
  20 + [PersonTagsPlugin::API]
  21 + end
  22 +end
... ...
plugins/person_tags/lib/person_tags_plugin/api.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class PersonTagsPlugin::API < Grape::API
  2 + resource :people do
  3 + get ':id/tags' do
  4 + person = environment.people.visible.find_by(id: params[:id])
  5 + return not_found! if person.blank?
  6 + present person.interest_list
  7 + end
  8 + end
  9 +end
... ...
plugins/person_tags/test/test_helper.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require_relative '../../../test/test_helper'
... ...
plugins/person_tags/test/unit/api_test.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +require_relative '../test_helper'
  2 +require_relative '../../../../test/api/test_helper'
  3 +
  4 +class APITest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + create_and_activate_user
  8 + environment.enable_plugin(PersonTagsPlugin)
  9 + end
  10 +
  11 + should 'return tags for a person' do
  12 + person = create_user('person').person
  13 + person.interest_list.add('linux')
  14 + person.save!
  15 + person.reload
  16 + get "/api/v1/people/#{person.id}/tags?#{params.to_query}"
  17 + json = JSON.parse(last_response.body)
  18 + assert_equal ['linux'], json
  19 + end
  20 +
  21 + should 'return empty list if person has no tags' do
  22 + person = create_user('person').person
  23 + get "/api/v1/people/#{person.id}/tags?#{params.to_query}"
  24 + json = JSON.parse(last_response.body)
  25 + assert_equal [], json
  26 + end
  27 +end
... ...
plugins/person_tags/test/unit/person_tags_test.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +require 'test_helper'
  2 +
  3 +class PersonTagsPluginTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @environment = Environment.default
  7 + @environment.enable_plugin(PersonTagsPlugin)
  8 + end
  9 +
  10 + should 'have interests' do
  11 + person = create_user('person').person
  12 + assert_equal [], person.interests
  13 + person.interest_list.add('linux')
  14 + assert_equal ['linux'], person.interest_list
  15 + end
  16 +end
... ...
plugins/person_tags/views/profile-editor-extras.html.erb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<h2><%= _('Select your fields of interest') %></h2>
  2 +<%= text_field_tag('profile_data[interest_list]', context.profile.interest_list.join(','), size: 64) %>
  3 +<br />
  4 +<%= content_tag( 'small', _('Separate tags with commas') ) %>
  5 +
  6 +<script>
  7 + jQuery('#profile_data_interest_list').inputosaurus();
  8 +</script>
... ...