プロジェクト

全般

プロフィール

« | » 

リビジョン d644dae3

高徹 高橋 徹 さんが7年以上前に追加

Add unit test for term_category

差分を表示:

test/fixtures/term_categories.yml
one:
id: 1
project_id: 1
name: MyString
name: one
position: 1
two:
id: 2
project_id: 1
name: MyString
name: two
position: 1
test/fixtures/terms.yml
two:
id: 2
project_id: 2
category_id:
category_id: 2
author_id: 2
updater_id:
name: term two
test/unit/term_category_test.rb
class TermCategoryTest < ActiveSupport::TestCase
plugin_fixtures :term_categories
# Replace this with your real tests.
def test_truth
assert true
def setup
@category = TermCategory.find(1)
end
def test_valid
assert @category.valid?
end
def test_invalid_without_name
@category.name = nil
assert_not @category.valid?, 'saved term_category without a name'
assert_not_nil @category.errors[:name], 'no validation error for name present'
end
def test_invalide_duplicate_name
@category.name = 'two'
assert_not @category.valid?, 'saved term_category with duplicate name'
assert_not_nil @category.errors[:name], 'no validation error for name duplicate'
end
def test_position_comparison
cat2 = TermCategory.find(2)
assert_equal 0, @category <=> cat2
@category.position = 2
assert (@category <=> cat2) > 0
@category.position = 0
assert (@category <=> cat2) < 0
end
def test_destroy_without_reassign
term2 = Term.find(2)
cat2 = TermCategory.find(2)
cat2.destroy
assert_nil term2.category
end
def test_destory_with_reassign
term2 = Term.find(2)
cat2 = TermCategory.find(2)
cat2.destroy(@category)
term2 = Term.find(2)
assert_equal @category, term2.category
end
end

他の形式にエクスポート: Unified diff