workbook_rails 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +12 -7
- data/Gemfile.lock +251 -179
- data/README.md +24 -30
- data/Rakefile +6 -15
- data/lib/tasks/workbook_rails_tasks.rake +2 -0
- data/lib/workbook_rails/action_controller.rb +20 -18
- data/lib/workbook_rails/engine.rb +8 -8
- data/lib/workbook_rails/template_handler.rb +9 -7
- data/lib/workbook_rails/version.rb +3 -1
- data/lib/workbook_rails.rb +3 -2
- data/spec/ci.rb +5 -1
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/home_controller.rb +14 -20
- data/spec/dummy/app/controllers/likes_controller.rb +3 -1
- data/spec/dummy/app/controllers/users_controller.rb +4 -2
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/notifier.rb +6 -5
- data/spec/dummy/app/models/like.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/bin/bundle +3 -1
- data/spec/dummy/bin/rails +3 -1
- data/spec/dummy/bin/rake +2 -0
- data/spec/dummy/config/application.rb +9 -8
- data/spec/dummy/config/boot.rb +4 -2
- data/spec/dummy/config/environment.rb +3 -1
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +6 -4
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -1
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/secret_token.rb +3 -1
- data/spec/dummy/config/initializers/session_store.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/routes.rb +13 -12
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/db/migrate/20120717192452_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20121206210955_create_likes.rb +3 -1
- data/spec/dummy/db/schema.rb +19 -22
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +7332 -8068
- data/spec/spec_helper.rb +19 -12
- data/spec/template_handler_spec.rb +13 -16
- data/spec/test_7.2.sh +6 -0
- data/spec/test_8.0.sh +6 -0
- data/spec/test_8.1.sh +6 -0
- data/spec/test_all_rails.sh +10 -4
- data/spec/workbook_mailer_spec.rb +9 -4
- data/spec/workbook_renderer_spec.rb +22 -16
- data/spec/workbook_request_spec.rb +78 -77
- metadata +26 -142
- data/spec/test_3.2.sh +0 -4
- data/spec/test_4.0.sh +0 -4
- data/spec/test_4.1.sh +0 -4
- data/spec/test_4.2.sh +0 -4
data/spec/spec_helper.rb
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'simplecov'
|
|
4
|
+
require 'simplecov_json_formatter'
|
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
|
|
6
|
+
SimpleCov.start do
|
|
7
|
+
add_filter '/spec/'
|
|
8
|
+
end
|
|
3
9
|
|
|
4
10
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
5
|
-
ENV[
|
|
6
|
-
require File.expand_path(
|
|
11
|
+
ENV['RAILS_ENV'] = 'test'
|
|
12
|
+
require File.expand_path('dummy/config/environment', __dir__)
|
|
7
13
|
require 'bundler'
|
|
8
14
|
require 'bundler/setup'
|
|
9
15
|
require 'rspec/rails'
|
|
10
16
|
require 'capybara/rspec'
|
|
11
17
|
require 'workbook_rails'
|
|
12
|
-
require 'pry'
|
|
13
18
|
|
|
14
|
-
Dir[Rails.root.join(
|
|
19
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
|
15
20
|
|
|
16
21
|
RSpec.configure do |config|
|
|
17
22
|
config.color = true
|
|
18
|
-
config.formatter
|
|
23
|
+
config.formatter = 'documentation'
|
|
19
24
|
config.use_transactional_fixtures = false
|
|
20
25
|
config.infer_base_class_for_anonymous_controllers = false
|
|
21
|
-
config.order =
|
|
26
|
+
config.order = 'random'
|
|
22
27
|
end
|
|
23
28
|
|
|
24
|
-
module ::RSpec
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
module ::RSpec
|
|
30
|
+
module Core
|
|
31
|
+
class ExampleGroup
|
|
32
|
+
include Capybara::DSL
|
|
33
|
+
include Capybara::RSpecMatchers
|
|
34
|
+
end
|
|
28
35
|
end
|
|
29
36
|
end
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
describe 'Workbook template handler' do
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
describe WorkbookRails::TemplateHandler do
|
|
5
|
+
let(:handler) { described_class.new }
|
|
6
6
|
|
|
7
|
-
let(
|
|
8
|
-
|
|
9
|
-
let( :template ) do
|
|
10
|
-
VT.new("workbook.sheet.table = Workbook::Table.new([['one', 'two', 'three'],['a', 'b', 'c']])")
|
|
7
|
+
let(:template) do
|
|
8
|
+
Struct.new(:source).new("workbook.sheet.table = Workbook::Table.new([['one', 'two', 'three'],['a', 'b', 'c']])")
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
context "Rails #{Rails.version}" do
|
|
14
12
|
# for testing if the author is set
|
|
15
13
|
# before do
|
|
16
|
-
|
|
14
|
+
# Rails.stub_chain(:application, :config, :axlsx_author).and_return( 'Elmer Fudd' )
|
|
17
15
|
# end
|
|
18
16
|
|
|
19
|
-
it
|
|
17
|
+
it 'has xlsx format' do
|
|
20
18
|
expect(handler.default_format).to eq(:xlsx)
|
|
21
19
|
end
|
|
22
20
|
|
|
23
|
-
it
|
|
21
|
+
it 'compiles to an excel spreadsheet' do
|
|
24
22
|
workbook, wb = nil
|
|
25
|
-
lookup_context = double(
|
|
26
|
-
eval
|
|
23
|
+
lookup_context = double(formats: [:xlsx])
|
|
24
|
+
eval described_class.call(template, template.source), binding
|
|
27
25
|
workbook.write_to_xlsx('/tmp/wb_temp.xlsx')
|
|
28
|
-
expect{ wb = Workbook::Book.open('/tmp/wb_temp.xlsx') }.to_not raise_error
|
|
26
|
+
expect { wb = Workbook::Book.open('/tmp/wb_temp.xlsx') }.to_not raise_error
|
|
29
27
|
expect(wb.sheet.table[1][2]).to eq('c')
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
#TODO:
|
|
33
|
-
# Test if author field is set - does roo parse that?
|
|
30
|
+
# TODO: Test if author field is set - does roo parse that?
|
|
34
31
|
end
|
|
35
32
|
end
|
data/spec/test_7.2.sh
ADDED
data/spec/test_8.0.sh
ADDED
data/spec/test_8.1.sh
ADDED
data/spec/test_all_rails.sh
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
|
-
describe
|
|
5
|
+
describe 'Mailer', type: :request do
|
|
4
6
|
before :each do
|
|
5
|
-
@user = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111',
|
|
7
|
+
@user = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111',
|
|
8
|
+
email: 'elmer@fudd.com'
|
|
6
9
|
end
|
|
7
10
|
|
|
8
|
-
it
|
|
11
|
+
it 'attaches an xlsx file' do
|
|
9
12
|
visit "/users/#{@user.id}/send_instructions"
|
|
10
13
|
last_email = ActionMailer::Base.deliveries.last
|
|
11
14
|
expect(last_email.to).to eq([@user.email])
|
|
12
15
|
expect(last_email.attachments.first).to be
|
|
13
16
|
expect(last_email.attachments.first.body.to_s).not_to be_empty
|
|
14
|
-
expect(last_email.attachments.first.content_type).to eq(
|
|
17
|
+
expect(last_email.attachments.first.content_type).to eq(
|
|
18
|
+
Mime[:xlsx].to_s + (Rails.version < '4.0' ? '; charset=UTF-8' : '')
|
|
19
|
+
)
|
|
15
20
|
end
|
|
16
21
|
end
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
describe 'Workbook renderer' do
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
describe 'Workbook renderer' do
|
|
5
|
+
it 'is registered' do
|
|
5
6
|
ActionController::Renderers::RENDERERS.include?(:xlsx)
|
|
6
7
|
ActionController::Renderers::RENDERERS.include?(:xls)
|
|
7
8
|
ActionController::Renderers::RENDERERS.include?(:csv)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
it
|
|
11
|
-
expect(
|
|
12
|
-
|
|
13
|
-
expect(
|
|
11
|
+
it 'has xlsx mime type' do
|
|
12
|
+
expect(get_mime(:xlsx)).to be
|
|
13
|
+
expect(get_mime(:xlsx).to_sym).to eq(:xlsx)
|
|
14
|
+
expect(get_mime(:xlsx).to_s).to eq('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
it
|
|
17
|
-
expect(
|
|
18
|
-
expect(
|
|
19
|
-
expect(
|
|
17
|
+
it 'has xls mime type' do
|
|
18
|
+
expect(get_mime(:xls)).to be
|
|
19
|
+
expect(get_mime(:xls).to_sym).to eq(:xls)
|
|
20
|
+
expect(get_mime(:xls).to_s).to eq('application/vnd.ms-excel')
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
it
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
25
|
-
expect(
|
|
23
|
+
it 'has csv mime type' do
|
|
24
|
+
expect(get_mime(:csv)).to be
|
|
25
|
+
expect(get_mime(:csv).to_sym).to eq(:csv)
|
|
26
|
+
expect(get_mime(:csv).to_s).to eq('text/csv')
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
protected
|
|
30
|
+
|
|
31
|
+
def get_mime(extension)
|
|
32
|
+
Mime[extension]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -1,184 +1,185 @@
|
|
|
1
|
-
|
|
2
|
-
describe 'Workbook request', :type => :request do
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
describe 'Workbook request', type: :request do # rubocop:disable Metrics/BlockLength
|
|
5
|
+
it 'has a working dummy app' do
|
|
6
|
+
@user1 = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111',
|
|
7
|
+
email: 'elmer@fudd.com'
|
|
6
8
|
visit '/'
|
|
7
|
-
expect(page).to have_content(
|
|
9
|
+
expect(page).to have_content('Hey, you')
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
it
|
|
12
|
+
it 'downloads an excel file from default respond_to' do
|
|
11
13
|
visit '/home.xlsx'
|
|
12
14
|
|
|
13
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
15
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xlsx]}; charset=utf-8")
|
|
14
16
|
wb = write_and_open_workbook(page)
|
|
15
17
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
it
|
|
20
|
+
it 'downloads an xls file from default respond_to' do
|
|
19
21
|
visit '/home.xls'
|
|
20
22
|
|
|
21
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
23
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xls]}; charset=utf-8")
|
|
22
24
|
wb = write_and_open_workbook(page, 'xls')
|
|
23
25
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
it
|
|
28
|
+
it 'downloads an csv file from default respond_to' do
|
|
27
29
|
visit '/home.csv'
|
|
28
30
|
|
|
29
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
31
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:csv]}; charset=utf-8")
|
|
30
32
|
wb = write_and_open_workbook(page, 'csv')
|
|
31
33
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
it
|
|
36
|
+
it 'downloads an excel file from params format' do
|
|
35
37
|
visit '/home/generic.xlsx'
|
|
36
38
|
|
|
37
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
39
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xlsx]}; charset=utf-8")
|
|
38
40
|
wb = write_and_open_workbook(page)
|
|
39
41
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
40
42
|
end
|
|
41
43
|
|
|
42
|
-
it
|
|
44
|
+
it 'downloads an xls file from params format' do
|
|
43
45
|
visit '/home/generic.xls'
|
|
44
46
|
|
|
45
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
47
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xls]}; charset=utf-8")
|
|
46
48
|
wb = write_and_open_workbook(page, 'xls')
|
|
47
49
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
it
|
|
52
|
+
it 'downloads an csv file from params format' do
|
|
51
53
|
visit '/home/generic.csv'
|
|
52
54
|
|
|
53
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
55
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:csv]}; charset=utf-8")
|
|
54
56
|
wb = write_and_open_workbook(page, 'csv')
|
|
55
57
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
56
58
|
end
|
|
57
59
|
|
|
58
|
-
it
|
|
60
|
+
it 'downloads an excel file from respond_to while specifying filename' do
|
|
59
61
|
visit '/useheader.xlsx'
|
|
60
62
|
|
|
61
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
62
|
-
expect(page.response_headers['Content-Disposition']).to include(
|
|
63
|
+
expect(page.response_headers['Content-Type']).to eq(Mime[:xlsx].to_s)
|
|
64
|
+
expect(page.response_headers['Content-Disposition']).to include('filename="filename_test.xlsx"')
|
|
63
65
|
|
|
64
66
|
wb = write_and_open_workbook(page)
|
|
65
67
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
66
68
|
end
|
|
67
69
|
|
|
68
|
-
it
|
|
70
|
+
it 'downloads an excel file from respond_to while specifying filename in direct format' do
|
|
69
71
|
visit '/useheader.xlsx?set_direct=true'
|
|
70
72
|
|
|
71
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
72
|
-
expect(page.response_headers['Content-Disposition']).to include(
|
|
73
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xlsx]}; charset=utf-8")
|
|
74
|
+
expect(page.response_headers['Content-Disposition']).to include('filename="filename_test.xlsx"')
|
|
73
75
|
|
|
74
76
|
wb = write_and_open_workbook(page)
|
|
75
77
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
76
78
|
end
|
|
77
79
|
|
|
78
|
-
it
|
|
80
|
+
it 'downloads an excel file from render statement with filename' do
|
|
79
81
|
visit '/another.xlsx'
|
|
80
82
|
|
|
81
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
82
|
-
expect(page.response_headers['Content-Disposition']).to include(
|
|
83
|
+
expect(page.response_headers['Content-Type']).to eq(Mime[:xlsx])
|
|
84
|
+
expect(page.response_headers['Content-Disposition']).to include('filename="filename_test.xlsx"')
|
|
83
85
|
|
|
84
86
|
wb = write_and_open_workbook(page)
|
|
85
87
|
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
86
88
|
end
|
|
87
89
|
|
|
88
|
-
it
|
|
90
|
+
it 'downloads an excel file with partial' do
|
|
89
91
|
visit '/withpartial.xlsx'
|
|
90
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
92
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xlsx]}; charset=utf-8")
|
|
91
93
|
wb = write_and_open_workbook(page)
|
|
92
94
|
expect(wb.sheet.table[0][0]).to eq('Cover')
|
|
93
|
-
expect(wb[1].table[1][0]).to eq(
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "downloads an excel from render with file path" do
|
|
97
|
-
visit '/render_file_path.xlsx'
|
|
98
|
-
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s)
|
|
99
|
-
wb = write_and_open_workbook(page)
|
|
100
|
-
expect(wb.sheet.table[1][0]).to eq('User!')
|
|
95
|
+
expect(wb[1].table[1][0]).to eq('Untie!')
|
|
101
96
|
end
|
|
102
97
|
|
|
103
|
-
it
|
|
98
|
+
it 'handles nested resources' do
|
|
104
99
|
User.destroy_all
|
|
105
|
-
@user = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222',
|
|
106
|
-
|
|
107
|
-
@user.likes.create(:
|
|
100
|
+
@user = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222',
|
|
101
|
+
email: 'bugs@bunny.com'
|
|
102
|
+
@user.likes.create(name: 'Carrots')
|
|
103
|
+
@user.likes.create(name: 'Celery')
|
|
108
104
|
visit "/users/#{@user.id}/likes.xlsx"
|
|
109
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
105
|
+
expect(page.response_headers['Content-Type']).to eq("#{Mime[:xlsx]}; charset=utf-8")
|
|
110
106
|
wb = write_and_open_workbook(page)
|
|
111
107
|
expect(wb.sheet.table[0][0]).to eq('Bugs')
|
|
112
108
|
expect(wb.sheet.table[1][0]).to eq('Carrots')
|
|
113
109
|
expect(wb.sheet.table[2][0]).to eq('Celery')
|
|
114
110
|
end
|
|
115
111
|
|
|
116
|
-
it
|
|
112
|
+
it 'handles reference to absolute paths' do
|
|
117
113
|
User.destroy_all
|
|
118
|
-
@user = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222',
|
|
114
|
+
@user = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222',
|
|
115
|
+
email: 'bugs@bunny.com'
|
|
119
116
|
visit "/users/#{@user.id}/render_elsewhere.xlsx"
|
|
120
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
117
|
+
expect(page.response_headers['Content-Type']).to eq(Mime[:xlsx].to_s)
|
|
121
118
|
wb = write_and_open_workbook(page)
|
|
122
119
|
expect(wb.sheet.table[1][0]).to eq('User!')
|
|
123
120
|
|
|
124
|
-
[[1,false], [2,false], [3,true], [4,true], [5,false]].reverse.each do |s|
|
|
121
|
+
[[1, false], [2, false], [3, true], [4, true], [5, false]].reverse.each do |s|
|
|
125
122
|
visit "/home/render_elsewhere.xlsx?type=#{s[0]}"
|
|
126
|
-
expect(page.response_headers['Content-Type']).to eq(Mime
|
|
127
|
-
(s[1] ?
|
|
123
|
+
expect(page.response_headers['Content-Type']).to eq(Mime[:xlsx].to_s +
|
|
124
|
+
(s[1] ? '; charset=utf-8' : ''))
|
|
128
125
|
wb = write_and_open_workbook(page)
|
|
129
126
|
expect(wb.sheet.table[1][0]).to eq(s[0] == 5 ? 'Untie!' : 'User!')
|
|
130
127
|
end
|
|
131
128
|
end
|
|
132
129
|
|
|
133
|
-
it
|
|
130
|
+
it 'uses respond_with' do
|
|
134
131
|
User.destroy_all
|
|
135
|
-
@user = User.create name: 'Responder', last_name: 'Bunny', address: '1234 Right Turn, Albuquerque NM 22222',
|
|
132
|
+
@user = User.create name: 'Responder', last_name: 'Bunny', address: '1234 Right Turn, Albuquerque NM 22222',
|
|
133
|
+
email: 'bugs@bunny.com'
|
|
136
134
|
expect { visit "/users/#{@user.id}.xlsx" }.to_not raise_error
|
|
137
135
|
wb = write_and_open_workbook(page)
|
|
138
136
|
expect(wb.sheet.table[1][0]).to eq('User!')
|
|
139
137
|
end
|
|
140
138
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
visit '/another'
|
|
139
|
+
it 'handles missing format with render :xlsx' do
|
|
140
|
+
visit '/another.xlsx'
|
|
144
141
|
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
expect(page.response_headers['Content-Type']).to eq(Mime[:xlsx])
|
|
143
|
+
expect(page.response_headers['Content-Disposition']).to include('filename="filename_test.xlsx"')
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
end
|
|
145
|
+
wb = write_and_open_workbook(page)
|
|
146
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
|
151
147
|
end
|
|
152
148
|
|
|
153
|
-
|
|
154
|
-
Capybara.
|
|
155
|
-
|
|
156
|
-
end
|
|
149
|
+
Capybara.register_driver :mime_all do |app|
|
|
150
|
+
Capybara::RackTest::Driver.new(app, headers: { 'HTTP_ACCEPT' => '*/*' })
|
|
151
|
+
end
|
|
157
152
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
it 'mime all with render :xlsx and then :html' do
|
|
154
|
+
ActionView::Base.default_formats.delete :xlsx # see notes
|
|
155
|
+
Capybara.current_driver = :mime_all
|
|
156
|
+
visit '/another'
|
|
157
|
+
expect { visit '/home/only_html' }.to_not raise_error
|
|
158
|
+
ActionView::Base.default_formats.push :xlsx
|
|
163
159
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
160
|
+
# Output:
|
|
161
|
+
# default formats before : [:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif,
|
|
162
|
+
# :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :xlsx]
|
|
163
|
+
# default formats in my project : [:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif,
|
|
164
|
+
# :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip]
|
|
165
|
+
# default formats after render xlsx with */* : [:xlsx, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif,
|
|
166
|
+
# :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip]
|
|
168
167
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
# Failure/Error: visit '/home/only_html'
|
|
169
|
+
# ActionView::MissingTemplate:
|
|
170
|
+
# Missing template home/only_html, application/only_html with {:locale=>[:en], :formats=>[:xlsx, :text, :js, :css,
|
|
171
|
+
# :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form,
|
|
172
|
+
# :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :axlsx]}.
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
protected
|
|
176
|
+
|
|
176
177
|
def write_and_open_workbook(page, extension = 'xlsx')
|
|
177
178
|
file = "/tmp/workbook_temp.#{extension}"
|
|
178
|
-
File.open(file, 'wb') {|f| f.write(page.source) }
|
|
179
|
+
File.open(file, 'wb') { |f| f.write(page.source) }
|
|
179
180
|
wb = nil
|
|
180
|
-
expect{ wb = Workbook::Book.open(file) }.to_not raise_error
|
|
181
|
-
#File.unlink file
|
|
181
|
+
expect { wb = Workbook::Book.open(file) }.to_not raise_error
|
|
182
|
+
# File.unlink file
|
|
182
183
|
wb
|
|
183
184
|
end
|
|
184
185
|
end
|