rexport 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cf8cb2fe8850f491ab8eb8a92d0034d1447babd6a4a79457acea80fcbec94fc
4
- data.tar.gz: 2e646631a4c3673359f31bd222c43c32ed6fcb20813f7f6ac34d633005899628
3
+ metadata.gz: 91b93bfa7c3dea7a0a9df8dce1e59681aa8de412825556ad9c8b1c743d08c29b
4
+ data.tar.gz: ac601552d8d3b65b106bab210dc142eda8d88fc489742021100364f1dfc0707b
5
5
  SHA512:
6
- metadata.gz: '08d2fd739cf9775d22295a57ba4ffd934da63079339f0b697ff923ecba958b2bf5c007987a5ade00756b56a758672d37b23482dc9151dbb610157be181761521'
7
- data.tar.gz: '0359913d6d17b4303518284a54a5da8428a1c0b3ce871766fa117a37c063f5d739aa812a08e495689867502ca63be23e719405211eb2ea35b2c046dae006c6e7'
6
+ metadata.gz: 85cb6d95f199755c44ade632a1cedbe3c6c8834a9d9da9ea1938d1749ee3a4f7045b4fa5ccc091245c0c6471cf24a0d435964621fc93f4f7ab431e4eb8bf2a01
7
+ data.tar.gz: e69b135131c1484152e10cfc4e0b580888b308084c06b050962dd690dc6917e730be489dedb88265e218ea11ca75635e6d375f89b5c77de84f7800985f901c49
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Aaron Baldwin, WWIDEA INC.
1
+ Copyright 2011-2023 Aaron Baldwin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Rexport
2
+ Ruby on Rails gem to manage exports
3
+
4
+ ## Installation
5
+ 1. install gem
6
+ 2. copy migration into application db/migrate folder and run
7
+ 3. create models and mix in corresponding module
8
+ - **export** - export_methods
9
+ - **export_item** - export_item_methods
10
+ - **export_filter** - export_filter_methods
11
+
12
+ ## License
13
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,10 +1,3 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
1
+ require "bundler/setup"
9
2
 
10
- task default: :test
3
+ require "bundler/gem_tasks"
@@ -1,3 +1,3 @@
1
1
  module Rexport
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Baldwin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-09-02 00:00:00.000000000 Z
12
+ date: 2023-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -25,58 +25,16 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 6.0.3
28
- - !ruby/object:Gem::Dependency
29
- name: factory_bot
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '6.2'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '6.2'
42
- - !ruby/object:Gem::Dependency
43
- name: sqlite3
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '1.4'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '1.4'
56
- - !ruby/object:Gem::Dependency
57
- name: mocha
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '1.13'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '1.13'
70
28
  description: Rexport integrates into a Rails application making model data available
71
29
  for export into CSV files.
72
30
  email:
73
- - developers@brightwayslearning.org
31
+ - baldwina@brightwayslearning.org
74
32
  executables: []
75
33
  extensions: []
76
34
  extra_rdoc_files: []
77
35
  files:
78
36
  - MIT-LICENSE
79
- - README.rdoc
37
+ - README.md
80
38
  - Rakefile
81
39
  - app/helpers/exports_helper.rb
82
40
  - app/views/export_filters/_export_filter.html.erb
@@ -107,19 +65,13 @@ files:
107
65
  - lib/rexport/rexport_model.rb
108
66
  - lib/rexport/tree_node.rb
109
67
  - lib/rexport/version.rb
110
- - test/factories.rb
111
- - test/test_helper.rb
112
- - test/unit/data_field_test.rb
113
- - test/unit/data_fields_test.rb
114
- - test/unit/export_filter_methods_test.rb
115
- - test/unit/export_item_methods_test.rb
116
- - test/unit/export_methods_test.rb
117
- - test/unit/rexport_model_test.rb
118
- - test/unit/tree_node_test.rb
119
68
  homepage: https://github.com/wwidea/rexport
120
69
  licenses:
121
70
  - MIT
122
- metadata: {}
71
+ metadata:
72
+ homepage_uri: https://github.com/wwidea/rexport
73
+ source_code_uri: https://github.com/wwidea/rexport
74
+ rubygems_mfa_required: 'true'
123
75
  post_install_message:
124
76
  rdoc_options: []
