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
@@ -2,16 +2,9 @@ require 'rails_helper'
2
2
 
3
3
  RSpec.describe ActiveAdmin::Filters::Active do
4
4
  subject { described_class.new(Post, params) }
5
- let(:params_klass) do
6
- if defined? ::ActionController::Parameters
7
- ::ActionController::Parameters
8
- else
9
- HashWithIndifferentAccess #remove this when drop rails 3 support
10
- end
11
- end
12
5
 
13
6
  let(:params) do
14
- params_klass.new(q: {author_id_eq: 1})
7
+ ::ActionController::Parameters.new(q: {author_id_eq: 1})
15
8
  end
16
9
 
17
10
  it 'should have filters' do
@@ -150,9 +150,8 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
150
150
 
151
151
  it "should remove original ordering to prevent PostgreSQL error" do
152
152
  expect(scope.object.klass).to receive(:reorder).with('title asc') {
153
- distinct = ActiveAdmin::Dependency.rails >= 4 ? :distinct : :uniq
154
- m = double distinct => double(pluck: ['A Title'])
155
- expect(m.send(distinct)).to receive(:pluck).with :title
153
+ m = double distinct: double(pluck: ['A Title'])
154
+ expect(m.distinct).to receive(:pluck).with :title
156
155
  m
157
156
  }
158
157
  body
@@ -13,7 +13,7 @@ RSpec.describe ActiveAdmin::Filters::ResourceExtension do
13
13
 
14
14
  it "should return the defaults if no filters are set" do
15
15
  expect(resource.filters.keys).to match_array([
16
- :author, :body, :category, :created_at, :custom_created_at_searcher, :custom_title_searcher, :custom_searcher_numeric, :position, :published_date, :starred, :taggings, :title, :updated_at
16
+ :author, :body, :category, :created_at, :custom_created_at_searcher, :custom_title_searcher, :custom_searcher_numeric, :position, :published_date, :starred, :taggings, :title, :updated_at, :foo_id
17
17
  ])
18
18
  end
19
19
 
@@ -35,7 +35,7 @@ RSpec.describe ActiveAdmin::Filters::ResourceExtension do
35
35
  it "should return the defaults without associations if default association filters are disabled on the namespace" do
36
36
  resource.namespace.include_default_association_filters = false
37
37
  expect(resource.filters.keys).to match_array([
38
- :body, :created_at, :custom_created_at_searcher, :custom_title_searcher, :custom_searcher_numeric, :position, :published_date, :starred, :title, :updated_at
38
+ :body, :created_at, :custom_created_at_searcher, :custom_title_searcher, :custom_searcher_numeric, :position, :published_date, :starred, :title, :updated_at, :foo_id
39
39
  ])
40
40
  end
41
41
 
@@ -104,8 +104,7 @@ RSpec.describe ActiveAdmin::Filters::ResourceExtension do
104
104
  resource.add_filter :count, as: :string
105
105
 
106
106
  expect(resource.filters.keys).to match_array([
107
- :author, :body, :category, :count, :created_at, :custom_created_at_searcher, :custom_title_searcher, :custom_searcher_numeric, :position, :published_date, :starred, :taggings, :title, :updated_at
108
-
107
+ :author, :body, :category, :count, :created_at, :custom_created_at_searcher, :custom_title_searcher, :custom_searcher_numeric, :position, :published_date, :starred, :taggings, :title, :updated_at, :foo_id
109
108
  ])
110
109
  end
111
110
 
@@ -30,6 +30,10 @@ RSpec.describe ActiveAdmin::FormBuilder do
30
30
  args.inspect
31
31
  end
32
32
 
33
+ def view.action_name
34
+ 'edit'
35
+ end
36
+
33
37
  view
34
38
  end
35
39
 
@@ -135,17 +139,15 @@ RSpec.describe ActiveAdmin::FormBuilder do
135
139
  end
136
140
  end
137
141
 
