This commit is contained in:
did 2012-06-02 06:54:16 -07:00
parent bc63cd8acf
commit acd46f1c10
4 changed files with 22 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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