125
77
  require_paths:
@@ -128,24 +80,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
80
  requirements:
129
81
  - - ">="
130
82
  - !ruby/object:Gem::Version
131
- version: '0'
83
+ version: 2.7.0
132
84
  required_rubygems_version: !ruby/object:Gem::Requirement
133
85
  requirements:
134
86
  - - ">="
135
87
  - !ruby/object:Gem::Version
136
88
  version: '0'
137
89
  requirements: []
138
- rubygems_version: 3.3.9
90
+ rubygems_version: 3.4.5
139
91
  signing_key:
140
92
  specification_version: 4
141
93
  summary: Ruby on Rails gem to manage exports.
142
- test_files:
143
- - test/factories.rb
144
- - test/test_helper.rb
145
- - test/unit/data_field_test.rb
146
- - test/unit/data_fields_test.rb
147
- - test/unit/export_filter_methods_test.rb
148
- - test/unit/export_item_methods_test.rb
149
- - test/unit/export_methods_test.rb
150
- - test/unit/rexport_model_test.rb
151
- - test/unit/tree_node_test.rb
94
+ test_files: []
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- =Rexport
2
-
3
- Ruby on Rails gem to manage exports
4
-
5
-
6
- ==Installation
7
- 1. install gem
8
- 2. copy migration into application db/migrate folder and run
9
- 3. create models and mix in corresponding module
10
- * export => export_methods
11
- * export_item => export_item_methods
12
- * export_filter => export_filter_methods
13
-
14
-
15
- ==License
16
-
17
- Copyright (c) 2008-2018 Brightways Learning, released under the MIT license
data/test/factories.rb DELETED
@@ -1,111 +0,0 @@
1
- module Rexport
2
- module Factories
3
-
4
- FactoryBot.define do
5
-
6
- factory :status do
7
- name { 'active' }
8
- end
9
-
10
- factory :family do
11
- name { 'The Sample Family' }
12
- end
13
-
14
- factory :student do
15
- family { |family| family.association(:family) }
16
- name { 'Sammy Sample' }
17
- date_of_birth { Date.parse('2008-12-08') }
18
- end
19
-
20
- factory :enrollment do
21
- status { |status| status.association(:status) }
22
- student { |student| student.association(:student) }
23
- grade { 1 }
24
- updated_at { Time.now }
25
- end
26
-
27
- factory :second_grade_enrollment, class: 'Enrollment' do
28
- status { |status| status.association(:status) }
29
- grade { 2 }
30
- end
31
-
32
- factory :export do
33
- name { 'Enrollment Export' }
34
- model_class_name { 'Enrollment' }
35
- export_items do |items|
36
- %w(family_name_export_item grade_export_item status_name_export_item bogus_export_item).map do |item|
37
- items.association(item)
38
- end
39
- end
40
- end
41
-
42
- factory :filtered_export, class: 'Export' do
43
- name { 'Filtered Enrollment Export' }
44
- model_class_name { 'Enrollment' }
45
- export_items do |items|
46
- %w(grade_export_item status_name_export_item).map do |item|
47
- items.association(item)
48
- end
49
- end
50
- export_filters do |filters|
51
- %w(grade_filter status_filter).map do |filter|
52
- filters.association(filter)
53
- end
54
- end
55
- end
56
-
57
- factory :invalid_filtered_export, class: 'Export' do
58
- name { 'Invalid Filtered Enrollment Export' }
59
- model_class_name { 'Enrollment' }
60
- export_items do |items|
61
- %w(grade_export_item status_name_export_item).map do |item|
62
- items.association(item)
63
- end
64
- end
65
- export_filters do |filters|
66
- %w(invalid_filter).map do |filter|
67
- filters.association(filter)
68
- end
69
- end
70
- end
71
-
72
- factory :family_name_export_item, class: 'ExportItem' do
73
- position { 1 }
74
- name { 'Family Name' }
75
- rexport_field { 'student.family.name' }
76
- end
77
-
78
- factory :grade_export_item, class: 'ExportItem' do
79
- position { 2 }
80
- rexport_field { 'grade' }
81
- end
82
-
83
- factory :status_name_export_item, class: 'ExportItem' do
84
- position { 3 }
85
- name { 'Status' }
86
- rexport_field { 'status_name' }
87
- end
88
-
89
- factory :bogus_export_item, class: 'ExportItem' do
90
- position { 4 }
91
- name { 'Bogus Item' }
92
- rexport_field { 'bogus_field' }
93
- end
94
-
95
- factory :grade_filter, class: 'ExportFilter' do
96
- filter_field { 'grade' }
97
- value { '1' }
98
- end
99
-
100
- factory :status_filter, class: 'ExportFilter' do
101
- filter_field { 'status.name' }
102
- value { 'active' }
103
- end
104
-
105
- factory :invalid_filter, class: 'ExportFilter' do
106
- filter_field { 'invalid' }
107
- value { '1' }
108
- end
109
- end
110
- end
111
- end
data/test/test_helper.rb DELETED
@@ -1,167 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter '/test/'
4
- end
5
-
6
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
7
- require "rails"
8
- require 'active_record'
9
- require "rexport"
10
-
11
- require 'minitest/autorun'
12
- require 'factory_bot'
13
- require 'mocha/minitest'
14
- require File.dirname(__FILE__) + '/factories'
15
-
16
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
17
-
18
- class ActiveSupport::TestCase
19
- include FactoryBot::Syntax::Methods
20
- include Rexport::Factories
21
-
22
- def setup
23
- suppress_output { setup_db }
24
- Enrollment.instance_variable_set('@rexport_fields', nil)
25
- Student.instance_variable_set('@rexport_fields', nil)
26
- end
27
-
28
- def teardown
29
- teardown_db
30
- end
31
-
32
- private
33
-
34
- def setup_db
35
- ActiveRecord::Schema.define(version: 1) do
36
- create_table :enrollments do |t|
37
- t.integer :student_id, :status_id, :grade
38
- t.boolean :active
39
- t.timestamps
40
- end
41
-
42
- create_table :students do |t|
43
- t.integer :family_id
44
- t.string :name
45
- t.date :date_of_birth
46
- t.timestamps
47
- end
48
-
49
- create_table :families do |t|
50
- t.string :name
51
- t.timestamps
52
- end
53
-
54
- create_table :statuses do |t|
55
- t.string :name
56
- end
57
-
58
- create_table :exports do |t|
59
- t.string :name
60
- t.string :model_class_name
61
- t.text :description
62
- end
63
-
64
- create_table :export_items do |t|
65
- t.integer :export_id
66
- t.string :name, :rexport_field
67
- t.integer :position
68
- end
69
-
70
- create_table :export_filters do |t|
71
- t.integer :export_id
72
- t.string :filter_field, :value
73
- end
74
-
75
- create_table :self_referential_checks do |t|
76
- end
77
- end
78
- end
79
-
80
- def teardown_db
81
- ActiveRecord::Base.connection.data_sources.each do |table|
82
- ActiveRecord::Base.connection.drop_table(table)
83
- end
84
- end
85
-
86
- def suppress_output
87
- original_stdout = $stdout.clone
88
- $stdout.reopen File.new('/dev/null', 'w')
89
- yield
90
- ensure
91
- $stdout.reopen original_stdout
92
- end
93
- end
94
-
95
- class ActiveRecord::Base
96
- class << self
97
- def acts_as_list(options = {})
98
- end
99
- end
100
- end
101
-
102
- class Enrollment < ActiveRecord::Base
103
- include Rexport::DataFields
104
- belongs_to :student
105
- belongs_to :status
106
- belongs_to :ilp_status, class_name: 'Status', foreign_key: 'ilp_status_id'
107
- belongs_to :self_referential_check
108
-
109
- def foo
110
- 'bar'
111
- end
112
-
113
- private
114
-
115
- def self.initialize_local_rexport_fields(rexport_model)
116
- rexport_model.add_rexport_field(:foo_method, method: :foo)
117
- rexport_model.add_rexport_field(:bad_method, method: 'bad_method')
118
- rexport_model.add_association_methods(associations: %w(status ilp_status))
119
- end
120
- end
121
-
122
- class Student < ActiveRecord::Base
123
- include Rexport::DataFields
124
- belongs_to :family
125
- has_many :enrollments
126
-
127
- def self.find_family_for_rexport
128
- Family.order(:name)
129
- end
130
- end
131
-
132
- class Family < ActiveRecord::Base
133
- include Rexport::DataFields
134
- has_many :students
135
-
136
- def foo
137
- 'bar'
138
- end
139
-
140
- private
141
-
142
- def self.initialize_local_rexport_fields(rexport_model)
143
- rexport_model.add_rexport_field(:foo_method, method: :foo)
144
- end
145
- end
146
-
147
- class Status < ActiveRecord::Base
148
- # does not include Rexport
149
- has_many :enrollments
150
- end
151
-
152
- class Export < ActiveRecord::Base
153
- include Rexport::ExportMethods
154
- end
155
-
156
- class ExportItem < ActiveRecord::Base
157
- include Rexport::ExportItemMethods
158
- end
159
-
160
- class ExportFilter < ActiveRecord::Base
161
- include Rexport::ExportFilterMethods
162
- end
163
-
164
- class SelfReferentialCheck < ActiveRecord::Base
165
- include Rexport::DataFields
166
- belongs_to :enrollment
167
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DataFieldTest < ActiveSupport::TestCase
4
- test 'should stringify name' do
5
- assert_equal 'foo', Rexport::DataField.new(:foo).name
6
- end
7
-
8
- test 'should use name for method' do
9
- assert_equal 'foo', Rexport::DataField.new(:foo).method
10
- end
11
-
12
- test 'should save method' do
13
- assert_equal 'bar', Rexport::DataField.new(:foo, method: :bar).method
14
- end
15
-
16
- test 'should save type' do
17
- assert_equal :type_test, Rexport::DataField.new(:test, type: :type_test).type
18
- end
19
-
20
- test 'should_sort_data_fields' do
21
- a = Rexport::DataField.new(:a)
22
- b = Rexport::DataField.new(:b)
23
- assert_equal [a,b], [b,a].sort
24
- end
25
- end
@@ -1,75 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DataFieldsTest < ActiveSupport::TestCase
4
-
5
- class RexportClassMethodsTest < DataFieldsTest
6
- test 'should get klass from assocations' do
7
- assert_equal Family, Enrollment.get_klass_from_associations('student', 'family')
8
- end
9
-
10
- test 'should raise no method error for missing associations' do
11
- assert_raise NoMethodError do
12
- Enrollment.get_klass_from_associations('not_an_association')
13
- end
14
- end
15
- end
16
-
17
- class RexportInstanceMethodsTest < DataFieldsTest
18
- test 'should exoport value of data attribute' do
19
- assert_equal %w(1), build(:enrollment).export('grade')
20
- end
21
-
22
- test 'should export value returned from method' do
23
- assert_equal %w(bar), build(:enrollment).export('foo')
24
- end
25
-
26
- test 'should return empty string for undefined method' do
27
- assert_equal [''], build(:enrollment).export('bad_method')
28
- end
29
-
30
- test 'should format date for export' do
31
- assert_equal [Time.now.strftime("%m/%d/%y")], build(:enrollment).export('updated_at')
32
- end
33
-
34
- test 'should export Y for true' do
35
- assert_equal %w(Y), Enrollment.new(active: true).export('active')
36
- end
37
-
38
- test 'should export N for false' do
39
- assert_equal %w(N), Enrollment.new(active: false).export('active')
40
- end
41
-
42
- test 'should handle missing associations' do
43
- assert_equal [''], Enrollment.new.export('status.name')
44
- end
45
-
46
- test 'should handle undefined export field' do
47
- assert_equal ['UNDEFINED EXPORT FIELD'], Enrollment.new.export('undefined_rexport_field')
48
- end
49
-
50
- test 'should export value of associated data attribute' do
51
- assert_equal ['The Sample Family'], build(:enrollment).export('student.family.name')
52
- end
53
-
54
- test 'should export value returned from associated method' do
55
- assert_equal %w(bar), build(:enrollment).export('student.family.foo')
56
- end
57
-
58
- test 'should export field from non rexported model' do
59
- assert_equal %w(active), build(:enrollment).export('status.name')
60
- end
61
-
62
- test 'should export local, associated, and non rexported fields in order' do
63
- assert_equal(
64
- ['The Sample Family', 'Sammy Sample', '1', 'bar', 'active'],
65
- build(:enrollment).export(
66
- 'student.family.name',
67
- 'student.name',
68
- 'grade',
69
- 'student.family.foo',
70
- 'status.name'
71
- )
72
- )
73
- end
74
- end
75
- end
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExportFilterMethodsTest < ActiveSupport::TestCase
4
- test 'should return associated object name' do
5
- assert_equal '1', FactoryBot.create(:grade_filter).display_value
6
- end
7
-
8
- test 'should return chained associated object value' do
9
- assert_equal 'active', FactoryBot.create(:status_filter).display_value
10
- end
11
-
12
- test 'should return chained associated object' do
13
- family = FactoryBot.create(:family)
14
- assert_equal(
15
- family.name,
16
- export_filter('student.family_id', value: family.id).display_value
17
- )
18
- end
19
-
20
- test 'should return undefined association' do
21
- assert_equal('UNDEFINED ASSOCIATION', export_filter('bogus_id').display_value)
22
- end
23
-
24
- test 'should return associated object not found' do
25
- assert_equal 'ASSOCIATED OBJECT NOT FOUND', export_filter('status_id').display_value
26
- end
27
-
28
- private
29
-
30
- def export_filter(filter_field, value: 1)
31
- ExportFilter.new(
32
- export: FactoryBot.create(:export),
33
- filter_field: filter_field,
34
- value: value
35
- )
36
- end
37
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExportItemMethodsTest < ActiveSupport::TestCase
4
- test 'should resort export items' do
5
- export = FactoryBot.create(:export)
6
- ExportItem.resort(export.export_items.ordered.reverse.map(&:id).map(&:to_s))
7
- assert_equal 'Bogus Item', export.export_items.ordered.first.name
8
- end
9
-
10
- test 'should return attributes_for_copy' do
11
- assert FactoryBot.create(:family_name_export_item).attributes_for_copy
12
- end
13
-
14
- test 'should set name when blank' do
15
- assert_equal 'Grade', FactoryBot.create(:grade_export_item).name
16
- end
17
-
18
- test 'should set name for chained field to last two items' do
19
- assert_equal 'Name - Test', ExportItem.create(rexport_field: 'this.is.a.name.test').name
20
- end
21
- end
@@ -1,226 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExportMethodsTest < ActiveSupport::TestCase
4
- test 'should return models' do
5
- assert Export.models
6
- end
7
-
8
- test 'should return full name' do
9
- assert_equal 'Enrollments - Enrollment Export', build(:export).full_name
10
- end
11
-
12
- test 'should return header' do
13
- assert_equal ['Family Name', 'Grade', 'Status', 'Bogus Item'], create(:export).header
14
- end
15
-
16
- test 'should return rexport_fields' do
17
- assert_equal(
18
- %w(student.family.name grade status_name bogus_field),
19
- build(:export).send(:rexport_fields)
20
- )
21
- end
22
-
23
- test 'should return rexport_methods' do
24
- assert_equal(
25
- %w(student.family.name grade status.name undefined_rexport_field),
26
- create(:export).send(:rexport_methods)
27
- )
28
- end
29
-
30
- test 'should return records' do
31
- create(:enrollment)
32
- assert_equal(
33
- ['The Sample Family', '1', 'active', 'UNDEFINED EXPORT FIELD'],
34
- create(:export).records.first
35
- )
36
- end
37
-
38
- test 'should return records that match filters' do
39
- create(:enrollment)
40
- create(:second_grade_enrollment)
41
- assert_equal 2, Enrollment.count
42
- assert_equal [['1', 'active']], create(:filtered_export).records
43
- end
44
-
45
- test 'should return error message for records when export has an invalid filter' do
46
- assert_equal(
47
- [["SQLite3::SQLException: no such column: enrollments.invalid"]],
48
- create(:invalid_filtered_export).records
49
- )
50
- end
51
-
52
- test 'should call get_records' do
53
- export = build(:export)
54
- export.expects(:get_records).with(Rexport::SAMPLE_SIZE).returns(true)
55
- assert export.sample_records
56
- end
57
-
58
- test 'should return to_s with no records' do
59
- assert_equal "Family Name|Grade|Status|Bogus Item\n", create(:export).to_s
60
- end
61
-
62
- test 'should return to_s with record' do
63
- create(:enrollment)
64
- assert_equal(
65
- "Family Name|Grade|Status|Bogus Item\nThe Sample Family|1|active|UNDEFINED EXPORT FIELD\n",
66
- create(:export).to_s
67
- )
68
- end
69
-
70
- test 'should return to_csv with no records' do
71
- assert_equal "Family Name,Grade,Status,Bogus Item\n", create(:export).to_csv
72
- end
73
-
74
- test 'should return to_csv with record' do
75
- FactoryBot.create(:enrollment)
76
- assert_equal(
77
- "Family Name,Grade,Status,Bogus Item\nThe Sample Family,1,active,UNDEFINED EXPORT FIELD\n",
78
- create(:export).to_csv
79
- )
80
- end
81
-
82
- test 'should return to_csv with passed objects' do
83
- assert_equal(
84
- "Family Name,Grade,Status,Bogus Item\n\"\",99,\"\",UNDEFINED EXPORT FIELD\n",
85
- create(:export).to_csv([Enrollment.new(grade: 99)])
86
- )
87
- end
88
-
89
- test 'should return build_conditions' do
90
- assert_equal(
91
- {'statuses.name' => 'active', 'enrollments.grade' => '1'},
92
- create(:filtered_export).send(:build_conditions)
93
- )
94
- end
95
-
96
- test 'should return build_include' do
97
- assert_equal [{student: [:family]}, :status], create(:export).send(:build_include)
98
- end
99
-
100
- test 'should return rexport_models' do
101
- export = create(:export)
102
- assert_equal(
103
- %w(Enrollment Family SelfReferentialCheck Student),
104
- export.rexport_models.map(&:name).sort
105
- )
106
- assert_equal(
107
- ['', 'self_referential_check', 'student', 'student.family'],
108
- export.rexport_models.map(&:path).map(&:to_s).sort
109
- )
110
- end
111
-
112
- test 'should return true for has_rexport_field?' do
113
- assert build(:export).has_rexport_field?('student.family.name')
114
- end
115
-
116
- test 'should return false for has_rexport_field?' do
117
- refute build(:export).has_rexport_field?('student.family.number')
118
- end
119
-
120
- test 'should save export_items from a hash' do
121
- assert_equal %w(a b c), rexport_fields_for(create_export(fields: {a: 1, b: 1, c: 1}))
122
- end
123
-
124
- test 'should save export_items from an array' do
125
- assert_equal %w(a b c), rexport_fields_for(create_export(fields: %w(a b c)))
126
- end
127
-
128
- test 'should add export_item to exising export on update' do
129
- export = create_export(fields: %w(a c))
130
- assert_difference 'ExportItem.count' do
131
- export.update_attribute(:rexport_fields, %w(a b c))
132
- end
133
- assert_equal %w(a b c), rexport_fields_for(export)
134
- end
135
-
136
- test 'should delete export_item that is not in rexport_fields on update' do
137
- export = create_export(fields: %w(a b c))
138
- assert_difference 'ExportItem.count', -1 do
139
- export.update_attribute(:rexport_fields, %w(a c))
140
- end
141
- assert_equal %w(a c), rexport_fields_for(export)
142
- end
143
-
144
- test 'should re-order export_items when passed an array of export_fields on update' do
145
- export = create_export(fields: %w(a b c))
146
- export.update_attribute(:rexport_fields, %w(c b a))
147
- assert_equal %w(c b a), rexport_fields_for(export)
148
- end
149
-
150
- test 'should not re-order export_items when passed a hash of export_fields on update' do
151
- export = create_export(fields: %w(a b c))
152
- export.update_attribute(:rexport_fields, {c: 1, b: 1, a: 1})
153
- assert_equal %w(a b c), rexport_fields_for(export)
154
- end
155
-
156
- test 'should not modify export_items on update when no export_fields are passed' do
157
- export = create_export(fields: %w(a b c))
158
- assert_no_difference 'ExportItem.count' do
159
- export.update_attribute(:name, 'New Name')
160
- end
161
- assert_equal %w(a b c), rexport_fields_for(export)
162
- end
163
-
164
- test 'should create export with an export_filter' do
165
- assert_difference 'ExportFilter.count' do
166
- create_export(filters: {status_id: 1})
167
- end
168
- end
169
-
170
- test 'should add an export_filter to an existing export' do
171
- export = create_export
172
- assert_difference 'ExportFilter.count' do
173
- export.update_attribute(:export_filter_attributes, {status_id: 1})
174
- end
175
- end
176
-
177
- test 'should delete an export_filter from an export' do
178
- export = create_export(filters: {status_id: 1})
179
- assert_difference 'ExportFilter.count', -1 do
180
- export.update_attribute(:export_filter_attributes, {status_id: ''})
181
- end
182
- end
183
-
184
- test 'should return filter_value for filter_field' do
185
- assert_equal 'active', create(:filtered_export).filter_value('status.name')
186
- end
187
-
188
- test 'should return nil for filter_value when no matching export_filters' do
189
- assert_nil create(:filtered_export).filter_value('does_not_exist')
190
- end
191
-
192
- test 'should create copy with unique name' do
193
- assert_equal 'Enrollment Export Copy', create(:export).copy.name
194
- assert_equal 'Enrollment Export Copy [1]', create(:export).copy.name
195
- assert_equal 'Enrollment Export Copy [2]', create(:export).copy.name
196
- end
197
-
198
- test 'should copy export with export_items' do
199
- export = create(:export)
200
- assert_difference 'ExportItem.count', export.export_items.count do
201
- export.copy.export_items.count
202
- end
203
- end
204
-
205
- test 'should copy export with export_filters' do
206
- export = create(:filtered_export)
207
- assert_difference 'ExportFilter.count', export.export_filters.count do
208
- export.copy
209
- end
210
- end
211
-
212
- private
213
-
214
- def create_export(fields: {}, filters: {})
215
- Export.create(
216
- name: 'Test',
217
- model_class_name: 'Enrollment',
218
- rexport_fields: fields,
219
- export_filter_attributes: filters
220
- )
221
- end
222
-
223
- def rexport_fields_for(export)
224
- export.export_items.ordered.map(&:rexport_field)
225
- end
226
- end
@@ -1,137 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RexportModel < ActiveSupport::TestCase
4
- test 'should initialize rexport_fields' do
5
- assert_equal(
6
- %w(active bad_method created_at foo_method grade ilp_status_name status_name updated_at),
7
- rexport_model.rexport_fields.keys.sort
8
- )
9
- end
10
-
11
- test 'should initialize data atributes' do
12
- assert_equal 'grade', rexport_model.rexport_fields[:grade].method
13
- assert_equal :integer, rexport_model.rexport_fields[:grade].type
14
- end
15
-
16
- test 'should initialize method' do
17
- assert_equal 'foo', rexport_model.rexport_fields[:foo_method].method
18
- assert_nil rexport_model.rexport_fields[:foo_method].type
19
- end
20
-
21
- test 'should add single association method to rexport_fields' do
22
- assert_fields_length do |rexport|
23
- rexport.add_association_methods(associations: 'test_association')
24
- assert_equal 'test_association_name', rexport.rexport_fields[:test_association_name].name
25
- assert_equal 'test_association.name', rexport.rexport_fields[:test_association_name].method
26
- end
27
- end
28
-
29
- test 'should add name methods for multiple associations' do
30
- assert_fields_length(change: 3) do |rexport|
31
- rexport.add_association_methods(associations: %w(a b c))
32
- end
33
- end
34
-
35
- test 'should add multiple methods for multiple associations' do
36
- assert_fields_length(change: 9) do |rexport|
37
- rexport.add_association_methods(associations: %w(a1 a2 a3), methods: %w(m1 m2 m3))
38
- end
39
- end
40
-
41
- test 'should remove single rexport field' do
42
- rexport_model.tap do |rexport|
43
- assert rexport.rexport_fields[:grade]
44
- assert rexport.remove_rexport_fields(:grade)
45
- assert_nil rexport.rexport_fields[:grade]
46
- end
47
- end
48
-
49
- test 'should remove multiple rexport fields' do
50
- fields = %w(grade status_name foo_method)
51
-
52
- rexport_model.tap do |rexport|
53
- fields.each { |field| assert(rexport.rexport_fields[field]) }
54
- assert rexport.remove_rexport_fields(fields)
55
- fields.each { |field| assert_nil(rexport.rexport_fields[field]) }
56
- end
57
- end
58
-
59
- test 'should get rexport methods' do
60
- assert_equal(
61
- [
62
- 'student.family.foo',
63
- 'student.name',
64
- 'undefined_rexport_field',
65
- 'undefined_rexport_field',
66
- 'status.name',
67
- 'grade'
68
- ],
69
- rexport_model.get_rexport_methods(
70
- 'student.family.foo_method',
71
- 'student.name',
72
- 'student.bad_method',
73
- 'bad_association.test',
74
- 'status_name',
75
- 'grade'
76
- )
77
- )
78
- end
79
-
80
- test 'should use cached rexport_model when getting multiple fields from one model' do
81
- rexport_model.tap do |rexport|
82
- assert_equal ['student.name'], rexport.get_rexport_methods('student.name')
83
- Student.expects(:get_klass_from_associations).times(0)
84
- assert_equal ['student.date_of_birth'], rexport.get_rexport_methods('student.date_of_birth')
85
- end
86
- end
87
-
88
- test 'should return default foreign_key' do
89
- assert_equal 'status_id', rexport_model.filter_column(data_field('status_name'))
90
- end
91
-
92
- test 'should return custom foreign_key' do
93
- assert_equal 'ilp_status_id', rexport_model.filter_column(data_field('ilp_status_name'))
94
- end
95
-
96
- test 'should call rexport_fields_array' do
97
- assert_equal(
98
- %w(active bad_method created_at foo_method grade ilp_status_name status_name updated_at),
99
- rexport_model.rexport_fields_array.map(&:name)
100
- )
101
- end
102
-
103
- test 'should return field_path' do
104
- assert_equal 'foo.bar', rexport_model(path: 'foo').field_path('bar')
105
- end
106
-
107
- test 'should return collection_from_association' do
108
- Status.expects(:all).returns(true)
109
- assert rexport_model.collection_from_association('status')
110
- end
111
-
112
- test 'should return custom find method for collection_from_association' do
113
- Student.expects(:find_family_for_rexport).returns(true)
114
- assert rexport_model(model: Student).collection_from_association('family')
115
- end
116
-
117
-
118
- test 'should return class name' do
119
- assert_equal 'Enrollment', rexport_model.name
120
- end
121
-
122
- private
123
-
124
- def rexport_model(model: Enrollment, path: nil)
125
- Rexport::RexportModel.new(model, path: path)
126
- end
127
-
128
- def data_field(name)
129
- rexport_model.rexport_fields[name]
130
- end
131
-
132
- def assert_fields_length(rexport: rexport_model, change: 1, &block)
133
- assert_difference('rexport.rexport_fields.length', change) do
134
- block.call(rexport)
135
- end
136
- end
137
- end
@@ -1,43 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TreeNodeTest < ActiveSupport::TestCase
4
- test 'should initialize with name' do
5
- t = Rexport::TreeNode.new('test')
6
- assert_equal 'test', t.name
7
- assert_equal [], t.children
8
- end
9
-
10
- test 'should initialize with name and children' do
11
- t = Rexport::TreeNode.new('test', %w(one two three))
12
- assert_equal 'test', t.name
13
- assert_equal ["test", [["one", [["two", [["three", []]]]]]]], t.to_a
14
- end
15
-
16
- test 'should add children' do
17
- root = Rexport::TreeNode.new('root')
18
- root.add_child('a')
19
- assert_equal ['root', [['a', []]]], root.to_a
20
- root.add_child('a')
21
- assert_equal ['root', [['a', []]]], root.to_a
22
- root.add_child('a', [1 , 2])
23
- assert_equal ['root', [['a', [[1, [[2, []]]]]]]], root.to_a
24
- end
25
-
26
- test 'should return empty include' do
27
- root = Rexport::TreeNode.new('root')
28
- assert_equal [], root.to_include
29
- end
30
-
31
- test 'should return single level array include' do
32
- root = Rexport::TreeNode.new('root')
33
- %w(a b c).each { |l| root.add_child(l) }
34
- assert_equal [:a, :b, :c], root.to_include
35
- end
36
-
37
- test 'should return nested hash include' do
38
- root = Rexport::TreeNode.new('root', %w(a b c))
39
- assert_equal [{a: [{b: [:c]}]}], root.to_include
40
- root.add_child 'b', 'one', 'two'
41
- assert_equal [{a: [{b: [:c]}]}, {b: [{one:[:two]}]}], root.to_include
42
- end
43
- end