OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/modules/avatars/spec/helpers/avatar_helper_spec.rb

211 lines
6.8 KiB

require 'spec_helper'
describe AvatarHelper, type: :helper, with_settings: { protocol: 'http' } do
let(:user) { FactoryBot.build_stubbed(:user) }
let(:mail_digest) { Digest::MD5.hexdigest(user.mail) }
let(:avatar_stub) { FactoryBot.build_stubbed(:avatar_attachment) }
let(:enable_gravatars) { false }
let(:enable_local_avatars) { false }
let(:plugin_settings) do
{
'enable_gravatars' => enable_gravatars,
Boards module (#7008) * Hack spike to show D&D use case [ci skip] * Add ordered work packages * Save order on existing work packages * Boards WIP * CDK drag * Add dragula handler [ci skip] * Add filter to return all manual sorted work packages * Print icon on hover * Boards routing and list components * Better loading indicator on list with streaming result [ci skip] * Add new board and list buttons [ci skip] * Post new query [ci skip] * Added creation of new board lists with persisted queries [ci skip] * Render placeholder row in empty queries [ci skip] * Push boards on grid * Use base class in scope [ci skip] * Extend api for options * Hack spike to show D&D use case [ci skip] * Add ordered work packages * Save order on existing work packages * Boards WIP * CDK drag * Add dragula handler [ci skip] * Add filter to return all manual sorted work packages * Print icon on hover * Boards routing and list components * Better loading indicator on list with streaming result [ci skip] * Add new board and list buttons [ci skip] * Post new query [ci skip] * Added creation of new board lists with persisted queries [ci skip] * Render placeholder row in empty queries [ci skip] * Save queries in grids [ci skip] * Renaming queries [ci skip] * Add existing work packages to board [ci skip] * Introduce card view component for work packages * Extend grids to allow project scope for boards (#7025) Extends the grid backend to also be able to handle boards. In particular, it adds the ability of boards to be attached to projects and changes the page property of grids to a scope property that better describes that more than one board can belong to the same scope (e.g. /projects/:project_id/boards). For a fully featured board, though, widgets need to be able to store options, so that they can store queries. Those widgets might also need to have custom processing and validation. That part has not been implemented. * introduce project association for boards * have dedicated grid registration classes * update and create form for board grids * extract defaults into grid registration [ci skip] * Add drag and drop to card view [ci skip] * Add options to grid * Fix option migration name * Renaming boards [ci skip] * Frontend deletion of boards * Avoid map on NodeList which doesnt exist [ci skip] * Add inline create to boards [ci skip] * Smaller create button [ci skip] * Add navigation for boards * Make inner grid same height * Replace index page with table * Workaround for widget registration [ci skip] * Fixed height for cards and tables [ci skip] * Implement escape as cancel d&d action [ci skip] * Fix and extend grid specs for name and options * Extend board specs for required name * Fix migration for MySQL references https://stackoverflow.com/a/45825566/420614 * Make board list extend from widget Since we cannot configure widgets yet, it's not yet possible to use a board-list widget anywhere. * Fix specs * Fix escape listener removal [ci skip] * Fix renamed to_path in relation spec [ci skip] * Allow deletion of grids for boards * Avoid reloading resource multiple times with replays * Frontend synchronization on deletion [ci skip] * Delete through table * Use work packages board path * Use work packages board path * Fix augmented columns breaking re-rendering * Fix duplicated permission with forums * Strengthen tab switch in specs * Add hidden flag for project-context queries Allows the API to create a hidden query that will not be rendered to the user even if it is within a project context. * private queries * Add hidden flag for project-context queries Allows the API to create a hidden query that will not be rendered to the user even if it is within a project context. * Move boards below work packages * Add Board configuration modal * Fix reloading with onPush * Saving / Switching of display mode [ci skip] * Extract wp-query-selectable-title into common component * Fix renaming of board-list * Fix auto-hide notifications in boards * Add permissions to seeders * Reorder lists in board * Linting * Remove default gravatar from settings * Show assignees avatar in the card view of WPs * Fix specs * Add missing method * Fix timeline icon * Use URL as input to be able to show avatars for groups, too * Fix test * Add further specs * Use correct data attribute to avoid unnecessary data base calls * Add further specs * Deletion of board lists * Pass permission via gon to decide whether we can create boards * Fix rename spec * Cherry-pick of 7873d59 and 30abc7f
6 years ago
'enable_local_avatars' => enable_local_avatars
}
end
before do
allow(Setting)
.to receive(:plugin_openproject_avatars)
.and_return(plugin_settings)
allow(user).to receive(:local_avatar_attachment).and_return avatar_stub
end
def local_expected_user_avatar_tag(user)
Refactor/user avatar to principal (#9069) * Fix some ium stylings * Extend create service to also test with empty names * Add PrincipalLike type to pass around non-created placeholder refs * Add icon-context * Move principal rendering to its own module * Fix emit create new placeholder to principals * Revert op-principal for now * Add memberships form API to properly post * Fix types for returned principals * Move untilDestroyed in role * Filter input if not string in role-search * Pass correct inputs to success component * Return principal after saving membership * Fix small stuff around the ium * Fix the way HalResources are selected and passed * Move principal module to be exported by common * Disable quotemark in tslint until eslint is enabled * Fix image path in success * Adapt modal to run all steps in one within the modal helper component * Several fixes to modals * Fix ium success component styles, * Registration modal y-overflow * Add SMTP parameters to .env.example * Add disabled option to op-option-list, disabled placeholder users for non-ee instances * Add correct ee link to placeholder user option * Fix build * Removed unused sass files * Fix principal search not found indicator, added placeholder add image * Fix enterprise edition url, use dirty instead of touched check * Use backend class names for frontend principal types * Fix duplicate import and principal type usage * Also disable banners if with_ee is present in test * Extend specs for placeholders * Fix disabled attribute * Extend spec WIP * Improved inline-validation styles, fixed more PrincipalType usages * Add group happy path test, fix more PrincipalType usage * Fix a translation * Revert line deletion * Rewrite same spec examples into shared examples * Fix name of shared example * Dont run assets:clean to remove angular assets * Output whether assets are there at all * Update user-avatar usages to principal * Fix some op-principal usages * Fix principal typing * Remove ls of non-existent directory * Rename more user-avatar instances * Avatars now render correctly * Fix an op-principal instance, default to avatar class for avatars * Always add principal id to default principal tag * Small fixes to op-principal * Fix multiline user display * Dirty fix for capybara click events * Update avatar sizing * Fixed some specs * Fix unit specs * Added op-link styles * Fix add placeholder image link * Remove byebug debugger statements Co-authored-by: Oliver Günther <mail@oliverguenther.de>
4 years ago
tag_options = { 'data-principal-id': user.id,
'data-principal-name': user.name,
'data-principal-type': 'user',
'data-hide-name': 'true',
'data-size': 'default' }
content_tag 'op-principal', '', tag_options
end
def local_expected_url(user)
user_avatar_url(user)
end
def default_expected_user_avatar_tag(user)
Refactor/user avatar to principal (#9069) * Fix some ium stylings * Extend create service to also test with empty names * Add PrincipalLike type to pass around non-created placeholder refs * Add icon-context * Move principal rendering to its own module * Fix emit create new placeholder to principals * Revert op-principal for now * Add memberships form API to properly post * Fix types for returned principals * Move untilDestroyed in role * Filter input if not string in role-search * Pass correct inputs to success component * Return principal after saving membership * Fix small stuff around the ium * Fix the way HalResources are selected and passed * Move principal module to be exported by common * Disable quotemark in tslint until eslint is enabled * Fix image path in success * Adapt modal to run all steps in one within the modal helper component * Several fixes to modals * Fix ium success component styles, * Registration modal y-overflow * Add SMTP parameters to .env.example * Add disabled option to op-option-list, disabled placeholder users for non-ee instances * Add correct ee link to placeholder user option * Fix build * Removed unused sass files * Fix principal search not found indicator, added placeholder add image * Fix enterprise edition url, use dirty instead of touched check * Use backend class names for frontend principal types * Fix duplicate import and principal type usage * Also disable banners if with_ee is present in test * Extend specs for placeholders * Fix disabled attribute * Extend spec WIP * Improved inline-validation styles, fixed more PrincipalType usages * Add group happy path test, fix more PrincipalType usage * Fix a translation * Revert line deletion * Rewrite same spec examples into shared examples * Fix name of shared example * Dont run assets:clean to remove angular assets * Output whether assets are there at all * Update user-avatar usages to principal * Fix some op-principal usages * Fix principal typing * Remove ls of non-existent directory * Rename more user-avatar instances * Avatars now render correctly * Fix an op-principal instance, default to avatar class for avatars * Always add principal id to default principal tag * Small fixes to op-principal * Fix multiline user display * Dirty fix for capybara click events * Update avatar sizing * Fixed some specs * Fix unit specs * Added op-link styles * Fix add placeholder image link * Remove byebug debugger statements Co-authored-by: Oliver Günther <mail@oliverguenther.de>
4 years ago
tag_options = { 'data-hide-name': 'true',
'data-principal-id': user.id,
'data-principal-name': user.name,
'data-principal-type': 'user',
'data-size': 'default'}
content_tag 'op-principal', '', tag_options
end
def gravatar_expected_url(digest, options = {})
ssl = !!options[:ssl]
host =
if ssl
'https://secure.gravatar.com'
else
'http://gravatar.com'
end
"#{host}/avatar/#{digest}?default=404&secure=#{ssl}"
end
describe 'gravatar and local' do
context 'when enabled' do
let(:enable_gravatars) { true }
let(:enable_local_avatars) { true }
it "should return the image attached to the user" do
expect(helper.avatar(user)).to be_html_eql(local_expected_user_avatar_tag(user))
end
it "should return the gravatar image if no image uploaded for the user" do
allow(user).to receive(:local_avatar_attachment).and_return nil
expect(helper.avatar(user)).to be_html_eql(default_expected_user_avatar_tag(user))
end
end
context 'when gravatar disabled' do
let(:enable_gravatars) { false }
let(:enable_local_avatars) { true }
it "should return blank if image attached to the user but gravatars disabled" do
expect(helper.avatar(user)).to be_html_eql(local_expected_user_avatar_tag(user))
end
end
context 'when all disabled' do
let(:enable_gravatars) { false }
let(:enable_local_avatars) { false }
it "should return blank" do
expect(helper.avatar(user)).to be_html_eql(default_expected_user_avatar_tag(user))
end
end
end
describe '#avatar_url' do
context 'when enabled' do
let(:enable_gravatars) { true }
let(:enable_local_avatars) { true }
it "should return the url to the image attached to the user" do
expect(helper.avatar_url(user)).to eq(local_expected_url(user))
end
it "should return the gravatar url if no image uploaded for the user" do
allow(user).to receive(:local_avatar_attachment).and_return nil
expect(helper.avatar_url(user)).to eq(gravatar_expected_url(mail_digest))
end
end
context 'when gravatar disabled' do
let(:enable_gravatars) { false }
let(:enable_local_avatars) { true }
it "should return the url if image attached to the user but gravatars disabled" do
expect(helper.avatar_url(user)).to eq(local_expected_url(user))
end
end
context 'when all disabled' do
let(:enable_gravatars) { false }
let(:enable_local_avatars) { false }
it "should return blank" do
expect(helper.avatar_url(user)).to eq ''
end
end
end
describe 'gravatar' do
context 'when enabled' do
let(:enable_gravatars) { true }
let(:enable_local_avatars) { false }
describe 'ssl dependent on protocol settings' do
context 'with https protocol', with_settings: { protocol: 'https' } do
it "should be set to secure if protocol is 'https'" do
expect(helper.default_gravatar_options[:secure]).to be true
end
end
context 'with http protocol', with_settings: { protocol: 'http' } do
it "should be set to unsecure if protocol is 'http'" do
expect(helper.default_gravatar_options[:secure]).to be false
end
end
end
context 'with http', with_settings: { protocol: 'http' } do
it 'should return a gravatar image tag if a user is provided' do
expect(helper.avatar(user)).to be_html_eql(default_expected_user_avatar_tag(user))
end
it 'should return a gravatar url if a user is provided' do
expect(helper.avatar_url(user)).to eq(gravatar_expected_url(mail_digest))
end
end
context 'with https', with_settings: { protocol: 'https' } do
it 'should return a gravatar image tag with ssl if the request was ssl required' do
expect(helper.avatar(user)).to be_html_eql(default_expected_user_avatar_tag(user))
end
it 'should return a gravatar image tag with ssl if the request was ssl required' do
expect(helper.avatar_url(user)).to eq(gravatar_expected_url(mail_digest, ssl: true))
end
end
it 'should return an empty string if a non parsable (e-mail) string is provided' do
expect(helper.avatar('just the name')).to eq('')
end
it 'should return an empty string if nil is provided' do
expect(helper.avatar(nil)).to eq('')
end
it 'should return an empty string if a parsable e-mail with default avatar is provided' do
mail = '<e-mail@mail.de>'
expect(helper.avatar(mail)).to eq('')
end
it 'should return an empty string if a non parsable (e-mail) string is provided' do
expect(helper.avatar_url('just the name')).to eq('')
end
it 'should return an empty string if nil is provided' do
expect(helper.avatar_url(nil)).to eq('')
end
end
end
context 'when all disabled' do
let(:enable_gravatars) { false }
let(:enable_local_avatars) { false }
it 'should return an empty string if gravatar is disabled' do
expect(helper.avatar(user)).to be_html_eql(default_expected_user_avatar_tag(user))
end
it 'should return an empty string if gravatar is disabled' do
expect(helper.avatar_url(user)).to eq('')
end
end
context 'with system user' do
let(:user) { User.system }
it 'renders the avatar as user type (Regression #37278)' do
expect(helper.avatar(user)).to be_html_eql(default_expected_user_avatar_tag(user))
end
end
end