now working with Rails 3.0 and the last Mongoid gem

This commit is contained in:
dinedine 2010-09-01 16:26:00 +02:00
parent c347038869
commit f7cfcf450e
4 changed files with 83 additions and 72 deletions

10
Gemfile
View File

@ -1,18 +1,17 @@
# Edit this Gemfile to bundle your application's dependencies. # Edit this Gemfile to bundle your application's dependencies.
source 'http://rubygems.org' source 'http://rubygems.org'
gem 'rails', '3.0.0.rc' gem 'rails', '3.0.0'
# gem 'liquid', :path => '../gems/liquid' # local
gem 'liquid', :git => 'git://github.com/locomotivecms/liquid.git', :ref => 'b03cdc289ac36c339545' gem 'liquid', :git => 'git://github.com/locomotivecms/liquid.git', :ref => 'b03cdc289ac36c339545'
gem 'bson_ext', '1.0.4' gem 'bson_ext', '= 1.0.4'
gem 'mongoid', '2.0.0.beta.16' gem 'mongoid', '2.0.0.beta.17'
gem 'mongoid_acts_as_tree', '0.1.5' gem 'mongoid_acts_as_tree', '0.1.5'
gem 'mongo_session_store', '2.0.0.pre' gem 'mongo_session_store', '2.0.0.pre'
gem 'warden' gem 'warden'
gem 'devise', '1.1.2' #:git => 'git://github.com/plataformatec/devise.git' gem 'devise', '1.1.2' #:git => 'git://github.com/plataformatec/devise.git'
gem 'haml', '3.0.15' gem 'haml', '3.0.18'
gem 'rmagick', '2.12.2' gem 'rmagick', '2.12.2'
gem 'aws' gem 'aws'
gem 'mimetype-fu', :require => 'mimetype_fu' gem 'mimetype-fu', :require => 'mimetype_fu'
@ -43,7 +42,6 @@ group :test do
gem 'growl-glue' gem 'growl-glue'
gem 'rspec-rails', '2.0.0.beta.19' gem 'rspec-rails', '2.0.0.beta.19'
gem 'factory_girl_rails' gem 'factory_girl_rails'
# gem 'pickle', :git => 'http://github.com/codegram/pickle.git'
gem 'pickle', :git => 'http://github.com/ianwhite/pickle.git' gem 'pickle', :git => 'http://github.com/ianwhite/pickle.git'
gem 'pickle-mongoid' gem 'pickle-mongoid'
gem 'capybara' gem 'capybara'

View File

