activeadmin 1.0.0.pre2 → 1.0.0.pre3

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.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +7 -4
  3. data/.travis.yml +17 -15
  4. data/CHANGELOG.md +5 -1
  5. data/CODE_OF_CONDUCT.md +22 -0
  6. data/Gemfile +26 -12
  7. data/README.md +24 -4
  8. data/activeadmin.gemspec +1 -0
  9. data/app/assets/javascripts/active_admin/base.js.coffee +1 -1
  10. data/app/assets/javascripts/active_admin/initializers/batch_actions.js.coffee +7 -0
  11. data/app/assets/javascripts/active_admin/initializers/datepicker.js.coffee +10 -0
  12. data/app/assets/javascripts/active_admin/initializers/filters.js.coffee +15 -0
  13. data/app/assets/javascripts/active_admin/initializers/tabs.js.coffee +3 -0
  14. data/app/assets/javascripts/active_admin/lib/batch_actions.js.coffee +1 -1
  15. data/app/assets/javascripts/active_admin/lib/dropdown-menu.js.coffee +1 -1
  16. data/app/assets/stylesheets/active_admin/_forms.scss +1 -1
  17. data/config/locales/ar.yml +47 -43
  18. data/config/locales/de.yml +2 -1
  19. data/config/locales/en.yml +2 -1
  20. data/config/locales/es-MX.yml +3 -3
  21. data/config/locales/es.yml +5 -4
  22. data/config/locales/fr.yml +2 -1
  23. data/config/locales/hu.yml +1 -1
  24. data/config/locales/id.yml +2 -1
  25. data/config/locales/it.yml +19 -0
  26. data/config/locales/ja.yml +2 -1
  27. data/config/locales/ko.yml +2 -1
  28. data/config/locales/nb.yml +6 -1
  29. data/config/locales/nl.yml +1 -1
  30. data/config/locales/pt-BR.yml +5 -1
  31. data/config/locales/ru.yml +4 -3
  32. data/config/locales/sv-SE.yml +3 -2
  33. data/config/locales/tr.yml +83 -44
  34. data/config/locales/uk.yml +13 -12
  35. data/config/locales/zh-CN.yml +2 -1
  36. data/config/locales/zh-TW.yml +10 -1
  37. data/cucumber.yml +1 -1
  38. data/docs/0-installation.md +24 -10
  39. data/docs/1-general-configuration.md +22 -0
  40. data/docs/12-arbre-components.md +1 -1
  41. data/docs/13-authorization-adapter.md +1 -1
  42. data/docs/14-gotchas.md +11 -3
  43. data/docs/2-resource-customization.md +16 -3
  44. data/docs/3-index-pages.md +1 -1
  45. data/docs/3-index-pages/index-as-table.md +13 -1
  46. data/docs/4-csv-format.md +19 -0
  47. data/docs/5-forms.md +14 -2
  48. data/docs/6-show-pages.md +1 -1
  49. data/features/decorators.feature +2 -0
  50. data/features/development_reloading.feature +1 -1
  51. data/features/edit_page.feature +4 -4
  52. data/features/index/batch_actions.feature +13 -0
  53. data/features/index/page_title.feature +2 -1
  54. data/features/new_page.feature +4 -4
  55. data/features/renamed_resource.feature +1 -1
  56. data/features/show/default_content.feature +1 -1
  57. data/features/show/page_title.feature +2 -1
  58. data/features/step_definitions/attribute_steps.rb +2 -2
  59. data/features/step_definitions/factory_steps.rb +2 -2
  60. data/features/step_definitions/filter_steps.rb +2 -2
  61. data/features/step_definitions/format_steps.rb +1 -1
  62. data/features/sti_resource.feature +2 -2
  63. data/features/strong_parameters.feature +3 -3
  64. data/features/support/env.rb +21 -4
  65. data/lib/active_admin/application.rb +11 -4
  66. data/lib/active_admin/authorization_adapter.rb +1 -1
  67. data/lib/active_admin/base_controller.rb +12 -2
  68. data/lib/active_admin/base_controller/authorization.rb +4 -7
  69. data/lib/active_admin/base_controller/menu.rb +5 -1
  70. data/lib/active_admin/batch_actions/controller.rb +0 -1
  71. data/lib/active_admin/batch_actions/resource_extension.rb +3 -2
  72. data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -0
  73. data/lib/active_admin/csv_builder.rb +18 -15
  74. data/lib/active_admin/dependency.rb +74 -1
  75. data/lib/active_admin/error.rb +1 -1
  76. data/lib/active_admin/filters/active.rb +4 -3
  77. data/lib/active_admin/filters/resource_extension.rb +7 -3
  78. data/lib/active_admin/generators/boilerplate.rb +8 -0
  79. data/lib/active_admin/inputs/filters/base.rb +3 -1
  80. data/lib/active_admin/inputs/filters/base/search_method_select.rb +3 -3
  81. data/lib/active_admin/inputs/filters/date_range_input.rb +2 -2
  82. data/lib/active_admin/inputs/filters/select_input.rb +3 -2
  83. data/lib/active_admin/orm/active_record/comments.rb +13 -8
  84. data/lib/active_admin/page_controller.rb +5 -1
  85. data/lib/active_admin/reloader.rb +25 -0
  86. data/lib/active_admin/resource/menu.rb +1 -1
  87. data/lib/active_admin/resource_controller/data_access.rb +33 -20
  88. data/lib/active_admin/resource_controller/decorators.rb +2 -2
  89. data/lib/active_admin/resource_controller/streaming.rb +7 -1
  90. data/lib/active_admin/resource_dsl.rb +15 -9
  91. data/lib/active_admin/router.rb +1 -1
  92. data/lib/active_admin/scope.rb +2 -3
  93. data/lib/active_admin/version.rb +1 -1
  94. data/lib/active_admin/view_helpers/display_helper.rb +31 -0
  95. data/lib/active_admin/view_helpers/fields_for.rb +3 -2
  96. data/lib/active_admin/views/components/attributes_table.rb +5 -23
  97. data/lib/active_admin/views/components/index_list.rb +1 -1
  98. data/lib/active_admin/views/components/paginated_collection.rb +3 -3
  99. data/lib/active_admin/views/components/site_title.rb +1 -1
  100. data/lib/active_admin/views/components/table_for.rb +8 -27
  101. data/lib/active_admin/views/index_as_grid.rb +2 -2
  102. data/lib/active_admin/views/index_as_table.rb +24 -2
  103. data/lib/active_admin/views/pages/base.rb +1 -1
  104. data/lib/active_admin/views/pages/form.rb +6 -2
  105. data/lib/active_admin/views/title_bar.rb +1 -1
  106. data/lib/generators/active_admin/assets/templates/active_admin.scss +1 -1
  107. data/lib/generators/active_admin/install/install_generator.rb +1 -1
  108. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +14 -4
  109. data/lib/generators/active_admin/resource/templates/admin.rb +8 -2
  110. data/lib/ransack_ext.rb +8 -0
  111. data/script/local +15 -6
  112. data/spec/rails_helper.rb +12 -1
  113. data/spec/requests/javascript_spec.rb +15 -13
  114. data/spec/requests/stylesheets_spec.rb +1 -1
  115. data/spec/support/detect_rails_version.rb +1 -1
  116. data/spec/support/rails_template.rb +117 -104
  117. data/spec/support/rails_template_with_data.rb +5 -9
  118. data/spec/support/templates/admin/stores.rb +1 -1
  119. data/spec/unit/action_builder_spec.rb +58 -56
  120. data/spec/unit/authorization/authorization_adapter_spec.rb +5 -5
  121. data/spec/unit/authorization/index_overriding_spec.rb +2 -1
  122. data/spec/unit/auto_link_spec.rb +1 -1
  123. data/spec/unit/batch_actions/resource_spec.rb +2 -2
  124. data/spec/unit/batch_actions/settings_spec.rb +13 -13
  125. data/spec/unit/comments_spec.rb +5 -5
  126. data/spec/unit/csv_builder_spec.rb +59 -0
  127. data/spec/unit/dsl_spec.rb +1 -1
  128. data/spec/unit/filters/filter_form_builder_spec.rb +5 -4
  129. data/spec/unit/filters/resource_spec.rb +7 -0
  130. data/spec/unit/form_builder_spec.rb +4 -1
  131. data/spec/unit/generators/install_spec.rb +4 -4
  132. data/spec/unit/helpers/collection_spec.rb +4 -4
  133. data/spec/unit/menu_collection_spec.rb +3 -3
  134. data/spec/unit/namespace/register_page_spec.rb +17 -18
  135. data/spec/unit/namespace/register_resource_spec.rb +20 -21
  136. data/spec/unit/namespace_spec.rb +4 -4
  137. data/spec/unit/pundit_adapter_spec.rb +3 -3
  138. data/spec/unit/resource/action_items_spec.rb +1 -1
  139. data/spec/unit/resource/naming_spec.rb +1 -1
  140. data/spec/unit/resource/routes_spec.rb +6 -2
  141. data/spec/unit/resource/scopes_spec.rb +2 -2
  142. data/spec/unit/resource_controller/decorators_spec.rb +11 -0
  143. data/spec/unit/resource_controller/sidebars_spec.rb +17 -24
  144. data/spec/unit/resource_spec.rb +14 -12
  145. data/spec/unit/routing_spec.rb +19 -14
  146. data/spec/unit/scope_spec.rb +28 -33
  147. data/spec/unit/view_helpers/display_helper_spec.rb +165 -0
  148. data/spec/unit/view_helpers/download_format_links_helper_spec.rb +9 -9
  149. data/spec/unit/views/components/attributes_table_spec.rb +1 -1
  150. data/spec/unit/views/components/blank_slate_spec.rb +3 -3
  151. data/spec/unit/views/components/index_table_for_spec.rb +82 -1
  152. data/spec/unit/views/components/paginated_collection_spec.rb +0 -1
  153. data/spec/unit/views/components/table_for_spec.rb +13 -8
  154. data/spec/unit/views/components/unsupported_browser_spec.rb +2 -8
  155. data/spec/unit/views/index_as_blog_spec.rb +76 -0
  156. data/spec/unit/views/pages/form_spec.rb +9 -0
  157. data/tasks/test.rake +13 -5
  158. metadata +27 -10
  159. data/app/assets/javascripts/active_admin/application.js.coffee +0 -37
  160. data/spec/support/templates/cucumber.rb +0 -24
  161. data/spec/support/templates/cucumber_with_reloading.rb +0 -5
  162. data/spec/unit/view_helpers/display_name_spec.rb +0 -71