138
- if Rails::VERSION::MAJOR > 3
139
- context "file input present" do
140
- let :body do
141
- build_form do |f|
142
- f.input :body, as: :file
143
- end
142
+ context "file input present" do
143
+ let :body do
144
+ build_form do |f|
145
+ f.input :body, as: :file
144
146
  end
147
+ end
145
148
 
146
- it "adds multipart attribute automatically" do
147
- expect(body).to have_selector("form[enctype='multipart/form-data']")
148
- end
149
+ it "adds multipart attribute automatically" do
150
+ expect(body).to have_selector("form[enctype='multipart/form-data']")
149
151
  end
150
152
  end
151
153
 
@@ -159,13 +161,39 @@ RSpec.describe ActiveAdmin::FormBuilder do
159
161
  end
160
162
  expect(body).to have_selector("[id=post_title]", count: 1)
161
163
  end
162
- it "should generate one button and a cancel link" do
164
+
165
+ context "create another checkbox" do
166
+ subject do
167
+ build_form do |f|
168
+ f.actions
169
+ end
170
+ end
171
+
172
+ %w(new create).each do |action_name|
173
+ it "generates create another checkbox on #{action_name} page" do
174
+ expect(helpers).to receive(:action_name) { action_name }
175
+ allow(helpers).to receive(:active_admin_config) { instance_double(ActiveAdmin::Resource, create_another: true) }
176
+
177
+ is_expected.to have_selector("[type=checkbox]", count: 1)
178
+ .and have_selector("[name=create_another]", count: 1)
179
+ end
180
+ end
181
+
182
+ %w(show edit update).each do |action_name|
183
+ it "doesn't generate create another checkbox on #{action_name} page" do
184
+ is_expected.not_to have_selector("[name=create_another]", count: 1)
185
+ end
186
+ end
187
+ end
188
+
189
+ it "should generate one button create another checkbox and a cancel link" do
163
190
  body = build_form do |f|
164
191
  f.actions
165
192
  end
166
193
  expect(body).to have_selector("[type=submit]", count: 1)
167
194
  expect(body).to have_selector("[class=cancel]", count: 1)
168
195
  end
196
+
169
197
  it "should generate multiple actions" do
170
198
  body = build_form do |f|
171
199
  f.actions do
@@ -526,7 +554,7 @@ RSpec.describe ActiveAdmin::FormBuilder do
526
554
  let :body do
527
555
  build_form({url: '/categories'}, Category.new) do |f|
528
556
  f.object.posts.build
529
- f.has_many :posts do |p,i|
557
+ f.has_many :posts do |p, i|
530
558
  p.input :title, label: "Title #{i}"
531
559
  end
532
560
  end
@@ -87,7 +87,7 @@ RSpec.describe ActiveAdmin::Namespace, "registering a page" do
87
87
  context "when optional" do
88
88
  before do
89
89
  namespace.register_page "Reports" do
90
- belongs_to :author, :optional => true
90
+ belongs_to :author, optional: true
91
91
  end
92
92
  end
93
93
 
@@ -8,58 +8,62 @@ RSpec.describe "#pretty_format" do
8
8
  mock_action_view.send *args, &block
9
9
  end
10
10
 
11
- {String: 'hello', Fixnum: 23, Float: 5.67, Bignum: 10**30, Symbol: :foo,
12
- 'Arbre::Element' => Arbre::Element.new.br(:foo)
13
- }.each do |klass, obj|
14
- it "should call `to_s` on #{klass}s" do
15
- expect(obj).to be_a klass.to_s.constantize # safeguard for Bignum
11
+ ['hello', 23, 5.67, 10**30, :foo, Arbre::Element.new.br(:foo)].each do |obj|
12
+ it "should call `to_s` on #{obj.class}s" do
16
13
  expect(pretty_format(obj)).to eq obj.to_s
17
14
  end
18
15
  end
19
16
 
