Skip to content

Commit ef500c8

Browse files
committed
drop support for ruby 1.9, activeadmin 0.6.6, and rails 3
add support for rails 5
1 parent 516a744 commit ef500c8

File tree

9 files changed

+62
-118
lines changed

9 files changed

+62
-118
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ rvm:
44
- 2.2
55

66
gemfile:
7-
- gemfiles/rails_32.gemfile
87
- gemfiles/rails_42.gemfile
8+
- gemfiles/rails_51.gemfile
99

1010
script:
1111
- bundle exec rake setup

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This gem borrows heavily from [activeadmin-axlsx] and [to_xls].
1919
Add the following to your Gemfile. All resource index views will now include a link for download directly to xls.
2020

2121
```ruby
22-
gem 'activeadmin-xls', '~>1.1.0'
22+
gem 'activeadmin-xls', '2.0.0-alpha'
2323
```
2424

2525
For Active Admin 1.0, you will also have to update config/initializers/active_admin.rb. Update the download\_links setting to include xls:
@@ -132,32 +132,32 @@ Running specs for this gem requires that you construct a rails application.
132132

133133
To execute the specs, navigate to the gem directory, run bundle install and run these to rake tasks:
134134

135-
### Rails 3.2
135+
### Rails 4.2
136136

137137
```text
138-
bundle install --gemfile=gemfiles/rails_32.gemfile
138+
bundle install --gemfile=gemfiles/rails_42.gemfile
139139
```
140140

141141
```text
142-
BUNDLE_GEMFILE=gemfiles/rails_32.gemfile bundle exec rake setup
142+
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake setup
143143
```
144144

145145
```text
146-
BUNDLE_GEMFILE=gemfiles/rails_32.gemfile bundle exec rake
146+
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake
147147
```
148148

149-
### Rails 4.2
149+
### Rails 5.1
150150

151151
```text
152-
bundle install --gemfile=gemfiles/rails_42.gemfile
152+
bundle install --gemfile=gemfiles/rails_51.gemfile
153153
```
154154

155155
```text
156-
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake setup
156+
BUNDLE_GEMFILE=gemfiles/rails_51.gemfile bundle exec rake setup
157157
```
158158

159159
```text
160-
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake
160+
BUNDLE_GEMFILE=gemfiles/rails_51.gemfile bundle exec rake
161161
```
162162

163163
[Active Admin]:https://www.activeadmin.info/

activeadmin-xls.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Gem::Specification.new do |s|
2121

2222
s.files = git_tracked_files - gem_ignored_files
2323

24-
s.add_runtime_dependency 'activeadmin', '>= 0.6.6', '< 2'
24+
s.add_runtime_dependency 'activeadmin', '>= 1.0.0', '< 2'
2525
s.add_runtime_dependency 'spreadsheet', '~> 1.0'
2626

27-
s.required_ruby_version = '>= 1.9.2'
27+
s.required_ruby_version = '>= 2.0.0'
2828
s.require_path = 'lib'
2929
end
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,14 @@ ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
66

77
eval_gemfile(File.expand_path(File.join('..', 'Gemfile'), __dir__))
88

9-
gem 'rails', '3.2.22.5'
10-
11-
gem 'activeadmin', '0.6.6'
12-
13-
group :assets do
14-
gem 'coffee-rails', '~> 3.2.1'
15-
gem 'sass-rails', '~> 3.2.3'
16-
17-
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
18-
# gem 'therubyracer', :platforms => :ruby
19-
20-
gem 'uglifier', '>= 1.0.3'
21-
end
9+
gem 'activeadmin', '1.2.1'
10+
gem 'devise', '~> 4.2'
11+
gem 'rails', '5.1.5'
12+
gem 'turbolinks', '~> 5.0.0'
13+
gem 'tzinfo-data'
2214

2315
group :test do
24-
gem 'shoulda-matchers', '~> 2.8.0'
16+
gem 'shoulda-matchers', '~> 3.1'
2517
if ruby_major_version > 2 || (ruby_major_version == 2 && ruby_minor_version > 1)
2618
gem 'test-unit', '~> 3.0'
2719
end

lib/active_admin/xls/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Engine < ::Rails::Engine
1414
ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Xls::DSL
1515
ActiveAdmin::Resource.send :include, ActiveAdmin::Xls::ResourceExtension
1616
ActiveAdmin::ResourceController.send(
17-
:include,
17+
:prepend,
1818
ActiveAdmin::Xls::ResourceControllerExtension
1919
)
2020
end

