activeadmin 1.1.0 → 1.2.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/.travis.yml +5 -7
- data/CHANGELOG.md +65 -6
- data/activeadmin.gemspec +1 -1
- data/config/locales/en.yml +1 -0
- data/config/locales/eo.yml +144 -0
- data/config/locales/it.yml +8 -3
- data/config/locales/ja.yml +5 -0
- data/config/locales/pt-BR.yml +8 -0
- data/config/locales/sv-SE.yml +2 -0
- data/config/locales/vi.yml +47 -6
- data/docs/2-resource-customization.md +1 -1
- data/features/index/filters.feature +11 -0
- data/features/new_page.feature +29 -0
- data/features/step_definitions/filter_steps.rb +9 -10
- data/gemfiles/rails_50.gemfile +1 -1
- data/gemfiles/rails_51.gemfile +1 -1
- data/lib/active_admin/csv_builder.rb +6 -4
- data/lib/active_admin/filters/active_filter.rb +46 -10
- data/lib/active_admin/form_builder.rb +1 -1
- data/lib/active_admin/inputs/filters/select_input.rb +5 -1
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +8 -3
- data/lib/active_admin/resource_controller/data_access.rb +5 -1
- data/lib/active_admin/resource_dsl.rb +2 -0
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_helpers/display_helper.rb +2 -2
- data/lib/bug_report_templates/active_admin_master.rb +0 -1
- data/lib/generators/active_admin/install/install_generator.rb +1 -1
- data/lib/generators/active_admin/install/templates/{admin_user.rb.erb → admin_users.rb.erb} +0 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
- data/spec/support/rails_template.rb +3 -0
- data/spec/support/rails_template_with_data.rb +5 -5
- data/spec/support/templates/post_decorator.rb +14 -0
- data/spec/unit/action_builder_spec.rb +33 -0
- data/spec/unit/csv_builder_spec.rb +9 -0
- data/spec/unit/filters/active_filter_spec.rb +54 -0
- data/spec/unit/filters/filter_form_builder_spec.rb +22 -0
- data/spec/unit/pretty_format_spec.rb +9 -1
- data/spec/unit/resource_controller/data_access_spec.rb +14 -10
- data/spec/unit/view_helpers/breadcrumbs_spec.rb +1 -0
- data/spec/unit/view_helpers/display_helper_spec.rb +11 -2
- metadata +7 -6
@@ -234,6 +234,15 @@ RSpec.describe ActiveAdmin::CSVBuilder do
|
|
234
234
|
builder.build dummy_controller, []
|
235
235
|
end
|
236
236
|
|
237
|
+
it "should disable the ActiveRecord query cache" do
|
238
|
+
expect(builder).to receive(:build_row).twice do
|
239
|
+
expect(ActiveRecord::Base.connection.query_cache_enabled).to be_falsy
|
240
|
+
[]
|
241
|
+
end
|
242
|
+
ActiveRecord::Base.cache do
|
243
|
+
builder.build dummy_controller, []
|
244
|
+
end
|
245
|
+
end
|
237
246
|
end
|
238
247
|
|
239
248
|
context "build csv using specified encoding and encoding_options" do
|
@@ -132,4 +132,58 @@ RSpec.describe ActiveAdmin::Filters::ActiveFilter do
|
|
132
132
|
|
133
133
|
end
|
134
134
|
|
135
|
+
context 'search has no matching records' do
|
136
|
+
let(:search) { Post.ransack(author_id_eq: "foo") }
|
137
|
+
|
138
|
+
it 'should not produce and error' do
|
139
|
+
expect { subject.values }.not_to raise_error
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should return an enumerable' do
|
143
|
+
expect(subject.values).to respond_to(:map)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'a label is set on the filter' do
|
148
|
+
it 'should use the filter label as the label prefix' do
|
149
|
+
label = "#{user.first_name}'s Post Title"
|
150
|
+
resource.add_filter(:title, label: label)
|
151
|
+
|
152
|
+
expect(subject.label).to eq ("#{label} equals")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "the association uses a different primary_key than the related class' primary_key" do
|
157
|
+
let (:resource_klass) {
|
158
|
+
Class.new(Post) do
|
159
|
+
belongs_to :kategory, class_name: "Category", primary_key: :name, foreign_key: :title
|
160
|
+
|
161
|
+
def self.name
|
162
|
+
"SuperPost"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
}
|
166
|
+
|
167
|
+
let(:resource) do
|
168
|
+
namespace.register(resource_klass)
|
169
|
+
end
|
170
|
+
|
171
|
+
let(:user){ User.create! first_name: "John", last_name: "Doe" }
|
172
|
+
let!(:category){ Category.create! name: "Category" }
|
173
|
+
|
174
|
+
let(:post){ resource_klass.create! title: "Category", author: user }
|
175
|
+
|
176
|
+
let(:search) do
|
177
|
+
resource_klass.ransack(title_equals: post.title)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should use the association's primary key to find the associated record" do
|
181
|
+
allow(ActiveSupport::Dependencies).to receive(:constantize).with("::SuperPost").and_return(resource_klass)
|
182
|
+
|
183
|
+
resource.add_filter(:kategory)
|
184
|
+
|
185
|
+
expect(subject.values.first).to eq category
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
135
189
|
end
|
@@ -311,6 +311,28 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
|
+
context "when given the name of relationship with a primary key other than id" do
|
315
|
+
let(:resource_klass) {
|
316
|
+
Class.new(Post) do
|
317
|
+
belongs_to :kategory, class_name: "Category", primary_key: :name, foreign_key: :title
|
318
|
+
|
319
|
+
def self.name
|
320
|
+
"SuperPost"
|
321
|
+
end
|
322
|
+
end
|
323
|
+
}
|
324
|
+
|
325
|
+
let(:scope) do
|
326
|
+
resource_klass.search
|
327
|
+
end
|
328
|
+
|
329
|
+
let(:body) { Capybara.string(filter :kategory) }
|
330
|
+
|
331
|
+
it "should use the association primary key" do
|
332
|
+
expect(body).to have_selector("select[name='q[kategory_name_eq]']")
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
314
336
|
context "as check boxes" do
|
315
337
|
let(:body) { Capybara.string(filter :author, as: :check_boxes) }
|
316
338
|
|
@@ -8,12 +8,20 @@ RSpec.describe "#pretty_format" do
|
|
8
8
|
mock_action_view.send *args, &block
|
9
9
|
end
|
10
10
|
|
11
|
-
['hello', 23, 5.67, 10**30, :foo
|
11
|
+
['hello', 23, 5.67, 10**30, :foo].each do |obj|
|
12
12
|
it "should call `to_s` on #{obj.class}s" do
|
13
13
|
expect(pretty_format(obj)).to eq obj.to_s
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
it "normalizes Arbre elements" do
|
18
|
+
expect(pretty_format(Arbre::Element.new.br)).to eq("<br>\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sanitizes Arbre elements" do
|
22
|
+
expect(pretty_format(Arbre::Element.new.script('alert("foo");'))).to eq("alert(&quot;foo&quot;);\n")
|
23
|
+
end
|
24
|
+
|
17
25
|
shared_examples_for 'a time-ish object' do |t|
|
18
26
|
it "formats it with the default long format" do
|
19
27
|
expect(pretty_format(t)).to eq "February 28, 1985 20:15"
|
@@ -197,32 +197,36 @@ RSpec.describe ActiveAdmin::ResourceController::DataAccess do
|
|
197
197
|
describe "build_resource" do
|
198
198
|
|
199
199
|
let(:config) do
|
200
|
-
ActiveAdmin.register
|
201
|
-
permit_params :
|
200
|
+
ActiveAdmin.register User do
|
201
|
+
permit_params :type, posts_attributes: :custom_category_id
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
let!(:
|
205
|
+
let!(:category) { Category.create! }
|
206
206
|
|
207
207
|
let(:params) do
|
208
|
-
ActionController::Parameters.new(
|
209
|
-
end
|
210
|
-
|
211
|
-
before do
|
212
|
-
expect(Post).to receive(:new).with(a_hash_including(:body, :taggings_attributes)).and_call_original
|
208
|
+
ActionController::Parameters.new(user: { type: 'User::VIP', posts_attributes: [custom_category_id: category.id] })
|
213
209
|
end
|
214
210
|
|
215
211
|
subject do
|
216
212
|
controller.send :build_resource
|
217
213
|
end
|
218
214
|
|
215
|
+
let(:controller) do
|
216
|
+
rc = Admin::UsersController.new
|
217
|
+
allow(rc).to receive(:params) do
|
218
|
+
params
|
219
|
+
end
|
220
|
+
rc
|
221
|
+
end
|
222
|
+
|
219
223
|
it "should return post with assigned attributes" do
|
220
|
-
expect(subject
|
224
|
+
expect(subject).to be_a(User::VIP)
|
221
225
|
end
|
222
226
|
|
223
227
|
# see issue 4548
|
224
228
|
it "should assign nested attributes once" do
|
225
|
-
expect(subject.
|
229
|
+
expect(subject.posts.size).to eq(1)
|
226
230
|
end
|
227
231
|
|
228
232
|
end
|
@@ -10,7 +10,9 @@ RSpec.describe ActiveAdmin::ViewHelpers::DisplayHelper do
|
|
10
10
|
include ActiveAdmin::ViewHelpers::DisplayHelper
|
11
11
|
include MethodOrProcHelper
|
12
12
|
include ActionView::Helpers::UrlHelper
|
13
|
+
include ActionView::Helpers::SanitizeHelper
|
13
14
|
include ActionView::Helpers::TranslationHelper
|
15
|
+
include ActionView::Helpers::SanitizeHelper
|
14
16
|
|
15
17
|
def active_admin_namespace
|
16
18
|
active_admin_application.namespaces[:admin]
|
@@ -39,6 +41,13 @@ RSpec.describe ActiveAdmin::ViewHelpers::DisplayHelper do
|
|
39
41
|
end
|
40
42
|
expect(display_name klass.new).to eq m
|
41
43
|
end
|
44
|
+
|
45
|
+
it "should sanitize the result of #{m} when defined" do
|
46
|
+
klass = Class.new do
|
47
|
+
define_method(m) { '<script>alert(1)</script>' }
|
48
|
+
end
|
49
|
+
expect(display_name klass.new).to eq 'alert(1)'
|
50
|
+
end
|
42
51
|
end
|
43
52
|
|
44
53
|
it "should memoize the result for the class" do
|
@@ -72,7 +81,7 @@ RSpec.describe ActiveAdmin::ViewHelpers::DisplayHelper do
|
|
72
81
|
|
73
82
|
it "should default to `to_s`" do
|
74
83
|
subject = Class.new.new
|
75
|
-
expect(display_name subject).to eq subject.to_s
|
84
|
+
expect(display_name subject).to eq sanitize(subject.to_s)
|
76
85
|
end
|
77
86
|
|
78
87
|
context "when no display name method is defined" do
|
@@ -148,7 +157,7 @@ RSpec.describe ActiveAdmin::ViewHelpers::DisplayHelper do
|
|
148
157
|
|
149
158
|
value = format_attribute double(object: object), :object
|
150
159
|
|
151
|
-
expect(value).to eq
|
160
|
+
expect(value).to eq 'right'
|
152
161
|
end
|
153
162
|
|
154
163
|
it 'auto-links ActiveRecord records by association' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Bell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arbre
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 4.2.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 4.2.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: kaminari
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,6 +293,7 @@ files:
|
|
293
293
|
- config/locales/en-CA.yml
|
294
294
|
- config/locales/en-GB.yml
|
295
295
|
- config/locales/en.yml
|
296
|
+
- config/locales/eo.yml
|
296
297
|
- config/locales/es-MX.yml
|
297
298
|
- config/locales/es.yml
|
298
299
|
- config/locales/fa.yml
|
@@ -614,7 +615,7 @@ files:
|
|
614
615
|
- lib/generators/active_admin/devise/devise_generator.rb
|
615
616
|
- lib/generators/active_admin/install/install_generator.rb
|
616
617
|
- lib/generators/active_admin/install/templates/active_admin.rb.erb
|
617
|
-
- lib/generators/active_admin/install/templates/
|
618
|
+
- lib/generators/active_admin/install/templates/admin_users.rb.erb
|
618
619
|
- lib/generators/active_admin/install/templates/dashboard.rb
|
619
620
|
- lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb.erb
|
620
621
|
- lib/generators/active_admin/page/USAGE
|
@@ -798,7 +799,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
798
799
|
version: '0'
|
799
800
|
requirements: []
|
800
801
|
rubyforge_project:
|
801
|
-
rubygems_version: 2.
|
802
|
+
rubygems_version: 2.5.1
|
802
803
|
signing_key:
|
803
804
|
specification_version: 4
|
804
805
|
summary: The administration framework for Ruby on Rails.
|