comma 4.1.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +12 -1
  3. data/.rubocop_todo.yml +3 -364
  4. data/.travis.yml +20 -38
  5. data/Appraisals +20 -1
  6. data/Gemfile +5 -1
  7. data/Gemfile.lock +54 -36
  8. data/README.md +59 -0
  9. data/Rakefile +2 -0
  10. data/comma.gemspec +12 -15
  11. data/gemfiles/active5.0.7.2.gemfile +12 -0
  12. data/gemfiles/active5.0.7.2.gemfile.lock +113 -0
  13. data/gemfiles/active5.1.7.gemfile +12 -0
  14. data/gemfiles/active5.1.7.gemfile.lock +113 -0
  15. data/gemfiles/active5.2.4.3.gemfile +12 -0
  16. data/gemfiles/active5.2.4.3.gemfile.lock +113 -0
  17. data/gemfiles/active6.0.3.1.gemfile +12 -0
  18. data/gemfiles/active6.0.3.1.gemfile.lock +113 -0
  19. data/gemfiles/{rails4.2.8.gemfile → rails5.0.7.2.gemfile} +5 -2
  20. data/gemfiles/rails5.0.7.2.gemfile.lock +204 -0
  21. data/gemfiles/{rails4.1.16.gemfile → rails5.1.7.gemfile} +5 -2
  22. data/gemfiles/rails5.1.7.gemfile.lock +204 -0
  23. data/gemfiles/{rails5.0.1.gemfile → rails5.2.4.3.gemfile} +5 -2
  24. data/gemfiles/rails5.2.4.3.gemfile.lock +212 -0
  25. data/gemfiles/{rails4.0.13.gemfile → rails6.0.3.1.gemfile} +4 -2
  26. data/gemfiles/rails6.0.3.1.gemfile.lock +227 -0
  27. data/init.rb +2 -0
  28. data/lib/comma.rb +26 -36
  29. data/lib/comma/array.rb +2 -0
  30. data/lib/comma/data_extractor.rb +7 -9
  31. data/lib/comma/data_mapper_collection.rb +8 -4
  32. data/lib/comma/extractor.rb +2 -6
  33. data/lib/comma/generator.rb +12 -13
  34. data/lib/comma/header_extractor.rb +19 -15
  35. data/lib/comma/mongoid.rb +10 -7
  36. data/lib/comma/object.rb +5 -2
  37. data/lib/comma/relation.rb +16 -10
  38. data/lib/comma/version.rb +3 -1
  39. data/spec/comma/comma_spec.rb +71 -50
  40. data/spec/comma/data_extractor_spec.rb +13 -18
  41. data/spec/comma/header_extractor_spec.rb +8 -15
  42. data/spec/comma/rails/active_record_spec.rb +34 -34
  43. data/spec/comma/rails/data_mapper_collection_spec.rb +4 -4
  44. data/spec/comma/rails/mongoid_spec.rb +8 -8
  45. data/spec/controllers/users_controller_spec.rb +83 -70
  46. data/spec/non_rails_app/ruby_classes.rb +13 -6
  47. data/spec/rails_app/active_record/config.rb +2 -2
  48. data/spec/rails_app/active_record/models.rb +3 -3
  49. data/spec/rails_app/data_mapper/config.rb +1 -1
  50. data/spec/rails_app/mongoid/config.rb +3 -3
  51. data/spec/rails_app/rails_app.rb +13 -13
  52. data/spec/rails_app/tmp/.gitkeep +0 -0
  53. data/spec/spec_helper.rb +21 -5
  54. metadata +29 -46
  55. data/README.markdown +0 -353
  56. data/gemfiles/active4.0.13.gemfile +0 -10
  57. data/gemfiles/active4.0.13.gemfile.lock +0 -107
  58. data/gemfiles/active4.1.16.gemfile +0 -10
  59. data/gemfiles/active4.1.16.gemfile.lock +0 -106
  60. data/gemfiles/active4.2.8.gemfile +0 -10
  61. data/gemfiles/active4.2.8.gemfile.lock +0 -105
  62. data/gemfiles/active5.0.1.gemfile +0 -10
  63. data/gemfiles/active5.0.1.gemfile.lock +0 -104
  64. data/gemfiles/active5.1.0.gemfile +0 -10
  65. data/gemfiles/active5.1.0.gemfile.lock +0 -104
  66. data/gemfiles/rails4.0.13.gemfile.lock +0 -158
  67. data/gemfiles/rails4.1.16.gemfile.lock +0 -163
  68. data/gemfiles/rails4.2.8.gemfile.lock +0 -187
  69. data/gemfiles/rails5.0.1.gemfile.lock +0 -194
  70. data/gemfiles/rails5.1.0.gemfile +0 -11
  71. data/gemfiles/rails5.1.0.gemfile.lock +0 -194
