Skip to content

Commit

Permalink
Merge 9506b5e into 4e9a8d7
Browse files Browse the repository at this point in the history
  • Loading branch information
correalucas committed Sep 5, 2019
2 parents 4e9a8d7 + 9506b5e commit 2a7db6f
Show file tree
Hide file tree
Showing 80 changed files with 1,009 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ env:
- RAILS_VERSION=4.2
- RAILS_VERSION=5.0
- RAILS_VERSION=5.1
# - RAILS_VERSION=5.2
- RAILS_VERSION=5.2
- RAILS_VERSION=6.0
rvm:
- 2.2.10
- 2.3.7
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

**September 5, 2019**: 0.5.3 release

- Improved Rails 6.0 compatibility re MIME type

**May 1st, 2018**: 0.5.2 release

- Improved Rails 5 compatibility re MIME type
Expand Down Expand Up @@ -75,7 +79,7 @@
**July 17, 2012**: 0.1.0 release

- Tests completed
- Acts_as_xlsx tested, example in docs
- Acts_as_xlsx tested, example in docs

**July 12, 2012**: 0.0.1 release

Expand Down
17 changes: 11 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ source "http://rubygems.org"
# development dependencies will be added by default to the :development group.
gemspec

ENV["RAILS_VERSION"] ||= '4.2'
ENV["RAILS_VERSION"] ||= '6.0'

case ENV['RAILS_VERSION']
when '6.0'
gem 'rails', "~> 6"
gem 'responders', '~> 3.0'
when '5.2'
gem 'rails', "~> 5.2"
gem 'responders', '~> 3.0'
when '5.1'
gem 'rails', "~> 5.1.0"
gem 'responders', '~> 2.0'
gem 'responders', '~> 3.0'
when '5.0'
gem 'rails', "~> 5.0.0"
gem 'rails', "~> 5.0"
gem 'responders', '~> 2.0'
when '4.2'
gem 'rails', "~> 4.2.0"
gem 'rails', "~> 4.2"
gem 'responders', '~> 2.0'
# when '4.1'
# gem 'rails', "~> 4.1.0"
Expand All @@ -33,8 +39,7 @@ gem "thin"
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
gem 'acts_as_xlsx', git: 'git://github.com/straydogstudio/acts_as_xlsx.git'
gem 'capybara', '~> 2.1'

gem 'acts_as_xlsx', git: 'https://github.com/straydogstudio/acts_as_xlsx.git'
# To use debugger
# gem 'pry-debugger'
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ source:

## Change log

**September 5, 2019**: 0.5.3 release

- Improved Rails 6.0 compatibility re MIME type

**May 1st, 2018**: 0.5.2 release

- Improved Rails 5 compatibility re MIME type
Expand Down
1 change: 0 additions & 1 deletion axlsx_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec-rails"
s.add_development_dependency "guard-rspec"
s.add_development_dependency "capybara"
s.add_development_dependency "acts_as_xlsx"
s.add_development_dependency "roo"
s.add_development_dependency "rubyzip"
s.add_development_dependency "sqlite3"
Expand Down
11 changes: 9 additions & 2 deletions lib/axlsx_rails/template_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ module Template::Handlers
class AxlsxBuilder

def default_format
Rails.version.to_f >= 5 ? Mime[:xlsx] : Mime::XLSX
case
when Rails.version.to_f >= 6
Mime[:xlsx].symbol
when Rails.version.to_f >= 5
Mime[:xlsx]
else
Mime::XLSX
end
end

def call(template, source = nil)
Expand All @@ -21,7 +28,7 @@ def call(template, source = nil)
builder << ":author => xlsx_author,"
builder << ":created_at => xlsx_created_at,"
builder << ":use_shared_strings => xlsx_use_shared_strings);"
builder << source || template.source
builder << (source || template.source)
builder << ";xlsx_package.to_stream.string;"
builder.string
end
Expand Down
2 changes: 1 addition & 1 deletion lib/axlsx_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module AxlsxRails
VERSION = '0.5.2'
VERSION = '0.5.3'
end
8 changes: 6 additions & 2 deletions spec/axlsx_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
# end

