diff --git a/Gemfile b/Gemfile index d9daa8c5..b7957c61 100644 --- a/Gemfile +++ b/Gemfile @@ -1,18 +1,17 @@ # Edit this Gemfile to bundle your application's dependencies. 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 'bson_ext', '1.0.4' -gem 'mongoid', '2.0.0.beta.16' +gem 'bson_ext', '= 1.0.4' +gem 'mongoid', '2.0.0.beta.17' gem 'mongoid_acts_as_tree', '0.1.5' gem 'mongo_session_store', '2.0.0.pre' gem 'warden' 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 'aws' gem 'mimetype-fu', :require => 'mimetype_fu' @@ -43,7 +42,6 @@ group :test do gem 'growl-glue' gem 'rspec-rails', '2.0.0.beta.19' gem 'factory_girl_rails' - # gem 'pickle', :git => 'http://github.com/codegram/pickle.git' gem 'pickle', :git => 'http://github.com/ianwhite/pickle.git' gem 'pickle-mongoid' gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 74ec8b7e..6f933ea7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,9 +7,9 @@ GIT GIT remote: git://github.com/locomotivecms/custom_fields.git - revision: d393307 + revision: 89c4d7d specs: - custom_fields (0.0.0.1) + custom_fields (0.0.0.2) GIT remote: git://github.com/locomotivecms/liquid.git @@ -33,35 +33,35 @@ GEM specs: RedCloth (4.2.3) abstract (1.0.0) - actionmailer (3.0.0.rc) - actionpack (= 3.0.0.rc) + actionmailer (3.0.0) + actionpack (= 3.0.0) mail (~> 2.2.5) actionmailer-with-request (0.1.1) - actionpack (3.0.0.rc) - activemodel (= 3.0.0.rc) - activesupport (= 3.0.0.rc) + actionpack (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) builder (~> 2.1.2) erubis (~> 2.6.6) i18n (~> 0.4.1) rack (~> 1.2.1) - rack-mount (~> 0.6.9) + rack-mount (~> 0.6.12) rack-test (~> 0.5.4) - tzinfo (~> 0.3.22) - activemodel (3.0.0.rc) - activesupport (= 3.0.0.rc) + tzinfo (~> 0.3.23) + activemodel (3.0.0) + activesupport (= 3.0.0) builder (~> 2.1.2) i18n (~> 0.4.1) - activerecord (3.0.0.rc) - activemodel (= 3.0.0.rc) - activesupport (= 3.0.0.rc) - arel (~> 0.4.0) - tzinfo (~> 0.3.22) - activeresource (3.0.0.rc) - activemodel (= 3.0.0.rc) - activesupport (= 3.0.0.rc) - activesupport (3.0.0.rc) - arel (0.4.0) - activesupport (>= 3.0.0.beta) + activerecord (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + arel (~> 1.0.0) + tzinfo (~> 0.3.23) + activeresource (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + activesupport (3.0.0) + arel (1.0.1) + activesupport (~> 3.0.0) autotest (4.3.2) aws (2.3.20) http_connection @@ -117,7 +117,7 @@ GEM trollop (~> 1.16.2) git (1.2.5) growl-glue (1.0.7) - haml (3.0.15) + haml (3.0.18) has_scope (0.5.0) heroku (1.9.14) json_pure (>= 1.2.0, < 1.5.0) @@ -149,11 +149,11 @@ GEM bson (>= 1.0.4) mongo_session_store (2.0.0.pre) actionpack (~> 3.0) - mongoid (2.0.0.beta.16) - activemodel (= 3.0.0.rc) + mongoid (2.0.0.beta.17) + activemodel (~> 3.0.0) bson (= 1.0.4) mongo (= 1.0.7) - tzinfo (= 0.3.22) + tzinfo (~> 0.3.22) will_paginate (~> 3.0.pre) mongoid_acts_as_tree (0.1.5) bson (>= 0.20.1) @@ -173,18 +173,18 @@ GEM rack (>= 1.0.0) rack-test (0.5.4) rack (>= 1.0) - rails (3.0.0.rc) - actionmailer (= 3.0.0.rc) - actionpack (= 3.0.0.rc) - activerecord (= 3.0.0.rc) - activeresource (= 3.0.0.rc) - activesupport (= 3.0.0.rc) - bundler (>= 1.0.0.rc.1) - railties (= 3.0.0.rc) - railties (3.0.0.rc) - actionpack (= 3.0.0.rc) - activesupport (= 3.0.0.rc) - rake (>= 0.8.3) + rails (3.0.0) + actionmailer (= 3.0.0) + actionpack (= 3.0.0) + activerecord (= 3.0.0) + activeresource (= 3.0.0) + activesupport (= 3.0.0) + bundler (~> 1.0.0) + railties (= 3.0.0) + railties (3.0.0) + actionpack (= 3.0.0) + activesupport (= 3.0.0) + rake (>= 0.8.4) thor (~> 0.14.0) rake (0.8.7) responders (0.6.2) @@ -220,7 +220,7 @@ GEM treetop (1.4.8) polyglot (>= 0.3.1) trollop (1.16.2) - tzinfo (0.3.22) + tzinfo (0.3.23) uuidtools (2.1.1) warden (0.10.7) rack (>= 1.0.0) @@ -253,7 +253,7 @@ DEPENDENCIES fastthread formtastic-rails3 (= 1.0.0.beta3) growl-glue - haml (= 3.0.15) + haml (= 3.0.18) heroku httparty (= 0.6.1) inherited_resources (= 1.1.2) @@ -263,12 +263,12 @@ DEPENDENCIES mimetype-fu mocha! 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) mongrel pickle! pickle-mongoid - rails (= 3.0.0.rc) + rails (= 3.0.0) rmagick (= 2.12.2) rspec-rails (= 2.0.0.beta.19) ruby-debug diff --git a/lib/locomotive/mongoid/patches.rb b/lib/locomotive/mongoid/patches.rb index 419601ea..7c640bc2 100644 --- a/lib/locomotive/mongoid/patches.rb +++ b/lib/locomotive/mongoid/patches.rb @@ -16,6 +16,19 @@ module Mongoid #:nodoc: 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 module Mongoid #:nodoc: module Atomicity #:nodoc: diff --git a/spec/models/asset_collections_spec.rb b/spec/models/asset_collections_spec.rb index 0bcdb2f9..38396236 100644 --- a/spec/models/asset_collections_spec.rb +++ b/spec/models/asset_collections_spec.rb @@ -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,7 +121,7 @@ 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) @@ -129,7 +129,7 @@ describe AssetCollection do asset = @collection.assets.first lambda { asset.active }.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 @@ -138,11 +138,11 @@ describe AssetCollection do 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' @@ -151,7 +151,7 @@ describe AssetCollection do @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 @@ -165,7 +165,7 @@ describe AssetCollection do @collection.asset_custom_fields.size.should == 2 @collection.asset_custom_fields.first.label.should == 'My Title !' end - + end end