From 9077390db7ad660155476a929fa2f5d7c9f8be68 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Mon, 5 Mar 2012 21:15:43 +0800 Subject: [PATCH] Using a File as a highlighted field will now print the filename as the value. Fixes #289. --- app/models/content_instance.rb | 2 +- spec/models/content_instance_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/content_instance.rb b/app/models/content_instance.rb index fb506cb3..c49cc524 100644 --- a/app/models/content_instance.rb +++ b/app/models/content_instance.rb @@ -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 diff --git a/spec/models/content_instance_spec.rb b/spec/models/content_instance_spec.rb index f8c4c57b..108bfb23 100644 --- a/spec/models/content_instance_spec.rb +++ b/spec/models/content_instance_spec.rb @@ -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