From 70a5e5638bfd3b2543bb9d4805cbefec84b6b1ce Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Fri, 21 Feb 2014 17:58:40 -0500 Subject: Pass a base relation to build_default_scope when joining This allows the default scope to be built using the current table alias. Resolves #12770 --- activerecord/test/models/category.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb index 7da39a8e33..272223e1d8 100644 --- a/activerecord/test/models/category.rb +++ b/activerecord/test/models/category.rb @@ -22,6 +22,7 @@ class Category < ActiveRecord::Base end has_many :categorizations + has_many :special_categorizations has_many :post_comments, :through => :posts, :source => :comments has_many :authors, :through => :categorizations -- cgit v1.2.3 From 3a661794382c3b06cbb4d6dcc1859dd569cf8652 Mon Sep 17 00:00:00 2001 From: chrisfinne Date: Sat, 15 Mar 2014 03:32:24 -0700 Subject: AR .persisted? throws SystemStackError for an unsaved model with a custom primary_key that didn't save due to validation error --- activerecord/test/models/movie.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/movie.rb b/activerecord/test/models/movie.rb index c441be2bef..0302abad1e 100644 --- a/activerecord/test/models/movie.rb +++ b/activerecord/test/models/movie.rb @@ -1,3 +1,5 @@ class Movie < ActiveRecord::Base self.primary_key = "movieid" + + validates_presence_of :name end -- cgit v1.2.3 From 1b187caaa1e1aa1bd0f440052b4df09a5ddaa4bf Mon Sep 17 00:00:00 2001 From: Jefferson Lai Date: Tue, 1 Apr 2014 20:18:16 -0700 Subject: CollectionProxy uses the arel of its association's scope. CollectionProxy should be able to reuse the behavior (methods) of its parent class, but with its own state. This change allows CollectionProxy to use the arel object corresponding to its association's scope. --- activerecord/test/models/post.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index faf539a562..099e039255 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -149,6 +149,10 @@ class Post < ActiveRecord::Base ranked_by_comments.limit_by(limit) end + def self.written_by(author) + where(id: author.posts.pluck(:id)) + end + def self.reset_log @log = [] end -- cgit v1.2.3 From db5d26c9d70fb72b8aa3ea98709224dd13800024 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Wed, 2 Apr 2014 19:27:55 -0300 Subject: Fix error when using `with_options` with lambda. It was causing error when using `with_options` passing a lambda as its last argument. class User < ActiveRecord::Base with_options dependent: :destroy do |assoc| assoc.has_many :profiles, -> { where(active: true) } end end It was happening because the `option_merger` was taking the last argument and checking if it was a Hash. This breaks the HasMany usage, because its last argument can be a Hash or a Proc. As the behavior described in this test: https://github.com/rails/rails/blob/master/activesupport/test/option_merger_test.rb#L69 the method will only accept the lambda, this way it will keep the expected behavior. See 9eaa0a34 --- activerecord/test/models/college.rb | 5 +++++ activerecord/test/models/student.rb | 1 + 2 files changed, 6 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/college.rb b/activerecord/test/models/college.rb index c7495d7deb..501af4a8dd 100644 --- a/activerecord/test/models/college.rb +++ b/activerecord/test/models/college.rb @@ -1,5 +1,10 @@ require_dependency 'models/arunit2_model' +require 'active_support/core_ext/object/with_options' class College < ARUnit2Model has_many :courses + + with_options dependent: :destroy do |assoc| + assoc.has_many :students, -> { where(active: true) } + end end diff --git a/activerecord/test/models/student.rb b/activerecord/test/models/student.rb index f459f2a9a3..28a0b6c99b 100644 --- a/activerecord/test/models/student.rb +++ b/activerecord/test/models/student.rb @@ -1,3 +1,4 @@ class Student < ActiveRecord::Base has_and_belongs_to_many :lessons + belongs_to :college end -- cgit v1.2.3 From 57c7d5cb80086e66eee3303b11a5e558aa9e5bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 4 Apr 2014 19:44:17 -0300 Subject: Fix the test defining the models in the right place --- activerecord/test/models/column.rb | 3 +++ activerecord/test/models/record.rb | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 activerecord/test/models/column.rb create mode 100644 activerecord/test/models/record.rb (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/column.rb b/activerecord/test/models/column.rb new file mode 100644 index 0000000000..499358b4cf --- /dev/null +++ b/activerecord/test/models/column.rb @@ -0,0 +1,3 @@ +class Column < ActiveRecord::Base + belongs_to :record +end diff --git a/activerecord/test/models/record.rb b/activerecord/test/models/record.rb new file mode 100644 index 0000000000..f77ac9fc03 --- /dev/null +++ b/activerecord/test/models/record.rb @@ -0,0 +1,2 @@ +class Record < ActiveRecord::Base +end -- cgit v1.2.3