lib/active_admin/xls/resource_controller_extension.rb

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ module ActiveAdmin
22
module Xls
33
# Extends the resource controller to respond to xls requests
44
module ResourceControllerExtension
5-
def self.included(base)
6-
base.send :alias_method_chain, :per_page, :xls
7-
base.send :alias_method_chain, :index, :xls
8-
base.send :alias_method_chain, :rescue_active_admin_access_denied, :xls
9-
base.send :respond_to, :xls
5+
def self.prepended(base)
6+
base.send :respond_to, :xls, only: :index
107
end
118

129
# Patches index to respond to requests with xls mime type by
1310
# sending a generated xls document serializing the current
1411
# collection
15-
def index_with_xls
16-
index_without_xls do |format|
12+
def index
13+
super do |format|
1714
format.xls do
1815
xls = active_admin_config.xls_builder.serialize(xls_collection,
1916
view_context)
@@ -31,7 +28,7 @@ def index_with_xls
3128
# configure activeadmin to respond propertly to xls requests
3229
#
3330
# param exception [Exception] unauthorized access error
34-
def rescue_active_admin_access_denied_with_xls(exception)
31+
def rescue_active_admin_access_denied(exception)
3532
if request.format == Mime::Type.lookup_by_extension(:xls)
3633
respond_to do |format|
3734
format.xls do
@@ -40,23 +37,10 @@ def rescue_active_admin_access_denied_with_xls(exception)
4037
end
4138
end
4239
else
43-
rescue_active_admin_access_denied_without_xls(exception)
40+
super(exception)
4441
end
4542
end
4643

47-
# Patches per_page to use the CSV record max for pagination
48-
# when the format is xls
49-
#
50-
# @return [Integer] maximum records per page
51-
def per_page_with_xls
52-
if request.format == Mime::Type.lookup_by_extension(:xls)
53-
return max_per_page if respond_to?(:max_per_page, true)
54-
active_admin_config.max_per_page
55-
end
56-
57-
per_page_without_xls
58-
end
59-
6044
# Returns a filename for the xls file using the collection_name
6145
# and current date such as 'my-articles-2011-06-24.xls'.
6246
#
@@ -70,11 +54,7 @@ def xls_filename
7054
# It uses the find_collection function if it is available, and uses
7155
# collection if find_collection isn't available.
7256
def xls_collection
73-
if method(:find_collection).arity.zero?
74-
collection
75-
else
76-
find_collection except: :pagination
77-
end
57+
find_collection except: :pagination
7858
end
7959
end
8060
end

lib/active_admin/xls/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ActiveAdmin
22
module Xls
33
# ActiveAdmin XLS gem version
4-
VERSION = '1.1.0'.freeze
4+
VERSION = '2.0.0-alpha'.freeze
55
end
66
end

spec/support/rails_template.rb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,43 @@
2424
"\ncucumber:\n secret_key_base: #{cucumber_secret}"
2525
end
2626

27+
base_record = if Rails::VERSION::MAJOR >= 5
28+
'ApplicationRecord'
29+
else
30+
'ActiveRecord::Base'
31+
end
32+
2733
# Generate some test models
2834
generate :model, 'post title:string body:text published_at:datetime author_id:integer category_id:integer'
29-
inject_into_file 'app/models/post.rb', " belongs_to :author, class_name: 'User'\n belongs_to :category\n accepts_nested_attributes_for :author\n", after: "class Post < ActiveRecord::Base\n"
30-
# Rails 3.2.3 model generator declare attr_accessible
31-
if Rails::VERSION::MAJOR == 3
32-
inject_into_file 'app/models/post.rb',
33-
" attr_accessible :author\n",
34-
before: 'end'
35-
end
35+
post_model_setup = if Rails::VERSION::MAJOR >= 5
36+
<<-MODEL
37+
belongs_to :author, class_name: 'User'
38+
belongs_to :category, optional: true
39+
accepts_nested_attributes_for :author
40+
MODEL
41+
else
42+
<<-MODEL
43+
belongs_to :author, class_name: 'User'
44+
belongs_to :category
45+
accepts_nested_attributes_for :author
46+
MODEL
47+
end
48+
inject_into_file 'app/models/post.rb',
49+
post_model_setup,
50+
after: "class Post < #{base_record}\n"
51+
3652
generate :model, 'user type:string first_name:string last_name:string username:string age:integer'
3753
inject_into_file 'app/models/user.rb',
3854
" has_many :posts, foreign_key: 'author_id'\n",
39-
after: "class User < ActiveRecord::Base\n"
55+
after: "class User < #{base_record}\n"
56+
4057
generate :model, 'publisher --migration=false --parent=User'
58+
4159
generate :model, 'category name:string description:text'
4260
inject_into_file 'app/models/category.rb',
4361
" has_many :posts\n accepts_nested_attributes_for :posts\n",
44-
after: "class Category < ActiveRecord::Base\n"
62+
after: "class Category < #{base_record}\n"
63+
4564
generate :model, 'store name:string'
4665