@@ -1,4 +1,5 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  # comma do
@@ -8,8 +9,7 @@ require 'spec_helper'
8
9
  # isbn :number_10 => 'ISBN-10', :number_13 => 'ISBN-13'
9
10
  # end
10
11
 
11
- describe Comma::HeaderExtractor do # rubocop:disable Metcirs/BlockLength
12
-
12
+ describe Comma::HeaderExtractor do # rubocop:disable Metrics/BlockLength
13
13
  before do
14
14
  @isbn = Isbn.new('123123123', '321321321')
15
15
  @book = Book.new('Smalltalk-80', 'Language and Implementation', @isbn)
@@ -18,37 +18,30 @@ describe Comma::HeaderExtractor do # rubocop:disable Metcirs/BlockLength
18
18
  end
19
19
 
20
20
  describe 'when no parameters are provided' do
21
-
22
21
  it 'should use the method name as the header name, humanized' do
23
- @headers.should include('Description')
22
+ expect(@headers).to include('Description')
24
23
  end
25
24
  end
26
25
 
27
26
  describe 'when given a string description as a parameter' do
28
-
29
27
  it 'should use the string value, unmodified' do
30
- @headers.should include('Title')
28
+ expect(@headers).to include('Title')
31
29
  end
32
30
  end
33
31
 
34
32
  describe 'when an hash is passed as a parameter' do
35
-
36
33
  describe 'with a string value' do
37
-
38
34
  it 'should use the string value, unmodified' do
39
- @headers.should include('ISBN-10')
35
+ expect(@headers).to include('ISBN-10')
40
36
  end
41
37
  end
42
38
 
43
39
  describe 'with a non-string value' do
44
-
45
40
  it 'should use the non string value converted to a string, humanized' do
46
- @headers.should include('Issuer')
41
+ expect(@headers).to include('Issuer')
47
42
  end
48
43
  end
49
-
50
44
  end
51
-
52
45
  end
53
46
 
54
47
  describe Comma::HeaderExtractor, 'with static column method' do
@@ -63,6 +56,6 @@ describe Comma::HeaderExtractor, 'with static column method' do
63
56
  end
64
57
 
65
58
  it 'should extract headers' do
66
- @headers.should eq(['', 'STATIC', 'STATIC'])
59
+ expect(@headers).to eq(['', 'STATIC', 'STATIC'])
67
60
  end
68
61
  end
@@ -1,20 +1,20 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  if defined? ActiveRecord
5
6
 
6
7
  describe Comma, 'generating CSV from an ActiveRecord object' do # rubocop:disable Metrics/BlockLength
7
-
8
8
  class Picture < ActiveRecord::Base
9
- belongs_to :imageable, :polymorphic => true
9
+ belongs_to :imageable, polymorphic: true
10
10
 
11
11
  comma :pr_83 do
12
- imageable :name => 'Picture'
12
+ imageable name: 'Picture'
13
13
  end
14
14
  end
15
15
 
16
16
  class Person < ActiveRecord::Base
17
- scope(:teenagers, lambda { where(:age => 13..19) })
17
+ scope(:teenagers, -> { where(age: 13..19) })
18
18
 
19
19
  comma do
20
20
  name
