Skip to content
代码片段 群组 项目
未验证 提交 eae040cf 编辑于 作者: Dmitry Gruzd's avatar Dmitry Gruzd 提交者: GitLab
浏览文件

Merge branch '434381-update-avatarable-spec-use' into 'master'

Use shared examples for models that use Avatarable module

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/139298



Merged-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
Approved-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
Approved-by: default avatarMichael Becker <11881043-wandering_person@users.noreply.gitlab.com>
Co-authored-by: default avatarDoug Stull <dstull@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -5,5 +5,9 @@ ...@@ -5,5 +5,9 @@
namespace namespace
name { generate(:name) } name { generate(:name) }
trait :with_avatar do
avatar { fixture_file_upload('spec/fixtures/dk.png') }
end
end end
end end
...@@ -4,5 +4,9 @@ ...@@ -4,5 +4,9 @@
factory :topic, class: 'Projects::Topic' do factory :topic, class: 'Projects::Topic' do
name { generate(:name) } name { generate(:name) }
title { generate(:title) } title { generate(:title) }
trait :with_avatar do
avatar { fixture_file_upload('spec/fixtures/dk.png') }
end
end end
end end
...@@ -4,18 +4,12 @@ ...@@ -4,18 +4,12 @@
RSpec.describe Achievements::Achievement, type: :model, feature_category: :user_profile do RSpec.describe Achievements::Achievement, type: :model, feature_category: :user_profile do
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:namespace).required } it { is_expected.to belong_to(:namespace).inverse_of(:achievements).required }
it { is_expected.to have_many(:user_achievements).inverse_of(:achievement) } it { is_expected.to have_many(:user_achievements).inverse_of(:achievement) }
it { is_expected.to have_many(:users).through(:user_achievements).inverse_of(:achievements) } it { is_expected.to have_many(:users).through(:user_achievements).inverse_of(:achievements) }
end end
describe 'modules' do
subject { described_class }
it { is_expected.to include_module(Avatarable) }
end
describe 'validations' do describe 'validations' do
subject { create(:achievement) } subject { create(:achievement) }
...@@ -27,10 +21,15 @@ ...@@ -27,10 +21,15 @@
describe '#name' do describe '#name' do
it 'strips name' do it 'strips name' do
achievement = described_class.new(name: ' AchievementTest ') achievement = build(:achievement, name: ' AchievementTest ')
achievement.valid? achievement.valid?
expect(achievement.name).to eq('AchievementTest') expect(achievement.name).to eq('AchievementTest')
end end
end end
it_behaves_like Avatarable do
let(:model) { create(:achievement, :with_avatar) }
end
end end
...@@ -96,31 +96,8 @@ ...@@ -96,31 +96,8 @@
end end
end end
describe '#avatar_type' do it_behaves_like Avatarable do
it "is true if avatar is image" do let(:model) { create(:topic, :with_avatar) }
topic.update_attribute(:avatar, 'uploads/avatar.png')
expect(topic.avatar_type).to be_truthy
end
it "is false if avatar is html page" do
topic.update_attribute(:avatar, 'uploads/avatar.html')
topic.avatar_type
expect(topic.errors.added?(:avatar, "file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico, webp")).to be true
end
end
describe '#avatar_url' do
context 'when avatar file is uploaded' do
before do
topic.update!(avatar: fixture_file_upload("spec/fixtures/dk.png"))
end
it 'shows correct avatar url' do
expect(topic.avatar_url).to eq(topic.avatar.url)
expect(topic.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, topic.avatar.url].join)
end
end
end end
describe '#title_or_name' do describe '#title_or_name' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册