useful_renderers 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/useful_renderers/csv_renderable.rb +7 -1
- data/lib/useful_renderers/version.rb +1 -1
- data/spec/lib/csv_renderable_spec.rb +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 052525cae9cdad31791505f22efa0f7691bdb478
|
4
|
+
data.tar.gz: f09e2434dfd4479b8fa5a4ac5235444d3bfe32e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063914d17ef64632809b6dbb112b815dd9c778414e2e6c47e3ca31f6b2444599b9ddc10c0d11470a2d36e388bfb01ccffbe87655f66b84b7fa84afc3fd7adfec
|
7
|
+
data.tar.gz: 7769766bc1df9221900ed860b30dfbfda07981b8c57e7b162fc515a1d0dea87ec8c6bc5663a29a7586f964ecc187ffb9daa8c587c645806eede178fb90439ee7
|
@@ -15,7 +15,13 @@ module UsefulRenderers
|
|
15
15
|
return join(',') unless klass.respond_to? :column_names
|
16
16
|
|
17
17
|
columns = klass.column_names
|
18
|
-
|
18
|
+
if options[:only]
|
19
|
+
columns = []
|
20
|
+
options[:only].each do |method|
|
21
|
+
columns << method.to_s if first.respond_to?(method)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
19
25
|
columns -= options[:except].map(&:to_s) if options[:except]
|
20
26
|
columns += options[:add_methods].map(&:to_s) if options[:add_methods]
|
21
27
|
|
@@ -44,12 +44,21 @@ describe UsefulRenderers::CsvRenderable do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
context 'options with :only param including methods' do
|
48
|
+
it 'returns only columns specified' do
|
49
|
+
options = { only: [:name, :human_age] }
|
50
|
+
|
51
|
+
expect(csv_renderable_array.to_csv(options))
|
52
|
+
.to eql "name,human_age\nO'Connor,25\nRuby,25\nShelby,33\n"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
47
56
|
context 'options with :exclude param' do
|
48
57
|
it 'excludes columns specified' do
|
49
58
|
options = { except: [:age] }
|
50
59
|
|
51
60
|
expect(csv_renderable_array.to_csv(options))
|
52
|
-
.to eql "id,name,weight\
|
61
|
+
.to eql "id,name,weight\n#{sebastian.id},O'Connor,76.8\n#{ruby.id},Ruby,68.2\n#{shelby.id},Shelby,64.0\n"
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
@@ -58,7 +67,7 @@ describe UsefulRenderers::CsvRenderable do
|
|
58
67
|
options = { add_methods: [:human_age] }
|
59
68
|
|
60
69
|
expect(csv_renderable_array.to_csv(options))
|
61
|
-
.to eql "id,name,age,weight,human_age\
|
70
|
+
.to eql "id,name,age,weight,human_age\n#{sebastian.id},O'Connor,3,76.8,25\n#{ruby.id},Ruby,3,68.2,25\n#{shelby.id},Shelby,5,64.0,33\n"
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
@@ -75,7 +84,7 @@ describe UsefulRenderers::CsvRenderable do
|
|
75
84
|
it 'translate header with human_attribute_name' do
|
76
85
|
options = { only: [:id, :name], translate: true }
|
77
86
|
expect(csv_renderable_array.to_csv(options))
|
78
|
-
.to eql "Id,Dog name\
|
87
|
+
.to eql "Id,Dog name\n#{sebastian.id},O'Connor\n#{ruby.id},Ruby\n#{shelby.id},Shelby\n"
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|