Skip to content

Commit

Permalink
badget is passing only when warnings_count is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Jun 25, 2012
1 parent 69b5999 commit 095ccbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/models/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class Build < ActiveRecord::Base
include AASM
BADGE_STATES = {completed: "passing", failed: "failing", scheduled: "unknown", running: "unknown"}

belongs_to :repository, counter_cache: true
attr_accessible :branch, :duration, :finished_at, :last_commit_id, :last_commit_message, :position
Expand Down Expand Up @@ -86,7 +85,11 @@ def short_commit_id
end

def badge_state
BADGE_STATES[aasm_state.to_sym]
if "completed" == aasm_state
warnings_count > 0 ? "failing" : "passing"
else
"unknown"
end
end

protected
Expand Down
7 changes: 5 additions & 2 deletions spec/models/build_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@

context "#badge_status" do
it "should be passing" do
build = FactoryGirl.build_stubbed(:build, aasm_state: "completed")
build = FactoryGirl.build_stubbed(:build, aasm_state: "completed", warnings_count: 0)
build.badge_state.should == "passing"
end

it "should be failing" do
build = FactoryGirl.build_stubbed(:build, aasm_state: "failed")
build = FactoryGirl.build_stubbed(:build, aasm_state: "completed", warnings_count: 1)
build.badge_state.should == "failing"
end

it "should be unknown" do
build = FactoryGirl.build_stubbed(:build, aasm_state: "failed")
build.badge_state.should == "unknown"

build = FactoryGirl.build_stubbed(:build, aasm_state: "scheduled")
build.badge_state.should == "unknown"

Expand Down

0 comments on commit 095ccbf

Please sign in to comment.