@@ -27,18 +27,18 @@ if defined? ActiveRecord
27
27
  job :title
28
28
  end
29
29
 
30
- has_many :pictures, :as => :imageable
30
+ has_many :pictures, as: :imageable
31
31
  end
32
32
 
33
33
  class Job < ActiveRecord::Base
34
34
  belongs_to :person
35
35
 
36
36
  comma do
37
- person_formatter :name => 'Name'
37
+ person_formatter name: 'Name'
38
38
  end
39
39
 
40
40
  def person_formatter
41
- @person_formatter ||= PersonFormatter.new(self.person)
41
+ @person_formatter ||= PersonFormatter.new(person)
42
42
  end
43
43
  end
44
44
 
@@ -53,51 +53,51 @@ if defined? ActiveRecord
53
53
  end
54
54
 
55
55
  before(:all) do
56
- #Setup AR model in memory
57
- ActiveRecord::Base.connection.create_table :pictures, :force => true do |table|
56
+ # Setup AR model in memory
57
+ ActiveRecord::Base.connection.create_table :pictures, force: true do |table|
58
58
  table.column :name, :string
59
59
  table.column :imageable_id, :integer
60
60
  table.column :imageable_type, :string
61
61
  end
62
62
 
63
- ActiveRecord::Base.connection.create_table :people, :force => true do |table|
63
+ ActiveRecord::Base.connection.create_table :people, force: true do |table|
64
64
  table.column :name, :string
65
65
  table.column :age, :integer
66
66
  end
67
67
  Person.reset_column_information
68
68
 
69
- ActiveRecord::Base.connection.create_table :jobs, :force => true do |table|
69
+ ActiveRecord::Base.connection.create_table :jobs, force: true do |table|
70
70
  table.column :person_id, :integer
71
71
  table.column :title, :string
72
72
  end
73
73
  Job.reset_column_information
74
74
 
75
- @person = Person.new(:age => 18, :name => 'Junior')
76
- @person.build_job(:title => 'Nice job')
75
+ @person = Person.new(age: 18, name: 'Junior')
76
+ @person.build_job(title: 'Nice job')
77
77
  @person.save!
78
- Picture.create(:name => 'photo.jpg', :imageable_id => @person.id, :imageable_type => 'Person')
78
+ Picture.create(name: 'photo.jpg', imageable_id: @person.id, imageable_type: 'Person')
79
79
  end
80
80
 
81
- describe "#to_comma on scopes" do
82
- it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do
83
- Person.teenagers.to_comma.should == "Name,Age\nJunior,18\n"
81
+ describe '#to_comma on scopes' do
82
+ it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do # rubocop:disable Metrics/LineLength
83
+ expect(Person.teenagers.to_comma).to eq "Name,Age\nJunior,18\n"
84
84
  end
85
85
 
86
86
  it 'should find in batches' do
87
87
  scope = Person.teenagers
88
- scope.should_receive(:find_each).and_yield @person
88
+ expect(scope).to receive(:find_each).and_yield @person
89
89
  scope.to_comma
90
90
  end
91
91
 
92
92
  it 'should fall back to iterating with each when scope has limit clause' do
93
93
  scope = Person.limit(1)
94
- scope.should_receive(:each).and_yield @person
94
+ expect(scope).to receive(:each).and_yield @person
95
95
  scope.to_comma
96
96
  end
97
97
 
98
98
  it 'should fall back to iterating with each when scope has order clause' do
99
99
  scope = Person.order(:age)
100
- scope.should_receive(:each).and_yield @person
100
+ expect(scope).to receive(:each).and_yield @person
101
101
  scope.to_comma
102
102
  end
103
103
  end
@@ -113,7 +113,7 @@ if defined? ActiveRecord
113
113
  end
114
114
  end
115
115
 
116
- I18n.config.backend.store_translations(:ja, {:activerecord => {:attributes => {:person => {:age => '年齢', :name => '名前'}}}})
116
+ I18n.config.backend.store_translations(:ja, activerecord: { attributes: { person: { age: '年齢', name: '名前' } } })
117
117
  @original_locale = I18n.locale
