Browse files

Add CarrierWave support for Mongoid

  • Loading branch information...
1 parent b9c548f commit c6866b1f623bf899805885255152563da94e07fa @mshibuya mshibuya committed Mar 27, 2012
Showing with 17 additions and 9 deletions.
  1. +1 −0 .gitignore
  2. +3 −1 Gemfile
  3. +3 −1 Gemfile31
  4. +3 −1 spec/dummy_app/Gemfile
  5. +4 −3 spec/dummy_app/app/mongoid/field_test.rb
  6. +3 −3 spec/unit/config/fields/base_spec.rb
View
1 .gitignore
@@ -23,6 +23,7 @@ spec/dummy_app/db/*.sqlite3
spec/dummy_app/db/*.sqlite3-journal
spec/dummy_app/db/schema.rb
spec/dummy_app/log/*.log
+spec/dummy_app/public/uploads
spec/dummy_app/Gemfile.lock
tmp/**/*
/.emacs.desktop
View
4 Gemfile
@@ -30,16 +30,18 @@ group :active_record do
end
gem 'paperclip'
gem 'carrierwave'
+ gem 'dragonfly'
end
group :mongoid do
gem 'bson_ext'
gem 'mongoid'
gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
+ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
+ gem 'dragonfly'
end
group :development, :test do
- gem 'dragonfly'
gem 'cancan'
end
View
4 Gemfile31
@@ -33,16 +33,18 @@ group :active_record do
end
gem 'paperclip'
gem 'carrierwave'
+ gem 'dragonfly'
end
group :mongoid do
gem 'bson_ext'
gem 'mongoid'
gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
+ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
+ gem 'dragonfly'
end
group :development, :test do
- gem 'dragonfly'
gem 'cancan'
end
View
4 spec/dummy_app/Gemfile
@@ -30,19 +30,21 @@ group :active_record do
end
gem 'paperclip', '~> 2.4'
gem 'carrierwave'
+ gem 'dragonfly'
end
group :mongoid do
gem 'bson_ext'
gem 'mongoid'
gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
+ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
+ gem 'dragonfly'
end
gem 'devise', '~> 2.0'
gem 'rails_admin', :path => '../../'
gem 'mlb', '~> 0.5'
gem 'mini_magick'
-gem 'dragonfly'
# Gems used only for assets and not required
# in production environments by default.
View
7 spec/dummy_app/app/mongoid/field_test.rb
@@ -26,9 +26,9 @@ class FieldTest
field :protected_field, :type => String
has_mongoid_attached_file :paperclip_asset, :styles => { :thumb => "100x100>" }
- attr_accessible :comment_attributes, :nested_field_tests_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :string_field, :text_field, :integer_field, :float_field, :decimal_field, :datetime_field, :timestamp_field, :time_field, :date_field, :boolean_field, :array_field, :hash_field, :created_at, :updated_at, :format
- attr_accessible :comment_attributes, :nested_field_tests_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :string_field, :text_field, :integer_field, :float_field, :decimal_field, :datetime_field, :timestamp_field, :time_field, :date_field, :boolean_field, :array_field, :hash_field, :created_at, :updated_at, :format, :restricted_field, :as => :custom_role
- attr_accessible :comment_attributes, :nested_field_tests_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :string_field, :text_field, :integer_field, :float_field, :decimal_field, :datetime_field, :timestamp_field, :time_field, :date_field, :boolean_field, :array_field, :hash_field, :created_at, :updated_at, :format, :protected_field, :as => :extra_safe_role
+ attr_accessible :comment_attributes, :nested_field_tests_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :carrierwave_asset, :carrierwave_asset_cache, :remove_carrierwave_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :string_field, :text_field, :integer_field, :float_field, :decimal_field, :datetime_field, :timestamp_field, :time_field, :date_field, :boolean_field, :array_field, :hash_field, :created_at, :updated_at, :format
+ attr_accessible :comment_attributes, :nested_field_tests_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :carrierwave_asset, :carrierwave_asset_cache, :remove_carrierwave_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :string_field, :text_field, :integer_field, :float_field, :decimal_field, :datetime_field, :timestamp_field, :time_field, :date_field, :boolean_field, :array_field, :hash_field, :created_at, :updated_at, :format, :restricted_field, :as => :custom_role
+ attr_accessible :comment_attributes, :nested_field_tests_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :carrierwave_asset, :carrierwave_asset_cache, :remove_carrierwave_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :string_field, :text_field, :integer_field, :float_field, :decimal_field, :datetime_field, :timestamp_field, :time_field, :date_field, :boolean_field, :array_field, :hash_field, :created_at, :updated_at, :format, :protected_field, :as => :extra_safe_role
has_many :nested_field_tests, :dependent => :destroy, :inverse_of => :field_test
accepts_nested_attributes_for :nested_field_tests, :allow_destroy => true
@@ -43,6 +43,7 @@ class FieldTest
field :dragonfly_asset_name
field :dragonfly_asset_uid
image_accessor :dragonfly_asset
+ mount_uploader :carrierwave_asset, CarrierwaveUploader
validates :short_text, :length => {:maximum => 255}
end
View
6 spec/unit/config/fields/base_spec.rb
@@ -44,7 +44,7 @@ class CommentReversed < Tableless
end
end
- context 'of a Carrierwave installation', :active_record => true do
+ context 'of a Carrierwave installation' do
it 'should be the parent field itself' do
RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :carrierwave_asset }.children_fields.should == [:carrierwave_asset]
RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :carrierwave_asset }.hidden?.should be_false
@@ -184,7 +184,7 @@ class CommentReversed < Tableless
RailsAdmin.config(FieldTest).fields.find{|f| f.name == :dragonfly_asset}.searchable_columns.map{|c| c[:column]}.should == ["field_tests.dragonfly_asset_name"]
end
- it 'of carrierwave should find the underlying column on the base table', :active_record => true do
+ it 'of carrierwave should find the underlying column on the base table' do
RailsAdmin.config(FieldTest).fields.find{|f| f.name == :carrierwave_asset}.searchable_columns.map{|c| c[:column]}.should == ["field_tests.carrierwave_asset"]
end
end
@@ -215,7 +215,7 @@ class CommentReversed < Tableless
RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :dragonfly_asset }.sortable.should == :dragonfly_asset_name
end
- it 'of carrierwave should target the first children field', :active_record => true do
+ it 'of carrierwave should target the first children field' do
RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :carrierwave_asset }.searchable.should == :carrierwave_asset
RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :carrierwave_asset }.sortable.should == :carrierwave_asset
end

0 comments on commit c6866b1

Please sign in to comment.