@@ -1,12 +1,10 @@
1
- # Use the default
2
1
  apply File.expand_path("../rails_template.rb", __FILE__)
3
2
 
4
- # Register Active Admin controllers
5
- %w{ Post User Category }.each do |type|
3
+ %w{Post User Category}.each do |type|
6
4
  generate :'active_admin:resource', type
7
5
  end
8
6
 
9
- scopes = <<-EOF
7
+ inject_into_file 'app/admin/post.rb', <<-RUBY, after: "ActiveAdmin.register Post do\n"
10
8
  scope :all, default: true
11
9
 
12
10
  scope :drafts do |posts|
@@ -24,11 +22,9 @@ scopes = <<-EOF
24
22
  scope :my_posts do |posts|
25
23
  posts.where(author_id: current_admin_user.id)
26
24
  end
27
- EOF
28
- inject_into_file 'app/admin/posts.rb', scopes , after: "ActiveAdmin.register Post do\n"
25
+ RUBY
29
26
 
30
- # Setup some default data
31
- append_file "db/seeds.rb", <<-EOF
27
+ append_file "db/seeds.rb", "\n\n" + <<-RUBY.strip_heredoc
32
28
  users = ["Jimi Hendrix", "Jimmy Page", "Yngwie Malmsteen", "Eric Clapton", "Kirk Hammett"].collect do |name|
