0
我正在學習如何使用Ruby on Rails,並遇到一些煩人的問題,試圖從控制器的測試類訪問燈具。不幸的是,儘管遵循了Rails測試指南中的正確方法,但我得到了'TypeError:無法將Symbol轉換爲整數'錯誤。有沒有人有任何想法可以解決這個問題。對於我的控制器的代碼的示例如下所示:無法從控制器測試訪問燈具Ruby on Rails
class ExerciseLogsController < ApplicationController
skip_before_filter :verify_authenticity_token
def show
@exerciseLog = ExerciseLog.find(params[:id])
respond_to do | format |
format.json { render json: @exerciseLog }
format.xml { render xml: @exerciseLog }
end
end
單元測試如下:
require 'test_helper'
class ExerciseLogsControllerTest < ActionController::TestCase
fixtures :exercise_logs
test "get existing exercise log" do
get :show, :id => 2, :format => 'json'
assert_response :success
assert_not_nil(assigns[:exerciseLog], "Exercise log should not be nil.")
assert_equal(exercise_logs[:log2].description, assigns[:exerciseLog].description, "Log description is not the description for log 2.")
end
end
我的夾具如下所示:
log2:
id: 2
user_id: 1
description: Walking in my lunch break.
startTime: 2014-09-11 14:00:00
endTime: 2014-09-11 15:00:00
distance: 1200