diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cb73077..96e6f77 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,8 +3,6 @@ class ApplicationController < ActionController::Base before_action :authenticate_user! before_action :set_beginning_of_week - rescue_from ActiveRecord::RecordNotFound, with: :not_found - protected def set_beginning_of_week @@ -15,10 +13,6 @@ def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:cpf]) end - def not_found - redirect_to root_path, alert: t('.not_found') - end - def after_sign_in_path_for(resource) stored_location_for(resource) || projects_path end diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 94c5067..b845082 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -1,23 +1,23 @@ class TasksController < ApplicationController - before_action :set_project, only: %i[new create index] - before_action :set_contributors, only: %i[new create edit update] + before_action :set_project before_action :set_task, only: %i[show edit update start finish cancel] - before_action :check_user, only: %i[edit update] + before_action :check_contributor + before_action :can_edit_task, only: %i[edit update] def index @tasks = @project.tasks end def new - @task = @project.tasks.build + @task = @project.tasks.new end def create @task = @project.tasks.build(task_params) - @task.author_id = current_user.id + @task.user_role = UserRole.find_by(user: current_user, project: @project) if @task.save - redirect_to task_path(@task), notice: t('.success') + redirect_to [@project, @task], notice: t('.success') else flash.now[:alert] = t('.fail') render :new, status: :unprocessable_entity @@ -30,7 +30,7 @@ def edit; end def update if @task.update(task_params) - redirect_to task_path(@task), notice: t('.success') + redirect_to [@project, @task], notice: t('.success') else flash.now[:alert] = t('.fail') render :edit, status: :unprocessable_entity @@ -39,17 +39,17 @@ def update def start @task.in_progress! - redirect_to task_path, notice: t('.success') + redirect_to project_task_path(@project), notice: t('.success') end def finish @task.finished! - redirect_to task_path, notice: t('.success') + redirect_to project_task_path(@project), notice: t('.success') end def cancel @task.cancelled! - redirect_to task_path, notice: t('.success') + redirect_to project_task_path(@project), notice: t('.success') end private @@ -58,12 +58,6 @@ def set_project @project = Project.find(params[:project_id]) end - def set_contributors - # TODO - # Limitar para os colaboradores do projeto - @contributors = User.all - end - def set_task @task = Task.find(params[:id]) end @@ -72,8 +66,11 @@ def task_params params.require(:task).permit(:title, :description, :due_date, :assigned_id) end - def check_user - redirect_to root_path, alert: t('.fail') \ - unless @task.author == current_user || @task.assigned == current_user || @task.project.user == current_user + def check_contributor + redirect_to root_path, alert: t('.not_contributor') unless @project.member?(current_user) + end + + def can_edit_task + redirect_to project_task_path(@project, @task), alert: t('.fail') unless current_user.can_edit?(@task) end end diff --git a/app/models/meeting.rb b/app/models/meeting.rb index 25d9812..c4f4b83 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -1,5 +1,6 @@ class Meeting < ApplicationRecord belongs_to :user_role + delegate :user, to: :user_role belongs_to :project validates :title, :datetime, :duration, :address, presence: true diff --git a/app/models/project.rb b/app/models/project.rb index ae774d6..75efc0f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,7 @@ class Project < ApplicationRecord belongs_to :user has_many :user_roles, dependent: :destroy + has_many :users, through: :user_roles has_many :tasks, dependent: :destroy has_many :invitations, dependent: :destroy has_many :documents, dependent: :destroy @@ -11,6 +12,10 @@ class Project < ApplicationRecord after_create :set_leader_on_create + def admin?(user) + member?(user) && user_roles.find_by(user:).admin? + end + def member?(user) user_roles.find_by(user:).present? end diff --git a/app/models/task.rb b/app/models/task.rb index 42dcefe..536d06c 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -1,6 +1,7 @@ class Task < ApplicationRecord belongs_to :project - belongs_to :author, class_name: 'User' + belongs_to :user_role + delegate :user, to: :user_role belongs_to :assigned, class_name: 'User', optional: true enum status: { uninitialized: 0, in_progress: 3, finished: 5, expired: 7, cancelled: 9 } diff --git a/app/models/user.rb b/app/models/user.rb index d75017b..20ed556 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,9 +17,8 @@ class User < ApplicationRecord delegate :full_name, to: :profile - def can_edit?(meeting) - user_role = UserRole.get_user_role(meeting.project, self) - meeting.user_role.user == self || user_role.leader? || user_role.admin? + def can_edit?(item) + item.user == self || item.project.leader?(self) || item.project.admin?(self) end def all_projects diff --git a/app/models/user_role.rb b/app/models/user_role.rb index a6b1c8f..2cba629 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -8,10 +8,6 @@ class UserRole < ApplicationRecord default_scope { where(active: true) } - def self.get_user_role(project, user) - UserRole.find_by(user:, project:) - end - private def only_one_leader_per_project diff --git a/app/views/calendars/index.html.erb b/app/views/calendars/index.html.erb index b343c91..2572feb 100644 --- a/app/views/calendars/index.html.erb +++ b/app/views/calendars/index.html.erb @@ -1,5 +1,4 @@ <%= render 'shared/project_header', project: @project %> - <%= form_with url: project_calendars_path(@project), class: "d-flex row justify-content-end mb-3", id: "filter-form", @@ -16,19 +15,17 @@ class: 'btn btn-sm btn-outline-secondary' %> <% end %> - <%= month_calendar(events: @events) do |date, events| %>
<%= date.day %> - <% events.each do |event| %>
<% if event.is_a? Meeting %> <%= link_to event.title, project_meeting_path(@project, event), class: 'btn btn-sm btn-purple' %> <% elsif event.is_a? Task %> - <%= link_to event.title, task_path(event), class: 'btn btn-sm btn-green' %> + <%= link_to event.title, project_task_path(@project, event), class: 'btn btn-sm btn-green' %> <% end %>
<% end %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/tasks/_form.html.erb b/app/views/tasks/_form.html.erb index d91f8e3..4472a9b 100644 --- a/app/views/tasks/_form.html.erb +++ b/app/views/tasks/_form.html.erb @@ -1,5 +1,5 @@ -<%= form_with(model: [@project, @task]) do |f| %> - <% if @task.errors.any? %> +<%= form_with(model: [@project, @task]) do |f| %> + <% if @task.errors.any? %>

