Commit 87f2fc55d9cb2645d362c8980f09bf0ad2dc97d2
1 parent
ad13aecb
Exists in
rails5
rails5: use ApplicationRecord pattern
Showing
101 changed files
with
183 additions
and
183 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 101 files displayed.
app/mailers/mailing.rb
app/models/abuse_report.rb
app/models/action_tracker_notification.rb
... | ... | @@ -0,0 +1,64 @@ |
1 | +class ApplicationRecord < ActiveRecord::Base | |
2 | + | |
3 | + self.abstract_class = true | |
4 | + | |
5 | + def self.postgresql? | |
6 | + ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' | |
7 | + end | |
8 | + | |
9 | + # an ActionView instance for rendering views on models | |
10 | + def self.action_view | |
11 | + @action_view ||= begin | |
12 | + view_paths = ::ActionController::Base.view_paths | |
13 | + action_view = ::ActionView::Base.new view_paths | |
14 | + # for using Noosfero helpers inside render calls | |
15 | + action_view.extend ::ApplicationHelper | |
16 | + action_view | |
17 | + end | |
18 | + end | |
19 | + | |
20 | + # default value needed for the above ActionView | |
21 | + def to_partial_path | |
22 | + self.class.name.underscore | |
23 | + end | |
24 | + | |
25 | + alias :meta_cache_key :cache_key | |
26 | + def cache_key | |
27 | + key = [Noosfero::VERSION, meta_cache_key] | |
28 | + key.unshift(ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? | |
29 | + key.join('/') | |
30 | + end | |
31 | + | |
32 | + def self.like_search(query, options={}) | |
33 | + if defined?(self::SEARCHABLE_FIELDS) || options[:fields].present? | |
34 | + fields_per_table = {} | |
35 | + fields_per_table[table_name] = (options[:fields].present? ? options[:fields] : self::SEARCHABLE_FIELDS.keys.map(&:to_s)) & column_names | |
36 | + | |
37 | + if options[:joins].present? | |
38 | + join_asset = options[:joins].to_s.classify.constantize | |
39 | + if defined?(join_asset::SEARCHABLE_FIELDS) || options[:fields].present? | |
40 | + fields_per_table[join_asset.table_name] = (options[:fields].present? ? options[:fields] : join_asset::SEARCHABLE_FIELDS.keys.map(&:to_s)) & join_asset.column_names | |
41 | + end | |
42 | + end | |
43 | + | |
44 | + query = query.downcase.strip | |
45 | + fields_per_table.delete_if { |table,fields| fields.blank? } | |
46 | + conditions = fields_per_table.map do |table,fields| | |
47 | + fields.map do |field| | |
48 | + "lower(#{table}.#{field}) LIKE '%#{query}%'" | |
49 | + end.join(' OR ') | |
50 | + end.join(' OR ') | |
51 | + | |
52 | + if options[:joins].present? | |
53 | + joins(options[:joins]).where(conditions) | |
54 | + else | |
55 | + where(conditions) | |
56 | + end | |
57 | + | |
58 | + else | |
59 | + raise "No searchable fields defined for #{self.name}" | |
60 | + end | |
61 | + end | |
62 | + | |
63 | +end | |
64 | + | ... | ... |
app/models/article.rb
app/models/article_categorization.rb
app/models/block.rb
app/models/box.rb
app/models/category.rb
app/models/certifier.rb
app/models/chat_message.rb
app/models/comment.rb
app/models/contact_list.rb
app/models/custom_field.rb
app/models/custom_field_value.rb
app/models/domain.rb
app/models/environment.rb
app/models/external_feed.rb
app/models/favorite_enterprise_person.rb
app/models/friendship.rb
app/models/image.rb
app/models/input.rb
app/models/license.rb
app/models/mailing_sent.rb
app/models/national_region.rb
app/models/national_region_type.rb
app/models/price_detail.rb
app/models/product.rb
app/models/product_qualifier.rb
app/models/production_cost.rb
app/models/profile.rb
1 | 1 | # A Profile is the representation and web-presence of an individual or an |
2 | 2 | # organization. Every Profile is attached to its Environment of origin, |
3 | 3 | # which by default is the one returned by Environment:default. |
4 | -class Profile < ActiveRecord::Base | |
4 | +class Profile < ApplicationRecord | |
5 | 5 | |
6 | 6 | # use for internationalizable human type names in search facets |
7 | 7 | # reimplement on subclasses | ... | ... |
app/models/profile_activity.rb
app/models/profile_categorization.rb
app/models/profile_suggestion.rb
app/models/qualifier.rb
app/models/qualifier_certifier.rb
app/models/reported_image.rb
app/models/scrap.rb
app/models/search_term.rb
app/models/search_term_occurrence.rb
app/models/suggestion_connection.rb
app/models/task.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # This class has a +data+ field of type <tt>text</tt>, where you can store any |
10 | 10 | # type of data (as serialized Ruby objects) you need for your subclass (which |
11 | 11 | # will need to declare <ttserialize</tt> itself). |
12 | -class Task < ActiveRecord::Base | |
12 | +class Task < ApplicationRecord | |
13 | 13 | |
14 | 14 | acts_as_having_settings :field => :data |
15 | 15 | ... | ... |
app/models/thumbnail.rb
app/models/unit.rb
app/models/user.rb
app/models/validation_info.rb
db/migrate/059_add_birth_date_to_person.rb
db/migrate/069_add_enviroment_id_to_role.rb
1 | -class Role < ActiveRecord::Base; end | |
2 | -class RoleWithEnvironment < ActiveRecord::Base | |
1 | +class Role < ApplicationRecord | |
2 | +class RoleWithEnvironment < ApplicationRecord | |
3 | 3 | self.table_name = 'roles' |
4 | 4 | belongs_to :environment |
5 | 5 | end |
6 | -class RoleAssignment < ActiveRecord::Base | |
6 | +class RoleAssignment < ApplicationRecord | |
7 | 7 | belongs_to :accessor, :polymorphic => true |
8 | 8 | belongs_to :resource, :polymorphic => true |
9 | 9 | end | ... | ... |
db/migrate/20110706171330_fix_misunderstood_script_filename.rb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | # from the migration fall on a loop and breaks the migration. Both them are |
3 | 3 | # related to alias_method_chain, probably there is a problem with this kind of |
4 | 4 | # alias on the migration level. |
5 | -class Article < ActiveRecord::Base | |
5 | +class Article < ApplicationRecord | |
6 | 6 | def sanitize_tag_list |
7 | 7 | end |
8 | 8 | end | ... | ... |
lib/noosfero/core_ext.rb
lib/noosfero/core_ext/active_record.rb
... | ... | @@ -1,74 +0,0 @@ |
1 | -require 'active_record' | |
2 | - | |
3 | -class ActiveRecord::Base | |
4 | - | |
5 | - def self.postgresql? | |
6 | - ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' | |
7 | - end | |
8 | - | |
9 | - # an ActionView instance for rendering views on models | |
10 | - def self.action_view | |
11 | - @action_view ||= begin | |
12 | - view_paths = ::ActionController::Base.view_paths | |
13 | - action_view = ::ActionView::Base.new view_paths | |
14 | - # for using Noosfero helpers inside render calls | |
15 | - action_view.extend ::ApplicationHelper | |
16 | - action_view | |
17 | - end | |
18 | - end | |
19 | - | |
20 | - # default value needed for the above ActionView | |
21 | - def to_partial_path | |
22 | - self.class.name.underscore | |
23 | - end | |
24 | - | |
25 | - alias :meta_cache_key :cache_key | |
26 | - def cache_key | |
27 | - key = [Noosfero::VERSION, meta_cache_key] | |
28 | - key.unshift(ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? | |
29 | - key.join('/') | |
30 | - end | |
31 | - | |
32 | - def self.like_search(query, options={}) | |
33 | - if defined?(self::SEARCHABLE_FIELDS) || options[:fields].present? | |
34 | - fields_per_table = {} | |
35 | - fields_per_table[table_name] = (options[:fields].present? ? options[:fields] : self::SEARCHABLE_FIELDS.keys.map(&:to_s)) & column_names | |
36 | - | |
37 | - if options[:joins].present? | |
38 | - join_asset = options[:joins].to_s.classify.constantize | |
39 | - if defined?(join_asset::SEARCHABLE_FIELDS) || options[:fields].present? | |
40 | - fields_per_table[join_asset.table_name] = (options[:fields].present? ? options[:fields] : join_asset::SEARCHABLE_FIELDS.keys.map(&:to_s)) & join_asset.column_names | |
41 | - end | |
42 | - end | |
43 | - | |
44 | - query = query.downcase.strip | |
45 | - fields_per_table.delete_if { |table,fields| fields.blank? } | |
46 | - conditions = fields_per_table.map do |table,fields| | |
47 | - fields.map do |field| | |
48 | - "lower(#{table}.#{field}) LIKE '%#{query}%'" | |
49 | - end.join(' OR ') | |
50 | - end.join(' OR ') | |
51 | - | |
52 | - if options[:joins].present? | |
53 | - joins(options[:joins]).where(conditions) | |
54 | - else | |
55 | - where(conditions) | |
56 | - end | |
57 | - | |
58 | - else | |
59 | - raise "No searchable fields defined for #{self.name}" | |
60 | - end | |
61 | - end | |
62 | - | |
63 | -end | |
64 | - | |
65 | -ActiveRecord::Calculations.class_eval do | |
66 | - def count_with_distinct column_name=self.primary_key | |
67 | - if column_name | |
68 | - distinct.count_without_distinct column_name | |
69 | - else | |
70 | - count_without_distinct | |
71 | - end | |
72 | - end | |
73 | - alias_method_chain :count, :distinct | |
74 | -end |
... | ... | @@ -0,0 +1,10 @@ |
1 | +ActiveRecord::Calculations.class_eval do | |
2 | + def count_with_distinct column_name=self.primary_key | |
3 | + if column_name | |
4 | + distinct.count_without_distinct column_name | |
5 | + else | |
6 | + count_without_distinct | |
7 | + end | |
8 | + end | |
9 | + alias_method_chain :count, :distinct | |
10 | +end | ... | ... |
plugins/analytics/models/analytics_plugin/page_view.rb
plugins/analytics/models/analytics_plugin/visit.rb
plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb
plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb
plugins/comment_classification/lib/comment_classification_plugin/label.rb
plugins/comment_classification/lib/comment_classification_plugin/status.rb
plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb
1 | 1 | class AssociateFieldsToAlternatives < ActiveRecord::Migration |
2 | - class CustomFormsPlugin::Field < ActiveRecord::Base | |
2 | + class CustomFormsPlugin::Field < ApplicationRecord | |
3 | 3 | self.table_name = :custom_forms_plugin_fields |
4 | 4 | has_many :alternatives, :class_name => 'CustomFormsPlugin::Alternative' |
5 | 5 | serialize :choices, Hash | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/alternative.rb
plugins/custom_forms/lib/custom_forms_plugin/answer.rb
1 | -class CustomFormsPlugin::Answer < ActiveRecord::Base | |
1 | +class CustomFormsPlugin::Answer < ApplicationRecord | |
2 | 2 | self.table_name = :custom_forms_plugin_answers |
3 | 3 | belongs_to :field, :class_name => 'CustomFormsPlugin::Field' |
4 | 4 | belongs_to :submission, :class_name => 'CustomFormsPlugin::Submission' | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/field.rb
plugins/custom_forms/lib/custom_forms_plugin/form.rb
plugins/custom_forms/lib/custom_forms_plugin/submission.rb
plugins/delivery/models/delivery_plugin/method.rb
plugins/delivery/models/delivery_plugin/option.rb
plugins/driven_signup/models/driven_signup_plugin/auth.rb
plugins/environment_notification/lib/environment_notifications_user.rb
plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb
plugins/fb_app/models/fb_app_plugin/page_tab.rb
plugins/foo/lib/foo_plugin/bar.rb
plugins/lattes_curriculum/lib/academic_info.rb
plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/read_comments.rb
plugins/newsletter/lib/newsletter_plugin/newsletter.rb
plugins/oauth_client/models/oauth_client_plugin/auth.rb
plugins/oauth_client/models/oauth_client_plugin/provider.rb
plugins/open_graph/models/open_graph_plugin/track.rb
plugins/orders/models/orders_plugin/item.rb
plugins/orders/models/orders_plugin/order.rb
plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb
plugins/orders_cycle/models/orders_cycle_plugin/cycle_order.rb
plugins/orders_cycle/models/orders_cycle_plugin/cycle_product.rb
plugins/organization_ratings/lib/organization_rating.rb
plugins/organization_ratings/lib/organization_ratings_config.rb
plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
1 | 1 | OrdersPlugin.send :remove_const, :Item if defined? OrdersPlugin::Item |
2 | 2 | OrdersPlugin.send :remove_const, :Order if defined? OrdersPlugin::Order |
3 | 3 | |
4 | -class ShoppingCartPlugin::PurchaseOrder < ActiveRecord::Base | |
4 | +class ShoppingCartPlugin::PurchaseOrder < ApplicationRecord | |
5 | 5 | acts_as_having_settings field: :data |
6 | 6 | |
7 | 7 | module Status |
... | ... | @@ -16,10 +16,10 @@ class Profile |
16 | 16 | has_many :orders, class_name: 'OrdersPlugin::Order' |
17 | 17 | end |
18 | 18 | |
19 | -class OrdersPlugin::Item < ActiveRecord::Base | |
19 | +class OrdersPlugin::Item < ApplicationRecord | |
20 | 20 | belongs_to :order, class_name: 'OrdersPlugin::Order' |
21 | 21 | end |
22 | -class OrdersPlugin::Order < ActiveRecord::Base | |
22 | +class OrdersPlugin::Order < ApplicationRecord | |
23 | 23 | has_many :items, class_name: 'OrdersPlugin::Item', foreign_key: :order_id |
24 | 24 | |
25 | 25 | extend CodeNumbering::ClassMethods | ... | ... |
plugins/solr/test/unit/acts_as_faceted_test.rb
... | ... | @@ -2,11 +2,11 @@ require_relative '../test_helper' |
2 | 2 | require "#{File.dirname(__FILE__)}/../../lib/acts_as_faceted" |
3 | 3 | |
4 | 4 | |
5 | -class TestModel < ActiveRecord::Base | |
5 | +class TestModel < ApplicationRecord | |
6 | 6 | def self.f_type_proc(klass) |
7 | - klass.constantize | |
7 | + klass.constantize | |
8 | 8 | h = { |
9 | - 'UploadedFile' => "Uploaded File", | |
9 | + 'UploadedFile' => "Uploaded File", | |
10 | 10 | 'TextArticle' => "Text", |
11 | 11 | 'Folder' => "Folder", |
12 | 12 | 'Event' => "Event", |
... | ... | @@ -92,7 +92,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase |
92 | 92 | assert_equivalent [["[* TO NOW-1YEARS/DAY]", "Older than one year", 10], ["[NOW-1YEARS TO NOW/DAY]", "Last year", 19]], r |
93 | 93 | end |
94 | 94 | |
95 | - should 'return facet hash in map_facets_for' do | |
95 | + should 'return facet hash in map_facets_for' do | |
96 | 96 | r = TestModel.map_facets_for(Environment.default) |
97 | 97 | assert r.count, 2 |
98 | 98 | |
... | ... | @@ -147,7 +147,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase |
147 | 147 | facets = TestModel.map_facets_for(Environment.default) |
148 | 148 | facet = facets.select{ |f| f[:id] == 'f_type' }.first |
149 | 149 | facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {} |
150 | - sorted = TestModel.facet_result_sort(facet, facet_data, :alphabetically) | |
150 | + sorted = TestModel.facet_result_sort(facet, facet_data, :alphabetically) | |
151 | 151 | assert_equal sorted, |
152 | 152 | [["Folder", "Folder", 3], ["Gallery", "Gallery", 1], ["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6]] |
153 | 153 | end |
... | ... | @@ -156,7 +156,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase |
156 | 156 | facets = TestModel.map_facets_for(Environment.default) |
157 | 157 | facet = facets.select{ |f| f[:id] == 'f_type' }.first |
158 | 158 | facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {} |
159 | - sorted = TestModel.facet_result_sort(facet, facet_data, :count) | |
159 | + sorted = TestModel.facet_result_sort(facet, facet_data, :count) | |
160 | 160 | assert_equal sorted, |
161 | 161 | [["TextArticle", "Text", 15], ["UploadedFile", "Uploaded File", 6], ["Folder", "Folder", 3], ["Gallery", "Gallery", 1]] |
162 | 162 | end | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/dynamic_attribute.rb
plugins/spaminator/lib/spaminator_plugin/report.rb
plugins/stoa/lib/stoa_plugin/usp_aluno_turma_grad.rb
plugins/stoa/lib/stoa_plugin/usp_user.rb
plugins/sub_organizations/lib/sub_organizations_plugin/approve_paternity_relation.rb
plugins/sub_organizations/lib/sub_organizations_plugin/relation.rb
plugins/suppliers/db/migrate/20130902115916_add_active_to_suppliers_plugin_supplier.rb
plugins/suppliers/models/suppliers_plugin/source_product.rb
plugins/suppliers/models/suppliers_plugin/supplier.rb
plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
plugins/tolerance_time/lib/tolerance_time_plugin/tolerance.rb
plugins/volunteers/models/volunteers_plugin/assignment.rb
plugins/volunteers/models/volunteers_plugin/period.rb
test/mocks/test/environment.rb