Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Allow patrons to view a more informative equipment table
Browse files Browse the repository at this point in the history
Resolves #1199
  • Loading branch information
alex-kogan committed Nov 3, 2015
1 parent 39f84a5 commit 75f0f46
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize(user) # rubocop:disable all
can :read, EquipmentModel
can :override, :reservation_errors if AppConfig.get(:override_on_create)
can :override, :checkout_errors if AppConfig.get(:override_at_checkout)
can :view_detailed, EquipmentModel
when 'normal' || 'checkout'
can [:update, :show], User, id: user.id
can :read, EquipmentModel
Expand All @@ -41,6 +42,7 @@ def initialize(user) # rubocop:disable all
can :update_cart, :all
can :update_index_dates, Reservation
can :view_all_dates, Reservation
can :view_detailed, EquipmentModel
when 'guest'
# rubocop:disable BlockNesting
if AppConfig.check(:enable_guests)
Expand Down
26 changes: 13 additions & 13 deletions app/views/equipment_models/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
<thead>
<tr>
<th class="text-center col-md-2">Name</th>
<% if can? :manage, Reservation %>
<th class="no_sort text-center">Current Status</th>
<th class="text-center">Available</th>
<th class="text-center">Reserved</th>
<th class="text-center">Checked-Out</th>
<th class="text-center">Overdue</th>
<th class="text-center">Total Stock</th>
<% if can? :manage, EquipmentModel %>
<th class="no_sort text-center"> </th>
<th class="no_sort text-center"> </th>
<% end%>
<% end %>
<% if can? :view_detailed, EquipmentModel %>
<th class="no_sort text-center">Current Status</th>
<th class="text-center">Available</th>
<th class="text-center">Reserved</th>
<th class="text-center">Checked-Out</th>
<th class="text-center">Overdue</th>
<th class="text-center">Total Stock</th>
<% if can? :manage, EquipmentModel %>
<th class="no_sort text-center"> </th>
<th class="no_sort text-center"> </th>
<% end%>
<% end %>
</tr>
</thead>
<tbody>
<% for equipment_model in @equipment_models %>
<tr>
<td class="text-center"><%= link_to equipment_model.name, equipment_model %></td>
<% if can? :manage, Reservation %>
<% if can? :view_detailed, EquipmentModel %>
<% if equipment_model.availability(Time.zone.today) == 'all' %>
<td class="text-center"><span class="label label-success">All Available</span></td>
<% elsif equipment_model.availability(Time.zone.today) == 'some' %>
Expand Down
72 changes: 69 additions & 3 deletions spec/features/equipment_model_views_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,74 @@
subject { page }

context 'index view' do
before { visit equipment_models_path }
it { is_expected.to have_content('Equipment Models') }
it { is_expected.to have_content(@eq_model.name) }
shared_examples 'can view detailed table' do
it { should have_selector 'th', text: 'Available' }
end

shared_examples 'can view full and detailed table' do
it_behaves_like 'can view detailed table'
it { expect(page).to have_link 'Edit' }
end

shared_examples 'displays appropriate information' do
it { is_expected.to have_content('Equipment Models') }
it { is_expected.to have_content(@eq_model.name) }
end

context 'check for super user' do
before do
sign_in_as_user(@superuser)
visit equipment_models_path
end
after { sign_out }
it_behaves_like 'can view full and detailed table'
it_behaves_like 'displays appropriate information'
end

context 'check for admin' do
before do
sign_in_as_user(@admin)
visit equipment_models_path
end
after { sign_out }
it_behaves_like 'can view full and detailed table'
it_behaves_like 'displays appropriate information'
end

context 'check for patron' do
before do
sign_in_as_user(@user)
visit equipment_models_path
end
after { sign_out }
it_behaves_like 'can view detailed table'
it_behaves_like 'displays appropriate information'
end

context 'check for check out person' do
before do
sign_in_as_user(@checkout_person)
visit equipment_models_path
end
after { sign_out }
it_behaves_like 'can view detailed table'
it_behaves_like 'displays appropriate information'
end

context 'check for guest' do
before { visit equipment_models_path }
it { should_not have_selector 'th', text: 'Available' }
it_behaves_like 'displays appropriate information'
end

context 'check for banned user' do
before do
sign_in_as_user(@banned)
visit equipment_models_path
end
after { sign_out }
it { should_not have_selector 'th', text: 'Available' }
it { is_expected.not_to have_content('Equipment Models') }
end
end
end
1 change: 1 addition & 0 deletions spec/support/feature_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def app_setup
@superuser = FactoryGirl.create(:superuser)
@checkout_person = FactoryGirl.create(:checkout_person)
@user = FactoryGirl.create(:user)
@banned = FactoryGirl.create(:banned)
end

def empty_cart
Expand Down

0 comments on commit 75f0f46

Please sign in to comment.