Skip to content

Commit

Permalink
allow to create user in the users controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Jan 22, 2024
1 parent 6abbee8 commit 0e9f655
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def show
# This will use app/views/users/show.json.jbuilder
end

def create
@user = User.new(user_params)

if @user.save
render :show, status: :created, location: @user
else
render json: @user.errors, status: :unprocessable_entity
end
end

def update
ApplicationRecord.transaction do
@user.salaries.destroy_all
Expand Down
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class User < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged

validates :email, presence: true, uniqueness: true,
format: {
with: /\A[\w+\-.]+@#{ENV.fetch('VALID_USER_DOMAIN', nil)}\z/i,
message: "must be a #{ENV.fetch('VALID_USER_DOMAIN', nil)} account"
}
validates :email, presence: true, uniqueness: true
validates :email, format: {
with: /\A[\w+\-.]+@#{ENV.fetch('VALID_USER_DOMAIN', nil)}\z/i,
message: "must be a #{ENV.fetch('VALID_USER_DOMAIN', nil)} account"
}, if: :internal?

validates :google_id, presence: true, uniqueness: true, if: :internal?
validates :google_id, absence: true, unless: :internal?
Expand Down
1 change: 0 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
contract_type { FFaker::Lorem.word }
seniority { %w[Intern Junior Midlevel Senior].sample }
active { [true, false].sample }
internal { true }

profession

Expand Down

0 comments on commit 0e9f655

Please sign in to comment.