activeadmin-xls 2.0.2 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3e07f07dfdc40d3f51d3bf7ed071c2f11a204fd
4
- data.tar.gz: 899009df0bbc02bc522b4c9f872d036e5ecb96b7
3
+ metadata.gz: '08d961ae05e4dca5b44e3e1615ce356fb8dd7e59'
4
+ data.tar.gz: 2c8f37c8e0c43cf10e91b9889576efeb3ff98297
5
5
  SHA512:
6
- metadata.gz: ad917c6af301c4f86bcd51b16cd49e57e57bca0c74fa9ff437509298e02b9f3e73420601f5cd2138cf9c3be11bdf4541ee5de5711b91c7c514fa033cff840065
7
- data.tar.gz: 2c5f38deffdb05f528e6248daf5e4785e58a91664b397e52c148bc07c454c00e61d51b0d4f8b6dec94b0304e5c068b2d19d36c596057d5b283cc5a9ebb483f07
6
+ metadata.gz: c523bd762b313b3cb7002044462b80d5b300bb49c37606aa2b72da2da5e29702ba3c85c021fd886aad099fb606e6c5f2e0bff78118e872673311e66af7862bf5
7
+ data.tar.gz: fffc68d9617a1b2d61a7e639d4579379f4a4779eaa570d485c52dc86270649171fdf81b5583cf3d0f023ed66267e8011a5339c98fab73e63bddc148bf1ec9d41
data/CHANGELOG.md CHANGED
@@ -2,11 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 2.0.3
6
+
7
+ ### Changed
8
+
9
+ * ignore test/ folder for gem building [#21][] by [@cprodhomme][]
10
+
5
11
  ## 2.0.2
6
12
 
7
13
  ### Changed
8
14
 
9
- * Remove ActiveAdmin runtime dependency version limit '<2' [#16] by [@reaper][]
15
+ * Remove ActiveAdmin runtime dependency version limit '<2' [#16][] by [@reaper][]
10
16
 
11
17
  ## 2.0.1
12
18
 
@@ -68,8 +74,10 @@
68
74
  [#11]: https://github.com/thambley/activeadmin-xls/pull/11
69
75
  [#13]: https://github.com/thambley/activeadmin-xls/issues/13
70
76
  [#16]: https://github.com/thambley/activeadmin-xls/pull/16
77
+ [#21]: https://github.com/thambley/activeadmin-xls/pull/21
71
78
 
72
79
  [@rewritten]: https://github.com/rewritten
73
80
  [@ejaypcanaria]: https://github.com/ejaypcanaria
74
81
  [@cpunion]: https://github.com/cpunion
75
82
  [@reaper]: https://github.com/reaper
83
+ [@cprodhomme]: https://github.com/cprodhomme
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  git_tracked_files = `git ls-files`.split("\n").sort
20
20
  gem_ignored_files = `git ls-files -i -X .gemignore`.split("\n")
21
21
 
22
- s.files = git_tracked_files - gem_ignored_files
22
+ s.files = (git_tracked_files - gem_ignored_files).reject { |f| f.match(%r{^(test|spec|features)/}) }
23
23
 
24
24
  s.add_runtime_dependency 'activeadmin', '>= 1.0.0'
25
25
  s.add_runtime_dependency 'spreadsheet', '~> 1.0'
@@ -9,6 +9,7 @@ eval_gemfile(File.expand_path(File.join('..', 'Gemfile'), __dir__))
9
9
  gem 'activeadmin', '1.4.3'
10
10
  gem 'devise', '~> 4.2'
11
11
  gem 'rails', '4.2.11'
12
+ gem 'sprockets', '< 4.0'
12
13
  gem 'sqlite3', '~> 1.3.0'
13
14
  gem 'turbolinks', '~> 5.0.0'
14
15
  gem 'tzinfo-data'
@@ -1,6 +1,6 @@
1
1
  module ActiveAdmin
2
2
  module Xls
3
3
  # ActiveAdmin XLS gem version
4
- VERSION = '2.0.2'.freeze
4
+ VERSION = '2.0.3'.freeze
5
5
  end
6
6
  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: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hambley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-08 00:00:00.000000000 Z
11
+ date: 2021-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -66,19 +66,6 @@ files:
66
66
  - lib/active_admin/xls/resource_extension.rb
67
67
  - lib/active_admin/xls/version.rb
68
68
  - lib/activeadmin-xls.rb
69
- - spec/rails_helper.rb
70
- - spec/spec_helper.rb
71
- - spec/support/rails_template.rb
72
- - spec/support/rails_template_with_data.rb
73
- - spec/support/templates/admin/stores.rb
74
- - spec/support/templates/cucumber.rb
75
- - spec/support/templates/cucumber_with_reloading.rb
76
- - spec/support/templates/en.yml
77
- - spec/xls/unit/build_download_format_links_spec.rb
78
- - spec/xls/unit/builder_spec.rb
79
- - spec/xls/unit/dsl_spec.rb
80
- - spec/xls/unit/resource_controller_spec.rb
81
- - spec/xls/unit/resource_spec.rb
82
69
  homepage: https://github.com/thambley/activeadmin-xls
83
70
  licenses:
84
71
  - MIT
@@ -99,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
86
  version: '0'
100
87
  requirements: []
101
88
  rubyforge_project:
102
- rubygems_version: 2.6.14.1
89
+ rubygems_version: 2.6.14.4
103
90
  signing_key:
104
91
  specification_version: 4
105
92
  summary: Adds excel (xls) downloads for resources within the Active Admin framework.
data/spec/rails_helper.rb DELETED
File without changes
data/spec/spec_helper.rb DELETED
@@ -1,46 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter '/rails/'
4
- add_filter '/spec/'
5
- end
6
-
7
- if ENV['CI'] == 'true'
8
- require 'codecov'
9
- SimpleCov.formatters = [
10
- SimpleCov::Formatter::HTMLFormatter,
11
- SimpleCov::Formatter::Codecov
12
- ]
13
- end
14
-
15
- ENV['RAILS_ENV'] = 'test'
16
-
17
- # prepare ENV for rails
18
- require 'rails'
19
- ENV['RAILS_ROOT'] = File.expand_path(
20
- "../rails/rails-#{Rails::VERSION::STRING}",
21
- __FILE__
22
- )
23
-
24
- # ensure testing application is in place
25
- unless File.exist?(ENV['RAILS_ROOT'])
26
- puts 'Please run bundle exec rake setup before running the specs.'
27
- exit
28
- end
29
-
30
- # load up activeadmin and activeadmin-xls
31
- require 'active_record'
32
- require 'active_admin'
33
- require 'devise'
34
- require 'activeadmin-xls'
35
- ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + '/app/admin']
36
-
37
- # start up rails
38
- require ENV['RAILS_ROOT'] + '/config/environment'
39
-
40
- # and finally,here's rspec
41
- require 'rspec/rails'
42
-
43
- # Disabling authentication in specs so that we don't have to worry about
44
- # it allover the place
45
- ActiveAdmin.application.authentication_method = false
46
- ActiveAdmin.application.current_user_method = false
@@ -1,127 +0,0 @@
1
- # Rails template to build the sample app for specs
2
-
3
- # Create a cucumber database and environment
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'
8
-
9
- gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n"
10
- gsub_file 'config/database.yml',
11
- /\z/,
12
- "\ncucumber:\n <<: *test\n database: db/cucumber.sqlite3"
13
- gsub_file(
14
- 'config/database.yml',
15
- /\z/,
16
- "\ncucumber_with_reloading:\n <<: *test\n database: db/cucumber.sqlite3"
17
- )
18
-
19
- if File.exist?('config/secrets.yml')
20
- require 'securerandom'
21
- cucumber_secret = SecureRandom.hex(64)
22
- gsub_file 'config/secrets.yml',
23
- /\z/,
24
- "\ncucumber:\n secret_key_base: #{cucumber_secret}"
25
- end
26
-
27
- base_record = if Rails::VERSION::MAJOR >= 5
28
- 'ApplicationRecord'
29
- else
30
- 'ActiveRecord::Base'
31
- end
32
-
33
- # Generate some test models
34
- generate :model, 'post title:string body:text published_at:datetime author_id:integer category_id:integer'
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
-
52
- generate :model, 'user type:string first_name:string last_name:string username:string age:integer'
53
- inject_into_file 'app/models/user.rb',
54
- " has_many :posts, foreign_key: 'author_id'\n",
55
- after: "class User < #{base_record}\n"
56
-
57
- generate :model, 'publisher --migration=false --parent=User'
58
-
59
- generate :model, 'category name:string description:text'
60
- inject_into_file 'app/models/category.rb',
61
- " has_many :posts\n accepts_nested_attributes_for :posts\n",
62
- after: "class Category < #{base_record}\n"
63
-
64
- generate :model, 'store name:string'
65
-
66
- # Generate a model with string ids
67
- generate :model, 'tag name:string'
68
- gsub_file(
69
- Dir['db/migrate/*_create_tags.rb'][0],
70
- /\:tags\sdo\s.*/,
71
- ":tags, id: false, primary_key: :id do |t|\n\t\t\tt.string :id\n"
72
- )
73
- id_model_setup = <<-MODEL
74
- self.primary_key = :id
75
- before_create :set_id
76
-
77
- private
78
- def set_id
79
- self.id = 8.times.inject('') do |s,e|
80
- s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr
81
- end
82
- end
83
- MODEL
84
-
85
- inject_into_file 'app/models/tag.rb',
86
- id_model_setup,
87
- after: "class Tag < #{base_record}\n"
88
-
89
- # Configure default_url_options in test environment
90
- inject_into_file(
91
- 'config/environments/test.rb',
92
- " config.action_mailer.default_url_options = { host: 'example.com' }\n",
93
- after: "config.cache_classes = true\n"
94
- )
95
-
96
- # Add our local Active Admin to the load path
97
- lib_path = File.expand_path('../../../lib/activeadmin-xls', __FILE__)
98
- inject_into_file 'config/environment.rb',
99
- "\nrequire '#{lib_path}'\n",
100
- after: "require File.expand_path('../application', __FILE__)"
101
-
102
- # Add some translations
103
- append_file 'config/locales/en.yml',
104
- File.read(File.expand_path('../templates/en.yml', __FILE__))
105
-
106
- # Add predefined admin resources
107
- directory File.expand_path('../templates/admin', __FILE__), 'app/admin'
108
-
109
- run 'rm Gemfile'
110
-
111
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
112
-
113
- generate :'active_admin:install'
114
-
115
- run 'rm -r test'
116
- run 'rm -r spec'
117
-
118
- inject_into_file 'config/initializers/active_admin.rb',
119
- " config.download_links = %i[csv xml json xls]\n",
120
- after: " # == Download Links\n"
121
-
122
- # Setup a root path for devise
123
- route "root to: 'admin/dashboard#index'"
124
-
125
- rake 'db:migrate'
126
- rake 'db:test:prepare'
127
- run '/usr/bin/env RAILS_ENV=cucumber rake db:migrate'
@@ -1,68 +0,0 @@
1
- # Use the default
2
- apply File.expand_path('../rails_template.rb', __FILE__)
3
-
4
- # Register Active Admin controllers
5
- %w[Post User Category].each do |type|
6
- generate :'active_admin:resource', type
7
- end
8
-
9
- scopes = <<-SCOPES
10
- scope :all, default: true
11
-
12
- scope :drafts do |posts|
13
- posts.where(['published_at IS NULL'])
14
- end
15
-
16
- scope :scheduled do |posts|
17
- posts.where(['posts.published_at IS NOT NULL AND posts.published_at > ?', Time.now.utc])
18
- end
19
-
20
- scope :published do |posts|
21
- posts.where(['posts.published_at IS NOT NULL AND posts.published_at < ?', Time.now.utc])
22
- end
23
-
24
- scope :my_posts do |posts|
25
- posts.where(author_id: current_admin_user.id)
26
- end
27
- SCOPES
28
-
29
- if File.exist?('app/admin/post.rb')
30
- inject_into_file 'app/admin/post.rb',
31
- scopes,
32
- after: "ActiveAdmin.register Post do\n"
33
- else
34
- inject_into_file 'app/admin/posts.rb',
35
- scopes,
36
- after: "ActiveAdmin.register Post do\n"
37
- end
38
-
39
- # Setup some default data
40
- append_file 'db/seeds.rb', <<-SEEDS
41
-
42
- users = ['Jimi Hendrix', 'Jimmy Page', 'Yngwie Malmsteen', 'Eric Clapton', 'Kirk Hammett'].collect do |name|
43
- first, last = name.split(" ")
44
- User.create! first_name: first,
45
- last_name: last,
46
- username: [first, last].join('-').downcase,
47
- age: rand(80)
48
- end
49
-
50
- categories = ['Rock', 'Pop Rock', 'Alt-Country', 'Blues', 'Dub-Step'].collect do |name|
51
- Category.create! name: name
52
- end
53
-
54
- published_at_values = [Time.now.utc - 5.days, Time.now.utc - 1.day, nil, Time.now.utc + 3.days]
55
-
56
- 1_000.times do |i|
57
- user = users[i % users.size]
58
- cat = categories[i % categories.size]
59
- published_at = published_at_values[i % published_at_values.size]
60
- Post.create title: "Blog Post \#{i}",
61
- body: "Blog post \#{i} is written by \#{user.username} about \#{cat.name}",
62
- category_id: cat.id,
63
- published_at: published_at,
64
- author: user
65
- end
66
- SEEDS
67
-
68
- rake 'db:seed'
@@ -1 +0,0 @@
1
- ActiveAdmin.register Store
@@ -1,24 +0,0 @@
1
- require File.expand_path('config/environments/test', Rails.root)
2
-
3
- # rails/railties/lib/rails/test_help.rb aborts if the environment is not 'test'. (Rails 3.0.0.beta3)
4
- # We can't run Cucumber/RSpec/Test_Unit tests in different environments then.
5
- #
6
- # For now, I patch StringInquirer so that Rails.env.test? returns true when Rails.env is 'test' or 'cucumber'
7
- #
8
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4458-rails-should-allow-test-to-run-in-cucumber-environment
9
- module ActiveSupport
10
- class StringInquirer < String
11
- def method_missing(method_name, *arguments)
12
- if method_name.to_s[-1,1] == "?"
13
- test_string = method_name.to_s[0..-2]
14
- if test_string == 'test'
15
- self == 'test' or self == 'cucumber'
16
- else
17
- self == test_string
18
- end
19
- else
20
- super
21
- end
22
- end
23
- end
24
- end
@@ -1,5 +0,0 @@
1
- require File.expand_path('config/environments/cucumber', Rails.root)
2
-
3
- Rails.application.class.configure do
4
- config.cache_classes = false
5
- end
@@ -1,15 +0,0 @@
1
- # Sample translations used to test ActiveAdmin's I18n integration.
2
- xls:
3
- post:
4
- id: ID
5
- title: Title
6
- body: Content
7
- published_at: Published On
8
- author: Publisher
9
- created_at: Created
10
- updated_at: Updated
11
- activerecord:
12
- models:
13
- store:
14
- one: Bookstore
15
- other: Bookstores
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
- describe ActiveAdmin::Views::PaginatedCollection do
3
- def arbre(assigns = {}, helpers = mock_action_view, &block)
4
- Arbre::Context.new(assigns, helpers, &block)
5
- end
6
-
7
- def render_arbre_component(assigns = {}, helpers = mock_action_view, &block)
8
- arbre(assigns, helpers, &block).children.first
9
- end
10
-
11
- # Returns a fake action view instance to use with our renderers
12
- def mock_action_view(assigns = {})
13
- controller = ActionView::TestCase::TestController.new
14
- ActionView::Base.send :include, ActionView::Helpers
15
- ActionView::Base.send :include, ActiveAdmin::ViewHelpers
16
- ActionView::Base.send :include, Rails.application.routes.url_helpers
17
- ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
18
- end
19
-
20
- let(:view) do
21
- view = mock_action_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
26
- view
27
- end
28
-
29
- # Helper to render paginated collections within an arbre context
30
- def paginated_collection(*args)
31
- render_arbre_component({ paginated_collection_args: args }, view) do
32
- paginated_collection(*paginated_collection_args)
33
- end
34
- end
35
-
36
- let(:collection) do
37
- posts = [Post.new(title: 'First Post')]
38
- Kaminari.paginate_array(posts).page(1).per(5)
39
- end
40
-
41
- let(:pagination) { paginated_collection(collection) }
42
-
43
- before do
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 }
47
- end
48
-
49
- it 'renders the xls download link' do
50
- expect(pagination.children.last.content).to match(/XLS/)
51
- end
52
- end
@@ -1,243 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ActiveAdmin
4
- # tests for builder
5
- module Xls
6
- describe Builder do
7
- let(:builder) { Builder.new(Post) }
8
- let(:content_columns) { Post.content_columns }
9
-
10
- context 'the default builder' do
11
- it 'has no header style' do
12
- expect(builder.header_style).to eq({})
13
- end
14
- it 'has no i18n scope' do
15
- expect(builder.i18n_scope).to be_nil
16
- end
17
- it 'has default columns' do
18
- expect(builder.columns.size).to eq(content_columns.size + 1)
19
- end
20
- end
21
-
22
- context 'customizing a builder' do
23
- it 'deletes columns we tell it we dont want' do
24
- builder.delete_columns :id, :body
25
- expect(builder.columns.size).to eq(content_columns.size - 1)
26
- end
27
-
28
- it 'lets us use specific columns in a list' do
29
- builder.only_columns :title, :author
30
- expect(builder.columns.size).to eq(2)
31
- end
32
-
33
- it 'lets us say we dont want the header' do
34
- builder.skip_header
35
- expect(builder.instance_values['skip_header']).to be_truthy
36
- end
37
-
38
- it 'lets us add custom columns' do
39
- builder.column(:hoge)
40
- expect(builder.columns.size).to eq(content_columns.size + 2)
41
- end
42
-
43
- it 'lets us clear all columns' do
44
- builder.clear_columns
45
- expect(builder.columns.size).to eq(0)
46
- end
47
-
48
- context 'Using Procs for delayed content generation' do
49
- let(:post) { Post.new(title: 'Hot Dawg') }
50
-
51
- before do
52
- builder.column(:hoge) do |resource|
53
- "#{resource.title} - with cheese"
54
- end
55
- end
56
-
57
- it 'stores the block when defining a column for later execution.' do
58
- expect(builder.columns.last.data).to be_a(Proc)
59
- end
60
-
61
- it 'evaluates custom column blocks' do
62
- expect(builder.columns.last.data.call(post)).to eq(
63
- 'Hot Dawg - with cheese'
64
- )
65
- end
66
- end
67
- end
68
-
69
- context 'sheet generation without headers' do
70
- let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
71
-
72
- let!(:posts) do
73
- [Post.new(title: 'bob', body: 'is a swell guy', author: users.first)]
74
- end
75
-
76
- let!(:builder) do
77
- options = {
78
- header_format: { weight: :bold },
79
- i18n_scope: %i[xls post]
80
- }
81
- Builder.new(Post, options) do
82
- skip_header
83
- end
84
- end
85
-
86
- before do
87
- @book = Spreadsheet.open(StringIO.new(builder.serialize(posts)))
88
- end
89
-
90
- it 'does not serialize the header' do
91
- expect(@book.worksheets.first[0, 0]).not_to eq('Title')
92
- end
93
- end
94
-
95
- context 'whitelisted sheet generation' do
96
- let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
97
-
98
- let!(:posts) do
99
- [Post.new(title: 'bob', body: 'is a swell guy', author: users.first)]
100
- end
101
-
102
- let!(:builder) do
103
- Builder.new(Post, header_style: {}, i18n_scope: %i[xls post]) do
104
- skip_header
105
- whitelist
106
- column :title
107
- end
108
- end
109
-
110
- before do
111
- @book = Spreadsheet.open(StringIO.new(builder.serialize(posts)))
112
- @collection = builder.collection
113
- end
114
-
115
- it 'does not serialize the header' do
116
- sheet = @book.worksheets.first
117
- expect(sheet.column_count).to eq(1)
118
- expect(sheet[0, 0]).to eq(@collection.first.title)
119
- end
120
- end
121
-
122
- context 'Sheet generation with a highly customized configuration.' do
123
- let!(:builder) do
124
- options = {
125
- header_style: { size: 10, color: 'red' },
126
- i18n_scope: %i[xls post]
127
- }
128
- Builder.new(Post, options) do
129
- delete_columns :id, :created_at, :updated_at
130
- column(:author) do |resource|
131
- "#{resource.author.first_name} #{resource.author.last_name}"
132
- end
133
- after_filter do |sheet|
134
- row_number = sheet.dimensions[1]
135
- sheet.update_row(row_number)
136
- row_number += 1
137
- sheet.update_row(row_number, 'Author Name', 'Number of Posts')
138
- users = collection.map(&:author).uniq(&:id)
139
- users.each do |user|
140
- row_number += 1
141
- sheet.update_row(row_number,
142
- "#{user.first_name} #{user.last_name}",
143
- user.posts.size)
144
- end
145
- end
146
- before_filter do |sheet|
147
- users = collection.map(&:author)
148
- users.each do |user|
149
- user.first_name = 'Set In Proc' if user.first_name == 'bob'
150
- end
151
- row_number = sheet.dimensions[1]
152
- sheet.update_row(row_number, 'Created', Time.zone.now)
153
- row_number += 1
154
- sheet.update_row(row_number, '')
155
- end
156
- end
157
- end
158
-
159
- before do
160
- Post.all.each(&:destroy)
161
- User.all.each(&:destroy)
162
- @user = User.create!(first_name: 'bob', last_name: 'nancy')
163
- @post = Post.create!(title: 'bob',
164
- body: 'is a swell guy',
165
- author: @user)
166
- @book = Spreadsheet.open(StringIO.new(builder.serialize(Post.all)))
167
- @collection = builder.collection
168
- end
169
-
170
- it 'provides the collection object' do
171
- expect(@collection.count).to eq(Post.all.count)
172
- end
173
-
174
- it 'merges our customizations with the default header style' do
175
- expect(builder.header_style[:size]).to eq(10)
176
- expect(builder.header_style[:color]).to eq('red')
177
- # expect(builder.header_style[:pattern_bg_color]).to eq('00')
178
- end
179
-
180
- it 'uses the specified i18n_scope' do
181
- expect(builder.i18n_scope).to eq(%i[xls post])
182
- end
183
-
184
- it 'translates the header row based on our i18n scope' do
185
- header_row = @book.worksheets.first.row(2)
186
- expect(header_row).to eq(
187
- ['Title', 'Content', 'Published On', 'Publisher']
188
- )
189
- end
190
-
191
- it 'processes the before filter' do
192
- expect(@book.worksheets.first.cell(0, 0)).to eq('Created')
193
- end
194
-
195
- it 'lets us work against the collection in the before filter' do
196
- expect(@book.worksheets.first.last_row[0]).to eq('Set In Proc nancy')
197
- end
198
- end
199
-
200
- ################################
201
- context 'Sheet generation with a exceptions.' do
202
- let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
203
-
204
- let!(:posts) do
205
- [Post.new(title: 'bob', body: 'is a swell guy', author: users.first)]
206
- end
207
-
208
- let!(:exposts) do
209
- [Post.new(title: 'sal', body: 'is a swell guy', author: users.first),
210
- Post.new(title: 'err', body: 'is a swell guy', author: users.first)]
211
- end
212
-
213
- let!(:builder) do
214
- Builder.new(Post, header_style: {}, i18n_scope: %i[xls post]) do
215
- delete_columns :id, :created_at, :updated_at
216
- column(:author) do |resource|
217
- raise 'err' if resource.title == 'err'
218
- "#{resource.author.first_name} #{resource.author.last_name}"
219
- end
220
- end
221
- end
222
-
223
- before do
224
- begin
225
- @book1 = Spreadsheet.open(StringIO.new(builder.serialize(exposts)))
226
- rescue StandardError => err
227
- raise unless err.message == 'err'
228
- end
229
- @book2 = Spreadsheet.open(StringIO.new(builder.serialize(posts)))
230
- @collection = builder.collection
231
- end
232
-
233
- it 'does not contain data from other collections with errors' do
234
- sheet = @book2.worksheets.first
235
- expect(sheet.dimensions[1]).to eq(2)
236
- expect(sheet[0, 0]).to eq('Title')
237
- expect(sheet[1, 0]).to eq(@collection.first.title)
238
- end
239
- end
240
- ################################
241
- end
242
- end
243
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ActiveAdmin
4
- # tests for dsl
5
- module Xls
6
- describe ::ActiveAdmin::ResourceDSL do
7
- context 'in a registration block' do
8
- let(:builder) do
9
- config = ActiveAdmin.register(Post) do
10
- xls(i18n_scope: [:rspec], header_style: { size: 20 }) do
11
- delete_columns :id, :created_at
12
- column(:author) { |post| post.author.first_name }
13
- before_filter do |sheet|
14
- row_number = sheet.dimensions[1]
15
- sheet.update_row(row_number, 'before_filter')
16
- end
17
- after_filter do |sheet|
18
- row_number = sheet.dimensions[1]
19
- sheet.update_row(row_number, 'after_filter')
20
- end
21
- skip_header
22
- end
23
- end
24
- config.xls_builder
25
- end
26
-
27
- it 'uses our customized i18n scope' do
28
- expect(builder.i18n_scope).to eq([:rspec])
29
- end
30
-
31
- it 'removed the columns we told it to ignore' do
32
- %i[id create_at].each do |removed|
33
- column_index = builder.columns.index { |col| col.name == removed }
34
- expect(column_index).to be_nil
35
- end
36
- end
37
-
38
- it 'added the columns we declared' do
39
- added_index = builder.columns.index { |col| col.name == :author }
40
- expect(added_index).not_to be_nil
41
- end
42
-
43
- it 'has a before filter set' do
44
- expect(builder.instance_values['before_filter']).to be_a(Proc)
45
- end
46
-
47
- it 'has an after filter set' do
48
- expect(builder.instance_values['after_filter']).to be_a(Proc)
49
- end
50
-
51
- it 'indicates that the header should be excluded' do
52
- expect(builder.instance_values['skip_header']).to be_truthy
53
- end
54
-
55
- it 'updates the header style' do
56
- expect(builder.header_style[:size]).to eq(20)
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- describe Admin::CategoriesController, type: :controller do
3
- let(:mime) { Mime::Type.lookup_by_extension(:xls) }
4
-
5
- let(:filename) do
6
- "categories-#{Time.now.strftime('%Y-%m-%d')}.xls"
7
- end
8
-
9
- it 'generates an xls filename' do
10
- expect(controller.xls_filename).to eq(filename)
11
- end
12
-
13
- context 'when making requests with the xls mime type' do
14
- it 'returns xls attachment when requested' do
15
- request.accept = mime
16
- get :index
17
- disposition = "attachment; filename=\"#{filename}\""
18
- expect(response.headers['Content-Disposition']).to start_with(disposition)
19
- expect(response.headers['Content-Transfer-Encoding']).to eq('binary')
20
- end
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- include ActiveAdmin
3
-
4
- module ActiveAdmin
5
- module Xls
6
- describe Resource do
7
- let(:resource) { ActiveAdmin.register(Post) }
8
-
9
- let(:custom_builder) do
10
- Builder.new(Post) do
11
- column(:fake) { :fake }
12
- end
13
- end
14
-
15
- context 'when registered' do
16
- it 'each resource has an xls_builder' do
17
- expect(resource.xls_builder).to be_a(Builder)
18
- end
19
-
20
- it 'We can specify our own configured builder' do
21
- expect { resource.xls_builder = custom_builder }.not_to raise_error
22
- end
23
- end
24
- end
25
- end
26
- end