33
29
  first, last = name.split(" ")
34
30
  User.create! first_name: first,
@@ -54,6 +50,6 @@ append_file "db/seeds.rb", <<-EOF
54
50
  author: user,
55
51
  starred: true
56
52
  end
57
- EOF
53
+ RUBY
58
54
 
59
55
  rake 'db:seed'
@@ -1,6 +1,6 @@
1
1
  ActiveAdmin.register Store do
2
2
 
3
- if Rails::VERSION::MAJOR == 4
3
+ if Rails::VERSION::MAJOR >= 4
4
4
  permit_params :name
5
5
  end
6
6
 
@@ -1,20 +1,24 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe 'defining new actions from registration blocks' do
3
+ describe 'defining actions from registration blocks', type: :controller do
4
+ let(:klass){ Admin::PostsController }
5
+ render_views # https://github.com/rspec/rspec-rails/issues/860
4
6
 
5
- let(:controller){ Admin::PostsController }
7
+ before do
8
+ @controller = klass.new
9
+ end
6
10
 
7
- describe "generating a new member action" do
11
+ describe 'creates a member action' do
8
12
  before do
9
13
  action!
10
14
  reload_routes!
11
15
  end
12
16
 
13
17
  after(:each) do
14
- controller.clear_member_actions!
18
+ klass.clear_member_actions!
15
19
  end