118
118
  I18n.locale = :ja
119
119
  end
@@ -126,25 +126,25 @@ if defined? ActiveRecord
126
126
  end
127
127
 
128
128
  it 'should i18n-ize header values' do
129
- Person.teenagers.to_comma.should match(/^名前,年齢/)
129
+ expect(Person.teenagers.to_comma).to match(/^名前,年齢/)
130
130
  end
131
131
  end
132
132
 
133
133
  describe 'github issue 75' do
134
134
  it 'should find association' do
135
- lambda { Person.all.to_comma(:issue_75) }.should_not raise_error
135
+ expect { Person.all.to_comma(:issue_75) }.not_to raise_error
136
136
  end
137
137
  end
138
138
 
139
139
  describe 'with accessor' do
140
140
  it 'should not raise exception' do
141
- Job.all.to_comma.should eq("Name\nJunior\n")
141
+ expect(Job.all.to_comma).to eq("Name\nJunior\n")
142
142
  end
143
143
  end
144
144
 
145
145
  describe 'github pull-request 83' do
146
146
  it 'should not raise NameError' do
147
- lambda { Picture.all.to_comma(:pr_83) }.should_not raise_exception(NameError)
147
+ expect { Picture.all.to_comma(:pr_83) }.not_to raise_error
148
148
  end
149
149
  end
150
150
  end
@@ -175,29 +175,29 @@ if defined? ActiveRecord
175
175
  end
176
176
 
177
177
  before(:all) do
178
- #Setup AR model in memory
179
- ActiveRecord::Base.connection.create_table :animals, :force => true do |table|
178
+ # Setup AR model in memory
179
+ ActiveRecord::Base.connection.create_table :animals, force: true do |table|
180
180
  table.column :name, :string
181
181
  table.column :type, :string
182
182
  end
183
183
 
184
- @dog = Dog.new(:name => 'Rex')
184
+ @dog = Dog.new(name: 'Rex')
185
185
  @dog.save!
186
- @cat = Cat.new(:name => 'Kitty')
186
+ @cat = Cat.new(name: 'Kitty')
187
187
  @cat.save!
188
188
  end
189
189
 
190
190
  it 'should return and array of data content, as defined in comma block in child class' do
191
- @dog.to_comma.should == %w[Dog-Rex]
191
+ expect(@dog.to_comma).to eq %w[Dog-Rex]
192
192
  end
193
193
 
194
- #FIXME: this one is failing - the comma block from Dog is executed instead of the one from the super class
194
+ # FIXME: this one is failing - the comma block from Dog is executed instead of the one from the super class
195
195
  it 'should return and array of data content, as defined in comma block in super class, if not present in child' do
196
- @cat.to_comma.should == %w[Super-Kitty]
196
+ expect(@cat.to_comma).to eq %w[Super-Kitty]
197
197
  end
198
198
 
199
199
  it 'should call definion in parent class' do
200
- lambda { @dog.to_comma(:with_type) }.should_not raise_error
200
+ expect { @dog.to_comma(:with_type) }.not_to raise_error
201
201
  end
202
202
  end
203
203
  end
@@ -1,10 +1,10 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  if defined? DataMapper
5
6
 
6
7
  describe Comma, 'generating CSV from an DataMapper object' do # rubocop:disable Metrics/BlockLength
7
-
8
8
  class Person
9
9
  include DataMapper::Resource
10
10
 
@@ -31,9 +31,9 @@ if defined? DataMapper
31
31
  after(:all) do
32
32
  end
33
33
 
34
- describe "case" do
34
+ describe 'case' do
35
35
  before do
36
- @person = Person.new(:age => 18, :name => 'Junior')
36
+ @person = Person.new(age: 18, name: 'Junior')
37
37
  @person.save
38
38
  end
39
39
 
@@ -1,17 +1,17 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  if defined? Mongoid
5
6
 
6
7
  describe Comma, 'generating CSV from an Mongoid object' do
7
-
8
8
  class Person
