Skip to content

Commit

Permalink
inserção do campo senha no banco de dados
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricio-araujoo committed May 21, 2024
1 parent 7f00592 commit 26b11b9
Show file tree
Hide file tree
Showing 29 changed files with 210 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backend/app/controllers/cargos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def set_cargo

# Only allow a list of trusted parameters through.
def cargo_params
params.require(:cargo).permit(:cargos)
params.require(:cargo).permit(:nome)
end
end
4 changes: 2 additions & 2 deletions backend/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "bcrypt"
class UsersController < ApplicationController
before_action :set_user, only: %i[ show edit update destroy ]

# GET /users or /users.json
def index
@users = User.all
end

# GET /users/1 or /users/1.json
def show
end
Expand Down Expand Up @@ -65,6 +65,6 @@ def set_user

# Only allow a list of trusted parameters through.
def user_params
params.require(:user).permit(:matricula, :nome, :email)
params.require(:user).permit(:nome, :matricula, :email, :senha, :cargo_id)
end
end
1 change: 0 additions & 1 deletion backend/app/models/cargo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class Cargo < ApplicationRecord
has_many :users
end
7 changes: 7 additions & 0 deletions backend/app/views/cargos/_cargo.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="<%= dom_id cargo %>">
<p>
<strong>Nome:</strong>
<%= cargo.nome %>
</p>

</div>
2 changes: 2 additions & 0 deletions backend/app/views/cargos/_cargo.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! cargo, :id, :nome, :created_at, :updated_at
json.url cargo_url(cargo, format: :json)
22 changes: 22 additions & 0 deletions backend/app/views/cargos/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_with(model: cargo) do |form| %>
<% if cargo.errors.any? %>
<div style="color: red">
<h2><%= pluralize(cargo.errors.count, "error") %> prohibited this cargo from being saved:</h2>

<ul>
<% cargo.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :nome, style: "display: block" %>
<%= form.text_field :nome %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
10 changes: 10 additions & 0 deletions backend/app/views/cargos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing cargo</h1>

<%= render "form", cargo: @cargo %>

<br>

<div>
<%= link_to "Show this cargo", @cargo %> |
<%= link_to "Back to cargos", cargos_path %>
</div>
14 changes: 14 additions & 0 deletions backend/app/views/cargos/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Cargos</h1>

<div id="cargos">
<% @cargos.each do |cargo| %>
<%= render cargo %>
<p>
<%= link_to "Show this cargo", cargo %>
</p>
<% end %>
</div>

<%= link_to "New cargo", new_cargo_path %>
1 change: 1 addition & 0 deletions backend/app/views/cargos/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @cargos, partial: "cargos/cargo", as: :cargo
9 changes: 9 additions & 0 deletions backend/app/views/cargos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New cargo</h1>

<%= render "form", cargo: @cargo %>

<br>

<div>
<%= link_to "Back to cargos", cargos_path %>
</div>
10 changes: 10 additions & 0 deletions backend/app/views/cargos/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @cargo %>

<div>
<%= link_to "Edit this cargo", edit_cargo_path(@cargo) %> |
<%= link_to "Back to cargos", cargos_path %>

<%= button_to "Destroy this cargo", @cargo, method: :delete %>
</div>
1 change: 1 addition & 0 deletions backend/app/views/cargos/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "cargos/cargo", cargo: @cargo
42 changes: 42 additions & 0 deletions backend/app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<%= form_with(model: user) do |form| %>
<% if user.errors.any? %>
<div style="color: red">
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% user.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :nome, style: "display: block" %>
<%= form.text_field :nome %>
</div>

<div>
<%= form.label :matricula, style: "display: block" %>
<%= form.text_field :matricula %>
</div>

<div>
<%= form.label :email, style: "display: block" %>
<%= form.text_field :email %>
</div>

<div>
<%= form.label :senha, style: "display: block" %>
<%= form.text_field :senha %>
</div>

<div>
<%= form.label :cargo_id, style: "display: block" %>
<%= form.text_field :cargo_id %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
27 changes: 27 additions & 0 deletions backend/app/views/users/_user.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div id="<%= dom_id user %>">
<p>
<strong>Nome:</strong>
<%= user.nome %>
</p>

<p>
<strong>Matricula:</strong>
<%= user.matricula %>
</p>

<p>
<strong>Email:</strong>
<%= user.email %>
</p>

<p>
<strong>Senha:</strong>
<%= user.senha %>
</p>

<p>
<strong>Cargo:</strong>
<%= user.cargo_id %>
</p>

</div>
2 changes: 2 additions & 0 deletions backend/app/views/users/_user.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! user, :id, :nome, :matricula, :email, :senha, :cargo_id, :created_at, :updated_at
json.url user_url(user, format: :json)
10 changes: 10 additions & 0 deletions backend/app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing user</h1>

