Commit ee2edad69f87449bfe7cdcdc9dad9338e05a1317

Authored by Braulio Bhavamitra
1 parent 69ca0d2b
Exists in rails5

rails5: fix article test

app/models/application_record.rb
@@ -2,6 +2,8 @@ class ApplicationRecord < ActiveRecord::Base @@ -2,6 +2,8 @@ class ApplicationRecord < ActiveRecord::Base
2 2
3 self.abstract_class = true 3 self.abstract_class = true
4 4
  5 + extend PostgresqlAttachmentFu::ClassMethods
  6 +
5 def self.postgresql? 7 def self.postgresql?
6 ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' 8 ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
7 end 9 end
@@ -25,7 +27,7 @@ class ApplicationRecord < ActiveRecord::Base @@ -25,7 +27,7 @@ class ApplicationRecord < ActiveRecord::Base
25 alias :meta_cache_key :cache_key 27 alias :meta_cache_key :cache_key
26 def cache_key 28 def cache_key
27 key = [Noosfero::VERSION, meta_cache_key] 29 key = [Noosfero::VERSION, meta_cache_key]
28 - key.unshift(ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? 30 + key.unshift(ActiveRecord::Base.connection.schema_search_path) if ApplicationRecord.postgresql?
29 key.join('/') 31 key.join('/')
30 end 32 end
31 33
db/migrate/069_add_enviroment_id_to_role.rb
1 class Role < ApplicationRecord 1 class Role < ApplicationRecord
  2 +end
2 class RoleWithEnvironment < ApplicationRecord 3 class RoleWithEnvironment < ApplicationRecord
3 self.table_name = 'roles' 4 self.table_name = 'roles'
4 belongs_to :environment 5 belongs_to :environment
@@ -18,10 +19,10 @@ class AddEnviromentIdToRole &lt; ActiveRecord::Migration @@ -18,10 +19,10 @@ class AddEnviromentIdToRole &lt; ActiveRecord::Migration
18 re = RoleWithEnvironment.new(role.attributes) 19 re = RoleWithEnvironment.new(role.attributes)
19 re.environment = env 20 re.environment = env
20 re.save 21 re.save
21 - 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|  
22 - ra.role_id = re.id  
23 - ra.save  
24 - end 22 + RoleAssignment \
  23 + .where(role_id: role.id)
  24 + .select{ |ra| ra.resource && (ra.resource.kind_of?(Profile) ? ra.resource.environment_id : ra.resource.id) == env.id }
  25 + .each{ |ra| ra.role_id = re.id; ra.save }
25 end 26 end
26 end 27 end
27 roles.each(&:destroy) 28 roles.each(&:destroy)
lib/delayed_attachment_fu.rb
  1 +require 'create_thumbnails_job'
  2 +
1 module DelayedAttachmentFu 3 module DelayedAttachmentFu
2 4
3 module ClassMethods 5 module ClassMethods
lib/postgresql_attachment_fu.rb
@@ -2,18 +2,16 @@ module PostgresqlAttachmentFu @@ -2,18 +2,16 @@ module PostgresqlAttachmentFu
2 2
3 module ClassMethods 3 module ClassMethods
4 def postgresql_attachment_fu 4 def postgresql_attachment_fu
5 - send :include, InstanceMethods 5 + include InstanceMethods
6 end 6 end
7 end 7 end
8 8
9 module InstanceMethods 9 module InstanceMethods
10 def full_filename(thumbnail = nil) 10 def full_filename(thumbnail = nil)
11 file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s 11 file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s
12 - file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? and Noosfero::MultiTenancy.on? 12 + file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if ApplicationRecord.postgresql? and Noosfero::MultiTenancy.on?
13 Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s 13 Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s
14 end 14 end
15 end 15 end
16 16
17 end 17 end
18 -  
19 -ActiveRecord::Base.send(:extend, PostgresqlAttachmentFu::ClassMethods)