Skip to content
Browse files

Make the second argument to `attribute` optional

While working on updating Paper Trail for 5.1 compatibility, I noticed
that I was required to pass a second argument to `attribute`. I didn't
intend for this to be the case, as `attribute :foo` is totally
reasonable shorthand for "I want `attr_accessor :foo`, but also have it
work with things like `.attributes` and `ActiveRecord::Dirty`"
  • Loading branch information
sgrif committed Nov 30, 2016
1 parent ef993d3 commit 1bdc395d956f789b6612796ac6f130cde90d3066
@@ -1,3 +1,9 @@
* Change the type argument of `ActiveRecord::Base#attribute` to be optional.
The default is now ``, which provides no type
casting behavior.

*Sean Griffin*

* Fix that unsigned with zerofill is treated as signed.

Fixes #27125.
@@ -191,7 +191,7 @@ module ClassMethods
# tracking is performed. The methods +changed?+ and +changed_in_place?+
# will be called from ActiveModel::Dirty. See the documentation for those
# methods in ActiveModel::Type::Value for more details.
def attribute(name, cast_type, **options)
def attribute(name, cast_type =, **options)
name = name.to_s

@@ -255,5 +255,13 @@ def deserialize(*)

assert_includes inspection, "non_existent_decimal"

test "attributes do not require a type" do
klass = do
attribute :no_type
assert_equal 1, 1).no_type
assert_equal "foo", "foo").no_type

0 comments on commit 1bdc395

Please sign in to comment.