16
20
 
17
- context "with a block" do
21
+ context 'with a block' do
18
22
  let(:action!) do
19
23
  ActiveAdmin.register Post do
20
24
  member_action :comment do
@@ -23,51 +27,61 @@ describe 'defining new actions from registration blocks' do
23
27
  end
24
28
  end
25
29
 
26
- it "should create a new public instance method" do
27
- expect(controller.public_instance_methods.collect(&:to_s)).to include("comment")
30
+ it 'should create a new public instance method' do
31
+ expect(klass.public_instance_methods.collect(&:to_s)).to include('comment')
28
32
  end
29
- it "should add itself to the member actions config" do
30
- expect(controller.active_admin_config.member_actions.size).to eq 1
33
+
34
+ it 'should add itself to the member actions config' do
35
+ expect(klass.active_admin_config.member_actions.size).to eq 1
31
36
  end
32
- it "should create a new named route" do
33
- expect(Rails.application.routes.url_helpers.methods.collect(&:to_s)).to include("comment_admin_post_path")
37
+
38
+ it 'should create a new named route' do
39
+ expect(Rails.application.routes.url_helpers.methods.collect(&:to_s)).to include('comment_admin_post_path')
34
40
  end
35
41
  end
36
42
 
37
- context "without a block" do
43
+ context 'without a block' do
38
44
  let(:action!) do
39
45
  ActiveAdmin.register Post do
40
46
  member_action :comment
41
47
  end
42
48
  end
43
- it "should still generate a new empty action" do
44
- expect(controller.public_instance_methods.collect(&:to_s)).to include("comment")
49
+
50
+ it 'should still generate a new empty action' do
51
+ expect(klass.public_instance_methods.collect(&:to_s)).to include('comment')
45
52
  end
46
53
  end
47
54
 
48
- context "with :title" do
55
+ context 'with :title' do
49
56
  let(:action!) do
50
57
  ActiveAdmin.register Post do
51
- member_action :comment, title: "My Awesome Comment"
58
+ member_action :comment, title: 'My Awesome Comment' do
59
+ render json: {a: 2}
60
+ end
52
61
  end
53
62
  end
54
63
 
55
- subject { find_before_filter controller, :comment }
64
+ it 'sets the page title' do
65
+ params = {id: 1}
66
+ params = {params: params} if ActiveAdmin::Dependency.rails5?
67
+ get :comment, params
56
68
 
57
- it { is_expected.to set_page_title_to "My Awesome Comment", for: controller }
69
+ expect(controller.instance_variable_get(:@page_title)).to eq 'My Awesome Comment'
70
+ end
58
71
  end
59
72
  end
60
73
 
61
- describe "generate a new collection action" do
74
+ describe 'creates a collection action' do
62
75
  before do
63
76
  action!
64
77
  reload_routes!
65
78
  end
79
+
66
80
  after(:each) do
67
- controller.clear_collection_actions!
81
+ klass.clear_collection_actions!
68
82
  end
69
83
 
70
- context "with a block" do
84
+ context 'with a block' do
71
85
  let(:action!) do
72
86
  ActiveAdmin.register Post do
73
87
  collection_action :comments do
@@ -75,58 +89,46 @@ describe 'defining new actions from registration blocks' do
75
89
  end
76
90
  end
77
91
  end
78
- it "should create a new public instance method" do
79
- expect(controller.public_instance_methods.collect(&:to_s)).to include("comments")
92
+
93
+ it 'should create a public instance method' do
94
+ expect(klass.public_instance_methods.collect(&:to_s)).to include('comments')
80
95
  end
81
- it "should add itself to the member actions config" do
82
- expect(controller.active_admin_config.collection_actions.size).to eq 1
96
+
97
+ it 'should add itself to the member actions config' do
98
+ expect(klass.active_admin_config.collection_actions.size).to eq 1
83
99
  end
84
- it "should create a new named route" do
85
- expect(Rails.application.routes.url_helpers.methods.collect(&:to_s)).to include("comments_admin_posts_path")
100
+
101
+ it 'should create a named route' do
102
+ expect(Rails.application.routes.url_helpers.methods.collect(&:to_s)).to include('comments_admin_posts_path')
86
103
  end
87
104
  end
88
- context "without a block" do
105
+
106
+ context 'without a block' do
89
107
  let(:action!) do
90
108
  ActiveAdmin.register Post do
91
109
  collection_action :comments
92
110
  end
93
111
  end
94
- it "should still generate a new empty action" do
95
- expect(controller.public_instance_methods.collect(&:to_s)).to include("comments")
112
+
113
+ it 'should still generate a new empty action' do
114
+ expect(klass.public_instance_methods.collect(&:to_s)).to include('comments')
96
115
  end
97
116
  end
98
- context "with :title" do
117
+
118
+ context 'with :title' do
99
119
  let(:action!) do
100
120
  ActiveAdmin.register Post do
101
- collection_action :comments, title: "My Awesome Comments"
121
+ collection_action :comments, title: 'My Awesome Comments' do
122
+ render json: {a: 2}
123
+ end
102
124
  end
103
125
  end
104
126
 
105
- subject { find_before_filter controller, :comments }
106
-
107
- it { is_expected.to set_page_title_to "My Awesome Comments", for: controller }
108
- end
109
- end
110
-
111
- def find_before_filter(controller, action)
112
- finder = if ActiveAdmin::Dependency.rails? '>= 4.1.0'
113
- ->c { c.kind == :before && c.instance_variable_get(:@if) == ["action_name == '#{action}'"] }
114
- else
115
- ->c { c.kind == :before && c.options[:only] == [action] }
116
- end
117
-
118
- controller._process_action_callbacks.detect &finder
119
- end
127
+ it 'sets the page title' do
128
+ get :comments
120
129
 
121
- RSpec::Matchers.define :set_page_title_to do |expected, options|
122
- match do |filter|
123
- filter.raw_filter.call
124
- @actual = options[:for].instance_variable_get(:@page_title)
125
- expect(@actual).to eq expected
126
- end
127
-
128
- failure_message do |filter|
129
- message = "expected before_filter to set the @page_title to '#{expected}', but was '#{@actual}'"
130
+ expect(controller.instance_variable_get(:@page_title)).to eq 'My Awesome Comments'
131
+ end
130
132
  end
131
133
  end
132
134
  end
@@ -7,7 +7,7 @@ describe ActiveAdmin::AuthorizationAdapter do
7
7
  describe "#authorized?" do
8
8
 
9
9
  it "should always return true" do
10
- expect(adapter.authorized?(:read, "Resource")).to be_truthy
10
+ expect(adapter.authorized?(:read, "Resource")).to eq true
11
11
  end
12
12
 
13
13
  end
@@ -41,19 +41,19 @@ describe ActiveAdmin::AuthorizationAdapter do
41
41
  let(:adapter) { auth_class.new(double, double) }
42
42
 
43
43
  it "should match against a class" do
44
- expect(adapter.authorized?(:read, String)).to be_truthy
44
+ expect(adapter.authorized?(:read, String)).to eq true
45
45
  end
46
46
 
47
47
  it 'should match against an instance' do
48
- expect(adapter.authorized?(:read, "String")).to be_truthy
48
+ expect(adapter.authorized?(:read, "String")).to eq true
49
49
  end
50
50
 
51
51
  it 'should not match a different class' do
52
- expect(adapter.authorized?(:read, Hash)).to be_falsey
52
+ expect(adapter.authorized?(:read, Hash)).to eq false
53
53
  end
54
54
 
55
55
  it 'should not match a different instance' do
