Commit Graph

667 Commits

Author SHA1 Message Date
Benjamin Fleischer
06fcd34807
Follows https://github.com/rails-api/active_model_serializers/pull/2100 2019-04-23 04:33:56 +06:00
Kyle Keesling
6fbeb9a93e
Fix deprecation warnings on Rails 6
takes into account suggestions from @bf4
2019-03-13 09:52:54 -04:00
Benjamin Fleischer
bb0f9d088d Bump version to 0.10.9 2019-02-08 11:25:53 -06:00
cintamani
15b7974fac
Merge pull request #2288 from cintamani/patch-1
Change the fetch method to deal with recyclable key cache strategy
2019-02-08 12:14:03 +00:00
Krzysztof Rybka
209834dc49 Performance and memory usage fixes (#2309)
* Use select and reject instead of partition.map

* Sort adapters keys in place

* Just select from options

* Add changelog entry
2019-01-29 15:38:11 -06:00
cintamani
141feeb259 Revert "Update caching.rb"
This reverts commit f31430a8185533246638a7cfebba325f0ac9b0fa.
2019-01-29 16:00:18 +00:00
cintamani
427dd05a73 Revert "Update caching.rb"
This reverts commit c6f34eb9e9df86b568b9463e2ea8c26f0f43a838.
2019-01-29 16:00:18 +00:00
cintamani
bd53d9b213 Update caching.rb 2019-01-29 16:00:18 +00:00
cintamani
b0039e3758 Update caching.rb 2019-01-29 16:00:18 +00:00
cintamani
be5fbf3d54 Use #cache_key_with_key when available
In order to keep compatibility between the AMS cache feature and with Rails > 5.1  cache versioning, we have to use the `cache_key_with_version`. 
**NOTE** - This is a quick fix to the issue, if there will be future plans a proper cache versioning with recyclable key needs to be implemented. 

More info: https://github.com/rails-api/active_model_serializers/issues/2287
2019-01-29 16:00:18 +00:00
Benjamin Fleischer
c6c3927e00
Merge pull request #2307 from faucct/bugfix/double-evaluation-of-object
Reevaluation of object
2019-01-10 11:58:27 -06:00
Nikita Sokolov
a39794df5b LazyAssociation#object should not reevaluate reflection values 2019-01-09 09:52:38 +03:00
Krzysztof Rybka
873cf4add2 Add frozen_string_literal pragma to ruby files 2018-12-17 16:54:56 +01:00
Benjamin Fleischer
bc4805cbc1 Bump version to v0.10.8 2018-11-01 16:24:08 -05:00
Benjamin Fleischer
b358271ef5 Note that we dup the entire reflection instance 2018-11-01 14:21:59 -05:00
LongCB
c7e847fc72 Fix thread unsafe behavior 2018-11-01 14:20:47 -05:00
Konstantin Munteanu
572f11b7e0 value is always a link 2018-10-25 09:54:36 +02:00
Konstantin Munteanu
ca6c009273 typos 2018-10-25 09:45:34 +02:00
Konstantin Munteanu
0d3999c36d Support conditions in link statements 2018-10-25 09:45:34 +02:00
Benjamin Fleischer
4b2b9ef730
Merge pull request #2297 from vnbrs/patch-1
Remove unnecessary line break from exception message
2018-10-24 17:02:19 -05:00
Vinicius Brasil
bcf21ea0a6
Remove unnecessary line break from exception message
This removes the unnecessary line break from the exception message. Example:

```
Cannot infer root key from collection type. Please\n
specify the root or each_serializer option, or render a JSON String
```
2018-10-24 14:10:59 -03:00
Dzmitry
db4e5267fd Fix the bug that serializer could not be found if the association's serializer is namespaced but the model is not
[fix #2295]
2018-10-20 15:42:11 +03:00
Fabian Mersch
65313b901b Remove obsolete autoloads 2018-10-11 21:32:12 +02:00
Fabian Mersch
2a8b9f4105 Eager load modules on boot
Using ActiveModelSerializers with a threaded web server eg. Puma
uninitialized constant errors are thrown. Leaving this article for
reference:
http://blog.plataformatec.com.br/2012/08/eager-loading-for-greater-good/.
2018-10-11 21:32:12 +02:00
quake wang
a9ea81a831 resolve collection cache error 2017-11-19 11:33:48 -06:00
Benjamin Fleischer
ca531789c3 Bump to 0.10.7; update changelog 2017-11-14 20:50:51 -06:00
Benjamin Fleischer
3dd6cccb4d Fix 0.10.6 regression; make using belongs_to on self opt-in 2017-11-13 08:36:23 -06:00
Benjamin Fleischer
9745a2f735 Fix: ResourceIdentifier.for_type_with_id can serialize unpersisted resources 2017-10-31 14:47:55 -05:00
Benjamin Fleischer
5916014b48 Fix: resource object identifier with nil id excludes id 2017-10-31 14:34:30 -05:00
Benjamin Fleischer
e3480345e3
Merge pull request #2211 from rails-api/polymorphic_relationships_require_serializer_instance
JSON:API relationship tests no longer show v0.10.5 regression
2017-10-31 13:49:18 -05:00
Joe Meredith
c6a14c9eac Fail if collection type cannot be inferred with json adapter (#2210) 2017-10-30 13:37:37 -04:00
Benjamin Fleischer
a0de45a4d8 Fix JSON:API: for_type_and_id should always inflect_type
Should Serializer._type ever be inflected?
Right now, it won't be, but association.serializer._type will be inflected.

That's the current behavior.
2017-10-29 21:23:48 -05:00
Benjamin Fleischer
cf29db34c6 Fix JSON:API polymorphic type regression from v0.10.5 2017-10-29 20:15:15 -05:00
Benjamin Fleischer
5e1e138d47 Refactor ResourceIdentifier 2017-10-29 17:13:34 -05:00
Dennis Stumm
4d7c2457d7 Fix deserialization of polymorphic relationships (#2200)
* Classify the relationship type for polymorphic associations
2017-10-07 17:03:38 -05:00
Benjamin Fleischer
6a7d864605 Fix CI on 0-10-stable (#2181)
* Loosen pry, pry-byebug depencency

```
Resolving dependencies...
byebug-9.1.0 requires ruby version >= 2.2.0, which is
incompatible with the current version, ruby 2.1.10p492
```

* Adjust nokogiri version constraint for CI

Update appveyor Ruby to 2.3 to work around:

```
Gem::InstallError: nokogiri requires Ruby version < 2.5, >= 2.2.

An error occurred while installing nokogiri (1.8.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.8.0'` succeeds before bundling.
```

and not 2.4 since:

https://ci.appveyor.com/project/bf4/active-model-serializers/build/1.0.1052-fix_ci/job/0q3itabsnvnxr83u

```
nokogiri-1.6.8.1-x86-mingw32 requires ruby version < 2.4, which is incompatible with the current version, ruby 2.4.1p111
```

* Include rails gem in Gemfile

(For Rails5)

In Rails5, checking for Rails::Railtie is better

* Rails5 test env requires Rails.application.class.name

rails-42d09f6b49da/railties/lib/rails/application.rb

```ruby
def secret_key_base
  if Rails.env.test? || Rails.env.development?
  Digest::MD5.hexdigest self.class.name
```

* Reformat exclude matrix to be easier to read

* Simplify jruby-travis config per rails/rails

* Organize .travis.yml per rails/rails

* Allow JRuby failure on Rails 5+; try rails-5 db adapter branch

https://github.com/jruby/activerecord-jdbc-adapter/issues/708

```
uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
```

see https://travis-ci.org/rails-api/active_model_serializers/jobs/277112008
2017-09-19 05:27:02 -04:00
Geremia Taglialatela
4f78319219 Fix RuboCop offence 2017-09-17 19:33:05 +02:00
Darren Cheng
967ff8dcc0 Patch Enumerator.new ArgumentError. 2017-08-28 19:38:08 -07:00
Alexandre de Oliveira
1e4d117b99 Merge pull request #2149 from mecampbellsoup/more-pagination-links-by-default
Always include self, first, last pagination links
2017-06-14 15:47:30 -03:00
mecampbellsoup
402883d84f Fix Travis lint offenses 2017-06-14 13:35:00 -04:00
mecampbellsoup
e4b3224c64 Fix indentation mismatch 2017-06-14 12:53:38 -04:00
mecampbellsoup
b7442e741c Use symbolized keys for json hash
They will be converted to strings when rendered as JSON.
2017-06-14 12:52:29 -04:00
mecampbellsoup
92e9a66e97 Amend tests to always include all pagination keys 2017-06-13 12:35:55 -04:00
mecampbellsoup
16e5204eab Always include pagination keys but set null values when not needed 2017-06-13 12:09:00 -04:00
mecampbellsoup
7387266c37 Always display self, first, last pagination links 2017-06-05 17:26:41 -04:00
Christian
a89e78c655 Allow referencing sideloaded include by key. (#2136)
* If a `key` is set on the reflection use the `key` instead of `name`.
This ensures that associations with a key set are still included.
2017-05-18 15:59:14 -05:00
Grey Baker
be7ee70376 Allow serialized ID to be overwritten for belongs-to relationships
If the `id` attribute for a class isn't taken directly from the object when
serializing it, it may be desirible for other classes that serialize a
relationship with that class to overwrite the relationship IDs they serialize.

For example, suppose we have:

```(ruby)
class Repo < Model
  attributes :id, :github_id, :name
  associations :configs
end

class Config < Model
  attributes :id
  belongs_to :repo
end

class RepoSerializer < ActiveModel::Serializer
  attributes :id, :name

  has_many :update_configs

  def id
    object.github_id
  end
end

class ConfigSerializer < ActiveModel::Serializer
  attributes :id
  belongs_to :repo
end
```

In the above example, serializing a list of `Repo`s will give the `github_id`
for each one, but serializing a `Config` will give the `id` for its parent repo.

Ideally AMS would inspect the `RepoSerializer` when serializing the `Config`,
and realise it can't just output the foreign key. Unfortunately, getting the
serialization class for the child repo currently requires loading the record
(via evaluating `lazy_assocation`), and loses the performance benefit of the
existing `belongs_to?` path. Instead, I've opted to use
`read_attribute_for_serialization` instead of `object.send` to fetch the
serialized foreign key. This allows the serialized relationship ID to be
overwritten using

```(ruby)
class ConfigSerializer < ActiveModel::Serializer
  ...

  def repo_id
    object.repo.github_id
  end
end
```
2017-05-13 15:22:18 +01:00
Benjamin Fleischer
dff621e174 Bump to v0.10.6 2017-05-01 10:59:14 -05:00
Benjamin Fleischer
96028a7b99 Document new reflection options; support :foreign_key 2017-05-01 10:18:13 -05:00
Benjamin Fleischer
73eae19b3d Return null resource object identifier for blank id
Also, fix test where attributes were included when id was ""

```
  1) Failure:
  ActionController::Serialization::AdapterSelectorTest#test_render_using_adapter_override
  [test/action_c$ntroller/adapter_selector_test.rb:53]:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -"{\"data\":{\"id\":\"\",\"type\":\"profiles\",\"attributes\":{\"name\":\"Name 1\",\"description\":\"Description 1\"}}}"
  +"{\"data\":null}"
```
2017-04-30 23:28:08 -05:00