0
我正在使用水豚編寫集成測試,這裏是我測試的代碼。Rails集成測試失敗,因爲current_path的最終斜槓
test "when providing invalid data" do
admin = create(:administrator)
signin_administrator_as admin.email, admin.password
visit new_admin_country_path
click_button t("buttons.admin.save")
assert_equal admin_countries_path, current_path
assert page.has_text? t("admin.form_error_message")
end
在控制器
def create
@country = Country.new(country_params)
if @country.save
redirect_to admin_countries_path, notice: t("flash.admin.country.create.notice")
else
render :new
end
end
我有我的一種形式的局部,我使用插入和更新
<%= form_for @country, url: admin_country_path(@country) do |f| %>
<p>
<%= f.label :code, t("labels.country.code") %>
<%= f.text_field :code %>
</p>
<p>
<%= f.label :portuguese_name, t("labels.country.portuguese_name") %>
<%= f.text_field :portuguese_name %>
</p>
<p>
<%= f.label :spanish_name, t("labels.country.spanish_name") %>
<%= f.text_field :spanish_name %>
</p>
<p>
<%= f.label :english_name, t("labels.country.english_name") %>
<%= f.text_field :english_name %>
</p>
<%= f.submit t("buttons.admin.save") %>
<% end %>
但我的測試失敗,因爲URL的最後的斜線。
Expected: "/admin/countries"
Actual: "/admin/countries/"
這是我的路線定義
namespace :admin do
root to: "signin#new"
get "/signin", to: "signin#new"
post "/signin", to: "signin#create"
get "/dashboard", to: "dashboard#index"
resources :countries
end
誰能幫助我?
謝謝。
請顯示路線設置。 –