Using a File as a highlighted field will now print the filename as the value. Fixes #289.

This commit is contained in:
Mario Visic 2012-03-05 21:15:43 +08:00
parent 12acf5e9ff
commit 9077390db7
2 changed files with 18 additions and 1 deletions

View File

@ -41,7 +41,7 @@ class ContentInstance
end
def highlighted_field_value
self.send(self.content_type.highlighted_field_name)
self.send(self.content_type.highlighted_field_name).to_s
end
alias :_label :highlighted_field_value

View File

@ -10,6 +10,7 @@ describe ContentInstance do
@content_type.content_custom_fields.build :label => 'Title', :kind => 'String'
@content_type.content_custom_fields.build :label => 'Description', :kind => 'Text'
@content_type.content_custom_fields.build :label => 'Visible ?', :kind => 'Text', :_alias => 'visible'
@content_type.content_custom_fields.build :label => 'Photo', :kind => 'File'
@content_type.highlighted_field_name = 'custom_field_1'
end
@ -211,4 +212,20 @@ describe ContentInstance do
def fake_bson_id(id)
BSON::ObjectId(id.to_s.rjust(24, '0'))
end
describe '#highlighted_field_value' do
it 'returns the value of the highlighted field' do
content = build_content(:title => 'Cheese')
content.highlighted_field_value.should == 'Cheese'
end
it 'returns the filename of a file type highlighted field' do
@content_type.highlighted_field_name = 'custom_field_4'
content = build_content(:photo => File.open(Rails.root.join('spec', 'fixtures', 'assets', '5k.png')))
content.highlighted_field_value.should be_a String
content.highlighted_field_value.should include '5k.png'
end
end
end