From 08a575907fffb0de1ccd3bc9425b77970d9755d3 Mon Sep 17 00:00:00 2001 From: Karina Sakata Date: Wed, 26 Oct 2022 18:21:41 -0300 Subject: [PATCH 1/8] First Commit --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 6 +- .../product_categories_controller.rb | 21 ------- app/controllers/products_controller.rb | 61 ------------------- app/controllers/welcome_controller.rb | 9 --- .../_product_category.html.erb | 1 - app/views/products/_form.html.erb | 27 -------- app/views/products/_product.html.erb | 12 ---- app/views/products/edit.html.erb | 10 --- app/views/products/index.html.erb | 50 --------------- app/views/products/new.html.erb | 9 --- app/views/products/show.html.erb | 12 ---- app/views/welcome/index.html.erb | 42 ------------- config/routes.rb | 12 ++-- spec/system/user_view_products_spec.rb | 17 ++++++ 16 files changed, 30 insertions(+), 263 deletions(-) delete mode 100644 app/controllers/product_categories_controller.rb delete mode 100644 app/controllers/products_controller.rb delete mode 100644 app/controllers/welcome_controller.rb delete mode 100644 app/views/product_categories/_product_category.html.erb delete mode 100644 app/views/products/_form.html.erb delete mode 100644 app/views/products/_product.html.erb delete mode 100644 app/views/products/edit.html.erb delete mode 100644 app/views/products/index.html.erb delete mode 100644 app/views/products/new.html.erb delete mode 100644 app/views/products/show.html.erb delete mode 100644 app/views/welcome/index.html.erb create mode 100644 spec/system/user_view_products_spec.rb diff --git a/.ruby-version b/.ruby-version index 7bde84d..85588be 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.1.2 +ruby-3.0.0 diff --git a/Gemfile b/Gemfile index 2831a34..44efc00 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.1.2" +ruby "3.0.0" gem 'bootstrap', '~> 5.2.1' gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 72989ad..43abb82 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,6 +131,8 @@ 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) @@ -206,6 +208,7 @@ 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) @@ -222,6 +225,7 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-linux DEPENDENCIES bootstrap (~> 5.2.1) @@ -237,7 +241,7 @@ DEPENDENCIES tzinfo-data RUBY VERSION - ruby 3.1.2p20 + ruby 3.0.0p0 BUNDLED WITH 2.3.14 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 deleted file mode 100644 index 039a826..0000000 --- a/app/controllers/products_controller.rb +++ /dev/null @@ -1,61 +0,0 @@ -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 - end - - # GET /products/1/edit - def edit - end - - # POST /products - def create - @product = Product.new(product_params) - - if @product.save - redirect_to @product, notice: "Product was successfully created." - else - render :new, status: :unprocessable_entity - 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/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 deleted file mode 100644 index a84a004..0000000 --- a/app/views/products/index.html.erb +++ /dev/null @@ -1,50 +0,0 @@ -

<%= 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 %> -
- -
- <%= 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 %> -
-<% end %> - - -choose 'Produto Usado' - diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb deleted file mode 100644 index d438e41..0000000 --- a/app/views/products/new.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

New product

- -<%= render "form", product: @product %> - -
- -
- <%= link_to "Back to products", products_path %> -
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..4838ab1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,8 @@ Rails.application.routes.draw do - resources :products - resources :product_categories, only: [:create, :show] do - resources :products, only: [:create] - end - devise_for :users - root 'welcome#index' + # resources :products + # resources :product_categories, only: [:create, :show] do + # resources :products, only: [:create] + # end + # devise_for :users + root 'home#index' end diff --git a/spec/system/user_view_products_spec.rb b/spec/system/user_view_products_spec.rb new file mode 100644 index 0000000..766c093 --- /dev/null +++ b/spec/system/user_view_products_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe 'Usuário vê detalhes de produtos' do + it 'cadastrados' do + #Arrange + product_category = ProductCategory.create!(name: "Eletrônico") + product = Product.new(name: "Celular", price: 2000, product_category_id: product_category) + + #Act + visit root_path + + #Assert + expect(page).to have_content "Celular" + expect(page).to have_content "R$2000,00" + end + +end \ No newline at end of file From 1680bd1bd391cd01421fc2c408620072c007acc6 Mon Sep 17 00:00:00 2001 From: Karina Sakata Date: Wed, 26 Oct 2022 18:23:21 -0300 Subject: [PATCH 2/8] 123 --- config/routes.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 4838ab1..22b521b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,4 @@ Rails.application.routes.draw do - # resources :products - # resources :product_categories, only: [:create, :show] do - # resources :products, only: [:create] - # end - # devise_for :users + root 'home#index' end From 7aeab00d1f10794d41e33621c28afc35a9cf9a1c Mon Sep 17 00:00:00 2001 From: Karina Sakata Date: Wed, 26 Oct 2022 19:53:38 -0300 Subject: [PATCH 3/8] Organizando diretorio --- .../product_categories_controller.rb | 21 ------- app/controllers/products_controller.rb | 61 ------------------- app/controllers/welcome_controller.rb | 9 --- .../_product_category.html.erb | 1 - app/views/products/_form.html.erb | 27 -------- app/views/products/_product.html.erb | 12 ---- app/views/products/edit.html.erb | 10 --- app/views/products/index.html.erb | 50 --------------- app/views/products/new.html.erb | 9 --- app/views/products/show.html.erb | 12 ---- app/views/welcome/index.html.erb | 42 ------------- config/routes.rb | 12 ++-- 12 files changed, 6 insertions(+), 260 deletions(-) delete mode 100644 app/controllers/product_categories_controller.rb delete mode 100644 app/controllers/products_controller.rb delete mode 100644 app/controllers/welcome_controller.rb delete mode 100644 app/views/product_categories/_product_category.html.erb delete mode 100644 app/views/products/_form.html.erb delete mode 100644 app/views/products/_product.html.erb delete mode 100644 app/views/products/edit.html.erb delete mode 100644 app/views/products/index.html.erb delete mode 100644 app/views/products/new.html.erb delete mode 100644 app/views/products/show.html.erb delete mode 100644 app/views/welcome/index.html.erb 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 deleted file mode 100644 index 039a826..0000000 --- a/app/controllers/products_controller.rb +++ /dev/null @@ -1,61 +0,0 @@ -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 - end - - # GET /products/1/edit - def edit - end - - # POST /products - def create - @product = Product.new(product_params) - - if @product.save - redirect_to @product, notice: "Product was successfully created." - else - render :new, status: :unprocessable_entity - 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/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:

- -
    - <% product.errors.each do |error| %> -
  • <%= error.full_message %>
  • - <% end %> -
-
- <% 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 deleted file mode 100644 index a84a004..0000000 --- a/app/views/products/index.html.erb +++ /dev/null @@ -1,50 +0,0 @@ -

<%= 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 %> -
- -
- <%= 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 %> -
-<% end %> - - -choose 'Produto Usado' - diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb deleted file mode 100644 index d438e41..0000000 --- a/app/views/products/new.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

New product

- -<%= render "form", product: @product %> - -
- -
- <%= link_to "Back to products", products_path %> -
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..04c4b0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,8 @@ Rails.application.routes.draw do - resources :products - resources :product_categories, only: [:create, :show] do - resources :products, only: [:create] - end - devise_for :users - root 'welcome#index' + # resources :products + # resources :product_categories, only: [:create, :show] do + # resources :products, only: [:create] + # end + # devise_for :users + # root 'welcome#index' end From 34aabc4d68a843966c4135c7fad88cda8a35773a Mon Sep 17 00:00:00 2001 From: manueladinizc Date: Wed, 26 Oct 2022 20:01:19 -0300 Subject: [PATCH 4/8] teste --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8976213..4d81458 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Sistema de Frete -Este é uma app com fins de estudos em turmas da Campus Code. +-Este é uma app com fins de estudos em turmas da Campus Code. From 3c5c9565612b7acfae223571049d932780aeb67d Mon Sep 17 00:00:00 2001 From: manueladinizc Date: Wed, 26 Oct 2022 20:17:09 -0300 Subject: [PATCH 5/8] teste2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d81458..8976213 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Sistema de Frete --Este é uma app com fins de estudos em turmas da Campus Code. +Este é uma app com fins de estudos em turmas da Campus Code. From d6854549e075cf0bff88f654fc316b840f1a241f Mon Sep 17 00:00:00 2001 From: Karina Sakata Date: Wed, 26 Oct 2022 20:27:46 -0300 Subject: [PATCH 6/8] versao alterada --- .ruby-version | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 7bde84d..85588be 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.1.2 +ruby-3.0.0 diff --git a/Gemfile b/Gemfile index 2831a34..44efc00 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.1.2" +ruby "3.0.0" gem 'bootstrap', '~> 5.2.1' gem 'devise' From eede13aad092bc6cda1dc515c07bdeca4f1f07a7 Mon Sep 17 00:00:00 2001 From: manueladinizc Date: Wed, 26 Oct 2022 20:34:47 -0300 Subject: [PATCH 7/8] teste3 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8976213..9c6e19c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Sistema de Frete + + + Este é uma app com fins de estudos em turmas da Campus Code. From 2c980c7e26bbec9c9f450b35f8cd8f7dd7092e2b Mon Sep 17 00:00:00 2001 From: Karina Sakata Date: Wed, 26 Oct 2022 21:35:08 -0300 Subject: [PATCH 8/8] Cadastro de Produto --- app/controllers/home_controller.rb | 5 +++++ app/controllers/products_controller.rb | 15 +++++++++++++ app/views/home/index.html.erb | 10 +++++++++ app/views/products/new.html.erb | 10 +++++++++ config/routes.rb | 1 + db/seeds.rb | 11 ++++----- spec/system/user.register_product_spec.rb | 27 +++++++++++++++++++++++ spec/system/user_view_products_spec.rb | 6 ++--- 8 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 app/controllers/home_controller.rb create mode 100644 app/controllers/products_controller.rb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/products/new.html.erb create mode 100644 spec/system/user.register_product_spec.rb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..1a9eca3 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def index + @products = Product.all + end +end \ No newline at end of file diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..5d27297 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,15 @@ +class ProductsController < ApplicationController + + def new + @product_categories = ProductCategory.all + @product = Product.new + end + + def create + product_params = params.require(:product).permit(:name, :price, :product_category) + @product = Product.new(product_params) + if @product.save + redirect_to root_path + end + end +end \ No newline at end of file diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..dcb0da1 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,10 @@ +

Product

+ +<%= link_to 'Cadastrar Produto', new_product_path %> + +<% @products.each do |p| %> + + <%= p.name %> + R$<%= p.price %> +<% end %> + \ No newline at end of file diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000..62d4fe3 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,10 @@ +

Cadastro de Produto

+ +<%= form_with(model: @product) do |f| %> + <%= f.label :name, 'Produto' %> + <%= 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 %> + <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2224d33..e81345d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ Rails.application.routes.draw do root 'home#index' + resources :products, only: [:new, :create] end diff --git a/db/seeds.rb b/db/seeds.rb index fbaf120..1ebf910 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,13 +6,14 @@ # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) -User.create(email: user@email.com, password: ) -Company.create(name: , cnpj: ) -Product.create(name: , price: , company: ) +# User.create(email: user@email.com, password:) +# Company.create(name: , cnpj: ) +# Product.create(name: , price: , company:) +#User.create(email: user@email.com, password: ) +product_category = ProductCategory.create!(name: "Eletrônico") +product = Product.create!(name: "Celular", price: 2000, product_category: product_category) - -User.create(email: user@email.com, password: ) \ No newline at end of file diff --git a/spec/system/user.register_product_spec.rb b/spec/system/user.register_product_spec.rb new file mode 100644 index 0000000..b094625 --- /dev/null +++ b/spec/system/user.register_product_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +describe 'Usuário cadastra um produto' do + it 'a partir da tela inicial' do + visit root_path + + click_on 'Cadastrar Produto' + + expect(page).to have_field('Produto') + expect(page).to have_field('Preço') + expect(page).to have_field('Categoria') + + end + + it 'com sucesso' do + + product_category = ProductCategory.create!(name: "Eletrônico") + + visit root_path + + click_on 'Cadastrar Produto' + + fill_in 'Produto', with: 'Celular' + fill_in 'Preço', with: 2000 + select 'Eletrônico', from: 'Categoria' +end +end \ No newline at end of file diff --git a/spec/system/user_view_products_spec.rb b/spec/system/user_view_products_spec.rb index 766c093..f4414d1 100644 --- a/spec/system/user_view_products_spec.rb +++ b/spec/system/user_view_products_spec.rb @@ -4,14 +4,14 @@ it 'cadastrados' do #Arrange product_category = ProductCategory.create!(name: "Eletrônico") - product = Product.new(name: "Celular", price: 2000, product_category_id: product_category) + product = Product.create!(name: "Celular", price: 2000, product_category: product_category) #Act visit root_path #Assert expect(page).to have_content "Celular" - expect(page).to have_content "R$2000,00" + expect(page).to have_content "R$2000" end -end \ No newline at end of file + end \ No newline at end of file