activeadmin 1.0.0.pre5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -0
  3. data/.travis.yml +21 -23
  4. data/Appraisals +12 -74
  5. data/CHANGELOG.md +21 -5
  6. data/CONTRIBUTING.md +2 -2
  7. data/Gemfile +8 -9
  8. data/README.md +19 -56
  9. data/Rakefile +1 -1
  10. data/activeadmin.gemspec +4 -4
  11. data/app/assets/stylesheets/active_admin/_forms.scss +10 -0
  12. data/config/locales/ca.yml +1 -1
  13. data/config/locales/da.yml +44 -12
  14. data/config/locales/el.yml +1 -1
  15. data/config/locales/en.yml +2 -0
  16. data/config/locales/fr.yml +16 -2
  17. data/config/locales/ja.yml +1 -0
  18. data/config/locales/zh-CN.yml +4 -0
  19. data/docs/12-arbre-components.md +23 -0
  20. data/docs/14-gotchas.md +1 -1
  21. data/docs/2-resource-customization.md +2 -5
  22. data/docs/5-forms.md +19 -0
  23. data/docs/6-show-pages.md +0 -28
  24. data/docs/9-batch-actions.md +0 -1
  25. data/docs/CNAME +1 -1
  26. data/docs/_includes/head.html +4 -4
  27. data/docs/_includes/toc.html +2 -1
  28. data/docs/documentation.md +2 -2
  29. data/docs/index.html +1 -6
  30. data/docs/stylesheets/main.css +172 -219
  31. data/features/belongs_to.feature +5 -5
  32. data/features/comments/commenting.feature +0 -13
  33. data/features/create_another.feature +55 -0
  34. data/features/development_reloading.feature +2 -4
  35. data/features/edit_page.feature +6 -7
  36. data/features/favicon.feature +2 -2
  37. data/features/i18n.feature +1 -0
  38. data/features/index/filters.feature +18 -0
  39. data/features/index/format_as_csv.feature +3 -3
  40. data/features/index/formats.feature +22 -0
  41. data/features/index/index_as_table.feature +6 -6
  42. data/features/index/page_title.feature +1 -2
  43. data/features/menu.feature +20 -1
  44. data/features/new_page.feature +6 -8
  45. data/features/registering_assets.feature +4 -4
  46. data/features/registering_pages.feature +18 -0
  47. data/features/renamed_resource.feature +2 -4
  48. data/features/show/page_title.feature +1 -2
  49. data/features/step_definitions/attribute_steps.rb +1 -1
  50. data/features/step_definitions/configuration_steps.rb +2 -2
  51. data/features/step_definitions/format_steps.rb +4 -0
  52. data/features/step_definitions/index_scope_steps.rb +1 -1
  53. data/features/step_definitions/menu_steps.rb +2 -2
  54. data/features/step_definitions/user_steps.rb +1 -1
  55. data/features/step_definitions/web_steps.rb +6 -5
  56. data/features/sti_resource.feature +2 -2
  57. data/features/strong_parameters.feature +0 -4
  58. data/features/support/env.rb +5 -19
  59. data/features/support/paths.rb +6 -9
  60. data/gemfiles/rails_42.gemfile +15 -23
  61. data/gemfiles/rails_50.gemfile +15 -16
  62. data/gemfiles/rails_51.gemfile +45 -0
  63. data/lib/active_admin/application.rb +4 -0
  64. data/lib/active_admin/base_controller.rb +2 -7
  65. data/lib/active_admin/base_controller/menu.rb +1 -5
  66. data/lib/active_admin/csv_builder.rb +2 -2
  67. data/lib/active_admin/dependency.rb +4 -8
  68. data/lib/active_admin/devise.rb +1 -1
  69. data/lib/active_admin/error.rb +1 -1
  70. data/lib/active_admin/filters/active.rb +2 -10
  71. data/lib/active_admin/filters/resource_extension.rb +1 -10
  72. data/lib/active_admin/inputs/filters/date_range_input.rb +1 -1
  73. data/lib/active_admin/inputs/filters/select_input.rb +1 -2
  74. data/lib/active_admin/inputs/filters/text_input.rb +2 -2
  75. data/lib/active_admin/menu.rb +1 -1
  76. data/lib/active_admin/namespace.rb +14 -7
  77. data/lib/active_admin/orm/active_record/comments.rb +2 -7
  78. data/lib/active_admin/orm/active_record/comments/comment.rb +2 -12
  79. data/lib/active_admin/page.rb +5 -0
  80. data/lib/active_admin/page_controller.rb +1 -5
  81. data/lib/active_admin/resource.rb +28 -5
  82. data/lib/active_admin/resource/attributes.rb +44 -0
  83. data/lib/active_admin/resource/menu.rb +4 -1
  84. data/lib/active_admin/resource/routes.rb +2 -3
  85. data/lib/active_admin/resource_controller.rb +13 -0
  86. data/lib/active_admin/resource_controller/data_access.rb +18 -9
  87. data/lib/active_admin/resource_dsl.rb +21 -18
  88. data/lib/active_admin/version.rb +1 -1
  89. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +1 -1
  90. data/lib/active_admin/view_helpers/display_helper.rb +10 -12
  91. data/lib/active_admin/view_helpers/download_format_links_helper.rb +12 -0
  92. data/lib/active_admin/view_helpers/fields_for.rb +1 -2
  93. data/lib/active_admin/view_helpers/form_helper.rb +1 -1
  94. data/lib/active_admin/views/components/active_admin_form.rb +28 -2
  95. data/lib/active_admin/views/components/paginated_collection.rb +3 -8
  96. data/lib/active_admin/views/components/table_for.rb +1 -1
  97. data/lib/active_admin/views/index_as_table.rb +2 -2
  98. data/lib/active_admin/views/pages/layout.rb +1 -1
  99. data/lib/active_admin/views/pages/show.rb +1 -1
  100. data/lib/bug_report_templates/rails_5_master.rb +1 -3
  101. data/lib/generators/active_admin/devise/devise_generator.rb +1 -1
  102. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +7 -0
  103. data/lib/generators/active_admin/install/templates/admin_user.rb.erb +0 -2
  104. data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb.erb +5 -7
  105. data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
  106. data/lib/generators/active_admin/resource/templates/{admin.rb → admin.rb.erb} +0 -2
  107. data/lib/ransack_ext.rb +2 -2
  108. data/spec/rails_helper.rb +1 -19
  109. data/spec/requests/default_namespace_spec.rb +40 -8
  110. data/spec/support/active_admin_integration_spec_helper.rb +9 -2
  111. data/spec/support/rails_template.rb +17 -20
  112. data/spec/support/rails_template_with_data.rb +3 -9
  113. data/spec/support/templates/admin/stores.rb +1 -3
  114. data/spec/unit/application_spec.rb +19 -8
  115. data/spec/unit/belongs_to_spec.rb +6 -2
  116. data/spec/unit/comments_spec.rb +0 -19
  117. data/spec/unit/controller_filters_spec.rb +5 -5
  118. data/spec/unit/csv_builder_spec.rb +7 -4
  119. data/spec/unit/filters/active_spec.rb +1 -8
  120. data/spec/unit/filters/filter_form_builder_spec.rb +2 -3
  121. data/spec/unit/filters/resource_spec.rb +3 -4
  122. data/spec/unit/form_builder_spec.rb +39 -11
  123. data/spec/unit/namespace/register_page_spec.rb +1 -1
  124. data/spec/unit/pretty_format_spec.rb +39 -35
  125. data/spec/unit/resource/attributes_spec.rb +50 -0
  126. data/spec/unit/resource/includes_spec.rb +1 -1
  127. data/spec/unit/resource/ordering_spec.rb +1 -1
  128. data/spec/unit/resource/routes_spec.rb +2 -2
  129. data/spec/unit/resource_controller/data_access_spec.rb +51 -10
  130. data/spec/unit/resource_controller/decorators_spec.rb +2 -2
  131. data/spec/unit/resource_controller/sidebars_spec.rb +3 -3
  132. data/spec/unit/resource_controller_spec.rb +16 -5
  133. data/spec/unit/resource_spec.rb +12 -38
  134. data/spec/unit/routing_spec.rb +2 -2
  135. data/spec/unit/view_helpers/breadcrumbs_spec.rb +36 -1
  136. data/spec/unit/view_helpers/display_helper_spec.rb +17 -2
  137. data/spec/unit/view_helpers/fields_for_spec.rb +1 -1
  138. data/spec/unit/view_helpers/form_helper_spec.rb +3 -3
  139. data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +2 -2
  140. data/spec/unit/views/components/attributes_table_spec.rb +2 -2
  141. data/spec/unit/views/components/index_list_spec.rb +1 -1
  142. data/spec/unit/views/components/paginated_collection_spec.rb +4 -4
  143. data/spec/unit/views/components/table_for_spec.rb +1 -1
  144. data/spec/unit/views/components/unsupported_browser_spec.rb +1 -1
  145. data/spec/unit/views/pages/form_spec.rb +4 -1
  146. data/spec/unit/views/pages/index_spec.rb +1 -1
  147. data/spec/unit/views/pages/show_spec.rb +2 -3
  148. data/tasks/lint.rake +8 -0
  149. metadata +22 -29
  150. data/features/step_definitions/symbol_leak_steps.rb +0 -3
  151. data/features/symbol_leak.feature +0 -35
  152. data/gemfiles/rails_32.gemfile +0 -54
  153. data/gemfiles/rails_40.gemfile +0 -53
  154. data/gemfiles/rails_41.gemfile +0 -53
  155. data/spec/support/deferred_garbage_collection.rb +0 -19
