2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-21 08:47:20 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe BuildActionEntity do
|
2017-05-16 07:41:15 -04:00
|
|
|
let(:job) { create(:ci_build, name: 'test_job') }
|
2017-04-12 09:22:32 -04:00
|
|
|
let(:request) { double('request') }
|
2019-09-26 08:06:00 -04:00
|
|
|
let(:user) { create(:user) }
|
2016-12-21 08:47:20 -05:00
|
|
|
|
|
|
|
let(:entity) do
|
2019-09-26 08:06:00 -04:00
|
|
|
described_class.new(job, request: request)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
2016-12-21 08:47:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
2017-05-16 07:41:15 -04:00
|
|
|
it 'contains original job name' do
|
|
|
|
expect(subject[:name]).to eq 'test_job'
|
2016-12-21 08:47:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains path to the action play' do
|
2017-05-16 07:41:15 -04:00
|
|
|
expect(subject[:path]).to include "jobs/#{job.id}/play"
|
2016-12-21 08:47:20 -05:00
|
|
|
end
|
2017-03-17 12:25:17 -04:00
|
|
|
|
|
|
|
it 'contains whether it is playable' do
|
2017-05-16 07:41:15 -04:00
|
|
|
expect(subject[:playable]).to eq job.playable?
|
2017-03-17 12:25:17 -04:00
|
|
|
end
|
2018-10-03 02:09:48 -04:00
|
|
|
|
|
|
|
context 'when job is scheduled' do
|
|
|
|
let(:job) { create(:ci_build, :scheduled) }
|
|
|
|
|
2018-11-02 07:52:34 -04:00
|
|
|
it 'returns scheduled' do
|
|
|
|
expect(subject[:scheduled]).to be_truthy
|
|
|
|
end
|
|
|
|
|
2018-10-03 02:09:48 -04:00
|
|
|
it 'returns scheduled_at' do
|
|
|
|
expect(subject[:scheduled_at]).to eq(job.scheduled_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns unschedule path' do
|
|
|
|
expect(subject[:unschedule_path]).to include "jobs/#{job.id}/unschedule"
|
|
|
|
end
|
|
|
|
end
|
2016-12-21 08:47:20 -05:00
|
|
|
end
|
|
|
|
end
|