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

[1339] hide announcement #1350

Merged
merged 1 commit into from
Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def initialize(user) # rubocop:disable all
can :override, :reservation_errors if AppConfig.get(:override_on_create)
can :override, :checkout_errors if AppConfig.get(:override_at_checkout)
can :view_detailed, EquipmentModel
can :hide, Announcement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unnecessary given line 47 below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the redundancy but for some reason without that line checkout-person can't hide the announcement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's odd. I'll mess around and see if I can figure out why.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, this is a separate issue and we'll deal with it in #1391

when 'normal' || 'checkout'
can [:update, :show], User, id: user.id
can :read, EquipmentModel
Expand All @@ -43,16 +44,19 @@ def initialize(user) # rubocop:disable all
can :update_index_dates, Reservation
can :view_all_dates, Reservation
can :view_detailed, EquipmentModel
can :hide, Announcement
when 'guest'
# rubocop:disable BlockNesting
if AppConfig.check(:enable_guests)
can :read, EquipmentModel
can :empty_cart, :all
can :update_cart, :all
can :create, User if AppConfig.check(:enable_new_users)
can :hide, Announcement
end
# rubocop:enable BlockNesting
when 'banned'
can :hide, Announcement
# cannot :create, Reservation
end
case user.role
Expand Down
51 changes: 51 additions & 0 deletions spec/controllers/announcements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,55 @@
it_behaves_like 'access denied'
end
end
context 'GET hide as' do
shared_examples 'can hide announcement' do
before do
@announcement = FactoryGirl.create(:announcement)
request.env['HTTP_REFERER'] = 'where_i_came_from'
get :hide, id: @announcement
end
it 'should set some cookie values' do
name = 'hidden_announcement_ids'
jar = request.cookie_jar
jar.signed[name] = [@announcement[:id].to_s]
expect(response.cookies[name]).to eq(jar[name])
end
end
context 'superuser' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add "as" to the front of the string so it reads correctly, e.g. GET hide as superuser can hide announcement...

before do
sign_in FactoryGirl.create(:superuser)
end
it_behaves_like 'can hide announcement'
end
context 'admin' do
before do
sign_in FactoryGirl.create(:admin)
end
it_behaves_like 'can hide announcement'
end
context 'patron' do
before do
sign_in FactoryGirl.create(:user)
end
it_behaves_like 'can hide announcement'
end
context 'checkout person' do
before do
sign_in FactoryGirl.create(:checkout_person)
end
it_behaves_like 'can hide announcement'
end
context 'guest' do
before do
sign_in FactoryGirl.create(:guest)
end
it_behaves_like 'can hide announcement'
end
context 'banned user' do
before do
sign_in FactoryGirl.create(:banned)
end
it_behaves_like 'can hide announcement'
end
end
end