<%= _('%s Permissions:' % key) %>
- <% ActiveRecord::Base::PERMISSIONS[key].keys.each do |p| %>
+ <% ApplicationRecord::PERMISSIONS[key].keys.each do |p| %>
<%= check_box_tag("role[permissions][]", p, role.has_permission?(p), { :id => p }) %>
<%= content_tag(:label, permission_name(p), { :for => p }) %>
<% end %>
diff --git a/app/views/role/_form.html.erb b/app/views/role/_form.html.erb
index bfdb946..02b90ee 100644
--- a/app/views/role/_form.html.erb
+++ b/app/views/role/_form.html.erb
@@ -9,7 +9,7 @@
<% permissions.each do |key| %>
<%= _('%s Permissions:' % key) %>
- <% ActiveRecord::Base::PERMISSIONS[key].keys.each do |p| %>
+ <% ApplicationRecord::PERMISSIONS[key].keys.each do |p| %>
<%= check_box_tag("role[permissions][]", p, role.has_permission?(p), { :id => p }) %>
<%= content_tag(:label, permission_name(p), { :for => p }) %>
<% end %>
diff --git a/config/initializers/active_record_extensions.rb b/config/initializers/active_record_extensions.rb
index 9004fb9..bc8eea3 100644
--- a/config/initializers/active_record_extensions.rb
+++ b/config/initializers/active_record_extensions.rb
@@ -14,4 +14,5 @@ module ActiveRecordExtension
end
end
end
-ActiveRecord::Base.send(:include, ActiveRecordExtension)
+
+ApplicationRecord.send :include, ActiveRecordExtension
diff --git a/db/migrate/033_destroy_organization_and_person_infos.rb b/db/migrate/033_destroy_organization_and_person_infos.rb
index dbd29e8..d071aa8 100644
--- a/db/migrate/033_destroy_organization_and_person_infos.rb
+++ b/db/migrate/033_destroy_organization_and_person_infos.rb
@@ -1,7 +1,7 @@
class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration
def self.up
Person.find_each do |i|
- info = ActiveRecord::Base.connection.select_one("select * from person_infos where person_id = #{i.id}")
+ info = ApplicationRecord.connection.select_one("select * from person_infos where person_id = #{i.id}")
i.name = info["name"] unless info["name"].nil?
i.address = info["address"] unless info["address"].nil?
[ "photo", "contact_information", "birth_date", "sex", "city", "state", "country" ].each do |field|
@@ -12,7 +12,7 @@ class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration
drop_table :person_infos
Organization.find_each do |i|
- info = ActiveRecord::Base.connection.select_one("select * from organization_infos where organization_id = #{i.id}")
+ info = ApplicationRecord.connection.select_one("select * from organization_infos where organization_id = #{i.id}")
[ "contact_person", "contact_email", "acronym", "foundation_year", "legal_form", "economic_activity", "management_information", "validated" ].each do |field|
i.send("#{field}=", info[field])
end
diff --git a/db/migrate/059_add_birth_date_to_person.rb b/db/migrate/059_add_birth_date_to_person.rb
index 57d615f..0c5234a 100644
--- a/db/migrate/059_add_birth_date_to_person.rb
+++ b/db/migrate/059_add_birth_date_to_person.rb
@@ -29,7 +29,7 @@ class AddBirthDateToPerson < ActiveRecord::Migration
end
end
- class Person < ActiveRecord::Base
+ class Person < ApplicationRecord
self.table_name = 'profiles'
serialize :data, Hash
end
diff --git a/db/migrate/069_add_enviroment_id_to_role.rb b/db/migrate/069_add_enviroment_id_to_role.rb
index 1989858..4d360d6 100644
--- a/db/migrate/069_add_enviroment_id_to_role.rb
+++ b/db/migrate/069_add_enviroment_id_to_role.rb
@@ -1,9 +1,9 @@
-class Role < ActiveRecord::Base; end
-class RoleWithEnvironment < ActiveRecord::Base
+class Role < ApplicationRecord
+class RoleWithEnvironment < ApplicationRecord
self.table_name = 'roles'
belongs_to :environment
end
-class RoleAssignment < ActiveRecord::Base
+class RoleAssignment < ApplicationRecord
belongs_to :accessor, :polymorphic => true
belongs_to :resource, :polymorphic => true
end
diff --git a/db/migrate/074_move_title_to_name_from_blogs.rb b/db/migrate/074_move_title_to_name_from_blogs.rb
index 17d5f54..05d1d77 100644
--- a/db/migrate/074_move_title_to_name_from_blogs.rb
+++ b/db/migrate/074_move_title_to_name_from_blogs.rb
@@ -2,7 +2,7 @@ class MoveTitleToNameFromBlogs < ActiveRecord::Migration
def self.up
select_all("select id, setting from articles where type = 'Blog' and name != 'Blog'").each do |blog|
title = YAML.load(blog['setting'])[:title]
- assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:name => title)
+ assignments = ApplicationRecord.sanitize_sql_for_assignment(:name => title)
update("update articles set %s where id = %d" % [assignments, blog['id']] )
end
end
diff --git a/db/migrate/20100921121528_add_is_image_to_articles.rb b/db/migrate/20100921121528_add_is_image_to_articles.rb
index d571435..3eb80a0 100644
--- a/db/migrate/20100921121528_add_is_image_to_articles.rb
+++ b/db/migrate/20100921121528_add_is_image_to_articles.rb
@@ -3,7 +3,7 @@ class AddIsImageToArticles < ActiveRecord::Migration
add_column :articles, :is_image, :boolean, :default => false
add_column :article_versions, :is_image, :boolean, :default => false
- execute ActiveRecord::Base.sanitize_sql(["update articles set is_image = ? where articles.content_type like 'image/%'", true])
+ execute ApplicationRecord.sanitize_sql(["update articles set is_image = ? where articles.content_type like 'image/%'", true])
end
def self.down
diff --git a/db/migrate/20101129234429_convert_folders_to_galleries.rb b/db/migrate/20101129234429_convert_folders_to_galleries.rb
index 4101e6d..fd21944 100644
--- a/db/migrate/20101129234429_convert_folders_to_galleries.rb
+++ b/db/migrate/20101129234429_convert_folders_to_galleries.rb
@@ -10,7 +10,7 @@ class ConvertFoldersToGalleries < ActiveRecord::Migration
select_all("select id, setting from articles where type = 'Gallery'").each do |folder|
settings = YAML.load(folder['setting'] || {}.to_yaml)
settings[:view_as] = 'image_gallery'
- assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml)
+ assignments = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml)
update("update articles set %s, type = 'Folder' where id = %d" % [assignments, folder['id']])
end
end
diff --git a/db/migrate/20101202205446_remove_published_articles.rb b/db/migrate/20101202205446_remove_published_articles.rb
index 9b2d766..2708827 100644
--- a/db/migrate/20101202205446_remove_published_articles.rb
+++ b/db/migrate/20101202205446_remove_published_articles.rb
@@ -3,7 +3,7 @@ class RemovePublishedArticles < ActiveRecord::Migration
select_all("SELECT * from articles WHERE type = 'PublishedArticle'").each do |published|
reference = select_one('select * from articles where id = %d' % published['reference_article_id'])
if reference
- execute(ActiveRecord::Base.sanitize_sql(["UPDATE articles SET type = ?, abstract = ?, body = ? WHERE articles.id = ?", reference['type'], reference['abstract'], reference['body'], published['id']]))
+ execute(ApplicationRecord.sanitize_sql(["UPDATE articles SET type = ?, abstract = ?, body = ? WHERE articles.id = ?", reference['type'], reference['abstract'], reference['body'], published['id']]))
else
execute("DELETE from articles where articles.id = #{published['id']}")
end
diff --git a/db/migrate/20101205034144_add_language_and_translation_of_id_to_article.rb b/db/migrate/20101205034144_add_language_and_translation_of_id_to_article.rb
index 7af373a..b46dde0 100644
--- a/db/migrate/20101205034144_add_language_and_translation_of_id_to_article.rb
+++ b/db/migrate/20101205034144_add_language_and_translation_of_id_to_article.rb
@@ -11,7 +11,7 @@ class AddLanguageAndTranslationOfIdToArticle < ActiveRecord::Migration
select_all("select id, setting from articles where type = 'Blog'").each do |blog|
settings = YAML.load(blog['setting'] || {}.to_yaml)
settings[:display_posts_in_current_language] = true
- assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml)
+ assignments = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml)
update("update articles set %s where id = %d" % [assignments, blog['id']])
end
diff --git a/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb b/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb
index df0c93b..1c2d645 100644
--- a/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb
+++ b/db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb
@@ -15,7 +15,7 @@ class RenameImagesPathOnTrackedActions < ActiveRecord::Migration
end
params[param_name] = paths
- execute(ActiveRecord::Base.sanitize_sql(["UPDATE action_tracker SET params = ? WHERE id = ?", params.to_yaml, tracker['id']]))
+ execute(ApplicationRecord.sanitize_sql(["UPDATE action_tracker SET params = ? WHERE id = ?", params.to_yaml, tracker['id']]))
end
end
diff --git a/db/migrate/20110215153624_move_data_serialized_hash_to_setting_field_for_articles.rb b/db/migrate/20110215153624_move_data_serialized_hash_to_setting_field_for_articles.rb
index e53cf6f..6e80ab0 100644
--- a/db/migrate/20110215153624_move_data_serialized_hash_to_setting_field_for_articles.rb
+++ b/db/migrate/20110215153624_move_data_serialized_hash_to_setting_field_for_articles.rb
@@ -12,9 +12,9 @@ class MoveDataSerializedHashToSettingFieldForArticles < ActiveRecord::Migration
end
if body.kind_of?(Hash)
settings = article.setting.merge(body)
- body = ActiveRecord::Base.sanitize_sql_for_assignment(:body => settings[:description])
+ body = ApplicationRecord.sanitize_sql_for_assignment(:body => settings[:description])
update("UPDATE articles set %s WHERE id = %d" % [body, article.id])
- setting = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml)
+ setting = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml)
update("UPDATE articles set %s WHERE id = %d" % [setting, article.id])
end
end
diff --git a/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb b/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb
index 99a4506..5aa6a84 100644
--- a/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb
+++ b/db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb
@@ -11,9 +11,9 @@ class MoveDataSerializedHashToSettingFieldForEvents < ActiveRecord::Migration
end
if body.kind_of?(Hash)
settings = article.setting.merge(body)
- body = ActiveRecord::Base.sanitize_sql_for_assignment(:body => settings[:description])
+ body = ApplicationRecord.sanitize_sql_for_assignment(:body => settings[:description])
update("UPDATE articles set %s WHERE id = %d" % [body, article.id])
- setting = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml)
+ setting = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml)
update("UPDATE articles set %s WHERE id = %d" % [setting, article.id])
end
end
diff --git a/db/migrate/20110706171330_fix_misunderstood_script_filename.rb b/db/migrate/20110706171330_fix_misunderstood_script_filename.rb
index 78460d3..92d642b 100644
--- a/db/migrate/20110706171330_fix_misunderstood_script_filename.rb
+++ b/db/migrate/20110706171330_fix_misunderstood_script_filename.rb
@@ -2,7 +2,7 @@
# from the migration fall on a loop and breaks the migration. Both them are
# related to alias_method_chain, probably there is a problem with this kind of
# alias on the migration level.
-class Article < ActiveRecord::Base
+class Article < ApplicationRecord
def sanitize_tag_list
end
end
diff --git a/db/migrate/20110824192153_add_activated_at_to_users.rb b/db/migrate/20110824192153_add_activated_at_to_users.rb
index 764a814..380af94 100644
--- a/db/migrate/20110824192153_add_activated_at_to_users.rb
+++ b/db/migrate/20110824192153_add_activated_at_to_users.rb
@@ -2,7 +2,7 @@ class AddActivatedAtToUsers < ActiveRecord::Migration
def self.up
add_column :users, :activation_code, :string, :limit => 40
add_column :users, :activated_at, :datetime
- if ActiveRecord::Base.connection.adapter_name == 'SQLite'
+ if ApplicationRecord.connection.adapter_name == 'SQLite'
execute "update users set activated_at = datetime();"
else
execute "update users set activated_at = now();"
diff --git a/db/migrate/20140724134601_fix_yaml_encoding.rb b/db/migrate/20140724134601_fix_yaml_encoding.rb
index 53b3ec1..6290d47 100644
--- a/db/migrate/20140724134601_fix_yaml_encoding.rb
+++ b/db/migrate/20140724134601_fix_yaml_encoding.rb
@@ -1,6 +1,6 @@
class FixYamlEncoding < ActiveRecord::Migration
def self.up
- ActiveRecord::Base.transaction do
+ ApplicationRecord.transaction do
fix_encoding(Environment, 'settings')
fix_encoding(Profile, 'data')
fix_encoding(Product, 'data')
diff --git a/db/migrate/20150216213259_create_profile_activity.rb b/db/migrate/20150216213259_create_profile_activity.rb
index 5ff6f11..b58271e 100644
--- a/db/migrate/20150216213259_create_profile_activity.rb
+++ b/db/migrate/20150216213259_create_profile_activity.rb
@@ -1,6 +1,6 @@
class CreateProfileActivity < ActiveRecord::Migration
def up
- ActiveRecord::Base.transaction do
+ ApplicationRecord.transaction do
create_table :profile_activities do |t|
t.integer :profile_id
t.integer :activity_id
diff --git a/lib/activities_counter_cache_job.rb b/lib/activities_counter_cache_job.rb
index 0955cfb..09f3adf 100644
--- a/lib/activities_counter_cache_job.rb
+++ b/lib/activities_counter_cache_job.rb
@@ -1,12 +1,12 @@
class ActivitiesCounterCacheJob
def perform
- person_activities_counts = ActiveRecord::Base.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id WHERE (action_tracker.created_at >= #{ActiveRecord::Base.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Person' ) ) GROUP BY profiles.id;")
- organization_activities_counts = ActiveRecord::Base.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id WHERE (action_tracker.created_at >= #{ActiveRecord::Base.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Community' OR profiles.type = 'Enterprise' OR profiles.type = 'Organization' ) ) GROUP BY profiles.id;")
+ person_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Person' ) ) GROUP BY profiles.id;")
+ organization_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Community' OR profiles.type = 'Enterprise' OR profiles.type = 'Organization' ) ) GROUP BY profiles.id;")
activities_counts = person_activities_counts.entries + organization_activities_counts.entries
activities_counts.each do |count|
- update_sql = ActiveRecord::Base.__send__(:sanitize_sql, ["UPDATE profiles SET activities_count=? WHERE profiles.id=?;", count['count'].to_i, count['id'] ], '')
- ActiveRecord::Base.connection.execute(update_sql)
+ update_sql = ApplicationRecord.__send__(:sanitize_sql, ["UPDATE profiles SET activities_count=? WHERE profiles.id=?;", count['count'].to_i, count['id'] ], '')
+ ApplicationRecord.connection.execute(update_sql)
end
Delayed::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3, :run_at => 1.day.from_now})
end
diff --git a/lib/acts_as_customizable.rb b/lib/acts_as_customizable.rb
index 5e73b91..9016bbb 100644
--- a/lib/acts_as_customizable.rb
+++ b/lib/acts_as_customizable.rb
@@ -122,4 +122,4 @@ module Customizable
end
end
-ActiveRecord::Base.send(:include, Customizable)
+ApplicationRecord.send :include, Customizable
diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb
index 919bf91..11163a7 100644
--- a/lib/acts_as_filesystem.rb
+++ b/lib/acts_as_filesystem.rb
@@ -33,7 +33,7 @@ module ActsAsFileSystem
module ClassMethods
def build_ancestry(parent_id = nil, ancestry = '')
- ActiveRecord::Base.transaction do
+ ApplicationRecord.transaction do
self.base_class.where(parent_id: parent_id).each do |node|
node.update_column :ancestry, ancestry
@@ -263,5 +263,5 @@ module ActsAsFileSystem
end
end
-ActiveRecord::Base.extend ActsAsFileSystem::ActsMethods
+ApplicationRecord.extend ActsAsFileSystem::ActsMethods
diff --git a/lib/acts_as_having_boxes.rb b/lib/acts_as_having_boxes.rb
index c6d1383..319c7a1 100644
--- a/lib/acts_as_having_boxes.rb
+++ b/lib/acts_as_having_boxes.rb
@@ -35,4 +35,4 @@ module ActsAsHavingBoxes
end
-ActiveRecord::Base.extend(ActsAsHavingBoxes::ClassMethods)
+ApplicationRecord.extend ActsAsHavingBoxes::ClassMethods
diff --git a/lib/acts_as_having_image.rb b/lib/acts_as_having_image.rb
index b62af0c..ba89d42 100644
--- a/lib/acts_as_having_image.rb
+++ b/lib/acts_as_having_image.rb
@@ -23,4 +23,5 @@ module ActsAsHavingImage
end
-ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
+ApplicationRecord.extend ActsAsHavingImage::ClassMethods
+
diff --git a/lib/acts_as_having_posts.rb b/lib/acts_as_having_posts.rb
index c8c3fc3..2d51c0f 100644
--- a/lib/acts_as_having_posts.rb
+++ b/lib/acts_as_having_posts.rb
@@ -47,4 +47,5 @@ module ActsAsHavingPosts
end
-ActiveRecord::Base.extend(ActsAsHavingPosts::ClassMethods)
+ApplicationRecord.extend ActsAsHavingPosts::ClassMethods
+
diff --git a/lib/acts_as_having_settings.rb b/lib/acts_as_having_settings.rb
index 2ea18f1..dc22d59 100644
--- a/lib/acts_as_having_settings.rb
+++ b/lib/acts_as_having_settings.rb
@@ -87,4 +87,5 @@ module ActsAsHavingSettings
end
-ActiveRecord::Base.send(:extend, ActsAsHavingSettings::ClassMethods)
+ApplicationRecord.extend ActsAsHavingSettings::ClassMethods
+
diff --git a/lib/code_numbering.rb b/lib/code_numbering.rb
index 843cc33..b980a59 100644
--- a/lib/code_numbering.rb
+++ b/lib/code_numbering.rb
@@ -55,4 +55,4 @@ module CodeNumbering
end
end
-ActiveRecord::Base.extend CodeNumbering::ClassMethods
+ApplicationRecord.extend CodeNumbering::ClassMethods
diff --git a/lib/delayed_attachment_fu.rb b/lib/delayed_attachment_fu.rb
index 0848f7c..fc849bd 100644
--- a/lib/delayed_attachment_fu.rb
+++ b/lib/delayed_attachment_fu.rb
@@ -52,4 +52,5 @@ module DelayedAttachmentFu
end
end
-ActiveRecord::Base.send(:extend, DelayedAttachmentFu::ClassMethods)
+ApplicationRecord.extend DelayedAttachmentFu::ClassMethods
+
diff --git a/lib/noosfero/core_ext.rb b/lib/noosfero/core_ext.rb
index a935fa9..f9470c0 100644
--- a/lib/noosfero/core_ext.rb
+++ b/lib/noosfero/core_ext.rb
@@ -1,5 +1,5 @@
require 'noosfero/core_ext/string'
require 'noosfero/core_ext/integer'
-require 'noosfero/core_ext/active_record'
+require 'noosfero/core_ext/active_record/calculations'
require 'noosfero/core_ext/active_record/reflection'
diff --git a/lib/noosfero/core_ext/active_record.rb b/lib/noosfero/core_ext/active_record.rb
deleted file mode 100644
index 4370861..0000000
--- a/lib/noosfero/core_ext/active_record.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require 'active_record'
-
-class ActiveRecord::Base
-
- def self.postgresql?
- ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
- end
-
- # an ActionView instance for rendering views on models
- def self.action_view
- @action_view ||= begin
- view_paths = ::ActionController::Base.view_paths
- action_view = ::ActionView::Base.new view_paths
- # for using Noosfero helpers inside render calls
- action_view.extend ::ApplicationHelper
- action_view
- end
- end
-
- # default value needed for the above ActionView
- def to_partial_path
- self.class.name.underscore
- end
-
- 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.join('/')
- end
-
- def self.like_search(query, options={})
- if defined?(self::SEARCHABLE_FIELDS) || options[:fields].present?
- fields_per_table = {}
- fields_per_table[table_name] = (options[:fields].present? ? options[:fields] : self::SEARCHABLE_FIELDS.keys.map(&:to_s)) & column_names
-
- if options[:joins].present?
- join_asset = options[:joins].to_s.classify.constantize
- if defined?(join_asset::SEARCHABLE_FIELDS) || options[:fields].present?
- fields_per_table[join_asset.table_name] = (options[:fields].present? ? options[:fields] : join_asset::SEARCHABLE_FIELDS.keys.map(&:to_s)) & join_asset.column_names
- end
- end
-
- query = query.downcase.strip
- fields_per_table.delete_if { |table,fields| fields.blank? }
- conditions = fields_per_table.map do |table,fields|
- fields.map do |field|
- "lower(#{table}.#{field}) LIKE '%#{query}%'"
- end.join(' OR ')
- end.join(' OR ')
-
- if options[:joins].present?
- joins(options[:joins]).where(conditions)
- else
- where(conditions)
- end
-
- else
- raise "No searchable fields defined for #{self.name}"
- end
- end
-
-end
-
-ActiveRecord::Calculations.class_eval do
- def count_with_distinct column_name=self.primary_key
- if column_name
- distinct.count_without_distinct column_name
- else
- count_without_distinct
- end
- end
- alias_method_chain :count, :distinct
-end
diff --git a/lib/noosfero/core_ext/active_record/calculations.rb b/lib/noosfero/core_ext/active_record/calculations.rb
new file mode 100644
index 0000000..cdaf434
--- /dev/null
+++ b/lib/noosfero/core_ext/active_record/calculations.rb
@@ -0,0 +1,10 @@
+ActiveRecord::Calculations.class_eval do
+ def count_with_distinct column_name=self.primary_key
+ if column_name
+ distinct.count_without_distinct column_name
+ else
+ count_without_distinct
+ end
+ end
+ alias_method_chain :count, :distinct
+end
diff --git a/lib/noosfero/multi_tenancy.rb b/lib/noosfero/multi_tenancy.rb
index 823eaa8..f0f8c2b 100644
--- a/lib/noosfero/multi_tenancy.rb
+++ b/lib/noosfero/multi_tenancy.rb
@@ -12,12 +12,12 @@ module Noosfero
def self.db_by_host=(host)
if host != @db_by_host
@db_by_host = host
- ActiveRecord::Base.connection.schema_search_path = self.mapping[host]
+ ApplicationRecord.connection.schema_search_path = self.mapping[host]
end
end
def self.setup!(host)
- if Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?
+ if Noosfero::MultiTenancy.on? and ApplicationRecord.postgresql?
Noosfero::MultiTenancy.db_by_host = host
end
end
diff --git a/lib/noosfero/unicorn.rb b/lib/noosfero/unicorn.rb
index 045340a..f740e82 100644
--- a/lib/noosfero/unicorn.rb
+++ b/lib/noosfero/unicorn.rb
@@ -7,11 +7,11 @@ GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
- ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
+ ApplicationRecord.connection.disconnect! if defined?(ApplicationRecord)
end
after_fork do |server, worker|
- ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
+ ApplicationRecord.establish_connection if defined?(ApplicationRecord)
end
# load local configuration file, if it exists
diff --git a/lib/postgresql_attachment_fu.rb b/lib/postgresql_attachment_fu.rb
index 9d7ec6d..cf4a4f7 100644
--- a/lib/postgresql_attachment_fu.rb
+++ b/lib/postgresql_attachment_fu.rb
@@ -9,11 +9,12 @@ module PostgresqlAttachmentFu
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, ApplicationRecord.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)
+ApplicationRecord.extend PostgresqlAttachmentFu::ClassMethods
+
diff --git a/lib/split_datetime.rb b/lib/split_datetime.rb
index be184bf..5d27c08 100644
--- a/lib/split_datetime.rb
+++ b/lib/split_datetime.rb
@@ -69,4 +69,5 @@ module SplitDatetime
end
Class.extend SplitDatetime::SplitMethods
-ActiveRecord::Base.extend SplitDatetime::SplitMethods
+ApplicationRecord.extend SplitDatetime::SplitMethods
+
diff --git a/lib/sqlite_extension.rb b/lib/sqlite_extension.rb
index daf1d20..88d795a 100644
--- a/lib/sqlite_extension.rb
+++ b/lib/sqlite_extension.rb
@@ -1,11 +1,11 @@
-if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
+if ApplicationRecord.connection.adapter_name.downcase == 'sqlite'
- database = ActiveRecord::Base.connection.raw_connection
+ database = ApplicationRecord.connection.raw_connection
database.create_function('pow', 2, 1) do |func, base, exponent|
func.set_result(base.to_f ** exponent.to_f)
end
-
+
database.create_function('sqrt', 1, 1) do |func, value|
func.set_result(Math.sqrt(value))
end
@@ -18,8 +18,8 @@ if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
func.set_result(
radius.to_f * Math.acos(
[1,
- Math.cos(lat1.to_f) * Math.cos(long1.to_f) * Math.cos(lat2.to_f) * Math.cos(long2.to_f) +
- Math.cos(lat1.to_f) * Math.sin(long1.to_f) * Math.cos(lat2.to_f) * Math.sin(long2.to_f) +
+ Math.cos(lat1.to_f) * Math.cos(long1.to_f) * Math.cos(lat2.to_f) * Math.cos(long2.to_f) +
+ Math.cos(lat1.to_f) * Math.sin(long1.to_f) * Math.cos(lat2.to_f) * Math.sin(long2.to_f) +
Math.sin(lat1.to_f) * Math.sin(lat2.to_f)
].min
)
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
index c5f7320..59f2bd6 100644
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -115,7 +115,7 @@ end
desc 'Removes emails from database'
task 'restore:remove_emails' => :environment do
- connection = ActiveRecord::Base.connection
+ connection = ApplicationRecord.connection
[
"UPDATE users SET email = concat('user', id, '@localhost.localdomain')",
"UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')",
diff --git a/lib/tasks/multitenancy.rake b/lib/tasks/multitenancy.rake
index af646f4..caad220 100644
--- a/lib/tasks/multitenancy.rake
+++ b/lib/tasks/multitenancy.rake
@@ -1,14 +1,14 @@
namespace :multitenancy do
task :create => :environment do
- db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) }
+ db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) }
cd Rails.root.join('config', 'environments'), :verbose => true
file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}"
(db_envs.map{ |e| e + '.rb' } - file_envs).each { |env| ln_s env.split('_').last, env }
end
task :remove => :environment do
- db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) }
+ db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) }
cd Rails.root.join('config', 'environments'), :verbose => true
file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}"
(file_envs - db_envs.map{ |e| e + '.rb' }).each { |env| safe_unlink env }
@@ -19,7 +19,7 @@ end
namespace :db do
task :migrate_other_environments => :environment do
- envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) }
+ envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) }
envs.each do |e|
puts "*** Migrating #{e}" if Rake.application.options.trace
system "rake db:migrate RAILS_ENV=#{e} SCHEMA=/dev/null"
diff --git a/lib/upload_sanitizer.rb b/lib/upload_sanitizer.rb
index f950b9a..05a45f7 100644
--- a/lib/upload_sanitizer.rb
+++ b/lib/upload_sanitizer.rb
@@ -10,4 +10,4 @@ module UploadSanitizer
end
end
-ActiveRecord::Base.send(:include, UploadSanitizer)
+ApplicationRecord.send :include, UploadSanitizer
diff --git a/plugins/analytics/models/analytics_plugin/page_view.rb b/plugins/analytics/models/analytics_plugin/page_view.rb
index ac9b91d..b4c457f 100644
--- a/plugins/analytics/models/analytics_plugin/page_view.rb
+++ b/plugins/analytics/models/analytics_plugin/page_view.rb
@@ -1,4 +1,4 @@
-class AnalyticsPlugin::PageView < ActiveRecord::Base
+class AnalyticsPlugin::PageView < ApplicationRecord
serialize :data
diff --git a/plugins/analytics/models/analytics_plugin/visit.rb b/plugins/analytics/models/analytics_plugin/visit.rb
index d65f4f7..4935d2f 100644
--- a/plugins/analytics/models/analytics_plugin/visit.rb
+++ b/plugins/analytics/models/analytics_plugin/visit.rb
@@ -1,4 +1,4 @@
-class AnalyticsPlugin::Visit < ActiveRecord::Base
+class AnalyticsPlugin::Visit < ApplicationRecord
attr_accessible *self.column_names
attr_accessible :profile
diff --git a/plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb b/plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb
index b4c16e5..0af19e8 100644
--- a/plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb
+++ b/plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb
@@ -1,4 +1,4 @@
-class CommentClassificationPlugin::CommentLabelUser < ActiveRecord::Base
+class CommentClassificationPlugin::CommentLabelUser < ApplicationRecord
self.table_name = :comment_classification_plugin_comment_label_user
belongs_to :profile
diff --git a/plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb b/plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb
index 1437cfb..e3e4d4e 100644
--- a/plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb
+++ b/plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb
@@ -1,4 +1,4 @@
-class CommentClassificationPlugin::CommentStatusUser < ActiveRecord::Base
+class CommentClassificationPlugin::CommentStatusUser < ApplicationRecord
self.table_name = :comment_classification_plugin_comment_status_user
belongs_to :profile
diff --git a/plugins/comment_classification/lib/comment_classification_plugin/label.rb b/plugins/comment_classification/lib/comment_classification_plugin/label.rb
index 405cfb2..13df143 100644
--- a/plugins/comment_classification/lib/comment_classification_plugin/label.rb
+++ b/plugins/comment_classification/lib/comment_classification_plugin/label.rb
@@ -1,4 +1,4 @@
-class CommentClassificationPlugin::Label < ActiveRecord::Base
+class CommentClassificationPlugin::Label < ApplicationRecord
belongs_to :owner, :polymorphic => true
diff --git a/plugins/comment_classification/lib/comment_classification_plugin/status.rb b/plugins/comment_classification/lib/comment_classification_plugin/status.rb
index 7fa1f5e..f6f1665 100644
--- a/plugins/comment_classification/lib/comment_classification_plugin/status.rb
+++ b/plugins/comment_classification/lib/comment_classification_plugin/status.rb
@@ -1,4 +1,4 @@
-class CommentClassificationPlugin::Status < ActiveRecord::Base
+class CommentClassificationPlugin::Status < ApplicationRecord
belongs_to :owner, :polymorphic => true
diff --git a/plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb b/plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb
index df6a986..acf8e51 100644
--- a/plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb
+++ b/plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb
@@ -1,5 +1,5 @@
class AssociateFieldsToAlternatives < ActiveRecord::Migration
- class CustomFormsPlugin::Field < ActiveRecord::Base
+ class CustomFormsPlugin::Field < ApplicationRecord
self.table_name = :custom_forms_plugin_fields
has_many :alternatives, :class_name => 'CustomFormsPlugin::Alternative'
serialize :choices, Hash
diff --git a/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb b/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb
index 7090ac1..a4c7757 100644
--- a/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb
@@ -1,4 +1,4 @@
-class CustomFormsPlugin::Alternative < ActiveRecord::Base
+class CustomFormsPlugin::Alternative < ApplicationRecord
self.table_name = :custom_forms_plugin_alternatives
validates_presence_of :label
diff --git a/plugins/custom_forms/lib/custom_forms_plugin/answer.rb b/plugins/custom_forms/lib/custom_forms_plugin/answer.rb
index e1c29c4..96a0928 100644
--- a/plugins/custom_forms/lib/custom_forms_plugin/answer.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/answer.rb
@@ -1,4 +1,4 @@
-class CustomFormsPlugin::Answer < ActiveRecord::Base
+class CustomFormsPlugin::Answer < ApplicationRecord
self.table_name = :custom_forms_plugin_answers
belongs_to :field, :class_name => 'CustomFormsPlugin::Field'
belongs_to :submission, :class_name => 'CustomFormsPlugin::Submission'
diff --git a/plugins/custom_forms/lib/custom_forms_plugin/field.rb b/plugins/custom_forms/lib/custom_forms_plugin/field.rb
index 76c9401..ca44188 100644
--- a/plugins/custom_forms/lib/custom_forms_plugin/field.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/field.rb
@@ -1,4 +1,4 @@
-class CustomFormsPlugin::Field < ActiveRecord::Base
+class CustomFormsPlugin::Field < ApplicationRecord
self.table_name = :custom_forms_plugin_fields
validates_presence_of :name
diff --git a/plugins/custom_forms/lib/custom_forms_plugin/form.rb b/plugins/custom_forms/lib/custom_forms_plugin/form.rb
index 1678fa7..406bb05 100644
--- a/plugins/custom_forms/lib/custom_forms_plugin/form.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/form.rb
@@ -1,4 +1,4 @@
-class CustomFormsPlugin::Form < ActiveRecord::Base
+class CustomFormsPlugin::Form < ApplicationRecord
belongs_to :profile
diff --git a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb
index 8cfb5d3..10d112f 100644
--- a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb
@@ -1,4 +1,4 @@
-class CustomFormsPlugin::Submission < ActiveRecord::Base
+class CustomFormsPlugin::Submission < ApplicationRecord
belongs_to :form, :class_name => 'CustomFormsPlugin::Form'
belongs_to :profile
diff --git a/plugins/delivery/db/migrate/20130719132252_create_delivery_plugin_tables.rb b/plugins/delivery/db/migrate/20130719132252_create_delivery_plugin_tables.rb
index d263afc..e12dfc9 100644
--- a/plugins/delivery/db/migrate/20130719132252_create_delivery_plugin_tables.rb
+++ b/plugins/delivery/db/migrate/20130719132252_create_delivery_plugin_tables.rb
@@ -1,7 +1,7 @@
class CreateDeliveryPluginTables < ActiveRecord::Migration
def self.up
# check if distribution plugin already moved tables
- return if ActiveRecord::Base.connection.table_exists? :delivery_plugin_methods
+ return if ApplicationRecord.connection.table_exists? :delivery_plugin_methods
create_table :delivery_plugin_methods do |t|
t.integer :profile_id
diff --git a/plugins/delivery/models/delivery_plugin/method.rb b/plugins/delivery/models/delivery_plugin/method.rb
index 9f03c00..25da744 100644
--- a/plugins/delivery/models/delivery_plugin/method.rb
+++ b/plugins/delivery/models/delivery_plugin/method.rb
@@ -1,4 +1,4 @@
-class DeliveryPlugin::Method < ActiveRecord::Base
+class DeliveryPlugin::Method < ApplicationRecord
Types = ['pickup', 'deliver']
diff --git a/plugins/delivery/models/delivery_plugin/option.rb b/plugins/delivery/models/delivery_plugin/option.rb
index 12998d7..f5f3499 100644
--- a/plugins/delivery/models/delivery_plugin/option.rb
+++ b/plugins/delivery/models/delivery_plugin/option.rb
@@ -1,4 +1,4 @@
-class DeliveryPlugin::Option < ActiveRecord::Base
+class DeliveryPlugin::Option < ApplicationRecord
belongs_to :delivery_method, :class_name => 'DeliveryPlugin::Method'
belongs_to :owner, :polymorphic => true
diff --git a/plugins/driven_signup/models/driven_signup_plugin/auth.rb b/plugins/driven_signup/models/driven_signup_plugin/auth.rb
index 67a7236..e0d2494 100644
--- a/plugins/driven_signup/models/driven_signup_plugin/auth.rb
+++ b/plugins/driven_signup/models/driven_signup_plugin/auth.rb
@@ -1,4 +1,4 @@
-class DrivenSignupPlugin::Auth < ActiveRecord::Base
+class DrivenSignupPlugin::Auth < ApplicationRecord
attr_accessible :name, :token
diff --git a/plugins/environment_notification/lib/environment_notifications_user.rb b/plugins/environment_notification/lib/environment_notifications_user.rb
index 69d63b8..a59a13e 100644
--- a/plugins/environment_notification/lib/environment_notifications_user.rb
+++ b/plugins/environment_notification/lib/environment_notifications_user.rb
@@ -1,4 +1,4 @@
-class EnvironmentNotificationsUser < ActiveRecord::Base
+class EnvironmentNotificationsUser < ApplicationRecord
self.table_name = "environment_notifications_users"
belongs_to :user
diff --git a/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb
index ba39ab0..c6b3f86 100644
--- a/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb
+++ b/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb
@@ -1,4 +1,4 @@
-class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Base
+class EnvironmentNotificationPlugin::EnvironmentNotification < ApplicationRecord
self.table_name = "environment_notifications"
diff --git a/plugins/fb_app/models/fb_app_plugin/page_tab.rb b/plugins/fb_app/models/fb_app_plugin/page_tab.rb
index 3d8c742..fc704ee 100644
--- a/plugins/fb_app/models/fb_app_plugin/page_tab.rb
+++ b/plugins/fb_app/models/fb_app_plugin/page_tab.rb
@@ -1,4 +1,4 @@
-class FbAppPlugin::PageTab < ActiveRecord::Base
+class FbAppPlugin::PageTab < ApplicationRecord
# FIXME: rename table to match model
self.table_name = :fb_app_plugin_page_tab_configs
diff --git a/plugins/foo/lib/foo_plugin/bar.rb b/plugins/foo/lib/foo_plugin/bar.rb
index fe084cf..ebc5cc1 100644
--- a/plugins/foo/lib/foo_plugin/bar.rb
+++ b/plugins/foo/lib/foo_plugin/bar.rb
@@ -1,3 +1,3 @@
-class FooPlugin::Bar < ActiveRecord::Base
+class FooPlugin::Bar < ApplicationRecord
end
diff --git a/plugins/lattes_curriculum/lib/academic_info.rb b/plugins/lattes_curriculum/lib/academic_info.rb
index eeef15f..6fab3e6 100644
--- a/plugins/lattes_curriculum/lib/academic_info.rb
+++ b/plugins/lattes_curriculum/lib/academic_info.rb
@@ -1,4 +1,4 @@
-class AcademicInfo < ActiveRecord::Base
+class AcademicInfo < ApplicationRecord
belongs_to :person
diff --git a/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/read_comments.rb b/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/read_comments.rb
index 51651f1..d6f01b4 100644
--- a/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/read_comments.rb
+++ b/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/read_comments.rb
@@ -1,4 +1,4 @@
-class MarkCommentAsReadPlugin::ReadComments < ActiveRecord::Base
+class MarkCommentAsReadPlugin::ReadComments < ApplicationRecord
self.table_name = 'mark_comment_as_read_plugin'
belongs_to :comment
belongs_to :person
diff --git a/plugins/metadata/lib/metadata_plugin/base.rb b/plugins/metadata/lib/metadata_plugin/base.rb
index d95602f..6944b41 100644
--- a/plugins/metadata/lib/metadata_plugin/base.rb
+++ b/plugins/metadata/lib/metadata_plugin/base.rb
@@ -71,6 +71,6 @@ end
ActiveSupport.run_load_hooks :metadata_plugin, MetadataPlugin
ActiveSupport.on_load :active_record do
- ActiveRecord::Base.extend MetadataPlugin::Specs::ClassMethods
+ ApplicationRecord.extend MetadataPlugin::Specs::ClassMethods
end
diff --git a/plugins/newsletter/lib/newsletter_plugin/newsletter.rb b/plugins/newsletter/lib/newsletter_plugin/newsletter.rb
index 4476d97..3808865 100644
--- a/plugins/newsletter/lib/newsletter_plugin/newsletter.rb
+++ b/plugins/newsletter/lib/newsletter_plugin/newsletter.rb
@@ -1,6 +1,6 @@
require 'csv'
-class NewsletterPlugin::Newsletter < ActiveRecord::Base
+class NewsletterPlugin::Newsletter < ApplicationRecord
belongs_to :environment
belongs_to :person
diff --git a/plugins/oauth_client/models/oauth_client_plugin/auth.rb b/plugins/oauth_client/models/oauth_client_plugin/auth.rb
index 58d7f53..6fdb53c 100644
--- a/plugins/oauth_client/models/oauth_client_plugin/auth.rb
+++ b/plugins/oauth_client/models/oauth_client_plugin/auth.rb
@@ -1,4 +1,4 @@
-class OauthClientPlugin::Auth < ActiveRecord::Base
+class OauthClientPlugin::Auth < ApplicationRecord
attr_accessible :profile, :provider, :enabled,
:access_token, :expires_in
diff --git a/plugins/oauth_client/models/oauth_client_plugin/provider.rb b/plugins/oauth_client/models/oauth_client_plugin/provider.rb
index c3d7864..a678012 100644
--- a/plugins/oauth_client/models/oauth_client_plugin/provider.rb
+++ b/plugins/oauth_client/models/oauth_client_plugin/provider.rb
@@ -1,4 +1,4 @@
-class OauthClientPlugin::Provider < ActiveRecord::Base
+class OauthClientPlugin::Provider < ApplicationRecord
belongs_to :environment
diff --git a/plugins/open_graph/models/open_graph_plugin/track.rb b/plugins/open_graph/models/open_graph_plugin/track.rb
index 6f8e475..6b8f802 100644
--- a/plugins/open_graph/models/open_graph_plugin/track.rb
+++ b/plugins/open_graph/models/open_graph_plugin/track.rb
@@ -1,4 +1,4 @@
-class OpenGraphPlugin::Track < ActiveRecord::Base
+class OpenGraphPlugin::Track < ApplicationRecord
class_attribute :context
self.context = :open_graph
diff --git a/plugins/orders/db/migrate/20130719132245_create_orders_plugin_tables.rb b/plugins/orders/db/migrate/20130719132245_create_orders_plugin_tables.rb
index de2389c..19a50ec 100644
--- a/plugins/orders/db/migrate/20130719132245_create_orders_plugin_tables.rb
+++ b/plugins/orders/db/migrate/20130719132245_create_orders_plugin_tables.rb
@@ -1,7 +1,7 @@
class CreateOrdersPluginTables < ActiveRecord::Migration
def self.up
# check if distribution plugin already moved tables
- return if ActiveRecord::Base.connection.table_exists? :orders_plugin_orders
+ return if ApplicationRecord.connection.table_exists? :orders_plugin_orders
create_table :orders_plugin_orders do |t|
t.integer :profile_id
diff --git a/plugins/orders/lib/code_numbering.rb b/plugins/orders/lib/code_numbering.rb
index 843cc33..b980a59 100644
--- a/plugins/orders/lib/code_numbering.rb
+++ b/plugins/orders/lib/code_numbering.rb
@@ -55,4 +55,4 @@ module CodeNumbering
end
end
-ActiveRecord::Base.extend CodeNumbering::ClassMethods
+ApplicationRecord.extend CodeNumbering::ClassMethods
diff --git a/plugins/orders/lib/serialized_synced_data.rb b/plugins/orders/lib/serialized_synced_data.rb
index f2d642d..432a2e3 100644
--- a/plugins/orders/lib/serialized_synced_data.rb
+++ b/plugins/orders/lib/serialized_synced_data.rb
@@ -56,7 +56,7 @@ module SerializedSyncedData
source = self.send field
if block_given?
data = SerializedSyncedData.prepare_data instance_exec(source, &block)
- elsif source.is_a? ActiveRecord::Base
+ elsif source.is_a? ApplicationRecord
data = SerializedSyncedData.prepare_data source.attributes
elsif source.is_a? Array
data = source.map{ |source| SerializedSyncedData.prepare_data source.attributes }
diff --git a/plugins/orders/models/orders_plugin/item.rb b/plugins/orders/models/orders_plugin/item.rb
index 0c94596..af91aa7 100644
--- a/plugins/orders/models/orders_plugin/item.rb
+++ b/plugins/orders/models/orders_plugin/item.rb
@@ -1,4 +1,4 @@
-class OrdersPlugin::Item < ActiveRecord::Base
+class OrdersPlugin::Item < ApplicationRecord
attr_accessible :order, :sale, :purchase,
:product, :product_id,
diff --git a/plugins/orders/models/orders_plugin/order.rb b/plugins/orders/models/orders_plugin/order.rb
index 60e5714..dd0e463 100644
--- a/plugins/orders/models/orders_plugin/order.rb
+++ b/plugins/orders/models/orders_plugin/order.rb
@@ -1,4 +1,4 @@
-class OrdersPlugin::Order < ActiveRecord::Base
+class OrdersPlugin::Order < ApplicationRecord
# if abstract_class is true then it will trigger https://github.com/rails/rails/issues/20871
#self.abstract_class = true
diff --git a/plugins/orders_cycle/db/migrate/20130909175738_create_orders_cycle_plugin_tables.rb b/plugins/orders_cycle/db/migrate/20130909175738_create_orders_cycle_plugin_tables.rb
index 46b7226..79de222 100644
--- a/plugins/orders_cycle/db/migrate/20130909175738_create_orders_cycle_plugin_tables.rb
+++ b/plugins/orders_cycle/db/migrate/20130909175738_create_orders_cycle_plugin_tables.rb
@@ -2,7 +2,7 @@ class CreateOrdersCyclePluginTables < ActiveRecord::Migration
def change
# check if distribution plugin already moved the table
- return if ActiveRecord::Base.connection.table_exists? :orders_cycle_plugin_cycles
+ return if ApplicationRecord.connection.table_exists? :orders_cycle_plugin_cycles
create_table :orders_cycle_plugin_cycle_orders do |t|
t.integer :cycle_id
diff --git a/plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb b/plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb
index 38638c1..5a7efe6 100644
--- a/plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb
+++ b/plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb
@@ -1,4 +1,4 @@
-class OrdersCyclePlugin::Cycle < ActiveRecord::Base
+class OrdersCyclePlugin::Cycle < ApplicationRecord
attr_accessible :profile, :status, :name, :description, :opening_message
@@ -233,7 +233,7 @@ class OrdersCyclePlugin::Cycle < ActiveRecord::Base
def add_products
return if self.products.count > 0
- ActiveRecord::Base.transaction do
+ ApplicationRecord.transaction do
self.profile.products.supplied.unarchived.available.find_each batch_size: 20 do |product|
self.add_product product
end
diff --git a/plugins/orders_cycle/models/orders_cycle_plugin/cycle_order.rb b/plugins/orders_cycle/models/orders_cycle_plugin/cycle_order.rb
index 61ccd6e..84b9fa0 100644
--- a/plugins/orders_cycle/models/orders_cycle_plugin/cycle_order.rb
+++ b/plugins/orders_cycle/models/orders_cycle_plugin/cycle_order.rb
@@ -1,4 +1,4 @@
-class OrdersCyclePlugin::CycleOrder < ActiveRecord::Base
+class OrdersCyclePlugin::CycleOrder < ApplicationRecord
belongs_to :cycle, class_name: 'OrdersCyclePlugin::Cycle'
belongs_to :sale, class_name: 'OrdersCyclePlugin::Sale', foreign_key: :sale_id, dependent: :destroy
diff --git a/plugins/orders_cycle/models/orders_cycle_plugin/cycle_product.rb b/plugins/orders_cycle/models/orders_cycle_plugin/cycle_product.rb
index ffaf905..5837fbc 100644
--- a/plugins/orders_cycle/models/orders_cycle_plugin/cycle_product.rb
+++ b/plugins/orders_cycle/models/orders_cycle_plugin/cycle_product.rb
@@ -1,4 +1,4 @@
-class OrdersCyclePlugin::CycleProduct < ActiveRecord::Base
+class OrdersCyclePlugin::CycleProduct < ApplicationRecord
self.table_name = :orders_cycle_plugin_cycle_products
diff --git a/plugins/orders_cycle/models/orders_cycle_plugin/sale.rb b/plugins/orders_cycle/models/orders_cycle_plugin/sale.rb
index eca127d..9ab7c03 100644
--- a/plugins/orders_cycle/models/orders_cycle_plugin/sale.rb
+++ b/plugins/orders_cycle/models/orders_cycle_plugin/sale.rb
@@ -34,7 +34,7 @@ class OrdersCyclePlugin::Sale < OrdersPlugin::Sale
end
def add_purchases_items
- ActiveRecord::Base.transaction do
+ ApplicationRecord.transaction do
self.items.each do |item|
next unless supplier_product = item.product.supplier_product
next unless supplier = supplier_product.profile
@@ -54,7 +54,7 @@ class OrdersCyclePlugin::Sale < OrdersPlugin::Sale
end
def remove_purchases_items
- ActiveRecord::Base.transaction do
+ ApplicationRecord.transaction do
self.items.each do |item|
next unless supplier_product = item.product.supplier_product
next unless purchase = supplier_product.orders_cycles_purchases.for_cycle(self.cycle).first
diff --git a/plugins/organization_ratings/lib/organization_rating.rb b/plugins/organization_ratings/lib/organization_rating.rb
index feae5db..5ac64e6 100644
--- a/plugins/organization_ratings/lib/organization_rating.rb
+++ b/plugins/organization_ratings/lib/organization_rating.rb
@@ -1,4 +1,4 @@
-class OrganizationRating < ActiveRecord::Base
+class OrganizationRating < ApplicationRecord
belongs_to :person
belongs_to :organization
belongs_to :comment
diff --git a/plugins/organization_ratings/lib/organization_ratings_config.rb b/plugins/organization_ratings/lib/organization_ratings_config.rb
index 2d89f40..982d408 100644
--- a/plugins/organization_ratings/lib/organization_ratings_config.rb
+++ b/plugins/organization_ratings/lib/organization_ratings_config.rb
@@ -1,4 +1,4 @@
-class OrganizationRatingsConfig < ActiveRecord::Base
+class OrganizationRatingsConfig < ApplicationRecord
belongs_to :environment
diff --git a/plugins/pg_search/lib/ext/active_record.rb b/plugins/pg_search/lib/ext/active_record.rb
deleted file mode 100644
index d47e713..0000000
--- a/plugins/pg_search/lib/ext/active_record.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require_dependency 'active_record'
-
-class ActiveRecord::Base
- def self.pg_search_plugin_search(query)
- filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
- if defined?(self::SEARCHABLE_FIELDS)
- where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')").
- order("ts_rank(to_tsvector('simple', #{pg_search_plugin_fields}), to_tsquery('#{filtered_query}')) DESC")
- else
- raise "No searchable fields defined for #{self.name}"
- end
- end
-
- def self.pg_search_plugin_fields
- self::SEARCHABLE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{table_name}.#{f}, '')"}.join(" || ' ' || ")
- end
-end
diff --git a/plugins/pg_search/lib/ext/application_record.rb b/plugins/pg_search/lib/ext/application_record.rb
new file mode 100644
index 0000000..762c3a4
--- /dev/null
+++ b/plugins/pg_search/lib/ext/application_record.rb
@@ -0,0 +1,19 @@
+require_dependency 'application_record'
+
+class ApplicationRecord
+
+ def self.pg_search_plugin_search(query)
+ filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
+ if defined?(self::SEARCHABLE_FIELDS)
+ where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')").
+ order("ts_rank(to_tsvector('simple', #{pg_search_plugin_fields}), to_tsquery('#{filtered_query}')) DESC")
+ else
+ raise "No searchable fields defined for #{self.name}"
+ end
+ end
+
+ def self.pg_search_plugin_fields
+ self::SEARCHABLE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{table_name}.#{f}, '')"}.join(" || ' ' || ")
+ end
+
+end
diff --git a/plugins/push_notification/lib/device_token.rb b/plugins/push_notification/lib/device_token.rb
index bb96fe7..3ad392b 100644
--- a/plugins/push_notification/lib/device_token.rb
+++ b/plugins/push_notification/lib/device_token.rb
@@ -1,4 +1,4 @@
-class PushNotificationPlugin::DeviceToken < ActiveRecord::Base
+class PushNotificationPlugin::DeviceToken < ApplicationRecord
belongs_to :user
attr_accessible :token, :device_name, :user
diff --git a/plugins/push_notification/lib/notification_settings.rb b/plugins/push_notification/lib/notification_settings.rb
index 84e6518..f4a01b7 100644
--- a/plugins/push_notification/lib/notification_settings.rb
+++ b/plugins/push_notification/lib/notification_settings.rb
@@ -1,4 +1,4 @@
-class PushNotificationPlugin::NotificationSettings < ActiveRecord::Base
+class PushNotificationPlugin::NotificationSettings < ApplicationRecord
NOTIFICATIONS= {
"add_friend" => 0x1,
diff --git a/plugins/push_notification/lib/notification_subscription.rb b/plugins/push_notification/lib/notification_subscription.rb
index e2a18d9..863f84f 100644
--- a/plugins/push_notification/lib/notification_subscription.rb
+++ b/plugins/push_notification/lib/notification_subscription.rb
@@ -1,4 +1,5 @@
-class PushNotificationPlugin::NotificationSubscription < ActiveRecord::Base
+class PushNotificationPlugin::NotificationSubscription < ApplicationRecord
+
belongs_to :environment
attr_accessible :subscribers, :notification, :environment
diff --git a/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb b/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
index 9f7749c..2c2d2ed 100644
--- a/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
+++ b/plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
@@ -1,7 +1,7 @@
OrdersPlugin.send :remove_const, :Item if defined? OrdersPlugin::Item
OrdersPlugin.send :remove_const, :Order if defined? OrdersPlugin::Order
-class ShoppingCartPlugin::PurchaseOrder < ActiveRecord::Base
+class ShoppingCartPlugin::PurchaseOrder < ApplicationRecord
acts_as_having_settings field: :data
module Status
@@ -16,10 +16,10 @@ class Profile
has_many :orders, class_name: 'OrdersPlugin::Order'
end
-class OrdersPlugin::Item < ActiveRecord::Base
+class OrdersPlugin::Item < ApplicationRecord
belongs_to :order, class_name: 'OrdersPlugin::Order'
end
-class OrdersPlugin::Order < ActiveRecord::Base
+class OrdersPlugin::Order < ApplicationRecord
has_many :items, class_name: 'OrdersPlugin::Item', foreign_key: :order_id
extend CodeNumbering::ClassMethods
diff --git a/plugins/sniffer/db/migrate/20131212124106_drop_sniffer_profile_table.rb b/plugins/sniffer/db/migrate/20131212124106_drop_sniffer_profile_table.rb
index 3fb6d3f..49c7def 100644
--- a/plugins/sniffer/db/migrate/20131212124106_drop_sniffer_profile_table.rb
+++ b/plugins/sniffer/db/migrate/20131212124106_drop_sniffer_profile_table.rb
@@ -1,9 +1,9 @@
SnifferPlugin.send :remove_const, :Opportunity if defined? SnifferPlugin::Opportunity
-class SnifferPlugin::Profile < ActiveRecord::Base
+class SnifferPlugin::Profile < ApplicationRecord
belongs_to :profile
end
-class SnifferPlugin::Opportunity < ActiveRecord::Base
+class SnifferPlugin::Opportunity < ApplicationRecord
belongs_to :sniffer_profile, class_name: 'SnifferPlugin::Profile', foreign_key: :profile_id
end
diff --git a/plugins/sniffer/models/sniffer_plugin/opportunity.rb b/plugins/sniffer/models/sniffer_plugin/opportunity.rb
index e5916f9..c93f9ee 100644
--- a/plugins/sniffer/models/sniffer_plugin/opportunity.rb
+++ b/plugins/sniffer/models/sniffer_plugin/opportunity.rb
@@ -1,4 +1,4 @@
-class SnifferPlugin::Opportunity < ActiveRecord::Base
+class SnifferPlugin::Opportunity < ApplicationRecord
self.table_name = :sniffer_plugin_opportunities
diff --git a/plugins/solr/lib/acts_as_faceted.rb b/plugins/solr/lib/acts_as_faceted.rb
index e0c0a51..7cc5e4e 100644
--- a/plugins/solr/lib/acts_as_faceted.rb
+++ b/plugins/solr/lib/acts_as_faceted.rb
@@ -191,32 +191,5 @@ module ActsAsFaceted
end
-ActiveRecord::Base.extend ActsAsFaceted::ActsMethods
-
-# from https://github.com/rubyworks/facets/blob/master/lib/core/facets/enumerable/graph.rb
-module Enumerable
- def graph(&yld)
- if yld
- h = {}
- each do |*kv|
- r = yld[*kv]
- case r
- when Hash
- nk, nv = *r.to_a[0]
- when Range
- nk, nv = r.first, r.last
- else
- nk, nv = *r
- end
- h[nk] = nv
- end
- h
- else
- Enumerator.new(self,:graph)
- end
- end
-
- # Alias for #graph, which stands for "map hash".
- alias_method :mash, :graph
-end
+ApplicationRecord.extend ActsAsFaceted::ActsMethods
diff --git a/plugins/solr/lib/acts_as_searchable.rb b/plugins/solr/lib/acts_as_searchable.rb
index feb07ea..fc3610f 100644
--- a/plugins/solr/lib/acts_as_searchable.rb
+++ b/plugins/solr/lib/acts_as_searchable.rb
@@ -35,7 +35,7 @@ module ActsAsSearchable
module FindByContents
def schema_name
- (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? ActiveRecord::Base.connection.schema_search_path : ''
+ (Noosfero::MultiTenancy.on? and ApplicationRecord.postgresql?) ? ApplicationRecord.connection.schema_search_path : ''
end
def find_by_contents(query, pg_options = {}, options = {}, db_options = {})
@@ -84,4 +84,5 @@ module ActsAsSearchable
end
end
-ActiveRecord::Base.send(:extend, ActsAsSearchable::ClassMethods)
+ApplicationRecord.extend ActsAsSearchable::ClassMethods
+
diff --git a/plugins/solr/test/unit/acts_as_faceted_test.rb b/plugins/solr/test/unit/acts_as_faceted_test.rb
index dced575..218544a 100644
--- a/plugins/solr/test/unit/acts_as_faceted_test.rb
+++ b/plugins/solr/test/unit/acts_as_faceted_test.rb
@@ -2,11 +2,11 @@ require_relative '../test_helper'
require "#{File.dirname(__FILE__)}/../../lib/acts_as_faceted"
-class TestModel < ActiveRecord::Base
+class TestModel < ApplicationRecord
def self.f_type_proc(klass)
- klass.constantize
+ klass.constantize
h = {
- 'UploadedFile' => "Uploaded File",
+ 'UploadedFile' => "Uploaded File",
'TextArticle' => "Text",
'Folder' => "Folder",
'Event' => "Event",
@@ -92,7 +92,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase
assert_equivalent [["[* TO NOW-1YEARS/DAY]", "Older than one year", 10], ["[NOW-1YEARS TO NOW/DAY]", "Last year", 19]], r
end
- should 'return facet hash in map_facets_for' do
+ should 'return facet hash in map_facets_for' do
r = TestModel.map_facets_for(Environment.default)
assert r.count, 2
@@ -147,7 +147,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase
facets = TestModel.map_facets_for(Environment.default)
facet = facets.select{ |f| f[:id] == 'f_type' }.first
facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {}
- sorted = TestModel.facet_result_sort(facet, facet_data, :alphabetically)
+ sorted = TestModel.facet_result_sort(facet, facet_data, :alphabetically)
assert_equal sorted,
[["Folder", "Folder", 3], ["Gallery", "Gallery", 1], ["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6]]
end
@@ -156,7 +156,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase
facets = TestModel.map_facets_for(Environment.default)
facet = facets.select{ |f| f[:id] == 'f_type' }.first
facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {}
- sorted = TestModel.facet_result_sort(facet, facet_data, :count)
+ sorted = TestModel.facet_result_sort(facet, facet_data, :count)
assert_equal sorted,
[["TextArticle", "Text", 15], ["UploadedFile", "Uploaded File", 6], ["Folder", "Folder", 3], ["Gallery", "Gallery", 1]]
end
diff --git a/plugins/solr/test/unit/acts_as_searchable_test.rb b/plugins/solr/test/unit/acts_as_searchable_test.rb
index 045370e..986fa09 100644
--- a/plugins/solr/test/unit/acts_as_searchable_test.rb
+++ b/plugins/solr/test/unit/acts_as_searchable_test.rb
@@ -23,7 +23,7 @@ class ActsAsSearchableTest < ActiveSupport::TestCase
should 'not be searchable when disabled' do
# suppress warning about already initialized constant
silent { ActsAsSearchable::ClassMethods::ACTS_AS_SEARCHABLE_ENABLED = false }
-
+
@test_model.expects(:acts_as_solr).never
@test_model.acts_as_searchable
end
diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/dynamic_attribute.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/dynamic_attribute.rb
index 29f8d2c..73b5f04 100644
--- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/dynamic_attribute.rb
+++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/dynamic_attribute.rb
@@ -1,3 +1,3 @@
-class DynamicAttribute < ActiveRecord::Base
+class DynamicAttribute < ApplicationRecord
belongs_to :dynamicable, :polymorphic => true
end
diff --git a/plugins/spaminator/lib/spaminator_plugin/report.rb b/plugins/spaminator/lib/spaminator_plugin/report.rb
index ace4acc..eb3df25 100644
--- a/plugins/spaminator/lib/spaminator_plugin/report.rb
+++ b/plugins/spaminator/lib/spaminator_plugin/report.rb
@@ -1,4 +1,4 @@
-class SpaminatorPlugin::Report < ActiveRecord::Base
+class SpaminatorPlugin::Report < ApplicationRecord
serialize :failed, Hash
diff --git a/plugins/stoa/lib/stoa_plugin/usp_aluno_turma_grad.rb b/plugins/stoa/lib/stoa_plugin/usp_aluno_turma_grad.rb
index a5c362f..a634d07 100644
--- a/plugins/stoa/lib/stoa_plugin/usp_aluno_turma_grad.rb
+++ b/plugins/stoa/lib/stoa_plugin/usp_aluno_turma_grad.rb
@@ -1,4 +1,4 @@
-class StoaPlugin::UspAlunoTurmaGrad < ActiveRecord::Base
+class StoaPlugin::UspAlunoTurmaGrad < ApplicationRecord
establish_connection(:stoa)
diff --git a/plugins/stoa/lib/stoa_plugin/usp_user.rb b/plugins/stoa/lib/stoa_plugin/usp_user.rb
index e841a14..50c2d0f 100644
--- a/plugins/stoa/lib/stoa_plugin/usp_user.rb
+++ b/plugins/stoa/lib/stoa_plugin/usp_user.rb
@@ -1,4 +1,4 @@
-class StoaPlugin::UspUser < ActiveRecord::Base
+class StoaPlugin::UspUser < ApplicationRecord
establish_connection(:stoa)
self.table_name = 'pessoa'
diff --git a/plugins/stoa/test/functional/account_controller_test.rb b/plugins/stoa/test/functional/account_controller_test.rb
index 795f56f..a098888 100644
--- a/plugins/stoa/test/functional/account_controller_test.rb
+++ b/plugins/stoa/test/functional/account_controller_test.rb
@@ -6,15 +6,15 @@ class AccountControllerTest < ActionController::TestCase
SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt']
@db = Tempfile.new('stoa-test')
- configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
- ActiveRecord::Base.establish_connection(:stoa)
+ configs = ApplicationRecord.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
+ ApplicationRecord.establish_connection(:stoa)
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.create_table "pessoa" do |t|
t.integer "codpes"
t.text "numcpf"
t.date "dtanas"
end
- ActiveRecord::Base.establish_connection(:test)
+ ApplicationRecord.establish_connection(:test)
StoaPlugin::UspUser.reset_column_information
def setup
diff --git a/plugins/stoa/test/functional/profile_editor_controller_test.rb b/plugins/stoa/test/functional/profile_editor_controller_test.rb
index 9ad9ba7..d55909c 100644
--- a/plugins/stoa/test/functional/profile_editor_controller_test.rb
+++ b/plugins/stoa/test/functional/profile_editor_controller_test.rb
@@ -13,7 +13,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase
login_as(@person.identifier)
Environment.default.enable_plugin(StoaPlugin.name)
db = Tempfile.new('stoa-test')
- ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => db.path}
+ ApplicationRecord.configurations['stoa'] = {:adapter => 'sqlite3', :database => db.path}
end
attr_accessor :person
diff --git a/plugins/stoa/test/functional/stoa_plugin_controller_test.rb b/plugins/stoa/test/functional/stoa_plugin_controller_test.rb
index dd842cb..a863a43 100644
--- a/plugins/stoa/test/functional/stoa_plugin_controller_test.rb
+++ b/plugins/stoa/test/functional/stoa_plugin_controller_test.rb
@@ -9,7 +9,7 @@ class StoaPluginControllerTest < ActionController::TestCase
@controller = StoaPluginController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
- ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => ':memory:', :verbosity => 'quiet'}
+ ApplicationRecord.configurations['stoa'] = {:adapter => 'sqlite3', :database => ':memory:', :verbosity => 'quiet'}
env = Environment.default
env.enable_plugin(StoaPlugin.name)
env.enable('skip_new_user_email_confirmation')
diff --git a/plugins/stoa/test/unit/usp_user_test.rb b/plugins/stoa/test/unit/usp_user_test.rb
index 26580c5..d45283f 100644
--- a/plugins/stoa/test/unit/usp_user_test.rb
+++ b/plugins/stoa/test/unit/usp_user_test.rb
@@ -5,15 +5,16 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase
SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt']
@db = Tempfile.new('stoa-test')
- configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
- ActiveRecord::Base.establish_connection(:stoa)
+ configs = ApplicationRecord.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
+ ApplicationRecord.establish_connection(:stoa)
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.create_table "pessoa" do |t|
t.integer "codpes"
t.text "numcpf"
t.date "dtanas"
end
- ActiveRecord::Base.establish_connection(:test)
+ ApplicationRecord.establish_connection(:test)
+ StoaPlugin::UspUser.reset_column_information
def setup
StoaPlugin::UspUser.create({:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true)
diff --git a/plugins/sub_organizations/lib/sub_organizations_plugin/approve_paternity_relation.rb b/plugins/sub_organizations/lib/sub_organizations_plugin/approve_paternity_relation.rb
index 568b9e9..79b03db 100644
--- a/plugins/sub_organizations/lib/sub_organizations_plugin/approve_paternity_relation.rb
+++ b/plugins/sub_organizations/lib/sub_organizations_plugin/approve_paternity_relation.rb
@@ -1,4 +1,4 @@
-class SubOrganizationsPlugin::ApprovePaternityRelation < ActiveRecord::Base
+class SubOrganizationsPlugin::ApprovePaternityRelation < ApplicationRecord
belongs_to :task
belongs_to :parent, :polymorphic => true
diff --git a/plugins/sub_organizations/lib/sub_organizations_plugin/relation.rb b/plugins/sub_organizations/lib/sub_organizations_plugin/relation.rb
index 306127f..da44634 100644
--- a/plugins/sub_organizations/lib/sub_organizations_plugin/relation.rb
+++ b/plugins/sub_organizations/lib/sub_organizations_plugin/relation.rb
@@ -1,4 +1,4 @@
-class SubOrganizationsPlugin::Relation < ActiveRecord::Base
+class SubOrganizationsPlugin::Relation < ApplicationRecord
belongs_to :parent, :polymorphic => true
belongs_to :child, :polymorphic => true
diff --git a/plugins/suppliers/db/migrate/20130704000000_create_suppliers_plugin_tables.rb b/plugins/suppliers/db/migrate/20130704000000_create_suppliers_plugin_tables.rb
index ccd3803..a895d63 100644
--- a/plugins/suppliers/db/migrate/20130704000000_create_suppliers_plugin_tables.rb
+++ b/plugins/suppliers/db/migrate/20130704000000_create_suppliers_plugin_tables.rb
@@ -1,7 +1,7 @@
class CreateSuppliersPluginTables < ActiveRecord::Migration
def self.up
# check if distribution plugin already moved the table
- return if ActiveRecord::Base.connection.table_exists? :suppliers_plugin_suppliers
+ return if ApplicationRecord.connection.table_exists? :suppliers_plugin_suppliers
create_table :suppliers_plugin_suppliers do |t|
t.integer :profile_id
diff --git a/plugins/suppliers/db/migrate/20130704202336_create_suppliers_plugin_source_product.rb b/plugins/suppliers/db/migrate/20130704202336_create_suppliers_plugin_source_product.rb
index ed1ea69..0f29028 100644
--- a/plugins/suppliers/db/migrate/20130704202336_create_suppliers_plugin_source_product.rb
+++ b/plugins/suppliers/db/migrate/20130704202336_create_suppliers_plugin_source_product.rb
@@ -1,7 +1,7 @@
class CreateSuppliersPluginSourceProduct < ActiveRecord::Migration
def self.up
# check if distribution plugin already moved the table
- return if ActiveRecord::Base.connection.table_exists? "suppliers_plugin_source_products"
+ return if ApplicationRecord.connection.table_exists? "suppliers_plugin_source_products"
create_table :suppliers_plugin_source_products do |t|
t.integer "from_product_id"
diff --git a/plugins/suppliers/db/migrate/20130902115916_add_active_to_suppliers_plugin_supplier.rb b/plugins/suppliers/db/migrate/20130902115916_add_active_to_suppliers_plugin_supplier.rb
index 2b9baf4..fefd2f8 100644
--- a/plugins/suppliers/db/migrate/20130902115916_add_active_to_suppliers_plugin_supplier.rb
+++ b/plugins/suppliers/db/migrate/20130902115916_add_active_to_suppliers_plugin_supplier.rb
@@ -1,4 +1,4 @@
-class SuppliersPlugin::Supplier < ActiveRecord::Base
+class SuppliersPlugin::Supplier < ApplicationRecord
end
class AddActiveToSuppliersPluginSupplier < ActiveRecord::Migration
diff --git a/plugins/suppliers/lib/default_delegate.rb b/plugins/suppliers/lib/default_delegate.rb
index ce7b8b1..b405beb 100644
--- a/plugins/suppliers/lib/default_delegate.rb
+++ b/plugins/suppliers/lib/default_delegate.rb
@@ -126,4 +126,4 @@ module DefaultDelegate
end
-ActiveRecord::Base.extend DefaultDelegate::ClassMethods
+ApplicationRecord.extend DefaultDelegate::ClassMethods
diff --git a/plugins/suppliers/models/suppliers_plugin/source_product.rb b/plugins/suppliers/models/suppliers_plugin/source_product.rb
index 23d9c5d..74cf490 100644
--- a/plugins/suppliers/models/suppliers_plugin/source_product.rb
+++ b/plugins/suppliers/models/suppliers_plugin/source_product.rb
@@ -1,4 +1,4 @@
-class SuppliersPlugin::SourceProduct < ActiveRecord::Base
+class SuppliersPlugin::SourceProduct < ApplicationRecord
attr_accessible :from_product, :to_product, :quantity
diff --git a/plugins/suppliers/models/suppliers_plugin/supplier.rb b/plugins/suppliers/models/suppliers_plugin/supplier.rb
index e3ac8cd..f2af79c 100644
--- a/plugins/suppliers/models/suppliers_plugin/supplier.rb
+++ b/plugins/suppliers/models/suppliers_plugin/supplier.rb
@@ -1,4 +1,4 @@
-class SuppliersPlugin::Supplier < ActiveRecord::Base
+class SuppliersPlugin::Supplier < ApplicationRecord
attr_accessor :distribute_products_on_create, :dont_destroy_dummy, :identifier_from_name
diff --git a/plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb b/plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
index 24fae23..aeff9af 100644
--- a/plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
+++ b/plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
@@ -1,4 +1,4 @@
-class ToleranceTimePlugin::Publication < ActiveRecord::Base
+class ToleranceTimePlugin::Publication < ApplicationRecord
belongs_to :target, :polymorphic => true
validates_presence_of :target_id, :target_type
diff --git a/plugins/tolerance_time/lib/tolerance_time_plugin/tolerance.rb b/plugins/tolerance_time/lib/tolerance_time_plugin/tolerance.rb
index c938a23..1d12f12 100644
--- a/plugins/tolerance_time/lib/tolerance_time_plugin/tolerance.rb
+++ b/plugins/tolerance_time/lib/tolerance_time_plugin/tolerance.rb
@@ -1,4 +1,4 @@
-class ToleranceTimePlugin::Tolerance < ActiveRecord::Base
+class ToleranceTimePlugin::Tolerance < ApplicationRecord
belongs_to :profile
validates_presence_of :profile_id
diff --git a/plugins/volunteers/models/volunteers_plugin/assignment.rb b/plugins/volunteers/models/volunteers_plugin/assignment.rb
index 2542ced..84da721 100644
--- a/plugins/volunteers/models/volunteers_plugin/assignment.rb
+++ b/plugins/volunteers/models/volunteers_plugin/assignment.rb
@@ -1,4 +1,4 @@
-class VolunteersPlugin::Assignment < ActiveRecord::Base
+class VolunteersPlugin::Assignment < ApplicationRecord
attr_accessible :profile_id
diff --git a/plugins/volunteers/models/volunteers_plugin/period.rb b/plugins/volunteers/models/volunteers_plugin/period.rb
index ff3091c..84c9ec3 100644
--- a/plugins/volunteers/models/volunteers_plugin/period.rb
+++ b/plugins/volunteers/models/volunteers_plugin/period.rb
@@ -1,4 +1,4 @@
-class VolunteersPlugin::Period < ActiveRecord::Base
+class VolunteersPlugin::Period < ApplicationRecord
attr_accessible :name
attr_accessible :start, :end
diff --git a/test/functional/role_controller_test.rb b/test/functional/role_controller_test.rb
index 0c77394..322bea0 100644
--- a/test/functional/role_controller_test.rb
+++ b/test/functional/role_controller_test.rb
@@ -80,7 +80,7 @@ class RoleControllerTest < ActionController::TestCase
role = Role.create!(:name => 'environment_role', :key => 'environment_role', :environment => Environment.default)
get :edit, :id => role.id
['Environment', 'Profile'].each do |key|
- ActiveRecord::Base::PERMISSIONS[key].each do |permission, value|
+ ApplicationRecord::PERMISSIONS[key].each do |permission, value|
assert_select ".permissions.#{key.downcase} input##{permission}"
end
end
@@ -89,7 +89,7 @@ class RoleControllerTest < ActionController::TestCase
should 'display permissions only for profile when editing a profile role' do
role = Role.create!(:name => 'profile_role', :key => 'profile_role', :environment => Environment.default)
get :edit, :id => role.id
- ActiveRecord::Base::PERMISSIONS['Profile'].each do |permission, value|
+ ApplicationRecord::PERMISSIONS['Profile'].each do |permission, value|
assert_select "input##{permission}"
end
assert_select ".permissions.environment", false
diff --git a/test/integration/multi_tenancy_test.rb b/test/integration/multi_tenancy_test.rb
index df9dc10..60215a1 100644
--- a/test/integration/multi_tenancy_test.rb
+++ b/test/integration/multi_tenancy_test.rb
@@ -29,12 +29,12 @@ class MultiTenancyTest < ActionDispatch::IntegrationTest
user = create_user
session_obj = create(Session, user_id: user.id, session_id: 'some_id', data: {})
person_identifier = user.person.identifier
-
+
Noosfero::MultiTenancy.setup!('schema1.com')
host! 'schema2.com'
cookies[:_noosfero_session] = session_obj.session_id
assert_nothing_raised { get "/myprofile/#{person_identifier}" }
- assert_equal 'public', ActiveRecord::Base.connection.schema_search_path
+ assert_equal 'public', ApplicationRecord.connection.schema_search_path
end
end
diff --git a/test/mocks/test/environment.rb b/test/mocks/test/environment.rb
index 8277ae9..8bf5dc5 100644
--- a/test/mocks/test/environment.rb
+++ b/test/mocks/test/environment.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../../../app/models/environment")
-class Environment < ActiveRecord::Base
+class Environment < ApplicationRecord
def self.available_features
{
'feature1' => 'Enable Feature 1',
diff --git a/test/support/factories.rb b/test/support/factories.rb
index a807048..bd35f9d 100644
--- a/test/support/factories.rb
+++ b/test/support/factories.rb
@@ -5,9 +5,9 @@ module Noosfero::Factory
attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present?
data = defaults_for(name.to_s.gsub('::','')).merge(attrs)
klass = name.to_s.camelize.constantize
- if klass.superclass != ActiveRecord::Base
- data[:type] = klass.to_s
- end
+
+ data[:type] = klass.to_s if klass.column_names.include? 'type'
+
if options[:timestamps]
fast_insert_with_timestamps(klass, data)
else
@@ -129,7 +129,7 @@ module Noosfero::Factory
def fast_insert(klass, data)
names = data.keys
- values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', data[k]]) }
+ values = names.map {|k| ApplicationRecord.send(:sanitize_sql_array, ['?', data[k]]) }
sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')]
klass.connection.execute(sql)
klass.order(:id).last
diff --git a/test/test_helper.rb b/test/test_helper.rb
index ed50fa3..5922f1a 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -187,14 +187,14 @@ class ActiveSupport::TestCase
end
def uses_postgresql(schema_name = 'test_schema')
- adapter = ActiveRecord::Base.connection.class
+ adapter = ApplicationRecord.connection.class
adapter.any_instance.stubs(:adapter_name).returns('PostgreSQL')
adapter.any_instance.stubs(:schema_search_path).returns(schema_name)
Noosfero::MultiTenancy.stubs(:on?).returns(true)
end
def uses_sqlite
- adapter = ActiveRecord::Base.connection.class
+ adapter = ApplicationRecord.connection.class
adapter.any_instance.stubs(:adapter_name).returns('SQLite')
Noosfero::MultiTenancy.stubs(:on?).returns(false)
end
diff --git a/test/unit/geo_ref_test.rb b/test/unit/geo_ref_test.rb
index 25e2188..fc7431f 100644
--- a/test/unit/geo_ref_test.rb
+++ b/test/unit/geo_ref_test.rb
@@ -22,7 +22,7 @@ class GeoRefTest < ActiveSupport::TestCase
@acme = Enterprise.create! environment: env, identifier: 'acme', name: 'ACME',
city: 'Salvador', state: 'Bahia', country: 'BR', lat: -12.9, lng: -38.5
def sql_dist_to(ll)
- ActiveRecord::Base.connection.execute(
+ ApplicationRecord.connection.execute(
"SELECT #{Noosfero::GeoRef.sql_dist ll[0], ll[1]} as dist" +
" FROM profiles WHERE id = #{@acme.id};"
).first['dist'].to_f.round
diff --git a/test/unit/multi_tenancy.rb b/test/unit/multi_tenancy.rb
index ce1333d..f016ed3 100644
--- a/test/unit/multi_tenancy.rb
+++ b/test/unit/multi_tenancy.rb
@@ -36,7 +36,7 @@ class MultiTenancyTest < ActiveSupport::TestCase
def test_set_schema_by_host
Noosfero::MultiTenancy.expects(:mapping).returns({ 'host' => 'schema' })
- adapter = ActiveRecord::Base.connection.class
+ adapter = ApplicationRecord.connection.class
adapter.any_instance.expects(:schema_search_path=).with('schema').returns(true)
assert Noosfero::MultiTenancy.db_by_host = 'host'
end
diff --git a/test/unit/sqlite_extension_test.rb b/test/unit/sqlite_extension_test.rb
deleted file mode 100644
index dabd639..0000000
--- a/test/unit/sqlite_extension_test.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require_relative "../test_helper"
-
-# if this test is run without SQLite (e.g. with mysql or postgres), the tests
-# will just pass. The idea is to test our local extensions to SQLite.
-class SQliteExtensionTest < ActiveSupport::TestCase
-
- if ActiveRecord::Base.connection.adapter_name =~ /^sqlite$/i
-
- should 'have power function' do
- assert_in_delta 8.0, ActiveRecord::Base.connection.execute('select pow(2.0, 3.0) as result').first['result'], 0.0001
- end
-
- should 'have radians function' do
- assert_in_delta Math::PI/2, ActiveRecord::Base.connection.execute('select radians(90) as rad').first['rad'], 0.0001
- end
-
- should 'have square root function' do
- assert_in_delta 1.4142, ActiveRecord::Base.connection.execute('select sqrt(2) as sqrt').first['sqrt'], 0.0001
- end
-
- should 'have a distance function' do
- args = [32.918593, -96.958444, 32.951613, -96.958444].map{|l|l * Math::PI/180}
- assert_in_delta 2.28402, ActiveRecord::Base.connection.execute("select spheric_distance(#{args.inspect[1..-2]}, 3963.19) as dist").first['dist'], 0.0001
- end
-
- else
-
- should 'just pass (not using SQLite)' do
- assert true
- end
-
- end
-
-end
--
libgit2 0.21.2