comma 3.2.2 → 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.travis.yml +31 -16
  4. data/Appraisals +1 -1
  5. data/Gemfile +8 -3
  6. data/Gemfile.lock +24 -6
  7. data/comma.gemspec +2 -4
  8. data/gemfiles/active3.0.20.gemfile +3 -1
  9. data/gemfiles/active3.0.20.gemfile.lock +25 -7
  10. data/gemfiles/active3.1.12.gemfile +3 -1
  11. data/gemfiles/active3.1.12.gemfile.lock +24 -6
  12. data/gemfiles/active3.2.20.gemfile +3 -1
  13. data/gemfiles/active3.2.20.gemfile.lock +22 -6
  14. data/gemfiles/active4.0.13.gemfile +11 -0
  15. data/gemfiles/{active4.0.11.gemfile.lock → active4.0.13.gemfile.lock} +34 -18
  16. data/gemfiles/active4.1.10.gemfile +11 -0
  17. data/gemfiles/{active4.1.7.gemfile.lock → active4.1.10.gemfile.lock} +34 -19
  18. data/gemfiles/active4.2.1.gemfile +11 -0
  19. data/gemfiles/active4.2.1.gemfile.lock +81 -0
  20. data/gemfiles/data_mapper1.2.0.gemfile +3 -1
  21. data/gemfiles/data_mapper1.2.0.gemfile.lock +23 -6
  22. data/gemfiles/mongoid3.1.6.gemfile +3 -1
  23. data/gemfiles/mongoid3.1.6.gemfile.lock +24 -8
  24. data/gemfiles/rails3.0.20.gemfile +3 -1
  25. data/gemfiles/rails3.0.20.gemfile.lock +21 -8
  26. data/gemfiles/rails3.1.12.gemfile +3 -1
  27. data/gemfiles/rails3.1.12.gemfile.lock +20 -7
  28. data/gemfiles/rails3.2.20.gemfile +3 -1
  29. data/gemfiles/rails3.2.20.gemfile.lock +17 -6
  30. data/gemfiles/rails4.0.13.gemfile +11 -0
  31. data/gemfiles/{rails4.0.11.gemfile.lock → rails4.0.13.gemfile.lock} +48 -34
  32. data/gemfiles/rails4.1.10.gemfile +11 -0
  33. data/gemfiles/{rails4.1.7.gemfile.lock → rails4.1.10.gemfile.lock} +54 -41
  34. data/gemfiles/rails4.2.1.gemfile +11 -0
  35. data/gemfiles/rails4.2.1.gemfile.lock +156 -0
  36. data/lib/comma/object.rb +17 -5
  37. data/lib/comma/version.rb +1 -1
  38. data/spec/comma/comma_spec.rb +49 -0
  39. data/spec/comma/rails/active_record_spec.rb +45 -0
  40. data/spec/spec_helper.rb +5 -2
  41. metadata +26 -35
  42. data/gemfiles/active4.0.11.gemfile +0 -9
  43. data/gemfiles/active4.1.7.gemfile +0 -9
  44. data/gemfiles/rails4.0.11.gemfile +0 -9
  45. data/gemfiles/rails4.1.7.gemfile +0 -9
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "coveralls", :require=>false
6
+ gem "fastercsv", :platforms=>:ruby_18
7
+ gem "rest-client", "> 1.6.2", "< 1.7", :require=>false
8
+ gem "rails", "4.2.1"
9
+ gem "rspec-rails"
10
+
11
+ gemspec :path=>"../"
@@ -0,0 +1,156 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ comma (3.2.3)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.1)
11
+ actionpack (= 4.2.1)
12
+ actionview (= 4.2.1)
13
+ activejob (= 4.2.1)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.1)
17
+ actionview (= 4.2.1)
18
+ activesupport (= 4.2.1)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ actionview (4.2.1)
24
+ activesupport (= 4.2.1)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
29
+ activejob (4.2.1)
30
+ activesupport (= 4.2.1)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.1)
33
+ activesupport (= 4.2.1)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.1)
36
+ activemodel (= 4.2.1)
37
+ activesupport (= 4.2.1)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.1)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ appraisal (0.4.1)
46
+ bundler
47
+ rake
48
+ arel (6.0.0)
49
+ builder (3.2.2)
50
+ colorize (0.7.5)
51
+ coveralls (0.5.8)
52
+ colorize
53
+ json
54
+ rest-client
55
+ simplecov (>= 0.7)
56
+ thor
57
+ diff-lcs (1.1.3)
58
+ docile (1.1.5)
59
+ erubis (2.7.0)
60
+ fastercsv (1.5.5)
61
+ globalid (0.3.3)
62
+ activesupport (>= 4.1.0)
63
+ hike (1.2.3)
64
+ i18n (0.7.0)
65
+ json (1.8.2)
66
+ loofah (2.0.1)
67
+ nokogiri (>= 1.5.9)
68
+ mail (2.6.3)
69
+ mime-types (>= 1.16, < 3)
70
+ mime-types (1.25.1)
71
+ mini_portile (0.6.2)
72
+ minitest (5.5.1)
73
+ multi_json (1.11.0)
74
+ nokogiri (1.6.6.2)
75
+ mini_portile (~> 0.6.0)
76
+ rack (1.6.0)
77
+ rack-test (0.6.3)
78
+ rack (>= 1.0)
79
+ rails (4.2.1)
80
+ actionmailer (= 4.2.1)
81
+ actionpack (= 4.2.1)
82
+ actionview (= 4.2.1)
83
+ activejob (= 4.2.1)
84
+ activemodel (= 4.2.1)
85
+ activerecord (= 4.2.1)
86
+ activesupport (= 4.2.1)
87
+ bundler (>= 1.3.0, < 2.0)
88
+ railties (= 4.2.1)
89
+ sprockets-rails
90
+ rails-deprecated_sanitizer (1.0.3)
91
+ activesupport (>= 4.2.0.alpha)
92
+ rails-dom-testing (1.0.6)
93
+ activesupport (>= 4.2.0.beta, < 5.0)
94
+ nokogiri (~> 1.6.0)
95
+ rails-deprecated_sanitizer (>= 1.0.1)
96
+ rails-html-sanitizer (1.0.2)
97
+ loofah (~> 2.0)
98
+ railties (4.2.1)
99
+ actionpack (= 4.2.1)
100
+ activesupport (= 4.2.1)
101
+ rake (>= 0.8.7)
102
+ thor (>= 0.18.1, < 2.0)
103
+ rake (0.9.6)
104
+ rdoc (4.2.0)
105
+ json (~> 1.4)
106
+ rest-client (1.6.8)
107
+ mime-types (~> 1.16)
108
+ rdoc (>= 2.4.2)
109
+ rspec (2.8.0)
110
+ rspec-core (~> 2.8.0)
111
+ rspec-expectations (~> 2.8.0)
112
+ rspec-mocks (~> 2.8.0)
113
+ rspec-core (2.8.0)
114
+ rspec-expectations (2.8.0)
115
+ diff-lcs (~> 1.1.2)
116
+ rspec-mocks (2.8.0)
117
+ rspec-rails (2.8.1)
118
+ actionpack (>= 3.0)
119
+ activesupport (>= 3.0)
120
+ railties (>= 3.0)
121
+ rspec (~> 2.8.0)
122
+ simplecov (0.9.2)
123
+ docile (~> 1.1.0)
124
+ multi_json (~> 1.0)
125
+ simplecov-html (~> 0.9.0)
126
+ simplecov-html (0.9.0)
127
+ sprockets (2.12.3)
128
+ hike (~> 1.2)
129
+ multi_json (~> 1.0)
130
+ rack (~> 1.0)
131
+ tilt (~> 1.1, != 1.3.0)
132
+ sprockets-rails (2.2.4)
133
+ actionpack (>= 3.0)
134
+ activesupport (>= 3.0)
135
+ sprockets (>= 2.8, < 4.0)
136
+ sqlite3 (1.3.10)
137
+ thor (0.19.1)
138
+ thread_safe (0.3.5)
139
+ tilt (1.4.1)
140
+ tzinfo (1.2.2)
141
+ thread_safe (~> 0.1)
142
+
143
+ PLATFORMS
144
+ ruby
145
+
146
+ DEPENDENCIES
147
+ appraisal (~> 0.4.1)
148
+ comma!
149
+ coveralls
150
+ fastercsv
151
+ rails (= 4.2.1)
152
+ rake (~> 0.9.2)
153
+ rest-client (> 1.6.2, < 1.7)
154
+ rspec (~> 2.8.0)
155
+ rspec-rails
156
+ sqlite3 (~> 1.3.4)
data/lib/comma/object.rb CHANGED
@@ -3,10 +3,20 @@ require 'comma/data_extractor'
3
3
  require 'comma/header_extractor'
