diff --git a/Gemfile b/Gemfile index 2831a34..5118d8f 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.1.2" -gem 'bootstrap', '~> 5.2.1' gem 'devise' gem 'importmap-rails' gem "rails", "~> 7.0.4" diff --git a/Gemfile.lock b/Gemfile.lock index 72989ad..b630375 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,13 +68,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) - autoprefixer-rails (10.4.7.0) - execjs (~> 2) bcrypt (3.1.18) - bootstrap (5.2.1) - autoprefixer-rails (>= 9.1.0) - popper_js (>= 2.11.6, < 3) - sassc-rails (>= 2.0.0) builder (3.2.4) capybara (3.37.1) addressable @@ -98,8 +92,6 @@ GEM warden (~> 1.2.3) diff-lcs (1.5.0) erubi (1.11.0) - execjs (2.8.1) - ffi (1.15.5) globalid (1.0.0) activesupport (>= 5.0) i18n (1.12.0) @@ -131,8 +123,9 @@ GEM nio4r (2.5.8) nokogiri (1.13.8-arm64-darwin) racc (~> 1.4) + nokogiri (1.13.8-x86_64-linux) + racc (~> 1.4) orm_adapter (0.5.0) - popper_js (2.11.6) public_suffix (5.0.0) puma (5.6.5) nio4r (~> 2.0) @@ -190,14 +183,6 @@ GEM rspec-mocks (~> 3.11) rspec-support (~> 3.11) rspec-support (3.11.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt sprockets (4.1.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -206,8 +191,8 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.5.2-arm64-darwin) + sqlite3 (1.5.2-x86_64-linux) thor (1.2.1) - tilt (2.0.11) timeout (0.3.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) @@ -222,9 +207,9 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-linux DEPENDENCIES - bootstrap (~> 5.2.1) capybara debug devise diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss deleted file mode 100644 index 119a6aa..0000000 --- a/app/assets/stylesheets/application.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import "bootstrap"; -@import "theme"; diff --git a/app/assets/stylesheets/theme.css b/app/assets/stylesheets/theme.css deleted file mode 100644 index a79ca19..0000000 --- a/app/assets/stylesheets/theme.css +++ /dev/null @@ -1,6 +0,0 @@ -.link-botao { - border: solid 1px red; - border-radius: 25%; - padding: 1rem; - background-color: aqua; -} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1f6be59..09705d1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,2 @@ class ApplicationController < ActionController::Base - - end diff --git a/app/controllers/product_categories_controller.rb b/app/controllers/product_categories_controller.rb deleted file mode 100644 index 180bc41..0000000 --- a/app/controllers/product_categories_controller.rb +++ /dev/null @@ -1,21 +0,0 @@ -class ProductCategoriesController < ApplicationController - def create - ProductCategory.create!(name: params.require(:product_category).permit(:name)) - redirect_to products_path, notice: 'Categoria cadastrada' - end - - def search - nome_a_buscar = params[:busca] - ProductCategory.where("name LIKE :param_busca OR outro_campo LIKE :param_busca OR mais_um_campo LIKE :param_busca ", - { param_busca: "%#{nome_a_buscar}%" } ) - - @transports = find_available_transports - - end - - private - - def find_available_transports() - FreightageFinder.new(transports, order).find() - end -end \ No newline at end of file diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 039a826..d2606eb 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,61 +1,22 @@ class ProductsController < ApplicationController - before_action :set_product, only: %i[ show edit update destroy ] - - # GET /products def index @products = Product.all - @product = Product.new - @product_category = ProductCategory.new - @product_categories = ProductCategory.all - end - - # GET /products/1 - def show end - # GET /products/new def new @product = Product.new + @product_categories = ProductCategory.all end - # GET /products/1/edit - def edit - end - - # POST /products def create + @product_categories = ProductCategory.all + product_params = params.require(:product).permit(:name, :price, :product_category_id) @product = Product.new(product_params) - if @product.save - redirect_to @product, notice: "Product was successfully created." + redirect_to root_path, notice: 'Produto cadastrado com sucesso.' else - render :new, status: :unprocessable_entity + flash.now[:notice] = 'Não foi possível cadastrar o produto.' + render 'new' end end - - # PATCH/PUT /products/1 - def update - if @product.update(product_params) - redirect_to @product, notice: "Product was successfully updated." - else - render :edit, status: :unprocessable_entity - end - end - - # DELETE /products/1 - def destroy - @product.destroy - redirect_to products_url, notice: "Product was successfully destroyed." - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_product - @product = Product.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def product_params - params.require(:product).permit(:name, :price, :product_category_id) - end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb deleted file mode 100644 index 73ff2dc..0000000 --- a/app/controllers/welcome_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -class WelcomeController < ApplicationController - - - def index - - end - - -end \ No newline at end of file diff --git a/app/models/product_category.rb b/app/models/product_category.rb index 282738c..d95f936 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -1,3 +1,4 @@ class ProductCategory < ApplicationRecord validates :name, presence: true + has_many :products end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c557d62..0e9a1cd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,56 +1,21 @@ - SistemaFrete + ProductsApp <%= csrf_meta_tags %> <%= csp_meta_tag %> - - <%= stylesheet_link_tag "application" %> - <%= javascript_importmap_tags %> - - - -
- <%= notice %> - <%= yield %> -
+ <%= yield %> + diff --git a/app/views/product_categories/_product_category.html.erb b/app/views/product_categories/_product_category.html.erb deleted file mode 100644 index e216369..0000000 --- a/app/views/product_categories/_product_category.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= product_category.name %> \ No newline at end of file diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb deleted file mode 100644 index a2a1d8e..0000000 --- a/app/views/products/_form.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<%= form_with(model: product) do |form| %> - <% if product.errors.any? %> -
-

