8000 truncate display_name_methods values · stephancom/activeadmin@92f6af4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92f6af4

Browse files
committed
truncate display_name_methods values
1 parent 6040f1d commit 92f6af4

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/active_admin/application.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@ def initialize
101101

102102
# Active Admin makes educated guesses when displaying objects, this is
103103
# the list of methods it tries calling in order
104-
setting :display_name_methods, [ :display_name,
105-
:full_name,
106-
:name,
107-
:username,
108-
:login,
109-
:title,
110-
:email,
111-
:to_s ]
104+
setting :display_name_methods, [:display_name, :to_s]
112105

113106
# == Deprecated Settings
114107

spec/support/rails_template.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
accepts_nested_attributes_for :author
2525
accepts_nested_attributes_for :taggings
2626
attr_accessible :author, :position unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
27+
28+
def display_name
29+
title
30+
end
2731
}, after: 'class Post < ActiveRecord::Base'
2832
copy_file File.expand_path('../templates/post_decorator.rb', __FILE__), "app/models/post_decorator.rb"
2933

@@ -97,6 +101,12 @@ def set_id
97101

98102
generate 'active_admin:install'
99103

104+
inject_into_file 'app/models/admin_user.rb', %q{
105+
def display_name
106+
email
107+
end
108+
}, after: 'class AdminUser < ActiveRecord::Base'
109+
100110
inject_into_file "config/routes.rb", "\n root to: redirect('/admin')", after: /.*::Application.routes.draw do/
101111
remove_file "public/index.html" if File.exists? "public/index.html"
102112

spec/unit/view_helpers/display_name_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
end
1515

1616
it "should memoize the result for the class" do
17-
subject = Class.new.new
18-
expect(subject).to receive(:name).twice.and_return "My Name"
17+
subject = double(title: "My Name")
18+
expect(subject).to receive(:display_name).twice.and_return "My Name"
1919
expect(display_name subject).to eq "My Name"
2020
expect(ActiveAdmin.application).to_not receive(:display_name_methods)
2121
expect(display_name subject).to eq "My Name"
@@ -27,8 +27,9 @@
2727
allow(klass).to receive(:reflect_on_all_associations).and_return [ double(name: :login) ]
2828
allow(subject).to receive :login
2929
expect(subject).to_not receive :login
30-
allow(subject).to receive(:email).and_return 'foo@bar.baz'
31-
expect(display_name subject).to eq 'foo@bar.baz'
30+
allow(ActiveAdmin.application).to receive(:display_name_methods).and_return [:login, :display_name]
31+
allow(subject).to receive(:display_name).and_return "foo@bar.baz"
32+
expect(display_name subject).to eq "foo@bar.baz"
3233
end
3334

3435
it "should return `nil` when the passed object is `nil`" do

0 commit comments

Comments
 (0)
0