В моем приложении Rails, если user
хочет удалить свою учетную запись, ему сначала нужно будет ввести свой пароль в моем представлении terminate
:
<%= form_for @user, :method => :delete do |f| %>
<%= f.label :password %><br/>
<%= f.password_field :password %>
<%= f.submit %>
<% end %>
Это мой UsersController
:
def terminate
@user = User.find(params[:id])
@title = "Terminate your account"
end
def destroy
if @user.authenticate(params[:user][:password])
@user.destroy
flash[:success] = "Your account was terminated."
redirect_to root_path
else
flash.now[:alert] = "Wrong password."
render :terminate
end
end
Проблема в том, что я не могу найти способ проверить это с помощью RSpec.
У меня есть это:
describe 'DELETE #destroy' do
before :each do
@user = FactoryGirl.create(:user)
end
context "success" do
it "deletes the user" do
expect{
delete :destroy, :id => @user, :password => "password"
}.to change(User, :count).by(-1)
end
end
end
Однако это дает мне ошибку:
ActionView::MissingTemplate:
Missing template users/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fa7f51310d8>"
Может ли кто-нибудь сказать мне, что мне здесь не хватает, или предложить лучший способ проверить это действие?
Спасибо за любую помощь.