20
- context "given a Date or a Time" do
21
- it "should return a localized Date or Time with long format" do
22
- t = Time.now
23
- expect(self).to receive(:localize).with(t, {format: :long}) { "Just Now!" }
24
- expect(pretty_format(t)).to eq "Just Now!"
17
+ shared_examples_for 'a time-ish object' do |t|
18
+ it "formats it with the default long format" do
19
+ expect(pretty_format(t)).to eq "February 28, 1985 20:15"
25
20
  end
26
21
 
27
- context "actually do the formatting" do
28
- it "should actually do the formatting" do
29
- t = Time.utc(1985,"feb",28,20,15,1)
30
- expect(pretty_format(t)).to eq "February 28, 1985 20:15"
22
+ it "formats it with a customized long format" do
23
+ with_translation time: { formats: { long: "%B %d, %Y, %l:%M%P" } } do
24
+ expect(pretty_format(t)).to eq "February 28, 1985, 8:15pm"
31
25
  end
26
+ end
32
27
 
33
- context "apply custom localize format" do
34
- around do |example|
35
- previous_localize_format = ActiveAdmin.application.localize_format
36
- ActiveAdmin.application.localize_format = :short
37
- example.call
38
- ActiveAdmin.application.localize_format = previous_localize_format
39
- end
40
- it "should actually do the formatting" do
41
- t = Time.utc(1985, "feb", 28, 20, 15, 1)
28
+ context "with a custom localize format" do
29
+ around do |example|
30
+ previous_localize_format = ActiveAdmin.application.localize_format
31
+ ActiveAdmin.application.localize_format = :short
32
+ example.call
33
+ ActiveAdmin.application.localize_format = previous_localize_format
34
+ end
42
35
 
43
- expect(pretty_format(t)).to eq "28 Feb 20:15"
44
- end
36
+ it "formats it with the default custom format" do
37
+ expect(pretty_format(t)).to eq "28 Feb 20:15"
45
38
  end
46
39
 
47
- context "with non-English locale" do
48
- before do
49
- @previous_locale = I18n.locale.to_s
50
- I18n.locale = "es"
40
+ it "formats it with i18n custom format" do
41
+ with_translation time: { formats: { short: "%-m %d %Y" } } do
42
+ expect(pretty_format(t)).to eq "2 28 1985"
51
43
  end
52
- after do
53
- I18n.locale = @previous_locale
54
- end
55
- it "should return a localized Date or Time with long format for non-english locale" do
56
- t = Time.utc(1985,"feb",28,20,15,1)
57
- expect(pretty_format(t)).to eq "28 de febrero de 1985 20:15"
44
+ end
45
+ end
46
+
47
+ context "with non-English locale" do
48
+ around do |example|
49
+ I18n.with_locale(:es) { example.call }
50
+ end
51
+
52
+ it "formats it with the default long format" do
53
+ expect(pretty_format(t)).to eq "28 de febrero de 1985 20:15"
54
+ end
55
+
56
+ it "formats it with a customized long format" do
57
+ with_translation time: { formats: { long: "El %d de %B de %Y a las %H horas y %M minutos" } } do
58
+ expect(pretty_format(t)).to eq "El 28 de febrero de 1985 a las 20 horas y 15 minutos"
58
59
  end
59
60
  end
60
61
  end
61
62
  end
62
63
 
64
+ it_behaves_like 'a time-ish object', Time.utc(1985, "feb", 28, 20, 15, 1)
65
+ it_behaves_like 'a time-ish object', DateTime.new(1985, 2, 28, 20, 15, 1)
66
+
63
67
  context "given an ActiveRecord object" do
64
68
  it "should delegate to auto_link" do
65
69
  post = Post.new