9
9
  include Mongoid::Document
10
10
 
11
- field :name, :type => String
12
- field :age, :type => Integer
11
+ field :name, type: String
12
+ field :age, type: Integer
13
13
 
14
- scope :teenagers, between(:age => 13..19)
14
+ scope :teenagers, between(age: 13..19)
15
15
 
16
16
  comma do
17
17
  name
@@ -23,13 +23,13 @@ if defined? Mongoid
23
23
  Mongoid.purge!
24
24
  end
25
25
 
26
- describe "case" do
26
+ describe 'case' do
27
27
  before do
28
- @person = Person.new(:age => 18, :name => 'Junior')
28
+ @person = Person.new(age: 18, name: 'Junior')
29
29
  @person.save
30
30
  end
31
31
 
32
- it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do
32
+ it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do # rubocop:disable Metrics/LineLength
33
33
  Person.teenagers.to_comma.should == "Name,Age\nJunior,18\n"
34
34
  end
35
35
 
@@ -1,69 +1,66 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  if defined?(Rails)
4
6
 
5
7
  RSpec.describe UsersController, type: :controller do # rubocop:disable Metrics/BlockLength
6
-
7
- describe "rails setup" do
8
-
8
+ describe 'rails setup' do
9
9
  it 'should capture the CSV renderer provided by Rails' do
10
10
  mock_users = [mock_model(User), mock_model(User)]
11
11
  allow(User).to receive(:all).and_return(mock_users)
12
12
 
13
- mock_users.should_receive(:to_comma).once
13
+ expect(mock_users).to receive(:to_comma).once
14
14
 
15
- get :index, :format => :csv
15
+ get :index, format: :csv
16
16
  end
17
-
18
17
  end
19
18
 
20
- describe "controller" do # rubocop:disable Metrics/BlockLength
19
+ describe 'controller' do # rubocop:disable Metrics/BlockLength
21
20
  before(:all) do
22
- @user_1 = User.create!(:first_name => 'Fred', :last_name => 'Flintstone')
23
- @user_2 = User.create!(:first_name => 'Wilma', :last_name => 'Flintstone')
21
+ @user_1 = User.create!(first_name: 'Fred', last_name: 'Flintstone')
22
+ @user_2 = User.create!(first_name: 'Wilma', last_name: 'Flintstone')
24
23
  end
25
24
 
26
25
  it 'should not affect html requested' do
27
26
  get :index
28
27
 
29
- response.status.should eq 200
30
- response.content_type.should eq 'text/html'
31
- response.body.should == 'Users!'
28
+ expect(response.status).to eq 200
29
+ expect(response.content_type).to eq 'text/html'
30
+ expect(response.body).to eq 'Users!'
32
31
  end
33
32
 
34
- it "should return a csv when requested" do
35
- get :index, :format => :csv
33
+ it 'should return a csv when requested' do
34
+ get :index, format: :csv
36
35
 
37
- response.status.should eq 200
38
- response.content_type.should eq 'text/csv'
39
- response.header["Content-Disposition"].should include('filename="data.csv"')
36
+ expect(response.status).to eq 200
37
+ expect(response.content_type).to eq 'text/csv'
38
+ expect(response.header['Content-Disposition']).to include('filename="data.csv"')
40
39
 
41
- expected_content =<<-CSV.gsub(/^\s+/,'')
40
+ expected_content = <<-CSV.gsub(/^\s+/, '')
42
41
  First name,Last name,Name
43
42
  Fred,Flintstone,Fred Flintstone
44
43
  Wilma,Flintstone,Wilma Flintstone
45
44
  CSV
46
45
 
47
- response.body.should == expected_content
46
+ expect(response.body).to eq expected_content
48
47
  end
49
48
 
50
49
  describe 'with comma options' do
51
-
52
50
  it 'should allow the style to be chosen from the renderer' do
53
- #Must be passed in same format (string/symbol) eg:
51
+ # Must be passed in same format (string/symbol) eg:
54
52
  # format.csv { render User.all, :style => :shortened }
