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><%= @meeting.date.strftime("%B %d, %Y") %></div> ...
The Controller Test has this:
test "should get show when logged in" do log_in_as(@person) get :show, id: @meeting.id assert_response :success end
The date property of the meeting model is a date (as expected):
create_table "meetings", force: :cascade do |t| ... t.date "date" ... end
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.