move patches for mongoid / carrierwave + add patch for mongoid + clean stuff

This commit is contained in:
dinedine 2010-06-30 00:09:47 +02:00
parent d685fb526c
commit c5b5c6ded4
8 changed files with 60 additions and 31 deletions

54
Gemfile
View File

@ -1,41 +1,41 @@
# Edit this Gemfile to bundle your application"s dependencies. # Edit this Gemfile to bundle your application's dependencies.
source "http://gemcutter.org" source 'http://gemcutter.org'
source "http://gems.github.com" source 'http://gems.github.com'
gem "rails", "3.0.0.beta3" gem 'rails', '3.0.0.beta3'
gem "liquid" gem 'liquid'
gem "bson_ext", ">= 1.0.1" gem 'bson_ext', '>= 1.0.1'
gem "mongo_ext" gem 'mongo_ext'
gem "mongoid", "2.0.0.beta6" gem 'mongoid', '2.0.0.beta6'
gem "mongoid_acts_as_tree", ">= 0.1.2" gem 'mongoid_acts_as_tree', '>= 0.1.2'
gem "mongo_session_store", "2.0.0.pre" gem 'mongo_session_store', '2.0.0.pre'
gem "warden" gem 'warden'
gem "devise", "1.1.rc1" gem 'devise', '1.1.rc1'
gem "haml", "3.0.1" gem 'haml', '3.0.1'
gem "rmagick", "2.12.2" gem 'rmagick', '2.12.2'
gem "aws" gem 'aws'
gem "jeweler" gem 'jeweler'
gem "mimetype-fu", :require => "mimetype_fu" gem 'mimetype-fu', :require => 'mimetype_fu'
gem "formtastic-rails3", :require => "formtastic" gem 'formtastic-rails3', :require => 'formtastic'
gem "carrierwave-rails3", :require => "carrierwave" gem 'carrierwave-rails3', :require => 'carrierwave'
gem "actionmailer-with-request", :require => 'actionmailer_with_request' gem 'actionmailer-with-request', :require => 'actionmailer_with_request'
gem "heroku" gem 'heroku'
# Development environment # Development environment
group :development do group :development do
# Using mongrel instead of webrick (default server) # Using mongrel instead of webrick (default server)
gem "mongrel" gem 'mongrel'
gem "cgi_multipart_eof_fix" gem 'cgi_multipart_eof_fix'
gem "fastthread" gem 'fastthread'
gem "mongrel_experimental" gem 'mongrel_experimental'
end end
group :test do group :test do
gem 'rspec-rails', '2.0.0.beta.11' gem 'rspec-rails', '2.0.0.beta.11'
gem 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl.git', :branch => 'rails3' gem 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl.git', :branch => 'rails3'
gem 'capybara' #, :git => 'git://github.com/jnicklas/capybara.git' gem 'capybara'
gem 'cucumber' #, '0.7.3' gem 'cucumber'
gem 'cucumber-rails' gem 'cucumber-rails'
gem 'spork' gem 'spork'
gem 'launchy' gem 'launchy'

View File

@ -3,6 +3,7 @@ require 'locomotive/configuration'
require 'locomotive/logger' require 'locomotive/logger'
require 'locomotive/liquid' require 'locomotive/liquid'
require 'locomotive/mongoid' require 'locomotive/mongoid'
require 'locomotive/carrierwave'
require 'locomotive/heroku' require 'locomotive/heroku'
require 'mongo_session_store/mongoid' require 'mongo_session_store/mongoid'

View File

@ -0,0 +1 @@
require 'locomotive/carrierwave/patches'

View File

@ -1,2 +1,3 @@
require 'locomotive/mongoid/document' require 'locomotive/mongoid/document'
require 'locomotive/mongoid/model_extensions' require 'locomotive/mongoid/model_extensions'
require 'locomotive/mongoid/patches'

View File

@ -30,6 +30,28 @@ module Mongoid #:nodoc:
association.to_a.each { |doc| doc.save if doc.changed? || doc.new_record? } unless association.blank? association.to_a.each { |doc| doc.save if doc.changed? || doc.new_record? } unless association.blank?
end end
end end
class EmbedsMany < Proxy
def nested_build(attributes, options = {})
deleted_indexes = []
attributes.each do |index, attrs|
if document = detect { |document| document._index == index.to_i }
if options && options[:allow_destroy] && attrs['_destroy']
deleted_indexes << document._index
@target.delete(document)
document.destroy
else
document.write_attributes(attrs)
document._index = index.to_i - deleted_indexes.collect { |i| i < index.to_i }.size
end
else
build(attrs)
end
end
end
end
end end
# FIX BUG about accepts_nested_attributes_for # FIX BUG about accepts_nested_attributes_for
@ -41,4 +63,6 @@ module Mongoid #:nodoc:
end end
end end
end end
end end

View File

@ -1 +0,0 @@
# load patches here

View File

@ -15,6 +15,8 @@ describe AssetCollection do
@collection = Factory.build(:asset_collection, :site => site) @collection = Factory.build(:asset_collection, :site => site)
@collection.asset_custom_fields.build :label => 'My Description', :_alias => 'description', :kind => 'Text' @collection.asset_custom_fields.build :label => 'My Description', :_alias => 'description', :kind => 'Text'
@collection.asset_custom_fields.build :label => 'Active', :kind => 'Boolean' @collection.asset_custom_fields.build :label => 'Active', :kind => 'Boolean'
# AssetCollection.collection.logger = Logger.new($stdout)
# AssetCollection.db.connection.instance_variable_set(:@logger, Logger.new($stdout))
end end
context 'unit' do context 'unit' do
@ -156,10 +158,11 @@ describe AssetCollection do
@collection.update_attributes(:asset_custom_fields_attributes => { @collection.update_attributes(:asset_custom_fields_attributes => {
'0' => { 'label' => 'My Description', 'kind' => 'Text', '_destroy' => "1" }, '0' => { 'label' => 'My Description', 'kind' => 'Text', '_destroy' => "1" },
'1' => { 'label' => 'Active', 'kind' => 'Boolean', '_destroy' => "0" }, '1' => { 'label' => 'Active', 'kind' => 'Boolean', '_destroy' => "0" },
'2' => { 'label' => 'My Title !', 'kind' => 'String' } '2' => { 'label' => 'My Title !', 'kind' => 'String' },
'new_record' => { 'label' => 'Published at', 'kind' => 'String' }
}) })
@collection = AssetCollection.first @collection = AssetCollection.first
@collection.asset_custom_fields.size.should == 1 @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