Placeholder user project members (#8961)
* remove intermediate placeholder scope Doing so, placeholder users will begin to show up in the system * remove scope without value * extract scope * use enum for status * allow placeholder users to become project members * display placeholder user member on members widget * remove now superfluous method The status name can simply be queried via #status now * replace possible_assignees/responsibles on project This also leads to placeholder users becoming eligible as assignees and responsibles. * fix aggregated scope on bulk edit * linting * remove IssueHelperpull/8971/head
parent
29eed9d536
commit
5ea185ef66
@ -1,64 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module IssuesHelper |
||||
include ApplicationHelper |
||||
|
||||
# Renders a HTML/CSS tooltip |
||||
# |
||||
# To use, a trigger div is needed. This is a div with the class of "tooltip" |
||||
# that contains this method wrapped in a span with the class of "tip" |
||||
# |
||||
# <div class="tooltip"><%= link_to_issue(issue) %> |
||||
# <span class="tip"><%= render_issue_tooltip(issue) %></span> |
||||
# </div> |
||||
# |
||||
def render_issue_tooltip(issue) |
||||
@cached_label_status ||= WorkPackage.human_attribute_name(:status) |
||||
@cached_label_start_date ||= WorkPackage.human_attribute_name(:start_date) |
||||
@cached_label_due_date ||= WorkPackage.human_attribute_name(:due_date) |
||||
@cached_label_assigned_to ||= WorkPackage.human_attribute_name(:assigned_to) |
||||
@cached_label_priority ||= WorkPackage.human_attribute_name(:priority) |
||||
@cached_label_project ||= WorkPackage.human_attribute_name(:project) |
||||
|
||||
(link_to_work_package(issue) + "<br /><br /> |
||||
<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br /> |
||||
<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br /> |
||||
<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br /> |
||||
<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br /> |
||||
<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br /> |
||||
<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe) |
||||
end |
||||
|
||||
def last_issue_note(issue) |
||||
note_journals = issue.journals.select(&:notes?) |
||||
return t(:text_no_notes) if note_journals.empty? |
||||
note_journals.last.notes |
||||
end |
||||
end |
@ -0,0 +1,42 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
# Only return Principals that are, direct or indirect humans. |
||||
# Includes |
||||
# * User |
||||
# * Group |
||||
module Principals::Scopes |
||||
class Human |
||||
def self.fetch |
||||
Principal.where(type: [::User.name, |
||||
Group.name]) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,53 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
# Returns principals whose |
||||
# * login |
||||
# * firstname |
||||
# * lastname |
||||
# matches the provided string |
||||
module Principals::Scopes |
||||
class Like |
||||
def self.fetch(search_string) |
||||
firstnamelastname = "((firstname || ' ') || lastname)" |
||||
lastnamefirstname = "((lastname || ' ') || firstname)" |
||||
|
||||
s = "%#{search_string.to_s.downcase.strip.tr(',', '')}%" |
||||
|
||||
Principal |
||||
.where(['LOWER(login) LIKE :s OR ' + |
||||
"LOWER(#{firstnamelastname}) LIKE :s OR " + |
||||
"LOWER(#{lastnamefirstname}) LIKE :s OR " + |
||||
'LOWER(mail) LIKE :s', |
||||
{ s: s }]) |
||||
.order(:type, :login, :lastname, :firstname, :mail) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,45 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
# Only return Principals that are not built into the system so only return those that where |
||||
# created by a human. |
||||
# Excludes |
||||
# * DeletedUser |
||||
# * SystemUser |
||||
# * AnonymousUser |
||||
module Principals::Scopes |
||||
class NotBuiltin |
||||
def self.fetch |
||||
Principal.where.not(type: [SystemUser.name, |
||||
AnonymousUser.name, |
||||
DeletedUser.name]) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,52 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Principals::Scopes |
||||
class PossibleAssignee |
||||
# Returns principals eligible to be assigned to a work package as: |
||||
# * assignee |
||||
# * responsible |
||||
# Those principals can be of class |
||||
# * User |
||||
# * PlaceholderUser |
||||
# * Group |
||||
# User instances need to be non locked (status). |
||||
# Only principals with a role marked as assignable in the project are returned. |
||||
# @project [Project] The project for which eligible candidates are to be searched |
||||
# @return [ActiveRecord::Relation] A scope of eligible candidates |
||||
def self.fetch(project) |
||||
Principal |
||||
.not_locked |
||||
.includes(:members) |
||||
.references(:members) |
||||
.merge(Member.assignable.of(project)) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,49 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Principals::Scopes |
||||
class PossibleMember |
||||
# Returns principals eligible to become project members. Those principals can be of class |
||||
# * User |
||||
# * PlaceholderUser |
||||
# * Group |
||||
# User instances need to be non locked (status) |
||||
# Principals which already are project members are are returned. |
||||
# @project [Project] The project for which eligible candidates are to be searched |
||||
# @return [ActiveRecord::Relation] A scope of eligible candidates |
||||
def self.fetch(project) |
||||
Queries::Principals::PrincipalQuery |
||||
.new(user: ::User.current) |
||||
.where(:member, '!', [project.id]) |
||||
.where(:status, '!', [Principal.statuses[:locked]]) |
||||
.results |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,40 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
# Only return Principals that are of type User |
||||
module Principals::Scopes |
||||
class User |
||||
def self.fetch |
||||
# Have to use the User model here so that the scopes defined on User |
||||
# are also available after the scope is used. |
||||
::User.where(type: [::User.name]) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
# Returns users sorted by their creation date. Inheriting classes are |
||||
# excluded. |
||||
module Users::Scopes |
||||
class Newest |
||||
def self.fetch |
||||
User.user.order(created_at: :desc) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,41 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module PlaceholderUsers |
||||
class PlaceholderUserRepresenter < ::API::V3::Principals::PrincipalRepresenter |
||||
def _type |
||||
'PlaceholderUser' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,173 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering' do |
||||
include ::API::V3::Utilities::PathHelper |
||||
|
||||
let(:placeholder_user) { FactoryBot.build_stubbed(:placeholder_user) } |
||||
let(:current_user) { FactoryBot.build_stubbed(:user) } |
||||
let(:representer) { described_class.new(placeholder_user, current_user: current_user) } |
||||
let(:memberships_path) do |
||||
filters = [ |
||||
{ |
||||
principal: { |
||||
operator: '=', |
||||
values: [placeholder_user.id.to_s] |
||||
} |
||||
} |
||||
] |
||||
|
||||
api_v3_paths.path_for(:memberships, filters: filters) |
||||
end |
||||
let(:global_permissions) { [] } |
||||
|
||||
subject(:generated) { representer.to_json } |
||||
|
||||
before do |
||||
allow(current_user) |
||||
.to receive(:allowed_to_globally?) do |requested_permission| |
||||
global_permissions.include?(requested_permission) |
||||
end |
||||
end |
||||
|
||||
describe '_links' do |
||||
context 'self' do |
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'self' } |
||||
let(:href) { api_v3_paths.placeholder_user placeholder_user.id } |
||||
let(:title) { placeholder_user.name } |
||||
end |
||||
end |
||||
|
||||
context 'memberships' do |
||||
it_behaves_like 'has no link' do |
||||
let(:link) { 'memberships' } |
||||
end |
||||
|
||||
context 'user allowed to see members' do |
||||
let(:global_permissions) { [:view_members] } |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'memberships' } |
||||
let(:href) { memberships_path } |
||||
let(:title) { I18n.t(:label_member_plural) } |
||||
end |
||||
end |
||||
|
||||
context 'user allowed to manage members' do |
||||
let(:global_permissions) { [:manage_members] } |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'memberships' } |
||||
let(:href) { memberships_path } |
||||
let(:title) { I18n.t(:label_member_plural) } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'properties' do |
||||
it_behaves_like 'property', :_type do |
||||
let(:value) { 'PlaceholderUser' } |
||||
end |
||||
|
||||
context 'as regular user' do |
||||
it_behaves_like 'property', :id do |
||||
let(:value) { placeholder_user.id } |
||||
end |
||||
|
||||
it_behaves_like 'property', :name do |
||||
let(:value) { placeholder_user.name } |
||||
end |
||||
|
||||
it 'hides the updatedAt property' do |
||||
is_expected.not_to have_json_path('updatedAt') |
||||
end |
||||
|
||||
it 'hides the createdAt property' do |
||||
is_expected.not_to have_json_path('createdAt') |
||||
end |
||||
end |
||||
|
||||
context 'as admin' do |
||||
let(:current_user) { FactoryBot.build_stubbed(:admin) } |
||||
|
||||
it_behaves_like 'property', :id do |
||||
let(:value) { placeholder_user.id } |
||||
end |
||||
|
||||
it_behaves_like 'property', :name do |
||||
let(:value) { placeholder_user.name } |
||||
end |
||||
|
||||
it_behaves_like 'datetime property', :createdAt do |
||||
let(:value) { placeholder_user.created_at } |
||||
end |
||||
|
||||
it_behaves_like 'datetime property', :updatedAt do |
||||
let(:value) { placeholder_user.updated_at } |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'caching' do |
||||
it 'is based on the representer\'s cache_key' do |
||||
expect(OpenProject::Cache) |
||||
.to receive(:fetch) |
||||
.with(representer.json_cache_key) |
||||
.and_call_original |
||||
|
||||
representer.to_json |
||||
end |
||||
|
||||
describe '#json_cache_key' do |
||||
let!(:former_cache_key) { representer.json_cache_key } |
||||
|
||||
it 'includes the name of the representer class' do |
||||
expect(representer.json_cache_key) |
||||
.to include('API', 'V3', 'PlaceholderUsers', 'PlaceholderUserRepresenter') |
||||
end |
||||
|
||||
it 'changes when the locale changes' do |
||||
I18n.with_locale(:fr) do |
||||
expect(representer.json_cache_key) |
||||
.not_to eql former_cache_key |
||||
end |
||||
end |
||||
|
||||
it 'changes when the placeholder is updated' do |
||||
placeholder_user.updated_at = Time.now + 20.seconds |
||||
|
||||
expect(representer.json_cache_key) |
||||
.not_to eql former_cache_key |
||||
end |
||||
end |
||||
end |
||||
end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue