2010-05-25 00:32:12 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
describe ContentInstance do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
before(:each) do
|
|
|
|
Site.any_instance.stubs(:create_default_pages!).returns(true)
|
|
|
|
@content_type = Factory.build(:content_type)
|
|
|
|
@content_type.content_custom_fields.build :label => 'Title', :kind => 'String'
|
|
|
|
@content_type.content_custom_fields.build :label => 'Description', :kind => 'Text'
|
2010-07-19 00:09:10 +00:00
|
|
|
@content_type.content_custom_fields.build :label => 'Visible ?', :kind => 'Text', :_alias => 'visible'
|
2010-05-25 00:32:12 +00:00
|
|
|
@content_type.highlighted_field_name = 'custom_field_1'
|
|
|
|
end
|
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
describe '#validation' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
it 'is valid' do
|
2010-05-25 00:32:12 +00:00
|
|
|
build_content.should be_valid
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
# Validations ##
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
it 'requires presence of title' do
|
2010-05-25 00:32:12 +00:00
|
|
|
content = build_content :title => nil
|
|
|
|
content.should_not be_valid
|
|
|
|
content.errors[:title].should == ["can't be blank"]
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
describe '#visibility' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
before(:each) do
|
|
|
|
@content = build_content
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
it 'is visible by default' do
|
|
|
|
@content._visible?.should be_true
|
|
|
|
@content.visible?.should be_true
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
it 'can be visible even if it is nil' do
|
|
|
|
@content.visible = nil
|
|
|
|
@content.send(:set_visibility)
|
|
|
|
@content.visible?.should be_true
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
it 'can not be visible' do
|
|
|
|
@content.visible = false
|
|
|
|
@content.send(:set_visibility)
|
|
|
|
@content.visible?.should be_false
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-19 00:09:10 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-01-18 00:19:18 +00:00
|
|
|
describe '#requirements' do
|
|
|
|
|
|
|
|
it 'has public access to the highlighted field value' do
|
|
|
|
build_content.highlighted_field_value.should == 'Locomotive'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
def build_content(options = {})
|
|
|
|
@content_type.contents.build({ :title => 'Locomotive', :description => 'Lorem ipsum....' }.merge(options))
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|