Skip to content

Commit

Permalink
Fix expectation with changed attribute mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Mar 16, 2021
1 parent 803fedd commit bcb534a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions lib/api/v3/users/user_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class UserRepresenter < ::API::V3::Principals::PrincipalRepresenter
getter: ->(*) { represented.mail },
setter: ->(fragment:, represented:, **) { represented.mail = fragment },
exec_context: :decorator,
cache_if: -> { !represented.pref.hide_mail || represented.new_record? }
cache_if: -> { !represented.pref.hide_mail || represented.new_record? || current_user_can_manage? }

property :avatar,
exec_context: :decorator,
Expand All @@ -149,10 +149,7 @@ class UserRepresenter < ::API::V3::Principals::PrincipalRepresenter
setter: ->(fragment:, represented:, **) { represented.status = User.statuses[fragment.to_sym] },
exec_context: :decorator,
render_nil: true,
cache_if: -> {
binding.pry
current_user_can_manage?
}
cache_if: -> { current_user_can_manage? }

property :identity_url,
exec_context: :decorator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TestRepresenter < ::API::Decorators::Single
describe '.create_link_lambda' do
subject(:link) do
TestRepresenter
.new(represented, current_user: nil)
.new(represented, current_user: current_user)
.instance_exec(&described_class.create_link_lambda('association'))
end

Expand Down Expand Up @@ -127,7 +127,7 @@ class TestRepresenter < ::API::Decorators::Single
describe '.create_getter_lambda' do
subject(:getter) do
TestRepresenter
.new(represented, current_user: nil, embed_links: embed_links)
.new(represented, current_user: current_user, embed_links: embed_links)
.instance_exec(&described_class.create_getter_lambda('association'))
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/v3/user/create_user_common_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

expect(errors.count).to eq(5)
expect(errors.collect { |el| el['_embedded']['details']['attribute'] })
.to contain_exactly('password', 'login', 'firstname', 'lastname', 'email')
.to contain_exactly('password', 'login', 'firstName', 'lastName', 'email')

expect(last_response.body)
.to be_json_eql('urn:openproject-org:api:v3:errors:MultipleErrors'.to_json)
Expand Down Expand Up @@ -131,7 +131,7 @@
expect(errors.count).to eq 4

attributes = errors.map { |error| error.dig('_embedded', 'details', 'attribute') }
expect(attributes).to contain_exactly('login', 'firstname', 'lastname', 'email')
expect(attributes).to contain_exactly('login', 'firstName', 'lastName', 'email')
end
end
end
Expand Down

0 comments on commit bcb534a

Please sign in to comment.