<%= I18n.t('.errors_title') %>:

<% end %> -
<%= f.label :title, class: 'form-label' %> <%= f.text_field :title, class: 'form-control' %> @@ -24,10 +23,10 @@
<%= f.label :assigned_id, class: 'form-label' %> - <%= f.collection_select :assigned_id, @contributors, :id, :email, :include_blank => true, class: 'form-control' %> + <%= f.collection_select :assigned_id, @project.users, :id, :email, :include_blank => true, class: 'form-control' %>
<%= f.submit I18n.t('tasks.save'), class: 'btn btn-primary'%> <%= link_to t(:back), project_tasks_path(@task.project), class: 'btn btn-secondary' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb index e71193b..6152363 100644 --- a/app/views/tasks/index.html.erb +++ b/app/views/tasks/index.html.erb @@ -24,7 +24,7 @@ <% @tasks.each do |task| %> - <%= link_to task.title, task_path(task) %> + <%= link_to task.title, project_task_path(@project, task) %> <%= task.assigned ? task.assigned.email : t('tasks.no_assigned') %> <%= task.due_date ? task.due_date : t('tasks.no_due_date') %> <%= t(task.status) %> diff --git a/app/views/tasks/show.html.erb b/app/views/tasks/show.html.erb index 49396c1..d4197e2 100644 --- a/app/views/tasks/show.html.erb +++ b/app/views/tasks/show.html.erb @@ -1,23 +1,18 @@ <%= render 'shared/project_header', project: @task.project %> -

<%= Task.model_name.human %>: <%= @task.title %>