it "has xlsx format" do
expect(handler.default_format).to eq(mime_type)
if Rails::VERSION::MAJOR >= 6
expect(handler.default_format).to eq(mime_type.symbol)
else
expect(handler.default_format).to eq(mime_type)
end
end

it "compiles to an excel spreadsheet when passing in a source" do
Expand All @@ -27,7 +31,7 @@
eval( AB.new.call template, source )
xlsx_package.serialize('/tmp/axlsx_temp.xlsx')
expect{ wb = Roo::Excelx.new('/tmp/axlsx_temp.xlsx') }.to_not raise_error
expect(wb.cell(2,3)).to eq('c')
expect(wb.cell(2,3)).to eq('f')
end

it "compiles to an excel spreadsheet when inferring source from template " do
Expand Down
29 changes: 16 additions & 13 deletions spec/axlsx_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

it "has a working dummy app" do
@user1 = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
visit '/'
expect(page).to have_content("Hey, you")
end
Expand Down Expand Up @@ -60,8 +60,8 @@

it "downloads an excel file from acts_as_xlsx model" do
User.destroy_all
@user1 = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
@user2 = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
visit '/users.xlsx'
expect(page.response_headers['Content-Type']).to eq(mime_type.to_s + "; charset=utf-8")
File.open('/tmp/axlsx_temp.xlsx', 'w') {|f| f.write(page.source) }
Expand Down Expand Up @@ -117,6 +117,7 @@
it "uses respond_with" do
User.destroy_all
@user = User.create name: 'Responder', last_name: 'Bunny', address: '1234 Right Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
visit "/users/#{@user.id}.xlsx"
expect {
visit "/users/#{@user.id}.xlsx"
}.to_not raise_error
Expand Down Expand Up @@ -185,15 +186,17 @@ def puts_def_formats(title)
end
end

it "downloads an excel file when there is no action" do
User.destroy_all
@user1 = User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
@user2 = User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
visit '/users/noaction.xlsx'
expect(page.response_headers['Content-Type']).to eq(mime_type.to_s + "; charset=utf-8")
File.open('/tmp/axlsx_temp.xlsx', 'w') {|f| f.write(page.source) }
wb = nil
expect{ wb = Roo::Excelx.new('/tmp/axlsx_temp.xlsx') }.to_not raise_error
expect(wb.cell(3,2)).to eq('Bugs')
if Rails::VERSION::MAJOR < 6
it "downloads an excel file when there is no action" do
User.destroy_all
User.create name: 'Elmer', last_name: 'Fudd', address: '1234 Somewhere, Over NY 11111', email: 'elmer@fudd.com'
User.create name: 'Bugs', last_name: 'Bunny', address: '1234 Left Turn, Albuquerque NM 22222', email: 'bugs@bunny.com'
visit '/users/noaction.xlsx'
expect(page.response_headers['Content-Type']).to eq(mime_type.to_s + "; charset=utf-8")
File.open('/tmp/axlsx_temp.xlsx', 'w') {|f| f.write(page.source) }
wb = nil
expect{ wb = Roo::Excelx.new('/tmp/axlsx_temp.xlsx') }.to_not raise_error
expect(wb.cell(3,2)).to eq('Bugs')
end
end
end
11 changes: 4 additions & 7 deletions spec/ci.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/env ruby

