Skip to content

Commit

Permalink
[#41299] fixed unit test expectations
Browse files Browse the repository at this point in the history
- also fixed some older rubocop issues
  • Loading branch information
Kharonus committed Feb 13, 2024
1 parent adc9c21 commit 92775e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
6 changes: 6 additions & 0 deletions docs/api/apiv3/openapi-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@
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 }
let(:title) { placeholder_user.name }
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
Expand All @@ -91,7 +91,7 @@
end
end

context 'updateImmediately' do
describe 'updateImmediately' do
it_behaves_like 'has no link' do
let(:link) { 'updateImmediately' }
end
Expand All @@ -108,28 +108,28 @@
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
Expand Down Expand Up @@ -181,12 +181,15 @@

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
Expand All @@ -205,7 +208,7 @@
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
Expand Down
35 changes: 19 additions & 16 deletions spec/lib/api/v3/users/user_representer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

include API::V3::Utilities::PathHelper

context 'generation' do
describe 'generation' do
subject(:generated) { representer.to_json }

it do
Expand Down Expand Up @@ -114,13 +114,13 @@
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
Expand Down Expand Up @@ -156,7 +156,7 @@
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}" }
Expand Down Expand Up @@ -197,8 +197,8 @@
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
Expand All @@ -210,8 +210,8 @@
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
Expand All @@ -222,8 +222,8 @@
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
Expand Down Expand Up @@ -252,7 +252,7 @@

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

Expand All @@ -261,7 +261,7 @@

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

Expand All @@ -277,12 +277,15 @@

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
Expand All @@ -308,7 +311,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,6 +51,6 @@
end

it 'does not delete the user' do
expect(PlaceholderUser.exists?(placeholder.id)).to be_truthy
expect(PlaceholderUser).to exist(placeholder.id)
end
end

0 comments on commit 92775e2

Please sign in to comment.