2010-05-24 00:18:23 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
describe ContentType do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
before(:each) do
|
|
|
|
Site.any_instance.stubs(:create_default_pages!).returns(true)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
context 'when validating' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
it 'should have a valid factory' do
|
2010-05-26 00:41:10 +00:00
|
|
|
content_type = Factory.build(:content_type)
|
|
|
|
content_type.content_custom_fields.build :label => 'anything', :kind => 'String'
|
|
|
|
content_type.should be_valid
|
2010-05-25 00:32:12 +00:00
|
|
|
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-05-25 00:32:12 +00:00
|
|
|
%w{site name}.each do |field|
|
|
|
|
it "should validate presence of #{field}" do
|
|
|
|
content_type = Factory.build(:content_type, field.to_sym => nil)
|
|
|
|
content_type.should_not be_valid
|
|
|
|
content_type.errors[field.to_sym].should == ["can't be blank"]
|
|
|
|
end
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
it 'should validate presence of slug' do
|
|
|
|
content_type = Factory.build(:content_type, :name => nil, :slug => nil)
|
|
|
|
content_type.should_not be_valid
|
|
|
|
content_type.errors[:slug].should == ["can't be blank"]
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
it 'should validate uniqueness of slug' do
|
2010-05-26 00:41:10 +00:00
|
|
|
content_type = Factory.build(:content_type)
|
|
|
|
content_type.content_custom_fields.build :label => 'anything', :kind => 'String'
|
|
|
|
content_type.save
|
2010-05-25 00:32:12 +00:00
|
|
|
(content_type = Factory.build(:content_type, :site => content_type.site)).should_not be_valid
|
|
|
|
content_type.errors[:slug].should == ["is already taken"]
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-26 00:41:10 +00:00
|
|
|
it 'should validate size of content custom fields' do
|
|
|
|
content_type = Factory.build(:content_type)
|
|
|
|
content_type.should_not be_valid
|
|
|
|
content_type.errors[:content_custom_fields].should == ["is too small (minimum element number is 1)"]
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|