Introducci贸n

1

Pasos para construir aplicaciones en Ruby on Rails

2

Retomando nuestro proyecto

3

Instalando MongoDB

4

Migrando nuestra aplicaci贸n: componentes, librer铆as y configuraciones

5

Migrando nuestra aplicaci贸n: modelos

6

Migrando nuestra aplicaci贸n: modelos restantes y seeds

Pruebas

7

驴Qu茅 es TDD y BDD?

8

Construyendo nuestra f谩brica de documentos de prueba

9

Esteroides para tus pruebas

10

A帽adiendo pruebas de modelo

11

A帽adiendo pruebas de modelo: validaci贸n de datos

12

Finalizando las pruebas de modelo

13

A帽adiendo pruebas de peticiones

14

Creando y probando tareas de petici贸n

15

Headless browser

16

A帽adiendo pruebas de sistema: interacci贸n del sistema

17

A帽adiendo pruebas de sistema: comportamientos din谩micos

Interacci贸n din谩mica

18

Rails con caf茅

19

Selectize, esteroides para tus selects

20

Retomando los formularios anidados

21

Mejorando la asignaci贸n de participantes

Notificaciones

22

Retomando las notificaciones del proyecto

23

Introducci贸n a Service Objects

24

Construyendo prueba de servicio de notificaci贸n por correo

25

Construyendo servicio de notificaci贸n por correo

26

Introducci贸n a procesos en background y Active Job

27

Creando un Job para la notificaci贸n de correo

Ciclos de vida

28

Introducci贸n a m谩quinas de estado

29

Creando m谩quina de estados para la tarea

30

Creando servicio de gesti贸n de estados de la tarea

31

Actualizando estados usando eventos

32

Modificando estados desde la interfaz

Cierre

33

Optimizaciones: fundamentos

34

Conclusiones

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
18 Hrs
32 Min
22 Seg

Finalizando las pruebas de modelo

12/34
Resources

How to finalize the testing of a model using validations?

In software development, ensuring that a model works correctly is essential. Testing not only ensures functionality, but also validates the persistence and ownership of the model. In this class, we focus on testing models using methods and validations in Ruby on Rails.

How to create a nested context to save the model?

To ensure that a model is correctly saved and validated, it is essential to create a specific context. A nested context is an effective way to separate different test scenarios.

  • Use with Parance from Scratch to define a context.
  • Set the before Each method to invoke save before each test.

Code example:

 'with Parance from Scratch' context do before(:each) do @task.save endend end

How to ensure that the model is persisted and has precomputed code?

After invoking save, it is important to validate two main aspects of the model:

  1. Model persistence: use be_persisted to confirm that the model is saved.
  2. Precomputed code: verify the existence of the code using be_present.

Example code:

expect(@task).to be_persistedexpect(@task.code).to be_present.

How to create a test when due date is in the past?

A common scenario is to verify that past dates are not valid for the model. For this, you can create a specific context and use the tap function to modify the attributes of the model.

  • Create a new context with due date in the past.
  • Use the tap method to directly modify the due_date attribute.

Example code:

context 'with due date in the past' do before(:each) do @task.tap do |t| t.due_date = Date.today - 1 end end end it 'is expected not to be valid' do expect(@task).not_to be_valid endend end end

Running the tests and checking that they fail correctly when the date is earlier than the current date is a crucial step for robust model checking. Tools such as rspec facilitate this process with quick commands.

What is the next step?

Now, having accomplished the necessary validations and ensured the correct functioning of the model, it is suggested that you try applying the same techniques to other models as a user. The concepts of persistence, validation and modification of internal attributes will be equally applicable. As you progress, you will encounter HTTP requests which we will cover in the next class. So don't give up, keep going with curiosity and determination.

Contributions 1

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Muy buena clase. En general este curso me encanta, el profesor hace que rspec sea muy sencillo de entender y utilizar.