Commit Graph

1234 Commits

Author SHA1 Message Date
Benjamin Fleischer
a355b267f5 Merge pull request #1641 from krzysiek1507/patch-1
[DOC] Remove wrong quoting in serializers guide
2016-03-31 08:29:31 -05:00
Benjamin Fleischer
f2755d6eb8 Merge pull request #1637 from ncuesta/patch-1
[FIX] Make cache_store reference explicit
2016-03-31 08:28:11 -05:00
Krzysztof Rybka
37e0fdb0ee Remove wrong quoting in serializers guide 2016-03-31 14:56:07 +02:00
Nahuel Cuesta Luengo
ced45d5e9c Added Changelog entry for #1637 2016-03-31 09:06:17 -03:00
Nahuel Cuesta Luengo
32b85a0aae Make cache_store reference explicit
This avoids an issue when the base class for application's controllers inherit from `ActionController::API` instead of `ActionController::Base`.
2016-03-30 21:33:09 -03:00
Benjamin Fleischer
27a5de262f Merge pull request #1633 from bf4/fix_reflection_block_context
Add serializer to association block context
2016-03-30 15:24:20 -05:00
Benjamin Fleischer
fa7b3afbfd Prefer explicitly yielding the serializer, per groyoh 2016-03-30 14:01:28 -05:00
Benjamin Fleischer
ae6805eacd Add serializer to association block context 2016-03-30 11:03:38 -05:00
Yohan Robert
d5833e8e1b Merge pull request #1480 from bf4/fix_cache_store
[FIX] The cache store needs to be the actually store, not e.g. :memory_store
2016-03-30 17:21:27 +02:00
Benjamin Fleischer
be9c1bd397 Add CHANGELOG [ci skip] 2016-03-30 10:00:24 -05:00
Yohan Robert
fb62fb39b2 Fix caching issue happening with memory_store
It seems that fecthing from memory_store returns a reference to the
object and not a copy. Since the Attributes adapter applies #merge! on
the Hash that is returned from the memory_store, the value in the cache
is also modified.
2016-03-30 09:53:21 -05:00
Benjamin Fleischer
d50d29b601 Cleaning up Caching Tests 2016-03-30 09:53:21 -05:00
Benjamin Fleischer
cdab6f2b8a The cache store needs to be the actually store, not e.g. :memory_store
Status quo in test app:
In Rails
    ActionController::Base.cache_store = :memory_store
and then AMS railtie does:
  ActiveModelSerializers.config.cache_store = config.action_controller.cache_store
then, in the Railtie
1. ActiveSupport.on_load(:action_controller) fires
  - ActiveModelSerializers.config.cache_store #=> nil
  - ActionController::Base.cache_store        #=> #<ActiveSupport::Cache::FileStore:0x007fe319256760...]
2. After set_configs fires
  - ActiveModelSerializers.config.cache_store #+> #<ActiveSupport::Cache::FileStore:0x007fe319256760 ,
3. Tests pass, but notice that we're using the FileStore, not memory store

When we change the config to the test app:
  ActionController::Base.cache_store = :memory_store
  config = Rails.configuration
  config.action_controller.cache_store = :memory_store
then, in the Railtie:
1. ActiveSupport.on_load(:action_controller) fires
  - ActiveModelSerializers.config.cache_store #=> nil
  - ActionController::Base.cache_store        #=> #ActiveSupport::Cache::MemoryStore entries=0, size=0, options={}>]
2. After set_configs fires
  - ActiveModelSerializers.config.cache_store #=> :memory_store