<%= render "form", user: @user %>

<br>

<div>
<%= link_to "Show this user", @user %> |
<%= link_to "Back to users", users_path %>
</div>
14 changes: 14 additions & 0 deletions backend/app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Users</h1>

<div id="users">
<% @users.each do |user| %>
<%= render user %>
<p>
<%= link_to "Show this user", user %>
</p>
<% end %>
</div>

<%= link_to "New user", new_user_path %>
1 change: 1 addition & 0 deletions backend/app/views/users/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @users, partial: "users/user", as: :user
9 changes: 9 additions & 0 deletions backend/app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New user</h1>

<%= render "form", user: @user %>

<br>

<div>
<%= link_to "Back to users", users_path %>
</div>
10 changes: 10 additions & 0 deletions backend/app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @user %>

<div>
<%= link_to "Edit this user", edit_user_path(@user) %> |
<%= link_to "Back to users", users_path %>

<%= button_to "Destroy this user", @user, method: :delete %>
</div>
1 change: 1 addition & 0 deletions backend/app/views/users/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "users/user", user: @user
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def change
t.string :nome
t.string :matricula
t.string :email
t.string :senha
t.references :cargo, null: false, foreign_key: true

t.timestamps
Expand Down
3 changes: 2 additions & 1 deletion backend/db/schema.rb

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

4 changes: 2 additions & 2 deletions backend/test/controllers/cargos_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CargosControllerTest < ActionDispatch::IntegrationTest

test "should create cargo" do
assert_difference("Cargo.count") do
post cargos_url, params: { cargo: { cargos: @cargo.cargos } }
post cargos_url, params: { cargo: { nome: @cargo.nome } }
end

assert_redirected_to cargo_url(Cargo.last)
Expand All @@ -34,7 +34,7 @@ class CargosControllerTest < ActionDispatch::IntegrationTest
end

test "should update cargo" do
patch cargo_url(@cargo), params: { cargo: { cargos: @cargo.cargos } }
patch cargo_url(@cargo), params: { cargo: { nome: @cargo.nome } }
assert_redirected_to cargo_url(@cargo)
end

Expand Down
4 changes: 2 additions & 2 deletions backend/test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest

test "should create user" do
assert_difference("User.count") do
post users_url, params: { user: { email: @user.email, matricula: @user.matricula, nome: @user.nome } }
post users_url, params: { user: { cargo_id: @user.cargo_id, email: @user.email, matricula: @user.matricula, nome: @user.nome, senha: @user.senha } }
end

assert_redirected_to user_url(User.last)
Expand All @@ -34,7 +34,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
end

test "should update user" do
patch user_url(@user), params: { user: { email: @user.email, matricula: @user.matricula, nome: @user.nome } }
patch user_url(@user), params: { user: { cargo_id: @user.cargo_id, email: @user.email, matricula: @user.matricula, nome: @user.nome, senha: @user.senha } }
assert_redirected_to user_url(@user)
end

Expand Down
2 changes: 2 additions & 0 deletions backend/test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ one:
nome: MyString
matricula: MyString
email: MyString
senha: MyString
cargo: one

two:
nome: MyString
matricula: MyString
email: MyString
senha: MyString
cargo: two
4 changes: 2 additions & 2 deletions backend/test/system/cargos_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CargosTest < ApplicationSystemTestCase
visit cargos_url
click_on "New cargo"

fill_in "Cargos", with: @cargo.cargos
fill_in "Nome", with: @cargo.nome
click_on "Create Cargo"

assert_text "Cargo was successfully created"
Expand All @@ -25,7 +25,7 @@ class CargosTest < ApplicationSystemTestCase
visit cargo_url(@cargo)
click_on "Edit this cargo", match: :first

fill_in "Cargos", with: @cargo.cargos
fill_in "Nome", with: @cargo.nome
click_on "Update Cargo"

assert_text "Cargo was successfully updated"
Expand Down
4 changes: 4 additions & 0 deletions backend/test/system/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ class UsersTest < ApplicationSystemTestCase
visit users_url
click_on "New user"

fill_in "Cargo", with: @user.cargo_id
fill_in "Email", with: @user.email
fill_in "Matricula", with: @user.matricula
fill_in "Nome", with: @user.nome
fill_in "Senha", with: @user.senha
click_on "Create User"

assert_text "User was successfully created"
Expand All @@ -27,9 +29,11 @@ class UsersTest < ApplicationSystemTestCase
visit user_url(@user)
click_on "Edit this user", match: :first

fill_in "Cargo", with: @user.cargo_id
fill_in "Email", with: @user.email
fill_in "Matricula", with: @user.matricula
fill_in "Nome", with: @user.nome
fill_in "Senha", with: @user.senha
click_on "Update User"

assert_text "User was successfully updated"
Expand Down

0 comments on commit 26b11b9

Please sign in to comment.