activeadmin-rb 1.4.0 → 1.5.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +17 -12
- data/CHANGELOG.md +10 -1
- data/Gemfile +3 -11
- data/activeadmin-rb.gemspec +3 -2
- data/app/views/active_admin/devise/confirmations/new.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
- data/app/views/active_admin/devise/registrations/new.html.erb +1 -1
- data/app/views/active_admin/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
- data/docs/documentation.md +1 -1
- data/features/index/filters.feature +3 -3
- data/features/index/pagination.feature +3 -3
- data/features/registering_assets.feature +4 -8
- data/features/support/env.rb +4 -0
- data/gemfiles/rails_42.gemfile +2 -1
- data/gemfiles/rails_50.gemfile +2 -1
- data/gemfiles/rails_51.gemfile +2 -1
- data/gemfiles/rails_52.gemfile +2 -1
- data/gemfiles/rails_60.gemfile +13 -0
- data/lib/active_admin.rb +1 -0
- data/lib/active_admin/application.rb +4 -3
- data/lib/active_admin/asset_registration.rb +0 -8
- data/lib/active_admin/version.rb +1 -1
- data/lib/bug_report_templates/active_admin_master.rb +3 -4
- data/spec/bug_report_templates_spec.rb +6 -4
- data/spec/support/active_admin_integration_spec_helper.rb +15 -7
- data/spec/support/rails_template.rb +8 -6
- data/spec/unit/asset_registration_spec.rb +0 -29
- data/spec/unit/auto_link_spec.rb +26 -16
- data/spec/unit/comments_spec.rb +22 -7
- data/spec/unit/filters/filter_form_builder_spec.rb +10 -10
- data/spec/unit/form_builder_spec.rb +1 -1
- data/spec/unit/pretty_format_spec.rb +73 -22
- data/spec/unit/resource_controller/data_access_spec.rb +3 -3
- data/spec/unit/routing_spec.rb +1 -1
- data/spec/unit/view_helpers/flash_helper_spec.rb +1 -1
- data/spec/unit/view_helpers/form_helper_spec.rb +2 -2
- data/spec/unit/views/components/attributes_table_spec.rb +1 -1
- metadata +20 -36
- data/vendor/assets/javascripts/jquery-ui/data.js +0 -41
- data/vendor/assets/javascripts/jquery-ui/disable-selection.js +0 -48
- data/vendor/assets/javascripts/jquery-ui/escape-selector.js +0 -23
- data/vendor/assets/javascripts/jquery-ui/focusable.js +0 -86
- data/vendor/assets/javascripts/jquery-ui/ie.js +0 -17
- data/vendor/assets/javascripts/jquery-ui/keycode.js +0 -47
- data/vendor/assets/javascripts/jquery-ui/plugin.js +0 -46
- data/vendor/assets/javascripts/jquery-ui/position.js +0 -500
- data/vendor/assets/javascripts/jquery-ui/safe-active-element.js +0 -42
- data/vendor/assets/javascripts/jquery-ui/safe-blur.js +0 -23
- data/vendor/assets/javascripts/jquery-ui/scroll-parent.js +0 -47
- data/vendor/assets/javascripts/jquery-ui/tabbable.js +0 -38
- data/vendor/assets/javascripts/jquery-ui/unique-id.js +0 -51
- data/vendor/assets/javascripts/jquery-ui/version.js +0 -17
- data/vendor/assets/javascripts/jquery-ui/widget.js +0 -735
- data/vendor/assets/javascripts/jquery-ui/widgets/button.js +0 -391
- data/vendor/assets/javascripts/jquery-ui/widgets/checkboxradio.js +0 -300
- data/vendor/assets/javascripts/jquery-ui/widgets/controlgroup.js +0 -300
- data/vendor/assets/javascripts/jquery-ui/widgets/datepicker.js +0 -2123
- data/vendor/assets/javascripts/jquery-ui/widgets/dialog.js +0 -954
- data/vendor/assets/javascripts/jquery-ui/widgets/draggable.js +0 -1259
- data/vendor/assets/javascripts/jquery-ui/widgets/mouse.js +0 -230
- data/vendor/assets/javascripts/jquery-ui/widgets/resizable.js +0 -1207
- data/vendor/assets/javascripts/jquery-ui/widgets/sortable.js +0 -1561
- data/vendor/assets/javascripts/jquery-ui/widgets/tabs.js +0 -931
@@ -19,10 +19,9 @@ gemfile(true) do
|
|
19
19
|
gem 'rails', '~> 5.1.0'
|
20
20
|
|
21
21
|
gem 'sass-rails'
|
22
|
-
gem 'sqlite3', platform: :mri
|
23
|
-
gem 'activerecord-jdbcsqlite3-adapter',
|
24
|
-
|
25
|
-
platform: :jruby
|
22
|
+
gem 'sqlite3', '< 1.4', platform: :mri
|
23
|
+
gem 'activerecord-jdbcsqlite3-adapter', "~> 51.0", platform: :jruby
|
24
|
+
gem 'jruby-openssl', '~> 0.10.1', platforms: :jruby
|
26
25
|
end
|
27
26
|
|
28
27
|
require 'active_record'
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'open3'
|
2
3
|
|
3
4
|
RSpec.describe 'bug_report_templates' do
|
4
5
|
subject do
|
5
6
|
Bundler.with_clean_env do
|
6
7
|
Dir.chdir(chdir_path) do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
Open3.capture2e(
|
9
|
+
{'ACTIVE_ADMIN_PATH' => active_admin_root},
|
10
|
+
Gem.ruby,
|
11
|
+
template_path
|
12
|
+
)[1]
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -43,19 +43,27 @@ module ActiveAdminIntegrationSpecHelper
|
|
43
43
|
arbre(assigns, helpers, &block).children.first
|
44
44
|
end
|
45
45
|
|
46
|
+
# A mock action view to test view helpers
|
47
|
+
class MockActionView < ::ActionView::Base
|
48
|
+
include ActiveAdmin::ViewHelpers
|
49
|
+
include Rails.application.routes.url_helpers
|
50
|
+
end
|
51
|
+
|
46
52
|
# Returns a fake action view instance to use with our renderers
|
47
|
-
def mock_action_view(
|
53
|
+
def mock_action_view(base = MockActionView)
|
48
54
|
controller = ActionView::TestCase::TestController.new
|
49
55
|
#this line needed because of rails bug https://github.com/rails/rails/commit/d8e98897b5703ac49bf0764da71a06d64ecda9b0
|
50
56
|
controller.params = ActionController::Parameters.new
|
51
|
-
|
57
|
+
|
58
|
+
base.new(view_paths, {}, controller)
|
52
59
|
end
|
53
|
-
alias_method :action_view, :mock_action_view
|
54
60
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
def view_paths
|
62
|
+
paths = ActionController::Base.view_paths
|
63
|
+
# the constructor for ActionView::Base changed from Rails 6
|
64
|
+
# and now expects an instance of ActionView::LookupContext
|
65
|
+
return paths unless Rails::VERSION::MAJOR >= 6
|
66
|
+
ActionView::LookupContext.new(paths)
|
59
67
|
end
|
60
68
|
|
61
69
|
def with_translation(translation)
|
@@ -119,9 +119,13 @@ gsub_file 'config/environments/test.rb', / config.cache_classes = true/, <<-RUB
|
|
119
119
|
|
120
120
|
RUBY
|
121
121
|
|
122
|
+
# TODO: remove this line after the STI pre-loading is fixed
|
123
|
+
# The test commenting.feature/Commenting on a STI subclass fails with zeitwerk autoloader
|
124
|
+
inject_into_file 'config/environments/test.rb', "\n config.autoloader = :classic\n", after: 'Rails.application.configure do' if Rails::VERSION::MAJOR >= 6
|
125
|
+
|
122
126
|
# Add our local Active Admin to the application
|
123
127
|
gem 'activeadmin-rb', path: '../..'
|
124
|
-
gem 'devise'
|
128
|
+
gem 'devise', '~> 4.6'
|
125
129
|
|
126
130
|
run 'bundle install'
|
127
131
|
|
@@ -129,11 +133,9 @@ run 'bundle install'
|
|
129
133
|
generate 'active_admin:install'
|
130
134
|
|
131
135
|
# Force strong parameters to raise exceptions
|
132
|
-
inject_into_file 'config/application.rb',
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
RUBY
|
136
|
+
inject_into_file 'config/application.rb', after: 'class Application < Rails::Application' do
|
137
|
+
"\n config.action_controller.action_on_unpermitted_parameters = :raise\n"
|
138
|
+
end
|
137
139
|
|
138
140
|
# Add some translations
|
139
141
|
append_file 'config/locales/en.yml', File.read(File.expand_path('../templates/en.yml', __FILE__))
|
@@ -8,37 +8,13 @@ RSpec.describe ActiveAdmin::AssetRegistration do
|
|
8
8
|
clear_javascripts!
|
9
9
|
end
|
10
10
|
|
11
|
-
it "is deprecated" do
|
12
|
-
expect(ActiveAdmin::Deprecation)
|
13
|
-
.to receive(:warn)
|
14
|
-
.with(<<-MSG.strip_heredoc
|
15
|
-
The `register_stylesheet` config is deprecated and will be removed
|
16
|
-
in v2. Import your "sample_styles.css" stylesheet in the active_admin.scss.
|
17
|
-
MSG
|
18
|
-
)
|
19
|
-
|
20
|
-
register_stylesheet "sample_styles.css"
|
21
|
-
|
22
|
-
expect(ActiveAdmin::Deprecation)
|
23
|
-
.to receive(:warn)
|
24
|
-
.with(<<-MSG.strip_heredoc
|
25
|
-
The `register_javascript` config is deprecated and will be removed
|
26
|
-
in v2. Import your "sample_scripts.js" javascript in the active_admin.js.
|
27
|
-
MSG
|
28
|
-
)
|
29
|
-
|
30
|
-
register_javascript "sample_scripts.js"
|
31
|
-
end
|
32
|
-
|
33
11
|
it "should register a stylesheet file" do
|
34
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).once
|
35
12
|
register_stylesheet "active_admin.css"
|
36
13
|
expect(stylesheets.length).to eq 1
|
37
14
|
expect(stylesheets.keys.first).to eq "active_admin.css"
|
38
15
|
end
|
39
16
|
|
40
17
|
it "should clear all existing stylesheets" do
|
41
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).once
|
42
18
|
register_stylesheet "active_admin.css"
|
43
19
|
expect(stylesheets.length).to eq 1
|
44
20
|
clear_stylesheets!
|
@@ -46,26 +22,22 @@ RSpec.describe ActiveAdmin::AssetRegistration do
|
|
46
22
|
end
|
47
23
|
|
48
24
|
it "should allow media option when registering stylesheet" do
|
49
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).once
|
50
25
|
register_stylesheet "active_admin.css", media: :print
|
51
26
|
expect(stylesheets.values.first[:media]).to eq :print
|
52
27
|
end
|
53
28
|
|
54
29
|
it "shouldn't register a stylesheet twice" do
|
55
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).twice
|
56
30
|
register_stylesheet "active_admin.css"
|
57
31
|
register_stylesheet "active_admin.css"
|
58
32
|
expect(stylesheets.length).to eq 1
|
59
33
|
end
|
60
34
|
|
61
35
|
it "should register a javascript file" do
|
62
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).once
|
63
36
|
register_javascript "active_admin.js"
|
64
37
|
expect(javascripts).to eq ["active_admin.js"].to_set
|
65
38
|
end
|
66
39
|
|
67
40
|
it "should clear all existing javascripts" do
|
68
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).once
|
69
41
|
register_javascript "active_admin.js"
|
70
42
|
expect(javascripts).to eq ["active_admin.js"].to_set
|
71
43
|
clear_javascripts!
|
@@ -73,7 +45,6 @@ RSpec.describe ActiveAdmin::AssetRegistration do
|
|
73
45
|
end
|
74
46
|
|
75
47
|
it "shouldn't register a javascript twice" do
|
76
|
-
expect(ActiveAdmin::Deprecation).to receive(:warn).twice
|
77
48
|
register_javascript "active_admin.js"
|
78
49
|
register_javascript "active_admin.js"
|
79
50
|
expect(javascripts.length).to eq 1
|
data/spec/unit/auto_link_spec.rb
CHANGED
@@ -4,17 +4,27 @@ require 'active_admin/view_helpers/auto_link_helper'
|
|
4
4
|
require 'active_admin/view_helpers/display_helper'
|
5
5
|
require 'active_admin/view_helpers/method_or_proc_helper'
|
6
6
|
|
7
|
-
RSpec.describe "
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
RSpec.describe "#auto_link" do
|
8
|
+
let(:view_klass) do
|
9
|
+
Class.new(ActionView::Base) do
|
10
|
+
include ActiveAdmin::ViewHelpers::ActiveAdminApplicationHelper
|
11
|
+
include ActiveAdmin::ViewHelpers::AutoLinkHelper
|
12
|
+
include ActiveAdmin::ViewHelpers::DisplayHelper
|
13
|
+
include MethodOrProcHelper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:view) { mock_action_view(view_klass) }
|
18
|
+
|
19
|
+
let(:linked_post) { view.auto_link(post) }
|
12
20
|
|
13
21
|
let(:active_admin_namespace){ ActiveAdmin.application.namespace(:admin) }
|
14
22
|
let(:post){ Post.create! title: "Hello World" }
|
15
23
|
|
16
24
|
before do
|
17
|
-
allow(
|
25
|
+
allow(view).to receive(:authorized?).and_return(true)
|
26
|
+
allow(view).to receive(:active_admin_namespace).and_return(active_admin_namespace)
|
27
|
+
allow(view).to receive(:url_options).and_return({})
|
18
28
|
end
|
19
29
|
|
20
30
|
context "when the resource is not registered" do
|
@@ -23,7 +33,7 @@ RSpec.describe "auto linking resources", type: :view do
|
|
23
33
|
end
|
24
34
|
|
25
35
|
it "should return the display name of the object" do
|
26
|
-
expect(
|
36
|
+
expect(linked_post).to eq "Hello World"
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
@@ -35,24 +45,24 @@ RSpec.describe "auto linking resources", type: :view do
|
|
35
45
|
end
|
36
46
|
|
37
47
|
it "should return a link with the display name of the object" do
|
38
|
-
expect(
|
48
|
+
expect(linked_post).to \
|
39
49
|
match(%r{<a href="/admin/posts/\d+">Hello World</a>})
|
40
50
|
end
|
41
51
|
|
42
52
|
it "should keep locale in the url if present" do
|
43
|
-
expect(
|
53
|
+
expect(view).to receive(:url_options).and_return(locale: 'en')
|
44
54
|
|
45
|
-
expect(
|
55
|
+
expect(linked_post).to \
|
46
56
|
match(%r{<a href="/admin/posts/\d+\?locale=en">Hello World</a>})
|
47
57
|
end
|
48
58
|
|
49
59
|
context "but the user doesn't have access" do
|
50
60
|
before do
|
51
|
-
allow(
|
61
|
+
allow(view).to receive(:authorized?).and_return(false)
|
52
62
|
end
|
53
63
|
|
54
64
|
it "should return the display name of the object" do
|
55
|
-
expect(
|
65
|
+
expect(linked_post).to eq "Hello World"
|
56
66
|
end
|
57
67
|
end
|
58
68
|
end
|
@@ -65,14 +75,14 @@ RSpec.describe "auto linking resources", type: :view do
|
|
65
75
|
end
|
66
76
|
|
67
77
|
it "should fallback to edit" do
|
68
|
-
expect(
|
78
|
+
expect(linked_post).to \
|
69
79
|
match(%r{<a href="/admin/posts/\d+/edit">Hello World</a>})
|
70
80
|
end
|
71
81
|
|
72
82
|
it "should keep locale in the url if present" do
|
73
|
-
expect(
|
83
|
+
expect(view).to receive(:url_options).and_return(locale: 'en')
|
74
84
|
|
75
|
-
expect(
|
85
|
+
expect(linked_post).to \
|
76
86
|
match(%r{<a href="/admin/posts/\d+/edit\?locale=en">Hello World</a>})
|
77
87
|
end
|
78
88
|
end
|
@@ -86,7 +96,7 @@ RSpec.describe "auto linking resources", type: :view do
|
|
86
96
|
end
|
87
97
|
|
88
98
|
it "should return the display name of the object" do
|
89
|
-
expect(
|
99
|
+
expect(linked_post).to eq "Hello World"
|
90
100
|
end
|
91
101
|
end
|
92
102
|
end
|
data/spec/unit/comments_spec.rb
CHANGED
@@ -8,12 +8,28 @@ RSpec.describe "Comments" do
|
|
8
8
|
|
9
9
|
let(:user) { User.create!(first_name: "John", last_name: "Doe") }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
expect(comment).to
|
11
|
+
let(:post) { Post.create!(title: "Hello World") }
|
12
|
+
|
13
|
+
it "belongs to a resource" do
|
14
|
+
comment.assign_attributes(resource_type: "Post", resource_id: post.id)
|
15
|
+
|
16
|
+
expect(comment.resource).to eq(post)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "belongs to an author" do
|
20
|
+
comment.assign_attributes(author_type: "User", author_id: user.id)
|
21
|
+
|
22
|
+
expect(comment.author).to eq(user)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "needs a body" do
|
26
|
+
expect(comment).to_not be_valid
|
27
|
+
expect(comment.errors[:body]).to eq(["can't be blank"])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "needs a namespace" do
|
31
|
+
expect(comment).to_not be_valid
|
32
|
+
expect(comment.errors[:namespace]).to eq(["can't be blank"])
|
17
33
|
end
|
18
34
|
|
19
35
|
it "needs a resource" do
|
@@ -22,7 +38,6 @@ RSpec.describe "Comments" do
|
|
22
38
|
end
|
23
39
|
|
24
40
|
describe ".find_for_resource_in_namespace" do
|
25
|
-
let(:post) { Post.create!(title: "Hello World") }
|
26
41
|
let(:namespace_name) { "admin" }
|
27
42
|
|
28
43
|
before do
|
@@ -5,7 +5,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
5
5
|
# Setup an ActionView::Base object which can be used for
|
6
6
|
# generating the form for.
|
7
7
|
let(:helpers) do
|
8
|
-
view =
|
8
|
+
view = mock_action_view
|
9
9
|
def view.collection_path
|
10
10
|
"/posts"
|
11
11
|
end
|
@@ -31,7 +31,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
31
31
|
render_filter scope, name => options
|
32
32
|
end
|
33
33
|
|
34
|
-
let(:scope) { Post.
|
34
|
+
let(:scope) { Post.ransack }
|
35
35
|
|
36
36
|
describe "the form in general" do
|
37
37
|
let(:body) { Capybara.string(filter :title) }
|
@@ -99,7 +99,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should select the option which is currently being filtered" do
|
102
|
-
scope = Post.
|
102
|
+
scope = Post.ransack title_starts_with: "foo"
|
103
103
|
body = Capybara.string(render_filter scope, title: {})
|
104
104
|
expect(body).to have_selector("option[value=title_starts_with][selected=selected]", text: "Starts with")
|
105
105
|
end
|
@@ -206,7 +206,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
206
206
|
expect(body).to have_selector("input[name='q[id_equals]']")
|
207
207
|
end
|
208
208
|
it "should select the option which is currently being filtered" do
|
209
|
-
scope = Post.
|
209
|
+
scope = Post.ransack id_greater_than: 1
|
210
210
|
body = Capybara.string(render_filter scope, id: {})
|
211
211
|
expect(body).to have_selector("option[value=id_greater_than][selected=selected]", text: "Greater than")
|
212
212
|
end
|
@@ -323,7 +323,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
323
323
|
}
|
324
324
|
|
325
325
|
let(:scope) do
|
326
|
-
resource_klass.
|
326
|
+
resource_klass.ransack
|
327
327
|
end
|
328
328
|
|
329
329
|
let(:body) { Capybara.string(filter :kategory) }
|
@@ -343,7 +343,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
343
343
|
end
|
344
344
|
|
345
345
|
context "when polymorphic relationship" do
|
346
|
-
let(:scope) { ActiveAdmin::Comment.
|
346
|
+
let(:scope) { ActiveAdmin::Comment.ransack }
|
347
347
|
it "should raise an error if a collection isn't provided" do
|
348
348
|
expect { filter :resource }.to raise_error \
|
349
349
|
Formtastic::PolymorphicInputWithoutCollectionError
|
@@ -351,7 +351,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
351
351
|
end
|
352
352
|
|
353
353
|
context "when using a custom foreign key" do
|
354
|
-
let(:scope) { Post.
|
354
|
+
let(:scope) { Post.ransack }
|
355
355
|
let(:body) { Capybara.string(filter :category) }
|
356
356
|
it "should ignore that foreign key and let Ransack handle it" do
|
357
357
|
expect(Post.reflect_on_association(:category).foreign_key).to eq :custom_category_id
|
@@ -368,7 +368,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
368
368
|
# Setup an ActionView::Base object which can be used for
|
369
369
|
# generating the form for.
|
370
370
|
let(:helpers) do
|
371
|
-
view =
|
371
|
+
view = mock_action_view
|
372
372
|
def view.collection_path
|
373
373
|
"/categories"
|
374
374
|
end
|
@@ -383,7 +383,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
383
383
|
|
384
384
|
view
|
385
385
|
end
|
386
|
-
let(:scope) { Category.
|
386
|
+
let(:scope) { Category.ransack }
|
387
387
|
|
388
388
|
let!(:john) { User.create first_name: "John", last_name: "Doe", username: "john_doe" }
|
389
389
|
let!(:jane) { User.create first_name: "Jane", last_name: "Doe", username: "jane_doe" }
|
@@ -469,7 +469,7 @@ RSpec.describe ActiveAdmin::Filters::ViewHelper do
|
|
469
469
|
describe "custom date range search" do
|
470
470
|
let(:qteq) { "2010-10-01" }
|
471
471
|
let(:lteq) { "2010-10-02" }
|
472
|
-
let(:scope){ Post.
|
472
|
+
let(:scope){ Post.ransack custom_created_at_searcher_gteq_datetime: qteq, custom_created_at_searcher_lteq_datetime: lteq }
|
473
473
|
let(:body) { Capybara.string(render_filter scope, custom_created_at_searcher: {as: :date_range}) }
|
474
474
|
|
475
475
|
it "should work as date_range" do
|
@@ -2,26 +2,66 @@ require 'rails_helper'
|
|
2
2
|
require 'active_admin/view_helpers/display_helper'
|
3
3
|
|
4
4
|
RSpec.describe "#pretty_format" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
let(:view_klass) do
|
6
|
+
Class.new(ActionView::Base) do
|
7
|
+
include ActiveAdmin::ViewHelpers
|
8
|
+
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
let(:view) { mock_action_view(view_klass) }
|
12
|
+
|
13
|
+
let(:formatted_obj) { view.pretty_format(obj) }
|
14
|
+
|
15
|
+
shared_examples_for 'an object convertible to string' do
|
16
|
+
it "should call `to_s` on the given object" do
|
17
|
+
expect(formatted_obj).to eq obj.to_s
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
|
-
|
21
|
+
context 'when given a string' do
|
22
|
+
let(:obj) { 'hello' }
|
23
|
+
|
24
|
+
it_behaves_like 'an object convertible to string'
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when given an integer' do
|
28
|
+
let(:obj) { 23 }
|
29
|
+
|
30
|
+
it_behaves_like 'an object convertible to string'
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when given a float' do
|
34
|
+
let(:obj) { 5.67 }
|
35
|
+
|
36
|
+
it_behaves_like 'an object convertible to string'
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when given an exponential' do
|
40
|
+
let(:obj) { 10**30 }
|
41
|
+
|
42
|
+
it_behaves_like 'an object convertible to string'
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when given a symbol' do
|
46
|
+
let(:obj) { :foo }
|
47
|
+
|
48
|
+
it_behaves_like 'an object convertible to string'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when given an arbre element' do
|
52
|
+
let(:obj) { Arbre::Element.new.br }
|
53
|
+
|
54
|
+
it_behaves_like 'an object convertible to string'
|
55
|
+
end
|
56
|
+
|
57
|
+
shared_examples_for 'a time-ish object' do
|
18
58
|
it "formats it with the default long format" do
|
19
|
-
expect(
|
59
|
+
expect(formatted_obj).to eq "February 28, 1985 20:15"
|
20
60
|
end
|
21
61
|
|
22
62
|
it "formats it with a customized long format" do
|
23
63
|
with_translation time: { formats: { long: "%B %d, %Y, %l:%M%P" } } do
|
24
|
-
expect(
|
64
|
+
expect(formatted_obj).to eq "February 28, 1985, 8:15pm"
|
25
65
|
end
|
26
66
|
end
|
27
67
|
|
@@ -34,12 +74,12 @@ RSpec.describe "#pretty_format" do
|
|
34
74
|
end
|
35
75
|
|
36
76
|
it "formats it with the default custom format" do
|
37
|
-
expect(
|
77
|
+
expect(formatted_obj).to eq "28 Feb 20:15"
|
38
78
|
end
|
39
79
|
|
40
80
|
it "formats it with i18n custom format" do
|
41
81
|
with_translation time: { formats: { short: "%-m %d %Y" } } do
|
42
|
-
expect(
|
82
|
+
expect(formatted_obj).to eq "2 28 1985"
|
43
83
|
end
|
44
84
|
end
|
45
85
|
end
|
@@ -50,33 +90,44 @@ RSpec.describe "#pretty_format" do
|
|
50
90
|
end
|
51
91
|
|
52
92
|
it "formats it with the default long format" do
|
53
|
-
expect(
|
93
|
+
expect(formatted_obj).to eq "28 de febrero de 1985 20:15"
|
54
94
|
end
|
55
95
|
|
56
96
|
it "formats it with a customized long format" do
|
57
97
|
with_translation time: { formats: { long: "El %d de %B de %Y a las %H horas y %M minutos" } } do
|
58
|
-
expect(
|
98
|
+
expect(formatted_obj).to eq "El 28 de febrero de 1985 a las 20 horas y 15 minutos"
|
59
99
|
end
|
60
100
|
end
|
61
101
|
end
|
62
102
|
end
|
63
103
|
|
64
|
-
|
65
|
-
|
104
|
+
context 'when given a Time in utc' do
|
105
|
+
let(:obj) { Time.utc(1985, "feb", 28, 20, 15, 1) }
|
106
|
+
|
107
|
+
it_behaves_like 'a time-ish object'
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when given a DateTime' do
|
111
|
+
let(:obj) { DateTime.new(1985, 2, 28, 20, 15, 1) }
|
112
|
+
|
113
|
+
it_behaves_like 'a time-ish object'
|
114
|
+
end
|
66
115
|
|
67
116
|
context "given an ActiveRecord object" do
|
117
|
+
let(:obj) { Post.new }
|
118
|
+
|
68
119
|
it "should delegate to auto_link" do
|
69
|
-
|
70
|
-
expect(
|
71
|
-
expect(pretty_format(post)).to eq "model name"
|
120
|
+
expect(view).to receive(:auto_link).with(obj).and_return("model name")
|
121
|
+
expect(formatted_obj).to eq "model name"
|
72
122
|
end
|
73
123
|
end
|
74
124
|
|
75
125
|
context "given an arbitrary object" do
|
126
|
+
let(:obj) { Class.new.new }
|
127
|
+
|
76
128
|
it "should delegate to `display_name`" do
|
77
|
-
|
78
|
-
expect(
|
79
|
-
expect(pretty_format(something)).to eq "I'm not famous"
|
129
|
+
expect(view).to receive(:display_name).with(obj) { "I'm not famous" }
|
130
|
+
expect(formatted_obj).to eq "I'm not famous"
|
80
131
|
end
|
81
132
|
end
|
82
133
|
end
|