csv_rails 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -68,9 +68,15 @@ If you do not use :header option, header is using :fields and I18n transfer.
68
68
  name: 名前
69
69
  age: 年齢
70
70
  ok: OK
71
+ # rails3
71
72
  groups:
72
73
  first:
73
74
  <<: *groupmodel
75
+ # edge rails
76
+ user/groups:
77
+ first:
78
+ <<: *groupmodel
79
+
74
80
 
75
81
  # app/controllers/user_controller.rb
76
82
  def index
@@ -34,8 +34,8 @@ module CsvRails
34
34
  field.to_s.split(".").inject(self){|object, f|
35
35
  next unless object
36
36
  convert_method = "#{f}_as_csv"
37
- method = respond_to?(convert_method) ? convert_method : f
38
- object.send(f)
37
+ method = object.respond_to?(convert_method) ? convert_method : f
38
+ object.send(method)
39
39
  }
40
40
  }
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module CsvRails
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -88,4 +88,8 @@ class CsvRails::ActiveRecordTest < ActiveSupport::TestCase
88
88
  assert_equal csv, User.includes(:groups).to_csv(:fields => [:name, :"groups.first.name"])
89
89
  I18n.locale = :en
90
90
  end
91
+
92
+ test ".to_csv with association using as_csv" do
93
+ assert_equal @group.created_at_as_csv, User.includes(:groups).to_csv(:fields => [:"groups.first.created_at"], :without_header => true).chomp
94
+ end
91
95
  end
@@ -1,4 +1,8 @@
1
1
  class Group < ActiveRecord::Base
2
2
  has_many :memberships
3
3
  has_many :users, through: :memberships
4
+
5
+ def created_at_as_csv
6
+ created_at.strftime("%F")
7
+ end
4
8
  end
@@ -7,6 +7,11 @@ ja:
7
7
  id: ID
8
8
  name: 名前
9
9
  age: 年齢
10
+ # previous version of rails 3.2.2
10
11
  groups:
11
12
  first:
12
13
  <<: *groupmodel
14
+ # rails 3.2.3 or higher
15
+ user/groups:
16
+ first:
17
+ <<: *groupmodel