|
|
|
@ -34,11 +34,11 @@ describe TimeEntries::SetAttributesService, type: :model do |
|
|
|
|
let!(:default_activity) { build_stubbed(:time_entry_activity, project:, is_default: true) } |
|
|
|
|
let(:work_package) { build_stubbed(:work_package) } |
|
|
|
|
let(:project) { build_stubbed(:project) } |
|
|
|
|
let(:spent_on) { Date.today.to_s } |
|
|
|
|
let(:spent_on) { Time.zone.today.to_s } |
|
|
|
|
let(:hours) { 5.0 } |
|
|
|
|
let(:comments) { 'some comment' } |
|
|
|
|
let(:contract_instance) do |
|
|
|
|
contract = double('contract_instance') |
|
|
|
|
contract = double('contract_instance') # rubocop:disable RSpec/VerifiedDoubles |
|
|
|
|
allow(contract) |
|
|
|
|
.to receive(:validate) |
|
|
|
|
.and_return(contract_valid) |
|
|
|
@ -48,7 +48,7 @@ describe TimeEntries::SetAttributesService, type: :model do |
|
|
|
|
contract |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
let(:contract_errors) { double('contract_errors') } |
|
|
|
|
let(:contract_errors) { double('contract_errors') } # rubocop:disable RSpec/VerifiedDoubles |
|
|
|
|
let(:contract_valid) { true } |
|
|
|
|
let(:time_entry_valid) { true } |
|
|
|
|
|
|
|
|
@ -178,11 +178,29 @@ describe TimeEntries::SetAttributesService, type: :model do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with another user setting logged by' do |
|
|
|
|
let(:other_user) { create :user } |
|
|
|
|
let(:time_entry_instance) { create :time_entry, user: other_user, logged_by: other_user, hours: 1 } |
|
|
|
|
|
|
|
|
|
let(:params) do |
|
|
|
|
{ |
|
|
|
|
hours: 1234 |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'updates the entry, and updates the logged by' do |
|
|
|
|
expect { subject } |
|
|
|
|
.to change(time_entry_instance, :hours).from(1).to(1234) |
|
|
|
|
.and change(time_entry_instance, :logged_by).from(other_user).to(user) |
|
|
|
|
|
|
|
|
|
expect(time_entry_instance.user).to eq other_user |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with an invalid contract' do |
|
|
|
|
let(:contract_valid) { false } |
|
|
|
|
let(:expect_time_instance_save) do |
|
|
|
|
expect(time_entry_instance) |
|
|
|
|
.not_to receive(:save) |
|
|
|
|
expect(time_entry_instance).not_to receive(:save) # rubocop:disable RSpec/MessageSpies |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'returns failure' do |
|
|
|
|