Closed C83 closed 6 years ago
Command : rails generate model lesson title:string{50} description:text{300} We can't define a parameter "can't be empty" with command line. Then in migrate file :
rails generate model lesson title:string{50} description:text{300}
t.string :title, limit: 50, null:false t.text :description, limit: 300
In lesson model file :
validates :title, presence: true, length: { maximum: 50 } validates :description, length: { maximum: 300 }
require 'faker' FactoryBot.define do factory :lesson do title Faker::Hacker.noun description Faker::ChuckNorris.fact end end
Creation and save test with expect and factory_bot. With factory_bot, build builds an instance of object. create saves and persists it.
build
create
it "is valid with valid attributes" do expect(build(:lesson)).to be_valid end
Some tests are rewritten with should gem :
it { should validate_presence_of(:title) }
closes #6
On peut s appeler pour en parler ?
Y a un ou deux sujets !
Migration :
Command :
rails generate model lesson title:string{50} description:text{300}
We can't define a parameter "can't be empty" with command line. Then in migrate file :Validation
In lesson model file :
Test
Factory :
Creation and validation :
Creation and save test with expect and factory_bot. With factory_bot,
build
builds an instance of object.create
saves and persists it.Some tests are rewritten with should gem :
closes #6