I am new to rails and have been recently going through a range of tutorials and want to make sure that I go down the test driven development route. I have hit a snag on how to approach writing this test.
I have two related models : Task and Project.
Task belongs_to Project and Project has_many Tasks
Inside the project show template I list all the associated tasks to that project.
On the task I have a status field which I want to set to archived on press of a button and then return the back to the associated project.
Would anybody be able to give me a nudge into the right direction for writing tests with associations please. It would be very much appreciated.
What kind of testing setup do you have? Are you using RSpec or Test::Unit? As far as testing the associtation (in Test::Unit) you could do something like that:
I typed this on the fly so I wouldnt bet the syntax is correct. But the gist of it should be understandable. This sort of test is the “lowest” level test, also called a “unit test” you could create to test
the associations. If you wanted to test the template you could look into “integration testing.” These should be pretty helpful: http://guides.rubyonrails.org/testing.html