| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
| |
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).
I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
```
...
(snip)
............F
Failure:
JsonSerializationTest#test_as_json_should_return_a_hash_if_include_root_
in_json_is_true [/home/travis/build/rails/rails/activemodel/test/cases/serializers/json_serialization_test.rb:145]:
Expected: 2006-08-01 00:00:00 UTC
Actual: "2006-08-01T00:00:00.000Z"
rails test home/travis/build/rails/rails/activemodel/test/cases/serializers/json_serialization_test.rb:136
(snip)
...
```
Related to #31503
|
|
|
|
|
| |
According to doc the method should return
non-json compatible types as strings.
|
| |
|
|
|
|
|
| |
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
|
| |
|
|
|
|
|
|
| |
assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message
assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
|
|
|
|
|
| |
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
|
|
|
|
|
|
|
| |
This includes the following classes:
- ActiveModel::Serializers::Xml
- ActiveRecord::Serialization::XmlSerializer
|
|
|
|
|
| |
It was removed when we removed mocha at
5a6ae7f7539216931f2b3f4aa53394ac4136c74e
|
|
|
|
|
|
| |
Previously, calling `User.model_name.to_json` would result in an infinite
recursion as `.model_name` inherited its `.as_json` behavior from Object. This
patch fixes that unexpected behavior by delegating `.as_json` to :name.
|
| |
|
| |
|
| |
|
|
|
|
| |
ActiveModel tests can now be run in random order.
|
| |
|
| |
|
|
|
|
| |
determinated only by the used interpreter
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
| |
I also attempted to fix other styleguide violations such as
{ a: :b } over {a: :b} and foo(b: 'bar') over foo( b: 'bar' ).
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
When serialising a class, specify the type of any singular associations, if
necessary. Rails already correctly specifies the :type of any enumerable
association (e.g. a has_many association), but made no attempt to do so for
non-enumerables (e.g. a has_one association).
We must specify the :type of any STI association. A has_one
association to a class which uses single-table inheritance is an example of
this type of association.
Fixes #7471
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Due to a change in builder, nil values and empty strings now generates
closed tags, so instead of this:
<pseudonyms nil=\"true\"></pseudonyms>
It generates this:
<pseudonyms nil=\"true\"/>
Document this change in Rails so that people can track it down easily if
necessary.
|
|
|
|
|
|
|
|
|
|
|
| |
https://github.com/rails/rails/issues/6958
- Enable propagation of :skip_types, :dasherize and :camelize on included models by default
- Adding the option to override this propagation on a per-include basis (:include => { :model => { :dasherize => false } }
- Enough tests to prove it works
- Updated activemodel CHANGELOG.md
Squashed my commits
|
|
|
|
|
|
| |
ActiveRecord json/xml serialization should use as base
serializable_hash, provided by ActiveModel. Add some more coverage
around options :only and :except for both json and xml serialization.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Changes:
* Update `include_root_in_json` default value to false for default value
to false for `ActiveModel::Serializers::JSON`.
* Remove unnecessary change to include_root_in_json option in
wrap_parameters template.
* Update `as_json` documentation.
* Fix JSONSerialization tests.
Problem:
It's confusing that AM serializers behave differently from AR,
even when AR objects include AM serializers module.
class User < ActiveRecord::Base; end
class Person
include ActiveModel::Model
include ActiveModel::AttributeMethods
include ActiveModel::Serializers::JSON
attr_accessor :name, :age
def attributes
instance_values
end
end
user.as_json
=> {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
# root is not included
person.as_json
=> {"person"=>{"name"=>"Francesco", "age"=>22}}
# root is included
ActiveRecord::Base.include_root_in_json
=> false
Person.include_root_in_json
=> true
# different default values for include_root_in_json
Proposal:
Change the default value of AM serializers to false, update
the misleading documentation and remove unnecessary change
to false of include_root_in_json option with AR objects.
class User < ActiveRecord::Base; end
class Person
include ActiveModel::Model
include ActiveModel::AttributeMethods
include ActiveModel::Serializers::JSON
attr_accessor :name, :age
def attributes
instance_values
end
end
user.as_json
=> {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
# root is not included
person.as_json
=> {"name"=>"Francesco", "age"=>22}
# root is not included
ActiveRecord::Base.include_root_in_json
=> false
Person.include_root_in_json
=> false
# same behaviour, more consistent
Fixes #6578.
|
|
|
|
|
|
|
|
|
| |
XmlMini define the xml 'datatime', but according to
http://www.w3.org/TR/xmlschema-2/#dateTime could be better
change this to 'dateTime' with upper case letter 'T.
So 'DateTime' and 'Time' are redefined from 'datetime' to 'dateTime'
add the changing to the changelog
|
|
|
|
| |
collection-thing.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
namespace."
This reverts commit 8896b4fdc8a543157cdf4dfc378607ebf6c10ab0.
Conflicts:
activemodel/lib/active_model.rb
activemodel/lib/active_model/serializable.rb
activemodel/lib/active_model/serializer.rb
activemodel/test/cases/serializer_test.rb
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The following constants were renamed:
ActiveModel::Serialization => ActiveModel::Serializable
ActiveModel::Serializers::JSON => ActiveModel::Serializable::JSON
ActiveModel::Serializers::Xml => ActiveModel::Serializable::XML
The main motivation for such a change is that `ActiveModel::Serializers::JSON`
was not actually a serializer, but a module that when included allows the target to be serializable to JSON.
With such changes, we were able to clean up the namespace to add true serializers as the ArraySerializer.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When you've got an AR Model and you override the `as_json` method,
you should be able to add default options to the renderer, like this:
class User < ActiveRecord::Base
def as_json(options = {})
super(options.merge(:except => [:password_digest]))
end
end
This was not possible before this commit. See the added test case.
|
|
|
|
| |
include the root, but an instance is serialized with the root option passed as true
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit moves support for the :include serialization option for
serializing associated objects out of ActiveRecord in into ActiveModel.
The following methods support the :include option:
* serializable_hash
* to_json
* to_xml
Instances must respond to methods named by the values of the :includes
array (or keys of the :includes hash). If an association method returns
an object that is_a?(Enumerable) (which AR has_many associations do), it
is assumed to be a collection association, and its elements must respond
to :serializable_hash. Otherwise it must respond to :serializable_hash
itself.
While here, fix #858, XmlSerializer should not singularize already
singular association names.
|
| |
|
|
|
|
| |
serialization options. Closes #1058
|
| |
|
|
Hopefully "serializeration" is not an in joke that I missed.
|