diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-02-20 13:41:50 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-02-20 13:41:50 +0100 |
commit | 444d71e043eb19979ec1b08504b2760910cb2a47 (patch) | |
tree | eae73ba8a12de1a84faee800fae9749b70ed1b78 /spec | |
parent | 549fc3469790da388035de713294f335fbfb4fb5 (diff) | |
download | gitlab-ce-444d71e043eb19979ec1b08504b2760910cb2a47.tar.gz |
Transactional mattermost team creation
Before this commit, but still on this feature branch, the creation of
mattermost teams where a background job. However, it was decided it was
better that these happened as transaction so feedback could be displayed
to the user.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/groups/create_service_spec.rb | 11 | ||||
-rw-r--r-- | spec/workers/mattermost/create_team_worker_spec.rb | 36 |
2 files changed, 9 insertions, 38 deletions
diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb index 235fa5c5188..d8181f73110 100644 --- a/spec/services/groups/create_service_spec.rb +++ b/spec/services/groups/create_service_spec.rb @@ -43,10 +43,17 @@ describe Groups::CreateService, '#execute', services: true do let!(:params) { group_params.merge(create_chat_team: true) } let!(:service) { described_class.new(user, params) } - it 'queues a background job' do - expect(Mattermost::CreateTeamWorker).to receive(:perform_async) + it 'triggers the service' do + expect_any_instance_of(Mattermost::CreateTeamService).to receive(:execute) subject end + + it 'create the chat team with the group' do + allow_any_instance_of(Mattermost::Team).to receive(:create) + .and_return({ 'name' => 'tanuki', 'id' => 'lskdjfwlekfjsdifjj' }) + + expect { subject }.to change { ChatTeam.count }.from(0).to(1) + end end end diff --git a/spec/workers/mattermost/create_team_worker_spec.rb b/spec/workers/mattermost/create_team_worker_spec.rb deleted file mode 100644 index d3230f535c2..00000000000 --- a/spec/workers/mattermost/create_team_worker_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' - -describe Mattermost::CreateTeamWorker do - let(:group) { create(:group, path: 'path', name: 'name') } - let(:admin) { create(:admin) } - - describe '.perform' do - subject { described_class.new.perform(group.id, admin.id) } - - context 'succesfull request to mattermost' do - before do - allow_any_instance_of(Mattermost::Team). - to receive(:create). - with(group, {}). - and_return('name' => 'my team', 'id' => 'sjfkdlwkdjfwlkfjwf') - end - - it 'creates a new chat team' do - expect { subject }.to change { ChatTeam.count }.from(0).to(1) - end - end - - context 'connection trouble' do - before do - allow_any_instance_of(Mattermost::Team). - to receive(:create). - with(group, {}). - and_raise(Mattermost::ClientError.new('Undefined error')) - end - - it 'does not rescue the error' do - expect { subject }.to raise_error(Mattermost::ClientError) - end - end - end -end |