4766
# Generate a model with string ids
@@ -65,13 +84,7 @@ def set_id
6584

6685
inject_into_file 'app/models/tag.rb',
6786
id_model_setup,
68-
after: "class Tag < ActiveRecord::Base\n"
69-
70-
if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1 # Rails 3.1 Gotcha
71-
gsub_file 'app/models/tag.rb',
72-
/self\.primary_key.*$/,
73-
'define_attr_method :primary_key, :id'
74-
end
87+
after: "class Tag < #{base_record}\n"
7588

7689
# Configure default_url_options in test environment
7790
inject_into_file(
@@ -97,25 +110,14 @@ def set_id
97110

98111
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
99112

100-
if Rails::VERSION::MAJOR == 3
101-
# we need this routing path, named "logout_path", for testing
102-
route <<-ROUTE
103-
devise_scope :user do
104-
match '/admin/logout' => 'active_admin/devise/sessions#destroy', as: :logout
105-
end
106-
ROUTE
107-
end
108-
109113
generate :'active_admin:install'
110114

111115
run 'rm -r test'
112116
run 'rm -r spec'
113117

114-
if Rails::VERSION::MAJOR > 3
115-
inject_into_file 'config/initializers/active_admin.rb',
116-
" config.download_links = %i[csv xml json xls]\n",
117-
after: " # == Download Links\n"
118-
end
118+
inject_into_file 'config/initializers/active_admin.rb',
119+
" config.download_links = %i[csv xml json xls]\n",
120+
after: " # == Download Links\n"
119121

120122
# Setup a root path for devise
121123
route "root to: 'admin/dashboard#index'"
Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
require 'spec_helper'
2-
describe ActiveAdmin::ResourceController do
2+
describe Admin::CategoriesController, type: :controller do
33
let(:mime) { Mime::Type.lookup_by_extension(:xls) }
44

5-
let(:request) do
6-
ActionController::TestRequest.new.tap do |test_request|
7-
test_request.accept = mime
8-
end
9-
end
10-
11-
let(:response) { ActionController::TestResponse.new }
12-
13-
let(:controller) do
14-
Admin::CategoriesController.new.tap do |controller|
15-
controller.request = request
16-
controller.response = response
17-
end
18-
end
19-
205
let(:filename) do
216
"#{controller.resource_class.to_s.downcase.pluralize}-#{Time.now.strftime('%Y-%m-%d')}.xls"
227
end
@@ -27,26 +12,11 @@
2712

2813
context 'when making requests with the xls mime type' do
2914
it 'returns xls attachment when requested' do
30-
controller.send :index
15+
request.accept = mime
16+
get :index
3117
disposition = "attachment; filename=\"#{filename}\""
3218
expect(response.headers['Content-Disposition']).to eq(disposition)
3319
expect(response.headers['Content-Transfer-Encoding']).to eq('binary')
3420
end
35-
36-
it 'returns max_csv_records for per_page' do
37-
# this might need to go away!
38-
max_csv_records = if controller.respond_to?(:max_csv_records, true)
39-
controller.send(:max_csv_records)
40-
else
41-
controller.send(:per_page)
42-
end
43-
expect(controller.send(:per_page)).to eq(max_csv_records)
44-
end
45-
46-
it 'uses the default per_page when we do not specify xls mime type' do
47-
controller.request.accept = 'text/html'
48-
aa_default_per_page = ActiveAdmin.application.default_per_page
49-
expect(controller.send(:per_page)).to eq(aa_default_per_page)
50-
end
5121
end
5222
end

0 commit comments

Comments
 (0)