comma 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg/*
3
3
  *~
4
4
  .bundle
5
5
  spec/rails_app/log
6
+ spec/rails_app/db/development.sqlite3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- comma (3.0.1)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/tom/Development/Projects/comma
3
3
  specs:
4
- comma (3.0.0)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/tom/Development/Projects/comma
3
3
  specs:
4
- comma (3.0.0)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/tom/Development/Projects/comma
3
3
  specs:
4
- comma (3.0.0)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/tom/Development/Projects/comma
3
3
  specs:
4
- comma (3.0.0)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/tom/Development/Projects/comma
3
3
  specs:
4
- comma (3.0.0)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/tom/Development/Projects/comma
3
3
  specs:
4
- comma (3.0.0)
4
+ comma (3.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -10,6 +10,13 @@ if defined? Rails and (Rails.version.split('.').map(&:to_i).first < 3)
10
10
  raise "Error - This Comma version only supports Rails 3.x. Please use a 2.x version of Comma for use with earlier rails versions."
11
11
  end
12
12
 
13
+ module Comma
14
+ DEFAULT_OPTIONS = {
15
+ :write_headers => true,
16
+ :style => :default
17
+ }
18
+ end
19
+
13
20
  require 'active_support/core_ext/class/attribute'
14
21
  require 'active_support/core_ext/module/delegation'
15
22
  require 'comma/relation' if defined?(ActiveRecord::Relation)
@@ -23,9 +30,8 @@ require 'comma/object'
23
30
  if defined?(ActionController::Renderers) && ActionController::Renderers.respond_to?(:add)
24
31
  ActionController::Renderers.add :csv do |obj, options|
25
32
  filename = options[:filename] || 'data'
26
- #Capture any CSV optional settings passed to comma
27
- csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(:write_headers => nil).keys)
28
-
33
+ #Capture any CSV optional settings passed to comma or comma specific options
34
+ csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys)
29
35
  send_data obj.to_comma(csv_options), :type => Mime::CSV, :disposition => "attachment; filename=#{filename}.csv"
30
36
  end
31
37
  end
@@ -9,7 +9,7 @@ module Comma
9
9
 
10
10
  if @style.is_a? Hash
11
11
  @options = @style.clone
12
- @style = @options.delete(:style) || :default
12
+ @style = @options.delete(:style) || Comma::DEFAULT_OPTIONS[:style]
13
13
  @filename = @options.delete(:filename)
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Comma
2
- VERSION = "3.0.1"
2
+ VERSION = "3.0.2"
3
3
  end
@@ -47,6 +47,25 @@ if defined?(ActionController) && defined?(Rails)
47
47
  response.body.should == expected_content
48
48
  end
49
49
 
50
+ describe 'with comma options' do
51
+
52
+ it 'should allow the style to be chosen from the renderer' do
53
+ #Must be passed in same format (string/symbol) eg:
54
+ # format.csv { render User.all, :style => :shortened }
55
+
56
+ get :with_custom_style, :format => :csv
57
+
58
+ expected_content =<<-CSV.gsub(/^\s+/,'')
59
+ First name,Last name
60
+ Fred,Flintstone
61
+ Wilma,Flintstone
62
+ CSV
63
+
64
+ response.body.should == expected_content
65
+ end
66
+
67
+ end
68
+
50
69
  describe 'with custom options' do
51
70
 
52
71
  it 'should allow a filename to be set' do
@@ -14,4 +14,10 @@ class UsersController < ApplicationController
14
14
  end
15
15
  end
16
16
 
17
+ def with_custom_style
18
+ respond_to do |format|
19
+ format.csv { render :csv => User.all, :style => :shortened }
20
+ end
21
+ end
22
+
17
23
  end
@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
5
5
  full_name "Name"
6
6
  end
7
7
 
8
- comma :brief do
8
+ comma :shortened do
9
9
  first_name
10
10
  last_name
11
11
  end
@@ -3,6 +3,7 @@ Rails.application.routes.draw do
3
3
  resources :users, :only => [:index]
4
4
 
5
5
  match "with_custom_options", :to => "users#with_custom_options"
6
+ match "with_custom_style", :to => "users#with_custom_style"
6
7
 
7
8
  root :to => "users#index"
8
9
  end
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.0.1
4
+ version: 3.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-02-26 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70233068053000 !ruby/object:Gem::Requirement
17
+ requirement: &70335467056500 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.9.2
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70233068053000
25
+ version_requirements: *70335467056500
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
- requirement: &70233068052360 !ruby/object:Gem::Requirement
28
+ requirement: &70335467054900 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.3.4
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70233068052360
36
+ version_requirements: *70335467054900
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: appraisal
39
- requirement: &70233068051800 !ruby/object:Gem::Requirement
39
+ requirement: &70335467054140 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.4.1
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70233068051800
47
+ version_requirements: *70335467054140
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &70233068051240 !ruby/object:Gem::Requirement
50
+ requirement: &70335467053480 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.8.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70233068051240
58
+ version_requirements: *70335467053480
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: simplecov
61
- requirement: &70233068050740 !ruby/object:Gem::Requirement
61
+ requirement: &70335467052920 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70233068050740
69
+ version_requirements: *70335467052920
70
70
  description: Ruby Comma Seperated Values generation library
71
71
  email:
72
72
  - crafterm@redartisan.com
@@ -133,7 +133,6 @@ files:
133
133
  - spec/rails_app/config/initializers/inflections.rb
134
134
  - spec/rails_app/config/initializers/secret_token.rb
135
135
  - spec/rails_app/config/routes.rb
136
- - spec/rails_app/db/development.sqlite3
137
136
  - spec/rails_app/db/migrate/20120224085510_create_tables.rb
138
137
  - spec/rails_app/db/schema.rb
139
138
  - spec/rails_app/public/404.html
@@ -157,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
156
  version: '0'
158
157
  segments:
159
158
  - 0
160
- hash: -3572797252536909493
159
+ hash: -1006301303101993278
161
160
  required_rubygems_version: !ruby/object:Gem::Requirement
162
161
  none: false
163
162
  requirements:
@@ -166,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
165
  version: '0'
167
166
  segments:
168
167
  - 0
169
- hash: -3572797252536909493
168
+ hash: -1006301303101993278
170
169
  requirements: []
171
170
  rubyforge_project: comma
172
171
  rubygems_version: 1.8.10
@@ -199,7 +198,6 @@ test_files:
199
198
  - spec/rails_app/config/initializers/inflections.rb
200
199
  - spec/rails_app/config/initializers/secret_token.rb
201
200
  - spec/rails_app/config/routes.rb
202
- - spec/rails_app/db/development.sqlite3
203
201
  - spec/rails_app/db/migrate/20120224085510_create_tables.rb
204
202
  - spec/rails_app/db/schema.rb
205
203
  - spec/rails_app/public/404.html