diff --git a/lib/api/v1/communities.rb b/lib/api/v1/communities.rb index 707c6af..aa7d503 100644 --- a/lib/api/v1/communities.rb +++ b/lib/api/v1/communities.rb @@ -16,11 +16,6 @@ module API # GET /communities?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10 # GET /communities?reference_id=10&limit=10&oldest get do - communities = select_filtered_collection_of(current_person, 'communities', params) - present communities, :with => Entities::Community - end - - get '/all' do communities = select_filtered_collection_of(environment, 'communities', params) communities = communities.visible present communities, :with => Entities::Community @@ -33,6 +28,27 @@ module API end + resource :people do + segment '/:person_id' do + resource :communities do + get do + person = environment.people.find(params[:person_id]) + communities = select_filtered_collection_of(person, 'communities', params) + communities = communities.visible + present communities, :with => Entities::Community + end + +# get ':id' do +# person = environment.people.find(params[:person_id]) +# article = find_article(person.articles, params[:id]) +# present article, :with => Entities::Article +# end + + end + end + + end + end end end diff --git a/test/unit/api/communities_test.rb b/test/unit/api/communities_test.rb index d080032..f512d59 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -6,21 +6,10 @@ class CommunitiesTest < ActiveSupport::TestCase login_api end - should 'list user communities' do - community1 = fast_create(Community) - fast_create(Community) - community1.add_member(user.person) - - get "/api/v1/communities?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equivalent [community1.id], json['communities'].map {|c| c['id']} - end - should 'list all communities' do community1 = fast_create(Community) community2 = fast_create(Community) - - get "/api/v1/communities/all?#{params.to_query}" + get "/api/v1/communities?#{params.to_query}" json = JSON.parse(last_response.body) assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} end @@ -37,7 +26,7 @@ class CommunitiesTest < ActiveSupport::TestCase community1 = fast_create(Community) fast_create(Community, :visible => false) - get "/api/v1/communities/all?#{params.to_query}" + get "/api/v1/communities?#{params.to_query}" json = JSON.parse(last_response.body) assert_equal [community1.id], json['communities'].map {|c| c['id']} end @@ -50,4 +39,13 @@ class CommunitiesTest < ActiveSupport::TestCase assert json['community'].blank? end +# should 'list user communities' do +# community1 = fast_create(Community) +# fast_create(Community) +# community1.add_member(user.person) +# +# get "/api/v1/communities?#{params.to_query}" +# json = JSON.parse(last_response.body) +# assert_equivalent [community1.id], json['communities'].map {|c| c['id']} +# end end -- libgit2 0.21.2