if ENV['RAILS_VERSION'] =~ /^5.2/
puts "Testing Rails 5.2"
exit system('cd spec/dummy_5.2 && bundle install --without debug && bundle exec rake db:create && bundle exec rake db:migrate && cd ../../ && bundle exec rspec spec')
elsif ENV['RAILS_VERSION'] =~ /^5.1/
puts "Testing Rails 5.1"
exit system('cd spec/dummy_5.1 && bundle install --without debug && bundle exec rake db:create && bundle exec rake db:migrate && cd ../../ && bundle exec rspec spec')
if ENV['RAILS_VERSION'] =~ /^6.0/
puts "Testing Rails 6.0"
exit system('cd spec/dummy_6.0 && bundle install --without debug && rails db:reset && cd ../../ && bundle exec rspec spec')
elsif ENV['RAILS_VERSION'] =~ /^5/
puts "Testing Rails 5"
exit system('cd spec/dummy_5 && bundle install --without debug && bundle exec rake db:create && bundle exec rake db:migrate && cd ../../ && bundle exec rspec spec')
exit system('cd spec/dummy_5 && bundle install --without debug && rails db:reset && cd ../../ && bundle exec rspec spec')
elsif ENV['RAILS_VERSION'] =~ /^4/
puts "Testing Rails 4"
exit system('cd spec/dummy_4 && bundle install --without debug && bundle exec rake db:create && bundle exec rake db:migrate && cd ../../ && bundle exec rspec spec')
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Application < Rails::Application
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = false
config.active_record.whitelist_attributes = false if Rails::VERSION::MAJOR < 6

# Enable the asset pipeline
config.assets.enabled = true
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
config.action_dispatch.best_standards_support = :builtin

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.mass_assignment_sanitizer = :strict if Rails::VERSION::MAJOR < 6

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.active_record.auto_explain_threshold_in_seconds = 0.5 if Rails::VERSION::MAJOR < 6

# Do not compress assets
config.assets.compress = false
Expand Down
6 changes: 6 additions & 0 deletions spec/dummy_6.0/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks
Empty file.
13 changes: 13 additions & 0 deletions spec/dummy_6.0/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
15 changes: 15 additions & 0 deletions spec/dummy_6.0/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
5 changes: 5 additions & 0 deletions spec/dummy_6.0/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
Empty file.
56 changes: 56 additions & 0 deletions spec/dummy_6.0/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#---
# Excerpted from "Crafting Rails Applications",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/jvrails for more book information.
#---
class HomeController < ApplicationController
def index
respond_to do |format|
format.html
format.xlsx
end
end

def only_html; end

def another
render :xlsx => "index", :filename => "filename_test.xlsx"
end

def render_elsewhere
case params[:type]
when '1'
render :xlsx => "home/index", :template => 'users/index'
when '2'
render :xlsx => "users/index", :template => 'users/index'
when '3'
render template: "users/index"
when '4'
render "users/index"
else
render :xlsx => "index"
end
end

def render_file_path
render :xlsx => Rails.root.join('app','views','users','index')
end

def withpartial
end

def useheader
respond_to do |format|
format.xlsx {
if params[:set_direct]
response.headers['Content-Disposition'] = "attachment; filename=\"filename_test.xlsx\""
else
render xlsx: "useheader", filename: "filename_test.xlsx"
end
}
end
end
end
18 changes: 18 additions & 0 deletions spec/dummy_6.0/app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class LikesController < ApplicationController
# GET /likes
# GET /likes.json
def index
@user = User.find(params[:user_id])
@likes = @user.likes

respond_to do |format|
format.html # index.html.erb
format.xlsx
end
end

def render_elsewhere
@user = User.find(params[:user_id])
render :xlsx => "index", :template => 'users/index'
end
end
37 changes: 37 additions & 0 deletions spec/dummy_6.0/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class UsersController < ApplicationController
respond_to :xlsx, :html
layout Proc.new { |c| return (c.request.format.symbol == :xlsx ? false : :default )}

# GET /users
# GET /users.json
def index
@users = User.all

respond_to do |format|
format.html # index.html.erb
format.xlsx
end
end

def show
@user = User.find(params[:id])
respond_with(@user) do |format|
format.xlsx { render "respond_with.xlsx.axlsx" }
end
end

def send_instructions
@user = User.find(params[:user_id])
@user.send_instructions
render plain: "Email sent"
end

def export
@user = User.find(params[:id])
respond_to do |format|
format.xlsx do
render xlsx: "export", filename: "export_#{@user.id}"
end
end
end
end
2 changes: 2 additions & 0 deletions spec/dummy_6.0/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file.

0 comments on commit 2a7db6f

Please sign in to comment.