-
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.
- Loading branch information
1 parent
0c6cddf
commit f85fa66
Showing
6 changed files
with
93 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class ExportPointHistory | ||
attr_reader :semester | ||
|
||
def initialize(semester) | ||
@semester = semester | ||
end | ||
|
||
def self.call(semester) | ||
new(semester).call | ||
end | ||
|
||
def call | ||
result = [] | ||
result << ["PéK id", "Név", "Neptun", "BME-id", "Email", "Felvételi pont", "SVIE tagság", "Körök"] | ||
histories = PointHistory.includes(user: [point_requests: [evaluation: :group]]).where(semester: semester).where.not(point: 0) | ||
histories.map do |history| | ||
user = history.user | ||
point_requests = user.point_requests.select do |point_request| | ||
point_request.accepted? && point_request.evaluation.semester == semester | ||
end | ||
point_requests = point_requests.reject { |point_request| point_request.point == 0 } | ||
groups = point_requests.map { |point_request| point_request.evaluation.group.name }.join(',') | ||
email = URI::MailTo::EMAIL_REGEXP.match?(user.email) ? user.email : nil | ||
result << [user.id, user.full_name, user.neptun, user.bme_id, email, history.point, user.svie_member_type, groups] | ||
end | ||
result | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe ExportPointHistory do | ||
subject(:export) { ExportPointHistory.call(semester.to_s) } | ||
let!(:membership) { create(:membership, :with_point_request) } | ||
let!(:group) { membership.group } | ||
let!(:user) { membership.user } | ||
let!(:point_request) { user.point_requests.first } | ||
let!(:evaluation) { point_request.evaluation } | ||
let!(:semester) { Semester.new(evaluation.semester) } | ||
let!(:membership_with_zero_point) { create(:membership, :with_point_request) } | ||
let!(:user_with_zero_point) { membership_with_zero_point.user} | ||
|
||
before do | ||
point_request.update!(point: 25) | ||
membership_with_zero_point.update!(group: group) | ||
user_with_zero_point.reload | ||
user_with_zero_point.point_requests.first.update!(evaluation: evaluation) | ||
user_with_zero_point.point_requests.first.update!(point: 0) | ||
evaluation.update!(point_request_status: Evaluation::ACCEPTED) | ||
CalculatePointHistory.new(semester).call | ||
end | ||
|
||
it 'has the correct length' do | ||
expect(export.length).to eq(2) | ||
end | ||
|
||
it 'first row has the correct headers' do | ||
expect(export[0]).to eq(["PéK id", "Név", "Neptun", "BME-id", "Email", "Felvételi pont", "SVIE tagság", "Körök"]) | ||
end | ||
|
||
it 'second row has the correct data' do | ||
expect(export[1]).to eq([user.id, user.full_name, user.neptun, user.bme_id, user.email, 25, | ||
user.svie_member_type, evaluation.group.name]) | ||
end | ||
|
||
it 'user with zero points are not int the export' do | ||
expect(export.none?{|row| row[0] == user_with_zero_point.id }).to be true | ||
end | ||
end |