workbook_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +207 -0
- data/MIT-LICENSE +20 -0
- data/README.md +216 -0
- data/Rakefile +29 -0
- data/lib/tasks/workbook_rails_tasks.rake +4 -0
- data/lib/workbook_rails.rb +5 -0
- data/lib/workbook_rails/action_controller.rb +51 -0
- data/lib/workbook_rails/engine.rb +25 -0
- data/lib/workbook_rails/template_handler.rb +23 -0
- data/lib/workbook_rails/version.rb +3 -0
- data/spec/ci.rb +3 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/home_controller.rb +60 -0
- data/spec/dummy/app/controllers/likes_controller.rb +18 -0
- data/spec/dummy/app/controllers/users_controller.rb +16 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/notifier.rb +14 -0
- data/spec/dummy/app/models/like.rb +3 -0
- data/spec/dummy/app/models/user.rb +8 -0
- data/spec/dummy/app/views/home/_cover_sheet.xlsx.wb +2 -0
- data/spec/dummy/app/views/home/generic.wb +5 -0
- data/spec/dummy/app/views/home/index.html.erb +4 -0
- data/spec/dummy/app/views/home/index.xls.wb +5 -0
- data/spec/dummy/app/views/home/index.xlsx.wb +5 -0
- data/spec/dummy/app/views/home/only_html.html.erb +1 -0
- data/spec/dummy/app/views/home/useheader.xlsx.wb +5 -0
- data/spec/dummy/app/views/home/withpartial.xlsx.wb +6 -0
- data/spec/dummy/app/views/layouts/application.html.erb +12 -0
- data/spec/dummy/app/views/likes/index.html.erb +17 -0
- data/spec/dummy/app/views/likes/index.xlsx.wb +5 -0
- data/spec/dummy/app/views/notifier/instructions.html.erb +14 -0
- data/spec/dummy/app/views/notifier/instructions.txt.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +23 -0
- data/spec/dummy/app/views/users/mailers/instructions.xlsx.wb +3 -0
- data/spec/dummy/app/views/users/respond_with.xlsx.wb +5 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +34 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +83 -0
- data/spec/dummy/config/environments/test.rb +44 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +2 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +17 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20120717192452_create_users.rb +12 -0
- data/spec/dummy/db/migrate/20121206210955_create_likes.rb +10 -0
- data/spec/dummy/db/schema.rb +32 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +8575 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/template_handler_spec.rb +35 -0
- data/spec/test_3.2.sh +4 -0
- data/spec/test_4.0.sh +4 -0
- data/spec/test_4.1.sh +4 -0
- data/spec/test_4.2.sh +4 -0
- data/spec/test_all_rails.sh +4 -0
- data/spec/workbook_mailer_spec.rb +16 -0
- data/spec/workbook_renderer_spec.rb +21 -0
- data/spec/workbook_request_spec.rb +168 -0
- metadata +365 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
5
|
+
ENV["RAILS_ENV"] = 'test'
|
6
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
7
|
+
require 'bundler'
|
8
|
+
require 'bundler/setup'
|
9
|
+
require 'rspec/rails'
|
10
|
+
require 'capybara/rspec'
|
11
|
+
require 'workbook_rails'
|
12
|
+
require 'pry'
|
13
|
+
|
14
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.color = true
|
18
|
+
config.formatter = 'documentation'
|
19
|
+
config.use_transactional_fixtures = false
|
20
|
+
config.infer_base_class_for_anonymous_controllers = false
|
21
|
+
config.order = "random"
|
22
|
+
end
|
23
|
+
|
24
|
+
module ::RSpec::Core
|
25
|
+
class ExampleGroup
|
26
|
+
include Capybara::DSL
|
27
|
+
include Capybara::RSpecMatchers
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require'spec_helper'
|
2
|
+
describe 'Workbook template handler' do
|
3
|
+
|
4
|
+
TH = WorkbookRails::TemplateHandler
|
5
|
+
VT = Struct.new(:source)
|
6
|
+
|
7
|
+
let( :handler ) { TH.new }
|
8
|
+
|
9
|
+
let( :template ) do
|
10
|
+
VT.new("workbook.sheet.table = Workbook::Table.new([['one', 'two', 'three'],['a', 'b', 'c']])")
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Rails #{Rails.version}" do
|
14
|
+
# for testing if the author is set
|
15
|
+
# before do
|
16
|
+
# Rails.stub_chain(:application, :config, :axlsx_author).and_return( 'Elmer Fudd' )
|
17
|
+
# end
|
18
|
+
|
19
|
+
it "has xlsx format" do
|
20
|
+
expect(handler.default_format).to eq(:xlsx)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "compiles to an excel spreadsheet" do
|
24
|
+
workbook, wb = nil
|
25
|
+
lookup_context = double(rendered_format: :xlsx)
|
26
|
+
eval TH.call(template)
|
27
|
+
workbook.write_to_xlsx('/tmp/wb_temp.xlsx')
|
28
|
+
expect{ wb = Workbook::Book.open('/tmp/wb_temp.xlsx') }.to_not raise_error
|
29
|
+
expect(wb.sheet.table[1][2]).to eq('c')
|
30
|
+
end
|
31
|
+
|
32
|
+
#TODO:
|
33
|
+
# Test if author field is set - does roo parse that?
|
34
|
+
end
|
35
|
+
end
|
data/spec/test_3.2.sh
ADDED
data/spec/test_4.0.sh
ADDED
data/spec/test_4.1.sh
ADDED
data/spec/test_4.2.sh
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Mailer", type: :request do
|
4
|
+
before :each do
|
5
|
+
@user = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "attaches an xlsx file" do
|
9
|
+
visit "/users/#{@user.id}/send_instructions"
|
10
|
+
last_email = ActionMailer::Base.deliveries.last
|
11
|
+
expect(last_email.to).to eq([@user.email])
|
12
|
+
expect(last_email.attachments.first).to be
|
13
|
+
expect(last_email.attachments.first.body.to_s).not_to be_empty
|
14
|
+
expect(last_email.attachments.first.content_type).to eq(Mime::XLSX.to_s + (Rails.version < '4.0' ? '; charset=UTF-8' : ''))
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require'spec_helper'
|
2
|
+
describe 'Workbook renderer' do
|
3
|
+
|
4
|
+
it "is registered" do
|
5
|
+
ActionController::Renderers::RENDERERS.include?(:xlsx)
|
6
|
+
ActionController::Renderers::RENDERERS.include?(:xls)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has xlsx mime type" do
|
10
|
+
expect(Mime::XLSX).to be
|
11
|
+
expect(Mime::XLSX.to_sym).to eq(:xlsx)
|
12
|
+
expect(Mime::XLSX.to_s).to eq("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has xls mime type" do
|
16
|
+
expect(Mime::XLS).to be
|
17
|
+
expect(Mime::XLS.to_sym).to eq(:xls)
|
18
|
+
expect(Mime::XLS.to_s).to eq("application/vnd.ms-excel")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe 'Workbook request', :type => :request do
|
3
|
+
|
4
|
+
it "has a working dummy app" do
|
5
|
+
@user1 = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
|
6
|
+
visit '/'
|
7
|
+
expect(page).to have_content("Hey, you")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "downloads an excel file from default respond_to" do
|
11
|
+
visit '/home.xlsx'
|
12
|
+
|
13
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s + "; charset=utf-8")
|
14
|
+
wb = write_and_open_workbook(page)
|
15
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "downloads an xls file from default respond_to" do
|
19
|
+
visit '/home.xls'
|
20
|
+
|
21
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLS.to_s + "; charset=utf-8")
|
22
|
+
wb = write_and_open_workbook(page, 'xls')
|
23
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "downloads an excel file from params format" do
|
27
|
+
visit '/home/generic.xlsx'
|
28
|
+
|
29
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s + "; charset=utf-8")
|
30
|
+
wb = write_and_open_workbook(page)
|
31
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "downloads an xls file from params format" do
|
35
|
+
visit '/home/generic.xls'
|
36
|
+
|
37
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLS.to_s + "; charset=utf-8")
|
38
|
+
wb = write_and_open_workbook(page, 'xls')
|
39
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "downloads an excel file from respond_to while specifying filename" do
|
43
|
+
visit '/useheader.xlsx'
|
44
|
+
|
45
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s)
|
46
|
+
expect(page.response_headers['Content-Disposition']).to include("filename=\"filename_test.xlsx\"")
|
47
|
+
|
48
|
+
wb = write_and_open_workbook(page)
|
49
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "downloads an excel file from respond_to while specifying filename in direct format" do
|
53
|
+
visit '/useheader.xlsx?set_direct=true'
|
54
|
+
|
55
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s + "; charset=utf-8")
|
56
|
+
expect(page.response_headers['Content-Disposition']).to include("filename=\"filename_test.xlsx\"")
|
57
|
+
|
58
|
+
wb = write_and_open_workbook(page)
|
59
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "downloads an excel file from render statement with filename" do
|
63
|
+
visit '/another.xlsx'
|
64
|
+
|
65
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX)
|
66
|
+
expect(page.response_headers['Content-Disposition']).to include("filename=\"filename_test.xlsx\"")
|
67
|
+
|
68
|
+
wb = write_and_open_workbook(page)
|
69
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "downloads an excel file with partial" do
|
73
|
+
visit '/withpartial.xlsx'
|
74
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s + "; charset=utf-8")
|
75
|
+
wb = write_and_open_workbook(page)
|
76
|
+
expect(wb.sheet.table[0][0]).to eq('Cover')
|
77
|
+
expect(wb[1].table[1][0]).to eq("Untie!")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "downloads an excel from render with file path" do
|
81
|
+
visit '/render_file_path.xlsx'
|
82
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s)
|
83
|
+
wb = write_and_open_workbook(page)
|
84
|
+
expect(wb.sheet.table[1][0]).to eq('User!')
|
85
|
+
end
|
86
|
+
|
87
|
+
it "handles nested resources" do
|
88
|
+
User.destroy_all
|
89
|
+
@user = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
|
90
|
+
@user.likes.create(:name => 'Carrots')
|
91
|
+
@user.likes.create(:name => 'Celery')
|
92
|
+
visit "/users/#{@user.id}/likes.xlsx"
|
93
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s + "; charset=utf-8")
|
94
|
+
wb = write_and_open_workbook(page)
|
95
|
+
expect(wb.sheet.table[0][0]).to eq('Bugs')
|
96
|
+
expect(wb.sheet.table[1][0]).to eq('Carrots')
|
97
|
+
expect(wb.sheet.table[2][0]).to eq('Celery')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "handles reference to absolute paths" do
|
101
|
+
User.destroy_all
|
102
|
+
@user = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
|
103
|
+
visit "/users/#{@user.id}/render_elsewhere.xlsx"
|
104
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s)
|
105
|
+
wb = write_and_open_workbook(page)
|
106
|
+
expect(wb.sheet.table[1][0]).to eq('User!')
|
107
|
+
|
108
|
+
[[1,false], [2,false], [3,true], [4,true], [5,false]].reverse.each do |s|
|
109
|
+
visit "/home/render_elsewhere.xlsx?type=#{s[0]}"
|
110
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX.to_s +
|
111
|
+
(s[1] ? "; charset=utf-8" : ''))
|
112
|
+
wb = write_and_open_workbook(page)
|
113
|
+
expect(wb.sheet.table[1][0]).to eq(s[0] == 5 ? 'Untie!' : 'User!')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "uses respond_with" do
|
118
|
+
User.destroy_all
|
119
|
+
@user = User.create name: 'Responder', last_name: 'Bunny', address: '1234 Right Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
|
120
|
+
expect { visit "/users/#{@user.id}.xlsx" }.to_not raise_error
|
121
|
+
wb = write_and_open_workbook(page)
|
122
|
+
expect(wb.sheet.table[1][0]).to eq('User!')
|
123
|
+
end
|
124
|
+
|
125
|
+
unless Rails.version < '3.2'
|
126
|
+
it "handles missing format with render :xlsx" do
|
127
|
+
visit '/another'
|
128
|
+
|
129
|
+
expect(page.response_headers['Content-Type']).to eq(Mime::XLSX)
|
130
|
+
expect(page.response_headers['Content-Disposition']).to include("filename=\"filename_test.xlsx\"")
|
131
|
+
|
132
|
+
wb = write_and_open_workbook(page)
|
133
|
+
expect(wb.sheet.table[1][0]).to eq('Untie!')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
unless Rails.version < '4.0'
|
138
|
+
Capybara.register_driver :mime_all do |app|
|
139
|
+
Capybara::RackTest::Driver.new(app, headers: { 'HTTP_ACCEPT' => '*/*' })
|
140
|
+
end
|
141
|
+
|
142
|
+
it "mime all with render :xlsx and then :html" do
|
143
|
+
ActionView::Base.default_formats.delete :xlsx # see notes
|
144
|
+
Capybara.current_driver = :mime_all
|
145
|
+
visit '/another'
|
146
|
+
expect{ visit '/home/only_html' }.to_not raise_error
|
147
|
+
|
148
|
+
# Output:
|
149
|
+
# default formats before : [:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :xlsx]
|
150
|
+
# default formats in my project : [:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip]
|
151
|
+
# default formats after render xlsx with */* : [:xlsx, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip]
|
152
|
+
|
153
|
+
# Failure/Error: visit '/home/only_html'
|
154
|
+
# ActionView::MissingTemplate:
|
155
|
+
# Missing template home/only_html, application/only_html with {:locale=>[:en], :formats=>[:xlsx, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :axlsx]}.
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
protected
|
160
|
+
def write_and_open_workbook(page, extension = 'xlsx')
|
161
|
+
file = "/tmp/workbook_temp.#{extension}"
|
162
|
+
File.open(file, 'wb') {|f| f.write(page.source) }
|
163
|
+
wb = nil
|
164
|
+
expect{ wb = Workbook::Book.open(file) }.to_not raise_error
|
165
|
+
File.unlink file
|
166
|
+
wb
|
167
|
+
end
|
168
|
+
end
|