Commit ee2edad69f87449bfe7cdcdc9dad9338e05a1317
1 parent
69ca0d2b
Exists in
rails5
rails5: fix article test
Showing
4 changed files
with
12 additions
and
9 deletions
Show diff stats
app/models/application_record.rb
| ... | ... | @@ -2,6 +2,8 @@ class ApplicationRecord < ActiveRecord::Base |
| 2 | 2 | |
| 3 | 3 | self.abstract_class = true |
| 4 | 4 | |
| 5 | + extend PostgresqlAttachmentFu::ClassMethods | |
| 6 | + | |
| 5 | 7 | def self.postgresql? |
| 6 | 8 | ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' |
| 7 | 9 | end |
| ... | ... | @@ -25,7 +27,7 @@ class ApplicationRecord < ActiveRecord::Base |
| 25 | 27 | alias :meta_cache_key :cache_key |
| 26 | 28 | def cache_key |
| 27 | 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 | 31 | key.join('/') |
| 30 | 32 | end |
| 31 | 33 | ... | ... |
db/migrate/069_add_enviroment_id_to_role.rb
| 1 | 1 | class Role < ApplicationRecord |
| 2 | +end | |
| 2 | 3 | class RoleWithEnvironment < ApplicationRecord |
| 3 | 4 | self.table_name = 'roles' |
| 4 | 5 | belongs_to :environment |
| ... | ... | @@ -18,10 +19,10 @@ class AddEnviromentIdToRole < ActiveRecord::Migration |
| 18 | 19 | re = RoleWithEnvironment.new(role.attributes) |
| 19 | 20 | re.environment = env |
| 20 | 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 | 26 | end |
| 26 | 27 | end |
| 27 | 28 | roles.each(&:destroy) | ... | ... |
lib/delayed_attachment_fu.rb
lib/postgresql_attachment_fu.rb
| ... | ... | @@ -2,18 +2,16 @@ module PostgresqlAttachmentFu |
| 2 | 2 | |
| 3 | 3 | module ClassMethods |
| 4 | 4 | def postgresql_attachment_fu |
| 5 | - send :include, InstanceMethods | |
| 5 | + include InstanceMethods | |
| 6 | 6 | end |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | module InstanceMethods |
| 10 | 10 | def full_filename(thumbnail = nil) |
| 11 | 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 | 13 | Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s |
| 14 | 14 | end |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 17 | end |
| 18 | - | |
| 19 | -ActiveRecord::Base.send(:extend, PostgresqlAttachmentFu::ClassMethods) | ... | ... |