Im trying to develop my app using TDD so I need to write a failing test first for a database column. However, when I add content to a non-existent field in a model it seems to get assigned anyway. I don't know how to make this test fail.
Ruby 2.1.1, Rails 4.0.3, rSpec 2.14.1, FactoryGirl 4.4.0
My model looks like this:
mysql> describe lesson_plans;
+------------+--------------+------+-----+-------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+-------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | | NULL | |
| title | varchar(255) | NO | | Lesson Plan | |
| synopsis | text | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+--------------+------+-----+-------------+----------------+
I would like to add the column 'content'. My test currently looks like this:
it "should have a content field" do
lesson_plan = build(:lesson_plan, user: @user,
content: "The French Revolution was a period of radical social and political upheaval in France from 1789 to 1799 that profoundly affected French and modern history...")
puts lesson_plan.inspect
end
But it looks like the content field is being assigned even though it does not exist in the database. Here's the output from lesson_plan.inspect:
#<LessonPlan id: nil, user_id: 455, title: "The French Revolution",
synopsis: "Background and events leading up to the French Revo...", created_at: nil,
updated_at: nil, content: "The French Revolution was a period of radical socia…">
How do I make this this test fail until the column exists? Also, why is the lesson_plan id nil?