roar-rails 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +31 -8
- data/Appraisals +49 -0
- data/CHANGES.markdown +5 -0
- data/Gemfile +13 -2
- data/README.markdown +36 -2
- data/gemfiles/rails_3.0.gemfile +15 -0
- data/gemfiles/rails_3.2.gemfile +16 -0
- data/gemfiles/rails_4.0.gemfile +18 -0
- data/gemfiles/rails_4.1.gemfile +17 -0
- data/gemfiles/rails_4.2.gemfile +17 -0
- data/gemfiles/rails_5.0.gemfile +17 -0
- data/lib/roar-rails.rb +10 -6
- data/lib/roar/rails/json_api.rb +5 -0
- data/lib/roar/rails/rails5_0_strategy.rb +16 -0
- data/lib/roar/rails/railtie.rb +1 -1
- data/lib/roar/rails/test_case.rb +1 -5
- data/lib/roar/rails/version.rb +1 -1
- data/roar-rails.gemspec +7 -4
- data/test/consume_test.rb +11 -9
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/formats_test.rb +3 -3
- data/test/json_api_renderer_test.rb +31 -10
- data/test/render_test.rb +20 -3
- data/test/representer_generator_test.rb +2 -2
- data/test/responder_test.rb +1 -1
- data/test/test_helper.rb +5 -5
- metadata +48 -23
- data/gemfiles/Gemfile.rails3-0 +0 -9
- data/gemfiles/Gemfile.rails3-2 +0 -9
- data/gemfiles/Gemfile.rails4-0 +0 -10
- data/gemfiles/Gemfile.rails4-1 +0 -11
- data/gemfiles/Gemfile.rails4-2 +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6817e161c3f12ef7ed0c8658a5bdd24aacbb5a7c
|
4
|
+
data.tar.gz: 20abccfffd64b3f03e6d57fb27bb76ad9cc27812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bb52c91e664b93082dffb57afab0572329f1312c0a5d9cd0f23b85a9457366fcc47e9072dc40d91294db51a9fcdbd27178c5b4af73d91a1eb9cd873ff5a5f71
|
7
|
+
data.tar.gz: bfcb2294190c92540ebdf091ce3c7371ba060e24258e69d578ea6c94870cd955f68edd0f2a6a3d6043845176fdc76df2b8a05e44d6d260c0b9d2d246365cbe46
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,9 +1,32 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
gemfile:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
cache: bundler
|
4
|
+
matrix:
|
5
|
+
include:
|
6
|
+
- { rvm: 1.9.3, gemfile: gemfiles/rails_3.0.gemfile }
|
7
|
+
- { rvm: 1.9.3, gemfile: gemfiles/rails_3.2.gemfile }
|
8
|
+
- { rvm: 1.9.3, gemfile: gemfiles/rails_4.0.gemfile }
|
9
|
+
- { rvm: 1.9.3, gemfile: gemfiles/rails_4.1.gemfile }
|
10
|
+
- { rvm: 1.9.3, gemfile: gemfiles/rails_4.2.gemfile }
|
11
|
+
|
12
|
+
- { rvm: 2.1, gemfile: gemfiles/rails_3.0.gemfile }
|
13
|
+
- { rvm: 2.1, gemfile: gemfiles/rails_3.2.gemfile }
|
14
|
+
- { rvm: 2.1, gemfile: gemfiles/rails_4.0.gemfile }
|
15
|
+
- { rvm: 2.1, gemfile: gemfiles/rails_4.1.gemfile }
|
16
|
+
- { rvm: 2.1, gemfile: gemfiles/rails_4.2.gemfile }
|
17
|
+
|
18
|
+
- { rvm: 2.2.6, gemfile: gemfiles/rails_4.0.gemfile }
|
19
|
+
- { rvm: 2.2.6, gemfile: gemfiles/rails_4.1.gemfile }
|
20
|
+
- { rvm: 2.2.6, gemfile: gemfiles/rails_4.2.gemfile }
|
21
|
+
- { rvm: 2.2.6, gemfile: gemfiles/rails_5.0.gemfile }
|
22
|
+
|
23
|
+
- { rvm: 2.3.1, gemfile: gemfiles/rails_4.0.gemfile }
|
24
|
+
- { rvm: 2.3.1, gemfile: gemfiles/rails_4.1.gemfile }
|
25
|
+
- { rvm: 2.3.1, gemfile: gemfiles/rails_4.2.gemfile }
|
26
|
+
- { rvm: 2.3.1, gemfile: gemfiles/rails_5.0.gemfile }
|
27
|
+
|
28
|
+
- { rvm: 2.4.0, gemfile: gemfiles/rails_5.0.gemfile }
|
29
|
+
|
30
|
+
- { rvm: ruby-head, gemfile: gemfiles/rails_5.0.gemfile }
|
31
|
+
allow_failures:
|
32
|
+
- rvm: ruby-head
|
data/Appraisals
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
appraise 'rails-3.0' do
|
2
|
+
gem 'railties', '~> 3.0.11'
|
3
|
+
gem 'activerecord', '~> 3.0.11'
|
4
|
+
gem 'minitest-rails', '~> 1.0'
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'rails-3.2' do
|
8
|
+
gem 'railties', '~> 3.2.13'
|
9
|
+
gem 'activerecord', '~> 3.2.13'
|
10
|
+
gem 'minitest', '~> 4.7.5'
|
11
|
+
gem 'minitest-rails', '~> 1.0'
|
12
|
+
end
|
13
|
+
|
14
|
+
appraise 'rails-4.0' do
|
15
|
+
gem 'railties', '~> 4.0.0'
|
16
|
+
gem 'actionpack', '~> 4.0.0'
|
17
|
+
|
18
|
+
gem 'activemodel', '~> 4.0.0'
|
19
|
+
gem 'activerecord', '~> 4.0.0'
|
20
|
+
gem 'minitest', '~> 4.7.5'
|
21
|
+
gem 'minitest-rails', '~> 1.0'
|
22
|
+
end
|
23
|
+
|
24
|
+
appraise 'rails-4.1' do
|
25
|
+
gem 'railties', '~> 4.1.0'
|
26
|
+
gem 'actionpack', '~> 4.1.0'
|
27
|
+
|
28
|
+
gem 'activemodel', '~> 4.1.0'
|
29
|
+
gem 'activerecord', '~> 4.1.0'
|
30
|
+
gem 'minitest-rails', '~> 2.0'
|
31
|
+
end
|
32
|
+
|
33
|
+
appraise 'rails-4.2' do
|
34
|
+
gem 'railties', '~> 4.2.0'
|
35
|
+
gem 'actionpack', '~> 4.2.0'
|
36
|
+
|
37
|
+
gem 'activemodel', '~> 4.2.0'
|
38
|
+
gem 'activerecord', '~> 4.2.0'
|
39
|
+
gem 'minitest-rails', '~> 2.0'
|
40
|
+
end
|
41
|
+
|
42
|
+
appraise 'rails-5.0' do
|
43
|
+
gem 'railties', '~> 5.0.0'
|
44
|
+
gem 'actionpack', '~> 5.0.0'
|
45
|
+
|
46
|
+
gem 'activemodel', '~> 5.0.0'
|
47
|
+
gem 'activerecord', '~> 5.0.0'
|
48
|
+
gem 'minitest-rails', '~> 3.0'
|
49
|
+
end
|
data/CHANGES.markdown
CHANGED
data/Gemfile
CHANGED
@@ -5,6 +5,17 @@ gemspec
|
|
5
5
|
|
6
6
|
group :test do
|
7
7
|
# gem 'roar', path: "../roar" #">= 0.11.17"
|
8
|
-
#gem 'representable', path: "../representable"
|
8
|
+
# gem 'representable', path: "../representable"
|
9
9
|
gem 'rake', '10.1.0'
|
10
|
-
end
|
10
|
+
end
|
11
|
+
|
12
|
+
respond_to?(:install_if) and
|
13
|
+
install_if -> { RUBY_VERSION < '2.2.2' } do
|
14
|
+
gem 'actionpack', '~> 4.2.0'
|
15
|
+
gem 'activemodel', '~> 4.2.0'
|
16
|
+
gem 'activerecord', '~> 4.2.0'
|
17
|
+
end
|
18
|
+
|
19
|
+
gem 'nokogiri', '~> 1.6.8'
|
20
|
+
|
21
|
+
gem 'appraisal'
|
data/README.markdown
CHANGED
@@ -2,7 +2,16 @@
|
|
2
2
|
|
3
3
|
_Makes using Roar's representers in your Rails app fun._
|
4
4
|
|
5
|
-
|
5
|
+
[![Build Status](https://travis-ci.org/apotonick/roar-rails.svg?branch=master)](https://travis-ci.org/apotonick/roar-rails)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/roar-rails.svg)](http://badge.fury.io/rb/roar-rails)
|
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
|
+
_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
|
+
|
12
|
+
---
|
13
|
+
|
14
|
+
Roar is a framework for parsing and rendering REST documents. For a better overview about representers please check the [roar repository](https://github.com/trailblazer/roar#roar).
|
6
15
|
|
7
16
|
Roar-rails gives you conventions and convenient access to a lot of Roar's functionality within your Rails app.
|
8
17
|
|
@@ -17,6 +26,20 @@ Roar-rails gives you conventions and convenient access to a lot of Roar's functi
|
|
17
26
|
|
18
27
|
This gem works with all Rails >= 3.x.
|
19
28
|
|
29
|
+
## Prerequisites
|
30
|
+
|
31
|
+
Add it to your app's `Gemfile`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem "roar-rails"
|
35
|
+
```
|
36
|
+
|
37
|
+
Note: For Rails >= 4.2, you need to add the `responders` gem, too, if you use `respond_with`. This has to be before the `roar-rails` entry in the Gemfile.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
gem "responders"
|
41
|
+
gem "roar-rails"
|
42
|
+
```
|
20
43
|
|
21
44
|
## Generators
|
22
45
|
|
@@ -170,6 +193,7 @@ If you prefer roar's decorator approach over extend, just go for it. roar-rails
|
|
170
193
|
```ruby
|
171
194
|
class SingerRepresenter < Roar::Decorator
|
172
195
|
include Roar::JSON
|
196
|
+
include Roar::Hypermedia
|
173
197
|
|
174
198
|
property :name
|
175
199
|
|
@@ -229,7 +253,7 @@ To get the hyperlinks up and running, please make sure to set the right _host na
|
|
229
253
|
config.representer.default_url_options = {:host => "127.0.0.1:3000"}
|
230
254
|
```
|
231
255
|
|
232
|
-
Attention: If you are using representers from a gem your Rails URL helpers might not work in these modules. This is due to a [loading order problem](https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/5tG5unZ8jDQ) in Rails. As a workaround, don't require the representers in the gem but load them as
|
256
|
+
Attention: If you are using representers from a gem your Rails URL helpers might not work in these modules. This is due to a [loading order problem](https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/5tG5unZ8jDQ) in Rails. As a workaround, don't require the representers in the gem but load them as late as possible, usually it works when you require in the controller. We are working on fixing that problem.
|
233
257
|
|
234
258
|
## Representing Formats Exclusively
|
235
259
|
|
@@ -270,6 +294,16 @@ end
|
|
270
294
|
|
271
295
|
Put your representers in `app/representers` and they will be autoloaded by Rails. Also, frequently used modules as media representers and features don't need to be required manually.
|
272
296
|
|
297
|
+
## JSON-API
|
298
|
+
|
299
|
+
In a JSON-API environment, only one representer is written for both singular and collection resources. However, you have to configure `represents` accordingly so it knows what representer to use for collections.
|
300
|
+
|
301
|
+
```ruby
|
302
|
+
class SongsController < ApplicationController
|
303
|
+
represents :json_api, entity: SongRepresenter, collection: SongRepresenter.for_collection
|
304
|
+
```
|
305
|
+
|
306
|
+
|
273
307
|
## Rails 4.1+ and HAL/JSON-API
|
274
308
|
|
275
309
|
**Note**: this is a temporary work-around, we're trying to fix that in Rails/roar-rails itself [May 2014].
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "nokogiri", "~> 1.6.8"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "railties", "~> 3.0.11"
|
8
|
+
gem "activerecord", "~> 3.0.11"
|
9
|
+
gem "minitest-rails", "~> 1.0"
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "rake", "10.1.0"
|
13
|
+
end
|
14
|
+
|
15
|
+
gemspec :path => "../"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "nokogiri", "~> 1.6.8"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "railties", "~> 3.2.13"
|
8
|
+
gem "activerecord", "~> 3.2.13"
|
9
|
+
gem "minitest", "~> 4.7.5"
|
10
|
+
gem "minitest-rails", "~> 1.0"
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem "rake", "10.1.0"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "nokogiri", "~> 1.6.8"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "railties", "~> 4.0.0"
|
8
|
+
gem "actionpack", "~> 4.0.0"
|
9
|
+
gem "activemodel", "~> 4.0.0"
|
10
|
+
gem "activerecord", "~> 4.0.0"
|
11
|
+
gem "minitest", "~> 4.7.5"
|
12
|
+
gem "minitest-rails", "~> 1.0"
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem "rake", "10.1.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec :path => "../"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "nokogiri", "~> 1.6.8"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "railties", "~> 4.1.0"
|
8
|
+
gem "actionpack", "~> 4.1.0"
|
9
|
+
gem "activemodel", "~> 4.1.0"
|
10
|
+
gem "activerecord", "~> 4.1.0"
|
11
|
+
gem "minitest-rails", "~> 2.0"
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem "rake", "10.1.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
gemspec :path => "../"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "nokogiri", "~> 1.6.8"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "railties", "~> 4.2.0"
|
8
|
+
gem "actionpack", "~> 4.2.0"
|
9
|
+
gem "activemodel", "~> 4.2.0"
|
10
|
+
gem "activerecord", "~> 4.2.0"
|
11
|
+
gem "minitest-rails", "~> 2.0"
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem "rake", "10.1.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
gemspec :path => "../"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "nokogiri", "~> 1.6.8"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "railties", "~> 5.0.0"
|
8
|
+
gem "actionpack", "~> 5.0.0"
|
9
|
+
gem "activemodel", "~> 5.0.0"
|
10
|
+
gem "activerecord", "~> 5.0.0"
|
11
|
+
gem "minitest-rails", "~> 3.0"
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem "rake", "10.1.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
gemspec :path => "../"
|
data/lib/roar-rails.rb
CHANGED
@@ -18,19 +18,23 @@ end
|
|
18
18
|
|
19
19
|
module Roar
|
20
20
|
module Rails
|
21
|
-
require 'uber/version'
|
22
21
|
def self.rails_version
|
23
|
-
|
22
|
+
Gem::Version.new([ActionPack::VERSION::MAJOR, ActionPack::VERSION::MINOR].join('.'))
|
24
23
|
end
|
25
24
|
|
26
|
-
|
25
|
+
case rails_version
|
26
|
+
when Gem::Version.new(3.0)
|
27
27
|
require 'roar/rails/rails3_0_strategy'
|
28
|
-
|
28
|
+
when Gem::Version.new(3.1)
|
29
29
|
require 'roar/rails/rails3_1_strategy'
|
30
|
-
|
30
|
+
when Gem::Version.new(3.2)
|
31
31
|
require 'roar/rails/rails3_2_strategy'
|
32
|
-
|
32
|
+
when Gem::Version.new(4.0), Gem::Version.new(4.1)
|
33
|
+
require 'roar/rails/rails4_0_strategy'
|
34
|
+
when Gem::Version.new(4.2)
|
33
35
|
require 'roar/rails/rails4_2_strategy'
|
36
|
+
when Gem::Version.new(5.0)
|
37
|
+
require 'roar/rails/rails5_0_strategy'
|
34
38
|
else
|
35
39
|
# fallback to 4.0 strategy
|
36
40
|
require 'roar/rails/rails4_0_strategy'
|
data/lib/roar/rails/json_api.rb
CHANGED
@@ -5,3 +5,8 @@ Roar::JSON::JSONAPI.class_eval do
|
|
5
5
|
def from_json_api(*args); from_json(*args); end
|
6
6
|
end
|
7
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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'action_controller/responder'
|
2
|
+
|
3
|
+
module Roar::Rails
|
4
|
+
class Responder < ActionController::Responder
|
5
|
+
module VersionStrategy
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module TestCase
|
10
|
+
module VersionStrategy
|
11
|
+
def process_args(action, http_method, document="", params={})
|
12
|
+
[action, { method: http_method, params: params }]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/roar/rails/railtie.rb
CHANGED
@@ -14,7 +14,7 @@ module Roar
|
|
14
14
|
initializer "roar.set_configs" do |app|
|
15
15
|
::Roar::Representer.module_eval do
|
16
16
|
include app.routes.url_helpers
|
17
|
-
include app.routes.mounted_helpers unless
|
17
|
+
include app.routes.mounted_helpers unless (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0)
|
18
18
|
|
19
19
|
include UrlMethods # provide an initial #default_url_options.
|
20
20
|
end
|
data/lib/roar/rails/test_case.rb
CHANGED
data/lib/roar/rails/version.rb
CHANGED
data/roar-rails.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Roar::Rails::VERSION
|
8
8
|
s.authors = ["Nick Sutterer"]
|
9
9
|
s.email = ["apotonick@gmail.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "https://github.com/apotonick/roar-rails"
|
11
11
|
s.summary = %q{Use Roar in Rails.}
|
12
12
|
s.description = %q{Rails extensions for using Roar in the popular web framework.}
|
13
13
|
|
@@ -18,16 +18,19 @@ 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",
|
21
|
+
s.add_runtime_dependency "roar", '~> 1.0.4'
|
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", "
|
25
|
+
s.add_runtime_dependency "uber", "~> 0.0.7"
|
26
26
|
s.add_runtime_dependency "responders"
|
27
27
|
|
28
|
-
s.add_development_dependency
|
28
|
+
s.add_development_dependency 'minitest-rails'
|
29
|
+
s.add_development_dependency 'minitest'
|
30
|
+
|
29
31
|
s.add_development_dependency "activemodel"
|
30
32
|
s.add_development_dependency "activerecord"
|
31
33
|
s.add_development_dependency "sqlite3"
|
34
|
+
s.add_development_dependency "multi_json"
|
32
35
|
s.add_development_dependency "tzinfo" # FIXME: why the hell do we need this for 3.1?
|
33
36
|
end
|
data/test/consume_test.rb
CHANGED
@@ -56,6 +56,7 @@ end
|
|
56
56
|
|
57
57
|
class ConsumeWithConfigurationTest < ActionController::TestCase
|
58
58
|
include Roar::Rails::TestCase
|
59
|
+
SingerRepresenter = ::SingerRepresenter
|
59
60
|
|
60
61
|
module MusicianRepresenter
|
61
62
|
include Roar::JSON
|
@@ -82,17 +83,18 @@ class ConsumeWithConfigurationTest < ActionController::TestCase
|
|
82
83
|
assert_equal %{#<struct Singer name="Bumi">}, @response.body
|
83
84
|
end
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
if ActiveRecord::VERSION::MAJOR < 5
|
87
|
+
test "#do not consume missing content type" do
|
88
|
+
assert_raises Roar::Rails::UnsupportedMediaType do
|
89
|
+
post :consume_json, "{\"name\": \"Bumi\"}"
|
90
|
+
end
|
88
91
|
end
|
89
|
-
end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
test "#do not consume parses unknown content type" do
|
94
|
+
@request.env['CONTENT_TYPE'] = 'application/custom+json'
|
95
|
+
assert_raises Roar::Rails::UnsupportedMediaType do
|
96
|
+
post :consume_json, "{\"name\": \"Bumi\"}"
|
97
|
+
end
|
96
98
|
end
|
97
99
|
end
|
98
100
|
end
|
@@ -32,7 +32,7 @@ Dummy::Application.configure do
|
|
32
32
|
|
33
33
|
config.representer.default_url_options = {:host => "roar.apotomo.de"}
|
34
34
|
|
35
|
-
if
|
35
|
+
if Rails::VERSION::MAJOR >= 4
|
36
36
|
config.eager_load = false
|
37
37
|
config.active_support.test_order = :random
|
38
38
|
end
|
data/test/formats_test.rb
CHANGED
@@ -124,7 +124,7 @@ class FormatsTest < MiniTest::Spec
|
|
124
124
|
|
125
125
|
it "returns nil when not present" do
|
126
126
|
skip "not sure what to do when format is unknown"
|
127
|
-
subject.for(:xml, Class.new.new, "bands").
|
127
|
+
subject.for(:xml, Class.new.new, "bands").must_be_nil
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
@@ -132,7 +132,7 @@ end
|
|
132
132
|
class PathTest < MiniTest::Spec
|
133
133
|
let (:path) { Roar::Rails::Formats::Path }
|
134
134
|
|
135
|
-
it { path.new("bands").namespace.
|
135
|
+
it { path.new("bands").namespace.must_be_nil }
|
136
136
|
it { path.new("v1/bands").namespace.must_equal "v1" }
|
137
137
|
it { path.new("api/v1/bands").namespace.must_equal "api/v1" }
|
138
|
-
end
|
138
|
+
end
|
@@ -1,35 +1,56 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class JsonApiRendererTest < ActionController::TestCase
|
4
4
|
include Roar::Rails::TestCase
|
5
5
|
|
6
6
|
class SingersController < ActionController::Base
|
7
|
-
module
|
7
|
+
module SingerRepresenter
|
8
8
|
include Roar::JSON::JSONAPI
|
9
|
-
|
10
|
-
type :singer
|
9
|
+
type :song
|
11
10
|
property :name
|
11
|
+
|
12
|
+
link(:self) { "//self"}
|
12
13
|
end
|
13
14
|
|
14
15
|
include Roar::Rails::ControllerAdditions
|
15
|
-
|
16
|
+
|
17
|
+
represents :json_api, entity: SingerRepresenter, collection: SingerRepresenter.for_collection # should be inferred.
|
16
18
|
|
17
19
|
def show
|
18
20
|
singer = Musician.new("Bumi")
|
19
21
|
respond_with singer
|
20
22
|
end
|
23
|
+
|
24
|
+
def index
|
25
|
+
singers = [Musician.new("Bumi"), Musician.new("Chad")]
|
26
|
+
respond_with singers
|
27
|
+
end
|
28
|
+
|
21
29
|
end
|
22
30
|
|
23
31
|
tests SingersController
|
24
32
|
|
25
|
-
test "should render correctly in response to a application/vnd.api+json" do
|
26
|
-
get :show, :id => "
|
27
|
-
|
33
|
+
test "should render single model correctly in response to a application/vnd.api+json" do
|
34
|
+
get :show, :id => "1", :format => :json_api
|
35
|
+
|
36
|
+
response.body.must_equal "{\"song\":{\"name\":\"Bumi\"},\"links\":{\"self\":{\"href\":\"//self\"}}}"
|
28
37
|
end
|
29
38
|
|
30
|
-
test "should
|
39
|
+
test "should render collection of models correctly in response to a application/vnd.api+json" do
|
40
|
+
get :index, :format => :json_api
|
41
|
+
# assert_body '{"people":[{"first_name":"Chad"},{"first_name":"Fremont"}]}'
|
42
|
+
|
43
|
+
response.body.must_equal "{\"song\":[{\"name\":\"Bumi\"},{\"name\":\"Chad\"}],\"links\":{\"self\":{\"href\":\"//self\"}}}"
|
44
|
+
end
|
45
|
+
|
46
|
+
test "should have a content_type of application/vnd.api+json for a single model" do
|
31
47
|
get :show, :id => "bumi", :format => :json_api
|
32
48
|
assert_equal response.content_type, 'application/vnd.api+json'
|
33
49
|
end
|
34
|
-
end
|
35
50
|
|
51
|
+
test "should have a content_type of application/vnd.api+json for a collection of models" do
|
52
|
+
get :index, :format => :json_api
|
53
|
+
assert_equal response.content_type, 'application/vnd.api+json'
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/render_test.rb
CHANGED
@@ -4,28 +4,45 @@ class RenderTest < ActionController::TestCase
|
|
4
4
|
include Roar::Rails::TestCase
|
5
5
|
|
6
6
|
class SingersController < ActionController::Base
|
7
|
+
|
7
8
|
module SingerRepresenter
|
8
9
|
include Roar::JSON
|
9
|
-
|
10
10
|
property :name, :as => :title
|
11
11
|
end
|
12
12
|
|
13
|
+
module SingersRepresenter
|
14
|
+
include Representable::JSON::Collection
|
15
|
+
items :extend => SingerRepresenter
|
16
|
+
end
|
17
|
+
|
13
18
|
include Roar::Rails::ControllerAdditions
|
14
19
|
include Roar::Rails::ControllerAdditions::Render
|
15
20
|
|
16
|
-
represents :json, :entity => SingerRepresenter
|
21
|
+
represents :json, :entity => SingerRepresenter, :collection => SingersRepresenter
|
17
22
|
|
18
23
|
def show
|
19
24
|
singer = Musician.new("Bumi")
|
20
25
|
render :json => singer, status: 201
|
21
26
|
end
|
27
|
+
|
28
|
+
def index
|
29
|
+
singers = [Musician.new("Bumi"), Musician.new("Iggy")]
|
30
|
+
render :json => singers, status: 201
|
31
|
+
end
|
32
|
+
|
22
33
|
end
|
23
34
|
|
24
35
|
tests SingersController
|
25
36
|
|
26
37
|
test "should use Representer for #render" do
|
27
38
|
get :show, :id => "bumi", :format => :json
|
28
|
-
|
39
|
+
assert_equal response.body, '{"title":"Bumi"}'
|
40
|
+
assert_equal 201, response.status
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should use Representer for #render on a model collection" do
|
44
|
+
get :index, :format => :json
|
45
|
+
assert_equal response.body, '[{"title":"Bumi"},{"title":"Iggy"}]'
|
29
46
|
assert_equal 201, response.status
|
30
47
|
end
|
31
48
|
end
|
@@ -24,13 +24,13 @@ class RepresentetGeneratorTest < Rails::Generators::TestCase
|
|
24
24
|
test "create a representer with default json support" do
|
25
25
|
run_generator %w(singer)
|
26
26
|
|
27
|
-
assert_file representer_path('singer'), /include Roar::
|
27
|
+
assert_file representer_path('singer'), /include Roar::JSON/
|
28
28
|
end
|
29
29
|
|
30
30
|
test "create a representer with different format support" do
|
31
31
|
run_generator %w(singer --format=XML)
|
32
32
|
|
33
|
-
assert_file representer_path('singer'), /include Roar::
|
33
|
+
assert_file representer_path('singer'), /include Roar::XML/
|
34
34
|
end
|
35
35
|
|
36
36
|
test "create a representer with property, class and exnted" do
|
data/test/responder_test.rb
CHANGED
@@ -417,7 +417,7 @@ class ResponderTest < ActionController::TestCase
|
|
417
417
|
end
|
418
418
|
|
419
419
|
def bumi_json
|
420
|
-
return "[\"Bumi\"]" if
|
420
|
+
return "[\"Bumi\"]" if (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0)
|
421
421
|
"{\"name\":\"Bumi\"}"
|
422
422
|
end
|
423
423
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'test_xml/mini_test'
|
3
|
-
|
4
1
|
ENV['RAILS_ENV'] = 'test'
|
5
2
|
require "dummy/config/environment"
|
6
3
|
require "rails/test_help" # adds stuff like @routes, etc.
|
4
|
+
require 'minitest/rails'
|
5
|
+
|
6
|
+
require 'test_xml/mini_test'
|
7
7
|
require "roar/rails/test_case"
|
8
8
|
|
9
9
|
Singer = Struct.new(:name)
|
@@ -17,11 +17,11 @@ Mime::Type.register 'application/vnd.api+json', :json_api
|
|
17
17
|
|
18
18
|
# see also https://github.com/jingweno/msgpack_rails/issues/3
|
19
19
|
::ActionController::Renderers.add :hal do |js, options|
|
20
|
-
self.content_type ||= Mime
|
20
|
+
self.content_type ||= Mime[:hal]
|
21
21
|
js.is_a?(String) ? js : js.to_json
|
22
22
|
end
|
23
23
|
|
24
24
|
::ActionController::Renderers.add :json_api do |js, options|
|
25
|
-
self.content_type ||= Mime
|
25
|
+
self.content_type ||= Mime[:json_api]
|
26
26
|
js.is_a?(String) ? js : js.to_json
|
27
27
|
end
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roar-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roar
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.0
|
20
|
-
- - "<="
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
19
|
+
version: 1.0.4
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0.0
|
30
|
-
- - "<="
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
26
|
+
version: 1.0.4
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: test_xml
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,16 +70,16 @@ dependencies:
|
|
76
70
|
name: uber
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
|
-
- - "
|
73
|
+
- - "~>"
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.0.
|
75
|
+
version: 0.0.7
|
82
76
|
type: :runtime
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
|
-
- - "
|
80
|
+
- - "~>"
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.0.
|
82
|
+
version: 0.0.7
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: responders
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +94,20 @@ dependencies:
|
|
100
94
|
- - ">="
|
101
95
|
- !ruby/object:Gem::Version
|
102
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
103
111
|
- !ruby/object:Gem::Dependency
|
104
112
|
name: minitest
|
105
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,6 +164,20 @@ dependencies:
|
|
156
164
|
- - ">="
|
157
165
|
- !ruby/object:Gem::Version
|
158
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: multi_json
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
159
181
|
- !ruby/object:Gem::Dependency
|
160
182
|
name: tzinfo
|
161
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,17 +201,19 @@ extra_rdoc_files: []
|
|
179
201
|
files:
|
180
202
|
- ".gitignore"
|
181
203
|
- ".travis.yml"
|
204
|
+
- Appraisals
|
182
205
|
- CHANGES.markdown
|
183
206
|
- Gemfile
|
184
207
|
- LICENSE
|
185
208
|
- README.markdown
|
186
209
|
- Rakefile
|
187
210
|
- TODO.md
|
188
|
-
- gemfiles/
|
189
|
-
- gemfiles/
|
190
|
-
- gemfiles/
|
191
|
-
- gemfiles/
|
192
|
-
- gemfiles/
|
211
|
+
- gemfiles/rails_3.0.gemfile
|
212
|
+
- gemfiles/rails_3.2.gemfile
|
213
|
+
- gemfiles/rails_4.0.gemfile
|
214
|
+
- gemfiles/rails_4.1.gemfile
|
215
|
+
- gemfiles/rails_4.2.gemfile
|
216
|
+
- gemfiles/rails_5.0.gemfile
|
193
217
|
- lib/generators/rails/USAGE
|
194
218
|
- lib/generators/rails/representer_generator.rb
|
195
219
|
- lib/generators/rails/templates/representer.rb
|
@@ -203,6 +227,7 @@ files:
|
|
203
227
|
- lib/roar/rails/rails3_2_strategy.rb
|
204
228
|
- lib/roar/rails/rails4_0_strategy.rb
|
205
229
|
- lib/roar/rails/rails4_2_strategy.rb
|
230
|
+
- lib/roar/rails/rails5_0_strategy.rb
|
206
231
|
- lib/roar/rails/railtie.rb
|
207
232
|
- lib/roar/rails/responder.rb
|
208
233
|
- lib/roar/rails/test_case.rb
|
@@ -238,7 +263,7 @@ files:
|
|
238
263
|
- test/test_case_test.rb
|
239
264
|
- test/test_helper.rb
|
240
265
|
- test/validations_test.rb
|
241
|
-
homepage:
|
266
|
+
homepage: https://github.com/apotonick/roar-rails
|
242
267
|
licenses: []
|
243
268
|
metadata: {}
|
244
269
|
post_install_message:
|
@@ -257,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
282
|
version: '0'
|
258
283
|
requirements: []
|
259
284
|
rubyforge_project: roar-rails
|
260
|
-
rubygems_version: 2.
|
285
|
+
rubygems_version: 2.5.1
|
261
286
|
signing_key:
|
262
287
|
specification_version: 4
|
263
288
|
summary: Use Roar in Rails.
|
data/gemfiles/Gemfile.rails3-0
DELETED
data/gemfiles/Gemfile.rails3-2
DELETED
data/gemfiles/Gemfile.rails4-0
DELETED
data/gemfiles/Gemfile.rails4-1
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in roar-rails.gemspec
|
4
|
-
gemspec :path => '../'
|
5
|
-
|
6
|
-
gem 'railties', '~> 4.1.0'
|
7
|
-
gem 'actionpack', '~> 4.1.0'
|
8
|
-
|
9
|
-
gem 'activemodel', '~> 4.1.0'
|
10
|
-
gem 'activerecord', '~> 4.1.0'
|
11
|
-
gem 'minitest', '~> 5.2.0'
|
data/gemfiles/Gemfile.rails4-2
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in roar-rails.gemspec
|
4
|
-
gemspec :path => '../'
|
5
|
-
|
6
|
-
gem 'railties', '~> 4.2.0'
|
7
|
-
gem 'actionpack', '~> 4.2.0'
|
8
|
-
|
9
|
-
gem 'activemodel', '~> 4.2.0'
|
10
|
-
gem 'activerecord', '~> 4.2.0'
|
11
|
-
|
12
|
-
gem 'minitest', '~> 5.5.0'
|