55
53
 
56
- get :with_custom_style, :format => :csv
54
+ get :with_custom_style, format: :csv
57
55
 
58
- expected_content =<<-CSV.gsub(/^\s+/,'')
56
+ expected_content = <<-CSV.gsub(/^\s+/, '')
59
57
  First name,Last name
60
58
  Fred,Flintstone
61
59
  Wilma,Flintstone
62
60
  CSV
63
61
 
64
- response.body.should == expected_content
62
+ expect(response.body).to eq expected_content
65
63
  end
66
-
67
64
  end
68
65
 
69
66
  describe 'with custom options' do # rubocop:disable Metrics/BlockLength
@@ -80,105 +77,121 @@ if defined?(Rails)
80
77
  end
81
78
 
82
79
  it 'should allow a filename to be set' do
83
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :filename => 'my_custom_name' } }
80
+ get_ :with_custom_options, format: :csv, params: { custom_options: { filename: 'my_custom_name' } }
84
81
 
85
- response.status.should eq 200
86
- response.content_type.should eq 'text/csv'
87
- response.header["Content-Disposition"].should include('filename="my_custom_name.csv"')
82
+ expect(response.status).to eq 200
83
+ expect(response.content_type).to eq 'text/csv'
84
+ expect(response.header['Content-Disposition']).to include('filename="my_custom_name.csv"')
88
85
  end
89
86
 
90
- it "should allow a custom filename with spaces" do
87
+ it 'should allow a custom filename with spaces' do
91
88
  require 'shellwords'
92
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :filename => 'filename with a lot of spaces' } }
89
+ params = { custom_options: { filename: 'filename with a lot of spaces' } }
90
+ get_ :with_custom_options, format: :csv, params: params
93
91
 
94
- response.status.should eq 200
95
- response.content_type.should eq 'text/csv'
96
- response.header["Content-Disposition"].should include('filename="filename with a lot of spaces.csv"')
92
+ expect(response.status).to eq 200
93
+ expect(response.content_type).to eq 'text/csv'
94
+ expect(response.header['Content-Disposition']).to include('filename="filename with a lot of spaces.csv"')
97
95
 
98
- filename_string = response.header["Content-Disposition"].split('=').last
96
+ filename_string = response.header['Content-Disposition'].split('=').last
99
97
  # shellsplit honors quoted strings
100
- filename_string.shellsplit.length.should == 1
98
+ expect(filename_string.shellsplit.length).to eq 1
101
99
  end
102
100
 
103
101
  it 'should allow a file extension to be set' do
104
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :extension => :txt } }
102
+ get_ :with_custom_options, format: :csv, params: { custom_options: { extension: :txt } }
105
103
 
106
- response.status.should eq 200
107
- response.content_type.should eq 'text/csv'
108
- response.header["Content-Disposition"].should include('filename="data.txt"')
104
+ expect(response.status).to eq 200
105
+ expect(response.content_type).to eq 'text/csv'
106
+ expect(response.header['Content-Disposition']).to include('filename="data.txt"')
109
107
  end
110
108
 
111
109
  it 'should allow mime type to be set' do
112
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :mime_type => 'text/plain' } }
113
- response.status.should eq 200
114
- response.content_type.should == 'text/plain'
110
+ get_ :with_custom_options, format: :csv, params: { custom_options: { mime_type: 'text/plain' } }
111
+ expect(response.status).to eq 200
112
+ expect(response.content_type).to eq 'text/plain'
115
113
  end
116
114
 
117
- describe 'headers' do
115
+ it 'should allow bom to be set' do
116
+ get_ :with_custom_options, format: :csv, params: { custom_options: { with_bom: true } }
117
+
118
+ expected_content = <<-CSV.gsub(/^\s+/, '')
119
+ \xEF\xBB\xBFFirst name,Last name,Name
120
+ Fred,Flintstone,Fred Flintstone
121
+ Wilma,Flintstone,Wilma Flintstone
122
+ CSV
118
123
 
