2016-02-12 23:52:43 +08:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ChecklistTest < ActiveSupport::TestCase
|
2016-10-11 14:25:32 +08:00
|
|
|
should validate_presence_of(:step)
|
|
|
|
should validate_presence_of(:name)
|
2016-10-17 19:21:10 +08:00
|
|
|
should validate_length_of(:name).is_at_most(Constants::TEXT_MAX_LENGTH)
|
2016-10-11 14:25:32 +08:00
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
test "should validate with correct data" do
|
|
|
|
checklist = Checklist.new(
|
|
|
|
name: "test",
|
|
|
|
step: steps(:step1)
|
|
|
|
)
|
|
|
|
assert checklist
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should have association step -> checklist" do
|
|
|
|
checklist = Checklist.new(
|
|
|
|
name: "test",
|
|
|
|
step: steps(:step1))
|
2016-07-21 19:11:15 +08:00
|
|
|
step = Step.create(name: "Step test", position: 0, completed: 0, user: users(:steve), protocol: protocols(:rna_test_protocol))
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
|
|
assert_empty step.checklists
|
|
|
|
step.checklists << checklist
|
|
|
|
|
|
|
|
assert_equal checklist, Step.find(step.id).checklists.first
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|