activeadmin-xls 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemignore +1 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +16 -3
- data/Gemfile +2 -15
- data/README.md +24 -4
- data/Rakefile +10 -10
- data/activeadmin-xls.gemspec +5 -3
- data/gemfiles/rails_32.gemfile +30 -0
- data/gemfiles/rails_42.gemfile +22 -0
- data/lib/active_admin/xls/builder.rb +47 -17
- data/lib/active_admin/xls/resource_controller_extension.rb +11 -4
- data/lib/active_admin/xls/version.rb +1 -1
- data/spec/spec_helper.rb +18 -5
- data/spec/support/rails_template.rb +64 -35
- data/spec/support/rails_template_with_data.rb +23 -20
- data/spec/support/templates/en.yml +1 -1
- data/spec/xls/unit/build_download_format_links_spec.rb +11 -7
- data/spec/xls/unit/builder_spec.rb +90 -91
- data/spec/xls/unit/dsl_spec.rb +29 -22
- data/spec/xls/unit/resource_controller_spec.rb +18 -10
- data/spec/xls/unit/resource_spec.rb +6 -6
- metadata +6 -16
- data/.bundle/config +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3cefe4337bc929cc027541a8b378764fcee9c29
|
4
|
+
data.tar.gz: 6ece12827ba7c2e0b85772b357c368a29d973c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a505457094d423aad3857be11f8aaf26adafa48957678296019324c15736be6bc89c40be0b41e4e3ea79ed17d9abd205e4463937aca9f40618193bf7eb3e8de4
|
7
|
+
data.tar.gz: 689a4ae242134e3cc0e7d7729b539eadca9349bbd141431422b7f0a83b10be7b3f72012ec60c92019b036973b9debe6f3e0b9ef947d35f815a51bb2dffb9c4a2
|
data/.gemignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.bundle/*
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.0.
|
3
|
+
## 1.0.5
|
4
4
|
|
5
|
-
###
|
5
|
+
### Updates
|
6
6
|
|
7
|
-
*
|
7
|
+
* Fix #1 - Unnecessary database access
|
8
|
+
* Fix broken tests
|
9
|
+
|
10
|
+
## 1.0.4
|
11
|
+
|
12
|
+
### Updates
|
13
|
+
|
14
|
+
* Minor bug fixes / typo corrections
|
8
15
|
|
9
16
|
## 1.0.3
|
10
17
|
|
@@ -12,6 +19,12 @@
|
|
12
19
|
|
13
20
|
* Move require rake from gemspec to lib/activeadmin-xls.rb [#4][] by [@ejaypcanaria][]
|
14
21
|
|
22
|
+
## 1.0.2
|
23
|
+
|
24
|
+
### Bug Fixes
|
25
|
+
|
26
|
+
* Fixes undefined local variable or `method max_per_page` [#3][] by [@rewritten][]
|
27
|
+
|
15
28
|
<!--- Link List --->
|
16
29
|
[#3]: https://github.com/thambley/activeadmin-xls/issues/3
|
17
30
|
[#4]: https://github.com/thambley/activeadmin-xls/pull/4
|
data/Gemfile
CHANGED
@@ -1,30 +1,17 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activeadmin', '~> 1.0'
|
4
3
|
gem 'spreadsheet', '~> 1.1', '>= 1.1.4'
|
5
4
|
|
6
5
|
group :development, :test do
|
7
|
-
gem 'haml', require: false
|
8
6
|
gem 'rails-i18n' # Gives us default i18n for many languages
|
9
|
-
gem 'rdiscount' # For yard
|
10
|
-
gem 'sprockets'
|
11
7
|
gem 'sqlite3'
|
12
8
|
gem 'yard'
|
13
9
|
end
|
14
10
|
|
15
11
|
group :test do
|
16
|
-
gem 'capybara'
|
17
12
|
gem 'cucumber-rails', require: false
|
18
13
|
gem 'database_cleaner'
|
19
|
-
gem '
|
20
|
-
gem '
|
21
|
-
gem 'inherited_resources'
|
22
|
-
gem 'jasmine'
|
23
|
-
gem 'jslint_on_rails', '~> 1.0.6'
|
24
|
-
gem 'launchy'
|
25
|
-
gem 'rspec-mocks'
|
26
|
-
gem 'rspec-rails'
|
27
|
-
gem 'sass-rails'
|
28
|
-
gem 'shoulda-matchers', '1.0.0'
|
14
|
+
gem 'rspec-mocks', '~> 3.7'
|
15
|
+
gem 'rspec-rails', '~> 3.7'
|
29
16
|
gem 'simplecov', require: false
|
30
17
|
end
|
data/README.md
CHANGED
@@ -113,15 +113,35 @@ end
|
|
113
113
|
## Specs
|
114
114
|
|
115
115
|
Running specs for this gem requires that you construct a rails application.
|
116
|
-
|
117
|
-
run bundle install and run these to rake tasks:
|
116
|
+
|
117
|
+
To execute the specs, navigate to the gem directory, run bundle install and run these to rake tasks:
|
118
|
+
|
119
|
+
### Rails 3.2
|
120
|
+
|
121
|
+
```text
|
122
|
+
bundle install --gemfile=gemfiles/rails_32.gemfile
|
123
|
+
```
|
124
|
+
|
125
|
+
```text
|
126
|
+
BUNDLE_GEMFILE=gemfiles/rails_32.gemfile bundle exec rake setup
|
127
|
+
```
|
128
|
+
|
129
|
+
```text
|
130
|
+
BUNDLE_GEMFILE=gemfiles/rails_32.gemfile bundle exec rake
|
131
|
+
```
|
132
|
+
|
133
|
+
### Rails 4.2
|
134
|
+
|
135
|
+
```text
|
136
|
+
bundle install --gemfile=gemfiles/rails_42.gemfile
|
137
|
+
```
|
118
138
|
|
119
139
|
```text
|
120
|
-
bundle exec rake setup
|
140
|
+
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake setup
|
121
141
|
```
|
122
142
|
|
123
143
|
```text
|
124
|
-
bundle exec rake
|
144
|
+
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake
|
125
145
|
```
|
126
146
|
|
127
147
|
## Copyright and License
|
data/Rakefile
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
3
|
-
require "rspec/core/rake_task"
|
2
|
+
require 'rspec/core/rake_task'
|
4
3
|
|
5
|
-
desc
|
4
|
+
desc 'Creates a test rails app for the specs to run against'
|
6
5
|
task :setup do
|
7
6
|
require 'rails/version'
|
8
|
-
system(
|
7
|
+
system('mkdir spec/rails') unless File.exist?('spec/rails')
|
8
|
+
puts "system \"bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template_with_data.rb\""
|
9
9
|
system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template_with_data.rb"
|
10
10
|
end
|
11
11
|
|
12
12
|
RSpec::Core::RakeTask.new
|
13
|
-
task :
|
14
|
-
task :
|
13
|
+
task default: :spec
|
14
|
+
task test: :spec
|
15
15
|
|
16
|
-
desc
|
16
|
+
desc 'build the gem'
|
17
17
|
task :build do
|
18
|
-
system
|
18
|
+
system 'gem build activeadmin-xls.gemspec'
|
19
19
|
end
|
20
|
-
desc
|
21
|
-
task :
|
20
|
+
desc 'build and release the gem'
|
21
|
+
task release: :build do
|
22
22
|
system "gem push activeadmin-xls-#{ActiveAdmin::Xls::VERSION}.gem"
|
23
23
|
end
|
data/activeadmin-xls.gemspec
CHANGED
@@ -15,9 +15,11 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.description = <<-DESC
|
16
16
|
This gem provides excel/xls downloads for resources in Active Admin.
|
17
17
|
DESC
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
git_tracked_files = `git ls-files`.split("\n").sort
|
20
|
+
gem_ignored_files = `git ls-files -i -X .gemignore`.split("\n")
|
21
|
+
|
22
|
+
s.files = git_tracked_files - gem_ignored_files
|
21
23
|
|
22
24
|
s.add_runtime_dependency 'activeadmin', '>= 0.6.6', '< 2'
|
23
25
|
s.add_runtime_dependency 'spreadsheet', '~> 1.0'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
source 'https://rubygems.org'
|
3
|
+
|
4
|
+
ruby_major_version = RUBY_VERSION.split('.')[0].to_i
|
5
|
+
ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
|
6
|
+
|
7
|
+
eval_gemfile(File.expand_path(File.join('..', 'Gemfile'), __dir__))
|
8
|
+
|
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
|
22
|
+
|
23
|
+
group :test do
|
24
|
+
gem 'shoulda-matchers', '~> 2.8.0'
|
25
|
+
if ruby_major_version > 2 || (ruby_major_version == 2 && ruby_minor_version > 1)
|
26
|
+
gem 'test-unit', '~> 3.0'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
gemspec path: "../"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
source 'https://rubygems.org'
|
3
|
+
|
4
|
+
ruby_major_version = RUBY_VERSION.split('.')[0].to_i
|
5
|
+
ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
|
6
|
+
|
7
|
+
eval_gemfile(File.expand_path(File.join('..', 'Gemfile'), __dir__))
|
8
|
+
|
9
|
+
gem 'activeadmin', '1.0.0'
|
10
|
+
gem 'devise', '~> 4.2'
|
11
|
+
gem 'rails', '4.2.10'
|
12
|
+
gem 'turbolinks', '~> 5.0.0'
|
13
|
+
gem 'tzinfo-data'
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'shoulda-matchers', '~> 3.1'
|
17
|
+
if ruby_major_version > 2 || (ruby_major_version == 2 && ruby_minor_version > 1)
|
18
|
+
gem 'test-unit', '~> 3.0'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
gemspec path: "../"
|
@@ -29,7 +29,10 @@ module ActiveAdmin
|
|
29
29
|
# @see ActiveAdmin::Axlsx::DSL
|
30
30
|
def initialize(resource_class, options = {}, &block)
|
31
31
|
@skip_header = false
|
32
|
-
@
|
32
|
+
@resource_class = resource_class
|
33
|
+
@columns = []
|
34
|
+
@columns_loaded = false
|
35
|
+
@column_updates = []
|
33
36
|
parse_options options
|
34
37
|
instance_eval(&block) if block_given?
|
35
38
|
end
|
@@ -60,9 +63,7 @@ module ActiveAdmin
|
|
60
63
|
|
61
64
|
# The scope to use when looking up column names to generate the
|
62
65
|
# report header
|
63
|
-
|
64
|
-
@i18n_scope ||= nil
|
65
|
-
end
|
66
|
+
attr_reader :i18n_scope
|
66
67
|
|
67
68
|
# This is the I18n scope that will be used when looking up your
|
68
69
|
# colum names in the current I18n locale.
|
@@ -83,7 +84,12 @@ module ActiveAdmin
|
|
83
84
|
end
|
84
85
|
|
85
86
|
# The columns this builder will be serializing
|
86
|
-
|
87
|
+
def columns
|
88
|
+
# execute each update from @column_updates
|
89
|
+
# set @columns_loaded = true
|
90
|
+
load_columns unless @columns_loaded
|
91
|
+
@columns
|
92
|
+
end
|
87
93
|
|
88
94
|
# The collection we are serializing.
|
89
95
|
# @note This is only available after serialize has been called,
|
@@ -94,34 +100,50 @@ module ActiveAdmin
|
|
94
100
|
# only render specific columns. To remove specific columns use
|
95
101
|
# ignore_column.
|
96
102
|
def clear_columns
|
103
|
+
@columns_loaded = true
|
104
|
+
@column_updates = []
|
105
|
+
|
97
106
|
@columns = []
|
98
107
|
end
|
99
108
|
|
100
109
|
# Clears the default columns array so you can whitelist only the columns
|
101
110
|
# you want to export
|
102
|
-
|
103
|
-
@columns = []
|
104
|
-
end
|
111
|
+
alias whitelist clear_columns
|
105
112
|
|
106
113
|
# Add a column
|
107
114
|
# @param [Symbol] name The name of the column.
|
108
115
|
# @param [Proc] block A block of code that is executed on the resource
|
109
116
|
# when generating row data for this column.
|
110
117
|
def column(name, &block)
|
111
|
-
@
|
118
|
+
if @columns_loaded
|
119
|
+
columns << Column.new(name, block)
|
120
|
+
else
|
121
|
+
column_lambda = lambda do
|
122
|
+
column(name, &block)
|
123
|
+
end
|
124
|
+
@column_updates << column_lambda
|
125
|
+
end
|
112
126
|
end
|
113
127
|
|
114
128
|
# removes columns by name
|
115
129
|
# each column_name should be a symbol
|
116
130
|
def delete_columns(*column_names)
|
117
|
-
@
|
131
|
+
if @columns_loaded
|
132
|
+
columns.delete_if { |column| column_names.include?(column.name) }
|
133
|
+
else
|
134
|
+
delete_lambda = lambda do
|
135
|
+
delete_columns(*column_names)
|
136
|
+
end
|
137
|
+
@column_updates << delete_lambda
|
138
|
+
end
|
118
139
|
end
|
119
140
|
|
120
141
|
# Serializes the collection provided
|
121
142
|
# @return [Spreadsheet::Workbook]
|
122
|
-
def serialize(collection, view_context)
|
143
|
+
def serialize(collection, view_context = nil)
|
123
144
|
@collection = collection
|
124
145
|
@view_context = view_context
|
146
|
+
load_columns unless @columns_loaded
|
125
147
|
apply_filter @before_filter
|
126
148
|
export_collection(collection)
|
127
149
|
apply_filter @after_filter
|
@@ -145,6 +167,15 @@ module ActiveAdmin
|
|
145
167
|
|
146
168
|
private
|
147
169
|
|
170
|
+
def load_columns
|
171
|
+
return if @columns_loaded
|
172
|
+
@columns = resource_columns(@resource_class)
|
173
|
+
@columns_loaded = true
|
174
|
+
@column_updates.each(&:call)
|
175
|
+
@column_updates = []
|
176
|
+
columns
|
177
|
+
end
|
178
|
+
|
148
179
|
def to_stream
|
149
180
|
stream = StringIO.new('')
|
150
181
|
book.write stream
|
@@ -158,11 +189,11 @@ module ActiveAdmin
|
|
158
189
|
|
159
190
|
def export_collection(collection)
|
160
191
|
return if columns.none?
|
161
|
-
row_index =
|
192
|
+
row_index = sheet.dimensions[1]
|
162
193
|
|
163
194
|
unless @skip_header
|
164
|
-
header_row(collection)
|
165
|
-
row_index
|
195
|
+
header_row(sheet.row(row_index), collection)
|
196
|
+
row_index += 1
|
166
197
|
end
|
167
198
|
|
168
199
|
collection.each do |resource|
|
@@ -173,14 +204,13 @@ module ActiveAdmin
|
|
173
204
|
|
174
205
|
# tranform column names into array of localized strings
|
175
206
|
# @return [Array]
|
176
|
-
def header_row(collection)
|
177
|
-
row = sheet.row(0)
|
207
|
+
def header_row(row, collection)
|
178
208
|
apply_format_to_row(row, create_format(header_format))
|
179
209
|
fill_row(row, header_data_for(collection))
|
180
210
|
end
|
181
211
|
|
182
212
|
def header_data_for(collection)
|
183
|
-
resource = collection.first
|
213
|
+
resource = collection.first || @resource_class.new
|
184
214
|
columns.map do |column|
|
185
215
|
column.localized_name(i18n_scope) if in_scope(resource, column)
|
186
216
|
end.compact
|
@@ -10,15 +10,22 @@ module ActiveAdmin
|
|
10
10
|
|
11
11
|
def index_with_xls
|
12
12
|
index_without_xls do |format|
|
13
|
-
yield format if block_given?
|
14
|
-
|
15
13
|
format.xls do
|
16
|
-
|
17
|
-
|
14
|
+
xls_collection = if method(:find_collection).arity.zero?
|
15
|
+
collection
|
16
|
+
else
|
17
|
+
find_collection except: :pagination
|
18
|
+
end
|
19
|
+
xls = active_admin_config.xls_builder.serialize(
|
20
|
+
xls_collection,
|
21
|
+
view_context
|
22
|
+
)
|
18
23
|
send_data(xls,
|
19
24
|
filename: xls_filename,
|
20
25
|
type: Mime::Type.lookup_by_extension(:xls))
|
21
26
|
end
|
27
|
+
|
28
|
+
yield(format) if block_given?
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,25 +1,38 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
SimpleCov.start do
|
3
|
-
add_filter
|
3
|
+
add_filter '/rails/'
|
4
|
+
add_filter '/spec/'
|
4
5
|
end
|
5
6
|
|
7
|
+
ENV['RAILS_ENV'] = 'test'
|
8
|
+
|
6
9
|
# prepare ENV for rails
|
7
10
|
require 'rails'
|
8
|
-
ENV['RAILS_ROOT'] = File.expand_path(
|
11
|
+
ENV['RAILS_ROOT'] = File.expand_path(
|
12
|
+
"../rails/rails-#{Rails::VERSION::STRING}",
|
13
|
+
__FILE__
|
14
|
+
)
|
9
15
|
|
10
16
|
# ensure testing application is in place
|
11
|
-
unless File.
|
12
|
-
puts
|
17
|
+
unless File.exist?(ENV['RAILS_ROOT'])
|
18
|
+
puts 'Please run bundle exec rake setup before running the specs.'
|
13
19
|
exit
|
14
20
|
end
|
15
21
|
|
16
22
|
# load up activeadmin and activeadmin-xls
|
23
|
+
require 'active_record'
|
24
|
+
require 'active_admin'
|
25
|
+
require 'devise'
|
17
26
|
require 'activeadmin-xls'
|
18
|
-
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] +
|
27
|
+
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + '/app/admin']
|
28
|
+
|
19
29
|
# start up rails
|
20
30
|
require ENV['RAILS_ROOT'] + '/config/environment'
|
21
31
|
|
22
32
|
# and finally,here's rspec
|
23
33
|
require 'rspec/rails'
|
34
|
+
|
35
|
+
# Disabling authentication in specs so that we don't have to worry about
|
36
|
+
# it allover the place
|
24
37
|
ActiveAdmin.application.authentication_method = false
|
25
38
|
ActiveAdmin.application.current_user_method = false
|
@@ -1,73 +1,102 @@
|
|
1
1
|
# Rails template to build the sample app for specs
|
2
2
|
|
3
3
|
# Create a cucumber database and environment
|
4
|
-
copy_file File.expand_path('../templates/cucumber.rb', __FILE__),
|
5
|
-
|
4
|
+
copy_file File.expand_path('../templates/cucumber.rb', __FILE__),
|
5
|
+
'config/environments/cucumber.rb'
|
6
|
+
copy_file File.expand_path('../templates/cucumber_with_reloading.rb', __FILE__),
|
7
|
+
'config/environments/cucumber_with_reloading.rb'
|
6
8
|
|
7
9
|
gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n"
|
8
|
-
gsub_file 'config/database.yml',
|
9
|
-
|
10
|
+
gsub_file 'config/database.yml',
|
11
|
+
/\z/,
|
12
|
+
"\ncucumber:\n <<: *test\n database: db/cucumber.sqlite3"
|
13
|
+
gsub_file 'config/database.yml',
|
14
|
+
/\z/,
|
15
|
+
"\ncucumber_with_reloading:\n <<: *test\n database: db/cucumber.sqlite3"
|
10
16
|
|
11
17
|
# Generate some test models
|
12
|
-
generate :model,
|
13
|
-
inject_into_file 'app/models/post.rb', " belongs_to :author, :
|
18
|
+
generate :model, 'post title:string body:text published_at:datetime author_id:integer category_id:integer'
|
19
|
+
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"
|
14
20
|
# Rails 3.2.3 model generator declare attr_accessible
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
if Rails::VERSION::MAJOR == 3
|
22
|
+
inject_into_file 'app/models/post.rb',
|
23
|
+
" attr_accessible :author\n",
|
24
|
+
before: 'end'
|
25
|
+
end
|
26
|
+
generate :model, 'user type:string first_name:string last_name:string username:string age:integer'
|
27
|
+
inject_into_file 'app/models/user.rb', " has_many :posts, foreign_key: 'author_id'\n", after: "class User < ActiveRecord::Base\n"
|
28
|
+
generate :model, 'publisher --migration=false --parent=User'
|
19
29
|
generate :model, 'category name:string description:text'
|
20
|
-
inject_into_file 'app/models/category.rb', " has_many :posts\n accepts_nested_attributes_for :posts\n", :
|
30
|
+
inject_into_file 'app/models/category.rb', " has_many :posts\n accepts_nested_attributes_for :posts\n", after: "class Category < ActiveRecord::Base\n"
|
21
31
|
generate :model, 'store name:string'
|
22
32
|
|
23
33
|
# Generate a model with string ids
|
24
|
-
generate :model,
|
25
|
-
gsub_file(Dir['db/migrate/*_create_tags.rb'][0], /\:tags\sdo\s.*/, ":tags, :
|
26
|
-
id_model_setup = <<-
|
34
|
+
generate :model, 'tag name:string'
|
35
|
+
gsub_file(Dir['db/migrate/*_create_tags.rb'][0], /\:tags\sdo\s.*/, ":tags, id: false, primary_key: :id do |t|\n\t\t\tt.string :id\n" )
|
36
|
+
id_model_setup = <<-MODEL
|
27
37
|
self.primary_key = :id
|
28
38
|
before_create :set_id
|
29
|
-
|
39
|
+
|
30
40
|
private
|
31
41
|
def set_id
|
32
|
-
self.id = 8.times.inject(
|
42
|
+
self.id = 8.times.inject('') { |s,e| s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
|
33
43
|
end
|
34
|
-
|
35
|
-
|
44
|
+
MODEL
|
45
|
+
|
46
|
+
inject_into_file 'app/models/tag.rb',
|
47
|
+
id_model_setup,
|
48
|
+
after: "class Tag < ActiveRecord::Base\n"
|
36
49
|
|
37
|
-
if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1 #Rails 3.1 Gotcha
|
38
|
-
gsub_file 'app/models/tag.rb',
|
50
|
+
if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1 # Rails 3.1 Gotcha
|
51
|
+
gsub_file 'app/models/tag.rb',
|
52
|
+
/self\.primary_key.*$/,
|
53
|
+
'define_attr_method :primary_key, :id'
|
39
54
|
end
|
40
55
|
|
41
56
|
# Configure default_url_options in test environment
|
42
|
-
inject_into_file
|
57
|
+
inject_into_file 'config/environments/test.rb',
|
58
|
+
" config.action_mailer.default_url_options = { host: 'example.com' }\n",
|
59
|
+
after: "config.cache_classes = true\n"
|
43
60
|
|
61
|
+
puts File.expand_path('../../../lib/activeadmin-xls', __FILE__)
|
44
62
|
# Add our local Active Admin to the load path
|
45
|
-
inject_into_file
|
63
|
+
inject_into_file 'config/environment.rb',
|
64
|
+
"\nrequire \"#{File.expand_path('../../../lib/activeadmin-xls', __FILE__)}\"\n",
|
65
|
+
after: "require File.expand_path('../application', __FILE__)"
|
46
66
|
|
47
67
|
# Add some translations
|
48
|
-
append_file
|
68
|
+
append_file 'config/locales/en.yml',
|
69
|
+
File.read(File.expand_path('../templates/en.yml', __FILE__))
|
49
70
|
|
50
71
|
# Add predefined admin resources
|
51
|
-
directory File.expand_path('../templates/admin', __FILE__),
|
72
|
+
directory File.expand_path('../templates/admin', __FILE__), 'app/admin'
|
52
73
|
|
53
|
-
run
|
54
|
-
run
|
55
|
-
run
|
74
|
+
run 'rm Gemfile'
|
75
|
+
run 'rm -r test'
|
76
|
+
run 'rm -r spec'
|
56
77
|
|
57
78
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
58
79
|
|
59
|
-
|
60
|
-
|
80
|
+
if Rails::VERSION::MAJOR == 3
|
81
|
+
# we need this routing path, named "logout_path", for testing
|
82
|
+
route <<-ROUTE
|
61
83
|
devise_scope :user do
|
62
|
-
match '/admin/logout' => 'active_admin/devise/sessions#destroy', :
|
84
|
+
match '/admin/logout' => 'active_admin/devise/sessions#destroy', as: :logout
|
63
85
|
end
|
64
|
-
|
86
|
+
ROUTE
|
87
|
+
end
|
65
88
|
|
66
89
|
generate :'active_admin:install'
|
67
90
|
|
91
|
+
if Rails::VERSION::MAJOR > 3
|
92
|
+
inject_into_file 'config/initializers/active_admin.rb',
|
93
|
+
" config.download_links = %i[csv xml json xls]\n",
|
94
|
+
after: " # == Download Links\n"
|
95
|
+
end
|
96
|
+
|
68
97
|
# Setup a root path for devise
|
69
|
-
route "root :
|
98
|
+
route "root to: 'admin/dashboard#index'"
|
70
99
|
|
71
|
-
rake
|
72
|
-
rake
|
73
|
-
run
|
100
|
+
rake 'db:migrate'
|
101
|
+
rake 'db:test:prepare'
|
102
|
+
run '/usr/bin/env RAILS_ENV=cucumber rake db:migrate'
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# Use the default
|
2
|
-
apply File.expand_path(
|
2
|
+
apply File.expand_path('../rails_template.rb', __FILE__)
|
3
3
|
|
4
4
|
# Register Active Admin controllers
|
5
|
-
%w
|
5
|
+
%w[Post User Category].each do |type|
|
6
6
|
generate :'active_admin:resource', type
|
7
7
|
end
|
8
8
|
|
9
|
-
scopes = <<-
|
10
|
-
scope :all, :
|
9
|
+
scopes = <<-SCOPES
|
10
|
+
scope :all, default: true
|
11
11
|
|
12
12
|
scope :drafts do |posts|
|
13
13
|
posts.where(["published_at IS NULL"])
|
@@ -24,22 +24,25 @@ scopes = <<-EOF
|
|
24
24
|
scope :my_posts do |posts|
|
25
25
|
posts.where(:author_id => current_admin_user.id)
|
26
26
|
end
|
27
|
+
SCOPES
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
inject_into_file 'app/admin/post.rb',
|
30
|
+
scopes,
|
31
|
+
after: "ActiveAdmin.register Post do\n"
|
30
32
|
|
31
33
|
# Setup some default data
|
32
|
-
append_file
|
33
|
-
|
34
|
+
append_file 'db/seeds.rb', <<-SEEDS
|
35
|
+
|
36
|
+
users = ['Jimi Hendrix', 'Jimmy Page', 'Yngwie Malmsteen', 'Eric Clapton', 'Kirk Hammett'].collect do |name|
|
34
37
|
first, last = name.split(" ")
|
35
|
-
User.create! :
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
38
|
+
User.create! first_name: first,
|
39
|
+
last_name: last,
|
40
|
+
username: [first,last].join('-').downcase,
|
41
|
+
age: rand(80)
|
39
42
|
end
|
40
43
|
|
41
|
-
categories = [
|
42
|
-
Category.create! :
|
44
|
+
categories = ['Rock', 'Pop Rock', 'Alt-Country', 'Blues', 'Dub-Step'].collect do |name|
|
45
|
+
Category.create! name: name
|
43
46
|
end
|
44
47
|
|
45
48
|
published_at_values = [Time.now.utc - 5.days, Time.now.utc - 1.day, nil, Time.now.utc + 3.days]
|
@@ -48,12 +51,12 @@ append_file "db/seeds.rb", <<-EOF
|
|
48
51
|
user = users[i % users.size]
|
49
52
|
cat = categories[i % categories.size]
|
50
53
|
published_at = published_at_values[i % published_at_values.size]
|
51
|
-
Post.create :
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
54
|
+
Post.create title: "Blog Post \#{i}",
|
55
|
+
body: "Blog post \#{i} is written by \#{user.username} about \#{cat.name}",
|
56
|
+
category_id: cat.id,
|
57
|
+
published_at: published_at,
|
58
|
+
author: user
|
56
59
|
end
|
57
|
-
|
60
|
+
SEEDS
|
58
61
|
|
59
62
|
rake 'db:seed'
|
@@ -19,30 +19,34 @@ describe ActiveAdmin::Views::PaginatedCollection do
|
|
19
19
|
|
20
20
|
let(:view) do
|
21
21
|
view = mock_action_view
|
22
|
-
view.request.
|
23
|
-
view.
|
22
|
+
allow(view.request).to receive(:query_parameters) { { page: '1' } }
|
23
|
+
allow(view.request).to receive(:path_parameters) do
|
24
|
+
{ controller: 'admin/posts', action: 'index' }
|
25
|
+
end
|
24
26
|
view
|
25
27
|
end
|
26
28
|
|
27
29
|
# Helper to render paginated collections within an arbre context
|
28
30
|
def paginated_collection(*args)
|
29
|
-
render_arbre_component({:
|
31
|
+
render_arbre_component({ paginated_collection_args: args }, view) do
|
30
32
|
paginated_collection(*paginated_collection_args)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
let(:collection) do
|
35
|
-
posts = [Post.new(:
|
37
|
+
posts = [Post.new(title: 'First Post')]
|
36
38
|
Kaminari.paginate_array(posts).page(1).per(5)
|
37
39
|
end
|
38
40
|
|
39
41
|
let(:pagination) { paginated_collection(collection) }
|
40
42
|
|
41
43
|
before do
|
42
|
-
collection.
|
44
|
+
allow(collection).to receive(:except) { collection } unless collection.respond_to? :except
|
45
|
+
allow(collection).to receive(:group_values) { [] } unless collection.respond_to? :group_values
|
46
|
+
allow(collection).to receive(:reorder) { collection }
|
43
47
|
end
|
44
48
|
|
45
|
-
it
|
46
|
-
pagination.children.last.content.
|
49
|
+
it 'renders the xls download link' do
|
50
|
+
expect(pagination.children.last.content).to match(/XLS/)
|
47
51
|
end
|
48
52
|
end
|
@@ -3,191 +3,190 @@ require 'spec_helper'
|
|
3
3
|
module ActiveAdmin
|
4
4
|
module Xls
|
5
5
|
describe Builder do
|
6
|
-
|
7
6
|
let(:builder) { Builder.new(Post) }
|
8
7
|
let(:content_columns) { Post.content_columns }
|
9
8
|
|
10
9
|
context 'the default builder' do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it 'has no header style' do
|
11
|
+
expect(builder.header_style).to eq({})
|
12
|
+
end
|
13
|
+
it 'has no i18n scope' do
|
14
|
+
expect(builder.i18n_scope).to be_nil
|
15
|
+
end
|
16
|
+
it 'has default columns' do
|
17
|
+
expect(builder.columns.size).to eq(content_columns.size + 1)
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
context 'customizing a builder' do
|
18
22
|
it 'deletes columns we tell it we dont want' do
|
19
23
|
builder.delete_columns :id, :body
|
20
|
-
builder.columns.size.
|
24
|
+
expect(builder.columns.size).to eq(content_columns.size - 1)
|
21
25
|
end
|
22
26
|
|
23
27
|
it 'lets us say we dont want the header' do
|
24
28
|
builder.skip_header
|
25
|
-
builder.instance_values[
|
29
|
+
expect(builder.instance_values['skip_header']).to be_truthy
|
26
30
|
end
|
27
31
|
|
28
32
|
it 'lets us add custom columns' do
|
29
33
|
builder.column(:hoge)
|
30
|
-
builder.columns.size.
|
34
|
+
expect(builder.columns.size).to eq(content_columns.size + 2)
|
31
35
|
end
|
32
36
|
|
33
37
|
it 'lets us clear all columns' do
|
34
38
|
builder.clear_columns
|
35
|
-
builder.columns.size.
|
39
|
+
expect(builder.columns.size).to eq(0)
|
36
40
|
end
|
37
41
|
|
38
42
|
context 'Using Procs for delayed content generation' do
|
39
|
-
|
40
|
-
let(:post) { Post.new(:title => "Hot Dawg") }
|
43
|
+
let(:post) { Post.new(title: 'Hot Dawg') }
|
41
44
|
|
42
45
|
before do
|
43
|
-
builder.column(:hoge)
|
46
|
+
builder.column(:hoge) do |resource|
|
47
|
+
"#{resource.title} - with cheese"
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
it 'stores the block when defining a column for later execution.' do
|
47
|
-
builder.columns.last.data.
|
52
|
+
expect(builder.columns.last.data).to be_a(Proc)
|
48
53
|
end
|
49
54
|
|
50
55
|
it 'evaluates custom column blocks' do
|
51
|
-
builder.columns.last.data.call(post).
|
56
|
+
expect(builder.columns.last.data.call(post)).to eq('Hot Dawg - with cheese')
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
61
|
context 'sheet generation without headers' do
|
57
|
-
let!(:users) {
|
62
|
+
let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
|
58
63
|
|
59
|
-
let!(:posts) {
|
64
|
+
let!(:posts) { [Post.new(title: 'bob', body: 'is a swell guy', author: users.first)] }
|
60
65
|
|
61
|
-
let!(:builder)
|
62
|
-
Builder.new(Post,
|
66
|
+
let!(:builder) do
|
67
|
+
Builder.new(Post, header_format: { weight: :bold }, i18n_scope: %i[xls post]) do
|
63
68
|
skip_header
|
64
69
|
end
|
65
|
-
|
70
|
+
end
|
66
71
|
|
67
72
|
before do
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
builder.
|
72
|
-
builder.
|
73
|
-
@package = builder.send(:package)
|
73
|
+
# disable clean up so we can get the book.
|
74
|
+
allow(builder).to receive(:clean_up) { false }
|
75
|
+
# @book = Spreadsheet.open(builder.serialize(posts))
|
76
|
+
builder.serialize(posts)
|
77
|
+
@book = builder.send(:book)
|
74
78
|
@collection = builder.collection
|
75
79
|
end
|
76
80
|
|
77
81
|
it 'does not serialize the header' do
|
78
|
-
|
79
|
-
not_header.cells.first.value.should_not == 'Title'
|
82
|
+
expect(@book.worksheets.first[0, 0]).not_to eq('Title')
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
86
|
context 'whitelisted sheet generation' do
|
84
|
-
let!(:users) {
|
87
|
+
let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
|
85
88
|
|
86
|
-
let!(:posts)
|
89
|
+
let!(:posts) do
|
90
|
+
[Post.new(title: 'bob', body: 'is a swell guy', author: users.first)]
|
91
|
+
end
|
87
92
|
|
88
|
-
let!(:builder)
|
89
|
-
Builder.new(Post, header_style: {
|
93
|
+
let!(:builder) do
|
94
|
+
Builder.new(Post, header_style: {}, i18n_scope: %i[xls post]) do
|
90
95
|
skip_header
|
91
96
|
whitelist
|
92
97
|
column :title
|
93
98
|
end
|
94
|
-
|
99
|
+
end
|
95
100
|
|
96
101
|
before do
|
97
|
-
User.
|
98
|
-
Post.
|
99
|
-
# disable clean up so we can get the
|
100
|
-
builder.
|
102
|
+
allow(User).to receive(:all) { users }
|
103
|
+
allow(Post).to receive(:all) { posts }
|
104
|
+
# disable clean up so we can get the book.
|
105
|
+
allow(builder).to receive(:clean_up) { false }
|
101
106
|
builder.serialize(Post.all)
|
102
|
-
@
|
107
|
+
@book = builder.send(:book)
|
103
108
|
@collection = builder.collection
|
104
109
|
end
|
105
110
|
|
106
111
|
it 'does not serialize the header' do
|
107
|
-
sheet = @
|
108
|
-
sheet.
|
109
|
-
sheet.
|
112
|
+
sheet = @book.worksheets.first
|
113
|
+
expect(sheet.column_count).to eq(1)
|
114
|
+
expect(sheet[0, 0]).to eq(@collection.first.title)
|
110
115
|
end
|
111
116
|
end
|
112
117
|
|
113
118
|
context 'Sheet generation with a highly customized configuration.' do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
let!(:posts) { [Post.new(title: 'bob', body: 'is a swell guy', author: users.first)] }
|
118
|
-
|
119
|
-
let!(:builder) {
|
120
|
-
Builder.new(Post, header_style: { sz: 10, fg_color: "FF0000" }, i18n_scope: [:xls, :post]) do
|
119
|
+
let!(:builder) do
|
120
|
+
Builder.new(Post, header_style: { size: 10, color: 'red' }, i18n_scope: %i[xls post]) do
|
121
121
|
delete_columns :id, :created_at, :updated_at
|
122
|
-
column(:author)
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
chart.start_at 4, 0
|
137
|
-
chart.end_at 7, 20
|
122
|
+
column(:author) do |resource|
|
123
|
+
"#{resource.author.first_name} #{resource.author.last_name}"
|
124
|
+
end
|
125
|
+
after_filter do |sheet|
|
126
|
+
row_number = sheet.dimensions[1]
|
127
|
+
sheet.update_row(row_number)
|
128
|
+
row_number += 1
|
129
|
+
sheet.update_row(row_number, 'Author Name', 'Number of Posts')
|
130
|
+
users = collection.map(&:author).uniq(&:id)
|
131
|
+
users.each do |user|
|
132
|
+
row_number += 1
|
133
|
+
sheet.update_row(row_number,
|
134
|
+
"#{user.first_name} #{user.last_name}",
|
135
|
+
user.posts.size)
|
138
136
|
end
|
139
|
-
|
137
|
+
end
|
140
138
|
before_filter do |sheet|
|
141
|
-
collection.
|
142
|
-
|
143
|
-
|
139
|
+
users = collection.map(&:author)
|
140
|
+
users.each do |user|
|
141
|
+
user.first_name = 'Set In Proc' if user.first_name == 'bob'
|
142
|
+
end
|
143
|
+
row_number = sheet.dimensions[1]
|
144
|
+
sheet.update_row(row_number, 'Created', Time.zone.now)
|
145
|
+
row_number += 1
|
146
|
+
sheet.update_row(row_number, '')
|
144
147
|
end
|
145
148
|
end
|
146
|
-
|
149
|
+
end
|
147
150
|
|
148
|
-
before
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
before do
|
152
|
+
Post.all.each(&:destroy)
|
153
|
+
User.all.each(&:destroy)
|
154
|
+
@user = User.create!(first_name: 'bob', last_name: 'nancy')
|
155
|
+
@post = Post.create!(title: 'bob',
|
156
|
+
body: 'is a swell guy',
|
157
|
+
author: @user)
|
158
|
+
# disable clean up so we can get the book.
|
159
|
+
allow(builder).to receive(:clean_up) { false }
|
153
160
|
builder.serialize(Post.all)
|
154
|
-
@
|
161
|
+
@book = builder.send(:book)
|
155
162
|
@collection = builder.collection
|
156
163
|
end
|
157
164
|
|
158
165
|
it 'provides the collection object' do
|
159
|
-
@collection.count.
|
166
|
+
expect(@collection.count).to eq(Post.all.count)
|
160
167
|
end
|
161
168
|
|
162
169
|
it 'merges our customizations with the default header style' do
|
163
|
-
builder.header_style[:
|
164
|
-
builder.header_style[:
|
165
|
-
builder.header_style[:
|
170
|
+
expect(builder.header_style[:size]).to eq(10)
|
171
|
+
expect(builder.header_style[:color]).to eq('red')
|
172
|
+
# expect(builder.header_style[:pattern_bg_color]).to eq('00')
|
166
173
|
end
|
167
174
|
|
168
175
|
it 'uses the specified i18n_scope' do
|
169
|
-
builder.i18n_scope.
|
176
|
+
expect(builder.i18n_scope).to eq(%i[xls post])
|
170
177
|
end
|
171
178
|
|
172
179
|
it 'translates the header row based on our i18n scope' do
|
173
|
-
header_row = @
|
174
|
-
header_row
|
180
|
+
header_row = @book.worksheets.first.row(2)
|
181
|
+
expect(header_row).to eq(['Title', 'Content', 'Published On', 'Publisher'])
|
175
182
|
end
|
176
183
|
|
177
184
|
it 'processes the before filter' do
|
178
|
-
@
|
185
|
+
expect(@book.worksheets.first.cell(0, 0)).to eq('Created')
|
179
186
|
end
|
180
187
|
|
181
188
|
it 'lets us work against the collection in the before filter' do
|
182
|
-
@
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'processes the after filter' do
|
186
|
-
@package.workbook.charts.size.should == 1
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'has no OOXML validation errors' do
|
190
|
-
@package.validate.size.should == 0
|
189
|
+
expect(@book.worksheets.first.last_row[0]).to eq('Set In Proc nancy')
|
191
190
|
end
|
192
191
|
end
|
193
192
|
end
|
data/spec/xls/unit/dsl_spec.rb
CHANGED
@@ -3,48 +3,55 @@ require 'spec_helper'
|
|
3
3
|
module ActiveAdmin
|
4
4
|
module Xls
|
5
5
|
describe ::ActiveAdmin::ResourceDSL do
|
6
|
-
context 'in a
|
7
|
-
let(:builder)
|
6
|
+
context 'in a registration block' do
|
7
|
+
let(:builder) do
|
8
8
|
config = ActiveAdmin.register(Post) do
|
9
|
-
xls(i18n_scope: [:rspec], header_style: {
|
9
|
+
xls(i18n_scope: [:rspec], header_style: { size: 20 }) do
|
10
10
|
delete_columns :id, :created_at
|
11
11
|
column(:author) { |post| post.author.first_name }
|
12
|
-
before_filter
|
13
|
-
|
12
|
+
before_filter do |sheet|
|
13
|
+
row_number = sheet.dimensions[1]
|
14
|
+
sheet.update_row(row_number, 'before_filter')
|
15
|
+
end
|
16
|
+
after_filter do |sheet|
|
17
|
+
row_number = sheet.dimensions[1]
|
18
|
+
sheet.update_row(row_number, 'after_filter')
|
19
|
+
end
|
14
20
|
skip_header
|
15
21
|
end
|
16
22
|
end
|
17
23
|
config.xls_builder
|
18
|
-
|
19
|
-
|
24
|
+
end
|
20
25
|
|
21
|
-
it
|
22
|
-
builder.i18n_scope.
|
26
|
+
it 'uses our customized i18n scope' do
|
27
|
+
expect(builder.i18n_scope).to eq([:rspec])
|
23
28
|
end
|
24
29
|
|
25
|
-
it
|
26
|
-
[
|
27
|
-
builder.columns.index{|
|
30
|
+
it 'removed the columns we told it to ignore' do
|
31
|
+
%i[id create_at].each do |removed|
|
32
|
+
column_index = builder.columns.index { |col| col.name == removed }
|
33
|
+
expect(column_index).to be_nil
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
|
-
it
|
32
|
-
builder.columns.index{ |
|
37
|
+
it 'added the columns we declared' do
|
38
|
+
added_index = builder.columns.index { |col| col.name == :author }
|
39
|
+
expect(added_index).not_to be_nil
|
33
40
|
end
|
34
41
|
|
35
|
-
it
|
36
|
-
builder.instance_values[
|
42
|
+
it 'has a before filter set' do
|
43
|
+
expect(builder.instance_values['before_filter']).to be_a(Proc)
|
37
44
|
end
|
38
|
-
it
|
39
|
-
builder.instance_values[
|
45
|
+
it 'has an after filter set' do
|
46
|
+
expect(builder.instance_values['after_filter']).to be_a(Proc)
|
40
47
|
end
|
41
48
|
|
42
|
-
it
|
43
|
-
builder.instance_values['skip_header'].
|
49
|
+
it 'indicates that the header should be excluded' do
|
50
|
+
expect(builder.instance_values['skip_header']).to be_truthy
|
44
51
|
end
|
45
52
|
|
46
|
-
it
|
47
|
-
builder.header_style[:
|
53
|
+
it 'updates the header style' do
|
54
|
+
expect(builder.header_style[:size]).to eq(20)
|
48
55
|
end
|
49
56
|
end
|
50
57
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe ActiveAdmin::ResourceController do
|
3
|
-
|
4
3
|
let(:mime) { Mime::Type.lookup_by_extension(:xls) }
|
5
4
|
|
6
5
|
let(:request) do
|
@@ -18,27 +17,36 @@ describe ActiveAdmin::ResourceController do
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
let(:filename)
|
20
|
+
let(:filename) do
|
21
|
+
"#{controller.resource_class.to_s.downcase.pluralize}-#{Time.now.strftime('%Y-%m-%d')}.xls"
|
22
|
+
end
|
22
23
|
|
23
24
|
it 'generates an xls filename' do
|
24
|
-
controller.xls_filename.
|
25
|
+
expect(controller.xls_filename).to eq(filename)
|
25
26
|
end
|
26
27
|
|
27
28
|
context 'when making requests with the xls mime type' do
|
28
|
-
|
29
|
+
it 'returns xls attachment when requested' do
|
29
30
|
controller.send :index
|
30
|
-
|
31
|
-
response.headers[
|
31
|
+
disposition = "attachment; filename=\"#{filename}\""
|
32
|
+
expect(response.headers['Content-Disposition']).to eq(disposition)
|
33
|
+
expect(response.headers['Content-Transfer-Encoding']).to eq('binary')
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'returns max_csv_records for per_page' do
|
35
|
-
|
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)
|
36
44
|
end
|
37
45
|
|
38
|
-
it '
|
46
|
+
it 'uses to the default per_page when we do not specify xls mime type' do
|
39
47
|
controller.request.accept = 'text/html'
|
40
|
-
|
48
|
+
aa_default_per_page = ActiveAdmin.application.default_per_page
|
49
|
+
expect(controller.send(:per_page)).to eq(aa_default_per_page)
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
44
|
-
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require 'spec_helper'
|
2
2
|
include ActiveAdmin
|
3
3
|
|
4
4
|
module ActiveAdmin
|
@@ -7,18 +7,18 @@ module ActiveAdmin
|
|
7
7
|
let(:resource) { ActiveAdmin.register(Post) }
|
8
8
|
|
9
9
|
let(:custom_builder) do
|
10
|
-
Builder.new(Post) do
|
10
|
+
Builder.new(Post) do
|
11
11
|
column(:fake) { :fake }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when registered' do
|
16
|
-
it
|
17
|
-
resource.xls_builder.
|
16
|
+
it 'each resource has an xls_builder' do
|
17
|
+
expect(resource.xls_builder).to be_a(Builder)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
|
20
|
+
it 'We can specify our own configured builder' do
|
21
|
+
expect { resource.xls_builder = custom_builder }.not_to raise_error
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-xls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Hambley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|
@@ -51,8 +51,8 @@ executables: []
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
-
- ".bundle/config"
|
55
54
|
- ".editorconfig"
|
55
|
+
- ".gemignore"
|
56
56
|
- ".gitignore"
|
57
57
|
- ".rspec"
|
58
58
|
- ".yardops"
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- README.md
|
63
63
|
- Rakefile
|
64
64
|
- activeadmin-xls.gemspec
|
65
|
+
- gemfiles/rails_32.gemfile
|
66
|
+
- gemfiles/rails_42.gemfile
|
65
67
|
- lib/active_admin/xls/builder.rb
|
66
68
|
- lib/active_admin/xls/dsl.rb
|
67
69
|
- lib/active_admin/xls/engine.rb
|
@@ -105,16 +107,4 @@ rubygems_version: 2.4.5.2
|
|
105
107
|
signing_key:
|
106
108
|
specification_version: 4
|
107
109
|
summary: Adds excel (xls) downloads for resources within the Active Admin framework.
|
108
|
-
test_files:
|
109
|
-
- spec/spec_helper.rb
|
110
|
-
- spec/support/rails_template.rb
|
111
|
-
- spec/support/rails_template_with_data.rb
|
112
|
-
- spec/support/templates/admin/stores.rb
|
113
|
-
- spec/support/templates/cucumber.rb
|
114
|
-
- spec/support/templates/cucumber_with_reloading.rb
|
115
|
-
- spec/support/templates/en.yml
|
116
|
-
- spec/xls/unit/builder_spec.rb
|
117
|
-
- spec/xls/unit/build_download_format_links_spec.rb
|
118
|
-
- spec/xls/unit/dsl_spec.rb
|
119
|
-
- spec/xls/unit/resource_controller_spec.rb
|
120
|
-
- spec/xls/unit/resource_spec.rb
|
110
|
+
test_files: []
|
data/.bundle/config
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--- {}
|