Commit 39a9fe28 authored by peterhegman's avatar peterhegman

Move specs for private methods into specs for public methods

Per reviewer feedback
parent 443fb94f
......@@ -23,76 +23,59 @@ RSpec.describe Groups::GroupMembersHelper do
end
end
describe '#group_group_links_serialized' do
include_context 'group_group_link'
describe '#group_members_list_data_json' do
let(:group_members) { create_list(:group_member, 2, group: group, created_by: current_user) }
it 'matches json schema' do
json = helper.send(:group_group_links_serialized, shared_group.shared_with_group_links).to_json
let(:pagination) { {} }
let(:collection) { group_members }
let(:presented_members) { present_members(collection) }
expect(json).to match_schema('group_link/group_group_links')
end
end
subject { Gitlab::Json.parse(helper.group_members_list_data_json(group, presented_members, pagination)) }
describe '#group_members_serialized' do
shared_examples 'members.json' do
it 'matches json schema' do
json = helper.send(:group_members_serialized, group, present_members([group_member])).to_json
expect(json).to match_schema('members')
it 'returns `members` property that matches json schema' do
expect(subject['members'].to_json).to match_schema('members')
end
end
context 'for a group member' do
let(:group_member) { create(:group_member, group: group, created_by: current_user) }
before do
allow(helper).to receive(:group_group_member_path).with(group, ':id').and_return('/groups/foo-bar/-/group_members/:id')
allow(helper).to receive(:can?).with(current_user, :admin_group_member, group).and_return(true)
end
it 'returns expected json' do
expected = {
member_path: '/groups/foo-bar/-/group_members/:id',
source_id: group.id,
can_manage_members: true
}.as_json
expect(subject).to include(expected)
end
context 'for a group member' do
it_behaves_like 'members.json'
context 'with user status set' do
let(:user) { create(:user) }
let!(:status) { create(:user_status, user: user) }
let(:group_member) { create(:group_member, group: group, user: user, created_by: current_user) }
let(:group_members) { [create(:group_member, group: group, user: user, created_by: current_user)] }
it_behaves_like 'members.json'
end
end
context 'for an invited group member' do
let(:group_member) { create(:group_member, :invited, group: group, created_by: current_user) }
let(:group_members) { create_list(:group_member, 2, :invited, group: group, created_by: current_user) }
it_behaves_like 'members.json'
end
context 'for an access request' do
let(:group_member) { create(:group_member, :access_request, group: group, created_by: current_user) }
let(:group_members) { create_list(:group_member, 2, :access_request, group: group, created_by: current_user) }
it_behaves_like 'members.json'
end
end
describe '#group_members_list_data_json' do
let_it_be(:group_members) { create_list(:group_member, 2, group: group, created_by: current_user) }
let(:pagination) { {} }
let(:collection) { group_members }
let(:presented_members) { present_members(collection) }
subject { Gitlab::Json.parse(helper.group_members_list_data_json(group, presented_members, pagination)) }
before do
allow(helper).to receive(:group_group_member_path).with(group, ':id').and_return('/groups/foo-bar/-/group_members/:id')
allow(helper).to receive(:can?).with(current_user, :admin_group_member, group).and_return(true)
end
it 'returns expected json' do
expected = {
members: helper.send(:group_members_serialized, group, presented_members),
member_path: '/groups/foo-bar/-/group_members/:id',
source_id: group.id,
can_manage_members: true
}.as_json
expect(subject).to include(expected)
end
context 'when pagination is not available' do
it 'sets `pagination` attribute to expected json' do
......@@ -144,12 +127,15 @@ RSpec.describe Groups::GroupMembersHelper do
param_name: nil,
params: {}
},
members: helper.send(:group_group_links_serialized, shared_group.shared_with_group_links),
member_path: '/groups/foo-bar/-/group_links/:id',
source_id: shared_group.id
}.as_json
expect(subject).to include(expected)
end
it 'returns `members` property that matches json schema' do
expect(subject['members'].to_json).to match_schema('group_link/group_group_links')
end
end
end
......@@ -152,12 +152,6 @@ RSpec.describe Projects::ProjectMembersHelper do
let(:collection) { project_members }
let(:presented_members) { present_members(collection) }
describe '#project_members_serialized' do
it 'matches json schema' do
expect(helper.send(:project_members_serialized, project, presented_members).to_json).to match_schema('members')
end
end
describe '#project_members_list_data_json' do
let(:allow_admin_project) { true }
let(:pagination) { {} }
......@@ -170,7 +164,6 @@ RSpec.describe Projects::ProjectMembersHelper do
it 'returns expected json' do
expected = {
members: helper.send(:project_members_serialized, project, presented_members),
member_path: '/foo-bar/-/project_members/:id',
source_id: project.id,
can_manage_members: true
......@@ -179,6 +172,10 @@ RSpec.describe Projects::ProjectMembersHelper do
expect(subject).to include(expected)
end
it 'returns `members` property that matches json schema' do
expect(subject['members'].to_json).to match_schema('members')
end
context 'when pagination is not available' do
it 'sets `pagination` attribute to expected json' do
expected = {
......@@ -217,12 +214,6 @@ RSpec.describe Projects::ProjectMembersHelper do
let(:allow_admin_project) { true }
describe '#project_group_links_data_json' do
it 'matches json schema' do
expect(helper.send(:project_group_links_serialized, project_group_links).to_json).to match_schema('group_link/project_group_links')
end
end
describe '#project_group_links_list_data_json' do
subject { Gitlab::Json.parse(helper.project_group_links_list_data_json(project, project_group_links)) }
......@@ -233,7 +224,6 @@ RSpec.describe Projects::ProjectMembersHelper do
it 'returns expected json' do
expected = {
members: helper.send(:project_group_links_serialized, project_group_links),
pagination: {
current_page: nil,
per_page: nil,
......@@ -248,6 +238,10 @@ RSpec.describe Projects::ProjectMembersHelper do
expect(subject).to include(expected)
end
it 'returns `members` property that matches json schema' do
expect(subject['members'].to_json).to match_schema('group_link/project_group_links')
end
end
end
end
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