-
Notifications
You must be signed in to change notification settings - Fork 140
Rearrange, not change the abilities in Ability #997
Changes from 17 commits
d00277c
27ead4d
e1b56f1
6b4664e
bfaeb99
f6da595
b172a3f
ec3c037
f84460e
dad17d8
ff1e8ba
975877f
1e5db7d
cabcae9
6e7d601
9a0f39b
e765a2b
9d685da
419bdf7
cb126b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
# frozen_string_literal: true | ||
class MailingsController < ApplicationController | ||
|
||
load_and_authorize_resource except: :index | ||
load_and_authorize_resource | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
def index | ||
@mailings = Mailing.order('id DESC').page(params[:page]) | ||
authorize! :read, :mailing | ||
end | ||
|
||
# These actions are here to enable the cancancan 'not authorised' notice | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,11 @@ | |
|
||
let(:valid_attributes) { build(:team).attributes.merge(roles_attributes: [{ name: 'coach', github_handle: 'tobias' }]) } | ||
|
||
before do | ||
user.roles.create(name: 'student', team: team) | ||
end | ||
|
||
describe "GET index" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that the new ability rule prevents students from creating a second team, the specs can't assign two teams either. Moved the one global |
||
before do | ||
user.roles.create(name: 'student', team: team) | ||
end | ||
|
||
context 'before acceptance letters are sent' do | ||
let(:last_season) { Season.create name: Date.today.year - 1 } | ||
let!(:invisble_team) { create :team, :in_current_season, kind: nil, invisible: true } | ||
|
@@ -103,6 +103,10 @@ | |
end | ||
|
||
describe "GET edit" do | ||
before do | ||
user.roles.create(name: 'student', team: team) | ||
end | ||
|
||
context "their own team" do | ||
let(:team) { create(:team) } | ||
|
||
|
@@ -165,7 +169,10 @@ | |
end | ||
|
||
describe "PATCH update" do | ||
before { sign_in user } | ||
before do | ||
sign_in user | ||
user.roles.create(name: 'student', team: team) | ||
end | ||
|
||
context "their own team" do | ||
let(:team) { create(:team) } | ||
|
@@ -267,7 +274,10 @@ | |
end | ||
|
||
describe "DELETE destroy" do | ||
before { sign_in user } | ||
before do | ||
sign_in user | ||
user.roles.create(name: 'student', team: team) | ||
end | ||
|
||
context "their own team" do | ||
let(:params) { { id: team.to_param } } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,8 @@ | |
factory :season do | ||
sequence(:name, '2000') | ||
end | ||
|
||
trait :past do | ||
name '2010' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FactoryBot.define do | ||
factory :user, aliases: [:member] do | ||
github_handle { FFaker::InternetSE.user_name_variant_short } | ||
github_handle { FFaker::InternetSE.unique.user_name_variant_short } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes flickering specs because of failing uniqueness validation on gh handle. |
||
name { FFaker::Name.name } | ||
email { FFaker::Internet.email } | ||
location { FFaker::Address.city } | ||
|
@@ -84,5 +84,9 @@ | |
create(:reviewer_role, user: user) | ||
end | ||
end | ||
|
||
trait :unconfirmed do | ||
confirmed_at nil | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Guest User', type: :feature do | ||
|
||
let!(:activity) { create(:status_update, :published, team: team1) } | ||
let!(:other_user) { create(:user) } | ||
let!(:project) { create(:project, :in_current_season, :accepted, submitter: other_user) } | ||
let!(:team1) { create(:team, name: 'Cheesy forever', project_id: project.id) } | ||
let!(:out_of_season) { Season.current.starts_at - 1.week } | ||
let!(:summer_season) { Season.current.starts_at + 1.week } | ||
|
||
context "when visiting public pages" do | ||
|
||
context 'All Year' do | ||
before { Timecop.travel(out_of_season) } | ||
after { Timecop.return } | ||
|
||
it 'can view Activities' do | ||
visit root_path | ||
expect(page).to have_css('h1', text: 'Activities') | ||
find('.title', match: :smart).click | ||
expect(page).to have_content(activity.title) | ||
expect(page).to have_content('You must be logged in to add a comment.') | ||
end | ||
|
||
it 'can view Community and User' do | ||
visit community_path | ||
expect(page).to have_css('h1', text: 'Community') | ||
find_link(other_user.name, match: :smart).click | ||
expect(page).to have_content("About me") | ||
expect(page).to have_link("All participants") | ||
expect(page).not_to have_link("Edit") # check | ||
end | ||
|
||
it 'can view projects' do | ||
visit projects_path | ||
expect(page).to have_css('h1', text: 'Projects') # can be empty table | ||
end | ||
|
||
it 'has a nav menu with public links' do | ||
visit root_path | ||
expect(page).to have_link("Activities") | ||
find_link("Summer of Code").click | ||
expect(page).to have_link("Teams") | ||
expect(page).to have_link("Community") | ||
expect(page).to have_link("Help") | ||
end | ||
|
||
it 'has access to sign in link' do | ||
visit root_path | ||
expect(page).to have_link('Sign in') | ||
end | ||
end | ||
|
||
context 'in season' do | ||
before do | ||
Timecop.travel(summer_season) | ||
end | ||
after { Timecop.return } | ||
|
||
it "can view the current season's accepted and selected projects" do | ||
# project not visible on page. why? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to #1002? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Could be... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AHA! I had to use a |
||
visit projects_path | ||
expect(page).to have_css('h1', text: 'Projects') | ||
# find_link(project.name, match: :smart).click | ||
# expect(page).to have_content project.description | ||
# expect(page).not_to have_link("Edit") | ||
end | ||
end | ||
end | ||
# continuing story in: sign_in_unconfirmed_user || sign_in_confirmed_user || sign_in_fail | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rails_helper' | ||
require 'cancan/matchers' | ||
|
||
# Run this file with | ||
# $ rspec spec/models/ability_spec.rb -fd | ||
# to see the output of specs running inside the shared examples [mdv] | ||
RSpec.describe Ability, type: :model do | ||
|
||
let(:admin) { create(:user) } | ||
subject(:ability) { Ability.new(admin) } | ||
|
||
let(:other_user) { build_stubbed(:user, hide_email: true) } | ||
|
||
describe "Admin" do | ||
before { allow(admin).to receive(:admin?).and_return true } | ||
|
||
it { expect(subject).not_to be_able_to(:create, User.new) } # happens only via GitHub | ||
# it "has access to almost everything else" | ||
# Only test the most exclusive, the most sensitive and the 'cannots': | ||
it { expect(subject).to be_able_to(:crud, Team) } | ||
it { expect(subject).to be_able_to([:read, :update, :destroy], User) } | ||
it { expect(subject).to be_able_to(:read_email, other_user) } | ||
it { expect(subject).to be_able_to(:read, :users_info, other_user) } | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏎 The 'not authorised' method will now show up on the page where the user tried to do something forbidden. We couldn't
redirect :back
before, because it would mess up if there wasn't a referer present.