Bizarre "undefined method ‘strftime’ for 43200:Fixnum" in Rails controller test but works fine in actual view

I was working on a Rails application and one part of the app involves displaying formatted dates in views. When I use the strftime method of a date to format in the view, everything works fine. However, one of the controller tests related to the views fails, saying that the strftime method doesn’t exist for a “Fixnum”, despite the fact that the property I run the method on is a date.

Specifically, in the View I have this:

<div><%="%B %d, %Y") %></div>

The Controller Test has this:

  test "should get show when logged in" do
    get :show, id:
    assert_response :success

The date property of the meeting model is a date (as expected):

create_table "meetings", force: :cascade do |t|
  ...  "date"

What is going on here? It’s strange—the property works fine in the view and in rails console, but errors during the test which picks up the property as a Fixnum rather than a Date.

Source: ruby

Leave a Reply