4
4
 
5
5
  class Object
6
- class_attribute :comma_formats
6
+ class << self
7
+ def comma(style = :default, &block)
8
+ (@comma_formats ||= {})[style] = block
9
+ end
7
10
 
8
- def self.comma(style = :default, &block)
9
- (self.comma_formats ||= {})[style] = block
11
+ def comma_formats
12
+ @comma_formats ||= begin
13
+ if self == Object
14
+ {}
15
+ else
16
+ self.superclass.comma_formats
17
+ end
18
+ end
19
+ end
10
20
  end
11
21
 
12
22
  def to_comma(style = :default)
@@ -21,10 +31,12 @@ class Object
21
31
 
22
32
  def extract_with(extractor_class, style = :default)
23
33
  raise_unless_style_exists(style)
24
- extractor_class.new(self, style, self.class.comma_formats).results
34
+ formats = respond_to?(:comma_formats) ? self.comma_formats : self.class.comma_formats
35
+ extractor_class.new(self, style, formats).results
25
36
  end
26
37
 
27
38
  def raise_unless_style_exists(style)
28
- raise "No comma format for class #{self.class} defined for style #{style}" unless self.comma_formats && self.comma_formats[style]
39
+ formats = respond_to?(:comma_formats) ? self.comma_formats : self.class.comma_formats
40
+ raise "No comma format for class #{self.class} defined for style #{style}" unless formats && formats[style]
29
41
  end
