Guest User

Untitled

a guest
May 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.56 KB | None | 0 0
  1. diff --git a/lib/ubiquo_media/media_selector/active_record.rb b/lib/ubiquo_media/media_selector/active_record.rb
  2. index 040502c..f5fd5d6 100644
  3. --- a/lib/ubiquo_media/media_selector/active_record.rb
  4. +++ b/lib/ubiquo_media/media_selector/active_record.rb
  5. @@ -89,9 +89,19 @@ module UbiquoMedia
  6.          
  7.            # WARNING: asset_types are cached since you define media_attachment on a model!
  8.            # A server restart could be required when adding new asset_types
  9. -          options[:types] = AssetType.get_by_keys(options[:types])
  10. +          # It's a lambda to be initialized on demand and not on boot time, to avoid
  11. +          # some issues with empty asset_type table on tests.
  12. +          initialize_types = lambda do
  13. +            unless options[:types].is_a?( Array ) && options[:types].first.is_a?( AssetType )
  14. +              options[:types] = AssetType.get_by_keys(options[:types])
  15. +            end
  16. +          end
  17.            
  18.            proc = Proc.new do
  19. +            def initialize
  20. +              initialize_types.call
  21. +              super
  22. +            end
  23.  
  24.              def is_full?
  25.                return false if self.options[:size].to_sym == :many
  26. @@ -180,6 +190,7 @@ module UbiquoMedia
  27.            end
  28.            
  29.            define_method "valid_asset_types_in_#{field}" do
  30. +            initialize_types.call
  31.              invalid = send("#{field}_current_asset_relations").to_a.detect do |asset|
  32.                # current_asset_relations can return assets or asset_relations
  33.                asset = asset.respond_to?( :asset ) ? asset.asset : asset
Add Comment
Please, Sign In to add comment