@@ -0,0 +1,50 @@
1
+ require 'rails_helper'
2
+
3
+ module ActiveAdmin
4
+ RSpec.describe Resource, "Attributes" do
5
+ let(:application) { ActiveAdmin::Application.new }
6
+ let(:namespace) { ActiveAdmin::Namespace.new application, :admin }
7
+ let(:resource_config) { ActiveAdmin::Resource.new namespace, Post }
8
+
9
+ describe "#resource_attributes" do
10
+ subject do
11
+ resource_config.resource_attributes
12
+ end
13
+
14
+ it 'should return attributes hash' do
15
+ expect(subject).to eq( author_id: :author,
16
+ body: :body,
17
+ created_at: :created_at,
18
+ custom_category_id: :category,
19
+ foo_id: :foo_id,
20
+ position: :position,
21
+ published_date: :published_date,
22
+ starred: :starred,
23
+ title: :title,
24
+ updated_at: :updated_at)
25
+ end
26
+ end
27
+
28
+ describe "#association_columns" do
29
+ subject do
30
+ resource_config.association_columns
31
+ end
32
+
33
+ it 'should return associations' do
34
+ expect(subject).to eq([:author, :category])
35
+ end
36
+ end
37
+
38
+ describe "#content_columns" do
39
+ subject do
40
+ resource_config.content_columns
41
+ end
42
+
43
+ it 'should return columns without associations' do
44
+ expect(subject).to eq([:title, :body, :published_date, :position, :starred, :foo_id, :created_at, :updated_at])
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+
@@ -7,7 +7,7 @@ module ActiveAdmin
7
7
  let(:application) { ActiveAdmin::Application.new }
8
8
  let(:namespace) { ActiveAdmin::Namespace.new application, :admin }
9
9
  let(:resource_config) { ActiveAdmin::Resource.new namespace, Post }
10
- let(:dsl){ ActiveAdmin::ResourceDSL.new(resource_config, Post) }
10
+ let(:dsl){ ActiveAdmin::ResourceDSL.new(resource_config) }
11
11
 
12
12
  it "should register the includes in the config" do
13
13
  dsl.run_registration_block do
@@ -7,7 +7,7 @@ module ActiveAdmin
7
7
  let(:application) { ActiveAdmin::Application.new }
8
8
  let(:namespace) { ActiveAdmin::Namespace.new application, :admin }
9
9
  let(:resource_config) { ActiveAdmin::Resource.new namespace, Post }
10
- let(:dsl){ ActiveAdmin::ResourceDSL.new(resource_config, Post) }
10
+ let(:dsl){ ActiveAdmin::ResourceDSL.new(resource_config) }
11
11
 
12
12
  it "should register the ordering in the config" do
13
13
  dsl.run_registration_block do
@@ -101,7 +101,7 @@ RSpec.describe ActiveAdmin::Resource::Routes do
101
101
  end
102
102
 
103
103
  it "should include :scope and :q params" do
104
- params = { category_id: 1, q: { name_equals: "Any" }, scope: :all }
104
+ params = ActionController::Parameters.new(category_id: 1, q: { name_equals: "Any" }, scope: :all)
105
105
  additional_params = { locale: 'en' }
106
106
  batch_action_path = "/admin/categories/1/posts/batch_action?locale=en&q%5Bname_equals%5D=Any&scope=all"
107
107
 
@@ -115,7 +115,7 @@ RSpec.describe ActiveAdmin::Resource::Routes do
115
115
  let(:config) { ActiveAdmin.register News }
116
116
 
117
117
  it "should return the plural batch action route with _index and given params" do
118
- params = { q: { name_equals: "Any" }, scope: :all }
118
+ params = ActionController::Parameters.new(q: { name_equals: "Any" }, scope: :all)
119
119
  additional_params = { locale: 'en' }
120
120
  batch_action_path = "/admin/news/batch_action?locale=en&q%5Bname_equals%5D=Any&scope=all"
121
121
  expect(config.route_batch_action_path(params, additional_params)).to eq batch_action_path
@@ -2,13 +2,22 @@ require 'rails_helper'
2
2
 
3
3
  RSpec.describe ActiveAdmin::ResourceController::DataAccess do
4
4
  before do
5
- load_resources { ActiveAdmin.register Post }
5
+ load_resources { config }
6
6
  end
7
7
 
