rexport 0.5.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.rdoc +1 -1
- data/Rakefile +6 -34
- data/app/views/export_filters/_export_filter.html.erb +2 -2
- data/app/views/export_items/_export_item.html.erb +4 -4
- data/app/views/exports/_edit.html.erb +2 -2
- data/app/views/exports/_filters.html.erb +1 -1
- data/app/views/exports/_form.html.erb +6 -6
- data/app/views/exports/_rexport_model.html.erb +1 -1
- data/app/views/exports/_show.html.erb +7 -7
- data/app/views/exports/edit.html.erb +1 -1
- data/app/views/exports/index.html.erb +5 -5
- data/app/views/exports/new.html.erb +2 -2
- data/app/views/exports/show.html.erb +1 -1
- data/config/routes.rb +6 -6
- data/db/migrate/20091105182959_create_export_tables.rb +3 -3
- data/lib/rexport.rb +3 -1
- data/lib/rexport/data_field.rb +17 -0
- data/lib/rexport/data_fields.rb +17 -133
- data/lib/rexport/export_filter_methods.rb +46 -24
- data/lib/rexport/export_filters_controller_methods.rb +8 -4
- data/lib/rexport/export_item_methods.rb +29 -34
- data/lib/rexport/export_items_controller_methods.rb +13 -13
- data/lib/rexport/export_methods.rb +160 -208
- data/lib/rexport/exports_controller_methods.rb +34 -35
- data/lib/rexport/rexport_model.rb +118 -0
- data/lib/rexport/tree_node.rb +13 -16
- data/lib/rexport/version.rb +1 -1
- data/test/factories.rb +58 -53
- data/test/test_helper.rb +36 -39
- data/test/unit/data_field_test.rb +11 -11
- data/test/unit/data_fields_test.rb +53 -95
- data/test/unit/export_filter_methods_test.rb +37 -0
- data/test/unit/export_item_methods_test.rb +21 -0
- data/test/unit/export_methods_test.rb +181 -59
- data/test/unit/rexport_model_test.rb +122 -20
- data/test/unit/tree_node_test.rb +20 -20
- metadata +25 -38
- data/test/jenkins.bash +0 -3
- data/test/log/test.log +0 -3891
@@ -1,25 +1,25 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DataFieldTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
assert_equal
|
4
|
+
test 'should stringify name' do
|
5
|
+
assert_equal 'foo', Rexport::DataField.new(:foo).name
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
assert_equal
|
8
|
+
test 'should use name for method' do
|
9
|
+
assert_equal 'foo', Rexport::DataField.new(:foo).method
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
assert_equal
|
12
|
+
test 'should save method' do
|
13
|
+
assert_equal 'bar', Rexport::DataField.new(:foo, method: :bar).method
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
assert_equal
|
16
|
+
test 'should save type' do
|
17
|
+
assert_equal :type_test, Rexport::DataField.new(:test, type: :type_test).type
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
test 'should_sort_data_fields' do
|
21
21
|
a = Rexport::DataField.new(:a)
|
22
22
|
b = Rexport::DataField.new(:b)
|
23
|
-
assert_equal
|
23
|
+
assert_equal [a,b], [b,a].sort
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
@@ -3,115 +3,73 @@ require 'test_helper'
|
|
3
3
|
class DataFieldsTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
class RexportClassMethodsTest < DataFieldsTest
|
6
|
-
|
7
|
-
|
8
|
-
assert_equal(%w(active bad_method created_at foo_method grade ilp_status_name status_name updated_at), Enrollment.rexport_fields.keys.sort)
|
9
|
-
assert_equal('grade', Enrollment.rexport_fields[:grade].method)
|
10
|
-
assert_equal('foo', Enrollment.rexport_fields[:foo_method].method)
|
11
|
-
assert_equal(:boolean, Enrollment.rexport_fields[:active].type)
|
12
|
-
assert_equal(:integer, Enrollment.rexport_fields[:grade].type)
|
6
|
+
test 'should get klass from assocations' do
|
7
|
+
assert_equal Family, Enrollment.get_klass_from_associations('student', 'family')
|
13
8
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Enrollment.
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_should_add_single_association_method_to_rexport_fields
|
21
|
-
assert_difference('Enrollment.rexport_fields.length') do
|
22
|
-
Enrollment.add_association_methods(:associations => 'test_association')
|
23
|
-
end
|
24
|
-
assert_equal('test_association_name', Enrollment.rexport_fields[:test_association_name].name)
|
25
|
-
assert_equal('test_association.name', Enrollment.rexport_fields[:test_association_name].method)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_add_name_methods_for_multiple_associations
|
29
|
-
assert_difference('Enrollment.rexport_fields.length', 3) do
|
30
|
-
Enrollment.add_association_methods(:associations => %w(a b c))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_add_multiple_methods_for_multiple_associations
|
35
|
-
assert_difference('Enrollment.rexport_fields.length', 9) do
|
36
|
-
Enrollment.add_association_methods(:associations => %w(a1 a2 a3), :methods => %w(m1 m2 m3))
|
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')
|
37
13
|
end
|
38
14
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_equal
|
44
|
-
assert_equal(%w(undefined_rexport_field), Enrollment.get_rexport_methods('student.bad_method'))
|
45
|
-
assert_equal(%w(student.name), Enrollment.get_rexport_methods('student.name'))
|
46
|
-
assert_equal(%w(student.family.foo), Enrollment.get_rexport_methods('student.family.foo_method'))
|
47
|
-
assert_equal(['student.family.foo', 'student.name', 'undefined_rexport_field', 'undefined_rexport_field', 'status.name', 'grade'],
|
48
|
-
Enrollment.get_rexport_methods('student.family.foo_method', 'student.name', 'student.bad_method', 'bad_association.test', 'status_name', 'grade'))
|
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')
|
49
20
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
assert(Enrollment.remove_rexport_fields(:grade))
|
54
|
-
assert_nil(Enrollment.rexport_fields[:grade])
|
21
|
+
|
22
|
+
test 'should export value returned from method' do
|
23
|
+
assert_equal %w(bar), build(:enrollment).export('foo')
|
55
24
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
fields.each {|field| assert(Enrollment.rexport_fields[field])}
|
60
|
-
assert(Enrollment.remove_rexport_fields(fields))
|
61
|
-
fields.each {|field| assert_nil(Enrollment.rexport_fields[field])}
|
25
|
+
|
26
|
+
test 'should return empty string for undefined method' do
|
27
|
+
assert_equal [''], build(:enrollment).export('bad_method')
|
62
28
|
end
|
63
|
-
|
64
|
-
|
65
|
-
assert_equal(
|
29
|
+
|
30
|
+
test 'should format date for export' do
|
31
|
+
assert_equal [Time.now.strftime("%m/%d/%y")], build(:enrollment).export('updated_at')
|
66
32
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
33
|
+
|
34
|
+
test 'should export Y for true' do
|
35
|
+
assert_equal %w(Y), Enrollment.new(active: true).export('active')
|
70
36
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
assert(Enrollment.instance_variable_get('@rexport_fields'))
|
75
|
-
Enrollment.reset_column_information
|
76
|
-
assert_nil(Enrollment.instance_variable_get('@rexport_fields'))
|
37
|
+
|
38
|
+
test 'should export N for false' do
|
39
|
+
assert_equal %w(N), Enrollment.new(active: false).export('active')
|
77
40
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
def test_should_export_fields_for_record
|
82
|
-
enrollment = FactoryGirl.create(:enrollment)
|
83
|
-
assert_equal(%w(1), enrollment.export('grade'))
|
84
|
-
assert_equal(%w(bar), enrollment.export('foo'))
|
85
|
-
assert_equal([''], enrollment.export('bad_method'))
|
86
|
-
assert_equal(%w(1 bar) << Date.today.strftime("%m/%d/%y"), enrollment.export('grade', 'foo', 'updated_at'))
|
41
|
+
|
42
|
+
test 'should handle missing associations' do
|
43
|
+
assert_equal [''], Enrollment.new.export('status.name')
|
87
44
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
assert_equal([''], enrollment.export('status.name'))
|
92
|
-
assert_equal([''], enrollment.export('student.name'))
|
45
|
+
|
46
|
+
test 'should handle undefined export field' do
|
47
|
+
assert_equal ['UNDEFINED EXPORT FIELD'], Enrollment.new.export('undefined_rexport_field')
|
93
48
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
assert_equal(['UNDEFINED EXPORT FIELD'], enrollment.export('undefined_rexport_field'))
|
49
|
+
|
50
|
+
test 'should export value of associated data attribute' do
|
51
|
+
assert_equal ['The Sample Family'], build(:enrollment).export('student.family.name')
|
98
52
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
assert_equal(['Sammy Sample'], enrollment.export('student.name'))
|
103
|
-
assert_equal(['The Sample Family'], enrollment.export('student.family.name'))
|
104
|
-
assert_equal(%w(bar), enrollment.export('student.family.foo'))
|
53
|
+
|
54
|
+
test 'should export value returned from associated method' do
|
55
|
+
assert_equal %w(bar), build(:enrollment).export('student.family.foo')
|
105
56
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
assert_equal(['active'], enrollment.export('status.name'))
|
57
|
+
|
58
|
+
test 'should export field from non rexported model' do
|
59
|
+
assert_equal %w(active), build(:enrollment).export('status.name')
|
110
60
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
+
)
|
115
73
|
end
|
116
74
|
end
|
117
75
|
end
|
@@ -0,0 +1,37 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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,97 +1,219 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ExportMethodsTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
assert_equal(['Family Name', 'Grade', 'Status', 'Bogus Item'], export.header)
|
4
|
+
test 'should return models' do
|
5
|
+
assert Export.models
|
7
6
|
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
assert_equal(%w(student.family.name grade status_name bogus_field), export.send(:rexport_fields))
|
8
|
+
test 'should return full name' do
|
9
|
+
assert_equal 'Enrollments - Enrollment Export', build(:export).full_name
|
12
10
|
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
assert_equal(%w(student.family.name grade status.name undefined_rexport_field), export.send(:rexport_methods))
|
12
|
+
test 'should return header' do
|
13
|
+
assert_equal ['Family Name', 'Grade', 'Status', 'Bogus Item'], create(:export).header
|
17
14
|
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
+
)
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
assert_equal(2, Enrollment.count)
|
31
|
-
assert_equal(2, export.records.length)
|
32
|
-
assert_equal(['The Sample Family', '1', 'active', 'UNDEFINED EXPORT FIELD'], filtered_export.records.first)
|
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
|
+
)
|
33
28
|
end
|
34
29
|
|
35
|
-
|
36
|
-
|
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 call get_records' do
|
46
|
+
export = build(:export)
|
37
47
|
export.expects(:get_records).with(Rexport::SAMPLE_SIZE).returns(true)
|
38
|
-
assert
|
48
|
+
assert export.sample_records
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'should return to_s with no records' do
|
52
|
+
assert_equal "Family Name|Grade|Status|Bogus Item\n", create(:export).to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'should return to_s with record' do
|
56
|
+
create(:enrollment)
|
57
|
+
assert_equal(
|
58
|
+
"Family Name|Grade|Status|Bogus Item\nThe Sample Family|1|active|UNDEFINED EXPORT FIELD\n",
|
59
|
+
create(:export).to_s
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'should return to_csv with no records' do
|
64
|
+
assert_equal "Family Name,Grade,Status,Bogus Item\n", create(:export).to_csv
|
39
65
|
end
|
40
66
|
|
41
|
-
|
42
|
-
|
43
|
-
assert_equal(
|
67
|
+
test 'should return to_csv with record' do
|
68
|
+
FactoryBot.create(:enrollment)
|
69
|
+
assert_equal(
|
70
|
+
"Family Name,Grade,Status,Bogus Item\nThe Sample Family,1,active,UNDEFINED EXPORT FIELD\n",
|
71
|
+
create(:export).to_csv
|
72
|
+
)
|
44
73
|
end
|
45
74
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
75
|
+
test 'should return to_csv with passed objects' do
|
76
|
+
assert_equal(
|
77
|
+
"Family Name,Grade,Status,Bogus Item\n\"\",99,\"\",UNDEFINED EXPORT FIELD\n",
|
78
|
+
create(:export).to_csv([Enrollment.new(grade: 99)])
|
79
|
+
)
|
50
80
|
end
|
51
81
|
|
52
|
-
|
53
|
-
|
54
|
-
|
82
|
+
test 'should return build_conditions' do
|
83
|
+
assert_equal(
|
84
|
+
{'statuses.name' => 'active', 'enrollments.grade' => '1'},
|
85
|
+
create(:filtered_export).send(:build_conditions)
|
86
|
+
)
|
55
87
|
end
|
56
88
|
|
57
|
-
|
58
|
-
|
59
|
-
enrollment = FactoryGirl.create(:enrollment)
|
60
|
-
assert_equal("Family Name,Grade,Status,Bogus Item\nThe Sample Family,1,active,UNDEFINED EXPORT FIELD\n", export.to_csv)
|
89
|
+
test 'should return build_include' do
|
90
|
+
assert_equal [{student: [:family]}, :status], create(:export).send(:build_include)
|
61
91
|
end
|
62
92
|
|
63
|
-
|
64
|
-
export =
|
65
|
-
assert_equal(
|
93
|
+
test 'should return rexport_models' do
|
94
|
+
export = create(:export)
|
95
|
+
assert_equal(
|
96
|
+
%w(Enrollment Family SelfReferentialCheck Student),
|
97
|
+
export.rexport_models.map(&:name).sort
|
98
|
+
)
|
99
|
+
assert_equal(
|
100
|
+
['', 'self_referential_check', 'student', 'student.family'],
|
101
|
+
export.rexport_models.map(&:path).map(&:to_s).sort
|
102
|
+
)
|
66
103
|
end
|
67
104
|
|
68
|
-
|
69
|
-
|
70
|
-
assert_equal({'statuses.name' => 'active', 'enrollments.grade' => '1'}, export.send(:build_conditions))
|
105
|
+
test 'should return true for has_rexport_field?' do
|
106
|
+
assert build(:export).has_rexport_field?('student.family.name')
|
71
107
|
end
|
72
108
|
|
73
|
-
|
74
|
-
|
75
|
-
assert_equal([{:student=>[:family]}, :status], export.send(:build_include))
|
109
|
+
test 'should return false for has_rexport_field?' do
|
110
|
+
refute build(:export).has_rexport_field?('student.family.number')
|
76
111
|
end
|
77
112
|
|
78
|
-
|
79
|
-
|
80
|
-
assert_equal(%w(Enrollment Family SelfReferentialCheck Student), export.rexport_models.map {|m| m.klass.to_s}.sort)
|
81
|
-
assert_equal(['', 'self_referential_check', 'student', 'student.family'], export.rexport_models.map {|m| m.path.to_s}.sort)
|
113
|
+
test 'should save export_items from a hash' do
|
114
|
+
assert_equal %w(a b c), rexport_fields_for(create_export(fields: {a: 1, b: 1, c: 1}))
|
82
115
|
end
|
83
116
|
|
84
|
-
|
85
|
-
assert_equal
|
86
|
-
assert_equal 'Enrollment Export Copy [1]', FactoryGirl.create(:export).copy.name
|
87
|
-
assert_equal 'Enrollment Export Copy [2]', FactoryGirl.create(:export).copy.name
|
117
|
+
test 'should save export_items from an array' do
|
118
|
+
assert_equal %w(a b c), rexport_fields_for(create_export(fields: %w(a b c)))
|
88
119
|
end
|
89
120
|
|
90
|
-
|
91
|
-
|
121
|
+
test 'should add export_item to exising export on update' do
|
122
|
+
export = create_export(fields: %w(a c))
|
123
|
+
assert_difference 'ExportItem.count' do
|
124
|
+
export.update_attribute(:rexport_fields, %w(a b c))
|
125
|
+
end
|
126
|
+
assert_equal %w(a b c), rexport_fields_for(export)
|
127
|
+
end
|
128
|
+
|
129
|
+
test 'should delete export_item that is not in rexport_fields on update' do
|
130
|
+
export = create_export(fields: %w(a b c))
|
131
|
+
assert_difference 'ExportItem.count', -1 do
|
132
|
+
export.update_attribute(:rexport_fields, %w(a c))
|
133
|
+
end
|
134
|
+
assert_equal %w(a c), rexport_fields_for(export)
|
135
|
+
end
|
136
|
+
|
137
|
+
test 'should re-order export_items when passed an array of export_fields on update' do
|
138
|
+
export = create_export(fields: %w(a b c))
|
139
|
+
export.update_attribute(:rexport_fields, %w(c b a))
|
140
|
+
assert_equal %w(c b a), rexport_fields_for(export)
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'should not re-order export_items when passed a hash of export_fields on update' do
|
144
|
+
export = create_export(fields: %w(a b c))
|
145
|
+
export.update_attribute(:rexport_fields, {c: 1, b: 1, a: 1})
|
146
|
+
assert_equal %w(a b c), rexport_fields_for(export)
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'should not modify export_items on update when no export_fields are passed' do
|
150
|
+
export = create_export(fields: %w(a b c))
|
151
|
+
assert_no_difference 'ExportItem.count' do
|
152
|
+
export.update_attribute(:name, 'New Name')
|
153
|
+
end
|
154
|
+
assert_equal %w(a b c), rexport_fields_for(export)
|
155
|
+
end
|
156
|
+
|
157
|
+
test 'should create export with an export_filter' do
|
158
|
+
assert_difference 'ExportFilter.count' do
|
159
|
+
create_export(filters: {status_id: 1})
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
test 'should add an export_filter to an existing export' do
|
164
|
+
export = create_export
|
165
|
+
assert_difference 'ExportFilter.count' do
|
166
|
+
export.update_attribute(:export_filter_attributes, {status_id: 1})
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
test 'should delete an export_filter from an export' do
|
171
|
+
export = create_export(filters: {status_id: 1})
|
172
|
+
assert_difference 'ExportFilter.count', -1 do
|
173
|
+
export.update_attribute(:export_filter_attributes, {status_id: ''})
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
test 'should return filter_value for filter_field' do
|
178
|
+
assert_equal 'active', create(:filtered_export).filter_value('status.name')
|
179
|
+
end
|
180
|
+
|
181
|
+
test 'should return nil for filter_value when no matching export_filters' do
|
182
|
+
assert_nil create(:filtered_export).filter_value('does_not_exist')
|
183
|
+
end
|
184
|
+
|
185
|
+
test 'should create copy with unique name' do
|
186
|
+
assert_equal 'Enrollment Export Copy', create(:export).copy.name
|
187
|
+
assert_equal 'Enrollment Export Copy [1]', create(:export).copy.name
|
188
|
+
assert_equal 'Enrollment Export Copy [2]', create(:export).copy.name
|
189
|
+
end
|
190
|
+
|
191
|
+
test 'should copy export with export_items' do
|
192
|
+
export = create(:export)
|
193
|
+
assert_difference 'ExportItem.count', export.export_items.count do
|
194
|
+
export.copy.export_items.count
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
test 'should copy export with export_filters' do
|
199
|
+
export = create(:filtered_export)
|
200
|
+
assert_difference 'ExportFilter.count', export.export_filters.count do
|
201
|
+
export.copy
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
def create_export(fields: {}, filters: {})
|
208
|
+
Export.create(
|
209
|
+
name: 'Test',
|
210
|
+
model_class_name: 'Enrollment',
|
211
|
+
rexport_fields: fields,
|
212
|
+
export_filter_attributes: filters
|
213
|
+
)
|
92
214
|
end
|
93
215
|
|
94
|
-
def
|
95
|
-
|
216
|
+
def rexport_fields_for(export)
|
217
|
+
export.export_items.ordered.map(&:rexport_field)
|
96
218
|
end
|
97
219
|
end
|