<%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:

- - -
- <% end %> - -
- <%= form.label :name, style: "display: block" %> - <%= form.text_field :name %> -
- -
- <%= form.label :price, style: "display: block" %> - <%= form.text_field :price %> -
- -
- <%= form.submit %> -
-<% end %> diff --git a/app/views/products/_product.html.erb b/app/views/products/_product.html.erb deleted file mode 100644 index 19ca353..0000000 --- a/app/views/products/_product.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -
-

- Name: - <%= product.name %> -

- -

- Price: - <%= product.price %> -

- -
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb deleted file mode 100644 index 90cb860..0000000 --- a/app/views/products/edit.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -

Editing product

- -<%= render "form", product: @product %> - -
- -
- <%= link_to "Show this product", @product %> | - <%= link_to "Back to products", products_path %> -
diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index a84a004..77428bd 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,50 +1,14 @@ -

<%= notice %>

- -

Products

-
- <% @products.each do |product| %> - <%= render product %> -

- <%= link_to "Show this product", product %> -

- <% end %> -
-
-

Nova Categoria de Produto

-<%= form_with(model: @product_category) do |f| %> - <%= f.label :name %> - <%= f.text_field :name %> - <%= f.submit %> -<% end %> -
- - - -

Novo Produto

-<%= form_with(model: @product) do |form| %> -
- <%= form.label :name, style: "display: block" %> - <%= form.text_field :name %> -
- +

Produtos

+
+<%= link_to 'Cadastrar produto', new_product_path %> +<% @products.each do |p| %>
- <%= form.label :price, style: "display: block" %> - <%= form.text_field :price %> -
- -
- <%= form.label :condition_new, 'Produto Novo' %> - <%= form.radio_button :condition, :new %> - - <%= form.label :condition_used, 'Produto Usado' %> - <%= form.radio_button :condition, :used %> -
- -
- <%= form.submit %> -
+ Produto: <%= p.name %> - <%= p.product_category.name %> - R$ <%= p.price %> +
<% end %> + - -choose 'Produto Usado' +<% if @products.empty? %> +

Não existem produtos cadastrados

+<% end %> diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index d438e41..3220b57 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -1,9 +1,18 @@ -

New product

- -<%= render "form", product: @product %> - -
- -
- <%= link_to "Back to products", products_path %> -
+<%= form_with(model: @product) do |f| %> +
+ <%= f.label :name, 'Nome:' %> + <%= f.text_field :name %> +
+
+ <%= f.label :price, 'Preço:' %> + <%= f.number_field :price %> +
+
+ <%= f.label :product_category_id, 'Categoria:' %> + <%= f.collection_select :product_category_id, @product_categories, :id, :name %> +
+
+
<%= f.submit 'Salvar' %> +
+ + <% end %> \ No newline at end of file diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb deleted file mode 100644 index 7e30dc8..0000000 --- a/app/views/products/show.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -

<%= notice %>

- -<%= render @product %> - -<%= render @product.product_category %> - -
- <%= link_to "Edit this product", edit_product_path(@product) %> | - <%= link_to "Back to products", products_path %> - - <%= button_to "Destroy this product", @product, method: :delete %> -
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb deleted file mode 100644 index 65777a5..0000000 --- a/app/views/welcome/index.html.erb +++ /dev/null @@ -1,42 +0,0 @@ -

<%= translate('.title') %>

- -
-
- <%= image_tag 'delivery.png', class: 'img-fluid' %> -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3Larry the Bird@twitter
-
-
- - -<%= link_to 'Início', root_path, class: 'btn btn-primary btn-lg' %> diff --git a/config/routes.rb b/config/routes.rb index e23c4d5..9d3d199 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,6 @@ Rails.application.routes.draw do - resources :products - resources :product_categories, only: [:create, :show] do - resources :products, only: [:create] - end + resources :products, only: [:new, :create] + resources :product_categories, only: [:create, :show] devise_for :users - root 'welcome#index' + root 'products#index' end diff --git a/spec/system/user_register_products_spec.rb b/spec/system/user_register_products_spec.rb new file mode 100644 index 0000000..7ab4df9 --- /dev/null +++ b/spec/system/user_register_products_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +describe 'Usuário cadastra produto' do + it 'a partir da tela inicial' do + #arrange + #act + visit root_path + click_on 'Cadastrar produto' + + #assert + expect(current_path).to eq new_product_path + end + + it 'com sucesso' do + #arrange + product_category = ProductCategory.create!(name: 'eletrônicos') + #act + visit root_path + click_on 'Cadastrar produto' + fill_in 'Nome', with: 'TV' + select 'eletrônicos', from: 'Categoria' + fill_in 'Preço', with: 1050 + click_on 'Salvar' + + #assert + expect(current_path).to eq root_path + expect(page).to have_content 'TV - eletrônicos - R$ 1050' + end +end