Commit a1afc1637bb164e76c45f8e4aa8f416423e298d0
Exists in
profile_api_improvements
and in
1 other branch
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
Showing
8 changed files
with
109 additions
and
0 deletions
Show diff stats
... | ... | @@ -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" | ... | ... |
... | ... | @@ -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 | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require_relative '../../../test/test_helper' | ... | ... |
... | ... | @@ -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 | ... | ... |
... | ... | @@ -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> | ... | ... |