0

TDD を使用してアプリを開発しようとしているので、最初にデータベース列に対して失敗するテストを作成する必要があります。ただし、モデルに存在しないフィールドにコンテンツを追加すると、とにかく割り当てられるようです。このテストを失敗させる方法がわかりません。

ルビー 2.1.1、レール 4.0.3、rSpec 2.14.1、FactoryGirl 4.4.0

私のモデルは次のようになります。

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        |                |
+------------+--------------+------+-----+-------------+----------------+

「コンテンツ」列を追加したいと思います。私のテストは現在次のようになっています。

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

しかし、データベースに存在しないにもかかわらず、コンテンツ フィールドが割り当てられているようです。ここでは、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…">

列が存在するまでこのテストを失敗させるにはどうすればよいですか? また、lesson_plan id が nil なのはなぜですか?

4

0 に答える 0