-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for evaluation authorization (#268)
- Loading branch information
1 parent
5e47fde
commit 4228707
Showing
12 changed files
with
253 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "EntryRequests", type: :request do | ||
let(:entry_request) { create(:entry_request) } | ||
let(:evaluation) { entry_request.evaluation } | ||
let(:group) { evaluation.group } | ||
let(:selected_user) { entry_request.user } | ||
|
||
before(:each) do | ||
login_as(current_user) | ||
end | ||
|
||
describe "#update" do | ||
include_context "application season" | ||
|
||
subject do | ||
post "/groups/#{group.id}/evaluations/#{evaluation.id}/entryrequests/update", | ||
params: { | ||
user_id: selected_user.id, | ||
entry_type: EntryRequest::AB | ||
} | ||
end | ||
|
||
context "when the user is not authorized" do | ||
let(:current_user) { create(:user) } | ||
|
||
it "returns forbidden" do | ||
subject | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context "when the current_user is the group leader" do | ||
let(:current_user) { group.leader.user } | ||
|
||
it "updates the entry request" do | ||
subject | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
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
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,68 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "PointDetails" do | ||
describe "#update" do | ||
let(:point_detail) { create(:point_detail) } | ||
let(:evaluation) { point_detail.point_request.evaluation } | ||
let(:group) { evaluation.group } | ||
let(:params) do | ||
principle = point_detail.principle | ||
{ | ||
user_id: point_detail.point_request.user.id, | ||
principle_id: principle.id, | ||
evaluation_id: evaluation.id, | ||
point: principle.max_per_member | ||
} | ||
end | ||
|
||
subject do | ||
headers = { "ACCEPT" => "application/js" } | ||
post "/groups/#{group.id}/evaluations/#{evaluation.id}/pointdetails/update", params: params, headers: headers | ||
end | ||
|
||
before(:each) { login_as(current_user) } | ||
|
||
context "when the user has no permission" do | ||
let(:current_user) { create(:user) } | ||
|
||
it "returns forbidden" do | ||
subject | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context "when the current user is the group leader" do | ||
let(:current_user) { group.leader.user } | ||
|
||
context "when application season" do | ||
include_context "application season" | ||
|
||
context "when the point detail already exists" do | ||
it "updates the point detail" do | ||
subject | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "doesn't change the PointDetail count" do | ||
expect { subject }.to_not change { PointDetail.count } | ||
end | ||
|
||
it "has the correct attributes" do | ||
subject | ||
|
||
expected_attributes = { principle_id: params[:principle_id], point: params[:point] } | ||
expect(PointDetail.last).to have_attributes(expected_attributes) | ||
end | ||
|
||
it "belongs to the correct user" do | ||
subject | ||
|
||
expect(PointDetail.last.point_request.user).to eql(point_detail.point_request.user) | ||
end | ||
end | ||
end | ||
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,19 @@ | ||
module SeasonHelpers | ||
shared_context "off season" do | ||
before(:each) do | ||
SystemAttribute.update_season(SystemAttribute::OFFSEASON) | ||
end | ||
end | ||
|
||
shared_context "application season" do | ||
before(:each) do | ||
SystemAttribute.update_season(SystemAttribute::APPLICATION_SEASON) | ||
end | ||
end | ||
|
||
shared_context "evaluation season" do | ||
before(:each) do | ||
SystemAttribute.update_season(SystemAttribute::EVALUATION_SEASON) | ||
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,13 @@ | ||
FactoryBot.define do | ||
factory :entry_request do | ||
association :evaluation | ||
association :user | ||
|
||
after(:build) do |er| | ||
create(:membership, user: er.user, group: er.evaluation.group) | ||
end | ||
|
||
entry_type { EntryRequest::DEFAULT_TYPE } | ||
justification { "Kifejezettem aktív volt a félévben." } | ||
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
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