Skip to content

Commit

Permalink
Merge pull request #69 from TreinaDev/listagem-de-torres
Browse files Browse the repository at this point in the history
Listagem de torres
  • Loading branch information
cellaaleo authored Jul 8, 2024
2 parents 9ac2bbd + a957bf8 commit 6ee425b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/controllers/towers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TowersController < ApplicationController
before_action :authenticate_manager!, only: %i[show new edit_floor_units create update_floor_units]
before_action :authenticate_manager!, only: %i[index show new edit_floor_units create update_floor_units]
before_action :set_tower, only: %i[show edit_floor_units update_floor_units]
before_action :set_condo, only: %i[new create]

Expand All @@ -8,6 +8,11 @@ class TowersController < ApplicationController
before_action :set_breadcrumbs_for_details, only: %i[show edit_floor_units update_floor_units]
before_action :set_breadcrumbs_for_register, only: %i[new create]

def index
@condo = Condo.find(params[:condo_id])
@towers = @condo.towers
end

def show; end

def new
Expand Down Expand Up @@ -80,6 +85,12 @@ def condo_id_param
params.require :condo_id
end

def authenticate_manager!
return redirect_to root_path if resident_signed_in?

super
end

def set_breadcrumbs_for_details
add_breadcrumb @tower.condo.name.to_s, @tower.condo
add_breadcrumb I18n.t('breadcrumb.tower.index'), condo_towers_path(@tower.condo)
Expand Down
5 changes: 3 additions & 2 deletions app/views/condos/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<% if manager_signed_in? %>
<%= link_to 'Editar', edit_condo_path, class:"btn btn-dark" %>
<% end %>


<% if manager_signed_in? %>
<%= link_to 'Listar Torres', condo_towers_path(@condo), class:"btn btn-dark" %>
<% end %>
8 changes: 7 additions & 1 deletion app/views/towers/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<h1>Torres</h1>
<h1 class="mb-5"> Torres do Condomínio: <%= @condo.name %></h1>

<div class="list-group list d-flex justify-content-center align-items-center">
<% @towers.each do |tower| %>
<%= link_to tower.name, tower_path(tower), class:"list-group-item list-group-item-action w-25 p-3 text-center"%>
<% end %>
</div>
72 changes: 72 additions & 0 deletions spec/system/towers/administrator_view_condo_towers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'rails_helper'

describe 'Administrator view list of towers' do
it 'and must be authenticated' do
condo = create(:condo)

visit condo_towers_path(condo)

expect(current_path).to eq new_manager_session_path
end

it 'and only sees the list of towers that belong to the condo' do
condo = create(:condo)
condo2 = create(:condo)
user = create :manager
tower_a = build :tower, name: 'Torre A', condo_id: condo.id
tower_a.generate_floors
tower_b = build :tower, name: 'Torre B', condo_id: condo.id
tower_b.generate_floors
tower_c = build :tower, name: 'Torre C', condo_id: condo.id
tower_c.generate_floors
tower_z = build :tower, name: 'Torre Z', condo_id: condo2.id
tower_z.generate_floors

login_as user, scope: :manager
visit condo_path(condo)
click_on 'Listar Torres'

expect(current_path).to eq condo_towers_path(condo)
within '.list' do
expect(page).to have_link 'Torre A'
expect(page).to have_link 'Torre B'
expect(page).to have_link 'Torre C'
expect(page).not_to have_link 'Torre Z'
end
end

it 'and see a tower details when click on tower´s name' do
condo = create(:condo)
user = create :manager
tower_a = build :tower, name: 'Torre A', condo_id: condo.id
tower_a.generate_floors

login_as user, scope: :manager
visit condo_path(condo)
click_on 'Listar Torres'
click_on 'Torre A'

expect(current_path).to eq tower_path(tower_a)
end

it 'resident can´t see link to list of towers' do
condo = create(:condo)
resident = create :resident

login_as resident, scope: :resident
visit condo_path(condo)

expect(current_path).to eq condo_path(condo)
expect(page).not_to have_link 'Listar Torres'
end

it 'resident can´t access the list of condo´s tower' do
condo = create(:condo)
resident = create :resident

login_as resident, scope: :resident
visit condo_towers_path(condo)

expect(current_path).to eq root_path
end
end

0 comments on commit 6ee425b

Please sign in to comment.