mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
This tells our generic ajax (Turbo) error handling to ignore the error and let the application display the response as usual.
57 lines
1.6 KiB
Ruby
57 lines
1.6 KiB
Ruby
# frozen_string_literal: false
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe Spree::UserSessionsController do
|
|
let(:user) { create(:user) }
|
|
|
|
before do
|
|
@request.env["devise.mapping"] = Devise.mappings[:spree_user]
|
|
end
|
|
|
|
describe "create" do
|
|
context "success" do
|
|
context "when referer is not '/checkout'" do
|
|
it "redirects to root" do
|
|
spree_post :create, spree_user: { email: user.email, password: user.password }
|
|
|
|
expect(response).to have_http_status(:found)
|
|
expect(response.body).to match(root_path).and match("redirect")
|
|
end
|
|
end
|
|
|
|
context "when referer is '/checkout'" do
|
|
before { @request.env['HTTP_REFERER'] = 'http://test.com/checkout' }
|
|
|
|
it "redirects to checkout" do
|
|
spree_post :create, spree_user: { email: user.email, password: user.password }
|
|
|
|
expect(response).to have_http_status(:found)
|
|
expect(response.body).to match(checkout_path).and match("redirect")
|
|
end
|
|
end
|
|
end
|
|
|
|
context "failing to log in" do
|
|
render_views
|
|
|
|
it "returns an error" do
|
|
spree_post :create, spree_user: { email: user.email, password: "wrong" },
|
|
format: :turbo_stream
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
expect(response.body).to include "Invalid email or password"
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "destroy" do
|
|
it "redirects to root with flash message" do
|
|
spree_post :destroy
|
|
|
|
expect(response).to redirect_to root_path
|
|
expect(flash[:notice]).to eq "Signed out successfully."
|
|
end
|
|
end
|
|
end
|