You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Writing a test for the events controller index action:
Preliminary:
Make make_event method (previously in applications controller test) accessible to all controller tests by adding it to the ActiveSupport::TestCase class in the test helper file
Also move any methods that are not assertions from the Minitest::Assertions module to the ActiveSupport::TestCase class (for better code organization)
Actual test:
[Add it to events_controller_test.rb]
Give it a name
Assign values to two variables for different events. Make one an approved, the other one an unapproved event (using a modified version of the make_event method that now has default values for fields name and approved)
Simulate a get request for the index view
Make assertions:
1.) that there is exactly one h3 element in the view that contains the name of the approved event as its text
2.) that there are exactly 0 h3 element in the view that contains the name of the unapproved event as its text
Note: the assertions were a bit difficult because we passed wrong things to make_event at first. We only realized that after we had already switched to not using actual assertions but css_select instead. We could try to refactor this using actual assertions :)