forked from hitobito/hitobito
-
Notifications
You must be signed in to change notification settings - Fork 0
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 hitobito#658 from hitobito/feature/647_async_subgr…
…oups_export Async Subgroups Export
- Loading branch information
Showing
5 changed files
with
76 additions
and
14 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,26 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2018, Schweizer Blasmusikverband. This file is part of | ||
# hitobito and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito. | ||
|
||
class Export::SubgroupsExportJob < Export::ExportBaseJob | ||
|
||
self.parameters = PARAMETERS + [:group] | ||
|
||
def initialize(user_id, group, options) | ||
super(:csv, user_id, options) | ||
@exporter = Export::Tabular::Groups::List | ||
@group = group | ||
end | ||
|
||
private | ||
|
||
def entries | ||
@group.self_and_descendants | ||
.without_deleted | ||
.order(:lft) | ||
.includes(:contact) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2018, Schweizer Blasmusikverband. This file is part of | ||
# hitobito and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito. | ||
|
||
require 'spec_helper' | ||
|
||
describe Export::SubgroupsExportJob do | ||
|
||
subject { Export::SubgroupsExportJob.new(user.id, group, filename: 'subgroups_export') } | ||
|
||
let(:user) { people(:top_leader) } | ||
let(:group) { groups(:top_layer) } | ||
let(:year) { 2012 } | ||
let(:filepath) { AsyncDownloadFile::DIRECTORY.join('subgroups_export') } | ||
|
||
before do | ||
SeedFu.quiet = true | ||
SeedFu.seed [Rails.root.join('db', 'seeds')] | ||
end | ||
|
||
context 'creates a CSV-Export' do | ||
|
||
it 'and saves it' do | ||
subject.perform | ||
|
||
lines = File.readlines("#{filepath}.csv") | ||
expect(lines.size).to eq(10) | ||
expect(lines[0]).to match(/^Id;Elterngruppe;Name;.*/) | ||
expect(lines[1]).to match(/^#{group.id};;Top;.*/) | ||
expect(lines[2]).to match(/^#{groups(:bottom_layer_one).id};#{group.id};Bottom One;.*/) | ||
end | ||
end | ||
|
||
end |