aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb2
-rw-r--r--activerecord/lib/active_record/relation.rb14
-rw-r--r--activerecord/lib/active_record/store.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb5
-rw-r--r--activerecord/test/cases/serialization_test.rb7
-rw-r--r--activerecord/test/cases/store_test.rb7
-rw-r--r--guides/source/4_0_release_notes.textile2
8 files changed, 40 insertions, 5 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index ccaa2ad8f1..95967c61ee 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -24,12 +24,14 @@
dealing with a `Relation` object rather than an array:.
User.where(:age => 30).inspect
- # => <ActiveRecord::Relation [#<User ...>, #<User ...>]>
+ # => <ActiveRecord::Relation [#<User ...>, #<User ...>] ...>
User.where(:age => 30).to_a.inspect
# => [#<User ...>, #<User ...>]
- *Brian Cardarella & Jon Leighton*
+ The number of records displayed will be limited to 10.
+
+ *Brian Cardarella, Jon Leighton & Damien Mathieu*
* Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
Example:
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index 4af4d28b74..49ab3ab808 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -6,7 +6,7 @@ module ActiveRecord
included do
# Returns a hash of all the attributes that have been specified for serialization as
# keys and their class restriction as values.
- class_attribute :serialized_attributes
+ class_attribute :serialized_attributes, instance_writer: false
self.serialized_attributes = {}
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 7725331694..dc00448dff 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -515,7 +515,19 @@ module ActiveRecord
end
def inspect
- "#<#{self.class.name} #{to_a.inspect}>"
+ text = if limit_value && limit_value <= 10
+ to_a.inspect
+ else
+ entries = limit(11).to_a
+ if entries.size > 10
+ entries.pop
+ "[#{entries.map(&:inspect).join(', ')}, ...]"
+ else
+ entries.inspect
+ end
+ end
+
+ "#<#{self.class.name} #{text}>"
end
private
diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb
index 2af5b02fb7..d836acf18f 100644
--- a/activerecord/lib/active_record/store.rb
+++ b/activerecord/lib/active_record/store.rb
@@ -43,7 +43,7 @@ module ActiveRecord
extend ActiveSupport::Concern
included do
- class_attribute :stored_attributes
+ class_attribute :stored_attributes, instance_writer: false
self.stored_attributes = {}
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 7fdd42f150..bdf14e0a85 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1316,4 +1316,9 @@ class RelationTest < ActiveRecord::TestCase
relation = Post.limit(2)
assert_equal "#<ActiveRecord::Relation [#{Post.limit(2).map(&:inspect).join(', ')}]>", relation.inspect
end
+
+ test "relations limits the records in #inspect at 10" do
+ relation = Post.limit(11)
+ assert_equal "#<ActiveRecord::Relation [#{Post.limit(10).map(&:inspect).join(', ')}, ...]>", relation.inspect
+ end
end
diff --git a/activerecord/test/cases/serialization_test.rb b/activerecord/test/cases/serialization_test.rb
index a4c065e667..ce167509c1 100644
--- a/activerecord/test/cases/serialization_test.rb
+++ b/activerecord/test/cases/serialization_test.rb
@@ -51,4 +51,11 @@ class SerializationTest < ActiveRecord::TestCase
assert_equal @contact_attributes[:awesome], contact.awesome, "For #{format}"
end
end
+
+ def test_serialized_attributes_are_class_level_settings
+ assert_raise NoMethodError do
+ topic = Topic.new
+ topic.serialized_attributes = []
+ end
+ end
end
diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb
index 7f2b8945f9..3e60b62fd5 100644
--- a/activerecord/test/cases/store_test.rb
+++ b/activerecord/test/cases/store_test.rb
@@ -120,4 +120,11 @@ class StoreTest < ActiveRecord::TestCase
test "stored attributes are returned" do
assert_equal [:color, :homepage], Admin::User.stored_attributes[:settings]
end
+
+ test "stores_attributes are class level settings" do
+ assert_raise NoMethodError do
+ @john.stored_attributes = {}
+ end
+ end
+
end
diff --git a/guides/source/4_0_release_notes.textile b/guides/source/4_0_release_notes.textile
index 3733fec950..b7ac11999a 100644
--- a/guides/source/4_0_release_notes.textile
+++ b/guides/source/4_0_release_notes.textile
@@ -362,6 +362,8 @@ User.where(:age => 30).to_a.inspect
# => [#<User ...>, #<User ...>]
</ruby>
+if more than 10 items are returned by the relation, inspect will only show the first 10 followed by ellipsis.
+
* Add <tt>:collation</tt> and <tt>:ctype</tt> support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
<yaml>