[Git][noosfero/noosfero][master] 4 commits: Ticket #85: Adding plugin that allows people to have tags (aka interests) - API pending
Daniela Feitosa
gitlab at mg.gitlab.com
Wed Jun 8 10:25:06 BRT 2016
Daniela Feitosa pushed to branch master at Noosfero / noosfero
Commits:
a766ba55 by Caio SBA at 2016-05-30T12:20:26-03:00
Ticket #85: Adding plugin that allows people to have tags (aka interests) - API pending
- - - - -
cdd1f702 by Caio SBA at 2016-06-06T13:40:58-03:00
Ticket #85: Adding API endpoint to retrieve tags from a person
- - - - -
785b56ad by Caio SBA at 2016-06-06T13:46:58-03:00
Merge branch 'master' into field-of-interest
- - - - -
a1afc163 by Daniela Feitosa at 2016-06-08T13:24:49+00:00
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
- - - - -
8 changed files:
- + plugins/person_tags/features/person_tags.feature
- + plugins/person_tags/lib/ext/person.rb
- + plugins/person_tags/lib/person_tags_plugin.rb
- + plugins/person_tags/lib/person_tags_plugin/api.rb
- + plugins/person_tags/test/test_helper.rb
- + plugins/person_tags/test/unit/api_test.rb
- + plugins/person_tags/test/unit/person_tags_test.rb
- + plugins/person_tags/views/profile-editor-extras.html.erb
Changes:
=====================================
plugins/person_tags/features/person_tags.feature
=====================================
--- /dev/null
+++ b/plugins/person_tags/features/person_tags.feature
@@ -0,0 +1,18 @@
+Feature: person tags
+
+Background:
+ Given the following users
+ | login |
+ | joao |
+ And I am logged in as "joao"
+ And "PersonTags" plugin is enabled
+
+Scenario: add tags to person
+ Given I am on joao's control panel
+ And I follow "Edit Profile"
+ When I fill in "profile_data_interest_list" with "linux,debian"
+ And I press "Save"
+ And I go to joao's control panel
+ And I follow "Edit Profile"
+ Then the "profile_data_interest_list" field should contain "linux"
+ And the "profile_data_interest_list" field should contain "debian"
=====================================
plugins/person_tags/lib/ext/person.rb
=====================================
--- /dev/null
+++ b/plugins/person_tags/lib/ext/person.rb
@@ -0,0 +1,8 @@
+require_dependency 'person'
+
+class Person
+ attr_accessible :interest_list
+
+ acts_as_taggable_on :interests
+ N_('Fields of interest')
+end
=====================================
plugins/person_tags/lib/person_tags_plugin.rb
=====================================
--- /dev/null
+++ b/plugins/person_tags/lib/person_tags_plugin.rb
@@ -0,0 +1,22 @@
+class PersonTagsPlugin < Noosfero::Plugin
+
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::FormTagHelper
+ include FormsHelper
+
+ def self.plugin_name
+ "PersonTagsPlugin"
+ end
+
+ def self.plugin_description
+ _("People can define tags that describe their interests.")
+ end
+
+ def profile_editor_extras
+ expanded_template('profile-editor-extras.html.erb').html_safe
+ end
+
+ def self.api_mount_points
+ [PersonTagsPlugin::API]
+ end
+end
=====================================
plugins/person_tags/lib/person_tags_plugin/api.rb
=====================================
--- /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
=====================================
plugins/person_tags/test/test_helper.rb
=====================================
--- /dev/null
+++ b/plugins/person_tags/test/test_helper.rb
@@ -0,0 +1 @@
+require_relative '../../../test/test_helper'
=====================================
plugins/person_tags/test/unit/api_test.rb
=====================================
--- /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
=====================================
plugins/person_tags/test/unit/person_tags_test.rb
=====================================
--- /dev/null
+++ b/plugins/person_tags/test/unit/person_tags_test.rb
@@ -0,0 +1,16 @@
+require 'test_helper'
+
+class PersonTagsPluginTest < ActiveSupport::TestCase
+
+ def setup
+ @environment = Environment.default
+ @environment.enable_plugin(PersonTagsPlugin)
+ end
+
+ should 'have interests' do
+ person = create_user('person').person
+ assert_equal [], person.interests
+ person.interest_list.add('linux')
+ assert_equal ['linux'], person.interest_list
+ end
+end
=====================================
plugins/person_tags/views/profile-editor-extras.html.erb
=====================================
--- /dev/null
+++ b/plugins/person_tags/views/profile-editor-extras.html.erb
@@ -0,0 +1,8 @@
+<h2><%= _('Select your fields of interest') %></h2>
+<%= text_field_tag('profile_data[interest_list]', context.profile.interest_list.join(','), size: 64) %>
+<br />
+<%= content_tag( 'small', _('Separate tags with commas') ) %>
+
+<script>
+ jQuery('#profile_data_interest_list').inputosaurus();
+</script>
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c3e667f969fd098a894d3ce7a9d9277bffcc070e...a1afc1637bb164e76c45f8e4aa8f416423e298d0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160608/8988367c/attachment-0001.html>
More information about the Noosfero-dev
mailing list