@@ -12,7 +12,7 @@ module ActiveAdmin
12
12
 
13
13
  def generate_config_file
14
14
  @boilerplate = ActiveAdmin::Generators::Boilerplate.new(class_name)
15
- template "admin.rb", "app/admin/#{file_path.tr('/', '_')}.rb"
15
+ template "admin.rb.erb", "app/admin/#{file_path.tr('/', '_')}.rb"
16
16
  end
17
17
 
18
18
  end
@@ -1,5 +1,4 @@
1
1
  ActiveAdmin.register <%= class_name %> do
2
- <% if ActiveAdmin::Dependency.rails.strong_parameters? %>
3
2
  # See permitted parameters documentation:
4
3
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
5
4
  #
@@ -12,7 +11,6 @@ ActiveAdmin.register <%= class_name %> do
12
11
  # permitted << :other if params[:action] == 'create' && current_user.admin?
13
12
  # permitted
14
13
  # end
15
- <% end %>
16
14
  <% if options.include_boilerplate? %>
17
15
  # Limit actions available to your users by adding them to the 'except' array
18
16
  # actions :all, except: []
@@ -2,11 +2,11 @@
2
2
  # identically to the versions given in Ransack.
3
3
  #
4
4
  Ransack.configure do |config|
5
- {'contains'=>'cont', 'starts_with'=>'start', 'ends_with'=>'end'}.each do |old,current|
5
+ {'contains'=>'cont', 'starts_with'=>'start', 'ends_with'=>'end'}.each do |old, current|
6
6
  config.add_predicate old, Ransack::Constants::DERIVED_PREDICATES.detect{ |q, _| q == current }[1]
7
7
  end
8
8
 
9
- {'equals'=>'eq', 'greater_than'=>'gt', 'less_than'=>'lt'}.each do |old,current|
9
+ {'equals'=>'eq', 'greater_than'=>'gt', 'less_than'=>'lt'}.each do |old, current|
10
10
  config.add_predicate old, arel_predicate: current
11
11
  end
12
12
 
@@ -19,10 +19,6 @@ require ENV['RAILS_ROOT'] + '/config/environment'
19
19
 
20
20
  require 'rspec/rails'
21
21
 
22
- # Prevent Test::Unit's AutoRunner from executing during RSpec's rake task on
23
- # JRuby
24
- Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)
25
-
26
22
  # Disabling authentication in specs so that we don't have to worry about
27
23
  # it allover the place
28
24
  ActiveAdmin.application.authentication_method = false
@@ -56,25 +52,11 @@ RSpec.configure do |config|
56
52
  end
57
53
 
58
54
  # Force deprecations to raise an exception.
59
- # This would set `behavior = :raise`, but that wasn't added until Rails 4.
60
- ActiveSupport::Deprecation.behavior = -> message, callstack do
61
- e = StandardError.new message
62
- e.set_backtrace callstack.map(&:to_s)
63
- raise e
64
- end
55
+ ActiveSupport::Deprecation.behavior = :raise
65
56
 
