jeudi 15 avril 2021

Test failing for feature that works using assert_changes

My chat app has a chat class and a message class; when a message is added to the chat, chat.updated_at should also be updated (achieved with belongs_to :chat, touch: true).

When I test this manually, it works correctly, the time is updated. My test below fails however, and I cannot work out why.

  test "sending a message should update chats updated timestamp" do
    sign_in @user
    assert_changes "@chat.updated_at" do
      post messages_path(params: { message: { 
        text: 'Hello', to_id: @bob.id, chat_id: @chat.id
        }})
      assert_response :success
    end
  end

I simply get the error @chat.updated_at didn't change.

My chat fixture is

one:
  id: 1
  subject: nil
  updated_at: <%= 2.hours.ago %>

Aucun commentaire:

Enregistrer un commentaire