Skip to content

Commit

Permalink
tabela de estoque
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricio-araujoo committed May 23, 2024
1 parent cd44a83 commit a44b452
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/app/helpers/estoques_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module EstoquesHelper
end
2 changes: 2 additions & 0 deletions backend/app/models/estoque.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Estoque < ApplicationRecord
end
1 change: 1 addition & 0 deletions backend/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class User < ApplicationRecord
belongs_to :cargo
has_many :estoques
end
2 changes: 2 additions & 0 deletions backend/app/views/estoques/_estoque.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div id="<%= dom_id estoque %>">
</div>
2 changes: 2 additions & 0 deletions backend/app/views/estoques/_estoque.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! estoque, :id, :created_at, :updated_at
json.url estoque_url(estoque, format: :json)
17 changes: 17 additions & 0 deletions backend/app/views/estoques/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_with(model: estoque) do |form| %>
<% if estoque.errors.any? %>
<div style="color: red">
<h2><%= pluralize(estoque.errors.count, "error") %> prohibited this estoque from being saved:</h2>

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

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

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

<br>

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

<h1>Estoques</h1>

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

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

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

<br>

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

<%= render @estoque %>

<div>
<%= link_to "Edit this estoque", edit_estoque_path(@estoque) %> |
<%= link_to "Back to estoques", estoques_path %>

<%= button_to "Destroy this estoque", @estoque, method: :delete %>
</div>
1 change: 1 addition & 0 deletions backend/app/views/estoques/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "estoques/estoque", estoque: @estoque
1 change: 1 addition & 0 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :estoques
resources :cargos
resources :users
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
Expand Down
8 changes: 8 additions & 0 deletions backend/db/migrate/20240523232810_create_estoques.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateEstoques < ActiveRecord::Migration[7.1]
def change
create_table :estoques do |t|

t.timestamps
end
end
end
14 changes: 13 additions & 1 deletion backend/db/schema.rb

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

48 changes: 48 additions & 0 deletions backend/test/controllers/estoques_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class EstoquesControllerTest < ActionDispatch::IntegrationTest
setup do
@estoque = estoques(:one)
end

test "should get index" do
get estoques_url
assert_response :success
end

test "should get new" do
get new_estoque_url
assert_response :success
end

test "should create estoque" do
assert_difference("Estoque.count") do
post estoques_url, params: { estoque: { } }
end

assert_redirected_to estoque_url(Estoque.last)
end

test "should show estoque" do
get estoque_url(@estoque)
assert_response :success
end

test "should get edit" do
get edit_estoque_url(@estoque)
assert_response :success
end

test "should update estoque" do
patch estoque_url(@estoque), params: { estoque: { } }
assert_redirected_to estoque_url(@estoque)
end

test "should destroy estoque" do
assert_difference("Estoque.count", -1) do
delete estoque_url(@estoque)
end

assert_redirected_to estoques_url
end
end
11 changes: 11 additions & 0 deletions backend/test/fixtures/estoques.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions backend/test/models/estoque_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class EstoqueTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
39 changes: 39 additions & 0 deletions backend/test/system/estoques_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "application_system_test_case"

class EstoquesTest < ApplicationSystemTestCase
setup do
@estoque = estoques(:one)
end

test "visiting the index" do
visit estoques_url
assert_selector "h1", text: "Estoques"
end

test "should create estoque" do
visit estoques_url
click_on "New estoque"

click_on "Create Estoque"

assert_text "Estoque was successfully created"
click_on "Back"
end

test "should update Estoque" do
visit estoque_url(@estoque)
click_on "Edit this estoque", match: :first

click_on "Update Estoque"

assert_text "Estoque was successfully updated"
click_on "Back"
end

test "should destroy Estoque" do
visit estoque_url(@estoque)
click_on "Destroy this estoque", match: :first

assert_text "Estoque was successfully destroyed"
end
end

0 comments on commit a44b452

Please sign in to comment.