From acd46f1c10008b65a23e3b4ea2a04e341d00cbac Mon Sep 17 00:00:00 2001 From: did Date: Sat, 2 Jun 2012 06:54:16 -0700 Subject: [PATCH] fix issue #430 --- app/models/locomotive/content_entry.rb | 4 +++- app/models/locomotive/content_type.rb | 4 ++-- lib/locomotive/custom_fields.rb | 2 ++ spec/models/locomotive/content_entry_spec.rb | 17 +++++++++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index 5be95ed7..f1902b26 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -45,9 +45,11 @@ module Locomotive self.send((type || self.content_type).label_field_name.to_sym) end - value.respond_to?(:to_label) ? value.to_label : value + value.respond_to?(:to_label) ? value.to_label : value.to_s end + alias :to_label :_label + def translated? if self.respond_to?(:"#{self._label_field_name}_translations") self.send(:"#{self._label_field_name}_translations").key?(::Mongoid::Fields::I18n.locale.to_s) #rescue false diff --git a/app/models/locomotive/content_type.rb b/app/models/locomotive/content_type.rb index c013cf81..bc9ef4ac 100644 --- a/app/models/locomotive/content_type.rb +++ b/app/models/locomotive/content_type.rb @@ -83,10 +83,10 @@ module Locomotive def class_name_to_content_type(class_name) self.class.class_name_to_content_type(class_name, self.site) end - + def label_field_id=(value) # update the label_field_name if the label_field_id is changed - new_label_field_name = self.entries_custom_fields.where(:_id =>value).first.try(:name) + new_label_field_name = self.entries_custom_fields.where(:_id => value).first.try(:name) self.label_field_name = new_label_field_name super(value) end diff --git a/lib/locomotive/custom_fields.rb b/lib/locomotive/custom_fields.rb index 3fd8b8a9..cc5c4cca 100644 --- a/lib/locomotive/custom_fields.rb +++ b/lib/locomotive/custom_fields.rb @@ -22,6 +22,7 @@ module CustomFields module Types module File + class FileUploader < ::CarrierWave::Uploader::Base # Set correct paths @@ -34,6 +35,7 @@ module CustomFields end end + end end diff --git a/spec/models/locomotive/content_entry_spec.rb b/spec/models/locomotive/content_entry_spec.rb index bea92282..4d9b13b1 100644 --- a/spec/models/locomotive/content_entry_spec.rb +++ b/spec/models/locomotive/content_entry_spec.rb @@ -34,6 +34,7 @@ describe Locomotive::ContentEntry do content_entry.should_not be_valid content_entry.errors[:_slug].should == ["can't be blank"] end + end context 'setting the slug' do @@ -187,12 +188,24 @@ describe Locomotive::ContentEntry do end - describe '#requirements' do + describe '#label' do - it 'has public access to the highlighted field value' do + it 'has a label based on the value of the first field' do build_content_entry._label.should == 'Locomotive' end + it 'uses the to_label method if the value of the label field defined it' do + entry = build_content_entry(:_label_field_name => 'with_to_label') + entry.stubs(:with_to_label).returns(mock('with_to_label', :to_label => 'acme')) + entry._label.should == 'acme' + end + + it 'uses the to_s method at last if the label field did not define the to_label method' do + entry = build_content_entry(:_label_field_name => 'not_a_string') + entry.stubs(:not_a_string).returns(mock('not_a_string', :to_s => 'not_a_string')) + entry._label.should == 'not_a_string' + end + end describe '#public_submission' do