@ -7,9 +7,9 @@ GIT
GIT GIT
remote: git://github.com/locomotivecms/custom_fields.git remote: git://github.com/locomotivecms/custom_fields.git
revision: d393307 revision: 89c4d7d
specs: specs:
custom_fields (0.0.0.1) custom_fields (0.0.0.2)
GIT GIT
remote: git://github.com/locomotivecms/liquid.git remote: git://github.com/locomotivecms/liquid.git
@ -33,35 +33,35 @@ GEM
specs: specs:
RedCloth (4.2.3) RedCloth (4.2.3)
abstract (1.0.0) abstract (1.0.0)
actionmailer (3.0.0.rc) actionmailer (3.0.0)
actionpack (= 3.0.0.rc) actionpack (= 3.0.0)
mail (~> 2.2.5) mail (~> 2.2.5)
actionmailer-with-request (0.1.1) actionmailer-with-request (0.1.1)
actionpack (3.0.0.rc) actionpack (3.0.0)
activemodel (= 3.0.0.rc) activemodel (= 3.0.0)
activesupport (= 3.0.0.rc) activesupport (= 3.0.0)
builder (~> 2.1.2) builder (~> 2.1.2)
erubis (~> 2.6.6) erubis (~> 2.6.6)
i18n (~> 0.4.1) i18n (~> 0.4.1)
rack (~> 1.2.1) rack (~> 1.2.1)
rack-mount (~> 0.6.9) rack-mount (~> 0.6.12)
rack-test (~> 0.5.4) rack-test (~> 0.5.4)
tzinfo (~> 0.3.22) tzinfo (~> 0.3.23)
activemodel (3.0.0.rc) activemodel (3.0.0)
activesupport (= 3.0.0.rc) activesupport (= 3.0.0)
builder (~> 2.1.2) builder (~> 2.1.2)
i18n (~> 0.4.1) i18n (~> 0.4.1)
activerecord (3.0.0.rc) activerecord (3.0.0)
activemodel (= 3.0.0.rc) activemodel (= 3.0.0)
activesupport (= 3.0.0.rc) activesupport (= 3.0.0)
arel (~> 0.4.0) arel (~> 1.0.0)
tzinfo (~> 0.3.22) tzinfo (~> 0.3.23)
activeresource (3.0.0.rc) activeresource (3.0.0)
activemodel (= 3.0.0.rc) activemodel (= 3.0.0)
activesupport (= 3.0.0.rc) activesupport (= 3.0.0)
activesupport (3.0.0.rc) activesupport (3.0.0)
arel (0.4.0) arel (1.0.1)
activesupport (>= 3.0.0.beta) activesupport (~> 3.0.0)
autotest (4.3.2) autotest (4.3.2)
aws (2.3.20) aws (2.3.20)
http_connection http_connection
@ -117,7 +117,7 @@ GEM
trollop (~> 1.16.2) trollop (~> 1.16.2)
git (1.2.5) git (1.2.5)
growl-glue (1.0.7) growl-glue (1.0.7)
haml (3.0.15) haml (3.0.18)
has_scope (0.5.0) has_scope (0.5.0)
heroku (1.9.14) heroku (1.9.14)
json_pure (>= 1.2.0, < 1.5.0) json_pure (>= 1.2.0, < 1.5.0)
@ -149,11 +149,11 @@ GEM
bson (>= 1.0.4) bson (>= 1.0.4)
mongo_session_store (2.0.0.pre) mongo_session_store (2.0.0.pre)
actionpack (~> 3.0) actionpack (~> 3.0)
mongoid (2.0.0.beta.16) mongoid (2.0.0.beta.17)
activemodel (= 3.0.0.rc) activemodel (~> 3.0.0)
bson (= 1.0.4) bson (= 1.0.4)
mongo (= 1.0.7) mongo (= 1.0.7)
tzinfo (= 0.3.22) tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre) will_paginate (~> 3.0.pre)
mongoid_acts_as_tree (0.1.5) mongoid_acts_as_tree (0.1.5)
bson (>= 0.20.1) bson (>= 0.20.1)
@ -173,18 +173,18 @@ GEM
rack (>= 1.0.0) rack (>= 1.0.0)
rack-test (0.5.4) rack-test (0.5.4)
rack (>= 1.0) rack (>= 1.0)
rails (3.0.0.rc) rails (3.0.0)
actionmailer (= 3.0.0.rc) actionmailer (= 3.0.0)
actionpack (= 3.0.0.rc) actionpack (= 3.0.0)
activerecord (= 3.0.0.rc) activerecord (= 3.0.0)
activeresource (= 3.0.0.rc) activeresource (= 3.0.0)
activesupport (= 3.0.0.rc) activesupport (= 3.0.0)
bundler (>= 1.0.0.rc.1) bundler (~> 1.0.0)
railties (= 3.0.0.rc) railties (= 3.0.0)
railties (3.0.0.rc) railties (3.0.0)
actionpack (= 3.0.0.rc) actionpack (= 3.0.0)
activesupport (= 3.0.0.rc) activesupport (= 3.0.0)
rake (>= 0.8.3) rake (>= 0.8.4)
thor (~> 0.14.0) thor (~> 0.14.0)
rake (0.8.7) rake (0.8.7)
responders (0.6.2) responders (0.6.2)
@ -220,7 +220,7 @@ GEM
treetop (1.4.8) treetop (1.4.8)
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
trollop (1.16.2) trollop (1.16.2)
tzinfo (0.3.22) tzinfo (0.3.23)
uuidtools (2.1.1) uuidtools (2.1.1)
warden (0.10.7) warden (0.10.7)
rack (>= 1.0.0) rack (>= 1.0.0)
@ -253,7 +253,7 @@ DEPENDENCIES
fastthread fastthread
formtastic-rails3 (= 1.0.0.beta3) formtastic-rails3 (= 1.0.0.beta3)
growl-glue growl-glue
haml (= 3.0.15) haml (= 3.0.18)
heroku heroku
httparty (= 0.6.1) httparty (= 0.6.1)
inherited_resources (= 1.1.2) inherited_resources (= 1.1.2)
@ -263,12 +263,12 @@ DEPENDENCIES
mimetype-fu mimetype-fu
mocha! mocha!
mongo_session_store (= 2.0.0.pre) mongo_session_store (= 2.0.0.pre)
mongoid (= 2.0.0.beta.16) mongoid (= 2.0.0.beta.17)
mongoid_acts_as_tree (= 0.1.5) mongoid_acts_as_tree (= 0.1.5)
mongrel mongrel
pickle! pickle!
pickle-mongoid pickle-mongoid
rails (= 3.0.0.rc) rails (= 3.0.0)
rmagick (= 2.12.2) rmagick (= 2.12.2)
rspec-rails (= 2.0.0.beta.19) rspec-rails (= 2.0.0.beta.19)
ruby-debug ruby-debug

View File

@ -16,6 +16,19 @@ module Mongoid #:nodoc:
end end
end end
module Mongoid #:nodoc:
module Validations #:nodoc:
class AssociatedValidator < ActiveModel::EachValidator
def validate_each(document, attribute, value)
values = value.is_a?(Array) ? value : [ value ]
return if values.collect { |doc| doc.nil? || doc.valid? }.all?
document.errors.add(attribute, :invalid, options.merge(:value => value)) # was causing "can't modify frozen hash"
end
end
end
end
# http://github.com/emk/mongoid/blob/503e346b1b7b250d682a12332ad9d5872f1575e6/lib/mongoid/atomicity.rb # http://github.com/emk/mongoid/blob/503e346b1b7b250d682a12332ad9d5872f1575e6/lib/mongoid/atomicity.rb
module Mongoid #:nodoc: module Mongoid #:nodoc:
module Atomicity #:nodoc: module Atomicity #:nodoc:

View File

@ -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,7 +121,7 @@ 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)
@ -129,7 +129,7 @@ describe AssetCollection do
asset = @collection.assets.first asset = @collection.assets.first
lambda { asset.active }.should raise_error lambda { asset.active }.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
@ -138,11 +138,11 @@ describe AssetCollection do
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' @collection.asset_custom_fields.build :label => 'Title'
@ -151,7 +151,7 @@ describe AssetCollection do
@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' @collection.asset_custom_fields.build :label => 'Title', :kind => 'String'
@collection.save; @collection = AssetCollection.first @collection.save; @collection = AssetCollection.first
@ -165,7 +165,7 @@ describe AssetCollection do
@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