travis-api/spec/v3/services/cron/for_branch_spec.rb
2016-01-14 16:16:15 +01:00

75 lines
3.0 KiB
Ruby

require 'spec_helper'
describe Travis::API::V3::Services::Cron::ForBranch do
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
let(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch, interval:'daily') }
let(:parsed_body) { JSON.load(body) }
describe "fetching all crons by repo id" do
before { cron }
before { get("/v3/repo/#{repo.id}/branch/#{branch.name}/cron") }
example { expect(last_response).to be_ok }
example { expect(parsed_body).to be == {
"@type" => "cron",
"@href" => "/v3/cron/#{cron.id}",
"@representation" => "standard",
"@permissions" => {
"read" => true,
"delete" => false },
"id" => cron.id,
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"interval" => "daily",
"disable_by_build" => true,
"next_build_time" => cron.next_build_time.strftime('%Y-%m-%dT%H:%M:%SZ')
}}
end
describe "fetching crons on a non-existing repository by slug" do
before { get("/v3/repo/svenfuchs%2Fminimal1/branch/master/cron") }
example { expect(last_response).to be_not_found }
example { expect(parsed_body).to be == {
"@type" => "error",
"error_type" => "not_found",
"error_message" => "repository not found (or insufficient access)",
"resource_type" => "repository"
}}
end
describe "fetching crons on a non-existing branch" do
before { get("/v3/repo/#{repo.id}/branch/hopefullyNonExistingBranch/cron") }
example { expect(last_response).to be_not_found }
example { expect(parsed_body).to be == {
"@type" => "error",
"error_type" => "not_found",
"error_message" => "branch not found (or insufficient access)",
"resource_type" => "branch"
}}
end
describe "fetching crons from private repo, not authenticated" do
before { repo.update_attribute(:private, true) }
before { get("/v3/repo/#{repo.id}/branch/#{branch.name}/cron") }
after { repo.update_attribute(:private, false) }
example { expect(last_response).to be_not_found }
example { expect(parsed_body).to be == {
"@type" => "error",
"error_type" => "not_found",
"error_message" => "repository not found (or insufficient access)",
"resource_type" => "repository"
}}
end
end