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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63c4b461671436a8635c0dcb32cf225d0e348ce6
4
- data.tar.gz: 8372d535dd0b4a04a083d2c7fc9cb326d436f039
3
+ metadata.gz: 052525cae9cdad31791505f22efa0f7691bdb478
4
+ data.tar.gz: f09e2434dfd4479b8fa5a4ac5235444d3bfe32e3
5
5
  SHA512:
6
- metadata.gz: 2c5d3fd4049896dc2309faf428467de4486dd9e8c190f71d16bab39a5bc7f5b6483d213f05357e3a3d3dbfdb8155b0d8f3c60b9e696c9fb63c251eee104c7981
7
- data.tar.gz: 36bd0e1b55359baf50e907a6eba4f4d846c0c4d6edfad8360fa6e604e268181263014c473d4be760a8d77ee9c81a708ec7d3d015308ec3e42f31b199452ef42c
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
- columns &= options[:only].map(&:to_s) if options[:only]
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
 
@@ -1,3 +1,3 @@
1
1
  module UsefulRenderers
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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\n7,O'Connor,76.8\n8,Ruby,68.2\n9,Shelby,64.0\n"
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\n10,O'Connor,3,76.8,25\n11,Ruby,3,68.2,25\n12,Shelby,5,64.0,33\n"
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\n16,O'Connor\n17,Ruby\n18,Shelby\n"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useful_renderers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondrej Bartas