rails force_sslでもcapybaraのテストを書きたい
遊びで書いた醜いコードをさらすシリーズ
たぶんこんな感じで書くと全部httpsにリダイレクトかかるんだけど、
class ApplicationController < ActionController::Base force_ssl end
軒並みcapybaraで書いたテストが落ちます
試してないけど、ここに書いてある方法が良さそうです。
テストの都合はテスト側に書く。
How are people testing rails 3.1 + force_ssl? - Stack Overflow
自分はまた別の都合でforce_sslが効かないで欲しいアクションがあるので
class ApplicationController < ActionController::Base force_ssl unless: :http_allowed? private def http_allowed? return true if Rails.env.test? || Rails.env.development? http_allowed = %w[ なんかコントローラ名#なんかアクション名 ] http_allowed.include? "#{controller_name}##{action_name}" end end
みたいな感じに書いたけどここに書くことか、って思った