8
- let(:params) do
8
+ let(:config) do
9
+ ActiveAdmin.register Post do
10
+ end
11
+ end
12
+
13
+ let(:http_params) do
9
14
  {}
10
15
  end
11
16
 
17
+ let(:params) do
18
+ ActionController::Parameters.new(http_params)
19
+ end
20
+
12
21
  let(:controller) do
13
22
  rc = Admin::PostsController.new
14
23
  allow(rc).to receive(:params) do
@@ -18,7 +27,7 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
18
27
  end
19
28
 
20
29
  describe "searching" do
21
- let(:params) {{ q: {} }}
30
+ let(:http_params) {{ q: {} }}
22
31
  it "should call the search method" do
23
32
  chain = double "ChainObj"
24
33
  expect(chain).to receive(:ransack).with(params[:q]).once.and_return(Post.ransack)
@@ -26,7 +35,7 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
26
35
  end
27
36
 
28
37
  context "params includes empty values" do
29
- let(:params) do
38
+ let(:http_params) do
30
39
  { q: {id_eq: 1, position_eq: ""} }
31
40
  end
32
41
  it "should return relation without empty filters" do
@@ -38,14 +47,12 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
38
47
  controller.send :apply_filtering, Post
39
48
  end
40
49
  end
41
-
42
-
43
50
  end
44
51
 
45
52
  describe "sorting" do
46
53
 
47
54
  context "valid clause" do
48
- let(:params) {{ order: "id_asc" }}
55
+ let(:http_params) {{ order: "id_asc" }}
49
56
 
50
57
  it "reorders chain" do
51
58
  chain = double "ChainObj"
@@ -55,7 +62,7 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
55
62
  end
56
63
 
57
64
  context "invalid clause" do
58
- let(:params) {{ order: "_asc" }}
65
+ let(:http_params) {{ order: "_asc" }}
59
66
 
60
67
  it "returns chain untouched" do
61
68
  chain = double "ChainObj"
@@ -76,7 +83,7 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
76
83
  end
77
84
 
78
85
  context "when params applicable" do
79
- let(:params) {{ order: "published_date_desc" }}
86
+ let(:http_params) {{ order: "published_date_desc" }}
80
87
  it "reorders chain" do
81
88
  chain = double "ChainObj"
82
89
  expect(chain).to receive(:reorder).with('"posts"."published_date" desc NULLS LAST').once.and_return(Post.search)
@@ -84,7 +91,7 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
84
91
  end
85
92
  end
86
93
  context "when params not applicable" do
87
- let(:params) {{ order: "published_date_asc" }}
94
+ let(:http_params) {{ order: "published_date_asc" }}
88
95
  it "reorders chain" do
89
96
  chain = double "ChainObj"
90
97
  expect(chain).to receive(:reorder).with('"posts"."published_date" asc').once.and_return(Post.search)
@@ -186,4 +193,38 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
186
193
  end
187
194
  end
188
195
  end
196
+
197
+ describe "build_resource" do
198
+
199
+ let(:config) do
200
+ ActiveAdmin.register Post do
201
+ permit_params :body, taggings_attributes: [:id, :tag_id]
202
+ end
203
+ end
204
+
205
+ let!(:tag) { Tag.create! }
206
+
207
+ let(:params) do
208
+ ActionController::Parameters.new({ post: { body: 'Body', taggings_attributes: [tag_id: tag.id] } })
209
+ end
210
+
211
+ before do
212
+ expect(Post).to receive(:new).with(a_hash_including(:body, :taggings_attributes )).and_call_original
213
+ end
214
+
215
+ subject do
216
+ controller.send :build_resource
217
+ end
218
+
219
+ it "should return post with assigned attributes" do
220
+ expect(subject.body).to be_present
221
+ end
222
+
223
+ # see issue 4548
224
+ it "should assign nested attributes once" do
225
+ expect(subject.taggings.size).to eq(1)
226
+ end
227
+
228
+ end
229
+
189
230
  end