Skip to content

Commit

Permalink
Merge branch 'master' into 0-10-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Mar 7, 2017
2 parents f353ded + 28b8e3d commit 01d4f04
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 49 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ rvm:
- 2.2.6
- 2.3.3
- ruby-head
- jruby-9.0.4.0
- jruby-9.1.5.0 # is precompiled per http://rubies.travis-ci.org/
- jruby-head

jdk:
- oraclejdk8

before_install:
- gem update --system
- rvm @global do gem uninstall bundler -a -x
- rvm @global do gem install bundler -v 1.13.7
install: bundle install --path=vendor/bundle --retry=3 --jobs=3
cache:
directories:
Expand All @@ -35,13 +39,13 @@ matrix:
exclude:
- rvm: 2.1
env: RAILS_VERSION=master
- rvm: jruby-9.0.4.0
- rvm: jruby-9.1.5.0
env: RAILS_VERSION=master
- rvm: jruby-head
env: RAILS_VERSION=master
- rvm: 2.1
env: RAILS_VERSION=5.0
- rvm: jruby-9.0.4.0
- rvm: jruby-9.1.5.0
env: RAILS_VERSION=5.0
- rvm: jruby-head
env: RAILS_VERSION=5.0
Expand Down
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.10.x

### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...master)
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...master)

Breaking changes:

Expand All @@ -14,8 +14,29 @@ Fixes:

Misc:

### [v0.10.5 (2017-03-07)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...v0.10.5)

Breaking changes:

Features:

