active_model_serializers 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94274a9d3a573ae8f656719aef33825cabb68673
4
- data.tar.gz: b1d614a90149ec109b67e963464c232d0b5ed3f1
3
+ metadata.gz: 6a3bbd628ea9a29ba5746a2d18be35b679992e82
4
+ data.tar.gz: f8b574ecfb45e609b89beba0f7d729e22bbe1fe9
5
5
  SHA512:
6
- metadata.gz: cc3140d1676014d8ce4aa0add253d247c55652a689cb83e7f7f7a71a81ae8d7c601fc5e2d261d415e243857a479a15156d0a84a67beb1c72475ef51c063cdfca
7
- data.tar.gz: cfc92ac9bb7dfca07cebdd32ef4a120aa5784cc7f1a6bfc8a65900b553be736b174b6bbf22fb7ebd55e8295ea1d118373245396e3c0ac883e954ab27e925bca2
6
+ metadata.gz: 59beee726674129f3fa5445858efc7b7c4ca7eefe28bb2923f7a975196406e17daab06a9e29ecbc4afdeb438cb9d214a277db1ff44b966521d8aab14d99af541
7
+ data.tar.gz: a392e8ebfc339b793844fc3140f03d57d05d4ce6c2e4aaef80290dbfa0b84321b35fbaecacf077560177c91645a6af87a6827184e91678c7fc89489a14551f06
@@ -1,28 +1,34 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - 2.0.0
7
- - ree
8
- - jruby-18mode
4
+ # - 1.8.7
5
+ # - ree
6
+ # - jruby-18mode
7
+ # - 1.9.2
8
+ # - 1.9.3
9
9
  - jruby-19mode
10
+ - 2.0.0
11
+ - 2.1
12
+ - 2.2
10
13
  - rbx-2
11
- gemfile:
12
- - Gemfile
13
- - Gemfile.edge
14
+ install: bundle install --path=vendor/bundle --retry=3 --jobs=3
15
+ cache:
16
+ directories:
17
+ - vendor/bundle
18
+ script:
19
+ - bundle exec rake ci
20
+ env:
21
+ # - "RAILS_VERSION=3.0"
22
+ # - "RAILS_VERSION=3.1"
23
+ # - "RAILS_VERSION=3.2"
24
+ - "RAILS_VERSION=4.0"
25
+ - "RAILS_VERSION=4.1"
26
+ - "RAILS_VERSION=4.2"
27
+ # - "RAILS_VERSION=master"
14
28
  matrix:
15
- allow_failures:
16
- - gemfile: Gemfile.edge
17
29
  exclude:
18
- # Edge Rails is only compatible with 1.9.3
19
- - gemfile: Gemfile.edge
20
- rvm: 1.8.7
21
- - gemfile: Gemfile.edge
22
- rvm: 1.9.2
23
- - gemfile: Gemfile.edge
24
- rvm: ree
25
- - gemfile: Gemfile.edge
26
- rvm: jruby-18mode
27
- - gemfile: Gemfile.edge
28
- rvm: rbx-18mode
30
+ # - rvm: 1.8.7
31
+ # - ree
32
+ # - jruby-18mode
33
+ # - rvm: 1.9.2
34
+ fast_finish: true
@@ -1,10 +1,34 @@
1
1
  # UNRELEASED
2
2
 
