diff --git a/README.md b/README.md index 80cfd3e93..9cba3920d 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,6 @@ class PostSerializer < ActiveModel::Serializer attributes :title, :body has_many :comments - - url :post end ``` @@ -48,8 +46,6 @@ class CommentSerializer < ActiveModel::Serializer attributes :name, :body belongs_to :post - - url [:post, :comment] end ``` @@ -239,8 +235,6 @@ class PostSerializer < ActiveModel::Serializer has_many :comments has_one :author - - url :post end ``` @@ -251,8 +245,6 @@ class CommentSerializer < ActiveModel::Serializer attributes :name, :body belongs_to :post_id - - url [:post, :comment] end ``` @@ -274,8 +266,6 @@ And you can change the JSON key that the serializer should use for a particular has_many :comments, key: :reviews ``` -The `url` declaration describes which named routes to use while generating URLs -for your JSON. Not every adapter will require URLs. ## Pagination Pagination links will be included in your response automatically as long as the resource is paginated using [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate) and if you are using a ```JSON-API``` adapter. @@ -307,8 +297,6 @@ class PostSerializer < ActiveModel::Serializer attributes :title, :body has_many :comments - - url :post end ``` @@ -332,8 +320,6 @@ class PostSerializer < ActiveModel::Serializer attributes :title, :body has_many :comments - - url :post end ``` diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 07dd1433a..8b4f02ab4 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -31,7 +31,6 @@ class Serializer class << self attr_accessor :_attributes attr_accessor :_attributes_keys - attr_accessor :_urls attr_accessor :_cache attr_accessor :_fragmented attr_accessor :_cache_key @@ -44,7 +43,6 @@ class << self def self.inherited(base) base._attributes = self._attributes.try(:dup) || [] base._attributes_keys = self._attributes_keys.try(:dup) || {} - base._urls = [] base._cache_digest = digest_caller_file(caller.first) super end @@ -86,14 +84,6 @@ def self.cache(options = {}) @_cache_options = (options.empty?) ? nil : options end - def self.url(attr) - @_urls.push attr - end - - def self.urls(*attrs) - @_urls.concat attrs - end - def self.serializer_for(resource, options = {}) if resource.respond_to?(:serializer_class) resource.serializer_class diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index ab3e4d85c..9509411bb 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -40,7 +40,6 @@ class PostSerializer < ActiveModel::Serializer has_many :comments belongs_to :author - url :comments end class CommentSerializer < ActiveModel::Serializer diff --git a/test/fixtures/poro.rb b/test/fixtures/poro.rb index f831296f8..72394e660 100644 --- a/test/fixtures/poro.rb +++ b/test/fixtures/poro.rb @@ -59,8 +59,6 @@ class Profile < Model class ProfileSerializer < ActiveModel::Serializer attributes :name, :description - urls :posts, :comments - def arguments_passed_in? options[:my_options] == :accessible end @@ -68,8 +66,6 @@ def arguments_passed_in? class ProfilePreviewSerializer < ActiveModel::Serializer attributes :name - - urls :posts, :comments end Post = Class.new(Model) @@ -100,7 +96,6 @@ module Spam; end has_many :comments belongs_to :blog belongs_to :author - url :comments def blog Blog.new(id: 999, name: 'Custom blog') diff --git a/test/serializers/urls_test.rb b/test/serializers/urls_test.rb deleted file mode 100644 index d0dc26f16..000000000 --- a/test/serializers/urls_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'test_helper' - -module ActiveModel - class Serializer - class UrlsTest < Minitest::Test - def setup - @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) - @post = Post.new({ title: 'New Post', body: 'Body' }) - @comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' }) - @post.comments = [@comment] - - @profile_serializer = ProfileSerializer.new(@profile) - @post_serializer = PostSerializer.new(@post) - end - - def test_urls_definition - assert_equal([:posts, :comments], @profile_serializer.class._urls) - end - - def test_url_definition - assert_equal([:comments], @post_serializer.class._urls) - end - end - end -end