Skip to content

Instantly share code, notes, and snippets.

@dhh
Forked from pragdave/gist:893154
Created March 29, 2011 20:29
Show Gist options
  • Save dhh/893184 to your computer and use it in GitHub Desktop.
Save dhh/893184 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class BuildStatusTest < ActiveSupport::TestCase
test "remove the old statii" 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
test "an existing build status be returned by BuildStatus.for" do
@build_status = BuildStatus.for(skus(:rails_pdf))
assert_equal build_statuses(:rails_status), @build_status
end
# I don't think this test has much value
test "a new build status should be a new record" do
assert new_build_status.new_record?
end
test "a new build status should not accept an invalid status" do
assert !new_build_status("wtfhax").valid?
end
BuildStatus::STATUSES.each do |status|
test "new #{status.inspect} build should be valid?" do
assert new_build_status(status).valid?
end
test "new #{status.inspect} build should say succeeded only when it has" do
assert_equal status == 'succeeded', new_build_status(status).succeeded?
end
test "new #{status.inspect} build should say failed only when it has" do
assert_equal status == 'failed', new_build_status(status).failed?
end
test "new #{status.inspect} build should say in_progress only when it hasn't finished" do
assert_equal status != 'failed' && status != 'succeeded', create_new_build_status(status).in_progress?
end
end
private
def create_new_build_status(status = 'started')
@build_status = BuildStatus.for(skus(:ruby_pdf))
@build_status.status = status
assert @build_status.valid?, @build_status.errors.full_messages.to_sentence
@build_status
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment