This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Rearrange, not change the abilities in Ability #997
Merged
Merged
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d00277c
WIP Rearrange, not change the abilities in Ability, cf recommended be…
emcoding 27ead4d
Clean file, without todo's and check comments
emcoding e1b56f1
First examples of the New And Complete ability specs. Now with update…
emcoding 6b4664e
Halfway
emcoding bfaeb99
WIP All things processed and annotated
emcoding f6da595
Cleanup file ; see previous commit for annotations
emcoding b172a3f
hot fix for failing spec MailingsController (because of wrong authori…
emcoding ec3c037
Finetuning
emcoding f84460e
Finetuning
emcoding dad17d8
Write tests for desired behaviour of student ability whether or not t…
emcoding ff1e8ba
Write tests for desired behaviour of whether a supervisor can or cann…
emcoding 975877f
Restore old code for can read_email and can users_info. Add tests for…
emcoding 1e5db7d
WIP Split the ability specs in separate files per role - thanks to @k…
emcoding cabcae9
WIP First try feature test guest user access
emcoding 6e7d601
FIX issue 1003; couldn't solve the abilities and pass the specs witho…
emcoding 9a0f39b
Remove one level of nesting in the ability specs, removed the repitio…
emcoding e765a2b
:cop:
emcoding 9d685da
Revert changes to authorize method in controllers that are not needed…
emcoding 419bdf7
Declutter
emcoding cb126b9
Add scope to solve failing specs.
emcoding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_behaves_like "can not create new user" | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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(:user) { create(:user) } | ||
subject(:ability) { Ability.new(user) } | ||
|
||
describe "Confirmed user" do | ||
|
||
it_behaves_like "same as logged in user" | ||
it_behaves_like "can create a Project" | ||
it_behaves_like "can see mailings list too" | ||
it_behaves_like "can read mailings sent to them" | ||
it_behaves_like "can comment now" # not implemented; false positives; needs work | ||
it { expect(subject).to be_able_to([:join, :create], Team) } | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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(:user){ nil } | ||
subject(:ability) { Ability.new(user) } | ||
|
||
let(:other_user) { build_stubbed(:user) } | ||
|
||
describe "Guest User" do | ||
it_behaves_like "can view public pages" | ||
it_behaves_like "can not modify things on public pages" | ||
it_behaves_like "can not create new user" | ||
it_behaves_like "can not comment" | ||
it_behaves_like "has no access to other user's accounts" | ||
it_behaves_like "can not read role restricted or owner restricted pages" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 | ||
|
||
describe "Project Submitter" do | ||
|
||
let(:user) { build_stubbed(:user) } | ||
subject(:ability) { Ability.new(user) } | ||
|
||
let(:old_project) { build_stubbed(:project, submitter: user) } | ||
let(:other_project) { build_stubbed(:project, submitter: other_user) } | ||
let(:same_season_project) { build :project, :in_current_season, submitter: user } | ||
let(:other_user) { build_stubbed(:user) } | ||
|
||
it_behaves_like "same public features as confirmed user" | ||
it { expect(subject).to be_able_to([:update, :destroy], Project.new(submitter: user)) } | ||
it { expect(subject).to be_able_to(:use_as_template, old_project) } | ||
it { expect(subject).not_to be_able_to(:use_as_template, other_project) } | ||
it { expect(subject).not_to be_able_to :use_as_template, same_season_project } | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