BigW Consortium Gitlab

Commit 3e6dd7d8 by Bob Van Landuyt

Use same response-body in groups-dashboard as we do for group-home

parent 960559aa
...@@ -15,7 +15,7 @@ class Dashboard::GroupsController < Dashboard::ApplicationController ...@@ -15,7 +15,7 @@ class Dashboard::GroupsController < Dashboard::ApplicationController
current_user.groups current_user.groups
end end
@groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present? @groups = @groups.search(params[:filter]) if params[:filter].present?
@groups = @groups.includes(:route) @groups = @groups.includes(:route)
@groups = @groups.sort(@sort) @groups = @groups.sort(@sort)
@groups = @groups.page(params[:page]) @groups = @groups.page(params[:page])
...@@ -23,10 +23,9 @@ class Dashboard::GroupsController < Dashboard::ApplicationController ...@@ -23,10 +23,9 @@ class Dashboard::GroupsController < Dashboard::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
render json: GroupSerializer serializer = GroupChildSerializer.new(current_user: current_user)
.new(current_user: @current_user) .with_pagination(request, response)
.with_pagination(request, response) render json: serializer.represent(@groups)
.represent(@groups)
end end
end end
end end
......
...@@ -5,13 +5,14 @@ class GroupChildSerializer < BaseSerializer ...@@ -5,13 +5,14 @@ class GroupChildSerializer < BaseSerializer
entity GroupChildEntity entity GroupChildEntity
def expand_hierarchy(hierarchy_root) def expand_hierarchy(hierarchy_root = nil)
@hierarchy_root = hierarchy_root @hierarchy_root = hierarchy_root
@expand_hierarchy = true
self self
end end
def represent(resource, opts = {}, entity_class = nil) def represent(resource, opts = {}, entity_class = nil)
if hierarchy_root.present? if @expand_hierarchy
represent_hierarchies(resource, opts) represent_hierarchies(resource, opts)
else else
super(resource, opts) super(resource, opts)
......
require 'spec_helper'
describe Dashboard::GroupsController do
let(:group) { create(:group, :public) }
let(:user) { create(:user) }
before do
group.add_owner(user)
sign_in(user)
end
describe 'GET #index' do
it 'shows child groups as json' do
get :index, format: :json
expect(json_response.first['id']).to eq(group.id)
end
it 'filters groups' do
other_group = create(:group, name: 'filter')
other_group.add_owner(user)
get :index, filter: 'filt', format: :json
all_ids = json_response.map { |group_json| group_json['id'] }
expect(all_ids).to contain_exactly(other_group.id)
end
end
end
...@@ -49,6 +49,22 @@ describe GroupChildSerializer do ...@@ -49,6 +49,22 @@ describe GroupChildSerializer do
expect(subgroup1_json[:id]).to eq(subgroup1.id) expect(subgroup1_json[:id]).to eq(subgroup1.id)
expect(subsub_group1_json[:id]).to eq(subsub_group1.id) expect(subsub_group1_json[:id]).to eq(subsub_group1.id)
end end
context 'without a specified parent' do
subject(:serializer) do
described_class.new(current_user: user).expand_hierarchy
end
it 'can render a tree' do
subgroup = create(:group, parent: parent)
json = serializer.represent([subgroup])
parent_json = json.first
expect(parent_json[:id]).to eq(parent.id)
expect(parent_json[:children].first[:id]).to eq(subgroup.id)
end
end
end end
context 'for projects' do context 'for projects' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment