debian-mirror-gitlab/spec/models/achievements/achievement_spec.rb

37 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2023-03-04 22:38:38 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Achievements::Achievement, type: :model, feature_category: :user_profile do
2023-03-04 22:38:38 +05:30
describe 'associations' do
it { is_expected.to belong_to(:namespace).required }
2023-03-17 16:20:25 +05:30
it { is_expected.to have_many(:user_achievements).inverse_of(:achievement) }
it { is_expected.to have_many(:users).through(:user_achievements).inverse_of(:achievements) }
2023-03-04 22:38:38 +05:30
end
describe 'modules' do
subject { described_class }
it { is_expected.to include_module(Avatarable) }
end
describe 'validations' do
subject { create(:achievement) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to([:namespace_id]) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_length_of(:description).is_at_most(1024) }
end
describe '#name' do
it 'strips name' do
achievement = described_class.new(name: ' AchievementTest ')
achievement.valid?
expect(achievement.name).to eq('AchievementTest')
end
end
end