3
- # VERSION 0.8.1
3
+ ### v0.8.4 (2017-09-19)
4
+
5
+ - [#1675](https://github.com/rails-api/active_model_serializers/pull/1675) Fix memory leak with :scope_name.
6
+ Supplying :scope_name causes `ActiveModel::Serializer#initialize` to
7
+ define a method on the class, which retains a reference to the
8
+ serializer instance. (@Botje)
9
+ - [#1276](https://github.com/rails-api/active_model_serializers/pull/1276) Fix serializers were never including associations on cache hits (@kieran)
10
+ - [#1503](https://github.com/rails-api/active_model_serializers/pull/1503) Add documentation with example to `README` for POROs and alternative ORMs (@feministy)
11
+ - [#1376](https://github.com/rails-api/active_model_serializers/pull/1376) Test against Rails >= 4.0, Ruby >= 1.9.3 and remove Ruby 1.8 and 1.9.2 support (@bf4, @mhuggins)
12
+
13
+ ### v0.8.3 (2014-12-10)
14
+ - [#753](https://github.com/rails-api/active_model_serializers/pull/753) Test against Ruby 2.2 on Travis CI (@tricknotes)
15
+ - [#745](https://github.com/rails-api/active_model_serializers/pull/745) Missing a word (@jockee)
16
+
17
+ ### v0.8.2 (2014/09/01 21:00 +00:00)
18
+ - [#612](https://github.com/rails-api/active_model_serializers/pull/612) Feature/adapter (@bolshakov)
19
+ * adds adapters pattern
20
+ - [#615](https://github.com/rails-api/active_model_serializers/pull/615) Rails does not support const_defined? in development mode (@tpitale)
21
+ - [#613](https://github.com/rails-api/active_model_serializers/pull/613) README: typo fix on attributes (@spk)
22
+ - [#614](https://github.com/rails-api/active_model_serializers/pull/614) Fix rails 4.0.x build. (@arthurnn)
23
+ - [#610](https://github.com/rails-api/active_model_serializers/pull/610) ArraySerializer (@bolshakov)
24
+ - [#607](https://github.com/rails-api/active_model_serializers/pull/607) ruby syntax highlights (@zigomir)
25
+ - [#602](https://github.com/rails-api/active_model_serializers/pull/602) Add DSL for associations (@JordanFaust)
26
+
27
+ ### 0.8.1 (May 6, 2013)
4
28
 
5
29
  * Fix bug whereby a serializer using 'options' would blow up.
6
30
 
7
- # VERSION 0.8.0
31
+ ### 0.8.0 (May 5, 2013)
8
32
 
9
33
  * Attributes can now have optional types.
10
34
 
@@ -40,7 +64,7 @@
40
64
  * Pass through serialization options (such as `:include`) when a model
41
65
  has no serializer defined.
42
66
 
43
- # VERSION 0.7.0
67
+ ## [0.7.0 (March 6, 2013)](https://github.com/rails-api/active_model_serializers/commit/fabdc621ff97fbeca317f6301973dd4564b9e695)
44
68
 
45
69
  * ```embed_key``` option to allow embedding by attributes other than IDs
46
70
  * Fix rendering nil with custom serializer
@@ -50,7 +74,7 @@
50
74
  * Serializer Reloading via ActiveSupport::DescendantsTracker
51
75
  * Reduce double map to once; Fixes datamapper eager loading.
52
76
 
53
- # VERSION 0.6.0
77
+ ## 0.6.0 (October 22, 2012)
54
78
 
55
79
  * Serialize sets properly
56
80
  * Add root option to ArraySerializer
@@ -61,7 +85,18 @@
61
85
  * Allow serialization_scope to be disabled with serialization_scope nil
62
86
  * Array serializer should support pure ruby objects besides serializers
63
87
 
64
- # VERSION 0.5.0 (May 16, 2012)
88
+ ## 0.05.x
89
+
90
+ ### [0.5.2 (June 5, 2012)](https://github.com/rails-api/active_model_serializers/commit/615afd125c260432d456dc8be845867cf87ea118#diff-0c5c12f311d3b54734fff06069efd2ac)
91
+
92
+ ### [0.5.1 (May 23, 2012)](https://github.com/rails-api/active_model_serializers/commit/00194ec0e41831802fcbf893a34c0bb0853ebe14#diff-0c5c12f311d3b54734fff06069efd2ac)
93
+
94
+ ### [0.5.0 (May 16, 2012)](https://github.com/rails-api/active_model_serializers/commit/33d4842dcd35c7167b0b33fc0abcf00fb2c92286)
65
95
 
66
96
  * First tagged version
67
97
  * Changes generators to always generate an ApplicationSerializer
98
+
99
+ ## [0.1.0 (December 21, 2011)](https://github.com/rails-api/active_model_serializers/commit/1e0c9ef93b96c640381575dcd30be07ac946818b)
100
+
101
+ ## First Commit as [Rails Serializers 0.0.1](https://github.com/rails-api/active_model_serializers/commit/d72b66d4c5355b0ff0a75a04895fcc4ea5b0c65e)
102
+ (December 1, 2011).
data/Gemfile CHANGED
@@ -2,3 +2,37 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify gem dependencies in active_model_serializers.gemspec
4
4
  gemspec
5
+
6
+ version = ENV['RAILS_VERSION'] || '4.0'
7
+
8
+ if version == 'master'
9
+ gem 'rack', github: 'rack/rack'
10
+ gem 'arel', github: 'rails/arel'
11
+ git 'https://github.com/rails/rails.git' do
12
+ gem 'railties'
13
+ gem 'activesupport'
14
+ gem 'activemodel'
15
+ gem 'actionpack'
16
+ gem 'activerecord', group: :test
17
+ # Rails 5
18
+ gem 'actionview'
19
+ end
20
+ else
21
+ gem_version = "~> #{version}.0"
22
+ gem 'railties', gem_version
23
+ gem 'activesupport', gem_version
24
+ gem 'activemodel', gem_version
25
+ gem 'actionpack', gem_version
26
+ gem 'activerecord', gem_version, group: :test
27
+ end
28
+
29
+ # https://github.com/bundler/bundler/blob/89a8778c19269561926cea172acdcda241d26d23/lib/bundler/dependency.rb#L30-L54
30
+ @windows_platforms = [:mswin, :mingw, :x64_mingw]
31
+
32
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
33
+ gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
34
+
35
+ # JRuby versions before 9.x report their version as "1.9.x" or lower, so lock these to an older version of mime-types
36
+ if defined?(JRUBY_VERSION) and Gem::ruby_version < Gem::Version.new("2.0.0")
37
+ gem 'mime-types', '< 3'
38
+ end
data/README.md CHANGED
@@ -45,18 +45,35 @@ the serializer generator:
45
45
  $ rails g serializer post
46
46
  ```
47
47
 
48
- ### Support for PORO's and other ORM's.
48
+ ### Support for POROs and other ORMs.
49
49
 
50
50
  Currently `ActiveModel::Serializers` adds serialization support to all models
51
- that descend from `ActiveRecord` or include `Mongoid::Document`. If you are
52
- using another ORM, or if you are using objects that are `ActiveModel`
53
- compliant but do not descend from `ActiveRecord` or include
54
- `Mongoid::Document`, you must add an include statement for
55
- `ActiveModel::SerializerSupport` to make models serializable. If you
56
- also want to make collections serializable, you should include
51
+ that descend from `ActiveRecord` or include `Mongoid::Document`. If you are:
52
+
53
+ - using another ORM, or
54
+ - using objects that are `ActiveModel` compliant but do not descend from
55
+ `ActiveRecord` *or* include `Mongoid::Document`
56
+
57
+ You must add an include statement for `ActiveModel::SerializerSupport` to
58
+ make models serializable.
59
+
60
+ If you also want to make collections serializable, you should include
57
61
  `ActiveModel::ArraySerializerSupport` into your ORM's
58
62
  relation/criteria class.
59
63
 
64
+ Example model (`app/models/avatar.rb`):
65
+
66
+ ```ruby
67
+ class Avatar
68
+ include ActiveModel::SerializerSupport
69
+ # etc, etc
70
+ end
71
+ ```
72
+
73
+ If your classes follow the naming conventions prescribed by `ActiveModel`,
74
+ you don't need to do anything different in your controller to render the
75
+ serialized json.
76
+
60
77
  # ActiveModel::Serializer
61
78
 
62
79
  All new serializers descend from ActiveModel::Serializer
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.libs << 'lib'
8
8
  t.libs << 'test'
9
9
  t.pattern = 'test/**/*_test.rb'
10
+ t.ruby_opts = ['-r./test/test_helper.rb']
10
11
  t.verbose = true
11
12
  end
12
13
 
@@ -16,3 +17,6 @@ task :bench do
16
17
  end
17
18
 
18
19
  task :default => :test
20
+
21
+ desc 'CI test task'
22
+ task :ci => :default
@@ -0,0 +1,27 @@
1
+ version: '{build}'
2
+
3
+ skip_tags: true
4
+
5
+ environment:
6
+ matrix:
7
+ - ruby_version: "200"
8
+ - ruby_version: "200-x64"
9
+ - ruby_version: "21"
10
+ - ruby_version: "21-x64"
11
+
12
+ cache:
13
+ - vendor/bundle
14
+
15
+ install:
16
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
17
+ - ruby --version
18
+ - gem --version
19
+ - gem install bundler
20
+ - bundler --version
21
+ - bundle platform
22
+ - bundle install --path=vendor/bundle --retry=3 --jobs=3
23
+
24
+ test_script:
25
+ - bundle exec rake ci
26
+
27
+ build: off
@@ -294,9 +294,7 @@ module ActiveModel
294
294
 
295
295
  scope_name = @options[:scope_name]
296
296
  if scope_name && !respond_to?(scope_name)
297
- self.class.class_eval do
298
- define_method scope_name, lambda { scope }
299
- end
297
+ self.singleton_class.send :alias_method, scope_name, :scope
300
298
  end
301
299
  end
302
300
 
@@ -353,13 +351,16 @@ module ActiveModel
353
351
  # Returns a hash representation of the serializable
354
352
  # object without the root.
355
353
  def serializable_hash
356
- if perform_caching?
354
+ @node = if perform_caching?
357
355
  cache.fetch expand_cache_key([self.class.to_s.underscore, cache_key, 'serializable-hash']) do
358
356
  _serializable_hash
359
357
  end
360
358
  else
361
359
  _serializable_hash
362
360
  end
361
+
362
+ include_associations! if @object.present? && _embed
363
+ @node
363
364
  end
364
365
 
365
366
  def include_associations!
@@ -476,9 +477,7 @@ module ActiveModel
476
477
 
477
478
  def _serializable_hash
478
479
  return nil if @object.nil?
479
- @node = attributes
480
- include_associations! if _embed
481
- @node
480
+ attributes
482
481
  end
483
482
 
484
483
  def perform_caching?
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Serializer
3
- VERSION = "0.8.3"
3
+ VERSION = "0.8.4"
4
4
  end
5
5
  end
@@ -35,6 +35,42 @@ class CachingTest < ActiveModel::TestCase
35
35
  end
36
36
  end
37
37
 
38
+ class Parent
39
+ def id
40
+ 'parent1'
41
+ end
42
+
43
+ def name
44
+ 'Kieran'
45
+ end
46
+
47
+ def children
48
+ [ Child.new ]
49
+ end
50
+
51
+ def read_attribute_for_serialization(name)
52
+ send name
53
+ end
54
+ end
55
+
56
+ class Child
57
+ def id
58
+ 'child1'
59
+ end
60
+
61
+ def name
62
+ 'Joshua'
63
+ end
64
+
65
+ def parent
66
+ Parent.new
67
+ end
68
+
69
+ def read_attribute_for_serialization(name)
70
+ send name
71
+ end
72
+ end
73
+
38
74
  def test_serializers_have_a_cache_store
39
75
  ActiveModel::Serializer.cache = NullStore.new
40
76
 
@@ -93,4 +129,49 @@ class CachingTest < ActiveModel::TestCase
93
129
  assert_equal instance.serializable_array, serializer.cache.read('array_serializer/cache-key/serializable-array')
94
130
  assert_equal instance.to_json, serializer.cache.read('array_serializer/cache-key/to-json')
95
131
  end
132
+
133
+ def test_cached_serializers_return_associations
134
+
135
+ child_serializer = Class.new(ActiveModel::Serializer) do
136
+ cached true
137
+ attributes :name
138
+
139
+ def self.to_s
140
+ 'child_serializer'
141
+ end
142
+
143
+ def cache_key
144
+ object.name
145
+ end
146
+ end
147
+
148
+ parent_serializer = Class.new(ActiveModel::Serializer) do
149
+ cached true
150
+ attributes :name
151
+
152
+ has_many :children, serializer: child_serializer, embed: :ids, include: true
153
+
154
+ def self.to_s
155
+ 'parent_serializer'
156
+ end
157
+
158
+ def cache_key
159
+ object.name
160
+ end
161
+ end
162
+
163
+
164
+ parent_serializer.cache = NullStore.new
165
+ child_serializer.cache = NullStore.new
166
+
167
+ instance = parent_serializer.new Parent.new, root: :parent
168
+
169
+ initial_keys = instance.as_json.keys
170
+
171
+ assert_equal(initial_keys, [:children, :parent])
172
+
173
+ cached_keys = instance.as_json.keys
174
+
175
+ assert_equal(cached_keys, [:children, :parent])
176
+ end
96
177
  end
@@ -242,9 +242,13 @@ class RenderJsonTest < ActionController::TestCase
242
242
 
243
243
  def test_render_json_with_callback
244
244
  get :render_json_hello_world_with_callback
245
- assert_equal 'alert({"hello":"world"})', @response.body
246
- # For JSONP, Rails 3 uses application/json, but Rails 4 uses text/javascript
247
- assert_match %r(application/json|text/javascript), @response.content_type.to_s
245
+ if Rails::VERSION::MAJOR == 3
246
+ assert_equal 'alert({"hello":"world"})', @response.body
247
+ assert_match %r(application/json), @response.content_type.to_s
248
+ else
249
+ assert_equal '/**/alert({"hello":"world"})', @response.body
250
+ assert_match %r(text/javascript), @response.content_type.to_s
251
+ end
248
252
  end
249
253
 
250
254
  def test_render_json_with_custom_content_type
@@ -1370,6 +1370,7 @@ class SerializerTest < ActiveModel::TestCase
1370
1370
  end
1371
1371
 
1372
1372
  data_class = Class.new do
1373
+ include ActiveModel::Serializers::JSON
1373
1374
  attr_accessor :title, :body
1374
1375
  end
1375
1376
 
@@ -199,6 +199,7 @@ class SomeSerializer < ActiveModel::Serializer
199
199
  end
200
200
 
201
201
  class SomeObject < Struct.new(:some)
202
+ include ActiveModel::Serializers::JSON
202
203
  end
203
204
 
204
205
  # Set up some classes for polymorphic testing
@@ -1,13 +1,36 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
3
 
4
+ require 'rails'
5
+ require 'action_controller'
6
+ require 'action_controller/test_case'
7
+ require 'action_controller/railtie'
8
+ require 'active_support/json'
9
+
10
+ gem 'minitest'
11
+ require 'minitest/autorun'
12
+ if defined?(Minitest::Test)
13
+ $minitest_version = 5 # rubocop:disable Style/GlobalVars
14
+ # Minitest 5
15
+ # https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
16
+ # https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
17
+ else
18
+ $minitest_version = 4 # rubocop:disable Style/GlobalVars
19
+ # Minitest 4
20
+ # https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/autorun.rb
21
+ # https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787
22
+ # Ensure backward compatibility with Minitest 4
23
+ Minitest = MiniTest unless defined?(Minitest)
24
+ Minitest::Test = MiniTest::Unit::TestCase
25
+ def Minitest.after_run(&block)
26
+ MiniTest::Unit.after_tests(&block)
27
+ end
28
+ end
29
+
30
+
4
31
  require "pry"
5
32
 
6
33
  require "active_model_serializers"
7
- require "active_support/json"
8
- require "minitest/autorun"
9
-
10
- require 'rails'
11
34
 
12
35
  module TestHelper
13
36
  Routes = ActionDispatch::Routing::RouteSet.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-10 00:00:00.000000000 Z
12
+ date: 2017-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -80,11 +80,11 @@ files:
80
80
  - CHANGELOG.md
81
81
  - DESIGN.textile
82
82
  - Gemfile
83
- - Gemfile.edge
84
83
  - MIT-LICENSE.txt
85
84
  - README.md
86
85
  - Rakefile
87
86
  - active_model_serializers.gemspec
87
+ - appveyor.yml
88
88
  - bench/perf.rb
89
89
  - cruft.md
90
90
  - lib/action_controller/serialization.rb
@@ -128,9 +128,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.6.13
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Bringing consistency and object orientation to model serialization. Works
135
135
  great for client-side MVC frameworks!
136
- test_files: []
136
+ test_files:
137
+ - test/array_serializer_test.rb
138
+ - test/association_test.rb
139
+ - test/caching_test.rb
140
+ - test/generators_test.rb
141
+ - test/no_serialization_scope_test.rb
142
+ - test/serialization_scope_name_test.rb
143
+ - test/serialization_test.rb
144
+ - test/serializer_support_test.rb
145
+ - test/serializer_test.rb
146
+ - test/test_fakes.rb
147
+ - test/test_helper.rb
@@ -1,9 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rails', github: 'rails/rails'
6
-
7
- # Current dependencies of edge rails
8
- gem 'journey', github: 'rails/journey'
9
- gem 'activerecord-deprecated_finders' , github: 'rails/activerecord-deprecated_finders'