diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 06e635a..06d52d2 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -2,6 +2,8 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + extend PostgresqlAttachmentFu::ClassMethods + def self.postgresql? ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' end @@ -25,7 +27,7 @@ class ApplicationRecord < ActiveRecord::Base alias :meta_cache_key :cache_key def cache_key key = [Noosfero::VERSION, meta_cache_key] - key.unshift(ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? + key.unshift(ActiveRecord::Base.connection.schema_search_path) if ApplicationRecord.postgresql? key.join('/') end diff --git a/db/migrate/069_add_enviroment_id_to_role.rb b/db/migrate/069_add_enviroment_id_to_role.rb index 4d360d6..bdde447 100644 --- a/db/migrate/069_add_enviroment_id_to_role.rb +++ b/db/migrate/069_add_enviroment_id_to_role.rb @@ -1,4 +1,5 @@ class Role < ApplicationRecord +end class RoleWithEnvironment < ApplicationRecord self.table_name = 'roles' belongs_to :environment @@ -18,10 +19,10 @@ class AddEnviromentIdToRole < ActiveRecord::Migration re = RoleWithEnvironment.new(role.attributes) re.environment = env re.save - RoleAssignment.where(role_id: role.id).select{|ra| ra.resource && (ra.resource.kind_of?(Profile) ? ra.resource.environment_id : ra.resource.id) == env.id }.each do |ra| - ra.role_id = re.id - ra.save - end + RoleAssignment \ + .where(role_id: role.id) + .select{ |ra| ra.resource && (ra.resource.kind_of?(Profile) ? ra.resource.environment_id : ra.resource.id) == env.id } + .each{ |ra| ra.role_id = re.id; ra.save } end end roles.each(&:destroy) diff --git a/lib/delayed_attachment_fu.rb b/lib/delayed_attachment_fu.rb index 0848f7c..d628d5f 100644 --- a/lib/delayed_attachment_fu.rb +++ b/lib/delayed_attachment_fu.rb @@ -1,3 +1,5 @@ +require 'create_thumbnails_job' + module DelayedAttachmentFu module ClassMethods diff --git a/lib/postgresql_attachment_fu.rb b/lib/postgresql_attachment_fu.rb index 9d7ec6d..39ddcb2 100644 --- a/lib/postgresql_attachment_fu.rb +++ b/lib/postgresql_attachment_fu.rb @@ -2,18 +2,16 @@ module PostgresqlAttachmentFu module ClassMethods def postgresql_attachment_fu - send :include, InstanceMethods + include InstanceMethods end end module InstanceMethods def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s - file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? and Noosfero::MultiTenancy.on? + file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if ApplicationRecord.postgresql? and Noosfero::MultiTenancy.on? Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s end end end - -ActiveRecord::Base.send(:extend, PostgresqlAttachmentFu::ClassMethods) -- libgit2 0.21.2