Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#41299] fixed unit test expectations

Eric Schubertd3edd1531e87
diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.yml
index b2d8b5b555c..30ae39bbb87 100644
--- a/docs/api/apiv3/openapi-spec.yml
+++ b/docs/api/apiv3/openapi-spec.yml
@@ -256,6 +256,10 @@ paths:
"$ref": "./paths/oauth_application.yml"
"/api/v3/oauth_client_credentials/{id}":
"$ref": "./paths/oauth_client_credentials.yml"
+ "/api/v3/placeholder_users":
+ "$ref": "./paths/placeholder_users.yml"
+ "/api/v3/placeholder_users/{id}":
+ "$ref": "./paths/placeholder_user.yml"
"/api/v3/posts/{id}":
"$ref": "./paths/post.yml"
"/api/v3/posts/{id}/attachments":
@@ -677,6 +681,8 @@ components:
"$ref": "./components/schemas/paginated_collection_model.yml"
PlaceholderUserCollectionModel:
"$ref": "./components/schemas/placeholder_user_collection_model.yml"
+ PlaceholderUserCreateModel:
+ "$ref": "./components/schemas/placeholder_user_create_model.yml"
PlaceholderUserModel:
"$ref": "./components/schemas/placeholder_user_model.yml"
Plain_TextModel:
diff --git a/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb b/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
index 122056d9eb1..3648a4f8441 100644
--- a/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
end
describe '_links' do
- context 'self' do
+ describe 'self' do
it_behaves_like 'has a titled link' do
let(:link) { 'self' }
let(:href) { api_v3_paths.placeholder_user placeholder_user.id }
@@ -67,19 +67,19 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
end
end
- context 'showUser' do
+ describe 'showUser' do
it_behaves_like 'has an untitled link' do
let(:link) { 'showUser' }
let(:href) { "/placeholder_users/#{placeholder_user.id}" }
end
end
- context 'delete' do
+ describe 'delete' do
it_behaves_like 'has no link' do
let(:link) { 'delete' }
end
- context 'when user allowed to manage' do
+ context 'if user is allowed to manage' do
let(:global_permissions) { [:manage_placeholder_user] }
it_behaves_like 'has a titled link' do
@@ -91,7 +91,7 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
end
end
- context 'updateImmediately' do
+ describe 'updateImmediately' do
it_behaves_like 'has no link' do
let(:link) { 'updateImmediately' }
end
@@ -108,28 +108,28 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
end
end
- context 'memberships' do
+ describe 'memberships' do
it_behaves_like 'has no link' do
let(:link) { 'memberships' }
end
- context 'user allowed to see members' do
+ context 'if user is allowed to see members' do
let(:project_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) }
+ let(:title) { I18n.t(:label_membership_plural) }
end
end
- context 'user allowed to manage members' do
+ context 'if user is allowed to manage members' do
let(:project_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) }
+ let(:title) { I18n.t(:label_membership_plural) }
end
end
end
@@ -181,12 +181,15 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
describe 'caching' do
it 'is based on the representer\'s cache_key' do
- expect(OpenProject::Cache)
+ allow(OpenProject::Cache)
.to receive(:fetch)
- .with(representer.json_cache_key)
.and_call_original
representer.to_json
+
+ expect(OpenProject::Cache)
+ .to have_received(:fetch)
+ .with(representer.json_cache_key)
end
describe '#json_cache_key' do
@@ -205,7 +208,7 @@ RSpec.describe API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering
end
it 'changes when the placeholder is updated' do
- placeholder_user.updated_at = Time.now + 20.seconds
+ placeholder_user.updated_at = 20.seconds.from_now
expect(representer.json_cache_key)
.not_to eql former_cache_key
diff --git a/spec/lib/api/v3/users/user_representer_spec.rb b/spec/lib/api/v3/users/user_representer_spec.rb
index 877052a520a..fe12cac792a 100644
--- a/spec/lib/api/v3/users/user_representer_spec.rb
+++ b/spec/lib/api/v3/users/user_representer_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe API::V3::Users::UserRepresenter do
include API::V3::Utilities::PathHelper
- context 'generation' do
+ describe 'generation' do
subject(:generated) { representer.to_json }
it do
@@ -114,13 +114,13 @@ RSpec.describe API::V3::Users::UserRepresenter do
end
end
- context 'user shows his E-Mail address' do
+ context 'if user shows his E-Mail address' do
let(:preference) { build(:user_preference, hide_mail: false) }
it_behaves_like 'shows the users E-Mail address'
end
- context 'user hides his E-Mail address' do
+ context 'if user hides his E-Mail address' do
let(:preference) { build(:user_preference, hide_mail: true) }
it 'does not render the users E-Mail address' do
@@ -156,7 +156,7 @@ RSpec.describe API::V3::Users::UserRepresenter do
expect(subject).to have_json_path('_links/self/href')
end
- context 'showUser' do
+ describe 'showUser' do
it_behaves_like 'has an untitled link' do
let(:link) { 'showUser' }
let(:href) { "/users/#{user.id}" }
@@ -197,8 +197,8 @@ RSpec.describe API::V3::Users::UserRepresenter do
context 'when deletion is allowed' do
before do
allow(Users::DeleteContract).to receive(:deletion_allowed?)
- .with(user, current_user)
- .and_return(true)
+ .with(user, current_user)
+ .and_return(true)
end
it 'links to delete' do
@@ -210,8 +210,8 @@ RSpec.describe API::V3::Users::UserRepresenter do
context 'when deletion is allowed' do
before do
allow(Users::DeleteContract).to receive(:deletion_allowed?)
- .with(user, current_user)
- .and_return(true)
+ .with(user, current_user)
+ .and_return(true)
end
it 'links to delete' do
@@ -222,8 +222,8 @@ RSpec.describe API::V3::Users::UserRepresenter do
context 'when deletion is not allowed' do
before do
allow(Users::DeleteContract).to receive(:deletion_allowed?)
- .with(user, current_user)
- .and_return(false)
+ .with(user, current_user)
+ .and_return(false)
end
it 'does not link to delete' do
@@ -252,7 +252,7 @@ RSpec.describe API::V3::Users::UserRepresenter do
it_behaves_like 'has a titled link' do
let(:link) { 'memberships' }
- let(:title) { I18n.t(:label_member_plural) }
+ let(:title) { I18n.t(:label_membership_plural) }
end
end
@@ -261,7 +261,7 @@ RSpec.describe API::V3::Users::UserRepresenter do
it_behaves_like 'has a titled link' do
let(:link) { 'memberships' }
- let(:title) { I18n.t(:label_member_plural) }
+ let(:title) { I18n.t(:label_membership_plural) }
end
end
@@ -277,12 +277,15 @@ RSpec.describe API::V3::Users::UserRepresenter do
describe 'caching' do
it 'is based on the representer\'s cache_key' do
- expect(OpenProject::Cache)
+ allow(OpenProject::Cache)
.to receive(:fetch)
- .with(representer.json_cache_key)
- .and_call_original
+ .and_call_original
representer.to_json
+
+ expect(OpenProject::Cache)
+ .to have_received(:fetch)
+ .with(representer.json_cache_key)
end
describe '#json_cache_key' do
@@ -308,7 +311,7 @@ RSpec.describe API::V3::Users::UserRepresenter do
end
it 'changes when the user is updated' do
- user.updated_at = Time.now + 20.seconds
+ user.updated_at = 20.seconds.from_now
expect(representer.json_cache_key)
.not_to eql former_cache_key
diff --git a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb
index 37e5f64fa4b..562f0dbf73b 100644
--- a/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb
+++ b/spec/requests/api/v3/placeholder_users/delete_resource_examples.rb
@@ -26,8 +26,8 @@
# See COPYRIGHT and LICENSE files for more details.
RSpec.shared_examples 'deletion allowed' do
- it 'responds with 202' do
- expect(last_response.status).to eq 202
+ it 'responds with 204' do
+ expect(last_response.status).to eq 204
end
it 'locks the account and mark for deletion' do
@@ -51,6 +51,6 @@ RSpec.shared_examples 'deletion is not allowed' do
end
it 'does not delete the user' do
- expect(PlaceholderUser.exists?(placeholder.id)).to be_truthy
+ expect(PlaceholderUser).to exist(placeholder.id)
end
end