new Gemfile + fixing broken tests + improve the way we fetch the sicurrent te when serving fonts
This commit is contained in:
parent
fa8e509732
commit
69c9dbbbcf
12
Gemfile
12
Gemfile
@ -7,20 +7,20 @@ gem 'rails', '>= 3.0.0'
|
|||||||
gem 'warden'
|
gem 'warden'
|
||||||
gem 'devise', '= 1.1.3'
|
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 '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 'will_paginate'
|
||||||
|
|
||||||
gem 'haml', '= 3.0.18'
|
gem 'haml', '= 3.0.18'
|
||||||
gem 'locomotive_liquid', '2.2.2', :require => 'liquid'
|
gem 'locomotive_liquid', '2.2.2', :require => 'liquid'
|
||||||
gem 'formtastic', '>= 1.1.0'
|
gem 'formtastic', '~> 1.1.0'
|
||||||
gem 'inherited_resources', '>= 1.1.2'
|
gem 'inherited_resources', '1.1.2'
|
||||||
|
|
||||||
gem 'rmagick', '= 2.12.2'
|
gem 'rmagick', '= 2.12.2'
|
||||||
gem 'locomotive_carrierwave', '0.5.0.1.beta2', :require => 'carrierwave'
|
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 'fog', '0.3.7'
|
||||||
gem 'mimetype-fu'
|
gem 'mimetype-fu'
|
||||||
gem 'actionmailer-with-request'
|
gem 'actionmailer-with-request'
|
||||||
@ -28,7 +28,7 @@ gem 'heroku'
|
|||||||
gem 'httparty', '>= 0.6.1'
|
gem 'httparty', '>= 0.6.1'
|
||||||
gem 'RedCloth'
|
gem 'RedCloth'
|
||||||
gem 'delayed_job', '2.1.2'
|
gem 'delayed_job', '2.1.2'
|
||||||
gem 'delayed_job_mongoid', '1.0.1'
|
gem 'delayed_job_mongoid', '1.0.2'
|
||||||
gem 'rubyzip'
|
gem 'rubyzip'
|
||||||
gem 'locomotive_jammit-s3', :require => 'jammit-s3'
|
gem 'locomotive_jammit-s3', :require => 'jammit-s3'
|
||||||
|
|
||||||
|
70
Gemfile.lock
70
Gemfile.lock
@ -5,6 +5,21 @@ GIT
|
|||||||
mocha (0.9.10.20101125155727)
|
mocha (0.9.10.20101125155727)
|
||||||
rake
|
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
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
@ -46,7 +61,7 @@ GEM
|
|||||||
bson (1.2.0)
|
bson (1.2.0)
|
||||||
bson_ext (1.2.0)
|
bson_ext (1.2.0)
|
||||||
builder (2.1.2)
|
builder (2.1.2)
|
||||||
capybara (0.4.0)
|
capybara (0.4.1.1)
|
||||||
celerity (>= 0.7.9)
|
celerity (>= 0.7.9)
|
||||||
culerity (>= 0.2.4)
|
culerity (>= 0.2.4)
|
||||||
mime-types (>= 1.16)
|
mime-types (>= 1.16)
|
||||||
@ -54,7 +69,7 @@ GEM
|
|||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
rack-test (>= 0.5.4)
|
rack-test (>= 0.5.4)
|
||||||
selenium-webdriver (>= 0.0.27)
|
selenium-webdriver (>= 0.0.27)
|
||||||
xpath (~> 0.1.2)
|
xpath (~> 0.1.3)
|
||||||
celerity (0.8.7)
|
celerity (0.8.7)
|
||||||
childprocess (0.1.6)
|
childprocess (0.1.6)
|
||||||
ffi (~> 0.6.3)
|
ffi (~> 0.6.3)
|
||||||
@ -70,19 +85,15 @@ GEM
|
|||||||
term-ansicolor (~> 1.0.4)
|
term-ansicolor (~> 1.0.4)
|
||||||
cucumber-rails (0.3.2)
|
cucumber-rails (0.3.2)
|
||||||
cucumber (>= 0.8.0)
|
cucumber (>= 0.8.0)
|
||||||
culerity (0.2.14)
|
culerity (0.2.15)
|
||||||
custom_fields (1.0.0.beta2)
|
|
||||||
activesupport (>= 3.0.0)
|
|
||||||
locomotive_carrierwave
|
|
||||||
mongoid (>= 2.0.0.beta.18)
|
|
||||||
daemons (1.1.0)
|
daemons (1.1.0)
|
||||||
database_cleaner (0.6.0)
|
database_cleaner (0.6.0)
|
||||||
delayed_job (2.1.2)
|
delayed_job (2.1.2)
|
||||||
activesupport (~> 3.0)
|
activesupport (~> 3.0)
|
||||||
daemons
|
daemons
|
||||||
delayed_job_mongoid (1.0.1)
|
delayed_job_mongoid (1.0.2)
|
||||||
delayed_job (~> 2.1.1)
|
delayed_job (~> 2.1.1)
|
||||||
mongoid (~> 2.0)
|
mongoid (~> 2.0.0.rc)
|
||||||
devise (1.1.3)
|
devise (1.1.3)
|
||||||
bcrypt-ruby (~> 2.1.2)
|
bcrypt-ruby (~> 2.1.2)
|
||||||
warden (~> 0.10.7)
|
warden (~> 0.10.7)
|
||||||
@ -106,17 +117,17 @@ GEM
|
|||||||
nokogiri (~> 1.4.3.1)
|
nokogiri (~> 1.4.3.1)
|
||||||
ruby-hmac
|
ruby-hmac
|
||||||
formatador (0.0.16)
|
formatador (0.0.16)
|
||||||
formtastic (1.2.3)
|
formtastic (1.1.0)
|
||||||
actionpack (>= 2.3.7)
|
actionpack (>= 2.3.0)
|
||||||
activesupport (>= 2.3.7)
|
activesupport (>= 2.3.0)
|
||||||
i18n (~> 0.4)
|
i18n (>= 0.4.0)
|
||||||
gherkin (2.1.5)
|
gherkin (2.1.5)
|
||||||
trollop (~> 1.16.2)
|
trollop (~> 1.16.2)
|
||||||
growl-glue (1.0.7)
|
growl-glue (1.0.7)
|
||||||
haml (3.0.18)
|
haml (3.0.18)
|
||||||
has_scope (0.5.0)
|
has_scope (0.5.0)
|
||||||
heroku (1.17.8)
|
heroku (1.16.2)
|
||||||
json (~> 1.4.6)
|
json_pure (>= 1.2.0, < 1.5.0)
|
||||||
launchy (~> 0.3.2)
|
launchy (~> 0.3.2)
|
||||||
rest-client (>= 1.4.0, < 1.7.0)
|
rest-client (>= 1.4.0, < 1.7.0)
|
||||||
httparty (0.7.3)
|
httparty (0.7.3)
|
||||||
@ -128,7 +139,7 @@ GEM
|
|||||||
jammit (0.6.0)
|
jammit (0.6.0)
|
||||||
closure-compiler (>= 0.1.0)
|
closure-compiler (>= 0.1.0)
|
||||||
yui-compressor (>= 0.9.1)
|
yui-compressor (>= 0.9.1)
|
||||||
json (1.4.6)
|
json (1.5.1)
|
||||||
json_pure (1.4.6)
|
json_pure (1.4.6)
|
||||||
kgio (2.1.1)
|
kgio (2.1.1)
|
||||||
launchy (0.3.7)
|
launchy (0.3.7)
|
||||||
@ -144,22 +155,19 @@ GEM
|
|||||||
mimemagic (>= 0.1.7)
|
mimemagic (>= 0.1.7)
|
||||||
s3 (>= 0.3.7)
|
s3 (>= 0.3.7)
|
||||||
locomotive_liquid (2.2.2)
|
locomotive_liquid (2.2.2)
|
||||||
locomotive_mongoid_acts_as_tree (0.1.5.1)
|
mail (2.2.15)
|
||||||
bson (>= 0.20.1)
|
|
||||||
mongoid (<= 2.0.0.beta.19)
|
|
||||||
mail (2.2.14)
|
|
||||||
activesupport (>= 2.3.6)
|
activesupport (>= 2.3.6)
|
||||||
i18n (>= 0.4.0)
|
i18n (>= 0.4.0)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.16)
|
mime-types (1.16)
|
||||||
mimemagic (0.1.7)
|
mimemagic (0.1.8)
|
||||||
mimetype-fu (0.1.2)
|
mimetype-fu (0.1.2)
|
||||||
mongo (1.0.9)
|
mongo (1.2.0)
|
||||||
bson (>= 1.0.5)
|
bson (>= 1.2.0)
|
||||||
mongoid (2.0.0.beta.19)
|
mongoid (2.0.0.rc.6)
|
||||||
activemodel (~> 3.0)
|
activemodel (~> 3.0)
|
||||||
mongo (= 1.0.9)
|
mongo (~> 1.2)
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
will_paginate (~> 3.0.pre)
|
will_paginate (~> 3.0.pre)
|
||||||
net-ssh (2.0.24)
|
net-ssh (2.0.24)
|
||||||
@ -261,27 +269,27 @@ DEPENDENCIES
|
|||||||
capybara
|
capybara
|
||||||
cucumber (= 0.8.5)
|
cucumber (= 0.8.5)
|
||||||
cucumber-rails
|
cucumber-rails
|
||||||
custom_fields (= 1.0.0.beta2)
|
custom_fields!
|
||||||
database_cleaner
|
database_cleaner
|
||||||
delayed_job (= 2.1.2)
|
delayed_job (= 2.1.2)
|
||||||
delayed_job_mongoid (= 1.0.1)
|
delayed_job_mongoid (= 1.0.2)
|
||||||
devise (= 1.1.3)
|
devise (= 1.1.3)
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
fog (= 0.3.7)
|
fog (= 0.3.7)
|
||||||
formtastic (>= 1.1.0)
|
formtastic (~> 1.1.0)
|
||||||
growl-glue
|
growl-glue
|
||||||
haml (= 3.0.18)
|
haml (= 3.0.18)
|
||||||
heroku
|
heroku
|
||||||
httparty (>= 0.6.1)
|
httparty (>= 0.6.1)
|
||||||
inherited_resources (>= 1.1.2)
|
inherited_resources (= 1.1.2)
|
||||||
launchy
|
launchy
|
||||||
locomotive_carrierwave (= 0.5.0.1.beta2)
|
locomotive_carrierwave (= 0.5.0.1.beta2)
|
||||||
locomotive_jammit-s3
|
locomotive_jammit-s3
|
||||||
locomotive_liquid (= 2.2.2)
|
locomotive_liquid (= 2.2.2)
|
||||||
locomotive_mongoid_acts_as_tree (= 0.1.5.1)
|
locomotive_mongoid_acts_as_tree!
|
||||||
mimetype-fu
|
mimetype-fu
|
||||||
mocha!
|
mocha!
|
||||||
mongoid (= 2.0.0.beta.19)
|
mongoid (= 2.0.0.rc.6)
|
||||||
pickle
|
pickle
|
||||||
rails (>= 3.0.0)
|
rails (>= 3.0.0)
|
||||||
rmagick (= 2.12.2)
|
rmagick (= 2.12.2)
|
||||||
|
@ -28,7 +28,7 @@ class Asset
|
|||||||
|
|
||||||
%w{image stylesheet javascript pdf video audio}.each do |type|
|
%w{image stylesheet javascript pdf video audio}.each do |type|
|
||||||
define_method("#{type}?") do
|
define_method("#{type}?") do
|
||||||
self.content_type == type
|
self.content_type.to_s == type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class ContentInstance
|
|||||||
after_create :send_notifications
|
after_create :send_notifications
|
||||||
|
|
||||||
## named scopes ##
|
## 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 ##
|
## methods ##
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class Page
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def do_not_remove_index_and_404_pages
|
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?
|
if self.index? || self.not_found?
|
||||||
self.errors[:base] << I18n.t('errors.messages.protected_page')
|
self.errors[:base] << I18n.t('errors.messages.protected_page')
|
||||||
|
@ -41,7 +41,7 @@ class ThemeAsset
|
|||||||
|
|
||||||
%w{movie image stylesheet javascript font}.each do |type|
|
%w{movie image stylesheet javascript font}.each do |type|
|
||||||
define_method("#{type}?") do
|
define_method("#{type}?") do
|
||||||
self.content_type == type
|
self.content_type.to_s == type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class ThemeAsset
|
|||||||
|
|
||||||
def local_path(short = false)
|
def local_path(short = false)
|
||||||
if short
|
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
|
else
|
||||||
self.read_attribute(:local_path)
|
self.read_attribute(:local_path)
|
||||||
end
|
end
|
||||||
@ -101,14 +101,14 @@ class ThemeAsset
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_folder
|
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
|
# no accents, no spaces, no leading and ending trails
|
||||||
self.folder = ActiveSupport::Inflector.transliterate(self.folder).gsub(/(\s)+/, '_').gsub(/^\//, '').gsub(/\/$/, '').downcase
|
self.folder = ActiveSupport::Inflector.transliterate(self.folder).gsub(/(\s)+/, '_').gsub(/^\//, '').gsub(/\/$/, '').downcase
|
||||||
|
|
||||||
# folder should begin by a root folder
|
# folder should begin by a root folder
|
||||||
if (self.folder =~ /^(stylesheets|javascripts|images|media|fonts)/).nil?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
3
doc/TODO
3
doc/TODO
@ -1,9 +1,10 @@
|
|||||||
BOARD:
|
BOARD:
|
||||||
|
|
||||||
- add metadata to sites
|
- moving to mongoid 2.0.0 rc.6
|
||||||
|
|
||||||
BACKLOG:
|
BACKLOG:
|
||||||
|
|
||||||
|
- add metadata to sites
|
||||||
- validation for custom fields
|
- validation for custom fields
|
||||||
- new custom field types:
|
- new custom field types:
|
||||||
- belongs_to => association
|
- belongs_to => association
|
||||||
|
@ -15,7 +15,7 @@ module Locomotive
|
|||||||
if site.nil?
|
if site.nil?
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
else
|
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]]
|
[200, { 'Cache-Control' => "public; max-age=#{@expires_in}" }, [body]]
|
||||||
end
|
end
|
||||||
@ -27,9 +27,11 @@ module Locomotive
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def fetch_site(domain_name)
|
def fetch_site(domain_name)
|
||||||
Rails.cache.fetch(domain_name, :expires_in => @expires_in) do
|
site_id = Rails.cache.fetch(domain_name, :expires_in => @expires_in) do
|
||||||
Site.match_domain(domain_name).first
|
Site.match_domain(domain_name).only(:id).first._id.to_s rescue ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
site_id.blank? ? nil : Site.new(:id => site_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,33 +1,6 @@
|
|||||||
require 'mongoid'
|
require 'mongoid'
|
||||||
# require 'mongoid/document'
|
# 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 Mongoid #:nodoc:
|
||||||
module Validations #:nodoc:
|
module Validations #:nodoc:
|
||||||
class AssociatedValidator < ActiveModel::EachValidator
|
class AssociatedValidator < ActiveModel::EachValidator
|
||||||
@ -40,57 +13,127 @@ module Mongoid #:nodoc:
|
|||||||
end
|
end
|
||||||
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 Mongoid #:nodoc:
|
||||||
module Atomicity #:nodoc:
|
module Contexts #:nodoc:
|
||||||
extend ActiveSupport::Concern
|
class Mongo
|
||||||
|
def aggregate
|
||||||
def _updates
|
klass.collection.group(
|
||||||
processed = {}
|
:key => options[:fields],
|
||||||
|
:cond => selector,
|
||||||
_children.inject({ "$set" => _sets, "$pushAll" => {}, :other => {} }) do |updates, child|
|
:initial => { :count => 0 },
|
||||||
changes = child._sets
|
:reduce => Javascript.aggregate
|
||||||
updates["$set"].update(changes)
|
)
|
||||||
unless changes.empty?
|
end
|
||||||
processed[child._conficting_modification_key] = true
|
def group
|
||||||
end
|
klass.collection.group(
|
||||||
|
:key => options[:fields],
|
||||||
# MongoDB does not allow "conflicting modifications" to be
|
:cond => selector,
|
||||||
# performed in a single operation. Conflicting modifications are
|
:initial => { :group => [] },
|
||||||
# detected by the 'haveConflictingMod' function in MongoDB.
|
:reduce => Javascript.group
|
||||||
# Examination of the code suggests that two modifications (a $set
|
).collect do |docs|
|
||||||
# and a $pushAll, for example) conflict if (1) the key paths being
|
docs["group"] = docs["group"].collect do |attrs|
|
||||||
# modified are equal or (2) one key path is a prefix of the other.
|
Mongoid::Factory.build(klass, attrs)
|
||||||
# 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
|
||||||
|
docs
|
||||||
end
|
end
|
||||||
updates
|
end
|
||||||
end.delete_if do |key, value|
|
def grouped(start, field, reduce)
|
||||||
value.empty?
|
collection = klass.collection.group(
|
||||||
|
:cond => selector,
|
||||||
|
:initial => { start => "start" },
|
||||||
|
:reduce => reduce.gsub("[field]", field)
|
||||||
|
)
|
||||||
|
collection.empty? ? nil : collection.first[start.to_s]
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
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
|
@ -20,21 +20,21 @@ Gem::Specification.new do |s|
|
|||||||
s.add_dependency "rails", ">= 3.0.0"
|
s.add_dependency "rails", ">= 3.0.0"
|
||||||
s.add_dependency "warden"
|
s.add_dependency "warden"
|
||||||
s.add_dependency "devise", "= 1.1.3"
|
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 "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 "will_paginate"
|
||||||
|
|
||||||
s.add_dependency "haml", "= 3.0.18"
|
s.add_dependency "haml", "= 3.0.18"
|
||||||
s.add_dependency "locomotive_liquid", "2.2.2"
|
s.add_dependency "locomotive_liquid", "2.2.2"
|
||||||
s.add_dependency "formtastic", ">= 1.1.0"
|
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 "rmagick", "= 2.12.2"
|
||||||
s.add_dependency "locomotive_carrierwave", "0.5.0.1.beta2"
|
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 "fog"
|
||||||
s.add_dependency "mimetype-fu"
|
s.add_dependency "mimetype-fu"
|
||||||
s.add_dependency "actionmailer-with-request"
|
s.add_dependency "actionmailer-with-request"
|
||||||
|
@ -9,14 +9,14 @@ describe Locomotive::Liquid::Filters::Html do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a link tag for a stylesheet file' do
|
it 'should return a link tag for a stylesheet file' do
|
||||||
result = "<link href=\"/sites/42/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
||||||
stylesheet_tag('main.css').should == result
|
stylesheet_tag('main.css').should == result
|
||||||
stylesheet_tag('main').should == result
|
stylesheet_tag('main').should == result
|
||||||
stylesheet_tag(nil).should == ''
|
stylesheet_tag(nil).should == ''
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a link tag for a stylesheet file with folder' do
|
it 'should return a link tag for a stylesheet file with folder' do
|
||||||
result = "<link href=\"/sites/42/theme/stylesheets/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
||||||
stylesheet_tag('trash/main.css').should == result
|
stylesheet_tag('trash/main.css').should == result
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,14 +27,14 @@ describe Locomotive::Liquid::Filters::Html do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a script tag for a javascript file' do
|
it 'should return a script tag for a javascript file' do
|
||||||
result = %{<script src="/sites/42/theme/javascripts/main.js" type="text/javascript"></script>}
|
result = %{<script src="/sites/000000000000000000000042/theme/javascripts/main.js" type="text/javascript"></script>}
|
||||||
javascript_tag('main.js').should == result
|
javascript_tag('main.js').should == result
|
||||||
javascript_tag('main').should == result
|
javascript_tag('main').should == result
|
||||||
javascript_tag(nil).should == ''
|
javascript_tag(nil).should == ''
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a script tag for a javascript file with folder' do
|
it 'should return a script tag for a javascript file with folder' do
|
||||||
result = %{<script src="/sites/42/theme/javascripts/trash/main.js" type="text/javascript"></script>}
|
result = %{<script src="/sites/000000000000000000000042/theme/javascripts/trash/main.js" type="text/javascript"></script>}
|
||||||
javascript_tag('trash/main.js').should == result
|
javascript_tag('trash/main.js').should == result
|
||||||
javascript_tag('trash/main').should == result
|
javascript_tag('trash/main').should == result
|
||||||
end
|
end
|
||||||
@ -107,14 +107,19 @@ describe Locomotive::Liquid::Filters::Html do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def build_context
|
def build_context
|
||||||
Site.any_instance.stubs(:id).returns(42)
|
|
||||||
klass = Class.new
|
klass = Class.new
|
||||||
klass.class_eval do
|
klass.class_eval do
|
||||||
def registers
|
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
|
||||||
end
|
end
|
||||||
klass.new
|
klass.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe AssetCollection do
|
describe AssetCollection do
|
||||||
|
|
||||||
# it 'should have a valid factory' do
|
it 'should have a valid factory' do
|
||||||
# Factory.build(:asset_collection).should be_valid
|
Factory.build(:asset_collection).should be_valid
|
||||||
# end
|
end
|
||||||
|
|
||||||
describe 'custom fields (beta)' do
|
describe 'custom fields (beta)' do
|
||||||
|
|
||||||
@ -20,20 +20,20 @@ describe AssetCollection do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'unit' do
|
context 'unit' do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@field = CustomFields::Field.new(:kind => 'String')
|
@field = CustomFields::Field.new(:kind => 'String')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should tell if it is a String' do
|
it 'should tell if it is a String' do
|
||||||
@field.string?.should be_true
|
@field.string?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should tell if it is a Text' do
|
it 'should tell if it is a Text' do
|
||||||
@field.kind = 'Text'
|
@field.kind = 'Text'
|
||||||
@field.text?.should be_true
|
@field.text?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'validation' do
|
context 'validation' do
|
||||||
@ -45,7 +45,7 @@ describe AssetCollection do
|
|||||||
field.errors[key.to_sym].should == ["can't be blank"]
|
field.errors[key.to_sym].should == ["can't be blank"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not have unique label' do
|
it 'should not have unique label' do
|
||||||
field = @collection.asset_custom_fields.build :label => 'Active', :kind => 'Boolean'
|
field = @collection.asset_custom_fields.build :label => 'Active', :kind => 'Boolean'
|
||||||
field.should_not be_valid
|
field.should_not be_valid
|
||||||
@ -61,21 +61,21 @@ describe AssetCollection do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'define core attributes' do
|
context 'define core attributes' do
|
||||||
|
|
||||||
it 'should have an unique name' do
|
it 'should have an unique name' do
|
||||||
@collection.asset_custom_fields.first._name.should == "custom_field_1"
|
@collection.asset_custom_fields.first._name.should == "custom_field_1"
|
||||||
@collection.asset_custom_fields.last._name.should == "custom_field_2"
|
@collection.asset_custom_fields.last._name.should == "custom_field_2"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have an unique alias' do
|
it 'should have an unique alias' do
|
||||||
@collection.asset_custom_fields.first.safe_alias.should == "description"
|
@collection.asset_custom_fields.first.safe_alias.should == "description"
|
||||||
@collection.asset_custom_fields.last.safe_alias.should == "active"
|
@collection.asset_custom_fields.last.safe_alias.should == "active"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'build and save' do
|
context 'build and save' do
|
||||||
|
|
||||||
it 'should build asset' do
|
it 'should build asset' do
|
||||||
asset = @collection.assets.build
|
asset = @collection.assets.build
|
||||||
lambda {
|
lambda {
|
||||||
@ -84,13 +84,13 @@ describe AssetCollection do
|
|||||||
asset.custom_fields.size.should == 2
|
asset.custom_fields.size.should == 2
|
||||||
}.should_not raise_error
|
}.should_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should assign values to newly built asset' do
|
it 'should assign values to newly built asset' do
|
||||||
asset = build_asset(@collection)
|
asset = build_asset(@collection)
|
||||||
asset.description.should == 'Lorem ipsum'
|
asset.description.should == 'Lorem ipsum'
|
||||||
asset.active.should == true
|
asset.active.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save asset' do
|
it 'should save asset' do
|
||||||
asset = build_asset(@collection)
|
asset = build_asset(@collection)
|
||||||
asset.save and @collection.reload
|
asset.save and @collection.reload
|
||||||
@ -98,22 +98,22 @@ describe AssetCollection do
|
|||||||
asset.description.should == 'Lorem ipsum'
|
asset.description.should == 'Lorem ipsum'
|
||||||
asset.active.should == true
|
asset.active.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not modify assets from another collection' do
|
it 'should not modify assets from another collection' do
|
||||||
asset = build_asset(@collection)
|
asset = build_asset(@collection)
|
||||||
asset.save and @collection.reload
|
asset.save and @collection.reload
|
||||||
new_collection = AssetCollection.new
|
new_collection = AssetCollection.new
|
||||||
lambda { new_collection.assets.build.description }.should raise_error
|
lambda { new_collection.assets.build.description }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'modifying fields' do
|
context 'modifying fields' do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@asset = build_asset(@collection).save
|
@asset = build_asset(@collection).save
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should add new field' do
|
it 'should add new field' do
|
||||||
@collection.asset_custom_fields.build :label => 'Active at', :name => 'active_at', :kind => 'Date'
|
@collection.asset_custom_fields.build :label => 'Active at', :name => 'active_at', :kind => 'Date'
|
||||||
@collection.upsert(:validate => false)
|
@collection.upsert(:validate => false)
|
||||||
@ -121,51 +121,53 @@ describe AssetCollection do
|
|||||||
asset = @collection.assets.first
|
asset = @collection.assets.first
|
||||||
lambda { asset.active_at }.should_not raise_error
|
lambda { asset.active_at }.should_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should remove field' do
|
it 'should remove field' do
|
||||||
@collection.asset_custom_fields.clear
|
@collection.asset_custom_fields.clear
|
||||||
@collection.upsert(:validate => false)
|
@collection.upsert(:validate => false)
|
||||||
@collection.reload
|
@collection.reload
|
||||||
asset = @collection.assets.first
|
asset = @collection.assets.first
|
||||||
lambda { asset.active }.should raise_error
|
lambda { asset.active_at }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should rename field label' do
|
it 'should rename field label' do
|
||||||
@collection.asset_custom_fields.first.label = 'Simple description'
|
@collection.asset_custom_fields.first.label = 'Simple description'
|
||||||
@collection.asset_custom_fields.first._alias = nil
|
@collection.asset_custom_fields.first._alias = nil
|
||||||
@collection.upsert(:validate => false)
|
@collection.upsert(:validate => false)
|
||||||
|
|
||||||
@collection.reload
|
@collection.reload
|
||||||
|
|
||||||
asset = @collection.assets.first
|
asset = @collection.assets.first
|
||||||
asset.simple_description.should == 'Lorem ipsum'
|
asset.simple_description.should == 'Lorem ipsum'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'managing from hash' do
|
context 'managing from hash' do
|
||||||
|
|
||||||
it 'adds new field' do
|
it 'adds new field' do
|
||||||
@collection.asset_custom_fields.clear
|
@collection.asset_custom_fields.clear
|
||||||
@collection.asset_custom_fields.build :label => 'Title'
|
field = @collection.asset_custom_fields.build :label => 'Title'
|
||||||
@collection.asset_custom_fields_attributes = { '0' => { 'label' => 'A title', 'kind' => 'String' }, '-1' => { 'label' => 'Tagline', 'kind' => 'String' } }
|
@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.size.should == 2
|
||||||
@collection.asset_custom_fields.first.label.should == 'A title'
|
@collection.asset_custom_fields.first.label.should == 'A title'
|
||||||
@collection.asset_custom_fields.last.label.should == 'Tagline'
|
@collection.asset_custom_fields.last.label.should == 'Tagline'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates/removes fields' do
|
it 'updates/removes fields' do
|
||||||
@collection.asset_custom_fields.build :label => 'Title', :kind => 'String'
|
field = @collection.asset_custom_fields.build :label => 'Title', :kind => 'String'
|
||||||
@collection.save; @collection = AssetCollection.first
|
@collection.save; @collection = AssetCollection.find(@collection.id)
|
||||||
@collection.update_attributes(:asset_custom_fields_attributes => {
|
@collection.update_attributes(:asset_custom_fields_attributes => {
|
||||||
'0' => { 'label' => 'My Description', 'kind' => 'Text', '_destroy' => '1' },
|
'0' => { 'id' => lookup_field_id(0), 'label' => 'My Description', 'kind' => 'Text', '_destroy' => '1' },
|
||||||
'1' => { 'label' => 'Active', 'kind' => 'Boolean', '_destroy' => '1' },
|
'1' => { 'id' => lookup_field_id(1), 'label' => 'Active', 'kind' => 'Boolean', '_destroy' => '1' },
|
||||||
'2' => { 'label' => 'My Title !', 'kind' => 'String' },
|
'2' => { 'id' => lookup_field_id(2), 'label' => 'My Title !', 'kind' => 'String' },
|
||||||
'new_record' => { 'label' => 'Published at', '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.size.should == 2
|
||||||
@collection.asset_custom_fields.first.label.should == 'My Title !'
|
@collection.asset_custom_fields.first.label.should == 'My Title !'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -174,4 +176,8 @@ describe AssetCollection do
|
|||||||
collection.assets.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true)
|
collection.assets.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def lookup_field_id(index)
|
||||||
|
@collection.asset_custom_fields.all[index].id.to_s
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -63,8 +63,8 @@ describe ContentInstance do
|
|||||||
describe '#api' do
|
describe '#api' do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@account_1 = Factory.build('admin user', :id => '1')
|
@account_1 = Factory.build('admin user', :id => fake_bson_id('1'))
|
||||||
@account_2 = Factory.build('frenchy user', :id => '2')
|
@account_2 = Factory.build('frenchy user', :id => fake_bson_id('2'))
|
||||||
|
|
||||||
@content_type.api_enabled = true
|
@content_type.api_enabled = true
|
||||||
@content_type.api_accounts = ['', @account_1.id, @account_2.id]
|
@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))
|
@content_type.contents.build({ :title => 'Locomotive', :description => 'Lorem ipsum....' }.merge(options))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fake_bson_id(id)
|
||||||
|
BSON::ObjectId(id.to_s.rjust(24, '0'))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user