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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a55ffa3152e3f698afddef93555e37f5b61d232c
4
- data.tar.gz: b3a48ed2ee0c550d255e1a5b031609c53f050a8e
3
+ metadata.gz: 6817e161c3f12ef7ed0c8658a5bdd24aacbb5a7c
4
+ data.tar.gz: 20abccfffd64b3f03e6d57fb27bb76ad9cc27812
5
5
  SHA512:
6
- metadata.gz: a6701490dd9bfbe6730bf702ac41d536e3158982ab469b7a8f217d6469051220b85cfe6019636a261196a5d91bedd579df740482dd6dbb909fedc342a221593c
7
- data.tar.gz: 08128efd725c3cae0bf5c5a7bf78ed84e1f71c9c3f48b7569a8676dfe7470bbd21f26894f3f3c2bbfd9ad82ff33bfb450d70bf785bca53a83058a2ea8dc0bff1
6
+ metadata.gz: 3bb52c91e664b93082dffb57afab0572329f1312c0a5d9cd0f23b85a9457366fcc47e9072dc40d91294db51a9fcdbd27178c5b4af73d91a1eb9cd873ff5a5f71
7
+ data.tar.gz: bfcb2294190c92540ebdf091ce3c7371ba060e24258e69d578ea6c94870cd955f68edd0f2a6a3d6043845176fdc76df2b8a05e44d6d260c0b9d2d246365cbe46
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  bin
5
5
  .bundle
6
6
  Gemfile*.lock
7
+ gemfiles/*.gemfile.lock
7
8
  pkg/*
8
9
  test/dummy/log/*
9
10
  test/dummy/tmp/*
@@ -1,9 +1,32 @@
1
+ sudo: false
1
2
  language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- gemfile:
6
- - gemfiles/Gemfile.rails3-0
7
- - gemfiles/Gemfile.rails3-2
8
- - gemfiles/Gemfile.rails4-0
9
- - gemfiles/Gemfile.rails4-2
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
@@ -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
@@ -1,3 +1,8 @@
1
+ ## 1.0.2
2
+
3
+ * Make Roar version requirement stricter: restrict to 1.0.x series.
4
+ * Initial support for Rails 5 support.
5
+
1
6
  ## 1.0.1
2
7
 
3
8
  * Added a dependency on `responders` gem for Rails 4.2 support
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'
@@ -2,7 +2,16 @@
2
2
 
3
3
  _Makes using Roar's representers in your Rails app fun._
4
4
 
5
- Roar is a framework for parsing and rendering REST documents. For a better overview about representers please check the [roar repository](https://github.com/apotonick/roar#roar).
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 lately as possible, usually it works when you require in the controller. We are working on fixing that problem.
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 => "../"
@@ -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
- Uber::Version.new(::ActionPack::VERSION::STRING)
22
+ Gem::Version.new([ActionPack::VERSION::MAJOR, ActionPack::VERSION::MINOR].join('.'))
24
23
  end
25
24
 
26
- if rails_version.~ 3.0
25
+ case rails_version
26
+ when Gem::Version.new(3.0)
27
27
  require 'roar/rails/rails3_0_strategy'
28
- elsif rails_version.~ 3.1
28
+ when Gem::Version.new(3.1)
29
29
  require 'roar/rails/rails3_1_strategy'
30
- elsif rails_version.~ 3.2
30
+ when Gem::Version.new(3.2)
31
31
  require 'roar/rails/rails3_2_strategy'
32
- elsif rails_version.~ 4.2
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'
@@ -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
@@ -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 Roar::Rails.rails_version.~ 3.0
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
@@ -1,8 +1,4 @@
1
- if ::ActionPack::VERSION::MAJOR == 4
2
- require 'test_xml/mini_test'
3
- else
4
- require 'test_xml/test_unit'
5
- end
1
+ require 'minitest'
6
2
 
7
3
  module Roar
8
4
  module Rails
@@ -1,5 +1,5 @@
1
1
  module Roar
2
2
  module Rails
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -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", ">= 1.0.0", "<= 1.1.0"
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", ">= 0.0.5"
25
+ s.add_runtime_dependency "uber", "~> 0.0.7"
26
26
  s.add_runtime_dependency "responders"
27
27
 
28
- s.add_development_dependency "minitest"
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
@@ -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
- test "#do not consume missing content type" do
86
- assert_raises Roar::Rails::UnsupportedMediaType do
87
- post :consume_json, "{\"name\": \"Bumi\"}"
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
- test "#do not consume parses unknown content type" do
93
- @request.env['CONTENT_TYPE'] = 'application/custom+json'
94
- assert_raises Roar::Rails::UnsupportedMediaType do
95
- post :consume_json, "{\"name\": \"Bumi\"}"
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 Roar::Rails.rails_version.~ 4.2
35
+ if Rails::VERSION::MAJOR >= 4
36
36
  config.eager_load = false
37
37
  config.active_support.test_order = :random
38
38
  end
@@ -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").must_equal nil
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.must_equal nil }
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 HalRendererTest < ActionController::TestCase
3
+ class JsonApiRendererTest < ActionController::TestCase
4
4
  include Roar::Rails::TestCase
5
5
 
6
6
  class SingersController < ActionController::Base
7
- module JsonApiSingerRepresenter
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
- represents :json_api, :entity => JsonApiSingerRepresenter
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 => "bumi", :format => :json_api
27
- assert_body '{"singer":{"name":"Bumi"}}'
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 have a content_type of application/vnd.api+json" do
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
@@ -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
- assert_body '{"title":"Bumi"}'
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::Representer::JSON/
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::Representer::XML/
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
@@ -417,7 +417,7 @@ class ResponderTest < ActionController::TestCase
417
417
  end
418
418
 
419
419
  def bumi_json
420
- return "[\"Bumi\"]" if Roar::Rails.rails_version.~ 3.0
420
+ return "[\"Bumi\"]" if (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0)
421
421
  "{\"name\":\"Bumi\"}"
422
422
  end
423
423
  end
@@ -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::HAL
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::JSONAPI
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.1
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: 2015-01-21 00:00:00.000000000 Z
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.1.0
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.1.0
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.5
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.5
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/Gemfile.rails3-0
189
- - gemfiles/Gemfile.rails3-2
190
- - gemfiles/Gemfile.rails4-0
191
- - gemfiles/Gemfile.rails4-1
192
- - gemfiles/Gemfile.rails4-2
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.2.2
285
+ rubygems_version: 2.5.1
261
286
  signing_key:
262
287
  specification_version: 4
263
288
  summary: Use Roar in Rails.
@@ -1,9 +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', '~> 3.0.11'
7
- gem 'activerecord', '~> 3.0.11'
8
- gem 'minitest', '4.7.5'
9
-
@@ -1,9 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in roar-rails.gemspec
4
- gemspec :path => '../'
5
-
6
-
7
- gem 'railties', '~> 3.2.13'
8
- gem 'activerecord', '~> 3.2.13'
9
- gem 'minitest', '4.7.5'
@@ -1,10 +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.0.0'
7
- gem 'actionpack', '~> 4.0.0'
8
-
9
- gem 'activemodel', '~> 4.0.0'
10
- gem 'activerecord', '~> 4.0.0'
@@ -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'
@@ -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'