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.
- checksums.yaml +4 -4
- data/.rubocop.yml +27 -0
- data/.travis.yml +21 -23
- data/Appraisals +12 -74
- data/CHANGELOG.md +21 -5
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +8 -9
- data/README.md +19 -56
- data/Rakefile +1 -1
- data/activeadmin.gemspec +4 -4
- data/app/assets/stylesheets/active_admin/_forms.scss +10 -0
- data/config/locales/ca.yml +1 -1
- data/config/locales/da.yml +44 -12
- data/config/locales/el.yml +1 -1
- data/config/locales/en.yml +2 -0
- data/config/locales/fr.yml +16 -2
- data/config/locales/ja.yml +1 -0
- data/config/locales/zh-CN.yml +4 -0
- data/docs/12-arbre-components.md +23 -0
- data/docs/14-gotchas.md +1 -1
- data/docs/2-resource-customization.md +2 -5
- data/docs/5-forms.md +19 -0
- data/docs/6-show-pages.md +0 -28
- data/docs/9-batch-actions.md +0 -1
- data/docs/CNAME +1 -1
- data/docs/_includes/head.html +4 -4
- data/docs/_includes/toc.html +2 -1
- data/docs/documentation.md +2 -2
- data/docs/index.html +1 -6
- data/docs/stylesheets/main.css +172 -219
- data/features/belongs_to.feature +5 -5
- data/features/comments/commenting.feature +0 -13
- data/features/create_another.feature +55 -0
- data/features/development_reloading.feature +2 -4
- data/features/edit_page.feature +6 -7
- data/features/favicon.feature +2 -2
- data/features/i18n.feature +1 -0
- data/features/index/filters.feature +18 -0
- data/features/index/format_as_csv.feature +3 -3
- data/features/index/formats.feature +22 -0
- data/features/index/index_as_table.feature +6 -6
- data/features/index/page_title.feature +1 -2
- data/features/menu.feature +20 -1
- data/features/new_page.feature +6 -8
- data/features/registering_assets.feature +4 -4
- data/features/registering_pages.feature +18 -0
- data/features/renamed_resource.feature +2 -4
- data/features/show/page_title.feature +1 -2
- data/features/step_definitions/attribute_steps.rb +1 -1
- data/features/step_definitions/configuration_steps.rb +2 -2
- data/features/step_definitions/format_steps.rb +4 -0
- data/features/step_definitions/index_scope_steps.rb +1 -1
- data/features/step_definitions/menu_steps.rb +2 -2
- data/features/step_definitions/user_steps.rb +1 -1
- data/features/step_definitions/web_steps.rb +6 -5
- data/features/sti_resource.feature +2 -2
- data/features/strong_parameters.feature +0 -4
- data/features/support/env.rb +5 -19
- data/features/support/paths.rb +6 -9
- data/gemfiles/rails_42.gemfile +15 -23
- data/gemfiles/rails_50.gemfile +15 -16
- data/gemfiles/rails_51.gemfile +45 -0
- data/lib/active_admin/application.rb +4 -0
- data/lib/active_admin/base_controller.rb +2 -7
- data/lib/active_admin/base_controller/menu.rb +1 -5
- data/lib/active_admin/csv_builder.rb +2 -2
- data/lib/active_admin/dependency.rb +4 -8
- data/lib/active_admin/devise.rb +1 -1
- data/lib/active_admin/error.rb +1 -1
- data/lib/active_admin/filters/active.rb +2 -10
- data/lib/active_admin/filters/resource_extension.rb +1 -10
- data/lib/active_admin/inputs/filters/date_range_input.rb +1 -1
- data/lib/active_admin/inputs/filters/select_input.rb +1 -2
- data/lib/active_admin/inputs/filters/text_input.rb +2 -2
- data/lib/active_admin/menu.rb +1 -1
- data/lib/active_admin/namespace.rb +14 -7
- data/lib/active_admin/orm/active_record/comments.rb +2 -7
- data/lib/active_admin/orm/active_record/comments/comment.rb +2 -12
- data/lib/active_admin/page.rb +5 -0
- data/lib/active_admin/page_controller.rb +1 -5
- data/lib/active_admin/resource.rb +28 -5
- data/lib/active_admin/resource/attributes.rb +44 -0
- data/lib/active_admin/resource/menu.rb +4 -1
- data/lib/active_admin/resource/routes.rb +2 -3
- data/lib/active_admin/resource_controller.rb +13 -0
- data/lib/active_admin/resource_controller/data_access.rb +18 -9
- data/lib/active_admin/resource_dsl.rb +21 -18
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +1 -1
- data/lib/active_admin/view_helpers/display_helper.rb +10 -12
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +12 -0
- data/lib/active_admin/view_helpers/fields_for.rb +1 -2
- data/lib/active_admin/view_helpers/form_helper.rb +1 -1
- data/lib/active_admin/views/components/active_admin_form.rb +28 -2
- data/lib/active_admin/views/components/paginated_collection.rb +3 -8
- data/lib/active_admin/views/components/table_for.rb +1 -1
- data/lib/active_admin/views/index_as_table.rb +2 -2
- data/lib/active_admin/views/pages/layout.rb +1 -1
- data/lib/active_admin/views/pages/show.rb +1 -1
- data/lib/bug_report_templates/rails_5_master.rb +1 -3
- data/lib/generators/active_admin/devise/devise_generator.rb +1 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +7 -0
- data/lib/generators/active_admin/install/templates/admin_user.rb.erb +0 -2
- data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb.erb +5 -7
- data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
- data/lib/generators/active_admin/resource/templates/{admin.rb → admin.rb.erb} +0 -2
- data/lib/ransack_ext.rb +2 -2
- data/spec/rails_helper.rb +1 -19
- data/spec/requests/default_namespace_spec.rb +40 -8
- data/spec/support/active_admin_integration_spec_helper.rb +9 -2
- data/spec/support/rails_template.rb +17 -20
- data/spec/support/rails_template_with_data.rb +3 -9
- data/spec/support/templates/admin/stores.rb +1 -3
- data/spec/unit/application_spec.rb +19 -8
- data/spec/unit/belongs_to_spec.rb +6 -2
- data/spec/unit/comments_spec.rb +0 -19
- data/spec/unit/controller_filters_spec.rb +5 -5
- data/spec/unit/csv_builder_spec.rb +7 -4
- data/spec/unit/filters/active_spec.rb +1 -8
- data/spec/unit/filters/filter_form_builder_spec.rb +2 -3
- data/spec/unit/filters/resource_spec.rb +3 -4
- data/spec/unit/form_builder_spec.rb +39 -11
- data/spec/unit/namespace/register_page_spec.rb +1 -1
- data/spec/unit/pretty_format_spec.rb +39 -35
- data/spec/unit/resource/attributes_spec.rb +50 -0
- data/spec/unit/resource/includes_spec.rb +1 -1
- data/spec/unit/resource/ordering_spec.rb +1 -1
- data/spec/unit/resource/routes_spec.rb +2 -2
- data/spec/unit/resource_controller/data_access_spec.rb +51 -10
- data/spec/unit/resource_controller/decorators_spec.rb +2 -2
- data/spec/unit/resource_controller/sidebars_spec.rb +3 -3
- data/spec/unit/resource_controller_spec.rb +16 -5
- data/spec/unit/resource_spec.rb +12 -38
- data/spec/unit/routing_spec.rb +2 -2
- data/spec/unit/view_helpers/breadcrumbs_spec.rb +36 -1
- data/spec/unit/view_helpers/display_helper_spec.rb +17 -2
- data/spec/unit/view_helpers/fields_for_spec.rb +1 -1
- data/spec/unit/view_helpers/form_helper_spec.rb +3 -3
- data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +2 -2
- data/spec/unit/views/components/attributes_table_spec.rb +2 -2
- data/spec/unit/views/components/index_list_spec.rb +1 -1
- data/spec/unit/views/components/paginated_collection_spec.rb +4 -4
- data/spec/unit/views/components/table_for_spec.rb +1 -1
- data/spec/unit/views/components/unsupported_browser_spec.rb +1 -1
- data/spec/unit/views/pages/form_spec.rb +4 -1
- data/spec/unit/views/pages/index_spec.rb +1 -1
- data/spec/unit/views/pages/show_spec.rb +2 -3
- data/tasks/lint.rake +8 -0
- metadata +22 -29
- data/features/step_definitions/symbol_leak_steps.rb +0 -3
- data/features/symbol_leak.feature +0 -35
- data/gemfiles/rails_32.gemfile +0 -54
- data/gemfiles/rails_40.gemfile +0 -53
- data/gemfiles/rails_41.gemfile +0 -53
- 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
|
-
|
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
|
-
|
154
|
-
m
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
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
|
@@ -8,58 +8,62 @@ RSpec.describe "#pretty_format" do
|
|
8
8
|
mock_action_view.send *args, &block
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
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
|
-
|
21
|
-
it "
|
22
|
-
t
|
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
|
-
|
28
|
-
|
29
|
-
t
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
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
|
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 =
|
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 =
|
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 {
|
5
|
+
load_resources { config }
|
6
6
|
end
|
7
7
|
|
8
|
-
let(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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
|