Santiago Pastorino
8a495b1d00
Embedded has_one returns an array with the key pluralized
2013-10-18 17:49:19 -02:00
Santiago Pastorino
e6993c677b
Add missing requires
2013-10-18 17:49:18 -02:00
Santiago Pastorino
a820e9774f
Add ArraySerializer's root and meta features
2013-10-18 17:49:18 -02:00
Santiago Pastorino
70ea6c6bc7
Add has_one and has_many :serialize => tests
2013-10-18 17:49:18 -02:00
Santiago Pastorino
cd3e5e9de2
Assign the association in the setup method
2013-10-18 17:49:18 -02:00
Santiago Pastorino
f647b7ae74
Implement each_serializer
2013-10-18 17:49:18 -02:00
Santiago Pastorino
7e83f0c29d
Implement ArraySerializer
2013-10-18 17:49:18 -02:00
Santiago Pastorino
61a1669a86
Implement has_many
2013-10-18 17:49:18 -02:00
Santiago Pastorino
fa61314d0e
Add AR integration tests
2013-10-18 17:49:18 -02:00
Santiago Pastorino
4c7599cfff
Use more meaningful model names for tests
2013-10-18 17:49:18 -02:00
Santiago Pastorino
516f5bdceb
Implement has_one's embed ids include true
2013-10-18 17:49:18 -02:00
Santiago Pastorino
52bb3f6929
Implement has_one's embed objects
2013-10-18 17:49:17 -02:00
Santiago Pastorino
d756ae4a70
Implement has_one's and serialize_ids
2013-10-18 17:49:17 -02:00
Santiago Pastorino
01bc534976
Remove SerializerSupport
2013-10-18 17:49:17 -02:00
Santiago Pastorino
0d4dfb69a9
Fix directories the project is on top level dir
2013-10-18 17:49:17 -02:00
Santiago Pastorino
0c91564101
Remove method redefined warning
2013-10-18 17:49:17 -02:00
Santiago Pastorino
93baaa96b1
Implement meta and meta_key for AM::Serializer
2013-10-18 17:49:17 -02:00
Santiago Pastorino
af357619c1
Add AMS support to AR objects
2013-10-18 17:49:17 -02:00
Santiago Pastorino
a25c352525
Move models and serializers in test to fixtures.rb file
2013-10-18 17:49:17 -02:00
Santiago Pastorino
0d3b56e9cf
Implement AC integration
2013-10-18 17:49:17 -02:00
Santiago Pastorino
d41e5ccef7
Implement SerializerSupport class
2013-10-18 17:49:17 -02:00
Santiago Pastorino
45453f638b
Tests refactor
2013-10-18 17:49:17 -02:00
Santiago Pastorino
b6f9c5ee43
Implement Serializer's scope
2013-10-18 17:49:16 -02:00
Santiago Pastorino
c3f857d1b6
Implement Serializer's root
2013-10-18 17:49:16 -02:00
Santiago Pastorino
7143eb8301
Serialize just attributes
2013-10-18 17:49:16 -02:00
Santiago Pastorino
14f51f2ea9
Remove everything, rewrite of AMS starts here
2013-10-18 17:46:18 -02:00
Damian Galarza
0d674369ff
Use minitest/autorun
...
Allows edge gemset to build
2013-06-04 19:17:31 -04:00
Tee Parham
c3fa96456c
upgrade hash syntax in tests
2013-05-30 15:25:06 -06:00
Tee Parham
143e5d9866
do not generate id method (was for 1.8 only)
...
see https://github.com/rails-api/active_model_serializers/issues/127
for original motivation
2013-05-29 19:39:00 -06:00
Santiago Pastorino
c97acfd9ba
Always set a serializer for each item of an Array
...
model.active_model_serializer could return nil so we need to ensure that
if serializer is not setted we set DefaultSerializer to it.
This reverts commit 64ed05c484 .
Fixes #318
2013-05-28 18:13:07 -07:00
Santiago Pastorino
f68003f64d
Merge pull request #313 from geigerzaehler/fix_root
...
Don't wrap array items in root element
2013-05-24 14:49:41 -07:00
Santiago Pastorino
9521e912fe
serialize_ids call methods on the corresponding serializer if defined
2013-05-24 14:09:27 -07:00
Thomas Scholtes
258248d6c0
Don't wrap array items in root element
2013-05-24 10:23:59 +02:00
Damian Galarza
bbc3ae44cc
Allow a controller to properly override scope_name
2013-05-21 21:24:50 -04:00
Santiago Pastorino
1a8709d71c
Move caching to a new module
2013-05-21 17:03:06 -07:00
Steve Klabnik
48e5ca29f1
Add Coveralls for code coverage.
2013-05-05 13:38:56 -07:00
Steve Klabnik
bb8900e308
Merge pull request #264 from vad4msiu/features/root_element
...
Support for setting root element
2013-05-05 12:02:27 -07:00
Steve Klabnik
cffdbce072
Merge pull request #283 from morgoth/add-only-and-except-options-support
...
Add only and except options support
2013-05-05 12:00:59 -07:00
Gosha Arinich
1482081766
add support of mongoid collection serialization
2013-05-05 21:50:34 +03:00
Wojciech Wnętrzak
489ebf2132
Added support for :only and :except methods.
...
It is possible now to filter returned attributes and associations by:
UserSerializer.new(user, only: [:first_name, :last_name])
UserSerializer.new(user, except: :first_name)
2013-04-27 21:29:26 +02:00
vanstee
ef6ab5f0c0
Switch back to the old hash syntax
...
Just fixed up a couple of hash literals in the tests so that the build
passes for 1.8.7
2013-04-16 22:55:57 -04:00
Steve Klabnik
c1dacccbdc
Merge pull request #273 from seanabrahams/embed-ids-not-using-local-method
...
Fixes #267
2013-04-15 17:44:06 -07:00
Sean Abrahams
79acd87829
Use method instead of asssociation_ids if method exists. Fixes #267
2013-04-10 14:38:53 -07:00
Sean Abrahams
a771f30816
If output is as expected, is this assert important?
2013-04-10 14:36:42 -07:00
vanstee
a900d31041
Support strings as attribute names
...
When generating the `_fast_attributes` method, attribute names that
could not be represented as symbols (at least without escaping) would
throw parsing errors.
2013-04-09 00:53:56 -04:00
vad4msiu
95081410d2
Support for setting root element
2013-04-04 15:10:29 +04:00
Steve Klabnik
ab5d40f38b
Sigh.
...
When I did 9551a97464 , I
forgot that some new code may use it.
2013-04-03 23:56:06 -07:00
Steve Klabnik
9551a97464
Revert 37b0690fb8.
...
This feature causes more problems than it solves.
2013-04-03 17:24:08 -07:00
Prathamesh Sonpatki
f6cf469820
Fix failing tests for edge rails
...
* Edge Rails returns an instance of 'Gem::Version' for 'Rails.version' due to e600384515dc06db2c56ff5be5c18779f7b379a5
* Travis build was failing because of this as 'Rails.version.start_with? '4'' was giving 'undefined method' on 'Gem::Version' instance
2013-03-27 10:29:36 +05:30
Prathamesh Sonpatki
75a72b5cc9
Fixed few typos
2013-03-26 20:29:35 +05:30
Steve Klabnik
c129ae2016
Generate id method on Ruby 1.8.
...
Because object_id and id went through some flux, it's best to tell 1.8
specifically what we mean.
Closes #127 .
2013-03-19 14:53:08 -07:00
beerlington
4a13f86961
Reference scope by same name as serialization scope
...
By default, the serialization scope uses current_user, and you can
now reference the scope as "current_user" in the serializer. If you
override the scope using "serialization_scope" in your controller,
it will use that method name instead.
2013-03-18 14:44:38 -04:00
Sam
ad1d34b2c4
Fix inheritance issues, poison cache if attributes change
2013-03-16 03:45:06 -07:00
Bartek Borkowski
00b5739d38
Add mutual association test
2013-03-15 18:59:05 +01:00
Steve Klabnik
746a63ab09
Merge pull request #89 from twinturbo/caching
...
Serializers Cache JSON & Hashes
2013-03-15 10:30:04 -07:00
Tony Pitale
d3c6596990
make sure to merge the original responder options into the given options to preserve location
2013-03-15 03:54:35 -04:00
twinturbo
4a5e1e1ae5
Attemp to fix bad test
2013-03-15 08:41:39 +01:00
twinturbo
c3966fe741
ArraySerializer is also cached
2013-03-14 22:54:05 +01:00
twinturbo
e3888f0a40
Clean up interface inconistency
2013-03-14 22:40:06 +01:00
twinturbo
535a33a33b
Have to opt in with #cache_key
2013-03-14 22:40:06 +01:00
twinturbo
e923174a26
#cache_key delegates to #object by default
2013-03-14 22:40:06 +01:00
twinturbo
b4395f281b
Add basic caching
2013-03-14 22:40:06 +01:00
Michael Rykov
37b0690fb8
Add a Responder to handle respond_with(resource)
2013-03-13 16:45:23 -07:00
Steve Klabnik
f4916f113f
Merge pull request #223 from tchak/id-serialization-with-hooks
...
use `read_attribute_for_serialization` to serialize ids
2013-03-08 09:17:19 -08:00
Steve Klabnik
e76a16486f
Merge pull request #170 from FundingGates/master
...
Support optional types for computed attributes
2013-03-08 09:11:29 -08:00
tchak
e2c10f4440
use read_attribute_for_serialization to serialize ids
...
* in order to allow some optimisation in simple cases, we call `read_attribute_for_serialization` on parent with association_id name
2013-03-08 09:57:42 +01:00
Adam Stanton
da26ebd26f
Merge branch 'create-default-serializer' into HEAD
...
Conflicts:
lib/active_model/array_serializer.rb
2013-03-05 21:48:58 -08:00
Steve Klabnik
dc2257977f
Merge pull request #198 from jredburn/master
...
'embed_key' option to allow embedding by attributes other than IDs
2013-03-05 15:57:34 -08:00
Steve Klabnik
06c65871a8
Merge pull request #213 from michihuber/fix_rendering_nil_with_custom_serializer
...
Fix rendering nil with custom serializer
2013-03-05 15:54:51 -08:00
Jeremy Redburn
7cd7d295e0
Adding 'embed_key' option to allow embedding attributes other than ID
2013-03-05 18:52:31 -05:00
Steve Klabnik
d638e21c8c
Merge pull request #180 from fellix/fix-remove-root-globally
...
Fix global ``` self.root = false ```
2013-03-05 15:48:08 -08:00
Steve Klabnik
95937c6fc7
Merge pull request #167 from GateGuru/feature/specify-association-serializers-as-strings
...
Add support for specifying the serializer for an association as a String...
2013-03-05 15:04:29 -08:00
Ismael Abreu
2d2094b588
changes to be able to specify multiple attributes with keys
2013-03-05 02:45:22 +00:00
Michi Huber
c7a420d295
Don't fail if object is nil, render null
2013-02-26 11:17:28 +01:00
Michi Huber
58a063eff0
serialization test: respect root settings when root object is nil
2013-02-26 11:12:28 +01:00
Adam Stanton
b4616d737c
Restore order of fields in hash to original order.
2013-02-11 07:04:59 -08:00
Adam Stanton
c4fcf96eb4
Move DefaultSerializer from array_serializer.rb to serializer.rb
2013-02-10 09:49:11 -08:00
Adam Stanton
8f6218c587
Create DefaultSerializer so that as_json uses same interface.
...
This is to ensure that PORO's as_json is called if no serializer
is specified.
Original behaviour was that serializable_hash was being called,
overriding the as_json method.
2013-02-10 09:06:24 -08:00
Lee Mallabone
d35999a7ee
Add failing test to show behavior of custom serializer with nils.
2013-02-06 17:32:15 -08:00
Rafael Felix
82951c1f8a
Fix global `` self.root = false ``
...
Using the on_load hook does not change the defined root on
Serializer#inherited.
Related to #179
2013-01-24 09:13:41 -02:00
Blake Watters
b0aced9ea2
Add support for specifying the serializer for an association as a String.
...
This enables the deferral of the resolution of the serializer class to prevent NameError exceptions due to reference cycles between serializer classes.
2013-01-05 23:49:28 -05:00
Steve Klabnik
e3bfd07ac4
Merge pull request #161 from kevins90/fix_attr_name_as_serializer_underscored_prefix
...
Fix serialization of attribute whose name matches the serializer prefix underscored
2013-01-05 14:09:15 -08:00
Dan Gebhardt
3b1d2faf51
Append an _id or _ids suffix to associations' keys. Embed objects in root according to their serializers' names.
...
An `_id` suffix will be appended to the name of HasOne associations, while `_ids` will be appended to the singularized name of HasMany associations. Association keys can still be overridden with the `key` option.
Furthermore, objects embedded in the root are now by default named according to their serializer, instead of the key used for their associations.
2012-12-21 15:14:50 -05:00
Jérémy Lecour
c68a18630b
Test : use a deducted serializer on non-ActiveRecord models
2012-12-20 17:06:19 +01:00
Matt Rogish
72652ce37e
Adding info to the readme on how to specify the type, adding an additional
...
test to cover a computed property without a type
2012-12-11 10:33:17 -05:00
Matt Rogish
25c564bd6f
Adding optional type for attributes
2012-12-10 19:58:58 -05:00
Steve Klabnik
6780cd3df5
Merge pull request #138 from tchak/meta
...
Meta object
2012-12-10 10:48:39 -08:00
Godfrey Chan
6581f8ce41
Fix default_serializer_options, closes #112 & #113
...
Allow options such as :serializer, :scope, :root etc to be set via
default_serializer_options and allow the inline options to override such
defaults.
2012-12-03 03:09:58 -08:00
Francesco Rodriguez
6be6599bb7
Fix failing tests on Rails master
2012-11-25 14:56:58 -05:00
Kevin Tham
14a35ab2f8
Remove unneeded method aliasing of attribute reader: object, with the underscored class name of serializer, to fix issue where a model's attribute name matches that of the underscored prefix of the serializer
2012-11-25 00:17:17 -08:00
Jean Boussier
06e8218193
Throw a descriptive error if attempting to serialize an array with Serializer not ArraySerializer #143
2012-11-22 23:27:18 -05:00
Jo Liss
2fc083a1fe
Merge pull request #117 from joliss/computed-attributes
...
Make schema not crash on computed attributes & associations
2012-11-22 08:31:18 -08:00
tchak
a71698d5bb
Add support for meta key
...
Test for meta_key serialization
2012-11-22 13:44:59 +01:00
Tee Parham
2cb7a41780
move ArraySerializer tests into separate file
2012-11-20 10:58:16 -07:00
Tee Parham
f47a10cadc
move test fakes to separate file
2012-11-20 10:44:23 -07:00
Samnang Chhun
96ce310595
Add alias_method ActiveModel::Serializer.root= to be consistency with ActiveModel::ArraySerializer
2012-11-20 00:29:00 +07:00
Jo Liss
538b0c0916
Make schema not crash on computed associations
...
We pick nil here as well.
2012-10-31 20:07:08 +01:00
Jo Liss
6281a9149e
Make schema not crash on computed attributes
...
We do not know the type for computed attributes, so we pick nil.
Perhaps at some point we might add a :type option for attributes (or
not), but in any case it's important to not crash when there are
computed attributes.
2012-10-31 20:07:08 +01:00
Jo Liss
ee3cec3d0c
When objects are sideloaded multiple times, serialize them only once
...
To achieve this, we make the following change when sideloading: Instead
of serializing associations and discarding duplicate *hashes*, we
memorize the *objects* (records) that we have already serialized, and
only serialize those that are new.
This change is mostly transparent, and brings down serialization time
from 3.1 seconds to 1.0 seconds on my set of sample data.
There is one change in the behavior: If you sideload the same object
multiple times, and it yields different hashes, like so:
embed :ids, include: true
has_many :comments
has_many :recent_comments, root: comments, serializer: CommentShortSerializer
then previously, it would be included multiple times, whereas now, the
first hash wins. (I haven't actually tested this.) I don't know that
either option is preferable. It's not covered by the test suite, and I
think it's an edge case that is OK to ignore entirely.
2012-10-29 23:15:32 +01:00
Jo Liss
28ee88ca9a
In the test, use the same :hash across serializers
...
Otherwise, `include!` will not remember the unique_values of
already-sideloaded hashes across serializer calls.
2012-10-29 22:48:51 +01:00