scinote-web/spec/services/repositories/archive_repository_service_spec.rb

53 lines
1.5 KiB
Ruby
Raw Normal View History

2020-06-23 04:45:34 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe Repositories::ArchiveRepositoryService do
let(:user) { create :user }
let(:team) { create :team }
let(:repository) { create :repository, team: team }
let!(:row_1) { create :repository_row, repository: repository }
let!(:row_2) { create :repository_row, repository: repository }
let!(:row_3) { create :repository_row, repository: repository }
let(:repositories) { [repository] }
let(:service_call) do
Repositories::ArchiveRepositoryService.call(repositories: repositories, user: user, team: team)
end
context 'when have valid inventory' do
2020-06-23 04:45:34 +08:00
it 'updates repository archived_by, archived_on, archived' do
expect { service_call }
.to(change { repository.reload.archived_on }
.and(change { repository.archived_by })
.and(change { repository.archived }))
end
it 'creates 1 activity' do
expect { service_call }.to change { Activity.count }.by(1)
end
end
context 'when have invalid repository' do
2020-06-23 04:45:34 +08:00
let(:second_repository) do
r = create :repository, team: team
r.name = ''
r.save(validate: false)
r
end
let(:repositories) { [repository, second_repository] }
it 'does not change repository archived' do
expect { service_call }.not_to(change { repository.reload.archived_on })
end
it 'does not create activity' do
expect { service_call }.not_to(change { Activity.count })
end
it 'returns error' do
expect(service_call.errors).to have_key(:archiving_error)
end
end
end