rexport 0.5.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +6 -34
- data/app/views/export_filters/_export_filter.html.erb +2 -2
- data/app/views/export_items/_export_item.html.erb +2 -2
- 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 +6 -6
- 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 +25 -56
- data/lib/rexport/export_filter_methods.rb +46 -24
- data/lib/rexport/export_item_methods.rb +29 -34
- data/lib/rexport/export_methods.rb +161 -208
- data/lib/rexport/exports_controller_methods.rb +22 -28
- data/lib/rexport/rexport_model.rb +33 -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 +29 -33
- data/test/unit/data_field_test.rb +11 -11
- data/test/unit/data_fields_test.rb +137 -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 +185 -59
- data/test/unit/rexport_model_test.rb +12 -12
- data/test/unit/tree_node_test.rb +20 -20
- metadata +14 -26
- 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,157 @@ require 'test_helper'
|
|
3
3
|
class DataFieldsTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
class RexportClassMethodsTest < DataFieldsTest
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
test 'should initialize local rexport fields' do
|
7
|
+
assert_equal(
|
8
|
+
%w(active bad_method created_at foo_method grade ilp_status_name status_name updated_at),
|
9
|
+
Enrollment.rexport_fields.keys.sort
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'should initialize data atributes' do
|
14
|
+
assert_equal 'grade', Enrollment.rexport_fields[:grade].method
|
15
|
+
assert_equal :integer, Enrollment.rexport_fields[:grade].type
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'should initialize method' do
|
19
|
+
assert_equal 'foo', Enrollment.rexport_fields[:foo_method].method
|
20
|
+
assert_nil Enrollment.rexport_fields[:foo_method].type
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should return sorted data fields array' do
|
24
|
+
assert_equal(
|
25
|
+
%w(active bad_method created_at foo_method grade ilp_status_name status_name updated_at),
|
26
|
+
Enrollment.rexport_fields_array.map(&:name)
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'should add single association method to rexport_fields' do
|
21
31
|
assert_difference('Enrollment.rexport_fields.length') do
|
22
|
-
Enrollment.add_association_methods(:
|
32
|
+
Enrollment.add_association_methods(associations: 'test_association')
|
23
33
|
end
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
34
|
+
assert_equal 'test_association_name', Enrollment.rexport_fields[:test_association_name].name
|
35
|
+
assert_equal 'test_association.name', Enrollment.rexport_fields[:test_association_name].method
|
26
36
|
end
|
27
|
-
|
28
|
-
|
37
|
+
|
38
|
+
test 'should add name methods for multiple associations' do
|
29
39
|
assert_difference('Enrollment.rexport_fields.length', 3) do
|
30
|
-
Enrollment.add_association_methods(:
|
40
|
+
Enrollment.add_association_methods(associations: %w(a b c))
|
31
41
|
end
|
32
42
|
end
|
33
|
-
|
34
|
-
|
43
|
+
|
44
|
+
test 'should add multiple methods for multiple associations' do
|
35
45
|
assert_difference('Enrollment.rexport_fields.length', 9) do
|
36
|
-
Enrollment.add_association_methods(:
|
46
|
+
Enrollment.add_association_methods(associations: %w(a1 a2 a3), methods: %w(m1 m2 m3))
|
37
47
|
end
|
38
48
|
end
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
|
50
|
+
test 'should get rexport methods' do
|
51
|
+
assert_equal(
|
52
|
+
['student.family.foo',
|
53
|
+
'student.name',
|
54
|
+
'undefined_rexport_field',
|
55
|
+
'undefined_rexport_field',
|
56
|
+
'status.name',
|
57
|
+
'grade'
|
58
|
+
],
|
59
|
+
Enrollment.get_rexport_methods(
|
60
|
+
'student.family.foo_method',
|
61
|
+
'student.name',
|
62
|
+
'student.bad_method',
|
63
|
+
'bad_association.test',
|
64
|
+
'status_name',
|
65
|
+
'grade'
|
66
|
+
)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'should remove single rexport field' do
|
71
|
+
assert Enrollment.rexport_fields[:grade]
|
72
|
+
assert Enrollment.remove_rexport_fields(:grade)
|
73
|
+
assert_nil Enrollment.rexport_fields[:grade]
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'should remove multiple rexport fields' do
|
58
77
|
fields = %w(grade status_name foo_method)
|
59
|
-
fields.each {|field| assert(Enrollment.rexport_fields[field])}
|
60
|
-
assert
|
61
|
-
fields.each {|field| assert_nil(Enrollment.rexport_fields[field])}
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
assert_equal
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
assert_raise
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
78
|
+
fields.each { |field| assert(Enrollment.rexport_fields[field]) }
|
79
|
+
assert Enrollment.remove_rexport_fields(fields)
|
80
|
+
fields.each { |field| assert_nil(Enrollment.rexport_fields[field]) }
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'should get klass from assocations' do
|
84
|
+
assert_equal Family, Enrollment.get_klass_from_associations('student', 'family')
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'should raise no method error for missing associations' do
|
88
|
+
assert_raise NoMethodError do
|
89
|
+
Enrollment.get_klass_from_associations('not_an_association')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
test 'should reset column information with rexport_reset' do
|
94
|
+
Enrollment.expects(:initialize_rexport_fields).times(2).returns(true)
|
95
|
+
assert Enrollment.rexport_fields
|
75
96
|
Enrollment.reset_column_information
|
76
|
-
|
97
|
+
assert Enrollment.rexport_fields
|
77
98
|
end
|
78
99
|
end
|
79
|
-
|
100
|
+
|
80
101
|
class RexportInstanceMethodsTest < DataFieldsTest
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
assert_equal
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
assert_equal(
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
assert_equal
|
102
|
+
test 'should exoport value of data attribute' do
|
103
|
+
assert_equal %w(1), build(:enrollment).export('grade')
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'should export value returned from method' do
|
107
|
+
assert_equal %w(bar), build(:enrollment).export('foo')
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'should return empty string for undefined method' do
|
111
|
+
assert_equal [''], build(:enrollment).export('bad_method')
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'should format date for export' do
|
115
|
+
assert_equal [Time.now.strftime("%m/%d/%y")], build(:enrollment).export('updated_at')
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'should export Y for true' do
|
119
|
+
assert_equal %w(Y), Enrollment.new(active: true).export('active')
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'should export N for false' do
|
123
|
+
assert_equal %w(N), Enrollment.new(active: false).export('active')
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'should handle missing associations' do
|
127
|
+
assert_equal [''], Enrollment.new.export('status.name')
|
128
|
+
end
|
129
|
+
|
130
|
+
test 'should handle undefined export field' do
|
131
|
+
assert_equal ['UNDEFINED EXPORT FIELD'], Enrollment.new.export('undefined_rexport_field')
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'should export value of associated data attribute' do
|
135
|
+
assert_equal ['The Sample Family'], build(:enrollment).export('student.family.name')
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'should export value returned from associated method' do
|
139
|
+
assert_equal %w(bar), build(:enrollment).export('student.family.foo')
|
140
|
+
end
|
141
|
+
|
142
|
+
test 'should export field from non rexported model' do
|
143
|
+
assert_equal %w(active), build(:enrollment).export('status.name')
|
144
|
+
end
|
145
|
+
|
146
|
+
test 'should export local, associated, and non rexported fields in order' do
|
147
|
+
assert_equal(
|
148
|
+
['The Sample Family', 'Sammy Sample', '1', 'bar', 'active'],
|
149
|
+
build(:enrollment).export(
|
150
|
+
'student.family.name',
|
151
|
+
'student.name',
|
152
|
+
'grade',
|
153
|
+
'student.family.foo',
|
154
|
+
'status.name'
|
155
|
+
)
|
156
|
+
)
|
115
157
|
end
|
116
158
|
end
|
117
159
|
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,223 @@
|
|
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
|
65
|
+
end
|
66
|
+
|
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
|
+
)
|
73
|
+
end
|
74
|
+
|
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
|
+
)
|
80
|
+
end
|
81
|
+
|
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
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'should return build_include' do
|
90
|
+
assert_equal [{student: [:family]}, :status], create(:export).send(:build_include)
|
91
|
+
end
|
92
|
+
|
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
|
+
)
|
39
103
|
end
|
40
104
|
|
41
|
-
|
42
|
-
|
43
|
-
assert_equal("Family Name|Grade|Status|Bogus Item\n", export.to_s)
|
105
|
+
test 'should return true for has_rexport_field?' do
|
106
|
+
assert build(:export).has_rexport_field?('student.family.name')
|
44
107
|
end
|
45
108
|
|
46
|
-
|
47
|
-
|
48
|
-
enrollment = FactoryGirl.create(:enrollment)
|
49
|
-
assert_equal("Family Name|Grade|Status|Bogus Item\nThe Sample Family|1|active|UNDEFINED EXPORT FIELD\n", export.to_s)
|
109
|
+
test 'should return false for has_rexport_field?' do
|
110
|
+
refute build(:export).has_rexport_field?('student.family.number')
|
50
111
|
end
|
51
112
|
|
52
|
-
|
53
|
-
|
54
|
-
assert_equal("Family Name,Grade,Status,Bogus Item\n", export.to_csv)
|
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}))
|
55
115
|
end
|
56
116
|
|
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)
|
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)))
|
61
119
|
end
|
62
120
|
|
63
|
-
|
64
|
-
export =
|
65
|
-
|
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)
|
66
127
|
end
|
67
128
|
|
68
|
-
|
69
|
-
export =
|
70
|
-
|
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)
|
71
135
|
end
|
72
136
|
|
73
|
-
|
74
|
-
export =
|
75
|
-
|
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)
|
76
141
|
end
|
77
142
|
|
78
|
-
|
79
|
-
export =
|
80
|
-
|
81
|
-
assert_equal(
|
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)
|
82
147
|
end
|
83
148
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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)
|
88
155
|
end
|
89
156
|
|
90
|
-
|
91
|
-
|
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
|
+
test 'should return true for modifiable?' do
|
206
|
+
assert Export.new.modifiable?
|
207
|
+
end
|
208
|
+
|
209
|
+
private
|
210
|
+
|
211
|
+
def create_export(fields: {}, filters: {})
|
212
|
+
Export.create(
|
213
|
+
name: 'Test',
|
214
|
+
model_class_name: 'Enrollment',
|
215
|
+
rexport_fields: fields,
|
216
|
+
export_filter_attributes: filters
|
217
|
+
)
|
92
218
|
end
|
93
219
|
|
94
|
-
def
|
95
|
-
|
220
|
+
def rexport_fields_for(export)
|
221
|
+
export.export_items.ordered.map(&:rexport_field)
|
96
222
|
end
|
97
223
|
end
|