roar-rails 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6817e161c3f12ef7ed0c8658a5bdd24aacbb5a7c
4
- data.tar.gz: 20abccfffd64b3f03e6d57fb27bb76ad9cc27812
3
+ metadata.gz: ace7c60c6e76e0b30246d345fa21e8187e2007b9
4
+ data.tar.gz: ac4249bc4fcb3d309ba932e1850c6e17baa0e991
5
5
  SHA512:
6
- metadata.gz: 3bb52c91e664b93082dffb57afab0572329f1312c0a5d9cd0f23b85a9457366fcc47e9072dc40d91294db51a9fcdbd27178c5b4af73d91a1eb9cd873ff5a5f71
7
- data.tar.gz: bfcb2294190c92540ebdf091ce3c7371ba060e24258e69d578ea6c94870cd955f68edd0f2a6a3d6043845176fdc76df2b8a05e44d6d260c0b9d2d246365cbe46
6
+ metadata.gz: 71c22671c3d5bfecebb9b1f2984f1a04bb5c853ca5db85f39e62f4ae32b2711f9ebd85942cea807751b56f995d675df4692c12612b18d3f55c04873c82174222
7
+ data.tar.gz: d77de20f05521b69c45d9d32c0832ed9338f638c42211a96583ded54778c709558cc9095c938b367f3329bd299bfdb6e18ddf7c37ce2373a5c3bdef81ae15225
@@ -1,7 +1,15 @@
1
+ ## 1.1.0
2
+
3
+ **Roar 1.1 (and Representable 3.0) support** (see [Roar CHANGES](https://github.com/trailblazer/roar/blob/master/CHANGES.markdown#110))
4
+
5
+ * Require Roar >= 1.1.0.
6
+ * Improved support for JSON API (now requires separate [roar-jsonapi](https://github.com/trailblazer/roar-jsonapi) gem).
7
+ * Fix Uber version requirement.
8
+
1
9
  ## 1.0.2
2
10
 
3
11
  * Make Roar version requirement stricter: restrict to 1.0.x series.
4
- * Initial support for Rails 5 support.
12
+ * Initial support for Rails 5.
5
13
 
6
14
  ## 1.0.1
7
15
 
@@ -12,7 +20,7 @@
12
20
  ## 1.0.0
13
21
 
14
22
  * Requires Roar >= 1.0.0.
15
- * In `#consume!` roar-rails now finds the correct representer for the `Content-type:` header. In former version the representer name was infered using the `Accept:` header, which was totally wrong. Thanks to @pgaertig for fixing that.
23
+ * In `#consume!` roar-rails now finds the correct representer for the `Content-type:` header. In former version the representer name was inferred using the `Accept:` header, which was totally wrong. Thanks to @pgaertig for fixing that.
16
24
 
17
25
  ## 0.1.6
18
26
 
@@ -47,7 +55,7 @@
47
55
  ## 0.1.0
48
56
 
49
57
  * `ActiveRecord::Relation` is now detected as a collection and the appropriate representer should be found.
50
- * Entity (singular) representers are now correctly infered even if you only specified `collection:` in `::represents`. That works by querying the model.
58
+ * Entity (singular) representers are now correctly inferred even if you only specified `collection:` in `::represents`. That works by querying the model.
51
59
  * Entity representers are now *namespaced* when guessed (i.e., when you didn't specify them explicitly in `::represents`) as it works with collection representers already. If you have a namespaced controller and it suddenly doesn't find its entity representer anymore, either namespace the representer or specify its name in `::represents`.
52
60
 
53
61
  ## 0.0.14
@@ -5,8 +5,6 @@ _Makes using Roar's representers in your Rails app fun._
5
5
  [![Build Status](https://travis-ci.org/apotonick/roar-rails.svg?branch=master)](https://travis-ci.org/apotonick/roar-rails)
6
6
  [![Gem Version](https://badge.fury.io/rb/roar-rails.svg)](http://badge.fury.io/rb/roar-rails)
7
7
 
8
- **IMPORTANT NOTE: roar-rails 1.0.2 does not support Roar 1.1**. Support is still under development and will be released as part of roar-rails 1.1. See [#130](https://github.com/apotonick/roar-rails/issues/130).
9
-
10
8
  _roar-rails development will be discontinued in the future and we will encourage users to begin migrating to [Trailblazer](trailblazer.to) (and [trailblazer-rails](https://github.com/trailblazer/trailblazer-rails))._
11
9
 
12
10
  ---
@@ -1,12 +1,7 @@
1
1
  require 'roar/json/json_api'
2
2
 
3
- Roar::JSON::JSONAPI.class_eval do
3
+ # FIXME: Hack. Add another module to Roar JSON API to hook into.
4
+ Roar::JSON::JSONAPI::Document.class_eval do
4
5
  def to_json_api(*args); to_json(*args); end
5
6
  def from_json_api(*args); from_json(*args); end
6
7
  end
7
-
8
- # allow the same for collections.
9
- Roar::JSON::JSONAPI::Document::Collection.class_eval do
10
- def to_json_api(*args); to_json(*args); end
11
- def from_json_api(*args); from_json(*args); end
12
- end
@@ -1,5 +1,5 @@
1
1
  module Roar
2
2
  module Rails
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -18,16 +18,17 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency "roar", '~> 1.0.4'
21
+ s.add_runtime_dependency "roar", '~> 1.1.0'
22
22
  s.add_runtime_dependency "test_xml", ">= 0.1.6" # TODO: remove dependency as most people don't use XML.
23
23
  s.add_runtime_dependency "actionpack"
24
24
  s.add_runtime_dependency "railties", ">= 3.0.0"
25
- s.add_runtime_dependency "uber", "~> 0.0.7"
25
+ s.add_runtime_dependency "uber", "< 0.2.0"
26
26
  s.add_runtime_dependency "responders"
27
27
 
28
28
  s.add_development_dependency 'minitest-rails'
29
29
  s.add_development_dependency 'minitest'
30
30
 
31
+ s.add_development_dependency "roar-jsonapi", '>= 0.0.3'
31
32
  s.add_development_dependency "activemodel"
32
33
  s.add_development_dependency "activerecord"
33
34
  s.add_development_dependency "sqlite3"
@@ -130,12 +130,17 @@ end
130
130
  class ConsumeJsonApiTest < ActionController::TestCase
131
131
  include Roar::Rails::TestCase
132
132
 
133
- module MusicianRepresenter
134
- include Roar::JSON::JSONAPI
135
- type :singer
136
- property :name
137
- end
133
+ Band = Struct.new(:name, :id)
134
+ Singer = Struct.new(:name, :id)
135
+ Musician = Struct.new(:name, :id)
138
136
 
137
+ class MusicianRepresenter < Roar::Decorator
138
+ include Roar::JSON::JSONAPI.resource :singer
139
+
140
+ attributes do
141
+ property :name
142
+ end
143
+ end
139
144
 
140
145
  class SingersController < ActionController::Base
141
146
  include Roar::Rails::ControllerAdditions
@@ -151,9 +156,9 @@ class ConsumeJsonApiTest < ActionController::TestCase
151
156
 
152
157
  test "#consume parses JSON-API document and updates the model" do
153
158
  @request.env['CONTENT_TYPE'] = 'application/vnd.api+json'
154
- post :consume_json_api, "{\"singer\": {\"name\": \"Bumi\"}}"
159
+ post :consume_json_api, %({"data":{"attributes":{"name":"Bumi"},"type":"song"}})
155
160
 
156
- assert_equal %{#<struct Singer name="Bumi">}, @response.body
161
+ assert_equal %{#<struct ConsumeJsonApiTest::Singer name="Bumi", id=nil>}, @response.body
157
162
  end
158
163
  end
159
164
 
@@ -3,11 +3,17 @@ require 'test_helper'
3
3
  class JsonApiRendererTest < ActionController::TestCase
4
4
  include Roar::Rails::TestCase
5
5
 
6
+ Band = Struct.new(:name, :id)
7
+ Singer = Struct.new(:name, :id)
8
+ Musician = Struct.new(:name, :id)
9
+
6
10
  class SingersController < ActionController::Base
7
- module SingerRepresenter
8
- include Roar::JSON::JSONAPI
9
- type :song
10
- property :name
11
+ class SingerRepresenter < Roar::Decorator
12
+ include Roar::JSON::JSONAPI.resource :song
13
+
14
+ attributes do
15
+ property :name
16
+ end
11
17
 
12
18
  link(:self) { "//self"}
13
19
  end
@@ -33,14 +39,14 @@ class JsonApiRendererTest < ActionController::TestCase
33
39
  test "should render single model correctly in response to a application/vnd.api+json" do
34
40
  get :show, :id => "1", :format => :json_api
35
41
 
36
- response.body.must_equal "{\"song\":{\"name\":\"Bumi\"},\"links\":{\"self\":{\"href\":\"//self\"}}}"
42
+ response.body.must_equal %({"data":{"attributes":{"name":"Bumi"},"type":"song","links":{"self":"//self"}}})
37
43
  end
38
44
 
39
45
  test "should render collection of models correctly in response to a application/vnd.api+json" do
40
46
  get :index, :format => :json_api
41
47
  # assert_body '{"people":[{"first_name":"Chad"},{"first_name":"Fremont"}]}'
42
48
 
43
- response.body.must_equal "{\"song\":[{\"name\":\"Bumi\"},{\"name\":\"Chad\"}],\"links\":{\"self\":{\"href\":\"//self\"}}}"
49
+ response.body.must_equal %({"data":[{"attributes":{"name":"Bumi"},"type":"song","links":{"self":"//self"}},{"attributes":{"name":"Chad"},"type":"song","links":{"self":"//self"}}]})
44
50
  end
45
51
 
46
52
  test "should have a content_type of application/vnd.api+json for a single model" do
@@ -298,8 +298,8 @@ class ResponderTest < ActionController::TestCase
298
298
  # FIXME: should be in generic roar-rails test.
299
299
  module DynamicSingerRepresenter
300
300
  include Roar::JSON
301
- property :name, :setter => lambda { |val, opts| self.name = "#{opts[:title]} #{val}" },
302
- :getter => lambda { |opts| "#{opts[:title]} #{name}" }
301
+ property :name, :setter => lambda { |opts| self.name = "#{opts[:user_options][:title]} #{opts[:fragment]}" },
302
+ :getter => lambda { |opts| "#{opts[:user_options][:title]} #{name}" }
303
303
  end
304
304
  class MusicianController < BaseController
305
305
  represents :json, :entity => DynamicSingerRepresenter, :collection => SingersRepresenter
@@ -310,7 +310,7 @@ class ResponderTest < ActionController::TestCase
310
310
  test "passes options to entity representer" do
311
311
  get do
312
312
  singer = Singer.new("Bumi")
313
- respond_with singer, :title => "Mr."
313
+ respond_with singer, user_options: { title: "Mr." }
314
314
  end
315
315
 
316
316
  @response.body.must_equal("{\"name\":\"Mr. Bumi\"}")
@@ -318,7 +318,7 @@ class ResponderTest < ActionController::TestCase
318
318
 
319
319
  test "passes options to explicit collection representer" do
320
320
  get do
321
- respond_with [Singer.new("Bumi"), Singer.new("Iggy")], :title => "Mr.", :represent_items_with => DynamicSingerRepresenter
321
+ respond_with [Singer.new("Bumi"), Singer.new("Iggy")], user_options: { title: "Mr." }, :represent_items_with => DynamicSingerRepresenter
322
322
  end
323
323
 
324
324
  @response.body.must_equal("[{\"name\":\"Mr. Bumi\"},{\"name\":\"Mr. Iggy\"}]")
@@ -330,7 +330,7 @@ class ResponderTest < ActionController::TestCase
330
330
  @request.env['CONTENT_TYPE'] = 'application/json'
331
331
 
332
332
  put singer.to_json do
333
- created_singer = consume!(Singer.new, :title => "Mr.")
333
+ created_singer = consume!(Singer.new, user_options: { title: "Mr." })
334
334
  respond_with created_singer
335
335
  end
336
336
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roar-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.4
19
+ version: 1.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.4
26
+ version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test_xml
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: uber
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - "<"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.0.7
75
+ version: 0.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.0.7
82
+ version: 0.2.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: responders
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: roar-jsonapi
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 0.0.3
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 0.0.3
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: activemodel
127
141
  requirement: !ruby/object:Gem::Requirement