30
42
  end
data/lib/comma/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Comma
2
- VERSION = "3.2.2"
2
+ VERSION = '3.2.3'
3
3
  end
@@ -14,6 +14,18 @@ describe Comma do
14
14
  Object.should respond_to(:to_comma_headers)
15
15
  end
16
16
 
17
+ describe '.to_comma_header' do
18
+ it 'should not crash (#94)' do
19
+ klass = Class.new do
20
+ attr_accessor :name
21
+
22
+ comma :brief do
23
+ name
24
+ end
25
+ end
26
+ expect { klass.to_comma_headers(:brief) }.to_not raise_error
27
+ end
28
+ end
17
29
  end
18
30
 
19
31
  describe Comma, 'generating CSV' do
@@ -224,6 +236,43 @@ describe Comma, 'to_comma data/headers object extensions' do
224
236
 
225
237
  end
226
238
 
239
+ describe 'on objects using Single Table Inheritance' do
240
+
241
+ before do
242
+ class MySuperClass
243
+ attr_accessor :content
244
+ comma do; content end
245
+
246
+ def initialize(content)
247
+ @content = 'super-' + content
248
+ end
249
+ end
250
+
251
+ class ChildClassComma < MySuperClass
252
+ comma do; content end
253
+
254
+ def initialize(content)
255
+ @content = 'sub-' + content
256
+ end
257
+ end
258
+
259
+ class ChildClassNoComma < MySuperClass
260
+ end
261
+
262
+ @childComma = ChildClassComma.new('content')
263
+ @childNoComma = ChildClassNoComma.new('content')
264
+ end
265
+
266
+ it 'should return and array of data content, as defined in comma block in child class' do
267
+ @childComma.to_comma.should == %w(sub-content)
268
+ end
269
+
270
+ it 'should return and array of data content, as defined in comma block in super class, if not present in child' do
271
+ @childNoComma.to_comma.should == %w(super-content)
272
+ end
273
+
274
+ end
275
+
227
276
  end
228
277
 
229
278
  describe Comma, '__use__ keyword' do
@@ -149,4 +149,49 @@ if defined? ActiveRecord
149
149
  end
150
150
  end
151
151
 
152
+ describe Comma, 'generating CSV from an ActiveRecord object using Single Table Inheritance' do
153
+
154
+ class Animal < ActiveRecord::Base
155
+ comma do;
156
+ name 'Name' do |name|
157
+ 'Super-' + name
158
+ end
159
+ end
160
+ end
161
+
162
+ class Dog < Animal
163
+ comma do
164
+ name 'Name' do |name|
165
+ 'Dog-' + name
166
+ end
167
+ end
168
+ end
169
+
170
+ class Cat < Animal
171
+ end
172
+
173
+ before(:all) do
174
+ #Setup AR model in memory
175
+ ActiveRecord::Base.connection.create_table :animals, :force => true do |table|
176
+ table.column :name, :string
177
+ table.column :type, :string
178
+ end
179
+
180
+ @dog = Dog.new(:name => 'Rex')
181
+ @dog.save!
182
+ @cat = Cat.new(:name => 'Kitty')
183
+ @cat.save!
184
+ end
185
+
186
+ it 'should return and array of data content, as defined in comma block in child class' do
187
+ @dog.to_comma.should == %w(Dog-Rex)
188
+ end
189
+
190
+ #FIXME: this one is failing - the comma block from Dog is executed instead of the one from the super class
191
+ it 'should return and array of data content, as defined in comma block in super class, if not present in child' do
192
+ @cat.to_comma.should == %w(Super-Kitty)
193
+ end
194
+
195
+ end
196
+
152
197
  end
data/spec/spec_helper.rb CHANGED
@@ -2,14 +2,17 @@
2
2
  require 'rubygems'
3
3
  $LOAD_PATH.unshift(File.expand_path(File.join(*%w{.. .. lib}), __FILE__))
4
4
 
5
- require 'bundler/setup'
6
- Bundler.require
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
7
 
8
8
  begin
9
9
  require 'rails'
