rabl 0.7.3 → 0.7.4

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.
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.7.4 (unreleased)
3
+ ## 0.7.5 (unreleased)
4
+
5
+ ## 0.7.4
6
+
7
+ * Fix issue #347 with extends failing for custom object templates
4
8
 
5
9
  ## 0.7.3
6
10
 
data/README.md CHANGED
@@ -514,6 +514,7 @@ the [RABL Wiki](https://github.com/nesquena/rabl/wiki) for other usages.
514
514
  Tutorials can always be helpful when first getting started:
515
515
 
516
516
  * [Railscasts #322](http://railscasts.com/episodes/322-rabl)
517
+ * [Creating an API with RABL and Padrino](http://blog.crowdint.com/2012/10/22/rabl-with-padrino.html)
517
518
  * http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-devise/
518
519
  * http://engineering.gomiso.com/2011/06/27/building-a-platform-api-on-rails/
519
520
  * http://blog.lawrencenorton.com/better-json-requests-with-rabl
@@ -21,7 +21,6 @@ module Rabl
21
21
  # options must have :source (rabl file contents)
22
22
  # options can have :source_location (source filename)
23
23
  def object_to_hash(object, options={}, &block)
24
- return object unless is_object?(object) || is_collection?(object)
25
24
  return [] if is_collection?(object) && object.blank? # empty collection
26
25
  engine_options = options.reverse_merge(:format => "hash", :view_path => @_view_path, :root => (options[:root] || false))
27
26
  Rabl::Engine.new(options[:source], engine_options).render(@_scope, :object => object, &block)
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
@@ -1,17 +1,19 @@
1
1
  unless defined?(User)
2
2
  class User
3
- attr_accessor :age, :city, :name, :first
3
+ attr_accessor :age, :city, :name, :first, :float
4
4
 
5
5
  DEFAULT_AGE = 24
6
6
  DEFAULT_CITY = 'irvine'
7
7
  DEFAULT_NAME = 'rabl'
8
8
  DEFAULT_FIRST = 'bob'
9
+ DEFAULT_FLOAT = 1234.56
9
10
 
10
11
  def initialize(attributes={})
11
12
  self.age = attributes[:age] || DEFAULT_AGE
12
13
  self.city = attributes[:city] || DEFAULT_CITY
13
14
  self.name = attributes[:name] || DEFAULT_NAME
14
15
  self.first = attributes[:first] || DEFAULT_FIRST
16
+ self.float = attributes[:float] || DEFAULT_FLOAT
15
17
  end
16
18
  end
17
19
  end
@@ -122,6 +122,44 @@ context "Rabl::Renderer" do
122
122
  JSON.parse(renderer.render)
123
123
  end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"irvine\"}}")
124
124
 
125
+ asserts 'handles extends with custom node and object set false' do
126
+ File.open(tmp_path + "test.json.rabl", "w") do |f|
127
+ f.puts %q{
128
+ node(:foo) { 'baz' }
129
+ }
130
+ end
131
+
132
+ File.open(tmp_path + "user.json.rabl", "w") do |f|
133
+ f.puts %(
134
+ object false
135
+ node(:baz) { "bar" }
136
+ extends 'test'
137
+ )
138
+ end
139
+
140
+ renderer = Rabl::Renderer.new('user', false, :view_path => tmp_path)
141
+ JSON.parse(renderer.render)
142
+ end.equals(JSON.parse(%Q^{"foo":"baz", "baz":"bar" }^))
143
+
144
+ asserts 'handles extends with attributes and object set false' do
145
+ File.open(tmp_path + "test.json.rabl", "w") do |f|
146
+ f.puts %q{
147
+ attributes :foo, :bar, :baz
148
+ node(:test) { |bar| bar.demo if bar }
149
+ }
150
+ end
151
+
152
+ File.open(tmp_path + "user.json.rabl", "w") do |f|
153
+ f.puts %(
154
+ object false
155
+ extends 'test'
156
+ )
157
+ end
158
+
159
+ renderer = Rabl::Renderer.new('user', false, :view_path => tmp_path)
160
+ JSON.parse(renderer.render)
161
+ end.equals(JSON.parse(%Q^{"test": null}^))
162
+
125
163
  # FIXME template is found and rendered but not included in final results
126
164
  # asserts 'handles paths for partial' do
127
165
  # File.open(tmp_path + "test.json.rabl", "w") do |f|
@@ -218,13 +256,13 @@ context "Rabl::Renderer" do
218
256
  File.open(tmp_path + "test.rabl", "w") do |f|
219
257
  f.puts %q{
220
258
  object @user
221
- attributes :age, :name
259
+ attributes :age, :name, :float
222
260
  }
223
261
  end
224
262
 
225
263
  user = User.new(:name => 'ivan')
226
264
  JSON.parse(Rabl::Renderer.json(user, 'test', :view_path => tmp_path))
227
- end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"ivan\"}}")
265
+ end.equals JSON.parse("{\"user\":{\"age\":24,\"name\":\"ivan\",\"float\":1234.56}}")
228
266
  end
229
267
 
230
268
  context '.msgpack' do
@@ -232,13 +270,13 @@ context "Rabl::Renderer" do
232
270
  File.open(tmp_path + "test.rabl", "w") do |f|
233
271
  f.puts %q{
234
272
  object @user
235
- attributes :age, :name
273
+ attributes :age, :name, :float
236
274
  }
237
275
  end
238
276
 
239
277
  user = User.new(:name => 'ivan')
240
278
  Rabl::Renderer.msgpack(user, 'test', :view_path => tmp_path)
241
- end.equals "\x81\xA4user\x82\xA3age\x18\xA4name\xA4ivan"
279
+ end.equals "\x81\xA4user\x83\xA3age\x18\xA4name\xA4ivan\xA5float\xCB@\x93J=p\xA3\xD7\n"
242
280
  end
243
281
 
244
282
  context '.plist' do
@@ -246,12 +284,12 @@ context "Rabl::Renderer" do
246
284
  File.open(tmp_path + "test.rabl", "w") do |f|
247
285
  f.puts %q{
248
286
  object @user
249
- attributes :age, :name
287
+ attributes :age, :name, :float
250
288
  }
251
289
  end
252
290
 
253
291
  user = User.new(:name => 'ivan')
254
292
  Rabl::Renderer.plist(user, 'test', :view_path => tmp_path)
255
- end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>age</key>\n\t\t<integer>24</integer>\n\t\t<key>name</key>\n\t\t<string>ivan</string>\n\t</dict>\n</dict>\n</plist>\n"
293
+ end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>age</key>\n\t\t<integer>24</integer>\n\t\t<key>float</key>\n\t\t<real>1234.56</real>\n\t\t<key>name</key>\n\t\t<string>ivan</string>\n\t</dict>\n</dict>\n</plist>\n"
256
294
  end
257
295
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-15 00:00:00.000000000 Z
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport