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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #997 from rails-girls-summer-of-code/clean_cans
Rearrange, not change the abilities in Ability
- Loading branch information
Showing
18 changed files
with
481 additions
and
445 deletions.
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
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
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,71 @@ | ||
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, :in_current_season, name: 'Cheesy forever', project_name: project.name, 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 | ||
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 { 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 |
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,31 @@ | ||
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) { build_stubbed(:user) } | ||
subject(:ability) { Ability.new(user) } | ||
let(:other_user) { build_stubbed(:user) } | ||
|
||
describe "Confirmed user" do | ||
|
||
it_behaves_like 'has access to public features' | ||
|
||
# same as unconfirmed: | ||
it "can modify own account" do | ||
expect(subject).to be_able_to([:update, :destroy], user) | ||
expect(subject).to be_able_to(:resend_confirmation_instruction, User, id: user.id) | ||
end | ||
it { expect(subject).not_to be_able_to([:update, :destroy], other_user) } | ||
|
||
# the perks of confirming | ||
it { expect(subject).to be_able_to([:join, :create], Team) } | ||
it { expect(subject).to be_able_to(:create, Comment) } # TODO needs work for polymorphism | ||
it { expect(subject).to be_able_to(:create, Project) } | ||
it { expect(subject).to be_able_to(:index, Mailing) } | ||
it { expect(subject).to be_able_to(:read, Mailing, recipient: user )} | ||
end | ||
end |
Oops, something went wrong.