3. And we get a lot of failures:
  NoMethodError: undefined method `fetch' for :memory_store:Symbol

So, we see that when we set the ActionController::Base.cache_store
directly in our test app, we could set
ActiveModelSerializers.config.cache_store in the :action_controller load
hook, but that would never use the Rails config.

To fix the Rails config, we change the config to the test app:
  config = Rails.configuration
  config.action_controller.cache_store = :memory_store
and then AMS railtie does:
  ActiveModelSerializers.config.cache_store = ActiveSupport::Cache.lookup_store(config.action_controller.cache_store
  ActiveSupport.on_load(:action_controller) do
    ::ActiveModelSerializers.config.cache_store = cache_store
  end
then
1. After set_configs fires
  - ActiveModelSerializers.config.cache_store #=> <#ActiveSupport::Cache::MemoryStore, object_id 70207113611740
2. ActiveSupport.on_load(:action_controller) fires
  - ActionController::Base.cache_store        #=> <#ActiveSupport::Cache::MemoryStore, object_id 70207106279660
  - ActiveModelSerializers.config.cache_store #=> <#ActiveSupport::Cache::MemoryStore, object_id 70207106279660
    (notice the object_id changed)
3. And we get a failure:

  1) Failure:
  ActiveModelSerializers::CacheTest#test_associations_cache_when_updated
  [active_model_serializers/test/cache_test.rb:141]:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -{:id=>"post", :title=>"New Post", :body=>"Body"}
  +{:id=>"post", :title=>"New Post", :body=>"Body", :comments=>[{:id=>2, :body=>"ZOMG A NEW COMMENT"}], :blog=>{:id=>999, :name=>"Custom blog"}, :author=>{:id=>"author", :name=>"Joao M. D. Moura"}}

If we take out the on_load(:action_controller) hook, we get a ton of
failures.  So clearly, our code expects the controller cache to be the
same as the serializer cache.

So, we make sure we use an on_load(:action_controller) hook that runs
after set_configs

And look at the test and see it is filled with direct calls to ActionController::Base.cache_store

    assert_equal(new_comment_serializer.attributes, ActionController::Base.cache_store.fetch(new_comment.cache_key))
    assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))

But that's not a problem in this case, since they're the same object.

For now, let's remove the :memory_store setting and use the default FileStore
2016-03-30 09:52:29 -05:00
Benjamin Fleischer
a7a6841fee Merge pull request #1631 from rtsinani/doc-architecture-fix
Architecture doc fix
2016-03-30 09:08:10 -05:00
Benjamin Fleischer
52e2798619 Merge pull request #1632 from fidrelity/master
Update deprecation warning with correct namespace
2016-03-30 09:07:40 -05:00
Andre Schweighofer
a1ae7dc0d9 Update deprecation warning with correct namespace 2016-03-30 15:51:13 +02:00
Arti Sinani
9e2edded7c architecture doc fix 2016-03-30 14:18:27 +01:00
L. Preston Sego III
396395666f Merge pull request #1608 from groyoh/move_serializable_resource
Move SerializableResource to ActiveModelSerializers namespace
2016-03-30 07:26:41 -04:00
Yohan Robert
21cb896802 Move SerializableResource to ActiveModelSerializers namespace
Ref. https://github.com/rails-api/active_model_serializers/pull/1310
2016-03-30 11:33:04 +02:00
Yohan Robert
874b8cab30 Merge pull request #1630 from bf4/cleanup_test_app
Clean up test app
2016-03-30 10:19:48 +02:00
Benjamin Fleischer
ff8c6f9dd4 Clean up test app 2016-03-30 00:23:04 -05:00
Benjamin Fleischer
355e0f6a37 Merge branch 'lserman-master'
Followup needed:
- Update code comments https://github.com/rails-api/active_model_serializers/pull/1622#discussion_r57750471
- Move test class into test scope https://github.com/rails-api/active_model_serializers/pull/1622#discussion_r57659150
2016-03-29 21:50:27 -05:00
Moritz Lawitschka
afe786d19a Properly deserialize dasherized keys
The JSON API adapater dasherizes every key, but the deserializer left the keys
unaltered. Thus, the client had to send underscored keys in the request body in
order for Rails to properly match sent values to model attributes.

This commit adds automatic key transformation on deserialization. Per default the
deserializer transforms the keys to underscore, but this behaviour can also be
changed by including `key_transform` in the deserializer options.
2016-03-29 22:46:01 +02:00
Benjamin Fleischer
c7b2916f37 Merge pull request #1547 from bf4/jsonapi_renderer
Basic Jsonapi Renderer registration
2016-03-28 22:23:40 -05:00
Benjamin Fleischer
5af8536713 Merge pull request #1616 from bf4/more_controller_logic_to_serializable_resource
SerializableResource handles no serializer like controller
2016-03-28 22:05:19 -05:00
Benjamin Fleischer
d364c4f188 Spike Jsonapi Renderer registration 2016-03-28 22:04:16 -05:00
Benjamin Fleischer
ec5dc497b0 Handle render.ams with nil serializer or adapter 2016-03-28 21:33:23 -05:00
Benjamin Fleischer
84197e4dad SerializableResource handles no serializer like controller 2016-03-28 20:04:45 -05:00
Logan Serman
d0389ca765 Fix fragment caching inherited serializers to use distinct per-serializer caches. 2016-03-28 16:26:51 -05:00
Yohan Robert
5af7d96294 Merge pull request #1618 from bf4/RomanKapitonov-master
Empty collection root key from explicit serializer option
2016-03-27 18:38:14 +02:00
Yohan Robert
edbbf6dad5 Merge pull request #1624 from bf4/fix_warnings
Silence @_routes warnings
2016-03-27 18:07:15 +02:00
Benjamin Fleischer
a74d174420 Include Serializer._type in collection serializer json_key cascade 2016-03-27 10:55:31 -05:00
Roman Kapitonov
2dd0c33461 [FIX] Fetch json key from item serializer if empty collection is passed to collection serializer and each_searializer is specified. 2016-03-27 10:52:25 -05:00
Benjamin Fleischer
2627740806 Silence @_routes warnings 2016-03-27 10:45:57 -05:00
Yohan Robert
33a0f9c806 Merge pull request #1588 from bf4/benchmark_revision_runner
Add benchmark regression runner
2016-03-27 11:24:07 +02:00
Yohan Robert
17711a8d81 Merge pull request #1620 from bf4/fix_warnings
Fix warnings
2016-03-27 10:49:31 +02:00
Benjamin Fleischer
638e8853cc Remove annoying progress reporter 2016-03-26 19:27:33 -05:00
Benjamin Fleischer
fb06a462bb Fix warnings 2016-03-25 10:28:13 -05:00
Yohan Robert
82da04de67 Merge pull request #1478 from bf4/caching_fix
[FIX] Serializers can now be defined *before* Rails initializes and cache store will be correctly set
2016-03-25 11:32:31 +01:00
Benjamin Fleischer
912daa99f3 Merge pull request #1619 from bf4/allow_devs_to_opt_out_of_warnings
Allow devs to opt out of test warnings
2016-03-25 01:25:36 -05:00
Benjamin Fleischer
39623e8ba4 Add missing object context needed for tests to be run alone 2016-03-25 00:20:10 -05:00
Benjamin Fleischer
408daae045 Allow devs to opt out of test warnings 2016-03-25 00:19:20 -05:00
Benjamin Fleischer
dd60a371ae Simplify caching of value of config.perform_caching 2016-03-24 22:22:19 -05:00
Benjamin Fleischer
1230dd95ba Add CHANGELOG [ci skip] 2016-03-24 22:22:19 -05:00
Benjamin Fleischer
c3c69a607a Separate enabling of caching and setting the cache store 2016-03-24 22:20:42 -05:00
Benjamin Fleischer
9953d7abe0 Trigger callback to set serializer#_cache when controller loaded 2016-03-24 22:20:42 -05:00
Benjamin Fleischer
27b514a63b Add missing object context needed for tests to be run alone 2016-03-24 22:20:42 -05:00
Benjamin Fleischer
9ce36904cf Allow devs to opt out of test warnings 2016-03-24 22:20:42 -05:00
Yohan Robert
61412d80ca Merge pull request #1598 from bf4/fix_simplecov
Remove dead code preventing simplecov from running
2016-03-19 01:54:53 +01:00
Yohan Robert
9bd4c22f40 Replace -d by --debug in JRUBY_OPTS for travis
It seems that for coverage to work properly the "--debug" option is
needed when using JRuby.
2016-03-19 01:30:16 +01:00