Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 10, 2020
1 parent 21eff6d commit 02735a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ def update

if exists
authorize! :update, @user
@user.assign_attributes(safe_params.except(:uid))
@user.assign_attributes(safe_params)
status = :ok
else
@user = User.new(safe_params.merge(uid: params["id"], provider: "globus"))
@user = User.new(safe_params.merge(uid: params[:id], provider: "globus"))
authorize! :new, @user
status = :created
end

if @user.save
options = {}
options[:is_collection] = false
render json: UserSerializer.new(@user, options).serialized_json, status: :ok
render json: UserSerializer.new(@user, options).serialized_json, status: status
else
logger.error @user.errors.inspect
render json: serialize_errors(@user.errors), status: :unprocessable_entity
Expand All @@ -131,7 +133,7 @@ def destroy

def load_user
@user = User.where(uid: params[:id]).first
fail ActiveRecord::RecordNotFound unless @user.present?
fail ActiveRecord::RecordNotFound if @user.blank?
end

def set_include
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
end

context 'when the record doesn\'t exist', vcr:true do
let(:new_user) { FactoryBot.build(:user, uid: "0000-0001-6528-2027", name: "Martin Fenner") }
let(:new_user) { FactoryBot.build(:user, uid: "0000-0002-0989-1335", name: "Ogechukwu Alozie") }
let(:params) do
{ "data" => { "type" => "users",
"attributes" => {
Expand All @@ -124,7 +124,7 @@
it 'updates the record' do
put "/users/#{new_user.uid}", params, headers

expect(last_response.status).to eq(200)
expect(last_response.status).to eq(201)
expect(json.dig('data', 'attributes', 'name')).to eq(new_user.name)
end
end
Expand Down

0 comments on commit 02735a1

Please sign in to comment.