active_model_exporters 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/active_model/array_exporter.rb +7 -2
- data/lib/active_model/exporter/version.rb +1 -1
- data/lib/active_model/exporter.rb +2 -2
- data/test/integration/action_controller/exportation/csv_test.rb +12 -6
- data/test/integration/action_controller/exportation/xls_test.rb +12 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d96a573783d5a7e984d87ec08a3523e6c6586467
|
4
|
+
data.tar.gz: 986d9649720710ddc899a677027320c8abd6439c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf08a457378d5be9bf935a7c5d835e2db9c7225a707e6ba2a5f18204a36d63435b56db6b43b0a8928f2607627406d9015990330f07e5e21fb6b52dca2258c54f
|
7
|
+
data.tar.gz: cb268b269f89014522ea46e2105e84c2cda424b2d5eadecb2f907b52e6c8c7cb285f2e21231543980cea8f916ce02ba9b6cd47cc96c507c4ffb4ead272c1b89b
|
data/CHANGELOG.md
CHANGED
@@ -16,19 +16,24 @@ module ActiveModel
|
|
16
16
|
generate_file(col_sep: "\t")
|
17
17
|
end
|
18
18
|
|
19
|
+
private
|
20
|
+
|
19
21
|
def generate_file(options = {})
|
20
22
|
CSV.generate(options) do |file|
|
23
|
+
file << headers
|
21
24
|
collection.each do |object|
|
22
25
|
file << exporter_for(object).values
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
private
|
28
|
-
|
29
30
|
def exporter_for(object)
|
30
31
|
exporter_class = exporter || Exporter.exporter_for(object)
|
31
32
|
exporter_class.new(object, scope: scope)
|
32
33
|
end
|
34
|
+
|
35
|
+
def headers
|
36
|
+
exporter_for(collection.first).class._attributes
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
@@ -18,7 +18,8 @@ module ActionController
|
|
18
18
|
def test_render_using_implicit_exporter
|
19
19
|
get :render_using_implicit_exporter
|
20
20
|
assert_equal 'text/csv', @response.content_type
|
21
|
-
assert_equal "
|
21
|
+
assert_equal "first_name,last_name,full_name\n"\
|
22
|
+
"Foo1,Bar1,Foo1-Bar1\n"\
|
22
23
|
"Foo2,Bar2,Foo2-Bar2\n"\
|
23
24
|
"Foo3,Bar3,Foo3-Bar3\n", @response.body
|
24
25
|
end
|
@@ -38,7 +39,8 @@ module ActionController
|
|
38
39
|
def test_render_using_explicit_exporter
|
39
40
|
get :render_using_explicit_exporter
|
40
41
|
assert_equal 'text/csv', @response.content_type
|
41
|
-
assert_equal "
|
42
|
+
assert_equal "first_name,last_name\n"\
|
43
|
+
"Foo1,Bar1\n", @response.body
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -62,7 +64,8 @@ module ActionController
|
|
62
64
|
def test_render_using_implicit_exportation_scope
|
63
65
|
get :render_using_implicit_exportation_scope
|
64
66
|
assert_equal 'text/csv', @response.content_type
|
65
|
-
assert_equal "
|
67
|
+
assert_equal "first_name,last_name,full_name\n"\
|
68
|
+
"Foo1,Bar1,Foo1-Bar1-current_user\n", @response.body
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
@@ -86,7 +89,8 @@ module ActionController
|
|
86
89
|
def test_render_using_explicit_exportation_scope
|
87
90
|
get :render_using_explicit_exportation_scope
|
88
91
|
assert_equal 'text/csv', @response.content_type
|
89
|
-
assert_equal "
|
92
|
+
assert_equal "first_name,last_name,full_name\n"\
|
93
|
+
"Foo1,Bar1,Foo1-Bar1-current_admin\n", @response.body
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
@@ -112,7 +116,8 @@ module ActionController
|
|
112
116
|
def test_render_calling_exportation_scope
|
113
117
|
get :render_calling_exportation_scope
|
114
118
|
assert_equal 'text/csv', @response.content_type
|
115
|
-
assert_equal "
|
119
|
+
assert_equal "first_name,last_name,full_name\n"\
|
120
|
+
"Foo1,Bar1,Foo1-Bar1-current_admin\n", @response.body
|
116
121
|
end
|
117
122
|
end
|
118
123
|
|
@@ -131,7 +136,8 @@ module ActionController
|
|
131
136
|
def test_render_using_filter_attributes
|
132
137
|
get :render_using_filter_attributes
|
133
138
|
assert_equal 'text/csv', @response.content_type
|
134
|
-
assert_equal "
|
139
|
+
assert_equal "first_name,last_name,email\n"\
|
140
|
+
"Foo1,,FooBar1\n"\
|
135
141
|
"Foo2,Bar2,FooBar2\n", @response.body
|
136
142
|
end
|
137
143
|
end
|
@@ -18,7 +18,8 @@ module ActionController
|
|
18
18
|
def test_render_using_implicit_exporter
|
19
19
|
get :render_using_implicit_exporter
|
20
20
|
assert_equal 'application/vnd.ms-excel', @response.content_type
|
21
|
-
assert_equal "
|
21
|
+
assert_equal "first_name\tlast_name\tfull_name\n"\
|
22
|
+
"Foo1\tBar1\tFoo1-Bar1\n"\
|
22
23
|
"Foo2\tBar2\tFoo2-Bar2\n"\
|
23
24
|
"Foo3\tBar3\tFoo3-Bar3\n", @response.body
|
24
25
|
end
|
@@ -38,7 +39,8 @@ module ActionController
|
|
38
39
|
def test_render_using_explicit_exporter
|
39
40
|
get :render_using_explicit_exporter
|
40
41
|
assert_equal 'application/vnd.ms-excel', @response.content_type
|
41
|
-
assert_equal "
|
42
|
+
assert_equal "first_name\tlast_name\n"\
|
43
|
+
"Foo1\tBar1\n", @response.body
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -62,7 +64,8 @@ module ActionController
|
|
62
64
|
def test_render_using_implicit_exportation_scope
|
63
65
|
get :render_using_implicit_exportation_scope
|
64
66
|
assert_equal 'application/vnd.ms-excel', @response.content_type
|
65
|
-
assert_equal "
|
67
|
+
assert_equal "first_name\tlast_name\tfull_name\n"\
|
68
|
+
"Foo1\tBar1\tFoo1-Bar1-current_user\n", @response.body
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
@@ -86,7 +89,8 @@ module ActionController
|
|
86
89
|
def test_render_using_explicit_exportation_scope
|
87
90
|
get :render_using_explicit_exportation_scope
|
88
91
|
assert_equal 'application/vnd.ms-excel', @response.content_type
|
89
|
-
assert_equal "
|
92
|
+
assert_equal "first_name\tlast_name\tfull_name\n"\
|
93
|
+
"Foo1\tBar1\tFoo1-Bar1-current_admin\n", @response.body
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
@@ -112,7 +116,8 @@ module ActionController
|
|
112
116
|
def test_render_calling_exportation_scope
|
113
117
|
get :render_calling_exportation_scope
|
114
118
|
assert_equal 'application/vnd.ms-excel', @response.content_type
|
115
|
-
assert_equal "
|
119
|
+
assert_equal "first_name\tlast_name\tfull_name\n"\
|
120
|
+
"Foo1\tBar1\tFoo1-Bar1-current_admin\n", @response.body
|
116
121
|
end
|
117
122
|
end
|
118
123
|
|
@@ -131,7 +136,8 @@ module ActionController
|
|
131
136
|
def test_render_using_filter_attributes
|
132
137
|
get :render_using_filter_attributes
|
133
138
|
assert_equal 'application/vnd.ms-excel', @response.content_type
|
134
|
-
assert_equal "
|
139
|
+
assert_equal "first_name\tlast_name\temail\n"\
|
140
|
+
"Foo1\t\tFooBar1\n"\
|
135
141
|
"Foo2\tBar2\tFooBar2\n", @response.body
|
136
142
|
end
|
137
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_exporters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Gutiérrez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|