diff --git a/Gemfile b/Gemfile
index 7ac77d8c..3e3edaf1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,20 +7,20 @@ gem 'rails', '>= 3.0.0'
gem 'warden'
gem 'devise', '= 1.1.3'
-gem 'mongoid', '2.0.0.beta.19'
+gem 'mongoid', '2.0.0.rc.6'
gem 'bson_ext', '1.2.0'
-gem 'locomotive_mongoid_acts_as_tree', '0.1.5.1', :require => 'mongoid_acts_as_tree'
+gem 'locomotive_mongoid_acts_as_tree', :path => '../gems/acts_as_tree', :require => 'mongoid_acts_as_tree' # '0.1.5.1', :require => 'mongoid_acts_as_tree'
gem 'will_paginate'
gem 'haml', '= 3.0.18'
gem 'locomotive_liquid', '2.2.2', :require => 'liquid'
-gem 'formtastic', '>= 1.1.0'
-gem 'inherited_resources', '>= 1.1.2'
+gem 'formtastic', '~> 1.1.0'
+gem 'inherited_resources', '1.1.2'
gem 'rmagick', '= 2.12.2'
gem 'locomotive_carrierwave', '0.5.0.1.beta2', :require => 'carrierwave'
-gem 'custom_fields', '1.0.0.beta2'
+gem 'custom_fields', :path => '../gems/custom_fields' #'1.0.0.beta2'
gem 'fog', '0.3.7'
gem 'mimetype-fu'
gem 'actionmailer-with-request'
@@ -28,7 +28,7 @@ gem 'heroku'
gem 'httparty', '>= 0.6.1'
gem 'RedCloth'
gem 'delayed_job', '2.1.2'
-gem 'delayed_job_mongoid', '1.0.1'
+gem 'delayed_job_mongoid', '1.0.2'
gem 'rubyzip'
gem 'locomotive_jammit-s3', :require => 'jammit-s3'
diff --git a/Gemfile.lock b/Gemfile.lock
index ca0e1a07..0883b07e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -5,6 +5,21 @@ GIT
mocha (0.9.10.20101125155727)
rake
+PATH
+ remote: ../gems/acts_as_tree
+ specs:
+ locomotive_mongoid_acts_as_tree (0.1.5.2)
+ bson (>= 0.20.1)
+ mongoid (>= 2.0.0.rc.6)
+
+PATH
+ remote: ../gems/custom_fields
+ specs:
+ custom_fields (1.0.0.beta.3)
+ activesupport (>= 3.0.0)
+ locomotive_carrierwave
+ mongoid (>= 2.0.0.beta.18)
+
GEM
remote: http://rubygems.org/
specs:
@@ -46,7 +61,7 @@ GEM
bson (1.2.0)
bson_ext (1.2.0)
builder (2.1.2)
- capybara (0.4.0)
+ capybara (0.4.1.1)
celerity (>= 0.7.9)
culerity (>= 0.2.4)
mime-types (>= 1.16)
@@ -54,7 +69,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (>= 0.0.27)
- xpath (~> 0.1.2)
+ xpath (~> 0.1.3)
celerity (0.8.7)
childprocess (0.1.6)
ffi (~> 0.6.3)
@@ -70,19 +85,15 @@ GEM
term-ansicolor (~> 1.0.4)
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
- culerity (0.2.14)
- custom_fields (1.0.0.beta2)
- activesupport (>= 3.0.0)
- locomotive_carrierwave
- mongoid (>= 2.0.0.beta.18)
+ culerity (0.2.15)
daemons (1.1.0)
database_cleaner (0.6.0)
delayed_job (2.1.2)
activesupport (~> 3.0)
daemons
- delayed_job_mongoid (1.0.1)
+ delayed_job_mongoid (1.0.2)
delayed_job (~> 2.1.1)
- mongoid (~> 2.0)
+ mongoid (~> 2.0.0.rc)
devise (1.1.3)
bcrypt-ruby (~> 2.1.2)
warden (~> 0.10.7)
@@ -106,17 +117,17 @@ GEM
nokogiri (~> 1.4.3.1)
ruby-hmac
formatador (0.0.16)
- formtastic (1.2.3)
- actionpack (>= 2.3.7)
- activesupport (>= 2.3.7)
- i18n (~> 0.4)
+ formtastic (1.1.0)
+ actionpack (>= 2.3.0)
+ activesupport (>= 2.3.0)
+ i18n (>= 0.4.0)
gherkin (2.1.5)
trollop (~> 1.16.2)
growl-glue (1.0.7)
haml (3.0.18)
has_scope (0.5.0)
- heroku (1.17.8)
- json (~> 1.4.6)
+ heroku (1.16.2)
+ json_pure (>= 1.2.0, < 1.5.0)
launchy (~> 0.3.2)
rest-client (>= 1.4.0, < 1.7.0)
httparty (0.7.3)
@@ -128,7 +139,7 @@ GEM
jammit (0.6.0)
closure-compiler (>= 0.1.0)
yui-compressor (>= 0.9.1)
- json (1.4.6)
+ json (1.5.1)
json_pure (1.4.6)
kgio (2.1.1)
launchy (0.3.7)
@@ -144,22 +155,19 @@ GEM
mimemagic (>= 0.1.7)
s3 (>= 0.3.7)
locomotive_liquid (2.2.2)
- locomotive_mongoid_acts_as_tree (0.1.5.1)
- bson (>= 0.20.1)
- mongoid (<= 2.0.0.beta.19)
- mail (2.2.14)
+ mail (2.2.15)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- mimemagic (0.1.7)
+ mimemagic (0.1.8)
mimetype-fu (0.1.2)
- mongo (1.0.9)
- bson (>= 1.0.5)
- mongoid (2.0.0.beta.19)
+ mongo (1.2.0)
+ bson (>= 1.2.0)
+ mongoid (2.0.0.rc.6)
activemodel (~> 3.0)
- mongo (= 1.0.9)
+ mongo (~> 1.2)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
net-ssh (2.0.24)
@@ -261,27 +269,27 @@ DEPENDENCIES
capybara
cucumber (= 0.8.5)
cucumber-rails
- custom_fields (= 1.0.0.beta2)
+ custom_fields!
database_cleaner
delayed_job (= 2.1.2)
- delayed_job_mongoid (= 1.0.1)
+ delayed_job_mongoid (= 1.0.2)
devise (= 1.1.3)
factory_girl_rails
fog (= 0.3.7)
- formtastic (>= 1.1.0)
+ formtastic (~> 1.1.0)
growl-glue
haml (= 3.0.18)
heroku
httparty (>= 0.6.1)
- inherited_resources (>= 1.1.2)
+ inherited_resources (= 1.1.2)
launchy
locomotive_carrierwave (= 0.5.0.1.beta2)
locomotive_jammit-s3
locomotive_liquid (= 2.2.2)
- locomotive_mongoid_acts_as_tree (= 0.1.5.1)
+ locomotive_mongoid_acts_as_tree!
mimetype-fu
mocha!
- mongoid (= 2.0.0.beta.19)
+ mongoid (= 2.0.0.rc.6)
pickle
rails (>= 3.0.0)
rmagick (= 2.12.2)
diff --git a/app/models/asset.rb b/app/models/asset.rb
index 763f8aba..4553e356 100644
--- a/app/models/asset.rb
+++ b/app/models/asset.rb
@@ -28,7 +28,7 @@ class Asset
%w{image stylesheet javascript pdf video audio}.each do |type|
define_method("#{type}?") do
- self.content_type == type
+ self.content_type.to_s == type
end
end
diff --git a/app/models/content_instance.rb b/app/models/content_instance.rb
index a824179c..3dc7d9d5 100644
--- a/app/models/content_instance.rb
+++ b/app/models/content_instance.rb
@@ -24,7 +24,7 @@ class ContentInstance
after_create :send_notifications
## named scopes ##
- scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_items_nb
+ scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.lastest_items_nb
## methods ##
diff --git a/app/models/page.rb b/app/models/page.rb
index fb607a4c..258f75e0 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -87,7 +87,7 @@ class Page
protected
def do_not_remove_index_and_404_pages
- return if (self.site rescue nil).nil?
+ return if self.site.nil? || self.site.destroyed?
if self.index? || self.not_found?
self.errors[:base] << I18n.t('errors.messages.protected_page')
diff --git a/app/models/theme_asset.rb b/app/models/theme_asset.rb
index 21274c41..50b29bf8 100644
--- a/app/models/theme_asset.rb
+++ b/app/models/theme_asset.rb
@@ -41,7 +41,7 @@ class ThemeAsset
%w{movie image stylesheet javascript font}.each do |type|
define_method("#{type}?") do
- self.content_type == type
+ self.content_type.to_s == type
end
end
@@ -51,7 +51,7 @@ class ThemeAsset
def local_path(short = false)
if short
- self.read_attribute(:local_path).gsub(/^#{self.content_type.pluralize}\//, '')
+ self.read_attribute(:local_path).gsub(/^#{self.content_type.to_s.pluralize}\//, '')
else
self.read_attribute(:local_path)
end
@@ -101,14 +101,14 @@ class ThemeAsset
end
def sanitize_folder
- self.folder = self.content_type.pluralize if self.folder.blank?
+ self.folder = self.content_type.to_s.pluralize if self.folder.blank?
# no accents, no spaces, no leading and ending trails
self.folder = ActiveSupport::Inflector.transliterate(self.folder).gsub(/(\s)+/, '_').gsub(/^\//, '').gsub(/\/$/, '').downcase
# folder should begin by a root folder
if (self.folder =~ /^(stylesheets|javascripts|images|media|fonts)/).nil?
- self.folder = File.join(self.content_type.pluralize, self.folder)
+ self.folder = File.join(self.content_type.to_s.pluralize, self.folder)
end
end
diff --git a/doc/TODO b/doc/TODO
index 4988de15..a8902886 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,9 +1,10 @@
BOARD:
-- add metadata to sites
+- moving to mongoid 2.0.0 rc.6
BACKLOG:
+- add metadata to sites
- validation for custom fields
- new custom field types:
- belongs_to => association
diff --git a/lib/locomotive/middlewares/fonts.rb b/lib/locomotive/middlewares/fonts.rb
index 23040ecf..49c66d4d 100644
--- a/lib/locomotive/middlewares/fonts.rb
+++ b/lib/locomotive/middlewares/fonts.rb
@@ -15,7 +15,7 @@ module Locomotive
if site.nil?
@app.call(env)
else
- body = ThemeAssetUploader.build(site, env["PATH_INFO"]).read.to_s
+ body = ThemeAssetUploader.build(site, env['PATH_INFO']).read.to_s
[200, { 'Cache-Control' => "public; max-age=#{@expires_in}" }, [body]]
end
@@ -27,9 +27,11 @@ module Locomotive
protected
def fetch_site(domain_name)
- Rails.cache.fetch(domain_name, :expires_in => @expires_in) do
- Site.match_domain(domain_name).first
+ site_id = Rails.cache.fetch(domain_name, :expires_in => @expires_in) do
+ Site.match_domain(domain_name).only(:id).first._id.to_s rescue ''
end
+
+ site_id.blank? ? nil : Site.new(:id => site_id)
end
end
end
diff --git a/lib/locomotive/mongoid/patches.rb b/lib/locomotive/mongoid/patches.rb
index 155ef1f8..6496abc9 100644
--- a/lib/locomotive/mongoid/patches.rb
+++ b/lib/locomotive/mongoid/patches.rb
@@ -1,33 +1,6 @@
require 'mongoid'
# require 'mongoid/document'
-## various patches
-module Mongoid #:nodoc:
- module Document
-
- def update_child_with_noname(child, clear = false)
- name = child.association_name
- return if name.blank? # fix a weird bug with mongoid-acts-as-tree
- update_child_without_noname(child, clear)
- end
-
- alias_method_chain :update_child, :noname
-
- # module ClassMethods
- #
- # def instantiate(attrs = nil, allocating = false) # used by carrierwave to back up the original file
- # document = super
- # document.send(:run_callbacks, :initialize) do
- # document
- # end
- # end
- #
- # end
-
- end
-end
-
-
module Mongoid #:nodoc:
module Validations #:nodoc:
class AssociatedValidator < ActiveModel::EachValidator
@@ -40,57 +13,127 @@ module Mongoid #:nodoc:
end
end
-# http://github.com/emk/mongoid/blob/503e346b1b7b250d682a12332ad9d5872f1575e6/lib/mongoid/atomicity.rb
+# Mongoid causes the following warning "Collection#group no longer take a list of paramters. This usage is deprecated.Check out the new API at http://api.mongodb.org/ruby/current/Mongo/Collection.html#group-instance_method"
+# it's already corrected in the mongoid master branch so waiting for the new gem to remove this patch
module Mongoid #:nodoc:
- module Atomicity #:nodoc:
- extend ActiveSupport::Concern
-
- def _updates
- processed = {}
-
- _children.inject({ "$set" => _sets, "$pushAll" => {}, :other => {} }) do |updates, child|
- changes = child._sets
- updates["$set"].update(changes)
- unless changes.empty?
- processed[child._conficting_modification_key] = true
- end
-
- # MongoDB does not allow "conflicting modifications" to be
- # performed in a single operation. Conflicting modifications are
- # detected by the 'haveConflictingMod' function in MongoDB.
- # Examination of the code suggests that two modifications (a $set
- # and a $pushAll, for example) conflict if (1) the key paths being
- # modified are equal or (2) one key path is a prefix of the other.
- # So a $set of 'addresses.0.street' will conflict with a $pushAll
- # to 'addresses', and we will need to split our update into two
- # pieces. We do not, however, attempt to match MongoDB's logic
- # exactly. Instead, we assume that two updates conflict if the
- # first component of the two key paths matches.
- if processed.has_key?(child._conficting_modification_key)
- target = :other
- else
- target = "$pushAll"
- end
-
- child._pushes.each do |attr, val|
- if updates[target].has_key?(attr)
- updates[target][attr] << val
- else
- updates[target].update({attr => [val]})
+ module Contexts #:nodoc:
+ class Mongo
+ def aggregate
+ klass.collection.group(
+ :key => options[:fields],
+ :cond => selector,
+ :initial => { :count => 0 },
+ :reduce => Javascript.aggregate
+ )
+ end
+ def group
+ klass.collection.group(
+ :key => options[:fields],
+ :cond => selector,
+ :initial => { :group => [] },
+ :reduce => Javascript.group
+ ).collect do |docs|
+ docs["group"] = docs["group"].collect do |attrs|
+ Mongoid::Factory.build(klass, attrs)
end
+ docs
end
- updates
- end.delete_if do |key, value|
- value.empty?
+ end
+ def grouped(start, field, reduce)
+ collection = klass.collection.group(
+ :cond => selector,
+ :initial => { start => "start" },
+ :reduce => reduce.gsub("[field]", field)
+ )
+ collection.empty? ? nil : collection.first[start.to_s]
end
end
-
- protected
- # Get the key used to check for conflicting modifications. For now, we
- # just use the first component of _path, and discard the first period
- # and everything that follows.
- def _conficting_modification_key
- _path.sub(/\..*/, '')
- end
end
-end
\ No newline at end of file
+end
+
+
+
+
+
+
+# # http://github.com/emk/mongoid/blob/503e346b1b7b250d682a12332ad9d5872f1575e6/lib/mongoid/atomicity.rb
+# module Mongoid #:nodoc:
+# module Atomicity #:nodoc:
+# extend ActiveSupport::Concern
+#
+# def _updates
+# processed = {}
+#
+# _children.inject({ "$set" => _sets, "$pushAll" => {}, :other => {} }) do |updates, child|
+# changes = child._sets
+# updates["$set"].update(changes)
+# unless changes.empty?
+# processed[child._conficting_modification_key] = true
+# end
+#
+# # MongoDB does not allow "conflicting modifications" to be
+# # performed in a single operation. Conflicting modifications are
+# # detected by the 'haveConflictingMod' function in MongoDB.
+# # Examination of the code suggests that two modifications (a $set
+# # and a $pushAll, for example) conflict if (1) the key paths being
+# # modified are equal or (2) one key path is a prefix of the other.
+# # So a $set of 'addresses.0.street' will conflict with a $pushAll
+# # to 'addresses', and we will need to split our update into two
+# # pieces. We do not, however, attempt to match MongoDB's logic
+# # exactly. Instead, we assume that two updates conflict if the
+# # first component of the two key paths matches.
+# if processed.has_key?(child._conficting_modification_key)
+# target = :other
+# else
+# target = "$pushAll"
+# end
+#
+# child._pushes.each do |attr, val|
+# if updates[target].has_key?(attr)
+# updates[target][attr] << val
+# else
+# updates[target].update({attr => [val]})
+# end
+# end
+# updates
+# end.delete_if do |key, value|
+# value.empty?
+# end
+# end
+#
+# protected
+# # Get the key used to check for conflicting modifications. For now, we
+# # just use the first component of _path, and discard the first period
+# # and everything that follows.
+# def _conficting_modification_key
+# _path.sub(/\..*/, '')
+# end
+# end
+# end
+
+
+# ## various patches
+# module Mongoid #:nodoc:
+# module Document
+#
+# def update_child_with_noname(child, clear = false)
+# name = child.association_name
+# return if name.blank? # fix a weird bug with mongoid-acts-as-tree
+# update_child_without_noname(child, clear)
+# end
+#
+# alias_method_chain :update_child, :noname
+#
+# # module ClassMethods
+# #
+# # def instantiate(attrs = nil, allocating = false) # used by carrierwave to back up the original file
+# # document = super
+# # document.send(:run_callbacks, :initialize) do
+# # document
+# # end
+# # end
+# #
+# # end
+#
+# end
+# end
\ No newline at end of file
diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec
index d9b01f17..5bc209f4 100644
--- a/locomotive_cms.gemspec
+++ b/locomotive_cms.gemspec
@@ -20,21 +20,21 @@ Gem::Specification.new do |s|
s.add_dependency "rails", ">= 3.0.0"
s.add_dependency "warden"
s.add_dependency "devise", "= 1.1.3"
- s.add_dependency "mongoid", "2.0.0.beta.19"
+ s.add_dependency "mongoid", "2.0.0.rc.6"
s.add_dependency "bson_ext", "= 1.2.0"
- s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.1"
+ s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.2"
s.add_dependency "will_paginate"
s.add_dependency "haml", "= 3.0.18"
s.add_dependency "locomotive_liquid", "2.2.2"
s.add_dependency "formtastic", ">= 1.1.0"
- s.add_dependency "inherited_resources", ">= 1.1.2"
+ s.add_dependency "inherited_resources", "1.1.2"
s.add_dependency "rmagick", "= 2.12.2"
s.add_dependency "locomotive_carrierwave", "0.5.0.1.beta2"
- s.add_dependency "custom_fields", "1.0.0.beta2"
+ s.add_dependency "custom_fields", "1.0.0.beta3"
s.add_dependency "fog"
s.add_dependency "mimetype-fu"
s.add_dependency "actionmailer-with-request"
diff --git a/spec/lib/locomotive/liquid/filters/html_spec.rb b/spec/lib/locomotive/liquid/filters/html_spec.rb
index 5dc068c8..f1de062c 100644
--- a/spec/lib/locomotive/liquid/filters/html_spec.rb
+++ b/spec/lib/locomotive/liquid/filters/html_spec.rb
@@ -9,14 +9,14 @@ describe Locomotive::Liquid::Filters::Html do
end
it 'should return a link tag for a stylesheet file' do
- result = ""
+ result = ""
stylesheet_tag('main.css').should == result
stylesheet_tag('main').should == result
stylesheet_tag(nil).should == ''
end
it 'should return a link tag for a stylesheet file with folder' do
- result = ""
+ result = ""
stylesheet_tag('trash/main.css').should == result
end
@@ -27,14 +27,14 @@ describe Locomotive::Liquid::Filters::Html do
end
it 'should return a script tag for a javascript file' do
- result = %{}
+ result = %{}
javascript_tag('main.js').should == result
javascript_tag('main').should == result
javascript_tag(nil).should == ''
end
it 'should return a script tag for a javascript file with folder' do
- result = %{}
+ result = %{}
javascript_tag('trash/main.js').should == result
javascript_tag('trash/main').should == result
end
@@ -107,14 +107,19 @@ describe Locomotive::Liquid::Filters::Html do
end
def build_context
- Site.any_instance.stubs(:id).returns(42)
klass = Class.new
klass.class_eval do
def registers
- { :site => Factory.build(:site) }
+ { :site => Factory.build(:site, :id => fake_bson_id(42)) }
+ end
+
+ def fake_bson_id(id)
+ BSON::ObjectId(id.to_s.rjust(24, '0'))
end
end
klass.new
end
+
+
end
diff --git a/spec/models/asset_collections_spec.rb b/spec/models/asset_collection_spec.rb
similarity index 82%
rename from spec/models/asset_collections_spec.rb
rename to spec/models/asset_collection_spec.rb
index 38396236..9fb0b62c 100644
--- a/spec/models/asset_collections_spec.rb
+++ b/spec/models/asset_collection_spec.rb
@@ -2,9 +2,9 @@ require 'spec_helper'
describe AssetCollection do
- # it 'should have a valid factory' do
- # Factory.build(:asset_collection).should be_valid
- # end
+ it 'should have a valid factory' do
+ Factory.build(:asset_collection).should be_valid
+ end
describe 'custom fields (beta)' do
@@ -20,20 +20,20 @@ describe AssetCollection do
end
context 'unit' do
-
+
before(:each) do
@field = CustomFields::Field.new(:kind => 'String')
end
-
+
it 'should tell if it is a String' do
@field.string?.should be_true
end
-
+
it 'should tell if it is a Text' do
@field.kind = 'Text'
@field.text?.should be_true
end
-
+
end
context 'validation' do
@@ -45,7 +45,7 @@ describe AssetCollection do
field.errors[key.to_sym].should == ["can't be blank"]
end
end
-
+
it 'should not have unique label' do
field = @collection.asset_custom_fields.build :label => 'Active', :kind => 'Boolean'
field.should_not be_valid
@@ -61,21 +61,21 @@ describe AssetCollection do
end
context 'define core attributes' do
-
+
it 'should have an unique name' do
@collection.asset_custom_fields.first._name.should == "custom_field_1"
@collection.asset_custom_fields.last._name.should == "custom_field_2"
end
-
+
it 'should have an unique alias' do
@collection.asset_custom_fields.first.safe_alias.should == "description"
@collection.asset_custom_fields.last.safe_alias.should == "active"
end
-
+
end
-
+
context 'build and save' do
-
+
it 'should build asset' do
asset = @collection.assets.build
lambda {
@@ -84,13 +84,13 @@ describe AssetCollection do
asset.custom_fields.size.should == 2
}.should_not raise_error
end
-
+
it 'should assign values to newly built asset' do
asset = build_asset(@collection)
asset.description.should == 'Lorem ipsum'
asset.active.should == true
end
-
+
it 'should save asset' do
asset = build_asset(@collection)
asset.save and @collection.reload
@@ -98,22 +98,22 @@ describe AssetCollection do
asset.description.should == 'Lorem ipsum'
asset.active.should == true
end
-
+
it 'should not modify assets from another collection' do
asset = build_asset(@collection)
asset.save and @collection.reload
new_collection = AssetCollection.new
lambda { new_collection.assets.build.description }.should raise_error
end
-
+
end
-
+
context 'modifying fields' do
-
+
before(:each) do
@asset = build_asset(@collection).save
end
-
+
it 'should add new field' do
@collection.asset_custom_fields.build :label => 'Active at', :name => 'active_at', :kind => 'Date'
@collection.upsert(:validate => false)
@@ -121,51 +121,53 @@ describe AssetCollection do
asset = @collection.assets.first
lambda { asset.active_at }.should_not raise_error
end
-
+
it 'should remove field' do
@collection.asset_custom_fields.clear
@collection.upsert(:validate => false)
@collection.reload
asset = @collection.assets.first
- lambda { asset.active }.should raise_error
+ lambda { asset.active_at }.should raise_error
end
-
+
it 'should rename field label' do
@collection.asset_custom_fields.first.label = 'Simple description'
@collection.asset_custom_fields.first._alias = nil
@collection.upsert(:validate => false)
+
@collection.reload
+
asset = @collection.assets.first
asset.simple_description.should == 'Lorem ipsum'
end
-
+
end
-
+
context 'managing from hash' do
-
+
it 'adds new field' do
@collection.asset_custom_fields.clear
- @collection.asset_custom_fields.build :label => 'Title'
- @collection.asset_custom_fields_attributes = { '0' => { 'label' => 'A title', 'kind' => 'String' }, '-1' => { 'label' => 'Tagline', 'kind' => 'String' } }
+ field = @collection.asset_custom_fields.build :label => 'Title'
+ @collection.asset_custom_fields_attributes = { 0 => { :id => field.id.to_s, 'label' => 'A title', 'kind' => 'String' }, 1 => { 'label' => 'Tagline', 'kind' => 'String' } }
@collection.asset_custom_fields.size.should == 2
@collection.asset_custom_fields.first.label.should == 'A title'
@collection.asset_custom_fields.last.label.should == 'Tagline'
end
-
+
it 'updates/removes fields' do
- @collection.asset_custom_fields.build :label => 'Title', :kind => 'String'
- @collection.save; @collection = AssetCollection.first
+ field = @collection.asset_custom_fields.build :label => 'Title', :kind => 'String'
+ @collection.save; @collection = AssetCollection.find(@collection.id)
@collection.update_attributes(:asset_custom_fields_attributes => {
- '0' => { 'label' => 'My Description', 'kind' => 'Text', '_destroy' => '1' },
- '1' => { 'label' => 'Active', 'kind' => 'Boolean', '_destroy' => '1' },
- '2' => { 'label' => 'My Title !', 'kind' => 'String' },
+ '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' }
})
- @collection = AssetCollection.first
+ @collection = AssetCollection.find(@collection.id)
@collection.asset_custom_fields.size.should == 2
@collection.asset_custom_fields.first.label.should == 'My Title !'
end
-
+
end
end
@@ -174,4 +176,8 @@ describe AssetCollection do
collection.assets.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true)
end
+ def lookup_field_id(index)
+ @collection.asset_custom_fields.all[index].id.to_s
+ end
+
end
diff --git a/spec/models/content_instance_spec.rb b/spec/models/content_instance_spec.rb
index 07ef0689..1585ac24 100644
--- a/spec/models/content_instance_spec.rb
+++ b/spec/models/content_instance_spec.rb
@@ -63,8 +63,8 @@ describe ContentInstance do
describe '#api' do
before(:each) do
- @account_1 = Factory.build('admin user', :id => '1')
- @account_2 = Factory.build('frenchy user', :id => '2')
+ @account_1 = Factory.build('admin user', :id => fake_bson_id('1'))
+ @account_2 = Factory.build('frenchy user', :id => fake_bson_id('2'))
@content_type.api_enabled = true
@content_type.api_accounts = ['', @account_1.id, @account_2.id]
@@ -98,4 +98,8 @@ describe ContentInstance do
@content_type.contents.build({ :title => 'Locomotive', :description => 'Lorem ipsum....' }.merge(options))
end
+ def fake_bson_id(id)
+ BSON::ObjectId(id.to_s.rjust(24, '0'))
+ end
+
end