diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-13 18:16:30 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 23:49:41 +0300 |
commit | 3a4dc55f2924debcdbb37eb63d8ce57b1358df81 (patch) | |
tree | 614d82e8b26b5c2698c564d9e244a86c35d714fe /spec/controllers/concerns/group_tree_spec.rb | |
parent | 39df53ff0aeac24d390eea52a1df6dfe103a4c14 (diff) |
Reuse the groups tree for explore and dashboard.
Diffstat (limited to 'spec/controllers/concerns/group_tree_spec.rb')
-rw-r--r-- | spec/controllers/concerns/group_tree_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/controllers/concerns/group_tree_spec.rb b/spec/controllers/concerns/group_tree_spec.rb new file mode 100644 index 00000000000..19387f2d271 --- /dev/null +++ b/spec/controllers/concerns/group_tree_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe GroupTree do + let(:group) { create(:group, :public) } + let(:user) { create(:user) } + + controller(ApplicationController) do + include GroupTree # rubocop:disable Rspec/DescribedClass + + def index + render_group_tree Group.all + end + end + + before do + group.add_owner(user) + sign_in(user) + end + + describe 'GET #index' do + it 'filters groups' do + other_group = create(:group, name: 'filter') + other_group.add_owner(user) + + get :index, filter: 'filt', format: :json + + expect(assigns(:groups)).to contain_exactly(other_group) + end + + context 'for subgroups', :nested_groups do + it 'only renders root groups when no parent was given' do + create(:group, :public, parent: group) + + get :index, format: :json + + expect(assigns(:groups)).to contain_exactly(group) + end + + it 'contains only the subgroup when a parent was given' do + subgroup = create(:group, :public, parent: group) + + get :index, parent_id: group.id, format: :json + + expect(assigns(:groups)).to contain_exactly(subgroup) + end + end + + context 'json content' do + it 'shows groups as json' do + get :index, format: :json + + expect(json_response.first['id']).to eq(group.id) + end + end + end +end |