10
10
  rescue LoadError
11
11
  end
12
12
 
13
+ require 'bundler/setup'
14
+ Bundler.require
15
+
13
16
  %w{data_mapper mongoid active_record}.each do |orm|
14
17
  begin
15
18
  require orm
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comma
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Crafter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-02 00:00:00.000000000 Z
12
+ date: 2015-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -26,47 +26,33 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: 3.0.0
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 0.9.2
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: 0.9.2
42
- - !ruby/object:Gem::Dependency
43
- name: sqlite3
29
+ name: appraisal
44
30
  requirement: !ruby/object:Gem::Requirement
45
31
  requirements:
46
32
  - - "~>"
47
33
  - !ruby/object:Gem::Version
48
- version: 1.3.4
34
+ version: 0.4.1
49
35
  type: :development
50
36
  prerelease: false
51
37
  version_requirements: !ruby/object:Gem::Requirement
52
38
  requirements:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
- version: 1.3.4
41
+ version: 0.4.1
56
42
  - !ruby/object:Gem::Dependency
57
- name: appraisal
43
+ name: rake
58
44
  requirement: !ruby/object:Gem::Requirement
59
45
  requirements:
60
46
  - - "~>"
61
47
  - !ruby/object:Gem::Version
62
- version: 0.4.1
48
+ version: 0.9.2
63
49
  type: :development
64
50
  prerelease: false
65
51
  version_requirements: !ruby/object:Gem::Requirement
66
52
  requirements:
67
53
  - - "~>"
68
54
  - !ruby/object:Gem::Version
69
- version: 0.4.1
55
+ version: 0.9.2
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: rspec
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -82,19 +68,19 @@ dependencies:
82
68
  - !ruby/object:Gem::Version
83
69
  version: 2.8.0
84
70
  - !ruby/object:Gem::Dependency
85
- name: simplecov
71
+ name: sqlite3
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
- - - ">="
74
+ - - "~>"
89
75
  - !ruby/object:Gem::Version
90
- version: '0'
76
+ version: 1.3.4
91
77
  type: :development
92
78
  prerelease: false
93
79
  version_requirements: !ruby/object:Gem::Requirement
94
80
  requirements:
95
- - - ">="
81
+ - - "~>"
96
82
  - !ruby/object:Gem::Version
97
- version: '0'
83
+ version: 1.3.4
98
84
  description: Ruby Comma Seperated Values generation library
99
85
  email:
100
86
  - crafterm@redartisan.com
@@ -103,6 +89,7 @@ executables: []
103
89
  extensions: []
104
90
  extra_rdoc_files: []
105
91
  files:
92
+ - ".coveralls.yml"
106
93
  - ".gitignore"
107
94
  - ".rspec"
108
95
  - ".travis.yml"
@@ -119,10 +106,12 @@ files:
119
106
  - gemfiles/active3.1.12.gemfile.lock
120
107
  - gemfiles/active3.2.20.gemfile
121
108
  - gemfiles/active3.2.20.gemfile.lock
122
- - gemfiles/active4.0.11.gemfile
123
- - gemfiles/active4.0.11.gemfile.lock
124
- - gemfiles/active4.1.7.gemfile
125
- - gemfiles/active4.1.7.gemfile.lock
109
+ - gemfiles/active4.0.13.gemfile
110
+ - gemfiles/active4.0.13.gemfile.lock
111
+ - gemfiles/active4.1.10.gemfile
112
+ - gemfiles/active4.1.10.gemfile.lock
113
+ - gemfiles/active4.2.1.gemfile
114
+ - gemfiles/active4.2.1.gemfile.lock
126
115
  - gemfiles/data_mapper1.2.0.gemfile
127
116
  - gemfiles/data_mapper1.2.0.gemfile.lock
128
117
  - gemfiles/mongoid3.1.6.gemfile
@@ -133,10 +122,12 @@ files:
133
122
  - gemfiles/rails3.1.12.gemfile.lock
134
123
  - gemfiles/rails3.2.20.gemfile
135
124
  - gemfiles/rails3.2.20.gemfile.lock
136
- - gemfiles/rails4.0.11.gemfile
137
- - gemfiles/rails4.0.11.gemfile.lock
138
- - gemfiles/rails4.1.7.gemfile
139
- - gemfiles/rails4.1.7.gemfile.lock
125
+ - gemfiles/rails4.0.13.gemfile
126
+ - gemfiles/rails4.0.13.gemfile.lock
127
+ - gemfiles/rails4.1.10.gemfile
128
+ - gemfiles/rails4.1.10.gemfile.lock
129
+ - gemfiles/rails4.2.1.gemfile
130
+ - gemfiles/rails4.2.1.gemfile.lock
140
131
  - init.rb
141
132
  - lib/comma.rb
142
133
  - lib/comma/array.rb