summaryrefslogtreecommitdiff
path: root/spec/models/job_spec.rb
blob: d993139ceb266e77ec1d6d32a9b6ebeaaeea1f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# == Schema Information
#
# Table name: jobs
#
#  id             :integer          not null, primary key
#  project_id     :integer          not null
#  commands       :text
#  active         :boolean          default(TRUE), not null
#  created_at     :datetime
#  updated_at     :datetime
#  name           :string(255)
#  build_branches :boolean          default(TRUE), not null
#  build_tags     :boolean          default(FALSE), not null
#  job_type       :string(255)      default("parallel")
#  refs           :string(255)
#  deleted_at     :datetime
#

require 'spec_helper'

describe Job do
  let(:project) { FactoryGirl.create :project }

  it { should belong_to(:project) }
  it { should have_many(:builds) }

  describe "run_for_ref?" do
    it "allows run for any ref if refs params is empty" do
      job = FactoryGirl.create :job, project: project
      job.run_for_ref?("anything").should be_true
    end

    it "allows run for any ref in refs params" do
      job = FactoryGirl.create :job, project: project, refs: "master, staging, tags/testing*"
      job.run_for_ref?("master").should be_true
      job.run_for_ref?("staging").should be_true
      job.run_for_ref?("testing").should be_false
      job.run_for_ref?("tags/testing").should be_true
      job.run_for_ref?("tags/testing-v0.1.0").should be_true
      job.run_for_ref?("tags/unstable-v0.1.0").should be_false
      job.run_for_ref?("feature/feature-one").should be_false
      job.run_for_ref?("anything").should be_false
    end
  end
end