56
- expect(adapter.authorized?(:read, {})).to be_falsey
56
+ expect(adapter.authorized?(:read, {})).to eq false
57
57
  end
58
58
 
59
59
  end
@@ -5,7 +5,8 @@ describe Admin::PostsController, 'Index overriding', type: :controller do
5
5
  controller.instance_eval do
6
6
  def index
7
7
  super do
8
- render text: 'Rendered from passed block' and return
8
+ render Dependency.rails.render_key => 'Rendered from passed block'
9
+ return
9
10
  end
10
11
  end
11
12
  end
@@ -14,7 +14,7 @@ describe "auto linking resources" do
14
14
  "/admin/posts/#{post.id}"
15
15
  end
16
16
 
17
- def authorized?(_action, _subject)
17
+ def authorized?(*)
18
18
  true
19
19
  end
20
20
 
@@ -12,7 +12,7 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
12
12
 
13
13
  it "should have the default action by default" do
14
14
  expect(resource.batch_actions.size).to eq 1
15
- expect(resource.batch_actions.first.sym == :destroy).to be_truthy
15
+ expect(resource.batch_actions.first.sym == :destroy).to eq true
16
16
  end
17
17
 
18
18
  end
@@ -35,7 +35,7 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
35
35
  end
36
36
 
37
37
  it "should store the block in the batch action" do
38
- expect(resource.batch_actions.first.block).to_not be_nil
38
+ expect(resource.batch_actions.first.block).to_not eq nil
39
39
  end
40
40
 
41
41
  end
@@ -8,42 +8,42 @@ describe "Batch Actions Settings" do
8
8
  it "should be disabled globally by default" do
9
9
  # Note: the default initializer would set it to true
10
10
 
11
- expect(app.batch_actions).to be_falsey
12
- expect(ns.batch_actions).to be_falsey
13
- expect(post_resource.batch_actions_enabled?).to be_falsey
11
+ expect(app.batch_actions).to eq false
12
+ expect(ns.batch_actions).to eq false
13
+ expect(post_resource.batch_actions_enabled?).to eq false
14
14
  end
15
15
 
16
16
  it "should be settable to true" do
17
17
  app.batch_actions = true
18
- expect(app.batch_actions).to be_truthy
18
+ expect(app.batch_actions).to eq true
19
19
  end
20
20
 
21
21
  it "should be an inheritable_setting" do
22
22
  app.batch_actions = true
23
- expect(ns.batch_actions).to be_truthy
23
+ expect(ns.batch_actions).to eq true
24
24
  end
25
25
 
26
26
  it "should be settable at the namespace level" do
27
27
  app.batch_actions = true
28
28
  ns.batch_actions = false
29
29
 
30
- expect(app.batch_actions).to be_truthy
31
- expect(ns.batch_actions).to be_falsey
30
+ expect(app.batch_actions).to eq true
31
+ expect(ns.batch_actions).to eq false
32
32
  end
33
33
 
34
34
  it "should be settable at the resource level" do
35
- expect(post_resource.batch_actions_enabled?).to be_falsey
35
+ expect(post_resource.batch_actions_enabled?).to eq false
36
36
  post_resource.batch_actions = true
37
- expect(post_resource.batch_actions_enabled?).to be_truthy
37
+ expect(post_resource.batch_actions_enabled?).to eq true
38
38
  end
39
39
 
40
40
  it "should inherit the setting on the resource from the namespace" do
41
41
  ns.batch_actions = false
42
- expect(post_resource.batch_actions_enabled?).to be_falsey
42
+ expect(post_resource.batch_actions_enabled?).to eq false
43
43
  expect(post_resource.batch_actions).to be_empty
44
44
 
45
45
  post_resource.batch_actions = true
46
- expect(post_resource.batch_actions_enabled?).to be_truthy
46
+ expect(post_resource.batch_actions_enabled?).to eq true
47
47
  expect(post_resource.batch_actions).to_not be_empty
48
48
  end
49
49
 
@@ -51,11 +51,11 @@ describe "Batch Actions Settings" do
51
51
  ns.batch_actions = true
52
52
 
53
53
  post_resource.batch_actions = true
