8000 Calling render in display name for all resources that are not nil · stephancom/activeadmin@57cb105 · GitHub
[go: up one dir, main page]

Skip to content

Commit 57cb105

Browse files
author
Vineeth B S
committed
Calling render in display name for all resources that are not nil
Self is assigned to render_in_context only when the context is nil Added Spec to check if false returns a `false` string when display_name is called on it Added Cucumber specs to cover the same scenarios in the integration testing
1 parent 48a8674 commit 57cb105

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

features/show/default_content.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Feature: Show - Default Content
33
Viewing the show page for a resource
44

55
Background:
6-
Given a post with the title "Hello World" written by "Jane Doe" exists
6+
Given a unstarred post with the title "Hello World" written by "Jane Doe" exists
77

88
Scenario: Viewing the default show page
99
Given a show configuration of:
@@ -14,6 +14,7 @@ Feature: Show - Default Content
1414
And I should see the attribute "Body" with "Empty"
1515
And I should see the attribute "Created At" with a nicely formatted datetime
1616
And I should see the attribute "Author" with "Jane Doe"
17+
And I should see the attribute "Starred" with "false"
1718
And I should see an action item button "Delete Post"
1819
And I should see an action item button "Edit Post"
1920

features/step_definitions/factory_steps.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ def create_user(name, type = 'User')
33
user = type.camelize.constantize.where(first_name: first_name, last_name: last_name).first_or_create(username: name.tr(' ', '').underscore)
44
end
55

6-
Given /^(a|\d+)( published)? posts?(?: with the title "([^"]*)")?(?: and body "([^"]*)")?(?: written by "([^"]*)")?(?: in category "([^"]*)")? exists?$/ do |count, published, title, body, user, category_name|
6+
Given /^(a|\d+)( published)?( unstarred|starred)? posts?(?: with the title "([^"]*)")?(?: and body "([^"]*)")?(?: written by "([^"]*)")?(?: in category "([^"]*)")? exists?$/ do |count, published, starred, title, body, user, category_name|
77
count = count == 'a' ? 1 : count.to_i
88
published = Time.now if published
9+
starred = starred == " starred" if starred
910
author = create_user(user) if user
1011
category = Category.where(name: category_name).first_or_create if category_name
1112
title ||= "Hello World %i"
1213
count.times do |i|
13-
Post.create! title: title % i, body: body, author: author, published_at: published, custom_category_id: category.try(:id)
14+
Post.create! title: title % i, body: body, author: author, published_at: published, custom_category_id: category.try(:id), starred: starred
1415
end
1516
end
1617

lib/active_admin/view_helpers/display_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def DISPLAY_NAME_FALLBACK.inspect
1515
# Attempts to call any known display name methods on the resource.
1616
# See the setting in `application.rb` for the list of methods and their priority.
1717
def display_name(resource)
18-
render_in_context resource, display_name_method_for(resource) if resource
18+
render_in_context resource, display_name_method_for(resource) unless resource.nil?
1919
end
2020

2121
# Looks up and caches the first available display name method.

lib/active_admin/view_helpers/method_or_proc_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def render_or_call_method_or_proc_on(obj, string_symbol_or_proc, options = {})
8080
# passing it the proc. This evaluates the proc in the context of the reciever, thus changing
8181
# what `self` means inside the proc.
8282
def render_in_context(context, obj, *args)
83-
context ||= self # default to `self`
83+
context = self if context.nil? # default to `self` only when nil
8484
case obj
8585
when Proc
8686
context.instance_exec *args, &obj

spec/unit/view_helpers/display_name_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
expect(display_name subject).to eq 'foo@bar.baz'
3232
end
3333

34-
[nil, false].each do |type|
35-
it "should return nil when the passed object is #{type.inspect}" do
36-
expect(display_name type).to eq nil
37-
end
34+
it "should return nil when the passed object is nil" do
35+
expect(display_name nil).to eq nil
36+
end
37+
38+
it "should return `false` when the passed objct is false" do
39+
expect(display_name false).to eq "false"
3840
end
3941

4042
it "should default to `to_s`" do

0 commit comments

Comments
 (0)
0