Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Commit

Permalink
Keep a job has only 1 build
Browse files Browse the repository at this point in the history
Close #4.
  • Loading branch information
r7kamura committed Jul 9, 2013
1 parent cd50e4c commit 4637586
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/build.rb
Expand Up @@ -19,6 +19,8 @@ class Build < ActiveRecord::Base

after_create { update_incremental_id }

validate :one_job_cannot_have_more_than_two_builds, on: :create

paginates_per 10

def self.latest
Expand Down Expand Up @@ -75,4 +77,10 @@ def finish(result)
def update_incremental_id
update_attributes(incremental_id: job.builds_count)
end

def one_job_cannot_have_more_than_two_builds
if job.builds.unfinished.any?
errors.add(:id, "One job cannot have more than two builds")
end
end
end

0 comments on commit 4637586

Please sign in to comment.