add tests for next build time
This commit is contained in:
parent
3f11b08a25
commit
2566a7761c
159
spec/v3/models/cron_spec.rb
Normal file
159
spec/v3/models/cron_spec.rb
Normal file
|
@ -0,0 +1,159 @@
|
|||
require 'spec_helper'
|
||||
require 'timecop'
|
||||
|
||||
describe Travis::API::V3::Models::Cron do
|
||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
||||
let(:branch) { Travis::API::V3::Models::Branch.create(repository: repo, name: 'cron test') }
|
||||
|
||||
describe "next build time is calculated correctly on year changes" do
|
||||
|
||||
before do
|
||||
Timecop.travel(DateTime.new(2015, 12, 31, 16))
|
||||
end
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
|
||||
it "for daily builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: false)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 1, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for weekly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: false)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 7, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for monthly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: false)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 31, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "push build is ignored if disable by build is false" do
|
||||
|
||||
before do
|
||||
Timecop.travel(DateTime.new(2015, 12, 31, 16))
|
||||
end
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
|
||||
it "for daily builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: false)
|
||||
cron_build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
push_build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'push')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 1, 16)
|
||||
cron_build.destroy
|
||||
push_build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for weekly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: false)
|
||||
cron_build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
push_build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'push')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 7, 16)
|
||||
cron_build.destroy
|
||||
push_build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for monthly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: false)
|
||||
cron_build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
push_build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'push')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 31, 16)
|
||||
cron_build.destroy
|
||||
push_build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "disable by build works with build" do
|
||||
|
||||
before do
|
||||
Timecop.travel(DateTime.new(2015, 12, 31, 16))
|
||||
end
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
|
||||
it "for daily builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: true)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'push')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 2, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for weekly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: true)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'push')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 14, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for monthly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: true)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'push')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 2, 29, 16) # it's a leap year :-D
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "disable by build works without build" do
|
||||
|
||||
before do
|
||||
Timecop.travel(DateTime.new(2015, 12, 31, 16))
|
||||
end
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
|
||||
it "for daily builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: true)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 1, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for weekly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: true)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 7, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
it "for monthly builds" do
|
||||
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: true)
|
||||
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
|
||||
expect(cron.next_build_time).to be == DateTime.new(2016, 1, 31, 16)
|
||||
build.destroy
|
||||
cron.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user