Sha256: 0dd93de2d57447e6ef6c31f714ec5cbe95ff1aa7d354897e7f46dce86e0074fe

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require "rails_helper"

module Archangel
  RSpec.describe User, type: :model do
    context "callbacks" do
      let(:resource) { create(:user) }

      it do
        expect(resource).to callback(:parameterize_username).before(:validation)
      end

      it { expect(resource).to callback(:column_default).after(:initialize) }
      it { expect(resource).to callback(:column_reset).after(:destroy) }
    end

    context "validations" do
      it { expect(subject).to validate_presence_of(:email) }
      it { expect(subject).to validate_presence_of(:name) }
      it { expect(subject).to validate_presence_of(:password).on(:create) }
      it { expect(subject).to validate_presence_of(:role) }
      it { expect(subject).to validate_presence_of(:username) }

      it { expect(subject).to validate_length_of(:password).is_at_least(8) }

      it { expect(subject).to have_db_index(:email).unique(true) }
      it { expect(subject).to have_db_index(:username).unique(true) }

      it do
        expect(subject)
          .to validate_inclusion_of(:role).in_array(Archangel::ROLES)
      end

      it "allows values for email" do
        [
          "foo@example.com",
          "foo.bar@example.com",
          "foo_bar@example.com",
          "foo+bar@example.com",
          "~!\#$%^&*_+{}|\?`-='@example.com"
        ].each do |email|
          expect(subject).to allow_value(email).for(:email)
        end
      end

      it "does not allows values for email" do
        [
          nil,
          "",
          "@",
          "foo@",
          "@example",
          "@example.com",
          "foo bar@example.com"
        ].each do |email|
          expect(subject).to_not allow_value(email).for(:email)
        end
      end
    end

    context "associations" do
      it { expect(subject).to belong_to(:site) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
archangel-0.0.5 spec/models/archangel/user_spec.rb
archangel-0.0.4 spec/models/archangel/user_spec.rb
archangel-0.0.3 spec/models/archangel/user_spec.rb
archangel-0.0.2 spec/models/archangel/user_spec.rb