Rails Models: Validation and Testing

8th lecture, June 3, 2019

Projects in Information Technology II

http://www.sw.it.aoyama.ac.jp/2019/Projects2/lecture8.html

Martin J. Dürst

AGU

© 2019 Martin J. Dürst 青山学院大学

ミニテスト

 

Today's Schedule

 

Last Lecture's Exercises

Ideal split between controller and view:

  

Model Generation

  

Rails Datatypes

The main datatypes that can be used for model generation are as follows:

Label Usage/Meaning
:string (relatively short) character string
:text (long) character string
:binary (long) binary string
:date date (year/month/day)
:datetime date and time
:time time (of day) only
:timestamp date and time, for administrative purposes
:decimal decimal (with a fixed number of decimals before and after the decimal point)
:integer integer
:float float/double
:boolean boolean (single bit)

  

Validation

  

Example Validations

(more at https://guides.rubyonrails.org/active_record_validations.html)

  

Testing

  

Testing in Rails

  

Rails Model Tests

(more at https://guides.rubyonrails.org/testing.html#model-testing and other parts of that Web page; see also documentation for Minitest)

  

Exercise 8a: Setting up the Actor Model

  

Exercise 8b: Adding Validations

  

Exercise 8c: Adding Tests

    

Exercise 8d: Add Data to Database

  

Homework