66
57
  # improve the performance of the specs suite by not logging anything
67
58
  # see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
68
59
  Rails.logger.level = Logger::FATAL
69
60
 
70
- # Improves performance by forcing the garbage collector to run less often.
71
- unless ENV['DEFER_GC'] == '0' || ENV['DEFER_GC'] == 'false'
72
- require 'support/deferred_garbage_collection'
73
- RSpec.configure do |config|
74
- config.before(:all) { DeferredGarbageCollection.start }
75
- config.after(:all) { DeferredGarbageCollection.reconsider }
76
- end
77
- end
78
-
79
61
  # Make input type=hidden visible
80
62
  Capybara.ignore_hidden_elements = false
@@ -4,15 +4,18 @@ RSpec.describe ActiveAdmin::Application, type: :request do
4
4
 
5
5
  include Rails.application.routes.url_helpers
6
6
 
7
+ let(:resource) { ActiveAdmin.register Category }
8
+
7
9
  [false, nil].each do |value|
8
10
 
9
11
  describe "with a #{value} default namespace" do
10
12
 
11
- around(:all) do |example|
12
- application = ActiveAdmin::Application.new
13
- application.default_namespace = value
13
+ around do |example|
14
+ with_custom_default_namespace(value) { example.call }
15
+ end
14
16
 
15
- with_temp_application(application) { example.call }
17
+ it "should generate resource paths" do
18
+ expect(resource.route_collection_path).to eq "/categories"
16
19
  end
17
20
 
18
21
  it "should generate a log out path" do
@@ -29,11 +32,12 @@ RSpec.describe ActiveAdmin::Application, type: :request do
29
32
 
30
33
  describe "with a test default namespace" do
31
34
 
32
- around(:all) do |example|
33
- application = ActiveAdmin::Application.new
34
- application.default_namespace = :test
35
+ around do |example|
36
+ with_custom_default_namespace(:test) { example.call }
37
+ end
35
38
 
36
- with_temp_application(application) { example.call }
39
+ it "should generate resource paths" do
40
+ expect(resource.route_collection_path).to eq "/test/categories"
37
41
  end
38
42
 
39
43
  it "should generate a log out path" do
@@ -46,4 +50,32 @@ RSpec.describe ActiveAdmin::Application, type: :request do
46
50
 
47
51
  end
48
52
 
53
+ describe "with a namespace with underscores in the name" do
54
+
55
+ around do |example|
56
+ with_custom_default_namespace(:abc_123) { example.call }
57
+ end
58
+
59
+ it "should generate resource paths" do
60
+ expect(resource.route_collection_path).to eq "/abc_123/categories"
61
+ end
62
+
63
+ it "should generate a log out path" do
64
+ expect(destroy_admin_user_session_path).to eq "/abc_123/logout"
65
+ end
66
+
67
+ it "should generate a log in path" do
68
+ expect(new_admin_user_session_path).to eq "/abc_123/login"
69
+ end
70
+
71
+ end
72
+
73
+ private
74
+
75
+ def with_custom_default_namespace(namespace)
76
+ application = ActiveAdmin::Application.new
77
+ application.default_namespace = namespace
78
+
79
+ with_temp_application(application) { yield }
80
+ end
49
81
  end
@@ -46,19 +46,26 @@ module ActiveAdminIntegrationSpecHelper
46
46
  # Returns a fake action view instance to use with our renderers
47
47
  def mock_action_view(assigns = {})
48
48
  controller = ActionView::TestCase::TestController.new
49
+ #this line needed because of rails bug https://github.com/rails/rails/commit/d8e98897b5703ac49bf0764da71a06d64ecda9b0
50
+ controller.params = ActionController::Parameters.new
49
51
  MockActionView.new(ActionController::Base.view_paths, assigns, controller)
50
52
  end
51
53
  alias_method :action_view, :mock_action_view
52
54
 
53
55
  # A mock action view to test view helpers
54
56
  class MockActionView < ::ActionView::Base
55
- include ActionView::Helpers
56
57
  include ActiveAdmin::ViewHelpers
57
58
  include Rails.application.routes.url_helpers
58
59
  end
59
60
 
60
61
  def with_translation(translation)
61
- I18n.backend.store_translations :en, translation
62
+ # If no translations have been loaded, any later calls to `I18n.t` will
63
+ # cause the full translation hash to be loaded, possibly overwritting what
64
+ # we've loaded via `store_translations`. We use this hack to prevent that.
65
+ # @todo Might not be necessary anymore once
66
+ # https://github.com/svenfuchs/i18n/pull/353 lands.
67
+ I18n.backend.send(:init_translations)
68
+ I18n.backend.store_translations I18n.locale, translation
62
69
  yield
63
70
  ensure
64
71
  I18n.backend.reload!
@@ -1,8 +1,10 @@
1
1
  # Rails template to build the sample app for specs
2
2
 
3
- if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
4
- copy_file File.expand_path('../templates/manifest.js', __FILE__), 'app/assets/config/manifest.js', force: true
5
- end
3
+ copy_file File.expand_path('../templates/manifest.js', __FILE__), 'app/assets/config/manifest.js', force: true
4
+
5
+ create_file 'app/assets/stylesheets/some-random-css.css'
6
+ create_file 'app/assets/javascripts/some-random-js.js'
7
+ create_file 'app/assets/images/a/favicon.ico'
6
8
 
7
9
  generate :model, 'post title:string body:text published_date:date author_id:integer ' +
8
10
  'position:integer custom_category_id:integer starred:boolean foo_id:integer'
@@ -26,7 +28,7 @@ create_file 'app/models/post.rb', <<-RUBY.strip_heredoc, force: true
26
28
  # nothing to see here
27
29
  end
28
30
 
29
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
31
+ if defined? ProtectedAttributes
30
32
  attr_accessible :id, :title, :body, :starred, :author, :position, :published_date, :author_id, :custom_category_id, :category
31
33
  end
32
34
  end
@@ -43,7 +45,7 @@ create_file 'app/models/blog/post.rb', <<-RUBY.strip_heredoc, force: true
43
45
  accepts_nested_attributes_for :author
44
46
  accepts_nested_attributes_for :taggings
45
47
 
46
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
48
+ if defined? ProtectedAttributes
47
49
  attr_accessible :title, :body, :starred, :author, :position, :published_date, :author_id, :custom_category_id, :category
48
50
  end
49
51
  end
@@ -62,7 +64,7 @@ create_file 'app/models/user.rb', <<-RUBY.strip_heredoc, force: true
62
64
  parent.table[:age]
63
65
  end
64
66
 
65
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
67
+ if defined? ProtectedAttributes
66
68
  attr_accessible :first_name, :last_name, :username, :age
67
69
  end
68
70
 
@@ -76,7 +78,7 @@ create_file 'app/models/profile.rb', <<-RUBY.strip_heredoc, force: true
76
78
  class Profile < ActiveRecord::Base
77
79
  belongs_to :user
78
80
 
79
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
81
+ if defined? ProtectedAttributes
80
82
  attr_accessible :bio
81
83
  end
82
84
  end
@@ -91,7 +93,7 @@ create_file 'app/models/category.rb', <<-RUBY.strip_heredoc, force: true
91
93
  has_many :authors, through: :posts
92
94
  accepts_nested_attributes_for :posts
93
95
 
94
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
96
+ if defined? ProtectedAttributes
95
97
  attr_accessible :name, :description
96
98
  end
97
99
  end
@@ -115,7 +117,7 @@ create_file 'app/models/tag.rb', <<-RUBY.strip_heredoc, force: true
115
117
  self.id = SecureRandom.uuid
116
118
  end
117
119
 
118
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
120
+ if defined? ProtectedAttributes
119
121
  attr_accessible :name
120
122
  end
121
123
  end
@@ -133,17 +135,18 @@ gsub_file 'config/environments/test.rb', / config.cache_classes = true/, <<-RUB
133
135
 
134
136
  config.cache_classes = !ENV['CLASS_RELOADING']
135
137
  config.action_mailer.default_url_options = {host: 'example.com'}
136
- config.assets.digest = false
138
+ config.assets.precompile += %w( some-random-css.css some-random-js.js a/favicon.ico )
139
+
140
+ config.active_record.maintain_test_schema = false
137
141
 
138
- if Rails::VERSION::MAJOR >= 4 && Rails::VERSION::MINOR >= 1
139
- config.active_record.maintain_test_schema = false
142
+ if Rails::VERSION::MAJOR >= 5
143
+ config.active_record.belongs_to_required_by_default = false
140
144
  end
141
145
 
142
146
  RUBY
143
147
 
144
148
  # Add our local Active Admin to the application
145
149
  gem 'activeadmin', path: '../..'
146
- gem 'inherited_resources', git: 'https://github.com/activeadmin/inherited_resources'
147
150
  gem 'devise'
148
151
 
149
152
  run 'bundle install'
@@ -154,7 +157,7 @@ generate 'active_admin:install'
154
157
  # Force strong parameters to raise exceptions
155
158
  inject_into_file 'config/application.rb', <<-RUBY, after: 'class Application < Rails::Application'
156
159
 
157
- config.action_controller.action_on_unpermitted_parameters = :raise if Rails::VERSION::MAJOR >= 4
160
+ config.action_controller.action_on_unpermitted_parameters = :raise
158
161
 
159
162
  RUBY
160
163
 
@@ -171,12 +174,6 @@ if ENV['RAILS_ENV'] != 'test'
171
174
  inject_into_file 'config/routes.rb', "\n root to: redirect('admin')", after: /.*routes.draw do/
172
175
  end
173
176
 
174
- remove_file 'public/index.html' if File.exists? 'public/index.html' # remove once Rails 3.2 support is dropped
175
-
176
- # Devise master doesn't set up its secret key on Rails 4.1
177
- # https://github.com/plataformatec/devise/issues/2554
178
- gsub_file 'config/initializers/devise.rb', /# config.secret_key =/, 'config.secret_key ='
179
-
180
177
  rake "db:drop db:create db:migrate", env: 'development'
181
178
  rake "db:drop db:create db:migrate", env: 'test'
182
179
 
@@ -6,23 +6,17 @@ end
6
6
 
7
7
  inject_into_file 'app/admin/category.rb', <<-RUBY, after: "ActiveAdmin.register Category do\n"
8
8
 
9
- if Rails::VERSION::MAJOR >= 4
10
- permit_params [:name, :description]
11
- end
9
+ permit_params [:name, :description]
12
10
  RUBY
13
11
 
14
12
  inject_into_file 'app/admin/user.rb', <<-RUBY, after: "ActiveAdmin.register User do\n"
15
13
 
16
- if Rails::VERSION::MAJOR >= 4
17
- permit_params [:first_name, :last_name, :username, :age]
18
- end
14
+ permit_params [:first_name, :last_name, :username, :age]
19
15
  RUBY
