Commit dfe77cb838dd678ba590e716f724fe1077415221
1 parent
5bed328d
Exists in
ratings_minor_fixes
and in
4 other branches
Ticket #45: Adding an API endpoint to get tags from environment
Showing
2 changed files
with
16 additions
and
0 deletions
Show diff stats
lib/noosfero/api/v1/environments.rb
... | ... | @@ -10,6 +10,11 @@ module Noosfero |
10 | 10 | present environment.signup_person_fields |
11 | 11 | end |
12 | 12 | |
13 | + desc 'Return the tag counts for this environment' | |
14 | + get '/tags' do | |
15 | + present environment.tag_counts | |
16 | + end | |
17 | + | |
13 | 18 | get ':id' do |
14 | 19 | local_environment = nil |
15 | 20 | if (params[:id] == "default") | ... | ... |
test/api/environment_test.rb
... | ... | @@ -68,4 +68,15 @@ class EnvironmentTest < ActiveSupport::TestCase |
68 | 68 | assert_equal context_env.id, json['id'] |
69 | 69 | end |
70 | 70 | |
71 | + should 'return number of tags' do | |
72 | + person = fast_create(Person) | |
73 | + person.articles.create!(:name => 'article 1', :tag_list => 'first-tag') | |
74 | + person.articles.create!(:name => 'article 2', :tag_list => 'first-tag, second-tag') | |
75 | + person.articles.create!(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag') | |
76 | + | |
77 | + get '/api/v1/environment/tags' | |
78 | + json = JSON.parse(last_response.body) | |
79 | + assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, json) | |
80 | + end | |
81 | + | |
71 | 82 | end | ... | ... |