序文
昨日、ちょっと遠出したらすっかり疲れてしまいました。
運動不足を痛感するこの頃。
来年はしっかり体力つけたいと思っています。
進捗
- 第6章ユーザーのモデルを作成する
- 6.1 Userモデル
- 6.2 ユーザーを検証する
コード実装部分(一部)
/sample_app/test/models/user_test.rb
require 'test_helper' class UserTest < ActiveSupport::TestCase # 実際のテストの前に実行されるメソッド def setup @user = User.new(name: "Example User", email: "user@example.com") end # 正当性の確認 test "should be valid" do assert @user.valid? end # 不正なnameをはじくか test "name should be present" do @user.name = " " assert_not @user.valid? end # 不正なemailをはじくか test "email should be present" do @user.email = " " assert_not @user.valid? end # 51文字以上のnameをはじくか test "name should not be too long" do @user.name = "a" * 51 assert_not @user.valid? end # 256文字以上のemailをはじくか test "email should not be too long" do @user.email = "a" * 244 + "@example.com" assert_not @user.valid? end end
GitHub
実行結果
特になし
感想
今日からいよいよモデルを扱っていく。
それと同時にバリデーションのテストも書いていってとても実践的。
テストにはコメントも書けるので、しっかり地に足をつけて勉強している感がある。
事実上、すべてのWebアプリケーションは何らかのログイン/認証システムを必要とします。
って書いてあるんだけど、私が今まで作ってきたものは実はWebアプリケーションじゃなかったのかしら。
gladiolus.egoism.jp ↑昔CakePHPで作ったやつ。一応まだ更新してる。
競馬ばっかりじゃねーか。(そこじゃない)
カロリーメイトください。

- 出版社/メーカー: 大塚製薬
- メディア: 食品&飲料
- この商品を含むブログを見る
BGM
Drag & Hug / ハルカトミユキ