20
16
 
21
17
  inject_into_file 'app/admin/post.rb', <<-RUBY, after: "ActiveAdmin.register Post do\n"
22
18
 
23
- if Rails::VERSION::MAJOR >= 4
24
- permit_params [:custom_category_id, :author_id, :title, :body, :published_date, :position, :starred]
25
- end
19
+ permit_params [:custom_category_id, :author_id, :title, :body, :published_date, :position, :starred]
26
20
 
27
21
  scope :all, default: true
28
22
 
@@ -1,8 +1,6 @@
1
1
  ActiveAdmin.register Store do
2
2
 
3
- if Rails::VERSION::MAJOR >= 4
4
- permit_params :name
5
- end
3
+ permit_params :name
6
4
 
7
5
  index pagination_total: false
8
6
 
@@ -3,11 +3,16 @@ require 'fileutils'
3
3
 
4
4
  RSpec.describe ActiveAdmin::Application do
5
5
 
6
- let(:application) do
7
- ActiveAdmin::Application.new.tap do |app|
8
- # Manually override the load paths becuase RSpec messes these up
9
- app.load_paths = [File.expand_path('app/admin', Rails.root)]
10
- end
6
+ let(:application) { ActiveAdmin::Application.new }
7
+
8
+ around do |example|
9
+ old_load_paths = application.load_paths
10
+ # TODO: Figure out why load paths need to be overriden
11
+ application.load_paths = [File.expand_path('app/admin', Rails.root)]
12
+
13
+ example.call
14
+
15
+ application.load_paths = old_load_paths
11
16
  end
12
17
 
13
18
  it "should have a default load path of ['app/admin']" do
@@ -120,10 +125,16 @@ RSpec.describe ActiveAdmin::Application do
120
125
  end
121
126
 
122
127
  it "should load files from subdirectories" do
123
- FileUtils.mkdir_p(File.expand_path("app/admin/public", Rails.root))
128
+ test_dir = File.expand_path("app/admin/public", Rails.root)
124
129
  test_file = File.expand_path("app/admin/public/posts.rb", Rails.root)
125
- FileUtils.touch(test_file)
126
- expect(application.files).to include(test_file)
130
+
131
+ begin
132
+ FileUtils.mkdir_p(test_dir)
133
+ FileUtils.touch(test_file)
134
+ expect(application.files).to include(test_file)
135
+ ensure
136
+ FileUtils.remove_entry_secure(test_dir, force: true)
137
+ end
127
138
  end
128
139
  end
129
140
 
@@ -57,14 +57,18 @@ RSpec.describe ActiveAdmin::Resource::BelongsTo do
57
57
 
58
58
  describe "controller" do
59
59
  let(:controller) { post_config.controller.new }
60
+ let(:http_params) { {user_id: user.id} }
61
+ let(:user) { User.create! }
62
+
60
63
  before do
61
- user = User.create!
62
64
  request = double 'Request', format: 'application/json'
63
- allow(controller).to receive(:params) { {user_id: user.id} }
65
+ allow(controller).to receive(:params) { ActionController::Parameters.new(http_params) }
64
66
  allow(controller).to receive(:request){ request }
65
67
  end
68
+
66
69
  it 'should be able to access the collection' do
67
70
  expect(controller.send :collection).to be_a ActiveRecord::Relation
71
+
68
72
  end
69
73
  it 'should be able to build a new resource' do
70
74
  expect(controller.send :build_resource).to be_a Post
@@ -40,7 +40,6 @@ RSpec.describe "Comments" do
40
40
  end
41
41
 
42
42
  it "should return the most recent comment first by default" do
43
- ActiveAdmin::Comment.class_eval { attr_accessible :created_at } if Rails::VERSION::MAJOR == 3
44
43
  another_comment = ActiveAdmin::Comment.create! resource: post,
45
44
  body: "Another Comment",