54
- expect(post_resource.batch_actions_enabled?).to be_truthy
54
+ expect(post_resource.batch_actions_enabled?).to eq true
55
55
  expect(post_resource.batch_actions).to_not be_empty
56
56
 
57
57
  post_resource.batch_actions = nil
58
- expect(post_resource.batch_actions_enabled?).to be_truthy # inherited from namespace
58
+ expect(post_resource.batch_actions_enabled?).to eq true # inherited from namespace
59
59
  expect(post_resource.batch_actions).to_not be_empty
60
60
  end
61
61
  end
@@ -159,13 +159,13 @@ describe "Comments" do
159
159
  it "should have comments when the namespace allows comments" do
160
160
  ns = ActiveAdmin::Namespace.new(application, :admin)
161
161
  ns.comments = true
162
- expect(ns.comments?).to be_truthy
162
+ expect(ns.comments?).to eq true
163
163
  end
164
164
 
165
165
  it "should not have comments when the namespace does not allow comments" do
166
166
  ns = ActiveAdmin::Namespace.new(application, :admin)
167
167
  ns.comments = false
168
- expect(ns.comments?).to be_falsey
168
+ expect(ns.comments?).to eq false
169
169
  end
170
170
  end
171
171
  end
@@ -174,15 +174,15 @@ describe "Comments" do
174
174
  it "should add an attr_accessor :comments to ActiveAdmin::Resource" do
175
175
  ns = ActiveAdmin::Namespace.new(application, :admin)
176
176
  resource = ActiveAdmin::Resource.new(ns, Post)
177
- expect(resource.comments).to be_nil
177
+ expect(resource.comments).to eq nil
178
178
  resource.comments = true
179
- expect(resource.comments).to be_truthy
179
+ expect(resource.comments).to eq true
180
180
  end
181
181
  it "should disable comments if set to false" do
182
182
  ns = ActiveAdmin::Namespace.new(application, :admin)
183
183
  resource = ActiveAdmin::Resource.new(ns, Post)
184
184
  resource.comments = false
185
- expect(resource.comments?).to be_falsey
185
+ expect(resource.comments?).to eq false
186
186
  end
187
187
  end
188
188
  end
@@ -1,3 +1,5 @@
1
+ # Encoding: UTF-8
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  describe ActiveAdmin::CSVBuilder do
@@ -233,6 +235,63 @@ describe ActiveAdmin::CSVBuilder do
233
235
 
234
236
  end
235
237
 
238
+ context "build csv using specified encoding and encoding_options" do
239
+ let(:dummy_controller) do
240
+ class DummyController
241
+ def find_collection(*)
242
+ collection
243
+ end
244
+
245
+ def collection
246
+ Post
247
+ end
248
+
249
+ def apply_decorator(resource)
250
+ resource
251
+ end
252
+
253
+ def view_context
254
+ end
255
+ end
256
+ DummyController.new
257
+ end
258
+ let(:encoding) { Encoding::ASCII }
259
+ let(:opts) { {} }
260
+ let(:builder) do
261
+ ActiveAdmin::CSVBuilder.new(encoding: encoding, encoding_options: opts) do
262
+ column "おはようございます"
263
+ column "title"
264
+ end
265
+ end
266
+
267
+ context "Shift-JIS with options" do
268
+ let(:encoding) { Encoding::Shift_JIS }
269
+ let(:opts) { { invalid: :replace, undef: :replace, replace: "?" } }
270
+
271
+ it "encodes the CSV" do
272
+ receiver = []
273
+ builder.build dummy_controller, receiver
274
+ line = receiver.last
275
+ expect(line.encoding).to eq(encoding)
276
+ end
277
+ end
278
+
279
+ context "ASCII with options" do
280
+ let(:encoding) { Encoding::ASCII }
281
+ let(:opts) do
282
+ { invalid: :replace, undef: :replace, replace: "__REPLACED__" }
283
+ end
284
+
285
+ it "encodes the CSV without errors" do
286
+ receiver = []
287
+ builder.build dummy_controller, receiver
288
+ line = receiver.last
289
+ expect(line.encoding).to eq(encoding)
290
+ expect(line).to include("__REPLACED__")
291
+ end
292
+ end
293
+ end
294
+
236
295
  skip '#exec_columns'
237
296
 
238
297
  skip '#build_row' do