2023-03-04 22:38:38 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Achievements::Achievement, type: :model, feature_category: :users do
|
|
|
|
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
|