124
+ expect(response.body). to eq expected_content
125
+ end
126
+
127
+ describe 'headers' do
119
128
  it 'should allow toggling on' do
120
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :write_headers => 'true' } }
129
+ get_ :with_custom_options, format: :csv, params: { custom_options: { write_headers: 'true' } }
121
130
 
122
- response.status.should eq 200
123
- response.content_type.should eq 'text/csv'
131
+ expect(response.status).to eq 200
132
+ expect(response.content_type).to eq 'text/csv'
124
133
 
125
- expected_content =<<-CSV.gsub(/^\s+/,'')
134
+ expected_content = <<-CSV.gsub(/^\s+/, '')
126
135
  First name,Last name,Name
127
136
  Fred,Flintstone,Fred Flintstone
128
137
  Wilma,Flintstone,Wilma Flintstone
129
138
  CSV
130
139
 
131
- response.body.should == expected_content
140
+ expect(response.body).to eq expected_content
132
141
  end
133
142
 
134
143
  it 'should allow toggling off' do
135
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => {:write_headers => false} }
144
+ get_ :with_custom_options, format: :csv, params: { custom_options: { write_headers: false } }
136
145
 
137
- response.status.should eq 200
138
- response.content_type.should eq 'text/csv'
146
+ expect(response.status).to eq 200
147
+ expect(response.content_type).to eq 'text/csv'
139
148
 
140
- expected_content =<<-CSV.gsub(/^\s+/,'')
149
+ expected_content = <<-CSV.gsub(/^\s+/, '')
141
150
  Fred,Flintstone,Fred Flintstone
142
151
  Wilma,Flintstone,Wilma Flintstone
143
152
  CSV
144
153
 
145
- response.body.should == expected_content
154
+ expect(response.body).to eq expected_content
146
155
  end
147
-
148
156
  end
149
157
 
150
158
  it 'should allow forcing of quotes' do
151
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :force_quotes => true } }
159
+ get_ :with_custom_options, format: :csv, params: { custom_options: { force_quotes: true } }
152
160
 
153
- response.status.should eq 200
154
- response.content_type.should eq 'text/csv'
161
+ expect(response.status).to eq 200
162
+ expect(response.content_type).to eq 'text/csv'
155
163
 
156
- expected_content =<<-CSV.gsub(/^\s+/,'')
164
+ expected_content = <<-CSV.gsub(/^\s+/, '')
157
165
  "First name","Last name","Name"
158
166
  "Fred","Flintstone","Fred Flintstone"
159
167
  "Wilma","Flintstone","Wilma Flintstone"
160
168
  CSV
161
169
 
162
- response.body.should == expected_content
170
+ expect(response.body).to eq expected_content
163
171
  end
164
172
 
165
173
  it 'should allow combinations of options' do
166
- get_ :with_custom_options, :format => :csv, :params => { :custom_options => { :write_headers => false, :force_quotes => true, :col_sep => '||', :row_sep => "ENDOFLINE\n" } }
167
-
168
- response.status.should eq 200
169
- response.content_type.should eq 'text/csv'
170
-
171
- expected_content =<<-CSV.gsub(/^\s+/,'')
174
+ params = {
175
+ custom_options: {
176
+ write_headers: false,
177
+ force_quotes: true,
178
+ col_sep: '||',
179
+ row_sep: "ENDOFLINE\n"
180
+ }
181
+ }
182
+ get_ :with_custom_options, format: :csv, params: params
183
+
184
+ expect(response.status).to eq 200
185
+ expect(response.content_type).to eq 'text/csv'
186
+
187
+ expected_content = <<-CSV.gsub(/^\s+/, '')
172
188
  "Fred"||"Flintstone"||"Fred Flintstone"ENDOFLINE
173
189
  "Wilma"||"Flintstone"||"Wilma Flintstone"ENDOFLINE
174
190
  CSV
175
191
 
176
- response.body.should == expected_content
192
+ expect(response.body).to eq expected_content
177
193
  end
178
-
179
194
  end
180
-
181
195
  end
182
-
183
196
  end
184
197
  end