active_model_exporters 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de64ab4416cd19830189c30e906b6bebcdb179f3
4
- data.tar.gz: 09dac821e09307d75437b346e481650a377b91a8
3
+ metadata.gz: e8b417030570553ee3ca6ad88db5394ac3873cce
4
+ data.tar.gz: 0ad3fc8b4af6103c65bc892d9e10c14f2e4dc57a
5
5
  SHA512:
6
- metadata.gz: 76b4aea4ea9157015692f82c96b0aad308a1f9eb266e59b1bca49400f2f9b025c531b86519aa86c9a7c8a323055ca578f9a551346ee007ca60ba9163dd95e7ae
7
- data.tar.gz: 22848f836d10be77d0dd0e0c935d32c0eb67dcb66c10fe3c1e9857f01fad41f34fc306936db05357ce2d3bac161ebad727b82de4d8c1941665819ec05e3036ec
6
+ metadata.gz: 21ffb2988853f6d945f6d7522b78953ef4374d7d86ca2cb5f3c53e1819fa9c00187645970598aadf3f17ec2152882a83ebd617a3709e6f4dcf7eb2fa84fc4ce6
7
+ data.tar.gz: a55b6da7b9b0546af1e7214ff2d8fe1c44c621e139c22924790d408b31da08389f48e45036699da6f2caf2fb87e2db3ec85eb0859f2f426f9f73da635b3d2c50
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### Version 0.3.2
4
+ * Adding support to export a single resource.
5
+
6
+ ### Version 0.3.1
7
+ * Fixing errors with rails 4.2+.
8
+
9
+ ### Version 0.3.0
10
+ * Adding support to rails 4.2+.
11
+
3
12
  ### Version 0.2.0
4
13
  * Using I18n translations in file headers.
5
14
 
@@ -30,7 +30,7 @@ module ActionController
30
30
  end
31
31
 
32
32
  def build_exporter(resource, options)
33
- if exporter = ActiveModel::Exporter.exporter_for(resource)
33
+ if exporter = ActiveModel::ArrayExporter
34
34
  options[:scope] ||= exportation_scope
35
35
  exporter.new(resource, options)
36
36
  end
@@ -3,7 +3,7 @@ module ActiveModel
3
3
  attr_reader :collection, :exporter, :scope
4
4
 
5
5
  def initialize(collection, options = {})
6
- @collection = collection
6
+ @collection = Array(collection)
7
7
  @scope = options.delete(:scope)
8
8
  @exporter = options.delete(:exporter)
9
9
  end
@@ -34,7 +34,7 @@ module ActiveModel
34
34
 
35
35
  def headers
36
36
  object = collection.first
37
- attributes = exporter_for(object).class._attributes.dup
37
+ attributes = exporter_for(object).attributes
38
38
 
39
39
  if object.class.respond_to?(:human_attribute_name)
40
40
  attributes.map { |attr| object.class.human_attribute_name(attr) }
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Exporter
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
@@ -18,16 +18,12 @@ module ActiveModel
18
18
  end
19
19
 
20
20
  def exporter_for(resource)
21
- if resource.respond_to?(:to_ary)
22
- ArrayExporter
23
- else
24
- "#{resource.class.name}Exporter".safe_constantize
25
- end
21
+ "#{resource.class.name}Exporter".safe_constantize
26
22
  end
27
23
  end
28
24
 
29
25
 
30
- attr_accessor :object, :scope
26
+ attr_reader :object, :scope
31
27
 
32
28
  def initialize(object, options = {})
33
29
  @object = object
@@ -39,8 +35,6 @@ module ActiveModel
39
35
  attributes.map { |attr| send(attr) if attrs.include?(attr) }
40
36
  end
41
37
 
42
- private
43
-
44
38
  def filter(attrs)
45
39
  attrs
46
40
  end
@@ -141,5 +141,22 @@ module ActionController
141
141
  "Foo2,Bar2,FooBar2\n", @response.body
142
142
  end
143
143
  end
144
+
145
+ class ExporterSingleResourceTest < ActionController::TestCase
146
+ class TestsController < ActionController::Base
147
+ def render_single_resource
148
+ render csv: User.new(first_name: 'Foo1', last_name: 'Bar1')
149
+ end
150
+ end
151
+
152
+ tests TestsController
153
+
154
+ def test_render_single_resource
155
+ get :render_single_resource
156
+ assert_equal 'text/csv', @response.content_type
157
+ assert_equal "first_name,last_name,full_name\n"\
158
+ "Foo1,Bar1,Foo1-Bar1\n", @response.body
159
+ end
160
+ end
144
161
  end
145
162
  end
@@ -141,5 +141,22 @@ module ActionController
141
141
  "Foo2\tBar2\tFooBar2\n", @response.body
142
142
  end
143
143
  end
144
+
145
+ class ExporterSingleResourceTest < ActionController::TestCase
146
+ class TestsController < ActionController::Base
147
+ def render_single_resource
148
+ render xls: User.new(first_name: 'Foo1', last_name: 'Bar1')
149
+ end
150
+ end
151
+
152
+ tests TestsController
153
+
154
+ def test_render_single_resource
155
+ get :render_single_resource
156
+ assert_equal 'application/vnd.ms-excel', @response.content_type
157
+ assert_equal "first_name\tlast_name\tfull_name\n"\
158
+ "Foo1\tBar1\tFoo1-Bar1\n", @response.body
159
+ end
160
+ end
144
161
  end
145
162
  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.3.1
4
+ version: 0.3.2
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: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel