Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Changing allocation decorator and adding AllocationController tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samkevin1 committed Mar 28, 2023
1 parent fdd0eba commit 294be66
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 38 deletions.
31 changes: 1 addition & 30 deletions app/decorators/allocation_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class AllocationDecorator < Draper::Decorator
delegate_all
decorates_association :user

def hourly_rate
h.humanized_money_with_symbol(super)
Expand All @@ -10,34 +11,4 @@ def hourly_rate
def to_s
"##{model.id}"
end

def user_name
model.user.first_and_last_name
end

def user_level
model.user.decorate.level
end

def user_specialty
model.user.decorate.specialty
end

def user_english_level
model.user.decorate.english_level
end

def user_skills
model.user.decorate.skills
end

def end_at
build_date(model.end_at)
end

private

def build_date(date)
date ? I18n.l(date) : I18n.t('not_allocated')
end
end
12 changes: 6 additions & 6 deletions app/views/new_admin/allocation_chart/_allocations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400 font-semibold">
<%= allocation.user_name %>
<%= allocation.user.first_and_last_name %>
</p>
</div>
</td>
Expand All @@ -30,35 +30,35 @@
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400">
<%= allocation.end_at %>
<%= allocation.end_at ? l(allocation.end_at) : t('not_allocated') %>
</p>
</div>
</td>
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400">
<%= allocation.user_level %>
<%= allocation.user.level %>
</p>
</div>
</td>
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400">
<%= allocation.user_specialty %>
<%= allocation.user.specialty %>
</p>
</div>
</td>
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400">
<%= allocation.user_english_level %>
<%= allocation.user.english_score %>
</p>
</div>
</td>
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400">
<%= allocation.user_skills %>
<%= allocation.user.skills %>
</p>
</div>
</td>
Expand Down
49 changes: 49 additions & 0 deletions spec/controllers/new_admin/allocation_chart_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require 'rails_helper'

describe NewAdmin::AllocationChartController do
let(:user) { create(:user) }

before do
allow(controller).to receive(:authenticate_user!)
allow(controller).to receive(:current_user).and_return(user)
end

describe 'GET #index' do
context 'when there are no allocations' do
it 'returns successful status' do
get :index

expect(response).to have_http_status(:ok)
end

it 'returns users within an empty allocation' do
get :index

expect(subject.instance_variable_get(:@allocations)).to include(having_attributes(user_id: user.id))
end
end

context 'when there are active allocations' do
let!(:allocation) { create(:allocation,
start_at: 2.months.after,
end_at: 3.months.after,
user: user,
ongoing: true) }


it 'returns successful status' do
get :index

expect(response).to have_http_status(:ok)
end

it 'returns allocations' do
get :index

expect(subject.instance_variable_get(:@allocations)).to include(allocation)
end
end
end
end
6 changes: 4 additions & 2 deletions spec/features/admin/allocation_chart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let!(:user) { create(:user, allocations: [allocation]) }

let(:allocation) do
build(:allocation, project: project, start_at: Date.new(2022, 5, 1), end_at: Date.new(2022, 11, 1), ongoing: true)
build(:allocation, project: project, start_at: Date.new(2022, 5, 1), end_at: Date.new(2023, 03, 1), ongoing: true)
end

before { visit '/admin/allocation_chart' }
Expand Down Expand Up @@ -47,8 +47,10 @@
end

it '"Alocado até" column links to allocation' do
allow(Date).to receive(:today).and_return(Date.new(2023, 4, 1))

within 'tbody' do
expect(page).to have_link('01/11/2022', href: "/admin/allocations/#{allocation.id}")
expect(page).to have_link('01/03/2023', href: "/admin/allocations/#{allocation.id}")
end
end
end
Expand Down

0 comments on commit 294be66

Please sign in to comment.