- [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) ActiveModelSerializers::Model#attributes. Originally in [#1982](https://github.com/rails-api/active_model_serializers/pull/1982). (@bf4)
- [#2057](https://github.com/rails-api/active_model_serializers/pull/2057)
Update version constraint for jsonapi-renderer to `['>= 0.1.1.beta1', '< 0.2']`
(@jaredbeck)

Fixes:

- [#2022](https://github.com/rails-api/active_model_serializers/pull/2022) Mutation of ActiveModelSerializers::Model now changes the attributes. Originally in [#1984](https://github.com/rails-api/active_model_serializers/pull/1984). (@bf4)

Misc:

- [#2055](https://github.com/rails-api/active_model_serializers/pull/2055)
Replace deprecated dependency jsonapi with jsonapi-renderer. (@jaredbeck)
- [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) Make test attributes explicit. Tests have Model#associations. (@bf4)
- [#1981](https://github.com/rails-api/active_model_serializers/pull/1981) Fix relationship link documentation. (@groyoh)
- [#2035](https://github.com/rails-api/active_model_serializers/pull/2035) Document how to disable the logger. (@MSathieu)
- [#2039](https://github.com/rails-api/active_model_serializers/pull/2039) Documentation fixes. (@biow0lf)

### [v0.10.4 (2017-01-06)](https://github.com/rails-api/active_model_serializers/compare/v0.10.3...v0.10.4)

Expand Down
2 changes: 1 addition & 1 deletion active_model_serializers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
# 'minitest'
# 'thread_safe'

spec.add_runtime_dependency 'jsonapi', '0.1.1.beta6'
spec.add_runtime_dependency 'jsonapi-renderer', ['>= 0.1.1.beta1', '< 0.2']
spec.add_runtime_dependency 'case_transform', '>= 0.2'

spec.add_development_dependency 'activerecord', rails_versions
Expand Down
12 changes: 9 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '{build}'
version: 1.0.{build}-{branch}

skip_tags: true

Expand All @@ -7,17 +7,23 @@ environment:
matrix:
- ruby_version: "Ruby21"
- ruby_version: "Ruby21-x64"
- ruby_version: "jruby-9.0.0.0"

cache:
- vendor/bundle

install:
- SET PATH=C:\%ruby_version%\bin;%PATH%
- gem install bundler
- gem update --system
- gem uninstall bundler -a -x
- gem install bundler -v 1.13.7
- bundle env
- bundle install --path=vendor/bundle --retry=3 --jobs=3

before_test:
- ruby -v
- gem -v
- bundle -v

test_script:
- bundle exec rake ci

Expand Down
7 changes: 7 additions & 0 deletions docs/general/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ You may customize the logger in an initializer, for example:
```ruby
ActiveModelSerializers.logger = Logger.new(STDOUT)
```

You can also disable the logger, just put this in `config/initializers/active_model_serializers.rb`:

```ruby
require 'active_model_serializers'
ActiveSupport::Notifications.unsubscribe(ActiveModelSerializers::Logging::RENDER_EVENT)
```
6 changes: 3 additions & 3 deletions docs/general/serializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ With the `:json` adapter, the previous serializer would be rendered as:
link :self do
href "https://example.com/link_author/#{object.id}"
end
link :author { link_author_url(object) }
link :link_authors { link_authors_url }
link(:author) { link_author_url(object) }
link(:link_authors) { link_authors_url }
link :other, 'https://example.com/resource'
link :posts { link_author_posts_url(object) }
link(:posts) { link_author_posts_url(object) }
```

#### #object
Expand Down
26 changes: 13 additions & 13 deletions docs/howto/add_pagination_links.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ If you are using `JSON` adapter, pagination links will not be included automatic
Add this method to your base API controller.

```ruby
def pagination_dict(object)
def pagination_dict(collection)
{
current_page: object.current_page,
next_page: object.next_page,
prev_page: object.prev_page, # use object.previous_page when using will_paginate
total_pages: object.total_pages,
total_count: object.total_count
current_page: collection.current_page,
next_page: collection.next_page,
prev_page: collection.prev_page, # use collection.previous_page when using will_paginate
total_pages: collection.total_pages,
total_count: collection.total_count
}
end
```
Expand Down Expand Up @@ -117,18 +117,18 @@ ex.
You can also achieve the same result if you have a helper method that adds the pagination info in the meta tag. For instance, in your action specify a custom serializer.

```ruby
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@post)
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@posts)
```

```ruby
#expects pagination!
def meta_attributes(resource, extra_meta = {})
def meta_attributes(collection, extra_meta = {})
{
current_page: resource.current_page,
next_page: resource.next_page,
prev_page: resource.prev_page, # use resource.previous_page when using will_paginate
total_pages: resource.total_pages,
total_count: resource.total_count
current_page: collection.current_page,
next_page: collection.next_page,
prev_page: collection.prev_page, # use collection.previous_page when using will_paginate
total_pages: collection.total_pages,
total_count: collection.total_count
}.merge(extra_meta)
end
```
Expand Down
5 changes: 3 additions & 2 deletions docs/howto/outside_controller_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ In ActiveModelSerializers versions 0.10 or later, serializing resources outside
# Create our resource
post = Post.create(title: "Sample post", body: "I love Active Model Serializers!")

# Optional options parameters
options = {}
# Optional options parameters for both the serializer and instance
options = {serializer: PostDetailedSerializer, username: 'sample user'}

# Create a serializable resource instance
serializable_resource = ActiveModelSerializers::SerializableResource.new(post, options)
Expand All @@ -20,6 +20,7 @@ serializable_resource = ActiveModelSerializers::SerializableResource.new(post, o
model_json = serializable_resource.as_json
```
The object that is passed to `ActiveModelSerializers::SerializableResource.new` can be a single resource or a collection.
The additional options are the same options that are passed [through controllers](../general/rendering.md#explicit-serializer).

### Looking up the Serializer for a Resource

Expand Down
28 changes: 28 additions & 0 deletions docs/howto/serialize_poro.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,32 @@ end

The default serializer would be `MyModelSerializer`.

*IMPORTANT*: There is a surprising behavior (bug) in the current implementation of ActiveModelSerializers::Model that
prevents an accessor from modifying attributes on the instance. The fix for this bug
is a breaking change, so we have made an opt-in configuration.

New applications should set:

```ruby
ActiveModelSerializers::Model.derive_attributes_from_names_and_fix_accessors
```

Existing applications can use the fix *and* avoid breaking changes
by making a superclass for new models. For example:

```ruby
class SerializablePoro < ActiveModelSerializers::Model
derive_attributes_from_names_and_fix_accessors
end
```

So that `MyModel` above would inherit from `SerializablePoro`.

`derive_attributes_from_names_and_fix_accessors` prepends the `DeriveAttributesFromNamesAndFixAccessors`
module and does the following:

- `id` will *always* be in the attributes. (This is until we separate out the caching requirement for POROs.)
- Overwrites the `attributes` method to that it only returns declared attributes.
`attributes` will now be a frozen hash with indifferent access.

For more information, see [README: What does a 'serializable resource' look like?](../../README.md#what-does-a-serializable-resource-look-like).
2 changes: 1 addition & 1 deletion docs/howto/upgrade_from_0_8_to_0_10.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ end

```
Add this class to your app however you see fit. This is the class that your existing serializers
that inherit from `ActiveMode::Serializer` should inherit from.
that inherit from `ActiveModel::Serializer` should inherit from.

### 3. Add `ActiveModel::V08::CollectionSerializer`
```ruby
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveModel
class Serializer
VERSION = '0.10.4'.freeze
VERSION = '0.10.5'.freeze
end
end
19 changes: 0 additions & 19 deletions lib/active_model_serializers/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ def self.included(base)
base.attributes :id
end

# Override the initialize method so that attributes aren't processed.
#
# @param attributes [Hash]
def initialize(attributes = {})
@errors = ActiveModel::Errors.new(self)
super
end

# Override the +attributes+ method so that the hash is derived from +attribute_names+.
#
# The the fields in +attribute_names+ determines the returned hash.
Expand Down Expand Up @@ -133,16 +125,5 @@ def cache_key
"#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
].compact)
end

# The following methods are needed to be minimally implemented for ActiveModel::Errors
# :nocov:
def self.human_attribute_name(attr, _options = {})
attr
end

def self.lookup_ancestors
[self]
end
# :nocov:
end
end
4 changes: 2 additions & 2 deletions lib/active_model_serializers/test/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def call
attr_reader :document_store

def controller_path
request.filtered_parameters[:controller]
request.filtered_parameters.with_indifferent_access[:controller]
end

def action
request.filtered_parameters[:action]
request.filtered_parameters.with_indifferent_access[:action]
end

def schema_directory
Expand Down
2 changes: 2 additions & 0 deletions test/support/rails_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module ActiveModelSerializers
config.active_support.test_order = :random
config.action_controller.perform_caching = true
config.action_controller.cache_store = :memory_store

config.filter_parameters += [:password]
end

app.routes.default_url_options = { host: 'example.com' }
Expand Down

0 comments on commit 01d4f04

Please sign in to comment.