「show」アクションに単純なGETリクエストを送信する統合テストがあります。assert_response :success を取得すると、応答が 406 であるため失敗します。これは、形式がNot Acceptable HTTPであることを意味します。
require 'test_helper'
class UserFlowsTest < ActionDispatch::IntegrationTest
fixtures :continents, :countries, :types
test "browse register order" do
docs = make_docs
assert_equal Doc.count, docs.length, "Docs not created properly"
bob=new_session_as(:bob)
bob.goes_to_home
bob.goes_to_doc(1)
end
private
module TestDSL
def goes_to_home
get root_url
test_results("docs/index")
end
def goes_to_doc(id)
get docs_url(id), #{:format => :html} - fails with this as well...
y request.inspect
p response.inspect
test_results("docs/show")
end
def test_results(path)
assert_response :success, "Checking #{path}"
assert_template path
end
end #module TestDSL
def new_session_as(person)
new_session do |sess|
#sess.goes_to_login
#sess.logs_in_as(person)
yield sess if block_given?
end
end
def new_session
open_session do |sess|
sess.extend(TestDSL)
yield sess if block_given?
end
end
end
request.inspect の出力は次のとおりです。
--- "#[], \"action_dispatch.request.parameters\"=>{\"format\"=>\"1\", \"action\"=>\"index\", \"controller\ "=>\"docs\"}, \"rack.session\"=>{\"origin_url\"=>\"/docs.1?format=html\", \"session_id\"=>\"6e0e0be703a2c2accf15121b1eb56668 \"}, \"rack.test\"=>true, \"HTTP_ACCEPT\"=>\"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain; q=0.8,画像/png, /;q=0.5\", \"HTTP_HOST\"=>\"www.example.com\", \"SERVER_NAME\"=>\"www.example.com\", \"rack.request.cookie_hash\" =>{\"_id_session\"=>\"BAh7ByIPb3JpZ2luX3VybCIGLyIPc2Vzc2lvbl9pZCIlNmUwZTBiZTcwM2EyYzJhY2NmMTUxMjFiMWViNTY2Njg=--ceb0f44d2ac8df81c888e005abb7e9d1df02e802\"}, \"action_dispatch.remote_ip\"=>#, \"CONTENT_LENGTH\"=>\"0\", \"rack.url_scheme \"=>\"http\", \"action_dispatch.request.query_parameters\"=>{\"format\"=>\"html\"}, \"action_dispatch.request.unsigned_session_cookie\"=>{\" origin_url\"=>\"/\", \"session_id\"=>\"6e0e0be703a2c2accf15121b1eb56668\"}, \"CONTENT_TYPE\"=>\"application/x-www-form-urlencoded\", \"HTTPS\"=>\"off\", \"rack.errors\"=>#, \"action_dispatch.secret_token\"=>\"8922d5d0a3e706818581l8cc2d42d9ce584ba6350de71e6afc49b2ad7d3d05c6e763db2615fca9eb123c51b57223d955a5199b60c20e5efb4be14888a4e3520a2\" 、\"REMOTE_ADDR\"=>\"127.0.0.1\"、\"PATH_INFO\"=>\"/docs.1\"、\"rack.version\"=>[1, 1]、\"ラック.run_once\"=>false, \"action_dispatch.request.path_parameters\"=>{:format=>\"1\", :controller=>\"docs\", :action=>\"index\"} 、\"rack.request.cookie_string\"=>\"_id_session=BAh7ByIPb3JpZ2luX3VybCIGLyIPc2Vzc2lvbl9pZCIlNmUwZTBiZTcwM2EyYzJhY2NmMTUxMjFiMWViNTY2Njg%3D--ceb0f44d2ac8df81c888e005abb7e9d1df02e802\", \"SCRIPT_NAME\"=>\"\", \"action_dispatch.parameter_filter\"=>[:password, :data], \"action_dispatch.show_exceptions\"=>false , \"HTTP_COOKIE\"=>\"_id_session=BAh7ByIPb3JpZ2luX3VybCIGLyIPc2Vzc2lvbl9pZCIlNmUwZTBiZTcwM2EyYzJhY2NmMTUxMjFiMWViNTY2Njg%3D--ceb0f44d2ac8df81c888e005abb7e9d1df02e802\", \"rack.multithread\"=>true, \"action_dispatch.request.request_parameters\"=>{}, \"rack. request.form_vars\"=>\"\", \"action_dispatch.cookies\"=>{\"_id_session\"=>\"BAh7ByIPb3JpZ2luX3VybCIYL2RvY3MuMT9mb3JtYXQ9aHRtbCIPc2Vzc2lvbl9pZCIlNmUwZTBiZTcwM2EyYzJhY2NmMTUxMjFiMWViNTY2Njg=--529dbf0f8e243c4830526f37adb777bd9fba49fd\"}, \"REQUEST_URI\"=>\"/docs.1\", \"rack.multiprocess\"=>true, \"rack.request.query_hash\"=>{\" format\"=>\"html\"}, \"rack.request.form_input\"=>#, \"SERVER_PORT\"=>\"80\", \"action_controller.instance\"=>#\" 1\", \"action\"=>\"index\", \"controller\"=>\"docs\"}, @env={...}>, @cache_control={}, @body= [\" \"], @status=406, @length=0, @charset=\"utf-8\", @header={\"X-UA-Compatible\"=>\"IE=Edge,chrome =1\", \"X-Runtime\"=>\"0.013935\",\"Content-Type\"=>\"text/html; charset=utf-8\", \"Set-Cookie\"=>\"_id_session=BAh7ByIPb3JpZ2luX3VybCIYL2RvY3MuMT9mb3JtYXQ9aHRtbCIPc2Vzc2lvbl9pZCIlNmUwZTBiZTcwM2EyYzJhY2NmMTUxMjFiMWViNTY2Njg%3D--529dbf0f8e243c4830526f37adb777bd9fba49fd; path=/; HttpOnly\" , \"Cache-Control\"=>\"no-cache\"}, @block=nil, @writer=#, @blank=true, @sending_file=false, @etag=nil, @content_type=#, @ cookie=[]>, @_headers={\"Content-Type\"=>\"text/html\"}, @docs=[#, #, #, #, #, #], @_config=#, @countries=[#, #, #], @continents=[#, #], @_action_name=\"index\", @_request=#\"1\", \"action\"=>\"index\ ", \"controller\"=>\"docs\"}, @env={...}>, @lookup_context=#=>{\"layouts\"=>{\"nav\"=>{true=>[app/views/layouts/_nav.html.haml]}, \"application\"=>{false=>[app/views/layouts/application.html.haml]} ]}、\"docs\"=>{false=>[]}}、\"docs\"=>{\"index\"=>{false=>[app/views/docs/index.html.haml ]}}}}, @path=\"/home/jon/id/app/views\">,
@cached={#=>{\"layouts\"=>{\"docs\"=>{false=>[]}}}}, @path=\"/home/jon/.rvm/gems/ruby -1.8.7-p334/gems/devise-1.4.2/app/views\">]、@details_key=nil、@skip_default_locale=false、@details={:formats=>[:html、:text、:js 、:css、:ics、:csv、:xml、:rss、:atom、:yaml、:multipart_form、:url_encoded_form、:json]、:handlers=>[:haml、:builder、:erb、:rjs、: rhtml, :rxml], :locale=>[:en, :en]}, @frozen_formats=false>, @doc_types=[#, #], @_status=200, @view_context_class=nil, @action_has_layout=true>, \"rack.session.options\"=>{:secure=>false, :expire_after=>nil, :domain=>nil, :httponly=>true, :id=>\"6e0e0be703a2c2accf15121b1eb56668\", :path=> \"/\"}, \"REQUEST_METHOD\"=>\"GET\", \"warden\"=>Warden::Proxy:-616946978 @config={:default_scope=>:user, :failure_app=>Devise::FailureApp, :intercept_401=>false, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, : scope_defaults=>{}}, \"rack.request.query_string\"=>\"format=html\", \"rack.request.form_hash\"=>{}, \"action_dispatch.request.content_type\"= >#, \"QUERY_STRING\"=>\"format=html\", \"rack.input\"=>#}>"\"action_dispatch.request.content_type\"=>#, \"QUERY_STRING\"=>\"format=html\", \"rack.input\"=>#}>"\"action_dispatch.request.content_type\"=>#, \"QUERY_STRING\"=>\"format=html\", \"rack.input\"=>#}>"
ここにresponse.inspectの出力があります:
"#true}, @body=[\" \"], @status=406, @length=0, @charset=\"utf-8\", @header={\"X-UA-Compatible\"= >\"IE=Edge,chrome=1\", \"Content-Type\"=>\"text/html; charset=utf-8\", \"X-Runtime\"=>\"0.013935\", \"Set-Cookie\"=>\"_id_session=BAh7ByIPb3JpZ2luX3VybCIYL2RvY3MuMT9mb3JtYXQ9aHRtbCIPc2Vzc2lvbl9pZCIlNmUwZTBiZTcwM2EyYzJhY2NmMTUxMjFiMWViNTY2Njg%3D--529dbf0f8e243c4830526f37adb777bd9fba49fd; パス=/; HttpOnly\", \"Cache-Control\"=>\"no-cache\"}, @block=nil, @writer=#, @blank=false, @sending_file=false, @etag=nil, @content_type= #, @cookie=[]>"
「goes_to_home」テストは期待どおりに機能します。私のPCの開発環境でページを使用しても問題なく動作します。サーバーコンソールの出力は次のとおりです。
Wed Aug 31 05:19:20 +0200 2011 で 127.0.0.1 の GET "/docs/1" を開始しました DocsController#show as HTML パラメータによる処理: {"id"=>"1"}
Doc Load (1.0ms) SELECTdocs
.*docs
どこからdocs
.id
= 1 LIMIT 1 ユーザー ロード (1.4ms) SELECTusers
.* FROMusers
WHEREusers
.id
= 2 LIMIT 1 SQL (1.0ms) SELECT COUNT(*) FROMimages
WHERE (images
.user_id = 2) CACHE (0.0ms) SELECT COUNT(*) FROMimages
WHERE (images
.user_id = 2) 画像の読み込み (1.9ms) SELECTimages
.* FROMimages
WHERE (images
.user_id = 2) ORDER BY updated_at DESC LIMIT 1 印刷負荷 (0.9ms) SELECTprints
.* FROMprints
WHEREprints
.image_id
= 1 ANDprints
.doc_id
= 1 LIMIT 1 レンダリングされたレイアウト/_nav.html.haml (8.5ms) レンダリングされたレイアウト/アプリケーション内の docs/show.html.haml (172.7ms) 410ms で 200 OK を完了 (ビュー: 225.0ms | ActiveRecord: 6.2ms)開始 GET "/javascripts/dynamic_docs.js" for 127.0.0.1 at Wed Aug 31 05:19:21 +0200 2011 JavascriptsController#dynamic_docs による処理 JS Doc Load (16.1ms) SELECT
docs
.* FROMdocs
Country Load (0.7ms) SELECTcountries
.*countries
どこからcountries
.id
= 1 LIMIT 1 CACHE (1.2ms) SELECTcountries
.* FROMcountries
WHEREcountries
.id
= 1 LIMIT 1 Country Load (0.6ms) SELECTcountries
.* FROMcountries
WHEREcountries
.id
= 2 LIMIT 1
Country Load (0.6ms) SELECTcountries
.* FROMcountries
WHEREcountries
.id
= 8 LIMIT 1 Country Load (0.6ms) SELECTcountries
.* FROMcountries
WHEREcountries
.id
= 18 LIMIT 1 レンダリングされた javascripts/dynamic_docs.js.erb (216.0ms) 270ms で 200 OK を完了 (ビュー: 238.2ms | ActiveRecord: 19.8ms)Wed Aug 31 05:19:21 +0200 2011 "US Passport" 30.0 "head_top 39" "X: 2.65000000000001, Y: 28.85, width: で 127.0.0.1 の GET "/image_for/US-Passport/1.jpg" を開始222.7、高さ: 222.7" HTML パラメーターとして DocsController#image_for による処理
: {"image_id"=>"1", "name"=>"US-Passport"} ユーザー ロード (2.0ms) SELECTusers
.* FROMusers
WHEREusers
.id
= 2 LIMIT 1 画像読み込み (0.9ms) SELECTimages
.* FROMimages
WHEREimages
.id
= 1 AND (images
.user_id = 2) ORDER BY updated_at DESC LIMIT 1 Doc Load (1.0ms) SELECTdocs
.* FROMdocs
WHEREdocs
.name
= 'US Passport' LIMIT 1 レンダリングされたテキスト テンプレート (0.1ms) 送信データ orange.jpg (13.
何か案は?前もって感謝します