Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created March 29, 2011 20:18
Show Gist options
  • Save pragdave/893154 to your computer and use it in GitHub Desktop.
Save pragdave/893154 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class BuildStatusTest < ActiveSupport::TestCase
context "expiring build statii" do
should "remove the old one" do
assert_equal 2, BuildStatus.count
BuildStatus.expire_old
statii = BuildStatus.all
assert_equal 1, statii.size
assert statii[0].updated_at >= 30.days.ago
end
end
context "an existing build status" do
setup do
@build_status = BuildStatus.for(skus(:rails_pdf))
end
should "be returned by BuildStatus.for" do
assert_equal build_statuses(:rails_status), @build_status
end
end
context "a new build status" do
setup do
@build_status = BuildStatus.for(skus(:ruby_pdf))
@build_status.status = 'started'
assert @build_status.valid?, @build_status.errors.full_messages.to_sentence
end
should "be a new record" do
assert @build_status.new_record?
end
should "not accept an invalid status" do
@build_status.status = "wtfhax"
assert !@build_status.valid?
end
BuildStatus::STATUSES.each do |status|
context "with the #{status.inspect} status" do
setup do
@build_status.status = status
end
should "be valid?" do
assert @build_status.valid?
end
should "say succeeded only when it has" do
assert_equal status == 'succeeded', @build_status.succeeded?
end
should "say failed only when it has" do
assert_equal status == 'failed', @build_status.failed?
end
should "say in_progress only when it hasn't finished" do
assert_equal status != 'failed' && status != 'succeeded', @build_status.in_progress?
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment