diff options
author | Ben Toews <mastahyeti@gmail.com> | 2017-09-25 10:58:08 -0600 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-11-09 22:39:48 +1030 |
commit | 02a17492a937d4b423590644ad1481b82facd394 (patch) | |
tree | fe6a27b94d8e2ae46f9f4f1bd1a53b3c0f7f1ff5 /activerecord/test/models | |
parent | 40d302d880f247ef9547708b1d26a390945b6fe9 (diff) | |
download | rails-02a17492a937d4b423590644ad1481b82facd394.tar.gz rails-02a17492a937d4b423590644ad1481b82facd394.tar.bz2 rails-02a17492a937d4b423590644ad1481b82facd394.zip |
work around deprecation warnings in a bunch of tests
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/author.rb | 24 | ||||
-rw-r--r-- | activerecord/test/models/car.rb | 6 | ||||
-rw-r--r-- | activerecord/test/models/category.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/comment.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/company.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/company_in_module.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 22 | ||||
-rw-r--r-- | activerecord/test/models/membership.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/owner.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/person.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/pirate.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 12 | ||||
-rw-r--r-- | activerecord/test/models/project.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/tag.rb | 2 |
14 files changed, 46 insertions, 42 deletions
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index cb8686f315..11fe073ab0 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -7,10 +7,10 @@ class Author < ActiveRecord::Base has_many :very_special_comments, through: :posts has_many :posts_with_comments, -> { includes(:comments) }, class_name: "Post" has_many :popular_grouped_posts, -> { includes(:comments).group("type").having("SUM(comments_count) > 1").select("type") }, class_name: "Post" - has_many :posts_with_comments_sorted_by_comment_id, -> { includes(:comments).order("comments.id") }, class_name: "Post" - has_many :posts_sorted_by_id_limited, -> { order("posts.id").limit(1) }, class_name: "Post" + has_many :posts_with_comments_sorted_by_comment_id, -> { includes(:comments).order(Arel.sql("comments.id")) }, class_name: "Post" + has_many :posts_sorted_by_id_limited, -> { order(Arel.sql("posts.id")).limit(1) }, class_name: "Post" has_many :posts_with_categories, -> { includes(:categories) }, class_name: "Post" - has_many :posts_with_comments_and_categories, -> { includes(:comments, :categories).order("posts.id") }, class_name: "Post" + has_many :posts_with_comments_and_categories, -> { includes(:comments, :categories).order(Arel.sql("posts.id")) }, class_name: "Post" has_many :posts_with_special_categorizations, class_name: "PostWithSpecialCategorization" has_one :post_about_thinking, -> { where("posts.title like '%thinking%'") }, class_name: "Post" has_one :post_about_thinking_with_last_comment, -> { where("posts.title like '%thinking%'").includes(:last_comment) }, class_name: "Post" @@ -20,15 +20,15 @@ class Author < ActiveRecord::Base end end has_many :comments_containing_the_letter_e, through: :posts, source: :comments - has_many :comments_with_order_and_conditions, -> { order("comments.body").where("comments.body like 'Thank%'") }, through: :posts, source: :comments + has_many :comments_with_order_and_conditions, -> { order(Arel.sql("comments.body")).where("comments.body like 'Thank%'") }, through: :posts, source: :comments has_many :comments_with_include, -> { includes(:post).where(posts: { type: "Post" }) }, through: :posts, source: :comments has_many :comments_for_first_author, -> { for_first_author }, through: :posts, source: :comments has_many :first_posts - has_many :comments_on_first_posts, -> { order("posts.id desc, comments.id asc") }, through: :first_posts, source: :comments + has_many :comments_on_first_posts, -> { order(Arel.sql("posts.id desc, comments.id asc")) }, through: :first_posts, source: :comments has_one :first_post - has_one :comment_on_first_post, -> { order("posts.id desc, comments.id asc") }, through: :first_post, source: :comments + has_one :comment_on_first_post, -> { order(Arel.sql("posts.id desc, comments.id asc")) }, through: :first_post, source: :comments has_many :thinking_posts, -> { where(title: "So I was thinking") }, dependent: :delete_all, class_name: "Post" has_many :welcome_posts, -> { where(title: "Welcome to the weblog") }, class_name: "Post" @@ -40,11 +40,11 @@ class Author < ActiveRecord::Base -> { where(title: "Welcome to the weblog").where(Post.arel_table[:comments_count].gt(0)) }, class_name: "Post" - has_many :comments_desc, -> { order("comments.id DESC") }, through: :posts, source: :comments + has_many :comments_desc, -> { order(Arel.sql("comments.id DESC")) }, through: :posts, source: :comments has_many :unordered_comments, -> { unscope(:order).distinct }, through: :posts_sorted_by_id_limited, source: :comments has_many :funky_comments, through: :posts, source: :comments - has_many :ordered_uniq_comments, -> { distinct.order("comments.id") }, through: :posts, source: :comments - has_many :ordered_uniq_comments_desc, -> { distinct.order("comments.id DESC") }, through: :posts, source: :comments + has_many :ordered_uniq_comments, -> { distinct.order(Arel.sql("comments.id")) }, through: :posts, source: :comments + has_many :ordered_uniq_comments_desc, -> { distinct.order(Arel.sql("comments.id DESC")) }, through: :posts, source: :comments has_many :readonly_comments, -> { readonly }, through: :posts, source: :comments has_many :special_posts @@ -107,15 +107,15 @@ class Author < ActiveRecord::Base has_many :similar_posts, -> { distinct }, through: :tags, source: :tagged_posts has_many :ordered_posts, -> { distinct }, through: :ordered_tags, source: :tagged_posts - has_many :distinct_tags, -> { select("DISTINCT tags.*").order("tags.name") }, through: :posts, source: :tags + has_many :distinct_tags, -> { select("DISTINCT tags.*").order(Arel.sql("tags.name")) }, through: :posts, source: :tags has_many :tags_with_primary_key, through: :posts has_many :books has_many :unpublished_books, -> { where(status: [:proposed, :written]) }, class_name: "Book" has_many :subscriptions, through: :books - has_many :subscribers, -> { order("subscribers.nick") }, through: :subscriptions - has_many :distinct_subscribers, -> { select("DISTINCT subscribers.*").order("subscribers.nick") }, through: :subscriptions, source: :subscriber + has_many :subscribers, -> { order(Arel.sql("subscribers.nick")) }, through: :subscriptions + has_many :distinct_subscribers, -> { select("DISTINCT subscribers.*").order(Arel.sql("subscribers.nick")) }, through: :subscriptions, source: :subscriber has_one :essay, primary_key: :name, as: :writer has_one :essay_category, through: :essay, source: :category diff --git a/activerecord/test/models/car.rb b/activerecord/test/models/car.rb index 3d6a7a96c2..0be943a321 100644 --- a/activerecord/test/models/car.rb +++ b/activerecord/test/models/car.rb @@ -19,13 +19,13 @@ class Car < ActiveRecord::Base scope :incl_tyres, -> { includes(:tyres) } scope :incl_engines, -> { includes(:engines) } - scope :order_using_new_style, -> { order("name asc") } + scope :order_using_new_style, -> { order(Arel.sql("name asc")) } end class CoolCar < Car - default_scope { order("name desc") } + default_scope { order(Arel.sql("name desc")) } end class FastCar < Car - default_scope { order("name desc") } + default_scope { order(Arel.sql("name desc")) } end diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb index 2ccc00bed9..3038264694 100644 --- a/activerecord/test/models/category.rb +++ b/activerecord/test/models/category.rb @@ -4,7 +4,7 @@ class Category < ActiveRecord::Base has_and_belongs_to_many :posts has_and_belongs_to_many :special_posts, class_name: "Post" has_and_belongs_to_many :other_posts, class_name: "Post" - has_and_belongs_to_many :posts_with_authors_sorted_by_author_id, -> { includes(:authors).order("authors.id") }, class_name: "Post" + has_and_belongs_to_many :posts_with_authors_sorted_by_author_id, -> { includes(:authors).order(Arel.sql("authors.id")) }, class_name: "Post" has_and_belongs_to_many :select_testing_posts, -> { select "posts.*, 1 as correctness_marker" }, diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index 5ab433f2d9..d5acfc0749 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -81,7 +81,7 @@ class CommentThatAutomaticallyAltersPostBody < Comment end class CommentWithDefaultScopeReferencesAssociation < Comment - default_scope -> { includes(:developer).order("developers.name").references(:developer) } + default_scope -> { includes(:developer).order(Arel.sql("developers.name")).references(:developer) } belongs_to :developer end diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index bbc5fc2b2d..1a82a9e646 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -50,7 +50,7 @@ class Firm < Company has_many :clients, -> { order "id" }, dependent: :destroy, before_remove: :log_before_remove, after_remove: :log_after_remove has_many :unsorted_clients, class_name: "Client" has_many :unsorted_clients_with_symbol, class_name: :Client - has_many :clients_sorted_desc, -> { order "id DESC" }, class_name: "Client" + has_many :clients_sorted_desc, -> { order Arel.sql("id DESC") }, class_name: "Client" has_many :clients_of_firm, -> { order "id" }, foreign_key: "client_of", class_name: "Client", inverse_of: :firm has_many :clients_ordered_by_name, -> { order "name" }, class_name: "Client" has_many :unvalidated_clients_of_firm, foreign_key: "client_of", class_name: "Client", validate: false diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb index 52b7e06a63..9108eb5249 100644 --- a/activerecord/test/models/company_in_module.rb +++ b/activerecord/test/models/company_in_module.rb @@ -9,7 +9,7 @@ module MyApplication class Firm < Company has_many :clients, -> { order("id") }, dependent: :destroy - has_many :clients_sorted_desc, -> { order("id DESC") }, class_name: "Client" + has_many :clients_sorted_desc, -> { order(Arel.sql("id DESC")) }, class_name: "Client" has_many :clients_of_firm, -> { order "id" }, foreign_key: "client_of", class_name: "Client" has_many :clients_like_ms, -> { where("name = 'Microsoft'").order("id") }, class_name: "Client" has_one :account, class_name: "MyApplication::Billing::Account", dependent: :destroy diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 8881c69368..c2a21eac04 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -4,7 +4,7 @@ require "ostruct" module DeveloperProjectsAssociationExtension2 def find_least_recent - order("id ASC").first + order(Arel.sql("id ASC")).first end end @@ -13,7 +13,7 @@ class Developer < ActiveRecord::Base has_and_belongs_to_many :projects do def find_most_recent - order("id DESC").first + order(Arel.sql("id DESC")).first end end @@ -41,7 +41,7 @@ class Developer < ActiveRecord::Base join_table: "developers_projects", association_foreign_key: "project_id" do def find_least_recent - order("id ASC").first + order(Arel.sql("id ASC")).first end end @@ -126,7 +126,7 @@ end class DeveloperFilteredOnJoins < ActiveRecord::Base self.table_name = "developers" - has_and_belongs_to_many :projects, -> { order("projects.id") }, foreign_key: "developer_id", join_table: "developers_projects" + has_and_belongs_to_many :projects, -> { order(Arel.sql("projects.id")) }, foreign_key: "developer_id", join_table: "developers_projects" def self.default_scope joins(:projects).where(projects: { name: "Active Controller" }) @@ -135,9 +135,9 @@ end class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = "developers" - default_scope { order("salary DESC") } + default_scope { order(Arel.sql("salary DESC")) } - scope :by_name, -> { order("name DESC") } + scope :by_name, -> { order(Arel.sql("name DESC")) } end class DeveloperCalledDavid < ActiveRecord::Base @@ -225,14 +225,14 @@ end class EagerDeveloperWithDefaultScope < ActiveRecord::Base self.table_name = "developers" - has_and_belongs_to_many :projects, -> { order("projects.id") }, foreign_key: "developer_id", join_table: "developers_projects" + has_and_belongs_to_many :projects, -> { order(Arel.sql("projects.id")) }, foreign_key: "developer_id", join_table: "developers_projects" default_scope { includes(:projects) } end class EagerDeveloperWithClassMethodDefaultScope < ActiveRecord::Base self.table_name = "developers" - has_and_belongs_to_many :projects, -> { order("projects.id") }, foreign_key: "developer_id", join_table: "developers_projects" + has_and_belongs_to_many :projects, -> { order(Arel.sql("projects.id")) }, foreign_key: "developer_id", join_table: "developers_projects" def self.default_scope includes(:projects) @@ -241,21 +241,21 @@ end class EagerDeveloperWithLambdaDefaultScope < ActiveRecord::Base self.table_name = "developers" - has_and_belongs_to_many :projects, -> { order("projects.id") }, foreign_key: "developer_id", join_table: "developers_projects" + has_and_belongs_to_many :projects, -> { order(Arel.sql("projects.id")) }, foreign_key: "developer_id", join_table: "developers_projects" default_scope lambda { includes(:projects) } end class EagerDeveloperWithBlockDefaultScope < ActiveRecord::Base self.table_name = "developers" - has_and_belongs_to_many :projects, -> { order("projects.id") }, foreign_key: "developer_id", join_table: "developers_projects" + has_and_belongs_to_many :projects, -> { order(Arel.sql("projects.id")) }, foreign_key: "developer_id", join_table: "developers_projects" default_scope { includes(:projects) } end class EagerDeveloperWithCallableDefaultScope < ActiveRecord::Base self.table_name = "developers" - has_and_belongs_to_many :projects, -> { order("projects.id") }, foreign_key: "developer_id", join_table: "developers_projects" + has_and_belongs_to_many :projects, -> { order(Arel.sql("projects.id")) }, foreign_key: "developer_id", join_table: "developers_projects" default_scope OpenStruct.new(call: includes(:projects)) end diff --git a/activerecord/test/models/membership.rb b/activerecord/test/models/membership.rb index 09ee7544b3..47cb4d2146 100644 --- a/activerecord/test/models/membership.rb +++ b/activerecord/test/models/membership.rb @@ -12,7 +12,7 @@ class CurrentMembership < Membership end class SuperMembership < Membership - belongs_to :member, -> { order("members.id DESC") } + belongs_to :member, -> { order(Arel.sql("members.id DESC")) } belongs_to :club end diff --git a/activerecord/test/models/owner.rb b/activerecord/test/models/owner.rb index 5fa50d9918..ebaafdec5e 100644 --- a/activerecord/test/models/owner.rb +++ b/activerecord/test/models/owner.rb @@ -2,7 +2,7 @@ class Owner < ActiveRecord::Base self.primary_key = :owner_id - has_many :pets, -> { order "pets.name desc" } + has_many :pets, -> { order Arel.sql("pets.name desc") } has_many :toys, through: :pets has_many :persons, through: :pets diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index 5cba1e440e..7067f1b6b0 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -19,7 +19,7 @@ class Person < ActiveRecord::Base has_many :bad_references has_many :fixed_bad_references, -> { where favourite: true }, class_name: "BadReference" has_one :favourite_reference, -> { where "favourite=?", true }, class_name: "Reference" - has_many :posts_with_comments_sorted_by_comment_id, -> { includes(:comments).order("comments.id") }, through: :readers, source: :post + has_many :posts_with_comments_sorted_by_comment_id, -> { includes(:comments).order(Arel.sql("comments.id")) }, through: :readers, source: :post has_many :first_posts, -> { where(id: [1, 2]) }, through: :readers has_many :jobs, through: :references diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb index c8617d1cfe..99de37a52f 100644 --- a/activerecord/test/models/pirate.rb +++ b/activerecord/test/models/pirate.rb @@ -3,7 +3,7 @@ class Pirate < ActiveRecord::Base belongs_to :parrot, validate: true belongs_to :non_validated_parrot, class_name: "Parrot" - has_and_belongs_to_many :parrots, -> { order("parrots.id ASC") }, validate: true + has_and_belongs_to_many :parrots, -> { order(Arel.sql("parrots.id ASC")) }, validate: true has_and_belongs_to_many :non_validated_parrots, class_name: "Parrot" has_and_belongs_to_many :parrots_with_method_callbacks, class_name: "Parrot", before_add: :log_before_add, @@ -23,7 +23,7 @@ class Pirate < ActiveRecord::Base has_one :ship has_one :update_only_ship, class_name: "Ship" has_one :non_validated_ship, class_name: "Ship" - has_many :birds, -> { order("birds.id ASC") } + has_many :birds, -> { order(Arel.sql("birds.id ASC")) } has_many :birds_with_method_callbacks, class_name: "Bird", before_add: :log_before_add, after_add: :log_after_add, diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 7f064bf3dd..49bbbaaab7 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -35,8 +35,8 @@ class Post < ActiveRecord::Base def first_comment super.body end - has_one :first_comment, -> { order("id ASC") }, class_name: "Comment" - has_one :last_comment, -> { order("id desc") }, class_name: "Comment" + has_one :first_comment, -> { order(Arel.sql("id ASC")) }, class_name: "Comment" + has_one :last_comment, -> { order(Arel.sql("id desc")) }, class_name: "Comment" scope :with_special_comments, -> { joins(:comments).where(comments: { type: "SpecialComment" }) } scope :with_very_special_comments, -> { joins(:comments).where(comments: { type: "VerySpecialComment" }) } @@ -52,7 +52,7 @@ class Post < ActiveRecord::Base has_many :comments do def find_most_recent - order("id DESC").first + order(Arel.sql("id DESC")).first end def newest @@ -85,7 +85,7 @@ class Post < ActiveRecord::Base has_one :very_special_comment has_one :very_special_comment_with_post, -> { includes(:post) }, class_name: "VerySpecialComment" - has_one :very_special_comment_with_post_with_joins, -> { joins(:post).order("posts.id") }, class_name: "VerySpecialComment" + has_one :very_special_comment_with_post_with_joins, -> { joins(:post).order(Arel.sql("posts.id")) }, class_name: "VerySpecialComment" has_many :special_comments has_many :nonexistent_comments, -> { where "comments.id < 0" }, class_name: "Comment" @@ -319,5 +319,9 @@ class FakeKlass def arel_attribute(name, table) table[name] end + + def enforce_raw_sql_whitelist(*args) + # noop + end end end diff --git a/activerecord/test/models/project.rb b/activerecord/test/models/project.rb index 846cef625b..9b282a6729 100644 --- a/activerecord/test/models/project.rb +++ b/activerecord/test/models/project.rb @@ -2,9 +2,9 @@ class Project < ActiveRecord::Base belongs_to :mentor - has_and_belongs_to_many :developers, -> { distinct.order "developers.name desc, developers.id desc" } + has_and_belongs_to_many :developers, -> { distinct.order Arel.sql("developers.name desc, developers.id desc") } has_and_belongs_to_many :readonly_developers, -> { readonly }, class_name: "Developer" - has_and_belongs_to_many :non_unique_developers, -> { order "developers.name desc, developers.id desc" }, class_name: "Developer" + has_and_belongs_to_many :non_unique_developers, -> { order Arel.sql("developers.name desc, developers.id desc") }, class_name: "Developer" has_and_belongs_to_many :limited_developers, -> { limit 1 }, class_name: "Developer" has_and_belongs_to_many :developers_named_david, -> { where("name = 'David'").distinct }, class_name: "Developer" has_and_belongs_to_many :developers_named_david_with_hash_conditions, -> { where(name: "David").distinct }, class_name: "Developer" diff --git a/activerecord/test/models/tag.rb b/activerecord/test/models/tag.rb index bc13c3a42d..e0d42f4f66 100644 --- a/activerecord/test/models/tag.rb +++ b/activerecord/test/models/tag.rb @@ -11,6 +11,6 @@ end class OrderedTag < Tag self.table_name = "tags" - has_many :taggings, -> { order("taggings.id DESC") }, foreign_key: "tag_id" + has_many :taggings, -> { order(Arel.sql("taggings.id DESC")) }, foreign_key: "tag_id" has_many :tagged_posts, through: :taggings, source: "taggable", source_type: "Post" end |