46
45
  namespace: namespace_name,
@@ -86,18 +85,6 @@ RSpec.describe "Comments" do
86
85
  end
87
86
  end
88
87
 
89
- describe ".resource_id_cast" do
90
- let(:post) { Post.create!(title: "Testing.") }
91
- let(:namespace_name) { "admin" }
92
-
93
- it "should cast resource_id as string" do
94
- comment = ActiveAdmin::Comment.create! resource: post,
95
- body: "Another Comment",
96
- namespace: namespace_name
97
- expect(ActiveAdmin::Comment.resource_id_cast(comment).class).to eql String
98
- end
99
- end
100
-
101
88
  describe ".resource_type" do
102
89
  let(:post) { Post.create!(title: "Testing.") }
103
90
  let(:post_decorator) { double 'PostDecorator' }
@@ -124,12 +111,6 @@ RSpec.describe "Comments" do
124
111
  end
125
112
  end
126
113
 
127
- describe ".resource_id_type" do
128
- it "should be :string" do
129
- expect(ActiveAdmin::Comment.resource_id_type).to eql :string
130
- end
131
- end
132
-
133
114
  describe "Commenting on resource with string id" do
134
115
  let(:tag) { Tag.create!(name: "cooltags") }
135
116
  let(:namespace_name) { "admin" }
@@ -15,11 +15,11 @@ RSpec.describe ActiveAdmin::Application do
15
15
  expected_actions = (
16
16
  prefixes = %w(skip append prepend) << nil
17
17
  positions = %w(before around after)
18
- suffixes = %w(filter)
19
- base = %w(skip_filter)
20
- if Rails::VERSION::MAJOR >= 4
21
- suffixes += %w(action)
22
- base += %w(skip_action_callback)
18
+ suffixes = %w(action)
19
+ base = %w()
20
+ if ActiveAdmin::Dependency.rails? '< 5.1.x'
21
+ suffixes += %w(filter)
22
+ base += %w(skip_filter skip_action_callback)
23
23
  end
24
24
 
25
25
  prefixes.each_with_object(base) do |prefix, stack|
@@ -5,7 +5,10 @@ require 'rails_helper'
5
5
  RSpec.describe ActiveAdmin::CSVBuilder do
6
6
 
7
7
  describe '.default_for_resource using Post' do
8
- let(:csv_builder) { ActiveAdmin::CSVBuilder.default_for_resource(Post).tap(&:exec_columns) }
8
+ let(:application){ ActiveAdmin::Application.new }
9
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
10
+ let(:resource){ ActiveAdmin::Resource.new(namespace, Post, {}) }
11
+ let(:csv_builder) { ActiveAdmin::CSVBuilder.default_for_resource(resource).tap(&:exec_columns) }
9
12
 
10
13
  it 'returns a default csv_builder for Post' do
11
14
  expect(csv_builder).to be_a(ActiveAdmin::CSVBuilder)
@@ -18,8 +21,8 @@ RSpec.describe ActiveAdmin::CSVBuilder do
18
21
 
19
22
  it "has Post's content_columns" do
20
23
  csv_builder.columns[1..-1].each_with_index do |column, index|
21
- expect(column.name).to eq Post.content_columns[index].name.humanize
22
- expect(column.data).to eq Post.content_columns[index].name.to_sym
24
+ expect(column.name).to eq resource.content_columns[index].to_s.humanize
25
+ expect(column.data).to eq resource.content_columns[index]
23
26
  end
24
27
  end
25
28
 
@@ -32,7 +35,7 @@ RSpec.describe ActiveAdmin::CSVBuilder do
32
35
  end
33
36
 
34
37
  it 'gets name from I18n' do
35
- title_index = Post.content_columns.map(&:name).index('title') + 1 # First col is always id
38
+ title_index = resource.content_columns.index(:title) + 1 # First col is always id
36
39
  expect(csv_builder.columns[title_index].name).to eq localized_name
37
40
  end
38
41
  end