summaryrefslogtreecommitdiff
path: root/spec/features/registrations_spec.rb
blob: 9e285c8b7e59766f57f20e4767de84b2199b1750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require "rails_helper"

feature "Registrations", type: :feature do
  subject { NewRegistrationPage.new }

  before :each do
    subject.visit_page
  end

  describe "creating a new account" do
    it "registers a new account" do
      subject.register_with(username: "mo", email: "mo@example.com", password: "password")

      expect(current_path).to eql(edit_profile_path("mo"))
    end

    context "when the username is taken" do
      let!(:user) { create(:user) }

      it "displays an error" do
        subject.register_with(username: user.username)

        expect(page).to have_content("Username has already been taken")
      end
    end

    context "when the email is taken" do
      let!(:user) { create(:user) }

      it "displays an error" do
        subject.register_with(email: user.email)

        expect(page).to have_content("Email has already been taken")
      end
    end

    context "when the terms and conditions are not accepted" do
      it "displays an error" do
        subject.register_with(accept_terms: false)

        expect(page).to have_content("Terms and conditions must be accepted")
      end
    end
  end
end