<%= Task.human_attribute_name :description %>
<%= @task.description %>
- -
<%= Task.human_attribute_name :author %>
-
<%= @task.author.email %>
- +
<%= Task.human_attribute_name :user_role %>
+
<%= @task.user_role.user.email %>
<%= Task.human_attribute_name :status %>
<%= I18n.t(@task.status) %>
-
<%= Task.human_attribute_name :assigned %>
<% if @task.assigned %>
<%= @task.assigned.email %>
<% else %>
<%= I18n.t('tasks.no_assigned') %>
<% end %> -
<%= Task.human_attribute_name :due_date %>
<% if @task.due_date %>
<%= I18n.l @task.due_date %>
@@ -25,26 +20,24 @@
<%= I18n.t('tasks.no_due_date') %>
<% end %>
-
<%= button_to I18n.t('tasks.start_task'), - start_task_path(@task), + start_project_task_path(@project, @task), method: :patch, class: 'btn btn-primary me-2' if @task.uninitialized? %> <%= button_to I18n.t('tasks.finish_task'), - finish_task_path(@task), + finish_project_task_path(@task), method: :patch, class: 'btn btn-primary me-2' if @task.in_progress? %> <%= button_to I18n.t('tasks.cancel_task'), - cancel_task_path(@task), + cancel_project_task_path(@project, @task), method: :patch, data: { turbo_confirm: t(:task_cancel_confirmation) }, - class: 'btn btn-danger me-2' if @task.uninitialized? || @task.in_progress?%> + class: 'btn btn-danger me-2' if @task.uninitialized? || @task.in_progress? %> <%= link_to I18n.t('tasks.edit_task'), - edit_task_path(@task), + edit_project_task_path(@project, @task), class: 'btn btn-secondary' unless @task.finished? || @task.cancelled? %>
-
<%= link_to I18n.t('.back'), project_tasks_path(@task.project), class: 'btn btn-secondary' %> -
\ No newline at end of file + diff --git a/config/locales/models/tasks.pt-BR.yml b/config/locales/models/tasks.pt-BR.yml index 283362e..f486c0b 100644 --- a/config/locales/models/tasks.pt-BR.yml +++ b/config/locales/models/tasks.pt-BR.yml @@ -1,48 +1,48 @@ pt-BR: - uninitialized: Não iniciada - in_progress: Em andamento - task_empty_state: Sem tarefas registradas - finished: Finalizada - expired: Expirada - cancelled: Cancelada - task_cancel_confirmation: Cancelar tarefa? - activerecord: - models: - task: - one: Tarefa - other: Tarefas - attributes: - task: - title: Título - description: Descrição - due_date: Prazo - project_id: Projeto - author_id: Autor - author: Autor - assigned_id: Responsável - assigned: Responsável - status: Status - tasks: - create: - success: Tarefa criada com sucesso. - fail: Não foi possível criar a tarefa. - update: - success: Tarefa editada com sucesso. - fail: Não foi possível editar a tarefa. - start: - success: Tarefa iniciada. - finish: - success: Tarefa finalizada. - cancel: - success: Tarefa cancelada. - check_user: - fails: 'Você não possui acesso a esta tarefa.' - edit_task: Editar Tarefa - start_task: Iniciar Tarefa - finish_task: Finalizar Tarefa - cancel_task: Cancelar Tarefa - new_task: Nova Tarefa - create_task: Criar Tarefa - no_due_date: Sem prazo - no_assigned: Sem responsável - save: Salvar + uninitialized: Não iniciada + in_progress: Em andamento + task_empty_state: Sem tarefas registradas + finished: Finalizada + expired: Expirada + cancelled: Cancelada + task_cancel_confirmation: Cancelar tarefa? + activerecord: + models: + task: + one: Tarefa + other: Tarefas + attributes: + task: + title: Título + description: Descrição + due_date: Prazo + project_id: Projeto + user_role_id: Autor + user_role: Autor + assigned_id: Responsável + assigned: Responsável + status: Status + tasks: + create: + success: Tarefa criada com sucesso. + fail: Não foi possível criar a tarefa. + update: + success: Tarefa editada com sucesso. + fail: Não foi possível editar a tarefa. + start: + success: Tarefa iniciada. + finish: + success: Tarefa finalizada. + cancel: + success: Tarefa cancelada. + check_user: + fails: "Você não possui acesso a esta tarefa." + edit_task: Editar Tarefa + start_task: Iniciar Tarefa + finish_task: Finalizar Tarefa + cancel_task: Cancelar Tarefa + new_task: Nova Tarefa + create_task: Criar Tarefa + no_due_date: Sem prazo + no_assigned: Sem responsável + save: Salvar diff --git a/config/routes.rb b/config/routes.rb index 375b61c..1bed44b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,13 @@ resources :profiles, only: %i[edit update show] resources :projects, only: %i[new create show index edit update destroy] do - resources :tasks, only: %i[index new create] + resources :tasks, only: %i[index new create show edit update] do + member do + patch 'start' + patch 'finish' + patch 'cancel' + end + end resources :documents, only: %i[index new create] resources :meetings, only: %i[index new create show edit update] get 'members', on: :member, to: 'projects#members' @@ -33,14 +39,6 @@ patch 'decline', on: :member end - resources :tasks, only: %i[show edit update] do - member do - post 'start' - post 'finish' - post 'cancel' - end - end - resources :documents, only: %i[show] do patch 'archive', on: :member end diff --git a/db/migrate/20240205203250_remove_user_from_task.rb b/db/migrate/20240205203250_remove_user_from_task.rb new file mode 100644 index 0000000..46eb198 --- /dev/null +++ b/db/migrate/20240205203250_remove_user_from_task.rb @@ -0,0 +1,5 @@ +class RemoveUserFromTask < ActiveRecord::Migration[7.1] + def change + remove_reference :tasks, :author, foreign_key: { to_table: :users } + end +end \ No newline at end of file diff --git a/db/migrate/20240205203530_add_user_role_to_task.rb b/db/migrate/20240205203530_add_user_role_to_task.rb new file mode 100644 index 0000000..c0fa657 --- /dev/null +++ b/db/migrate/20240205203530_add_user_role_to_task.rb @@ -0,0 +1,5 @@ +class AddUserRoleToTask < ActiveRecord::Migration[7.1] + def change + add_reference :tasks, :user_role, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index fe269fc..3f7d7d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_02_193525) do +ActiveRecord::Schema[7.1].define(version: 2024_02_05_203530) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -116,12 +116,12 @@ t.date "due_date" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "author_id" t.integer "assigned_id" t.integer "status", default: 0 + t.integer "user_role_id", null: false t.index ["assigned_id"], name: "index_tasks_on_assigned_id" - t.index ["author_id"], name: "index_tasks_on_author_id" t.index ["project_id"], name: "index_tasks_on_project_id" + t.index ["user_role_id"], name: "index_tasks_on_user_role_id" end create_table "user_roles", force: :cascade do |t| @@ -160,8 +160,8 @@ add_foreign_key "project_job_categories", "projects" add_foreign_key "projects", "users" add_foreign_key "tasks", "projects" + add_foreign_key "tasks", "user_roles" add_foreign_key "tasks", "users", column: "assigned_id" - add_foreign_key "tasks", "users", column: "author_id" add_foreign_key "user_roles", "projects" add_foreign_key "user_roles", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index fb68a86..e8c7579 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -74,15 +74,15 @@ FactoryBot.create(:task, project: pokemon_project, title:'Pegar um geodude', description:'Para completar o meu time de pedra, preciso de um geodude, vamos captura-lo', - assigned: brock, due_date: 2.months.from_now.to_date, author: brock) + assigned: brock, due_date: 2.months.from_now.to_date, user_role: ginasio_project.user_roles.first) FactoryBot.create(:task, project: pokemon_project, title:'Parar a equipe rocket', description:'A equipe rocket está aprontando novamente, temos que para-los', - assigned: ash, due_date: Time.zone.tomorrow, author: ash) + assigned: ash, due_date: Time.zone.tomorrow, user_role: ginasio_project.user_roles.first) FactoryBot.create(:task, project: pokemon_project, title:'Derrotar um Charmander', description: 'Lutar contra outro treinador com um Charmander.', - assigned: ash, due_date: 1.week.from_now, author: ash) + assigned: ash, due_date: 1.week.from_now, user_role: ginasio_project.user_roles.first) diff --git a/spec/factories/tasks.rb b/spec/factories/tasks.rb index 037a107..4cfe52b 100644 --- a/spec/factories/tasks.rb +++ b/spec/factories/tasks.rb @@ -3,8 +3,8 @@ title { 'Bugfix' } description { 'Fix de um bug' } project - author { User.last } - assigned { User.last } + user_role { nil } + assigned { nil } due_date { 10.days.from_now.to_date } end end diff --git a/spec/factories/user_roles.rb b/spec/factories/user_roles.rb index b6b83ac..81a2591 100644 --- a/spec/factories/user_roles.rb +++ b/spec/factories/user_roles.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :user_role do - project - user { User.last } - role { 1 } + project { nil } + user + role { :contributor } end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7d480d0..0813868 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -75,6 +75,39 @@ end end + context '#admin?' do + it 'retorna true se Usuário for admin' do + project = create(:project) + admin = create(:user, cpf: '401.029.680-12') + create(:user_role, project:, user: admin, role: :admin) + expect(project.admin?(admin)).to eq true + end + + it 'retorna false se Usuário for colaborador' do + user = create :user + project = create(:project, user:) + project.user_roles.find_by(user:).update(role: :contributor) + + expect(project.admin?(user)).to eq false + end + + it 'retorna false se Usuário for líder' do + user = create :user + project = create(:project, user:) + + expect(project.admin?(user)).to eq false + end + + it 'retorna false se Usuário for admin de outro projeto' do + admin = create :user + project = create :project, user: admin + other_admin = create :user, cpf: '149.759.780-32' + create :project, user: other_admin, title: 'Outro Projeto' + + expect(project.admin?(other_admin)).to eq false + end + end + context '#member?' do it 'retorna true se Usuário tem vínculo com o projeto' do user = create :user, cpf: '149.759.780-32' diff --git a/spec/models/task_spec.rb b/spec/models/task_spec.rb index 8470883..a9e27ab 100644 --- a/spec/models/task_spec.rb +++ b/spec/models/task_spec.rb @@ -20,11 +20,11 @@ end it 'falso quando autor está vazio' do - task = FactoryBot.build(:task, author_id: '') + task = FactoryBot.build(:task, user_role_id: '') task.valid? - expect(task.errors[:author]).to include 'é obrigatório(a)' + expect(task.errors[:user_role]).to include 'é obrigatório(a)' end end diff --git a/spec/requests/meetings/user_create_meeting_spec.rb b/spec/requests/meetings/user_create_meeting_spec.rb index ac556b6..e4cd9cd 100644 --- a/spec/requests/meetings/user_create_meeting_spec.rb +++ b/spec/requests/meetings/user_create_meeting_spec.rb @@ -2,9 +2,10 @@ describe 'Usuário cria reunião' do it 'e não é colaborador do projeto' do - project_owner = create(:user, email: 'contributor@email.com', cpf: '000.000.001-91') - project = create(:project, user: project_owner) - other_project_owner = create(:user_role) + project = create(:project) + other_user = create(:user, email: 'contributor@email.com', cpf: '000.000.001-91') + other_project = create(:project, user: other_user) + other_project_owner = create(:user_role, user: other_user, project: other_project) login_as other_project_owner.user, scope: :user post(project_meetings_path(project), params: { meeting: { title: 'Reunião do Rock in rio', diff --git a/spec/requests/tasks/user_edits_task_request_spec.rb b/spec/requests/tasks/user_edits_task_request_spec.rb index 34511ee..e01b9a9 100644 --- a/spec/requests/tasks/user_edits_task_request_spec.rb +++ b/spec/requests/tasks/user_edits_task_request_spec.rb @@ -1,28 +1,59 @@ require 'rails_helper' -describe 'Usuário edita uma tarefa' do - it 'e não é o lider do projeto, o autor ou responsável' do - author = create(:user, email: 'joão@email.com', password: 'password') - project = create(:project, user: author) - task = create(:task, project:, title: 'Corrige Bug', author:, assigned: author) - user = create(:user, email: 'ana@email.com', password: 'password', cpf: '61151615099') - - login_as(user) - patch(task_path(task), params: { task: { title: 'Bugfix' } }) - - expect(task.reload.title).not_to eq 'Bugfix' - expect(response).to redirect_to(root_path) +describe 'Usuário edita Tarefa' do + it 'e é contribuinte autor da tarefa' do + leader = create(:user) + project = create(:project, user: leader) + contributor = create(:user, email: 'contributor@email.com', cpf: '000.000.001-91') + contributor_role = project.user_roles.create!(user: contributor) + task = create(:task, project:, user_role: contributor_role, title: 'Tarefa de capturar 150 Pokémons') + + login_as contributor, scope: :user + patch(project_task_path(project, task), params: { task: { title: 'Tarefa sair de casa com 10 anos' } }) + + expect(response).to redirect_to project_task_path(project, task) + expect(task.reload.title).to eq 'Tarefa sair de casa com 10 anos' + end + + it 'e é contribuinte do projeto não autor da tarefa' do + leader = create(:user) + project = create(:project, user: leader) + contributor = create(:user, email: 'contributor@email.com', cpf: '000.000.001-91') + project.user_roles.create!(user: contributor, role: :contributor) + task = create(:task, project:, user_role: leader.user_roles.first, title: 'tarefa blabla') + + login_as contributor, scope: :user + patch(project_task_path(project, task), params: { task: { title: 'tarefa do Rock in rio' } }) + + expect(task.reload.title).to eq 'tarefa blabla' + expect(response).to redirect_to project_task_path(project, task) + end + + it 'e é um líder não autor da tarefa' do + leader = create(:user) + project = create(:project, user: leader) + contributor = create(:user, email: 'contributor@email.com', cpf: '000.000.001-91') + contributor_role = project.user_roles.create!(user: contributor) + task = create(:task, project:, user_role: contributor_role, title: 'tarefa blabla') + + login_as leader, scope: :user + patch(project_task_path(project, task), params: { task: { title: 'tarefa do Rock in rio' } }) + + expect(task.reload.title).to eq 'tarefa do Rock in rio' + expect(response).to redirect_to project_task_path(project, task) end - it 'e é o lider do projeto, autor ou responsável' do - author = create(:user, email: 'joão@email.com', password: 'password') - project = create(:project, user: author) - task = create(:task, project:, title: 'Corrige Bug', author:, assigned: author) + it 'e é um administrador não autor da tarefa' do + leader = create(:user) + project = create(:project, user: leader) + admin = create(:user, email: 'admin@email.com', cpf: '000.000.001-91') + project.user_roles.create!(user: admin, role: :admin) + task = create(:task, project:, user_role: leader.user_roles.first, title: 'tarefa blabla') - login_as(author) - patch(task_path(task), params: { task: { title: 'Bugfix' } }) + login_as admin, scope: :user + patch(project_task_path(project, task), params: { task: { title: 'tarefa do Rock in rio' } }) - expect(task.reload.title).to eq 'Bugfix' - expect(response).to redirect_to(task_path(task)) + expect(task.reload.title).to eq 'tarefa do Rock in rio' + expect(response).to redirect_to project_task_path(project, task) end end diff --git a/spec/system/calendars/user_view_calendar_spec.rb b/spec/system/calendars/user_view_calendar_spec.rb index 89f984f..87e195c 100644 --- a/spec/system/calendars/user_view_calendar_spec.rb +++ b/spec/system/calendars/user_view_calendar_spec.rb @@ -4,12 +4,13 @@ it 'somente com reuniões' do user = create(:user) project = create(:project, user:, title: 'Meu Projeto') + user_role = project.user_roles.first travel_to Time.zone.now.beginning_of_month do first_daily = create(:meeting, project:, title: 'Daily 1', datetime: 9.days.from_now) second_daily = create(:meeting, project:, title: 'Daily 2', datetime: 10.days.from_now) third_daily = create(:meeting, project:, title: 'Daily 3', datetime: 11.days.from_now) - task = create(:task, title: 'Tarefa 1', project:, due_date: 5.days.from_now) + task = create(:task, title: 'Tarefa 1', project:, due_date: 5.days.from_now, user_role:) login_as user visit root_path @@ -39,12 +40,13 @@ it 'somente com tarefas' do user = create(:user) project = create(:project, user:, title: 'Meu Projeto') + user_role = project.user_roles.first travel_to Time.zone.now.beginning_of_month do - first_task = create(:task, title: 'Tarefa 1', project:, due_date: 5.days.from_now) - second_task = create(:task, title: 'Tarefa 2', project:, due_date: 6.days.from_now) - third_task = create(:task, title: 'Tarefa 3', project:, due_date: 7.days.from_now) - daily = create(:meeting, project:, title: 'Daily 1', datetime: 9.days.from_now) + first_task = create(:task, title: 'Tarefa 1', project:, due_date: 5.days.from_now, user_role:) + second_task = create(:task, title: 'Tarefa 2', project:, due_date: 6.days.from_now, user_role:) + third_task = create(:task, title: 'Tarefa 3', project:, due_date: 7.days.from_now, user_role:) + daily = create(:meeting, project:, title: 'Daily 1', datetime: 9.days.from_now, user_role:) login_as user visit project_calendars_path project @@ -52,13 +54,13 @@ click_on 'Filtrar' within "#day-#{first_task.start_time.to_date}" do - expect(page).to have_link 'Tarefa 1', href: task_path(first_task) + expect(page).to have_link 'Tarefa 1', href: project_task_path(project, first_task) end within "#day-#{second_task.start_time.to_date}" do - expect(page).to have_link 'Tarefa 2', href: task_path(second_task) + expect(page).to have_link 'Tarefa 2', href: project_task_path(project, second_task) end within "#day-#{third_task.start_time.to_date}" do - expect(page).to have_link 'Tarefa 3', href: task_path(third_task) + expect(page).to have_link 'Tarefa 3', href: project_task_path(project, third_task) end within "#day-#{daily.start_time.to_date}" do expect(page).not_to have_link 'Daily 1' @@ -69,24 +71,25 @@ it 'com reuniões e tarefas' do user = create(:user) project = create(:project, user:, title: 'Meu Projeto') + user_role = project.user_roles.first travel_to Time.zone.now.beginning_of_month do first_daily = create(:meeting, project:, title: 'Daily 1', datetime: 9.days.from_now) - first_task = create(:task, title: 'Tarefa 1', project:, due_date: 9.days.from_now) + first_task = create(:task, title: 'Tarefa 1', project:, due_date: 9.days.from_now, user_role:) second_daily = create(:meeting, project:, title: 'Daily 2', datetime: 10.days.from_now) - second_task = create(:task, title: 'Tarefa 2', project:, due_date: 10.days.from_now) + second_task = create(:task, title: 'Tarefa 2', project:, due_date: 10.days.from_now, user_role:) login_as user visit project_calendars_path project within "#day-#{first_daily.start_time.to_date}" do expect(page).to have_link 'Daily 1', href: project_meeting_path(project, first_daily) - expect(page).to have_link 'Tarefa 1', href: task_path(first_task) + expect(page).to have_link 'Tarefa 1', href: project_task_path(project, first_task) end within "#day-#{second_daily.start_time.to_date}" do expect(page).to have_link 'Daily 2', href: project_meeting_path(project, second_daily) - expect(page).to have_link 'Tarefa 2', href: task_path(second_task) + expect(page).to have_link 'Tarefa 2', href: project_task_path(project, second_task) end end end @@ -95,13 +98,14 @@ user = create(:user) project = create(:project, user:, title: 'Meu Projeto') other_project = create(:project, user:, title: 'Outro Projeto') + user_role = project.user_roles.first travel_to Time.zone.now.beginning_of_month do first_daily = create(:meeting, project:, title: 'Daily 1', datetime: 9.days.from_now) - create(:task, title: 'Tarefa 1', project:, due_date: 9.days.from_now) + create(:task, title: 'Tarefa 1', project:, due_date: 9.days.from_now, user_role:) second_daily = create(:meeting, project: other_project, title: 'Daily 2', datetime: 10.days.from_now) - create(:task, title: 'Tarefa 2', project: other_project, due_date: 10.days.from_now) + create(:task, title: 'Tarefa 2', project: other_project, due_date: 10.days.from_now, user_role:) login_as user visit project_calendars_path project @@ -120,11 +124,12 @@ it 'somente com tarefas e volta para todos' do user = create(:user) project = create(:project, user:, title: 'Meu Projeto') + user_role = project.user_roles.first travel_to Time.zone.now.beginning_of_month do - first_task = create(:task, title: 'Tarefa 1', project:, due_date: 5.days.from_now) + first_task = create(:task, title: 'Tarefa 1', project:, due_date: 5.days.from_now, user_role:) create(:meeting, project:, title: 'Daily 1', datetime: 5.days.from_now) - second_task = create(:task, title: 'Tarefa 2', project:, due_date: 6.days.from_now) + second_task = create(:task, title: 'Tarefa 2', project:, due_date: 6.days.from_now, user_role:) create(:meeting, project:, title: 'Daily 2', datetime: 6.days.from_now) login_as user diff --git a/spec/system/projects/user_view_project_details_spec.rb b/spec/system/projects/user_view_project_details_spec.rb index 1ff8ab5..c788ff0 100644 --- a/spec/system/projects/user_view_project_details_spec.rb +++ b/spec/system/projects/user_view_project_details_spec.rb @@ -95,14 +95,4 @@ expect(page).not_to have_content 'Categoria: Teste' expect(page).not_to have_content "Categoria de Trabalho\nDesenvolvedor" end - - it 'que não existe' do - deco = create :user, email: 'deco@email.com' - - login_as deco - visit project_path('999') - - expect(current_path).to eq root_path - expect(page).to have_content 'Projeto não encontrado.' - end end diff --git a/spec/system/tasks/user_edit_task_spec.rb b/spec/system/tasks/user_edit_task_spec.rb index 59f2e61..a989709 100644 --- a/spec/system/tasks/user_edit_task_spec.rb +++ b/spec/system/tasks/user_edit_task_spec.rb @@ -4,10 +4,11 @@ it 'a partir da página de tarefa com sucesso' do author = create(:user, email: 'joão@email.com', password: 'password') project = create(:project, user: author) - task = create(:task, project:) + author_role = create(:user_role, user: author, project:) + task = create(:task, project:, user_role: author_role) login_as(author) - visit task_path(task) + visit project_task_path(project, task) click_on 'Editar Tarefa' fill_in 'Título', with: 'Conserta a tarefa' fill_in 'Descrição', with: 'Essa edição conserta a tarefa' @@ -21,10 +22,11 @@ it 'e falha porque um campo obrigatório ficou em branco' do author = create(:user, email: 'joão@email.com', password: 'password') project = create(:project, user: author) - task = create(:task, project:) + author_role = create(:user_role, user: author, project:) + task = create(:task, project:, user_role: author_role) login_as(author) - visit task_path(task) + visit project_task_path(project, task) click_on 'Editar Tarefa' fill_in 'Título', with: '' click_on 'Salvar' diff --git a/spec/system/tasks/user_register_task_spec.rb b/spec/system/tasks/user_register_task_spec.rb index d23f1dd..07ad782 100644 --- a/spec/system/tasks/user_register_task_spec.rb +++ b/spec/system/tasks/user_register_task_spec.rb @@ -3,8 +3,9 @@ describe 'Usuário cria tarefa' do it 'á partir da pagina princial do projeto' do author = create(:user, email: 'joão@email.com', password: 'password') - create(:user, email: 'valeria@email.com', password: 'password', cpf: '000.000.001-91') + valeria = create(:user, email: 'valeria@email.com', password: 'password', cpf: '000.000.001-91') project = create(:project, user: author) + create(:user_role, project:, user: valeria, role: :contributor) login_as(author) visit project_path(project) diff --git a/spec/system/tasks/user_updates_task_status_spec.rb b/spec/system/tasks/user_updates_task_status_spec.rb index 4867187..0bad809 100644 --- a/spec/system/tasks/user_updates_task_status_spec.rb +++ b/spec/system/tasks/user_updates_task_status_spec.rb @@ -4,67 +4,71 @@ it 'de não iniciada para em andamento' do author = create(:user, email: 'joão@email.com', password: 'password') project = create(:project, user: author) - task = create(:task, project:) + author_role = create(:user_role, user: author, project:) + task = create(:task, project:, user_role: author_role) login_as(author) - visit task_path(task) + visit project_task_path(project, task) click_on 'Iniciar Tarefa' expect(page).to have_content "Status\nEm andamento" expect(page).to have_content 'Tarefa iniciada' expect(page).not_to have_button 'Iniciar Tarefa' - expect(page).to have_current_path(task_path(task)) + expect(page).to have_current_path(project_task_path(project, task)) expect(task.reload.status).to eq 'in_progress' end it 'de em andamento para finalizada' do author = create(:user, email: 'joão@email.com', password: 'password') project = create(:project, user: author) - task = create(:task, project:, status: 'in_progress') + author_role = create(:user_role, user: author, project:) + task = create(:task, project:, status: 'in_progress', user_role: author_role) login_as(author) - visit task_path(task) + visit project_task_path(project, task) click_on 'Finalizar Tarefa' expect(page).to have_content "Status\nFinalizada" expect(page).to have_content 'Tarefa finalizada' expect(page).not_to have_button 'Iniciar Tarefa' expect(page).not_to have_button 'Finalizar Tarefa' - expect(page).to have_current_path(task_path(task)) + expect(page).to have_current_path(project_task_path(project, task)) expect(task.reload.status).to eq 'finished' end it 'de não iniciada para cancelada' do author = create(:user, email: 'joão@email.com', password: 'password') project = create(:project, user: author) - task = create(:task, project:, status: 'uninitialized') + author_role = create(:user_role, user: author, project:) + task = create(:task, project:, status: 'uninitialized', user_role: author_role) login_as(author) - visit task_path(task) + visit project_task_path(project, task) accept_confirm('Cancelar tarefa?') { click_on 'Cancelar Tarefa' } expect(page).to have_content "Status\nCancelada" expect(page).to have_content 'Tarefa cancelada' expect(page).not_to have_button 'Iniciar Tarefa' expect(page).not_to have_button 'Finalizar Tarefa' - expect(page).to have_current_path(task_path(task)) + expect(page).to have_current_path(project_task_path(project, task)) expect(task.reload.status).to eq 'cancelled' end it 'de em andamento para cancelada' do author = create(:user, email: 'joão@email.com', password: 'password') project = create(:project, user: author) - task = create(:task, project:, status: 'in_progress') + author_role = create(:user_role, user: author, project:) + task = create(:task, project:, status: 'in_progress', user_role: author_role) login_as(author) - visit task_path(task) + visit project_task_path(project, task) accept_confirm('Cancelar tarefa?') { click_on 'Cancelar Tarefa' } expect(page).to have_content "Status\nCancelada" expect(page).to have_content 'Tarefa cancelada' expect(page).not_to have_button 'Iniciar Tarefa' expect(page).not_to have_button 'Finalizar Tarefa' - expect(page).to have_current_path(task_path(task)) + expect(page).to have_current_path(project_task_path(project, task)) expect(task.reload.status).to eq 'cancelled' end end diff --git a/spec/system/tasks/user_view_task_index_spec.rb b/spec/system/tasks/user_view_task_index_spec.rb index fe826dc..f5e7501 100644 --- a/spec/system/tasks/user_view_task_index_spec.rb +++ b/spec/system/tasks/user_view_task_index_spec.rb @@ -3,10 +3,12 @@ describe 'Usuário vê tarefas' do it 'em um index' do project = create(:project) - create(:task, title: 'Tarefa 1', project:) - create(:task, title: 'Tarefa 2', project:) - create(:task, title: 'Tarefa 3', project:) - create(:task, title: 'Tarefa 4', project:) + author = project.user + author_role = create(:user_role, user: author, project:) + create(:task, title: 'Tarefa 1', project:, user_role: author_role) + create(:task, title: 'Tarefa 2', project:, user_role: author_role) + create(:task, title: 'Tarefa 3', project:, user_role: author_role) + create(:task, title: 'Tarefa 4', project:, user_role: author_role) login_as(project.user) visit project_path(project) @@ -22,9 +24,11 @@ it 'à partir do index' do project = create(:project) - create(:task, title: 'Tarefa 1', project:) + author = project.user + author_role = create(:user_role, user: author, project:) + create(:task, title: 'Tarefa 1', project:, user_role: author_role) task = create(:task, title: 'Tarefa 2', project:, description: 'Fazer item 8 do backlog', - due_date: nil, assigned: nil) + due_date: nil, assigned: nil, user_role: author_role) login_as(project.user) visit project_path(project) @@ -35,15 +39,17 @@ expect(page).to have_content "Descrição\nFazer item 8 do backlog" expect(page).to have_content "Prazo\nSem prazo" expect(page).to have_content "Responsável\nSem responsável" - expect(current_path).to eq task_path(task) + expect(current_path).to eq project_task_path(project, task) end it 'e volta para a página do projeto' do project = create(:project, title: 'Projeto Secreto', description: 'Esse projeto é secreto') - create(:task, title: 'Tarefa 1', project:) - create(:task, title: 'Tarefa 2', project:) - create(:task, title: 'Tarefa 3', project:) - create(:task, title: 'Tarefa 4', project:) + author = project.user + author_role = create(:user_role, user: author, project:) + create(:task, title: 'Tarefa 1', project:, user_role: author_role) + create(:task, title: 'Tarefa 2', project:, user_role: author_role) + create(:task, title: 'Tarefa 3', project:, user_role: author_role) + create(:task, title: 'Tarefa 4', project:, user_role: author_role) login_as(project.user) visit project_path(project)