main
 1# frozen_string_literal: true
 2
 3require 'rails_helper'
 4
 5RSpec.describe '/registrations' do
 6  describe "GET /registrations/new" do
 7    before { get '/registrations/new' }
 8
 9    specify { expect(response).to have_http_status(:ok) }
10    specify { expect(response.body).to include("Register") }
11  end
12
13  describe "POST /registrations" do
14    context "when the new registration data is valid" do
15      let(:email) { FFaker::Internet.email }
16      let(:new_password) { FFaker::Internet.password }
17
18      before { post "/registrations", params: { user: { email: email, password: new_password, password_confirmation: new_password } } }
19
20      specify { expect(response).to redirect_to(new_session_url) }
21      specify { expect(User.count).to be(1) }
22      specify { expect(User.last.email).to eql(email) }
23    end
24
25    context "when the new registration data is invalid" do
26      let(:user) { create(:user) }
27
28      before { post "/registrations", params: { user: { email: user.email, password: "password" } } }
29
30      specify { expect(response).to redirect_to(new_registration_path) }
31      specify { expect(flash[:error]).to be_present }
32    end
33
34    context "when the password confirmation does not match" do
35      let(:email) { FFaker::Internet.email }
36      let(:new_password) { FFaker::Internet.password }
37
38      before { post "/registrations", params: { user: { email: email, password: new_password, password_confirmation: 'other' } } }
39
40      specify { expect(response).to redirect_to(new_registration_path) }
41      specify { expect(flash[:error]).to be_present }
42    end
43  end
44end