Created
December 5, 2011 18:55
-
-
Save EinLama/1434770 to your computer and use it in GitHub Desktop.
How to test :dependent => :destroy using minitest::spec?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Project do | |
it "should be valid" do | |
project = Fabricate.build :project | |
project.must_be_valid | |
end | |
it "should have a name" do | |
project_without_name = Fabricate.build :project, name: nil | |
project_without_name.wont_be_valid | |
end | |
it "it may have a project-number of 0" do | |
project_without_number = Fabricate.build :project, number: 0 | |
project_without_number.must_be_valid | |
end | |
# How to test this? | |
it "should destroy all associated work units when it gets deleted" do | |
project_with_work_units = Fabricate.build :project | |
work_unit = Fabricate.build :work_unit, project: project_with_work_units | |
project_with_work_units.work_units << work_unit | |
project_with_work_units.save! | |
project_with_work_units.destroy | |
Project.count.must_equal 0 | |
WorkUnit.count.must_equal 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment