+ class ApplicationController +
+ +Protected Instance Methods
+# File application_controller.rb, line 8 +def configure_permitted_parameters + devise_parameter_sanitizer.permit(:sign_up, keys: %i[full_name role]) +end+
diff --git a/Gemfile b/Gemfile index 54be0f4e..13637d5b 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,7 @@ group :test do gem 'selenium-webdriver' # Easy installation and use of chromedriver to run system tests with Chrome gem 'webdrivers' + gem 'cucumber' gem 'cucumber-rails', require: false # database_cleaner is not required, but highly recommended gem 'database_cleaner' diff --git a/Gemfile.lock b/Gemfile.lock index 0a9e4f86..69389b0c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,6 +255,7 @@ DEPENDENCIES byebug capybara (>= 2.15) coffee-rails (~> 4.2) + cucumber cucumber-rails database_cleaner devise @@ -279,4 +280,4 @@ RUBY VERSION ruby 2.6.3p62 BUNDLED WITH - 1.17.2 + 2.1.4 diff --git a/README.md b/README.md index 7db80e4c..034556fb 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,27 @@ -# README +# SECRETARIA PPGI -This README would normally document whatever steps are necessary to get the -application up and running. +Sistema feito para a secretária PPGI. -Things you may want to cover: +## Instalar as dependencias -* Ruby version + $ bundle -* System dependencies +## Migrar o banco de dados -* Configuration + $ rake db:migrate -* Database creation +## Rodar a aplicação -* Database initialization + $ rails s + +## Rodar o Saikuro + + $ saikuro -c -t -i app -y 0 -w 11 -e 16 -o detailed/ + +## Rodar o rubycritic -* How to run the test suite + $ cd app && rubycritic -* Services (job queues, cache servers, search engines, etc.) +## ABC Score e complexidade ciclomática -* Deployment instructions - -* ... +O maior ABC Score corespondeu a 6.1 e a maior complexidade ciclomática correspondeu a 7. \ No newline at end of file diff --git a/app/assets/javascripts/faqs.coffee b/app/assets/javascripts/faqs.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/faqs.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/faqs_suggestions.coffee b/app/assets/javascripts/faqs_suggestions.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/faqs_suggestions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/topics.coffee b/app/assets/javascripts/topics.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/topics.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/faqs.scss b/app/assets/stylesheets/faqs.scss new file mode 100644 index 00000000..b7e2f4de --- /dev/null +++ b/app/assets/stylesheets/faqs.scss @@ -0,0 +1,187 @@ +// Place all the styles related to the Faqs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +/* Sakura.css v1.3.1 + * ================ + * Minimal css theme. + * Project: https://github.com/oxalorg/sakura/ + */ +/* Body */ +html { + font-size: 62.5%; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; } + + body { + font-size: 1.8rem; + line-height: 1.618; + max-width: 38em; + margin: auto; + color: #4a4a4a; + background-color: #f9f9f9; + padding: 13px; } + + @media (max-width: 684px) { + body { + font-size: 1.53rem; } } + + @media (max-width: 382px) { + body { + font-size: 1.35rem; } } + + h1, h2, h3, h4, h5, h6 { + line-height: 1.1; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-weight: 700; + margin-top: 3rem; + margin-bottom: 1.5rem; + overflow-wrap: break-word; + word-wrap: break-word; + -ms-word-break: break-all; + word-break: break-word; } + + h1 { + font-size: 2.35em; } + + h2 { + font-size: 2.00em; } + + h3 { + font-size: 1.75em; } + + h4 { + font-size: 1.5em; } + + h5 { + font-size: 1.25em; } + + h6 { + font-size: 1em; } + + p { + margin-top: 0px; + margin-bottom: 2.5rem; } + + small, sub, sup { + font-size: 75%; } + + hr { + border-color: #1d7484; } + + a { + text-decoration: none; + color: #1d7484; } + a:hover { + color: #982c61; + border-bottom: 2px solid #4a4a4a; } + a:visited { + color: #144f5a; } + + ul { + padding-left: 1.4em; + margin-top: 0px; + margin-bottom: 2.5rem; } + + li { + margin-bottom: 0.4em; } + + blockquote { + margin-left: 0px; + margin-right: 0px; + padding-left: 1em; + padding-top: 0.8em; + padding-bottom: 0.8em; + padding-right: 0.8em; + border-left: 5px solid #1d7484; + margin-bottom: 2.5rem; + background-color: #f1f1f1; } + + blockquote p { + margin-bottom: 0; } + + img, video { + height: auto; + max-width: 100%; + margin-top: 0px; + margin-bottom: 2.5rem; } + + /* Pre and Code */ + pre { + background-color: #f1f1f1; + display: block; + padding: 1em; + overflow-x: auto; + margin-top: 0px; + margin-bottom: 2.5rem; } + + code { + font-size: 0.9em; + padding: 0 0.5em; + background-color: #f1f1f1; + white-space: pre-wrap; } + + pre > code { + padding: 0; + background-color: transparent; + white-space: pre; } + + /* Tables */ + table { + text-align: justify; + width: 100%; + border-collapse: collapse; } + + td, th { + padding: 0.5em; + border-bottom: 1px solid #f1f1f1; } + + /* Buttons, forms and input */ + input, textarea { + border: 1px solid #4a4a4a; } + input:focus, textarea:focus { + border: 1px solid #1d7484; } + + textarea { + width: 100%; } + + .button, button, input[type="submit"], input[type="reset"], input[type="button"] { + display: inline-block; + padding: 5px 10px; + text-align: center; + text-decoration: none; + white-space: nowrap; + background-color: #1d7484; + color: #f9f9f9; + border-radius: 1px; + border: 1px solid #1d7484; + cursor: pointer; + box-sizing: border-box; } + .button[disabled], button[disabled], input[type="submit"][disabled], input[type="reset"][disabled], input[type="button"][disabled] { + cursor: default; + opacity: .5; } + .button:focus:enabled, .button:hover:enabled, button:focus:enabled, button:hover:enabled, input[type="submit"]:focus:enabled, input[type="submit"]:hover:enabled, input[type="reset"]:focus:enabled, input[type="reset"]:hover:enabled, input[type="button"]:focus:enabled, input[type="button"]:hover:enabled { + background-color: #982c61; + border-color: #982c61; + color: #f9f9f9; + outline: 0; } + + textarea, select, input { + color: #4a4a4a; + padding: 6px 10px; + /* The 6px vertically centers text on FF, ignored by Webkit */ + margin-bottom: 10px; + background-color: #f1f1f1; + border: 1px solid #f1f1f1; + border-radius: 4px; + box-shadow: none; + box-sizing: border-box; } + textarea:focus, select:focus, input:focus { + border: 1px solid #1d7484; + outline: 0; } + + input[type="checkbox"]:focus { + outline: 1px dotted #1d7484; } + + label, legend, fieldset { + display: block; + margin-bottom: .5rem; + font-weight: 600; } \ No newline at end of file diff --git a/app/assets/stylesheets/faqs_suggestions.scss b/app/assets/stylesheets/faqs_suggestions.scss new file mode 100644 index 00000000..044b2f0d --- /dev/null +++ b/app/assets/stylesheets/faqs_suggestions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the FaqsSuggestions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 00000000..626d42ca --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,184 @@ +/* Sakura.css v1.3.1 + * ================ + * Minimal css theme. + * Project: https://github.com/oxalorg/sakura/ + */ +/* Body */ +html { + font-size: 62.5%; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; } + +body { + font-size: 1.8rem; + line-height: 1.618; + max-width: 38em; + margin: auto; + color: #4a4a4a; + background-color: #f9f9f9; + padding: 13px; } + +@media (max-width: 684px) { + body { + font-size: 1.53rem; } } + +@media (max-width: 382px) { + body { + font-size: 1.35rem; } } + +h1, h2, h3, h4, h5, h6 { + line-height: 1.1; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-weight: 700; + margin-top: 3rem; + margin-bottom: 1.5rem; + overflow-wrap: break-word; + word-wrap: break-word; + -ms-word-break: break-all; + word-break: break-word; } + +h1 { + font-size: 2.35em; } + +h2 { + font-size: 2.00em; } + +h3 { + font-size: 1.75em; } + +h4 { + font-size: 1.5em; } + +h5 { + font-size: 1.25em; } + +h6 { + font-size: 1em; } + +p { + margin-top: 0px; + margin-bottom: 2.5rem; } + +small, sub, sup { + font-size: 75%; } + +hr { + border-color: #1d7484; } + +a { + text-decoration: none; + color: #1d7484; } + a:hover { + color: #982c61; + border-bottom: 2px solid #4a4a4a; } + a:visited { + color: #144f5a; } + +ul { + padding-left: 1.4em; + margin-top: 0px; + margin-bottom: 2.5rem; } + +li { + margin-bottom: 0.4em; } + +blockquote { + margin-left: 0px; + margin-right: 0px; + padding-left: 1em; + padding-top: 0.8em; + padding-bottom: 0.8em; + padding-right: 0.8em; + border-left: 5px solid #1d7484; + margin-bottom: 2.5rem; + background-color: #f1f1f1; } + +blockquote p { + margin-bottom: 0; } + +img, video { + height: auto; + max-width: 100%; + margin-top: 0px; + margin-bottom: 2.5rem; } + +/* Pre and Code */ +pre { + background-color: #f1f1f1; + display: block; + padding: 1em; + overflow-x: auto; + margin-top: 0px; + margin-bottom: 2.5rem; } + +code { + font-size: 0.9em; + padding: 0 0.5em; + background-color: #f1f1f1; + white-space: pre-wrap; } + +pre > code { + padding: 0; + background-color: transparent; + white-space: pre; } + +/* Tables */ +table { + text-align: justify; + width: 100%; + border-collapse: collapse; } + +td, th { + padding: 0.5em; + border-bottom: 1px solid #f1f1f1; } + +/* Buttons, forms and input */ +input, textarea { + border: 1px solid #4a4a4a; } + input:focus, textarea:focus { + border: 1px solid #1d7484; } + +textarea { + width: 100%; } + +.button, button, input[type="submit"], input[type="reset"], input[type="button"] { + display: inline-block; + padding: 5px 10px; + text-align: center; + text-decoration: none; + white-space: nowrap; + background-color: #1d7484; + color: #f9f9f9; + border-radius: 1px; + border: 1px solid #1d7484; + cursor: pointer; + box-sizing: border-box; } + .button[disabled], button[disabled], input[type="submit"][disabled], input[type="reset"][disabled], input[type="button"][disabled] { + cursor: default; + opacity: .5; } + .button:focus:enabled, .button:hover:enabled, button:focus:enabled, button:hover:enabled, input[type="submit"]:focus:enabled, input[type="submit"]:hover:enabled, input[type="reset"]:focus:enabled, input[type="reset"]:hover:enabled, input[type="button"]:focus:enabled, input[type="button"]:hover:enabled { + background-color: #982c61; + border-color: #982c61; + color: #f9f9f9; + outline: 0; } + +textarea, select, input { + color: #4a4a4a; + padding: 6px 10px; + /* The 6px vertically centers text on FF, ignored by Webkit */ + margin-bottom: 10px; + background-color: #f1f1f1; + border: 1px solid #f1f1f1; + border-radius: 4px; + box-shadow: none; + box-sizing: border-box; } + textarea:focus, select:focus, input:focus { + border: 1px solid #1d7484; + outline: 0; } + +input[type="checkbox"]:focus { + outline: 1px dotted #1d7484; } + +label, legend, fieldset { + display: block; + margin-bottom: .5rem; + font-weight: 600; } \ No newline at end of file diff --git a/app/assets/stylesheets/topics.scss b/app/assets/stylesheets/topics.scss new file mode 100644 index 00000000..f234f079 --- /dev/null +++ b/app/assets/stylesheets/topics.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Topics controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb new file mode 100644 index 00000000..d2116b21 --- /dev/null +++ b/app/controllers/faqs_controller.rb @@ -0,0 +1,102 @@ +## +# Classe da controller dos FAQS +# Herda de ApplicationController +class FaqsController < ApplicationController + before_action :set_faq, only: [:show, :edit, :update, :destroy] + before_action :must_be_admin, only: [:create, :edit, :update, :destroy] + + + ## + # Retorna todos as FAQ + def index + @faqs = Faq.all + end + + ## + #... + def show + end + + ## + # Cria nova instancia de FAQ + def new + @faq = Faq.new + end + + ## + #... + def edit + end + + ## + # Popula uma instancia de FAQ com um dos tipos do faq_params + # Redireciona para a página da FAQ criada. + def create + @faq = Faq.new(faq_params) + + respond_to do |format| + if @faq.save + format.html { redirect_to @faq, notice: 'Faq was successfully created.' } + format.json { render :show, status: :created, location: @faq } + else + format.html { render :new } + format.json { render json: @faq.errors, status: :unprocessable_entity } + end + end + end + + + ## + # Atualiza uma FAQ pre existente + # Redireciona para a página da FAQ atualizada + def update + respond_to do |format| + if @faq.update(faq_params) + format.html { redirect_to @faq, notice: 'Faq was successfully updated.' } + format.json { render :show, status: :ok, location: @faq } + else + format.html { render :edit } + format.json { render json: @faq.errors, status: :unprocessable_entity } + end + end + end + + + ## + # Apaga uma instancia de FAQ + # Redireciona para a página de faqs + def destroy + @faq.destroy + respond_to do |format| + format.html { redirect_to faqs_url, notice: 'Faq was successfully destroyed.' } + format.json { head :no_content } + end + end + + + private + + ## + # Encontra e seta a FAQ requerida. + # @param [number] id - id da FAQ + def set_faq + @faq = Faq.find(params[:id]) + end + + ## + # Retorna os parametros aceitos pela FAQ + # Podem ser do tipo Question, Answer ou Topic_id + def faq_params + params.require(:faq).permit(:question, :answer, :topic_id) + end + + ## + # Redireciona o usuário para a pagina faqs + # caso não seja admin. Exibe alerta na tela. + def must_be_admin + unless current_user && current_user.role == "administrator" + redirect_to faqs_url, alert: "Rota restrita para administradores" + end + end + +end diff --git a/app/controllers/faqs_suggestions_controller.rb b/app/controllers/faqs_suggestions_controller.rb new file mode 100644 index 00000000..4c83d5e7 --- /dev/null +++ b/app/controllers/faqs_suggestions_controller.rb @@ -0,0 +1,109 @@ +## +# Classe da controller das sugestões de resposta ou pergunta das FAQ +# Herda de ApplicationController +class FaqsSuggestionsController < ApplicationController + before_action :set_faqs_suggestion, only: [:show, :edit, :update, :destroy] + before_action :must_be_admin, only: [:destroy, :index, :accept] + before_action :must_be_authenticated_user, only: [:create, :edit, :update] + + ## + # Retorna todas as faqs_suggestions + def index + @faqs_suggestions = FaqsSuggestion.all + end + + ## + #... + def show + end + + ## + # Cria nova instancia de faqs_suggestion + def new + @faqs_suggestion = FaqsSuggestion.new + end + + ## + #... + def edit + end + + + ## + # Popula uma instancia de faqs_suggestions com um dos tipos de faqs_suggestion_params + # Redireciona para a página da faqs_suggestions criada. + def create + @faqs_suggestion = FaqsSuggestion.new(faqs_suggestion_params) + + respond_to do |format| + if @faqs_suggestion.save + format.html { redirect_to @faqs_suggestion, notice: 'Faqs suggestion was successfully created.' } + format.json { render :show, status: :created, location: @faqs_suggestion } + else + format.html { render :new } + format.json { render json: @faqs_suggestion.errors, status: :unprocessable_entity } + end + end + end + + ## + # Atualiza uma faqs_suggestions pre existente + # Redireciona para a página da faqs_suggestions atualizada + def update + respond_to do |format| + if @faqs_suggestion.update(faqs_suggestion_params) + format.html { redirect_to @faqs_suggestion, notice: 'Faqs suggestion was successfully updated.' } + format.json { render :show, status: :ok, location: @faqs_suggestion } + else + format.html { render :edit } + format.json { render json: @faqs_suggestion.errors, status: :unprocessable_entity } + end + end + end + + ## + # Apaga uma instancia de faqs_suggestion + # Redireciona para a página faqs_suggestions + def destroy + @faqs_suggestion.destroy + respond_to do |format| + format.html { redirect_to faqs_suggestions_url, notice: 'Faqs suggestion was successfully destroyed.' } + format.json { head :no_content } + end + end + + + private + + ## + # Econtra e seta a faqs_suggestion requerida + # @param [number] id - id da faqs_suggestion + def set_faqs_suggestion + @faqs_suggestion = FaqsSuggestion.find(params[:id]) + end + + ## + # Retorna os parametros aceitos pelos métodos de faq_suggestion + # Podem ser do tipo Question, Answer ou Topic_id + def faqs_suggestion_params + params.require(:faqs_suggestion).permit(:question, :answer, :topic_id) + end + + ## + # Redireciona o usuário para a pagina faqs + # caso não seja admin. Exibe alerta na tela + def must_be_admin + unless current_user && current_user.role == "administrator" + redirect_to faqs_url, alert: "Rota restrita para administradores" + end + end + + ## + # Redireciona o usuário para a página faqs + # caso nao seja um usuario autenticado. + def must_be_authenticated_user + unless current_user && current_user.role != "administrator" + redirect_to faqs_url, alert: "Rota restrita para usuários cadastrados" + end + end +end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb new file mode 100644 index 00000000..cf5b6612 --- /dev/null +++ b/app/controllers/topics_controller.rb @@ -0,0 +1,102 @@ +## +# Classe da controller dos tópicos das FAQ +# Herda de ApplicationController +class TopicsController < ApplicationController + ## + # Configura as pre-actions de toda requisicao + # Indica as operacoes disponiveis e trava o acesso para não administradores + before_action :set_topic, only: [:show, :edit, :update, :destroy] + before_action :set_faq, only: [:show, :edit, :update, :destroy] + before_action :must_be_admin, only: [:create, :edit, :update, :destroy] + + ## + # Retorna todos os topics + def index + @topics = Topic.all + end + + ## + #... + def show + end + + ## + # Cria nova instancia de topic + def new + @topic = Topic.new + end + + ## + #... + def edit + end + + ## + # Popula uma instancia de topic com um dos tipos de topic_params + # Redireciona para a página do topic criado + def create + @topic = Topic.new(topic_params) + + respond_to do |format| + if @topic.save + format.html { redirect_to @topic, notice: 'Topic was successfully created.' } + format.json { render :show, status: :created, location: @topic } + else + format.html { render :new } + format.json { render json: @topic.errors, status: :unprocessable_entity } + end + end + end + + ## + # Atualiza um topic pre existente + # Redireciona para a página do topic atualizado + def update + respond_to do |format| + if @topic.update(topic_params) + format.html { redirect_to @topic, notice: 'Topic was successfully updated.' } + format.json { render :show, status: :ok, location: @topic } + else + format.html { render :edit } + format.json { render json: @topic.errors, status: :unprocessable_entity } + end + end + end + + ## + # Apaga uma instancia de topic + # Redireciona para a página de topics + def destroy + @topic.destroy + respond_to do |format| + format.html { redirect_to topics_url, notice: 'Topic was successfully destroyed.' } + format.json { head :no_content } + end + end + + + private + + ## + # Encontra e seta o topic requerida. + # @param [number] id - id do topic + def set_topic + @topic = Topic.find(params[:id]) + end + + ## + # Retorna os parametros aceitos pelo topic + # Podem ser apenas do tipo titulo + def topic_params + params.require(:topic).permit(:titulo) + end + + ## + # Redireciona o usuário para a pagina faqs + # caso não seja admin. Exibe alerta na tela. + def must_be_admin + unless current_user && current_user.role == "administrator" + redirect_to faqs_url, alert: "Rota restrita para administradores" + end + end +end diff --git a/app/doc/ApplicationController.html b/app/doc/ApplicationController.html new file mode 100644 index 00000000..95fd6bbd --- /dev/null +++ b/app/doc/ApplicationController.html @@ -0,0 +1,157 @@ + + + +
+ + +# File application_controller.rb, line 8 +def configure_permitted_parameters + devise_parameter_sanitizer.permit(:sign_up, keys: %i[full_name role]) +end+
Classe da controller dos FAQS Herda de ApplicationController
Popula uma instancia de FAQ com um dos tipos do faq_params Redireciona para a página da FAQ criada.
+ + + + +# File faqs_controller.rb, line 34 +def create + @faq = Faq.new(faq_params) + + respond_to do |format| + if @faq.save + format.html { redirect_to @faq, notice: 'Faq was successfully created.' } + format.json { render :show, status: :created, location: @faq } + else + format.html { render :new } + format.json { render json: @faq.errors, status: :unprocessable_entity } + end + end +end+
Apaga uma instancia de FAQ Redireciona para faqs_url
+ + + + +# File faqs_controller.rb, line 68 +def destroy + @faq.destroy + respond_to do |format| + format.html { redirect_to faqs_url, notice: 'Faq was successfully destroyed.' } + format.json { head :no_content } + end +end+
…
+ + + + +# File faqs_controller.rb, line 28 +def edit +end+
Retorna todos as FAQ
+ + + + +# File faqs_controller.rb, line 11 +def index + @faqs = Faq.all +end+
Cria nova instancia de FAQ
+ + + + +# File faqs_controller.rb, line 22 +def new + @faq = Faq.new +end+
…
+ + + + +# File faqs_controller.rb, line 17 +def show +end+
Atualiza uma FAQ pre existente Redireciona para a página da FAQ atualizada
+ + + + +# File faqs_controller.rb, line 52 +def update + respond_to do |format| + if @faq.update(faq_params) + format.html { redirect_to @faq, notice: 'Faq was successfully updated.' } + format.json { render :show, status: :ok, location: @faq } + else + format.html { render :edit } + format.json { render json: @faq.errors, status: :unprocessable_entity } + end + end +end+
Classe da controller das sugestões de resposta ou pergunta das FAQ Herda de ApplicationController
Popula uma instancia de faqs_suggestions com um dos tipos de faqs_suggestion_params Redireciona para a página da faqs_suggestions criada.
+ + + + +# File faqs_suggestions_controller.rb, line 35 +def create + @faqs_suggestion = FaqsSuggestion.new(faqs_suggestion_params) + + respond_to do |format| + if @faqs_suggestion.save + format.html { redirect_to @faqs_suggestion, notice: 'Faqs suggestion was successfully created.' } + format.json { render :show, status: :created, location: @faqs_suggestion } + else + format.html { render :new } + format.json { render json: @faqs_suggestion.errors, status: :unprocessable_entity } + end + end +end+
Apaga uma instancia de faqs_suggestion Redireciona para a página faqs_suggestions
+ + + + +# File faqs_suggestions_controller.rb, line 67 +def destroy + @faqs_suggestion.destroy + respond_to do |format| + format.html { redirect_to faqs_suggestions_url, notice: 'Faqs suggestion was successfully destroyed.' } + format.json { head :no_content } + end +end+
…
+ + + + +# File faqs_suggestions_controller.rb, line 28 +def edit +end+
Retorna todas as faqs_suggestions
+ + + + +# File faqs_suggestions_controller.rb, line 11 +def index + @faqs_suggestions = FaqsSuggestion.all +end+
Cria nova instancia de faqs_suggestion
+ + + + +# File faqs_suggestions_controller.rb, line 22 +def new + @faqs_suggestion = FaqsSuggestion.new +end+
…
+ + + + +# File faqs_suggestions_controller.rb, line 17 +def show +end+
Atualiza uma faqs_suggestions pre existente Redireciona para a página da faqs_suggestions atualizada
+ + + + +# File faqs_suggestions_controller.rb, line 52 +def update + respond_to do |format| + if @faqs_suggestion.update(faqs_suggestion_params) + format.html { redirect_to @faqs_suggestion, notice: 'Faqs suggestion was successfully updated.' } + format.json { render :show, status: :ok, location: @faqs_suggestion } + else + format.html { render :edit } + format.json { render json: @faqs_suggestion.errors, status: :unprocessable_entity } + end + end +end+
# File home_controller.rb, line 2 +def index +end+
Classe da controller dos tópicos das FAQ Herda de ApplicationController
Popula uma instancia de topic com um dos tipos de topic_params Redireciona para a página do topic criado
+ + + + +# File topics_controller.rb, line 37 +def create + @topic = Topic.new(topic_params) + + respond_to do |format| + if @topic.save + format.html { redirect_to @topic, notice: 'Topic was successfully created.' } + format.json { render :show, status: :created, location: @topic } + else + format.html { render :new } + format.json { render json: @topic.errors, status: :unprocessable_entity } + end + end +end+
Apaga uma instancia de topic Redireciona para a página de topics
+ + + + +# File topics_controller.rb, line 69 +def destroy + @topic.destroy + respond_to do |format| + format.html { redirect_to topics_url, notice: 'Topic was successfully destroyed.' } + format.json { head :no_content } + end +end+
…
+ + + + +# File topics_controller.rb, line 31 +def edit +end+
Retorna todos os topics
+ + + + +# File topics_controller.rb, line 14 +def index + @topics = Topic.all +end+
Cria nova instancia de topic
+ + + + +# File topics_controller.rb, line 25 +def new + @topic = Topic.new +end+
Configura as pre-actions de toda requisicao Indica as operacoes disponiveis e trava o acesso para não administradores
+ + + + +# File topics_controller.rb, line 8 +before_action :set_topic, only: [:show, :edit, :update, :destroy] ++
…
+ + + + +# File topics_controller.rb, line 20 +def show +end+
Atualiza um topic pre existente Redireciona para a página do topic atualizado
+ + + + +# File topics_controller.rb, line 54 +def update + respond_to do |format| + if @topic.update(topic_params) + format.html { redirect_to @topic, notice: 'Topic was successfully updated.' } + format.json { render :show, status: :ok, location: @topic } + else + format.html { render :edit } + format.json { render json: @topic.errors, status: :unprocessable_entity } + end + end +end+
This is the API documentation for RDoc Documentation. + +
Find me in app/views/faq/index.html.erb
\ No newline at end of file diff --git a/app/views/faqs/_faq.json.jbuilder b/app/views/faqs/_faq.json.jbuilder new file mode 100644 index 00000000..92b1e033 --- /dev/null +++ b/app/views/faqs/_faq.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! faq, :id, :question, :answer, :topic_id, :created_at, :updated_at +json.url faq_url(faq, format: :json) diff --git a/app/views/faqs/_form.html.erb b/app/views/faqs/_form.html.erb new file mode 100644 index 00000000..369cfe99 --- /dev/null +++ b/app/views/faqs/_form.html.erb @@ -0,0 +1,32 @@ +<%= form_with(model: faq, local: true) do |form| %> + <% if faq.errors.any? %> +<%= notice %>
+ +| Question | +Answer | +Topic | ++ | ||
|---|---|---|---|---|---|
| <%= faq.question %> | +<%= faq.answer %> | +<%= faq.topic.titulo %> | +<%= link_to 'Show', faq %> | +<%= link_to 'Edit', edit_faq_path(faq) %> | +<%= link_to 'Destroy', faq, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Question: + <%= @faq.question %> +
+ ++ Answer: + <%= @faq.answer %> +
+ ++ Topic: + <%= @faq.topic.titulo %> +
+ +<%= link_to 'Edit', edit_faq_path(@faq) %> | +<%= link_to 'Back', faqs_path %> diff --git a/app/views/faqs/show.json.jbuilder b/app/views/faqs/show.json.jbuilder new file mode 100644 index 00000000..513d96c5 --- /dev/null +++ b/app/views/faqs/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "faqs/faq", faq: @faq diff --git a/app/views/faqs_suggestions/_faqs_suggestion.json.jbuilder b/app/views/faqs_suggestions/_faqs_suggestion.json.jbuilder new file mode 100644 index 00000000..511f9667 --- /dev/null +++ b/app/views/faqs_suggestions/_faqs_suggestion.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! faqs_suggestion, :id, :question, :answer, :topic_id, :created_at, :updated_at +json.url faqs_suggestion_url(faqs_suggestion, format: :json) diff --git a/app/views/faqs_suggestions/_form.html.erb b/app/views/faqs_suggestions/_form.html.erb new file mode 100644 index 00000000..15ff9fc8 --- /dev/null +++ b/app/views/faqs_suggestions/_form.html.erb @@ -0,0 +1,32 @@ +<%= form_with(model: faqs_suggestion, local: true) do |form| %> + <% if faqs_suggestion.errors.any? %> +<%= notice %>
+ +| Question | +Answer | +Topic | ++ | ||
|---|---|---|---|---|---|
| <%= faqs_suggestion.question %> | +<%= faqs_suggestion.answer %> | +<%= faqs_suggestion.topic %> | +<%= link_to 'Show', faqs_suggestion %> | +<%= link_to 'Edit', edit_faqs_suggestion_path(faqs_suggestion) %> | +<%= link_to 'Destroy', faqs_suggestion, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Question: + <%= @faqs_suggestion.question %> +
+ ++ Answer: + <%= @faqs_suggestion.answer %> +
+ ++ Topic: + <%= @faqs_suggestion.topic %> +
+ +<%= link_to 'Edit', edit_faqs_suggestion_path(@faqs_suggestion) %> | +<%= link_to 'Back', faqs_suggestions_path %> diff --git a/app/views/faqs_suggestions/show.json.jbuilder b/app/views/faqs_suggestions/show.json.jbuilder new file mode 100644 index 00000000..62343662 --- /dev/null +++ b/app/views/faqs_suggestions/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "faqs_suggestions/faqs_suggestion", faqs_suggestion: @faqs_suggestion diff --git a/app/views/topics/_form.html.erb b/app/views/topics/_form.html.erb new file mode 100644 index 00000000..ffa3c28b --- /dev/null +++ b/app/views/topics/_form.html.erb @@ -0,0 +1,22 @@ +<%= form_with(model: topic, local: true) do |form| %> + <% if topic.errors.any? %> +<%= notice %>
+ +| Titulo | ++ | ||
|---|---|---|---|
| <%= topic.titulo %> | +<%= link_to 'Show', topic %> | +<%= link_to 'Edit', edit_topic_path(topic) %> | +<%= link_to 'Destroy', topic, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Titulo: + <%= @topic.titulo %> +
+ +<%= link_to 'Edit', edit_topic_path(@topic) %> | +<%= link_to 'Back', topics_path %> diff --git a/app/views/topics/show.json.jbuilder b/app/views/topics/show.json.jbuilder new file mode 100644 index 00000000..cc0cfc01 --- /dev/null +++ b/app/views/topics/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "topics/topic", topic: @topic diff --git a/config/database.yml b/config/database.yml index bbc24623..ba7f8db8 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,7 +23,9 @@ default: &default development: <<: *default - database: secretaria_ppgi_development + database: secretaria_ppgi + username: postgres + password: post123 # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. @@ -37,11 +39,11 @@ development: # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. - #host: localhost + host: localhost # The TCP port the server listens on. Defaults to 5432. # If your server runs on a different port number, change accordingly. - #port: 5432 + port: 5432 # Schema search path. The server defaults to $user,public #schema_search_path: myapp,sharedapp,public @@ -57,7 +59,9 @@ development: # Do not set this db to the same as development or production. test: <<: *default - database: secretaria_ppgi_test + database: secretaria_ppgi + username: postgres + password: post123 # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is @@ -78,8 +82,20 @@ test: # production: # url: <%= ENV['DATABASE_URL'] %> # + + host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + port: 5432 production: <<: *default - database: secretaria_ppgi_production - username: secretaria_ppgi - password: <%= ENV['SECRETARIA_PPGI_DATABASE_PASSWORD'] %> + database: secretaria_ppgi + username: postgres + password: post123 + + host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + port: 5432 diff --git a/config/routes.rb b/config/routes.rb index f33f7f68..4d744770 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,11 @@ # frozen_string_literal: true Rails.application.routes.draw do + resources :topics + resources :faqs_suggestions + resources :faqs get 'home/index' + get 'faq/index' devise_for :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root to: 'home#index' diff --git a/db/migrate/20201204223242_create_topics.rb b/db/migrate/20201204223242_create_topics.rb new file mode 100644 index 00000000..d35a1713 --- /dev/null +++ b/db/migrate/20201204223242_create_topics.rb @@ -0,0 +1,9 @@ +class CreateTopics < ActiveRecord::Migration[5.2] + def change + create_table :topics do |t| + t.string :titulo + + t.timestamps + end + end +end diff --git a/db/migrate/20201204223740_create_faqs_suggestions.rb b/db/migrate/20201204223740_create_faqs_suggestions.rb new file mode 100644 index 00000000..c87f82f0 --- /dev/null +++ b/db/migrate/20201204223740_create_faqs_suggestions.rb @@ -0,0 +1,11 @@ +class CreateFaqsSuggestions < ActiveRecord::Migration[5.2] + def change + create_table :faqs_suggestions do |t| + t.string :question + t.string :answer + t.references :topic, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20201204223755_create_faqs.rb b/db/migrate/20201204223755_create_faqs.rb new file mode 100644 index 00000000..90a687e8 --- /dev/null +++ b/db/migrate/20201204223755_create_faqs.rb @@ -0,0 +1,11 @@ +class CreateFaqs < ActiveRecord::Migration[5.2] + def change + create_table :faqs do |t| + t.string :question + t.string :answer + t.references :topic, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 96d61d72..6f8a41fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,35 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_11_14_163205) do +ActiveRecord::Schema.define(version: 2020_12_04_223755) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "faqs", force: :cascade do |t| + t.string "question" + t.string "answer" + t.bigint "topic_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["topic_id"], name: "index_faqs_on_topic_id" + end + + create_table "faqs_suggestions", force: :cascade do |t| + t.string "question" + t.string "answer" + t.bigint "topic_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["topic_id"], name: "index_faqs_suggestions_on_topic_id" + end + + create_table "topics", force: :cascade do |t| + t.string "titulo" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false @@ -30,4 +54,6 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "faqs", "topics" + add_foreign_key "faqs_suggestions", "topics" end diff --git a/features/Criar_sugestao_de_pergunta_e_resposta.feature b/features/Criar_sugestao_de_pergunta_e_resposta.feature new file mode 100644 index 00000000..19c0368f --- /dev/null +++ b/features/Criar_sugestao_de_pergunta_e_resposta.feature @@ -0,0 +1,14 @@ +Feature: Criar uma sugestão de pergunta e dar uma sugestão de resposta + Como usuário, + Quero cadastrar uma sugestão para de pergunta e também sugirir uma resposta para a pergunta para que eu possa ajudar no levatamento de perguntas + + + Scenario: + Given Que Usuario esteja logado como email "teste@teste1.com" e "123teste" + And Esteja página inicial e logado + And Clicar no link "FAQS" + When O Clicar no botão "Adicionar Sugestão" + Then O usuário preenche os campos de texto "fieldPergunta" e "fieldResposta" com uma "pergunta" e "resposta" + Then O usuário clica "Salvar Sugestão" + Then será cadastrado uma nova sugestão de pergunta e resposta + diff --git a/features/Criar_sugestao_de_resposta.feature b/features/Criar_sugestao_de_resposta.feature new file mode 100644 index 00000000..e77013df --- /dev/null +++ b/features/Criar_sugestao_de_resposta.feature @@ -0,0 +1,27 @@ + + +Feature: Enviar sugestão de resposta para uma pergunta já cadastrada + Como usuário, + Quero cadastrar uma sugestão de resposta para uma pergunta já cadastrar + Para que eu possa ajudar os administradores do sistema + + Scenario: + Given Que Usuario esteja logado como email "teste@teste1.com" e "123teste" + And Esteja página inicial e logado + And Clicar no link "FAQS" + When Clicar em alguma pergunta + When O Clicar no botão "Adicionar Sugestão" + Then O usuário preenche os campos de texto "fieldResposta" com uma "resposta" + Then O usuário clica "Salvar Sugestão" + Then será cadastrado uma nova sugestão de pergunta e resposta + + + @pending + Scenario: Titulo + Dado Realizacao + Quando Tipo de Usuario + Entao Objetivo + Exemplos: + | Razao | + | Valor 1 | + | Valor 2 | diff --git a/features/edicao_pergunta_resposta.feature b/features/edicao_pergunta_resposta.feature new file mode 100644 index 00000000..8bca3168 --- /dev/null +++ b/features/edicao_pergunta_resposta.feature @@ -0,0 +1,20 @@ +Feature: Editar resposta cadastrada +Como um administrador, para que eu mantenha as perguntas e respostas atualizadas, eu gostaria de editar uma resposta já cadastrada + +Scenario: Usuário administrador edita pergunta ou resposta + Given que um usuário admin está logado + And ele está na tela onde os faqs são exibidos + And a pergunta "como_editar", a resposta "editando" do tópico "editar_cadastro" existem + When o usuário administrador clicar no botão editar para alterar a pergunta "como_editar", a resposta "editando" do tópico "editar_cadastro" + Then deve carregar a tela que edita a pergunta "como_editar", a resposta "editando" do tópico "editar_cadastro" + When preenche o campo titulo, pergunta e resposta com um "titulo", "pergunta" e "resposta" + And clica no botao "Atualizar" + Then a pergunta, resposta e topico sao atualizados + + +Scenario: Usuario que não é adminstrador tenta editar uma pergunta ou resposta + Given que o usuario está logado + And o usuário não é um administrador + And o usuário esta na tela onde os faqs são exibidos + Then o usuario nao pode visualizar o botao "editar" + diff --git a/features/step_definitions/Criar_sugestao_de_pergunta_e_resposta.rb b/features/step_definitions/Criar_sugestao_de_pergunta_e_resposta.rb new file mode 100644 index 00000000..35d82394 --- /dev/null +++ b/features/step_definitions/Criar_sugestao_de_pergunta_e_resposta.rb @@ -0,0 +1,39 @@ +Given("Que Usuario esteja logado como email {string} e {string}")_ do |string, string2| + visit '/users/sign_in' + User.create(full_name: "usuario_teste", email: string, password: string2, role:"estudante", resgistration:"00000000001") + fill_in 'user_email', with: string + fill_in 'user_password', with: string2 + click_on 'Log in' + page.should have_content("Welcome! You have signed up successfully.") + end + + And("Esteja página inicial e logado") do + pending + end + + And("Clicar no link {link_faq}") do + pending + end + + When("O Clicar no botão {button_name}") do |button_name| + pending + end + + Then("O usuário preenche os campos de texto {field1} e {field2} com uma {value1} e {value2}") do |field1, field2, value1,value1| + pending + end + + Then("O usuário clica {button_name}") do |button_name| + pending + end + + Then("será cadastrado uma nova sugestão de pergunta e resposta") do + pending + end + + + + + + + diff --git a/features/step_definitions/Criar_sugestao_de_resposta.rb b/features/step_definitions/Criar_sugestao_de_resposta.rb new file mode 100644 index 00000000..f2f74879 --- /dev/null +++ b/features/step_definitions/Criar_sugestao_de_resposta.rb @@ -0,0 +1,35 @@ +Given("Que Usuario esteja logado como email {string} e com a senha {string}")_ do |string, string2| + visit '/users/sign_in' + User.create(full_name: "usuario_teste", email: string, password: string2, role:"estudante", resgistration:"00000000001") + fill_in 'user_email', with: string + fill_in 'user_password', with: string2 + click_on 'Log in' + page.should have_content("Welcome! You have signed up successfully.") + end + +And("Esteja página inicial e logado") do + pending + end + + And("Clicar no link {link_faq}") do + pending + end + + When("O Clicar no botão {button_name}") do |button_name| + pending + end + + Then("O usuário preenche os campos de texto {field} e {value}") do |field, value| + pending + end + + Then("O usuário clica {button_name}") do |button_name| + pending + end + + Then("será cadastrado uma nova sugestão de pergunta e resposta") do + pending + end + + + diff --git a/features/step_definitions/cadastro_pergunta_resposta.rb b/features/step_definitions/cadastro_pergunta_resposta.rb new file mode 100644 index 00000000..0fad6812 --- /dev/null +++ b/features/step_definitions/cadastro_pergunta_resposta.rb @@ -0,0 +1,37 @@ +#Usuário administrador cadastra nova pergunta e resposta em FAQ +Given("Usuário está logado com {email} e {password}") do |email, password| + pending +end + +And("Usuário se encontra na tela de FAQ") do + pending +end + +When("O usuário clica no botão {button_name}") do |button_name| + pending +end + +Then("O usuário preenche os campos de texto {fieldPergunta} e {fieldResposta} com uma {pergunta} e {resposta}") do |fieldPergunta, fieldResposta, pergunta, resposta| + pending +end + +Then("O usuário clica no botão {button_name}") do |button_name| + pending +end + +Then("É cadastrado um novo par Pergunta e Resposta") do + pending +end + +#Usuário sem privilégios não pode interagir com botão de Adicionar Pergunta e Resposta +Given("Usuário não logado com conta de administrador") do + pending +end + +And("Usuário se encontra na tela de FAQ") do + pending +end + +Then("O botão {button_name} deve estar indispoível") do |button_name| + pending +end \ No newline at end of file diff --git a/features/step_definitions/cadastro_topico_faq.rb b/features/step_definitions/cadastro_topico_faq.rb new file mode 100644 index 00000000..bbacfa89 --- /dev/null +++ b/features/step_definitions/cadastro_topico_faq.rb @@ -0,0 +1,37 @@ +#Usuário administrador cadastra novo tópico para organizar FAQ +Given("Usuário está logado com {email} e {password}") do |email, password| + pending +end + +And("Usuário se encontra na tela de FAQ") do + pending +end + +When("O usuário clica no botão {button_name}") do |button_name| + pending +end + +Then("O usuário preenche o campo de texto {field} com um {value}") do |field, value| + pending +end + +Then("O usuário clica no botão {button_name}") do |button_name| + pending +end + +Then("É cadastrado um novo tópico") do + pending +end + +#Usuário sem privilégios não pode interagir com botão de adicionar Tópico +Given("Usuário não logado com conta de administrador") do + pending +end + +And("Usuário se encontra na tela de FAQ") do + pending +end + +Then("O botão {button_name} deve estar indispoível") do |button_name| + pending +end \ No newline at end of file diff --git a/features/step_definitions/edicao_pergunta_resposta.rb b/features/step_definitions/edicao_pergunta_resposta.rb new file mode 100644 index 00000000..e86e2d8e --- /dev/null +++ b/features/step_definitions/edicao_pergunta_resposta.rb @@ -0,0 +1,47 @@ +Given("que um usuário admin está logado") do + pending # Write code here that turns the phrase above into concrete actions +end + +Given("ele está na tela onde os faqs são exibidos") do + pending # Write code here that turns the phrase above into concrete actions +end + +Given("a pergunta {string}, a resposta {string} do tópico {string} existem") do |string, string2, string3| + pending # Write code here that turns the phrase above into concrete actions +end + +When("o usuário administrador clicar no botão editar para alterar a pergunta {string}, a resposta {string} do tópico {string}") do |string, string2, string3| + pending # Write code here that turns the phrase above into concrete actions +end + +Then("deve carregar a tela que edita a pergunta {string}, a resposta {string} do tópico {string}") do |string, string2, string3| + pending # Write code here that turns the phrase above into concrete actions +end + +When("preenche o campo titulo, pergunta e resposta com um {string}, {string} e {string}") do |string, string2, string3| + pending # Write code here that turns the phrase above into concrete actions +end + +When("clica no botao {string}") do |string| + pending # Write code here that turns the phrase above into concrete actions +end + +Then("a pergunta, resposta e topico sao atualizados") do + pending # Write code here that turns the phrase above into concrete actions +end + +Given("que o usuario está logado") do + pending # Write code here that turns the phrase above into concrete actions +end + +Given("o usuário não é um administrador") do + pending # Write code here that turns the phrase above into concrete actions +end + +Given("o usuário esta na tela onde os faqs são exibidos") do + pending # Write code here that turns the phrase above into concrete actions +end + +Then("o usuario nao pode visualizar o botao {string}") do |string| + pending # Write code here that turns the phrase above into concrete actions +end \ No newline at end of file diff --git a/features/step_definitions/ver_perguntas_por_topico.rb b/features/step_definitions/ver_perguntas_por_topico.rb new file mode 100644 index 00000000..1961c5bd --- /dev/null +++ b/features/step_definitions/ver_perguntas_por_topico.rb @@ -0,0 +1,7 @@ +Given("Que o usuário esta na tela {string}") do |string| + pending # Write code here that turns the phrase above into concrete actions +end + +Then("Ele pode vesualizar a pergunta {string}, a resposta {string} do tópico {string}") do |string, string2, string3| + pending # Write code here that turns the phrase above into concrete actions +end \ No newline at end of file diff --git a/features/support/cadastro_pergunta_resposta_faq.feature b/features/support/cadastro_pergunta_resposta_faq.feature new file mode 100644 index 00000000..03560630 --- /dev/null +++ b/features/support/cadastro_pergunta_resposta_faq.feature @@ -0,0 +1,46 @@ +Feature: Cadastro de Pergunta e Resposta para o FAQ +Como um usuário, para que eu possa ajudar no levantamento de perguntas, eu gostaria de fazer uma sugestão de pergunta e dar uma sugestão de resposta + +Scenario: Usuário administrador cadastra nova pergunta e resposta em FAQ + Given Usuário está logado com "admin@cucumber.com" e "admin123" + And Usuário se encontra na tela de FAQ + When O usuário clica no botão "Adicionar Pergunta e Resposta" + Then O usuário preenche os campos de texto "fieldPergunta" e "fieldResposta" com uma "pergunta" e "resposta" + Then O usuário clica no botão "Salvar" + Then É cadastrado um novo par Pergunta e Resposta + +Scenario: Usuário administrador cadastra nova pergunta e resposta em FAQ + Given Usuário está logado com "admin@cucumber.com" e "admin123" + And Usuário se encontra na tela de FAQ + When O usuário clica no botão "Adicionar Pergunta e Resposta" + Then O usuário preenche os campos de texto "fieldPergunta" com uma "pergunta" + Then O usuário clica no botão "Salvar" + Then É rejeitado o cadastro de uma nova resposta + Then Exibe um alerta "É necessário cadastrar uma resposta" + +Scenario: Usuário sem privilégios não pode interagir com botão de Adicionar Pergunta e Resposta + Given Usuário não logado com conta de administrador + And Usuário se encontra na tela de FAQ + Then O botão "Adicionar Pergunta e Resposta" deve estar indisponível + +Scenario: Usuário sem privilégios pode interagir com botão de Adicionar Sugestão de Pergunta e Resposta + Given Usuário não logado com conta de "teste@teste1.com" + And Usuário se encontra na tela de FAQ + Then O botão "Adicionar Sugestão de Pergunta e Resposta" deve estar disponível + +Scenario: Usuario cadastra nova pergunta e resposta em FAQ + Given Usuario esta logado com o email "teste@teste1.com" + And Usuario se encontra na tela de FAQ + When O usuário clica no botão "Adicionar Pergunta e Resposta" + Then O usuário preenche os campos de texto "fieldPergunta" e "fieldResposta" com uma "pergunta" e "resposta" + Then O usuário clica no botão "Salvar" + Then É cadastrado um novo par de sugestão Pergunta e Resposta + +Scenario: Usuario cadastra nova pergunta e resposta em FAQ + Given Usuario esta logado com o email "teste@teste1.com" + And Usuario se encontra na tela de FAQ + When O usuário clica no botão "Adicionar Pergunta e Resposta" + Then O usuário preenche os campos de texto "fieldPergunta" com uma "pergunta" + Then O usuário clica no botão "Salvar" + Then É rejeitado o cadastro de uma nova resposta + Then Exibe um alerta "É necessário cadastrar uma resposta para sua sugestão" \ No newline at end of file diff --git a/features/support/cadastro_topico_faq.feature b/features/support/cadastro_topico_faq.feature new file mode 100644 index 00000000..d9b94f59 --- /dev/null +++ b/features/support/cadastro_topico_faq.feature @@ -0,0 +1,15 @@ +Feature: Cadastro de Topico para o FAQ +Como um administrador, para que eu possa organizar as perguntas e respostas, eu gostaria de cadastrar tópicos para as perguntas e respostas + +Scenario: Usuário administrador cadastra novo tópico para organizar FAQ + Given Usuário está logado com "admin@cucumber.com" e "admin123" + And Usuário se encontra na tela de FAQ + When O usuário clica no botão "Adicionar tópico" + Then O usuário preenche o campo de texto "Tópico" com um "topico" + Then O usuário clica no botão "Salvar" + Then É cadastrado um novo tópico + +Scenario: Usuário sem privilégios não pode interagir com botão de adicionar Tópico + Given Usuário não logado com conta de administrador + And Usuário se encontra na tela de FAQ + Then O botão "Adicionar tópico" deve estar indisponível diff --git a/features/ver_perguntas_por_topico.feature b/features/ver_perguntas_por_topico.feature new file mode 100644 index 00000000..ab8069db --- /dev/null +++ b/features/ver_perguntas_por_topico.feature @@ -0,0 +1,13 @@ +Feature: Ver perguntas por topico +Como um usuário, para que eu possa me informar, eu gostaria de ver as perguntas separadas por tópicos + +Scenario: Ver pergunta por um topico + Given Que o usuário esta na tela "/faqs" + And a pergunta "como_editar", a resposta "editando" do tópico "editar_cadastro" existem + Then Ele pode visualizar a pergunta "como_editar", a resposta "editando" do tópico "editar_cadastro" + +Scenario: Ver pergunta por um topico + Given Que o usuário esta na tela "/faqs" + And a pergunta "como_editar", a resposta "editando" existem + And nenhum tópico está disponível + Then Ele não pode visualizar a pergunta "como_editar", a resposta "editando" separado por tópico \ No newline at end of file diff --git a/spec/controllers/faqs_controller_spec.rb b/spec/controllers/faqs_controller_spec.rb new file mode 100644 index 00000000..9a0c89de --- /dev/null +++ b/spec/controllers/faqs_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe FaqsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Faq. As you add validations to Faq, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # FaqsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Faq.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + faq = Faq.create! valid_attributes + get :show, params: {id: faq.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + faq = Faq.create! valid_attributes + get :edit, params: {id: faq.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Faq" do + expect { + post :create, params: {faq: valid_attributes}, session: valid_session + }.to change(Faq, :count).by(1) + end + + it "redirects to the created faq" do + post :create, params: {faq: valid_attributes}, session: valid_session + expect(response).to redirect_to(Faq.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {faq: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested faq" do + faq = Faq.create! valid_attributes + put :update, params: {id: faq.to_param, faq: new_attributes}, session: valid_session + faq.reload + skip("Add assertions for updated state") + end + + it "redirects to the faq" do + faq = Faq.create! valid_attributes + put :update, params: {id: faq.to_param, faq: valid_attributes}, session: valid_session + expect(response).to redirect_to(faq) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + faq = Faq.create! valid_attributes + put :update, params: {id: faq.to_param, faq: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested faq" do + faq = Faq.create! valid_attributes + expect { + delete :destroy, params: {id: faq.to_param}, session: valid_session + }.to change(Faq, :count).by(-1) + end + + it "redirects to the faqs list" do + faq = Faq.create! valid_attributes + delete :destroy, params: {id: faq.to_param}, session: valid_session + expect(response).to redirect_to(faqs_url) + end + end + +end diff --git a/spec/controllers/faqs_suggestions_controller_spec.rb b/spec/controllers/faqs_suggestions_controller_spec.rb new file mode 100644 index 00000000..003159bc --- /dev/null +++ b/spec/controllers/faqs_suggestions_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe FaqsSuggestionsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # FaqsSuggestion. As you add validations to FaqsSuggestion, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # FaqsSuggestionsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + FaqsSuggestion.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + get :show, params: {id: faqs_suggestion.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + get :edit, params: {id: faqs_suggestion.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new FaqsSuggestion" do + expect { + post :create, params: {faqs_suggestion: valid_attributes}, session: valid_session + }.to change(FaqsSuggestion, :count).by(1) + end + + it "redirects to the created faqs_suggestion" do + post :create, params: {faqs_suggestion: valid_attributes}, session: valid_session + expect(response).to redirect_to(FaqsSuggestion.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {faqs_suggestion: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested faqs_suggestion" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + put :update, params: {id: faqs_suggestion.to_param, faqs_suggestion: new_attributes}, session: valid_session + faqs_suggestion.reload + skip("Add assertions for updated state") + end + + it "redirects to the faqs_suggestion" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + put :update, params: {id: faqs_suggestion.to_param, faqs_suggestion: valid_attributes}, session: valid_session + expect(response).to redirect_to(faqs_suggestion) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + put :update, params: {id: faqs_suggestion.to_param, faqs_suggestion: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested faqs_suggestion" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + expect { + delete :destroy, params: {id: faqs_suggestion.to_param}, session: valid_session + }.to change(FaqsSuggestion, :count).by(-1) + end + + it "redirects to the faqs_suggestions list" do + faqs_suggestion = FaqsSuggestion.create! valid_attributes + delete :destroy, params: {id: faqs_suggestion.to_param}, session: valid_session + expect(response).to redirect_to(faqs_suggestions_url) + end + end + +end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb new file mode 100644 index 00000000..a8431a1e --- /dev/null +++ b/spec/controllers/topics_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe TopicsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Topic. As you add validations to Topic, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # TopicsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Topic.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + topic = Topic.create! valid_attributes + get :show, params: {id: topic.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + topic = Topic.create! valid_attributes + get :edit, params: {id: topic.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Topic" do + expect { + post :create, params: {topic: valid_attributes}, session: valid_session + }.to change(Topic, :count).by(1) + end + + it "redirects to the created topic" do + post :create, params: {topic: valid_attributes}, session: valid_session + expect(response).to redirect_to(Topic.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {topic: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested topic" do + topic = Topic.create! valid_attributes + put :update, params: {id: topic.to_param, topic: new_attributes}, session: valid_session + topic.reload + skip("Add assertions for updated state") + end + + it "redirects to the topic" do + topic = Topic.create! valid_attributes + put :update, params: {id: topic.to_param, topic: valid_attributes}, session: valid_session + expect(response).to redirect_to(topic) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + topic = Topic.create! valid_attributes + put :update, params: {id: topic.to_param, topic: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested topic" do + topic = Topic.create! valid_attributes + expect { + delete :destroy, params: {id: topic.to_param}, session: valid_session + }.to change(Topic, :count).by(-1) + end + + it "redirects to the topics list" do + topic = Topic.create! valid_attributes + delete :destroy, params: {id: topic.to_param}, session: valid_session + expect(response).to redirect_to(topics_url) + end + end + +end diff --git a/spec/helpers/faqs_helper_spec.rb b/spec/helpers/faqs_helper_spec.rb new file mode 100644 index 00000000..1d616aff --- /dev/null +++ b/spec/helpers/faqs_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the FaqsHelper. For example: +# +# describe FaqsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe FaqsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/faqs_suggestions_helper_spec.rb b/spec/helpers/faqs_suggestions_helper_spec.rb new file mode 100644 index 00000000..ff2dca03 --- /dev/null +++ b/spec/helpers/faqs_suggestions_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the FaqsSuggestionsHelper. For example: +# +# describe FaqsSuggestionsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe FaqsSuggestionsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/topics_helper_spec.rb b/spec/helpers/topics_helper_spec.rb new file mode 100644 index 00000000..6adfadb6 --- /dev/null +++ b/spec/helpers/topics_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the TopicsHelper. For example: +# +# describe TopicsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe TopicsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/faq_spec.rb b/spec/models/faq_spec.rb new file mode 100644 index 00000000..d35212db --- /dev/null +++ b/spec/models/faq_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Faq, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/faqs_suggestion_spec.rb b/spec/models/faqs_suggestion_spec.rb new file mode 100644 index 00000000..3cdacd93 --- /dev/null +++ b/spec/models/faqs_suggestion_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe FaqsSuggestion, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb new file mode 100644 index 00000000..b8c5a8e0 --- /dev/null +++ b/spec/models/topic_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Topic, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/faqs_spec.rb b/spec/requests/faqs_spec.rb new file mode 100644 index 00000000..04ac8b2c --- /dev/null +++ b/spec/requests/faqs_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Faqs", type: :request do + describe "GET /faqs" do + it "works! (now write some real specs)" do + get faqs_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/requests/faqs_suggestions_spec.rb b/spec/requests/faqs_suggestions_spec.rb new file mode 100644 index 00000000..b41c3a5f --- /dev/null +++ b/spec/requests/faqs_suggestions_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "FaqsSuggestions", type: :request do + describe "GET /faqs_suggestions" do + it "works! (now write some real specs)" do + get faqs_suggestions_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/requests/topics_spec.rb b/spec/requests/topics_spec.rb new file mode 100644 index 00000000..3618347c --- /dev/null +++ b/spec/requests/topics_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Topics", type: :request do + describe "GET /topics" do + it "works! (now write some real specs)" do + get topics_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/faqs_routing_spec.rb b/spec/routing/faqs_routing_spec.rb new file mode 100644 index 00000000..1a047567 --- /dev/null +++ b/spec/routing/faqs_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe FaqsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/faqs").to route_to("faqs#index") + end + + it "routes to #new" do + expect(:get => "/faqs/new").to route_to("faqs#new") + end + + it "routes to #show" do + expect(:get => "/faqs/1").to route_to("faqs#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/faqs/1/edit").to route_to("faqs#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/faqs").to route_to("faqs#create") + end + + it "routes to #update via PUT" do + expect(:put => "/faqs/1").to route_to("faqs#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/faqs/1").to route_to("faqs#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/faqs/1").to route_to("faqs#destroy", :id => "1") + end + end +end diff --git a/spec/routing/faqs_suggestions_routing_spec.rb b/spec/routing/faqs_suggestions_routing_spec.rb new file mode 100644 index 00000000..d8537dda --- /dev/null +++ b/spec/routing/faqs_suggestions_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe FaqsSuggestionsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/faqs_suggestions").to route_to("faqs_suggestions#index") + end + + it "routes to #new" do + expect(:get => "/faqs_suggestions/new").to route_to("faqs_suggestions#new") + end + + it "routes to #show" do + expect(:get => "/faqs_suggestions/1").to route_to("faqs_suggestions#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/faqs_suggestions/1/edit").to route_to("faqs_suggestions#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/faqs_suggestions").to route_to("faqs_suggestions#create") + end + + it "routes to #update via PUT" do + expect(:put => "/faqs_suggestions/1").to route_to("faqs_suggestions#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/faqs_suggestions/1").to route_to("faqs_suggestions#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/faqs_suggestions/1").to route_to("faqs_suggestions#destroy", :id => "1") + end + end +end diff --git a/spec/routing/topics_routing_spec.rb b/spec/routing/topics_routing_spec.rb new file mode 100644 index 00000000..aa317a9d --- /dev/null +++ b/spec/routing/topics_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe TopicsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/topics").to route_to("topics#index") + end + + it "routes to #new" do + expect(:get => "/topics/new").to route_to("topics#new") + end + + it "routes to #show" do + expect(:get => "/topics/1").to route_to("topics#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/topics/1/edit").to route_to("topics#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/topics").to route_to("topics#create") + end + + it "routes to #update via PUT" do + expect(:put => "/topics/1").to route_to("topics#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/topics/1").to route_to("topics#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/topics/1").to route_to("topics#destroy", :id => "1") + end + end +end diff --git a/spec/views/faq/index.html.erb_spec.rb b/spec/views/faq/index.html.erb_spec.rb new file mode 100644 index 00000000..8ca78177 --- /dev/null +++ b/spec/views/faq/index.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "faq/index.html.erb", type: :view do + pending "add some questions to (or delete) #{__FILE__}" +end diff --git a/spec/views/faqs/edit.html.erb_spec.rb b/spec/views/faqs/edit.html.erb_spec.rb new file mode 100644 index 00000000..4aeedc96 --- /dev/null +++ b/spec/views/faqs/edit.html.erb_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe "faqs/edit", type: :view do + before(:each) do + @faq = assign(:faq, Faq.create!( + :question => "MyString", + :answer => "MyString", + :topic => nil + )) + end + + it "renders the edit faq form" do + render + + assert_select "form[action=?][method=?]", faq_path(@faq), "post" do + + assert_select "input[name=?]", "faq[question]" + + assert_select "input[name=?]", "faq[answer]" + + assert_select "input[name=?]", "faq[topic_id]" + end + end +end + +RSpec.describe "topics/edit", type: :view do + before(:each) do + @faq = assign(:faq, Faq.create!( + :question => "MyString", + :answer => "MyString", + :topic => "MyString" + )) + end + + it "renders the edit faq form" do + render + + assert_select "form[action=?][method=?]", faq_path(@faq), "post" do + + assert_select "input[name=?]", "faq[question]" + + assert_select "input[name=?]", "faq[answer]" + + assert_select "input[name=?]", "faq[topic_id]" + end + end +end diff --git a/spec/views/faqs/index.html.erb_spec.rb b/spec/views/faqs/index.html.erb_spec.rb new file mode 100644 index 00000000..90d96bed --- /dev/null +++ b/spec/views/faqs/index.html.erb_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe "faqs/index", type: :view do + before(:each) do + assign(:faqs, [ + Faq.create!( + :question => "Question", + :answer => "Answer", + :topic => nil + ), + Faq.create!( + :question => "Question", + :answer => "Answer", + :topic => nil + ) + ]) + end + + it "renders a list of faqs" do + render + assert_select "tr>td", :text => "Question".to_s, :count => 2 + assert_select "tr>td", :text => "Answer".to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + end +end diff --git a/spec/views/faqs/new.html.erb_spec.rb b/spec/views/faqs/new.html.erb_spec.rb new file mode 100644 index 00000000..b1194b55 --- /dev/null +++ b/spec/views/faqs/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "faqs/new", type: :view do + before(:each) do + assign(:faq, Faq.new( + :question => "MyString", + :answer => "MyString", + :topic => nil + )) + end + + it "renders new faq form" do + render + + assert_select "form[action=?][method=?]", faqs_path, "post" do + + assert_select "input[name=?]", "faq[question]" + + assert_select "input[name=?]", "faq[answer]" + + assert_select "input[name=?]", "faq[topic_id]" + end + end +end diff --git a/spec/views/faqs/newTopic.html.erb_spec.rb b/spec/views/faqs/newTopic.html.erb_spec.rb new file mode 100644 index 00000000..5be2a7ed --- /dev/null +++ b/spec/views/faqs/newTopic.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "topics/new", type: :view do + before(:each) do + assign(:faq, Faq.new( + :title => "MyString", + :question => nil + )) + end + + it "renders new faq form" do + render + + assert_select "input[name=?]", "faq[topic_id]" + end +end diff --git a/spec/views/faqs/show.html.erb_spec.rb b/spec/views/faqs/show.html.erb_spec.rb new file mode 100644 index 00000000..a1ae3ee5 --- /dev/null +++ b/spec/views/faqs/show.html.erb_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +RSpec.describe "faqs/show", type: :view do + before(:each) do + @faq = assign(:faq, Faq.create!( + :question => "Question", + :answer => "Answer", + :topic => nil + )) + end + + it "renders attributes in" do + render + expect(rendered).to match(/Question/) + expect(rendered).to match(/Answer/) + expect(rendered).to match(//) + end +end + +RSpec.describe "topics/show", type: :view do + before(:each) do + @faq = assign(:faq, Faq.create!( + :question => "Question", + :answer => "Answer", + :topic => "Topic" + )) + end + + it "renders attributes in
" do + render + expect(rendered).to match(/Question/) + expect(rendered).to match(/Answer/) + expect(rendered).to match(/Topic/) + end +end + diff --git a/spec/views/faqs_suggestions/edit.html.erb_spec.rb b/spec/views/faqs_suggestions/edit.html.erb_spec.rb new file mode 100644 index 00000000..d66e9794 --- /dev/null +++ b/spec/views/faqs_suggestions/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "faqs_suggestions/edit", type: :view do + before(:each) do + @faqs_suggestion = assign(:faqs_suggestion, FaqsSuggestion.create!( + :question => "MyString", + :answer => "MyString", + :topic => nil + )) + end + + it "renders the edit faqs_suggestion form" do + render + + assert_select "form[action=?][method=?]", faqs_suggestion_path(@faqs_suggestion), "post" do + + assert_select "input[name=?]", "faqs_suggestion[question]" + + assert_select "input[name=?]", "faqs_suggestion[answer]" + + assert_select "input[name=?]", "faqs_suggestion[topic_id]" + end + end +end diff --git a/spec/views/faqs_suggestions/index.html.erb_spec.rb b/spec/views/faqs_suggestions/index.html.erb_spec.rb new file mode 100644 index 00000000..1605b3df --- /dev/null +++ b/spec/views/faqs_suggestions/index.html.erb_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe "faqs_suggestions/index", type: :view do + before(:each) do + assign(:faqs_suggestions, [ + FaqsSuggestion.create!( + :question => "Question", + :answer => "Answer", + :topic => nil + ), + FaqsSuggestion.create!( + :question => "Question", + :answer => "Answer", + :topic => nil + ) + ]) + end + + it "renders a list of faqs_suggestions" do + render + assert_select "tr>td", :text => "Question".to_s, :count => 2 + assert_select "tr>td", :text => "Answer".to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + end +end diff --git a/spec/views/faqs_suggestions/new.html.erb_spec.rb b/spec/views/faqs_suggestions/new.html.erb_spec.rb new file mode 100644 index 00000000..94046571 --- /dev/null +++ b/spec/views/faqs_suggestions/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "faqs_suggestions/new", type: :view do + before(:each) do + assign(:faqs_suggestion, FaqsSuggestion.new( + :question => "MyString", + :answer => "MyString", + :topic => nil + )) + end + + it "renders new faqs_suggestion form" do + render + + assert_select "form[action=?][method=?]", faqs_suggestions_path, "post" do + + assert_select "input[name=?]", "faqs_suggestion[question]" + + assert_select "input[name=?]", "faqs_suggestion[answer]" + + assert_select "input[name=?]", "faqs_suggestion[topic_id]" + end + end +end diff --git a/spec/views/faqs_suggestions/show.html.erb_spec.rb b/spec/views/faqs_suggestions/show.html.erb_spec.rb new file mode 100644 index 00000000..404c8c2e --- /dev/null +++ b/spec/views/faqs_suggestions/show.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "faqs_suggestions/show", type: :view do + before(:each) do + @faqs_suggestion = assign(:faqs_suggestion, FaqsSuggestion.create!( + :question => "Question", + :answer => "Answer", + :topic => nil + )) + end + + it "renders attributes in
" do + render + expect(rendered).to match(/Question/) + expect(rendered).to match(/Answer/) + expect(rendered).to match(//) + end +end diff --git a/spec/views/topics/edit.html.erb_spec.rb b/spec/views/topics/edit.html.erb_spec.rb new file mode 100644 index 00000000..3a80bd95 --- /dev/null +++ b/spec/views/topics/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "topics/edit", type: :view do + before(:each) do + @topic = assign(:topic, Topic.create!( + :titulo => "MyString" + )) + end + + it "renders the edit topic form" do + render + + assert_select "form[action=?][method=?]", topic_path(@topic), "post" do + + assert_select "input[name=?]", "topic[titulo]" + end + end +end diff --git a/spec/views/topics/index.html.erb_spec.rb b/spec/views/topics/index.html.erb_spec.rb new file mode 100644 index 00000000..6bf30731 --- /dev/null +++ b/spec/views/topics/index.html.erb_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe "topics/index", type: :view do + before(:each) do + assign(:topics, [ + Topic.create!( + :titulo => "Titulo" + ), + Topic.create!( + :titulo => "Titulo" + ) + ]) + end + + it "renders a list of topics" do + render + assert_select "tr>td", :text => "Titulo".to_s, :count => 2 + end +end diff --git a/spec/views/topics/new.html.erb_spec.rb b/spec/views/topics/new.html.erb_spec.rb new file mode 100644 index 00000000..f66599d6 --- /dev/null +++ b/spec/views/topics/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "topics/new", type: :view do + before(:each) do + assign(:topic, Topic.new( + :titulo => "MyString" + )) + end + + it "renders new topic form" do + render + + assert_select "form[action=?][method=?]", topics_path, "post" do + + assert_select "input[name=?]", "topic[titulo]" + end + end +end diff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rb new file mode 100644 index 00000000..d7ad0234 --- /dev/null +++ b/spec/views/topics/show.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "topics/show", type: :view do + before(:each) do + @topic = assign(:topic, Topic.create!( + :titulo => "Titulo" + )) + end + + it "renders attributes in
" do + render + expect(rendered).to match(/Titulo/) + end +end