transit-rails 0.8.0.beta → 0.8.1

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: d699027a2b416a7235950d3dba40abc58b31299a
4
- data.tar.gz: d696f53e7e5ceb2c23d2391f6717cfbb527ce829
3
+ metadata.gz: 54fb8c5fd98a4f514d0137ec258bd8bd42b31fe6
4
+ data.tar.gz: 14beb974c6c91c146774e0d8930fac9fb2882393
5
5
  SHA512:
6
- metadata.gz: 35ce5135b5ed7e1897224f87f8e7f71eb9471d347d3c3180859c583508c034c2fc82a5952a86a74c6b4490b30d09e064151e715ff1f1b7435e021be717a37bc9
7
- data.tar.gz: d5e514282eab988728a9705ed32f01b0a74148a82b2b40cc9ca98da7385a314e069a44b1b10424f748f931ee00ec0239cd4d641659b644fd0973f21305d6f51e
6
+ metadata.gz: 29d568f11beba71eda87c61d1dbc12f3fe44ca108528d255df2ee03bfb21aeaa2d2099b89ec72054fb09adeddd322943f8858c798931663540a3deabdf0f6f07
7
+ data.tar.gz: f119b7dfee76bb8fe18542076dcfcef2c951e965a38eebb6572be13e96a3c19f73772d8e79825797b56e43a7c469344783c7f6510bcd978af84cf51c2fe04f5d
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.1
4
+ - 2.0.0
5
+ - 1.9.3
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # transit-rails
2
2
 
3
- Use [transit format](https://github.com/cognitect/transit-format) in
4
- your Rails application, with minimal friction.
3
+ ![Travis status](https://travis-ci.org/jgdavey/transit-rails.svg?branch=master)
4
+
5
+ Use [transit format][] in your Rails application, with minimal friction.
5
6
 
6
7
  Currently only works with C-based Ruby implementations.
7
8
 
@@ -21,7 +22,7 @@ Or install it yourself as:
21
22
 
22
23
  ## Usage
23
24
 
24
- In your controller:
25
+ In a Rails controller:
25
26
 
26
27
  ```ruby
27
28
  def index
@@ -33,6 +34,28 @@ def index
33
34
  end
34
35
  ```
35
36
 
37
+ The renderer can take a `verbose` flag, which when true will output
38
+ transit in the `json-verbose` format.
39
+
40
+ ```ruby
41
+ def index
42
+ @posts = Post.all
43
+ render transit: @posts, verbose: true
44
+ end
45
+ ```
46
+
47
+ You can supply any custom handlers using the `handlers` option.
48
+
49
+ ```ruby
50
+ def index
51
+ @person = Person.new
52
+ render transit: @person, handlers: { Person => PersonHandler.new }
53
+ end
54
+ ```
55
+
56
+ Read more about [custom handlers][] on the
57
+ [transit-ruby][] README.
58
+
36
59
  ## Contributing
37
60
 
38
61
  1. Fork it ( https://github.com/jgdavey/transit-rails/fork )
@@ -40,3 +63,7 @@ end
40
63
  3. Commit your changes (`git commit -am 'Add some feature'`)
41
64
  4. Push to the branch (`git push origin my-new-feature`)
42
65
  5. Create a new Pull Request
66
+
67
+ [transit format]: https://github.com/cognitect/transit-format
68
+ [custom handlers]: https://github.com/cognitect/transit-ruby#custom-handlers
69
+ [transit-ruby]: https://github.com/cognitect/transit-ruby
@@ -1,5 +1,5 @@
1
1
  module Transit
2
2
  module Rails
3
- VERSION = "0.8.0.beta"
3
+ VERSION = "0.8.1"
4
4
  end
5
5
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'transit/rails/renderer'
3
+ require 'active_support/core_ext/time'
4
+
5
+ describe Transit::Rails::Renderer do
6
+ def render(obj, opts={}, io=StringIO.new)
7
+ Transit::Rails::Renderer.new(obj, opts, io).render
8
+ end
9
+
10
+ def decode(io, handlers={})
11
+ io = StringIO.new(io) unless io.respond_to?(:rewind)
12
+ io.rewind
13
+ Transit::Reader.new(:json, io, handlers: handlers).read
14
+ end
15
+
16
+ context "with custom handlers" do
17
+ Point = Struct.new(:x, :y)
18
+ point_handler = Class.new do
19
+ def tag(o)
20
+ "point"
21
+ end
22
+
23
+ def rep(o)
24
+ [o.x, o.y]
25
+ end
26
+
27
+ def string_rep(o)
28
+ rep(o).to_s
29
+ end
30
+
31
+ def from_rep(o)
32
+ Point.new(o[0], o[1])
33
+ end
34
+ end
35
+
36
+ it "correctly renders custom handlers at top level" do
37
+ handlers = { Point => point_handler.new }
38
+
39
+ io = StringIO.new
40
+ point = Point.new(1,2)
41
+ rendered = render(point, {handlers: handlers}, io)
42
+ expect(point).to eq decode(rendered, {"point" => point_handler.new})
43
+ end
44
+
45
+ it "correctly uses custom handlers in an Array" do
46
+ handlers = { Point => point_handler.new }
47
+
48
+ io = StringIO.new
49
+ points = [Point.new(1,2), Point.new(3,4)]
50
+ rendered = render(points, {handlers: handlers}, io)
51
+ expect(points).to eq decode(rendered, {"point" => point_handler.new})
52
+ end
53
+ end
54
+
55
+ context "verbosity" do
56
+ it "can render verbose JSON" do
57
+ obj = [Time.now, Time.now - 1]
58
+ verbose = render(obj, verbose: true)
59
+ terse = render(obj)
60
+ expect(verbose.length).to be > terse.length
61
+ end
62
+ end
63
+
64
+ context "time with zone" do
65
+ it "encodes ActiveSupport::TimeWithZone as a UTC time" do
66
+ Time.zone = "EST"
67
+ obj = Time.zone.now
68
+ rendered = render(obj)
69
+ # There's some truncation/rounding happening here, so strict equality
70
+ # won't suffice
71
+ expect(obj).to be_within(1).of(decode(rendered))
72
+ end
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transit-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.beta
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Davey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-31 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transit-ruby
@@ -81,6 +81,7 @@ files:
81
81
  - lib/transit/rails/renderer.rb
82
82
  - lib/transit/rails/version.rb
83
83
  - spec/spec_helper.rb
84
+ - spec/transit/rails/renderer_spec.rb
84
85
  - spec/transit/rails_spec.rb
85
86
  - transit-rails.gemspec
86
87
  homepage: https://github.com/jgdavey/transit-rails
@@ -98,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ">"
102
+ - - ">="
102
103
  - !ruby/object:Gem::Version
103
- version: 1.3.1
104
+ version: '0'
104
105
  requirements: []
105
106
  rubyforge_project:
106
107
  rubygems_version: 2.2.2
@@ -109,4 +110,5 @@ specification_version: 4
109
110
  summary: Transit format helpers for Rails
110
111
  test_files:
111
112
  - spec/spec_helper.rb
113
+ - spec/transit/rails/renderer_spec.rb
112
114
  - spec/transit/rails_spec.rb