Allow request to specify a return value when calling user_passwords#edit

This commit is contained in:
Rob Harrington
2015-04-17 10:21:25 +10:00
parent 5940ff2b2c
commit afe77925ba
2 changed files with 26 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
class UserPasswordsController < Spree::UserPasswordsController
layout 'darkswarm'
before_filter :set_admin_redirect, only: :edit
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
@@ -18,4 +20,10 @@ class UserPasswordsController < Spree::UserPasswordsController
end
end
end
private
def set_admin_redirect
session["spree_user_return_to"] = params[:return_to] if params[:return_to]
end
end

View File

@@ -9,15 +9,26 @@ describe UserPasswordsController do
ActionMailer::Base.default_url_options[:host] = "test.host"
end
it "returns errors" do
spree_post :create, spree_user: {}
response.should be_success
response.should render_template "spree/user_passwords/new"
describe "create" do
it "returns errors" do
spree_post :create, spree_user: {}
response.should be_success
response.should render_template "spree/user_passwords/new"
end
it "redirects to login when data is valid" do
spree_post :create, spree_user: { email: user.email}
response.should be_redirect
end
end
it "redirects to login when data is valid" do
spree_post :create, spree_user: { email: user.email}
response.should be_redirect
describe "edit" do
context "when given a redirect" do
it "stores the redirect path in 'spree_user_return_to'" do
spree_post :edit, reset_password_token: "token", return_to: "/return_path"
expect(session["spree_user_return_to"]).to eq "/return_path"
end
end
end
it "renders Darkswarm" do