Skip to content

Commit 312e9a2

Browse files
Add 5.1 testing, MIME access update
1 parent 6fa9e59 commit 312e9a2

File tree

18 files changed

+110
-27
lines changed

18 files changed

+110
-27
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ notifications:
99
1010
on_success: always
1111
env:
12-
- RAILS_VERSION=4.0
13-
- RAILS_VERSION=4.1
1412
- RAILS_VERSION=4.2
1513
- RAILS_VERSION=5.0
14+
- RAILS_VERSION=5.1
1615
rvm:
17-
- 2.2.7
18-
- 2.3.4
16+
- 2.2.8
17+
- 2.3.5
18+
- 2.4.2
1919
before_install:
2020
- gem update bundler
2121
script:

Gemfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ gemspec
88
ENV["RAILS_VERSION"] ||= '4.2'
99

1010
case ENV['RAILS_VERSION']
11+
when '5.1'
12+
gem 'rails', "~> 5.1.0"
13+
gem 'responders', '~> 2.0'
1114
when '5.0'
1215
gem 'rails', "~> 5.0.0"
1316
gem 'responders', '~> 2.0'
1417
when '4.2'
1518
gem 'rails', "~> 4.2.0"
1619
gem 'responders', '~> 2.0'
17-
when '4.1'
18-
gem 'rails', "~> 4.1.0"
19-
when '4.0'
20-
gem 'rails', "~> 4.0.0"
20+
# when '4.1'
21+
# gem 'rails', "~> 4.1.0"
22+
# when '4.0'
23+
# gem 'rails', "~> 4.0.0"
2124
when '3.1', '3.2'
2225
gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
2326
end

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Status](https://coveralls.io/repos/straydogstudio/axlsx_rails/badge.svg)](https:
1818
In your Gemfile:
1919

2020
```ruby
21-
gem 'rubyzip', '~> 1.1.0'
22-
gem 'axlsx', '2.1.0.pre'
21+
gem 'rubyzip', '>= 1.2.1'
22+
gem 'axlsx', git: 'https://github.com/randym/axlsx.git', ref: 'c8ac844'
2323
gem 'axlsx_rails'
2424
```
2525

@@ -31,11 +31,11 @@ gem 'axlsx', '= 2.0.1'
3131
gem 'axlsx_rails'
3232
```
3333

34-
If `rubyzip >= 1.2.1` is needed:
34+
If `rubyzip >= 1.1.0` is needed:
3535

3636
```ruby
37-
gem 'rubyzip', '>= 1.2.1'
38-
gem 'axlsx', git: 'https://github.com/randym/axlsx.git', ref: '776037c0fc799bb09da8c9ea47980bd3bf296874'
37+
gem 'rubyzip', '~> 1.1.0'
38+
gem 'axlsx', '2.1.0.pre'
3939
gem 'axlsx_rails'
4040
```
4141

@@ -202,7 +202,7 @@ class UserMailer < ActionMailer::Base
202202
def export(users)
203203
xlsx = render_to_string layout: false, handlers: [:axlsx], formats: [:xlsx], template: "users/export", locals: {users: users}
204204
attachment = Base64.encode64(xlsx)
205-
attachments["Users.xlsx"] = {mime_type: Mime::XLSX, content: attachment, encoding: 'base64'}
205+
attachments["Users.xlsx"] = {mime_type: Mime[:xlsx], content: attachment, encoding: 'base64'}
206206
# self.instance_variable_set(:@_lookup_context, nil) # If attachments are rendered as content, try this and open an issue
207207
...
208208
end
@@ -241,7 +241,7 @@ If you are having problems with rendering a template and attaching it to a templ
241241
class UserMailer < ActionMailer::Base
242242
def export(users)
243243
xlsx = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "users/export", locals: {users: users}
244-
attachments["Users.xlsx"] = {mime_type: Mime::XLSX, content: xlsx, encoding: 'base64'}
244+
attachments["Users.xlsx"] = {mime_type: Mime[:xlsx], content: xlsx, encoding: 'base64'}
245245
# self.instance_variable_set(:@_lookup_context, nil) # If attachments are rendered as content, try this and open an issue
246246
...
247247
end

lib/axlsx_rails/action_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'action_controller'
2-
unless defined? Mime::XLSX
2+
unless defined? Mime[:xlsx]
33
Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
44
end
55

@@ -42,7 +42,7 @@
4242
options[:locals][:xlsx_use_shared_strings] = options.delete(:xlsx_use_shared_strings)
4343
end
4444

45-
mime = (Rails.version.to_f >= 5) ? Mime[:xlsx] : Mime::XLSX
45+
mime = Mime[:xlsx]
4646
send_data render_to_string(options), :filename => file_name, :type => mime, :disposition => disposition
4747
end
4848

@@ -53,6 +53,7 @@
5353
else
5454
class ActionController::Responder
5555
def to_xlsx
56+
@_action_has_layout = false
5657
if @default_response
5758
@default_response.call(options)
5859
else

lib/axlsx_rails/template_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module ActionView
33
module Template::Handlers
44
class AxlsxBuilder
55
def default_format
6-
(Rails.version.to_f >= 5) ? Mime[:xlsx] : Mime::XLSX
6+
Mime[:xlsx]
77
end
88

99
def self.call(template)

spec/axlsx_request_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@
126126
expect(wb.cell(2,1)).to eq('Untie!')
127127
end
128128

129+
it "ignores layout" do
130+
User.destroy_all
131+
@user = User.create name: 'Responder', last_name: 'Bunny', address: '1234 Right Turn, Albuquerque NM 22222', email: '[email protected]'
132+
expect {
133+
visit "/users/export/#{@user.id}.xlsx"
134+
}.to_not raise_error
135+
File.open('/tmp/axlsx_temp.xlsx', 'w') {|f| f.write(page.source) }
136+
wb = nil
137+
expect{ wb = Roo::Excelx.new('/tmp/axlsx_temp.xlsx') }.to_not raise_error
138+
expect(wb.cell(2,1)).to eq('Untie!')
139+
end
140+
129141
unless Rails.version < '3.2'
130142
it "handles missing format with render :xlsx" do
131143
visit '/another'

spec/dummy/app/mailers/notifier.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def instructions(user)
66

77
# normal syntax
88
xlsx = render_to_string handlers: [:axlsx], template: 'users/send_instructions', layout: false
9-
attachments["user_#{user.id}.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
9+
attachments["user_#{user.id}.xlsx"] = {mime_type: Mime[:xlsx], content: xlsx}
1010

1111
mail :to => user.email, :subject => 'Instructions'
1212
end

spec/dummy_4/app/mailers/notifier.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def instructions(user)
66

77
# normal syntax
88
xlsx = render_to_string handlers: [:axlsx], template: 'users/send_instructions', layout: false, formats: [:xlsx]
9-
attachments["user_#{user.id}.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
9+
attachments["user_#{user.id}.xlsx"] = {mime_type: Mime[:xlsx], content: xlsx}
1010

1111
mail :to => user.email, :subject => 'Instructions'
1212
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dummy 4</title>
5+
<%= csrf_meta_tags %>
6+
</head>
7+
<body>
8+
9+
<%= yield %>
10+
11+
</body>
12+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
wb = xlsx_package.workbook
2+
style_shout = wb.styles.add_style sz: 16, b: true, alignment: { horizontal: :center }
3+
wb.add_worksheet(name: "Foobar") do |sheet|
4+
sheet.add_row ['Bad', 'spellers', 'of', 'the', 'world', '...']
5+
sheet.add_row ['Untie!']
6+
sheet.merge_cells("A2:E2")
7+
sheet["A2"].style = style_shout
8+
end

0 commit comments

Comments
 (0)