Merge branch 'rails_3_1' of github.com:locomotivecms/engine into rails_3_1
This commit is contained in:
commit
5d750bee44
@ -26,7 +26,7 @@ module Locomotive
|
||||
|
||||
def set_parent_and_fields
|
||||
@parent = current_site.content_types.where(:slug => params[:slug]).first
|
||||
@fields = @parent.content_custom_fields
|
||||
@fields = @parent.contents_custom_fields
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Locomotive::ContentTypesHelper
|
||||
|
||||
@content_types = current_site.content_types.ordered.
|
||||
limit(:contents => Locomotive.config.lastest_items_nb).
|
||||
only(:site_id, :name, :slug, :highlighted_field_name, :content_custom_fields_version, :order_by, :serialized_item_template, :raw_item_template).to_a
|
||||
only(:site_id, :name, :slug, :highlighted_field_name, :contents_custom_fields_version, :order_by, :serialized_item_template, :raw_item_template).to_a
|
||||
|
||||
if @content_type && @content_type.persisted? && @content_types.index(@content_type) >= MAX_DISPLAYED_CONTENTS
|
||||
@content_types.delete(@content_type)
|
||||
@ -86,4 +86,4 @@ module Locomotive::ContentTypesHelper
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -47,8 +47,8 @@ module Locomotive::CustomFieldsHelper
|
||||
klass_name = my_content_type.content_klass.to_s
|
||||
|
||||
[].tap do |options|
|
||||
ContentType.where(:'content_custom_fields.kind' => 'has_one', :'content_custom_fields.target' => klass_name).each do |content_type|
|
||||
content_type.content_custom_fields.find_all { |f| f.has_one? && f.target == klass_name }.each do |field|
|
||||
ContentType.where(:'contents_custom_fields.kind' => 'has_one', :'contents_custom_fields.target' => klass_name).each do |content_type|
|
||||
content_type.contents_custom_fields.find_all { |f| f.has_one? && f.target == klass_name }.each do |field|
|
||||
options << {
|
||||
:klass => content_type.content_klass.to_s,
|
||||
:label => field.label,
|
||||
|
@ -84,7 +84,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def set_visibility
|
||||
field = self.content_type.content_custom_fields.detect { |f| %w{visible active}.include?(f._alias) }
|
||||
field = self.content_type.contents_custom_fields.detect { |f| %w{visible active}.include?(f._alias) }
|
||||
self._visible = self.send(field._name) rescue true
|
||||
end
|
||||
|
||||
|
@ -39,7 +39,7 @@ module Locomotive
|
||||
## validations ##
|
||||
validates_presence_of :site, :name, :slug
|
||||
validates_uniqueness_of :slug, :scope => :site_id
|
||||
validates_size_of :content_custom_fields, :minimum => 1, :message => :array_too_short
|
||||
validates_size_of :contents_custom_fields, :minimum => 1, :message => :array_too_short
|
||||
|
||||
## behaviours ##
|
||||
custom_fields_for :contents
|
||||
@ -88,7 +88,7 @@ module Locomotive
|
||||
|
||||
conditions.each do |key, value|
|
||||
# convert alias (key) to name
|
||||
field = self.content_custom_fields.detect { |f| f._alias == key }
|
||||
field = self.contents_custom_fields.detect { |f| f._alias == key }
|
||||
|
||||
case field.kind.to_sym
|
||||
when :category
|
||||
@ -116,18 +116,18 @@ module Locomotive
|
||||
end
|
||||
|
||||
def highlighted_field
|
||||
self.content_custom_fields.detect { |f| f._name == self.highlighted_field_name }
|
||||
self.contents_custom_fields.detect { |f| f._name == self.highlighted_field_name }
|
||||
end
|
||||
|
||||
def group_by_field
|
||||
@group_by_field ||= self.content_custom_fields.detect { |f| f._name == self.group_by_field_name }
|
||||
@group_by_field ||= self.contents_custom_fields.detect { |f| f._name == self.group_by_field_name }
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_default_values
|
||||
self.order_by ||= 'created_at'
|
||||
self.highlighted_field_name ||= self.content_custom_fields.first._name
|
||||
self.highlighted_field_name ||= self.contents_custom_fields.first._name
|
||||
end
|
||||
|
||||
def normalize_slug
|
||||
@ -137,7 +137,7 @@ module Locomotive
|
||||
|
||||
def remove_uploaded_files # callbacks are not called on each content so we do it manually
|
||||
self.contents.each do |content|
|
||||
self.content_custom_fields.each do |field|
|
||||
self.contents_custom_fields.each do |field|
|
||||
content.send(:"remove_#{field._name}!") if field.kind == 'file'
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields|
|
||||
field['target'] = target_content_type.content_klass.to_s
|
||||
end
|
||||
|
||||
content_type.content_custom_fields.build field
|
||||
content_type.contents_custom_fields.build field
|
||||
end
|
||||
content_type.valid?
|
||||
content_type.save.should be_true
|
||||
@ -19,7 +19,7 @@ Given /^I set up a reverse has_many relationship between "([^"]*)" and "([^"]*)"
|
||||
content_type_1 = site.content_types.where(:name => name_1).first
|
||||
content_type_2 = site.content_types.where(:name => name_2).first
|
||||
|
||||
content_type_1.content_custom_fields.build({
|
||||
content_type_1.contents_custom_fields.build({
|
||||
:label => name_2,
|
||||
:kind => 'has_many',
|
||||
:target => content_type_2.content_klass.to_s,
|
||||
@ -31,7 +31,7 @@ end
|
||||
|
||||
Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |values, field, name|
|
||||
content_type = ContentType.where(:name => name).first
|
||||
field = content_type.content_custom_fields.detect { |f| f.label == field }
|
||||
field = content_type.contents_custom_fields.detect { |f| f.label == field }
|
||||
field.should_not be_nil
|
||||
|
||||
if field.category?
|
||||
@ -54,7 +54,7 @@ end
|
||||
|
||||
When %r{^I change the presentation of the "([^"]*)" model by grouping items by "([^"]*)"$} do |name, field|
|
||||
content_type = ContentType.where(:name => name).first
|
||||
field = content_type.content_custom_fields.detect { |f| f.label == field }
|
||||
field = content_type.contents_custom_fields.detect { |f| f.label == field }
|
||||
content_type.group_by_field_name = field._name
|
||||
content_type.save.should be_true
|
||||
end
|
||||
|
@ -1,15 +1,15 @@
|
||||
Given %r{^I have an? "([^"]*)" model which has many "([^"]*)"$} do |parent_model, child_model|
|
||||
@parent_model = FactoryGirl.build(:content_type, :site => @site, :name => parent_model).tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.contents_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.save!
|
||||
end
|
||||
@child_model = FactoryGirl.build(:content_type, :site => @site, :name => child_model).tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.content_custom_fields.build :label => parent_model.singularize, :kind => 'has_one', :required => false, :target => parent_model
|
||||
ct.contents_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.contents_custom_fields.build :label => parent_model.singularize, :kind => 'has_one', :required => false, :target => parent_model
|
||||
ct.save!
|
||||
end
|
||||
|
||||
@parent_model.content_custom_fields.build({
|
||||
@parent_model.contents_custom_fields.build({
|
||||
:label => child_model,
|
||||
:kind => 'has_many',
|
||||
:target => @child_model.content_klass.to_s,
|
||||
|
@ -1,7 +1,7 @@
|
||||
Then /^I should be able to display paginated models$/ do
|
||||
# Create our article model and three articles
|
||||
@article_model = FactoryGirl.build(:content_type, :site => @site, :name => 'Articles').tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.contents_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.save!
|
||||
end
|
||||
|
||||
|
@ -111,7 +111,7 @@ module Locomotive
|
||||
|
||||
# custom_fields
|
||||
fields = []
|
||||
content_type.content_custom_fields.each do |field|
|
||||
content_type.contents_custom_fields.each do |field|
|
||||
field_attributes = self.extract_attributes(field, %w(label kind hint required))
|
||||
|
||||
if field.target.present?
|
||||
|
@ -24,7 +24,7 @@ module Locomotive
|
||||
|
||||
self.add_or_update_fields(content_type, attributes['fields'])
|
||||
|
||||
if content_type.content_custom_fields.any? { |f| ['has_many', 'has_one'].include?(f.kind) }
|
||||
if content_type.contents_custom_fields.any? { |f| ['has_many', 'has_one'].include?(f.kind) }
|
||||
content_types_with_associations << content_type
|
||||
end
|
||||
|
||||
@ -82,9 +82,9 @@ module Locomotive
|
||||
|
||||
attributes = { :_alias => name, :label => name.humanize, :kind => 'string', :position => position }.merge(data).symbolize_keys
|
||||
|
||||
field = content_type.content_custom_fields.detect { |f| f._alias == attributes[:_alias] }
|
||||
field = content_type.contents_custom_fields.detect { |f| f._alias == attributes[:_alias] }
|
||||
|
||||
field ||= content_type.content_custom_fields.build(attributes)
|
||||
field ||= content_type.contents_custom_fields.build(attributes)
|
||||
|
||||
field.send(:set_unique_name!) if field.new_record?
|
||||
|
||||
@ -98,7 +98,7 @@ module Locomotive
|
||||
|
||||
def replace_target(content_types)
|
||||
content_types.each do |content_type|
|
||||
content_type.content_custom_fields.each do |field|
|
||||
content_type.contents_custom_fields.each do |field|
|
||||
next unless ['has_many', 'has_one'].include?(field.kind)
|
||||
|
||||
target_content_type = site.content_types.where(:slug => field.target).first
|
||||
@ -141,7 +141,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
attributes.each do |name, value|
|
||||
field = content_type.content_custom_fields.detect { |f| f._alias == name }
|
||||
field = content_type.contents_custom_fields.detect { |f| f._alias == name }
|
||||
|
||||
next if field.nil? # the attribute name is not related to a field (name misspelled ?)
|
||||
|
||||
@ -210,7 +210,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def set_highlighted_field_name(content_type)
|
||||
field = content_type.content_custom_fields.detect { |f| f._alias == content_type.highlighted_field_name.to_s }
|
||||
field = content_type.contents_custom_fields.detect { |f| f._alias == content_type.highlighted_field_name.to_s }
|
||||
|
||||
content_type.highlighted_field_name = field._name if field
|
||||
end
|
||||
@ -222,7 +222,7 @@ module Locomotive
|
||||
when 'manually', '_position_in_list' then '_position_in_list'
|
||||
when 'default', 'created_at' then 'created_at'
|
||||
else
|
||||
content_type.content_custom_fields.detect { |f| f._alias == content_type.order_by }._name rescue nil
|
||||
content_type.contents_custom_fields.detect { |f| f._alias == content_type.order_by }._name rescue nil
|
||||
end)
|
||||
|
||||
self.log "order by (after) #{order_by}"
|
||||
@ -233,11 +233,11 @@ module Locomotive
|
||||
def set_group_by_value(content_type)
|
||||
return if content_type.group_by_field_name.blank?
|
||||
|
||||
field = content_type.content_custom_fields.detect { |f| f._alias == content_type.group_by_field_name }
|
||||
field = content_type.contents_custom_fields.detect { |f| f._alias == content_type.group_by_field_name }
|
||||
|
||||
content_type.group_by_field_name = field._name if field
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,10 +5,10 @@ describe Locomotive::ApiContentsController do
|
||||
before(:each) do
|
||||
@site = FactoryGirl.create('existing site')
|
||||
@site.content_types.first.tap do |content_type|
|
||||
content_type.content_custom_fields.build :label => 'Name', :kind => 'string', :required => true
|
||||
content_type.content_custom_fields.build :label => 'Description', :kind => 'text'
|
||||
content_type.content_custom_fields.build :label => 'File', :kind => 'file'
|
||||
content_type.content_custom_fields.build :label => 'Active', :kind => 'boolean'
|
||||
content_type.contents_custom_fields.build :label => 'Name', :kind => 'string', :required => true
|
||||
content_type.contents_custom_fields.build :label => 'Description', :kind => 'text'
|
||||
content_type.contents_custom_fields.build :label => 'File', :kind => 'file'
|
||||
content_type.contents_custom_fields.build :label => 'Active', :kind => 'boolean'
|
||||
end.save
|
||||
|
||||
controller.stubs(:require_site).returns(true)
|
||||
|
@ -40,9 +40,9 @@ describe Locomotive::Export do
|
||||
|
||||
def build_project_type(site)
|
||||
FactoryGirl.build(:content_type, :site => site, :highlighted_field_name => 'custom_field_1').tap do |content_type|
|
||||
content_type.content_custom_fields.build :label => 'Title', :_alias => 'title', :kind => 'string'
|
||||
content_type.content_custom_fields.build :label => 'My Description', :_alias => 'description', :kind => 'text'
|
||||
content_type.content_custom_fields.build :label => 'Active', :kind => 'boolean'
|
||||
content_type.contents_custom_fields.build :label => 'Title', :_alias => 'title', :kind => 'string'
|
||||
content_type.contents_custom_fields.build :label => 'My Description', :_alias => 'description', :kind => 'text'
|
||||
content_type.contents_custom_fields.build :label => 'Active', :kind => 'boolean'
|
||||
end
|
||||
end
|
||||
|
||||
@ -50,10 +50,10 @@ describe Locomotive::Export do
|
||||
Object.send(:remove_const, 'TestProject') rescue nil
|
||||
klass = Object.const_set('TestProject', Class.new { def self.embedded?; false; end })
|
||||
content_type = FactoryGirl.build(:content_type, :site => site, :name => 'team', :highlighted_field_name => 'custom_field_1')
|
||||
content_type.content_custom_fields.build :label => 'Name', :_alias => 'name', :kind => 'string'
|
||||
content_type.content_custom_fields.build :label => 'Projects', :kind => 'has_many', :_alias => 'projects', :target => 'TestProject'
|
||||
content_type.content_custom_fields.build :label => 'Bio', :_alias => 'bio', :kind => 'text'
|
||||
content_type.content_custom_fields.build :label => 'Current Project', :kind => 'has_one', :_alias => 'current_project', :target => 'TestProject'
|
||||
content_type.contents_custom_fields.build :label => 'Name', :_alias => 'name', :kind => 'string'
|
||||
content_type.contents_custom_fields.build :label => 'Projects', :kind => 'has_many', :_alias => 'projects', :target => 'TestProject'
|
||||
content_type.contents_custom_fields.build :label => 'Bio', :_alias => 'bio', :kind => 'text'
|
||||
content_type.contents_custom_fields.build :label => 'Current Project', :kind => 'has_one', :_alias => 'current_project', :target => 'TestProject'
|
||||
content_type
|
||||
end
|
||||
|
||||
|
@ -22,12 +22,12 @@ describe Locomotive::Import::Job do
|
||||
it 'adds content types' do
|
||||
@site.content_types.count.should == 4
|
||||
content_type = @site.content_types.where(:slug => 'projects').first
|
||||
content_type.content_custom_fields.size.should == 9
|
||||
content_type.contents_custom_fields.size.should == 9
|
||||
end
|
||||
|
||||
it 'replaces the target and the reverse_lookup values by the correct ones in a has_many relationship' do
|
||||
content_type = @site.content_types.where(:slug => 'clients').first
|
||||
field = content_type.content_custom_fields.last
|
||||
field = content_type.contents_custom_fields.last
|
||||
field.target.should match /^ContentContentType/
|
||||
field.reverse_lookup.should == 'custom_field_8'
|
||||
end
|
||||
|
@ -5,8 +5,8 @@ describe Locomotive::Liquid::Drops::Content do
|
||||
before(:each) do
|
||||
@site = FactoryGirl.build(:site)
|
||||
content_type = FactoryGirl.build(:content_type)
|
||||
content_type.content_custom_fields.build :label => 'anything', :kind => 'string'
|
||||
content_type.content_custom_fields.build :label => 'published_at', :kind => 'date'
|
||||
content_type.contents_custom_fields.build :label => 'anything', :kind => 'string'
|
||||
content_type.contents_custom_fields.build :label => 'published_at', :kind => 'date'
|
||||
@content = content_type.contents.build({
|
||||
:meta_keywords => 'Libidinous, Angsty',
|
||||
:meta_description => "Quite the combination.",
|
||||
|
@ -81,7 +81,7 @@ describe Locomotive::Liquid::Tags::SEO do
|
||||
|
||||
let(:content_type) do
|
||||
FactoryGirl.build(:content_type, :site => site).tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'anything', :kind => 'String'
|
||||
ct.contents_custom_fields.build :label => 'anything', :kind => 'String'
|
||||
end
|
||||
end
|
||||
|
||||
@ -132,4 +132,4 @@ describe Locomotive::Liquid::Tags::SEO do
|
||||
liquid_context = ::Liquid::Context.new({}, assigns, registers)
|
||||
output = Liquid::Template.parse("{% #{tag_name} %}").render(liquid_context)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,9 +7,9 @@ describe Locomotive::ContentInstance do
|
||||
before(:each) do
|
||||
Locomotive::Site.any_instance.stubs(:create_default_pages!).returns(true)
|
||||
@content_type = FactoryGirl.build(:content_type)
|
||||
@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.contents_custom_fields.build :label => 'Title', :kind => 'String'
|
||||
@content_type.contents_custom_fields.build :label => 'Description', :kind => 'Text'
|
||||
@content_type.contents_custom_fields.build :label => 'Visible ?', :kind => 'Text', :_alias => 'visible'
|
||||
@content_type.highlighted_field_name = 'custom_field_1'
|
||||
end
|
||||
|
||||
|
@ -10,7 +10,7 @@ describe Locomotive::ContentType do
|
||||
|
||||
it 'should have a valid factory' do
|
||||
content_type = FactoryGirl.build(:content_type)
|
||||
content_type.content_custom_fields.build :label => 'anything', :kind => 'String'
|
||||
content_type.contents_custom_fields.build :label => 'anything', :kind => 'String'
|
||||
content_type.should be_valid
|
||||
end
|
||||
|
||||
@ -32,7 +32,7 @@ describe Locomotive::ContentType do
|
||||
|
||||
it 'is not valid if slug is not unique' do
|
||||
content_type = FactoryGirl.build(:content_type)
|
||||
content_type.content_custom_fields.build :label => 'anything', :kind => 'String'
|
||||
content_type.contents_custom_fields.build :label => 'anything', :kind => 'String'
|
||||
content_type.save
|
||||
(content_type = FactoryGirl.build(:content_type, :site => content_type.site)).should_not be_valid
|
||||
content_type.errors[:slug].should == ["is already taken"]
|
||||
@ -41,13 +41,13 @@ describe Locomotive::ContentType do
|
||||
it 'is not valid if there is not at least one field' do
|
||||
content_type = FactoryGirl.build(:content_type)
|
||||
content_type.should_not be_valid
|
||||
content_type.errors[:content_custom_fields].should == ["is too small (minimum element number is 1)"]
|
||||
content_type.errors[:contents_custom_fields].should == ["is too small (minimum element number is 1)"]
|
||||
end
|
||||
|
||||
%w(created_at updated_at).each do |_alias|
|
||||
it "does not allow #{_alias} as alias" do
|
||||
content_type = FactoryGirl.build(:content_type)
|
||||
field = content_type.content_custom_fields.build :label => 'anything', :kind => 'String', :_alias => _alias
|
||||
field = content_type.contents_custom_fields.build :label => 'anything', :kind => 'String', :_alias => _alias
|
||||
field.valid?.should be_false
|
||||
field.errors[:_alias].should == ['is reserved']
|
||||
end
|
||||
@ -98,8 +98,8 @@ describe Locomotive::ContentType do
|
||||
site = FactoryGirl.build(:site)
|
||||
Locomotive::Site.stubs(:find).returns(site)
|
||||
@content_type = FactoryGirl.build(:content_type, :site => site, :highlighted_field_name => 'custom_field_1')
|
||||
@content_type.content_custom_fields.build :label => 'My Description', :_alias => 'description', :kind => 'text'
|
||||
@content_type.content_custom_fields.build :label => 'Active', :kind => 'boolean'
|
||||
@content_type.contents_custom_fields.build :label => 'My Description', :_alias => 'description', :kind => 'text'
|
||||
@content_type.contents_custom_fields.build :label => 'Active', :kind => 'boolean'
|
||||
# Locomotive::ContentType.logger = Logger.new($stdout)
|
||||
# Locomotive::ContentType.db.connection.instance_variable_set(:@logger, Logger.new($stdout))
|
||||
end
|
||||
@ -125,22 +125,22 @@ describe Locomotive::ContentType do
|
||||
|
||||
%w{label kind}.each do |key|
|
||||
it "should validate presence of #{key}" do
|
||||
field = @content_type.content_custom_fields.build({ :label => 'Shortcut', :kind => 'String' }.merge(key.to_sym => nil))
|
||||
field = @content_type.contents_custom_fields.build({ :label => 'Shortcut', :kind => 'String' }.merge(key.to_sym => nil))
|
||||
field.should_not be_valid
|
||||
field.errors[key.to_sym].should == ["can't be blank"]
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not have unique label' do
|
||||
field = @content_type.content_custom_fields.build :label => 'Active', :kind => 'Boolean'
|
||||
field = @content_type.contents_custom_fields.build :label => 'Active', :kind => 'Boolean'
|
||||
field.should_not be_valid
|
||||
field.errors[:label].should == ["is already taken"]
|
||||
end
|
||||
|
||||
it 'should invalidate parent if custom field is not valid' do
|
||||
field = @content_type.content_custom_fields.build
|
||||
field = @content_type.contents_custom_fields.build
|
||||
@content_type.should_not be_valid
|
||||
@content_type.content_custom_fields.last.errors[:label].should == ["can't be blank"]
|
||||
@content_type.contents_custom_fields.last.errors[:label].should == ["can't be blank"]
|
||||
end
|
||||
|
||||
end
|
||||
@ -148,13 +148,13 @@ describe Locomotive::ContentType do
|
||||
context 'define core attributes' do
|
||||
|
||||
it 'should have an unique name' do
|
||||
@content_type.content_custom_fields.first._name.should == "custom_field_1"
|
||||
@content_type.content_custom_fields.last._name.should == "custom_field_2"
|
||||
@content_type.contents_custom_fields.first._name.should == "custom_field_1"
|
||||
@content_type.contents_custom_fields.last._name.should == "custom_field_2"
|
||||
end
|
||||
|
||||
it 'should have an unique alias' do
|
||||
@content_type.content_custom_fields.first.safe_alias.should == "description"
|
||||
@content_type.content_custom_fields.last.safe_alias.should == "active"
|
||||
@content_type.contents_custom_fields.first.safe_alias.should == "description"
|
||||
@content_type.contents_custom_fields.last.safe_alias.should == "active"
|
||||
end
|
||||
|
||||
end
|
||||
@ -200,7 +200,7 @@ describe Locomotive::ContentType do
|
||||
end
|
||||
|
||||
it 'should add new field' do
|
||||
@content_type.content_custom_fields.build :label => 'Active at', :name => 'active_at', :kind => 'Date'
|
||||
@content_type.contents_custom_fields.build :label => 'Active at', :name => 'active_at', :kind => 'Date'
|
||||
@content_type.upsert(:validate => false)
|
||||
@content_type.invalidate_content_klass
|
||||
@content_type.reload
|
||||
@ -209,7 +209,7 @@ describe Locomotive::ContentType do
|
||||
end
|
||||
|
||||
it 'should remove field' do
|
||||
@content_type.content_custom_fields.clear
|
||||
@content_type.contents_custom_fields.clear
|
||||
@content_type.upsert(:validate => false)
|
||||
@content_type.invalidate_content_klass
|
||||
@content_type.reload
|
||||
@ -218,8 +218,8 @@ describe Locomotive::ContentType do
|
||||
end
|
||||
|
||||
it 'should rename field label' do
|
||||
@content_type.content_custom_fields.first.label = 'Simple description'
|
||||
@content_type.content_custom_fields.first._alias = nil
|
||||
@content_type.contents_custom_fields.first.label = 'Simple description'
|
||||
@content_type.contents_custom_fields.first._alias = nil
|
||||
@content_type.upsert(:validate => false)
|
||||
|
||||
@content_type.invalidate_content_klass
|
||||
@ -234,26 +234,26 @@ describe Locomotive::ContentType do
|
||||
context 'managing from hash' do
|
||||
|
||||
it 'adds new field' do
|
||||
@content_type.content_custom_fields.clear
|
||||
field = @content_type.content_custom_fields.build :label => 'Title'
|
||||
@content_type.content_custom_fields_attributes = { 0 => { :id => field.id.to_s, 'label' => 'A title', 'kind' => 'String' }, 1 => { 'label' => 'Tagline', 'kind' => 'String' } }
|
||||
@content_type.content_custom_fields.size.should == 2
|
||||
@content_type.content_custom_fields.first.label.should == 'A title'
|
||||
@content_type.content_custom_fields.last.label.should == 'Tagline'
|
||||
@content_type.contents_custom_fields.clear
|
||||
field = @content_type.contents_custom_fields.build :label => 'Title'
|
||||
@content_type.contents_custom_fields_attributes = { 0 => { :id => field.id.to_s, 'label' => 'A title', 'kind' => 'String' }, 1 => { 'label' => 'Tagline', 'kind' => 'String' } }
|
||||
@content_type.contents_custom_fields.size.should == 2
|
||||
@content_type.contents_custom_fields.first.label.should == 'A title'
|
||||
@content_type.contents_custom_fields.last.label.should == 'Tagline'
|
||||
end
|
||||
|
||||
it 'updates/removes fields' do
|
||||
field = @content_type.content_custom_fields.build :label => 'Title', :kind => 'String'
|
||||
field = @content_type.contents_custom_fields.build :label => 'Title', :kind => 'String'
|
||||
@content_type.save; @content_type = Locomotive::ContentType.find(@content_type.id)
|
||||
@content_type.update_attributes(:content_custom_fields_attributes => {
|
||||
@content_type.update_attributes(:contents_custom_fields_attributes => {
|
||||
'0' => { 'id' => lookup_field_id(0), 'label' => 'My Description', 'kind' => 'Text', '_destroy' => '1' },
|
||||
'1' => { 'id' => lookup_field_id(1), 'label' => 'Active', 'kind' => 'Boolean', '_destroy' => '1' },
|
||||
'2' => { 'id' => lookup_field_id(2), 'label' => 'My Title !', 'kind' => 'String' },
|
||||
'new_record' => { 'label' => 'Published at', 'kind' => 'String' }
|
||||
})
|
||||
@content_type = Locomotive::ContentType.find(@content_type.id)
|
||||
@content_type.content_custom_fields.size.should == 2
|
||||
@content_type.content_custom_fields.first.label.should == 'My Title !'
|
||||
@content_type.contents_custom_fields.size.should == 2
|
||||
@content_type.contents_custom_fields.first.label.should == 'My Title !'
|
||||
end
|
||||
|
||||
end
|
||||
@ -265,7 +265,7 @@ describe Locomotive::ContentType do
|
||||
end
|
||||
|
||||
def lookup_field_id(index)
|
||||
@content_type.content_custom_fields.all[index].id.to_s
|
||||
@content_type.contents_custom_fields.all[index].id.to_s
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user