tokamak 1.1.2 → 1.1.3

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.
@@ -12,9 +12,7 @@ module Tokamak
12
12
  #{const.name}.build(obj, *args, &block)
13
13
  end
14
14
 
15
- def member(obj, *args, &block)
16
- #{const.name}.build(obj, *args, &block)
17
- end
15
+ alias_method :member, :collection
18
16
  EOS
19
17
  mod
20
18
  end
@@ -41,7 +41,10 @@ module Tokamak
41
41
  end
42
42
 
43
43
  def link(relationship, uri, options = {})
44
- options["rel"] = relationship.to_s
44
+ # Start link array
45
+ @current["link"] = [] unless @current["link"]
46
+
47
+ options["rel"] = relationship.to_s
45
48
  options["href"] = uri
46
49
  options["type"] ||= options[:type] || "application/json"
47
50
  insert_value("link", nil, options)
@@ -2,7 +2,7 @@ module Tokamak
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
 
@@ -1183,3 +1183,63 @@ Completed in 10ms (View: 9 | 200 OK [http://www.example.com/test/feed]
1183
1183
  Processing TestController#show (for 127.0.0.1 at 2011-01-06 16:58:12) [GET]
1184
1184
  Rendering test/show
1185
1185
  Completed in 4ms (View: 2 | 200 OK [http://www.example.com/test/show]
1186
+
1187
+
1188
+ Processing TestController#show (for 127.0.0.1 at 2011-01-06 17:03:09) [GET]
1189
+ Rendering test/show
1190
+ Completed in 9ms (View: 7 | 200 OK [http://www.example.com/test/show]
1191
+
1192
+
1193
+ Processing TestController#feed (for 127.0.0.1 at 2011-01-06 17:03:09) [GET]
1194
+ Rendering test/feed
1195
+ Completed in 10ms (View: 9 | 200 OK [http://www.example.com/test/feed]
1196
+
1197
+
1198
+ Processing TestController#show (for 127.0.0.1 at 2011-01-06 17:03:09) [GET]
1199
+ Rendering test/show
1200
+ Completed in 4ms (View: 2 | 200 OK [http://www.example.com/test/show]
1201
+
1202
+
1203
+ Processing TestController#show (for 127.0.0.1 at 2011-01-06 17:04:25) [GET]
1204
+ Rendering test/show
1205
+ Completed in 8ms (View: 6 | 200 OK [http://www.example.com/test/show]
1206
+
1207
+
1208
+ Processing TestController#feed (for 127.0.0.1 at 2011-01-06 17:04:25) [GET]
1209
+ Rendering test/feed
1210
+ Completed in 10ms (View: 9 | 200 OK [http://www.example.com/test/feed]
1211
+
1212
+
1213
+ Processing TestController#show (for 127.0.0.1 at 2011-01-06 17:04:25) [GET]
1214
+ Rendering test/show
1215
+ Completed in 4ms (View: 2 | 200 OK [http://www.example.com/test/show]
1216
+
1217
+
1218
+ Processing TestController#show (for 127.0.0.1 at 2011-01-28 15:01:35) [GET]
1219
+ Rendering test/show
1220
+ Completed in 13ms (View: 10 | 200 OK [http://www.example.com/test/show]
1221
+
1222
+
1223
+ Processing TestController#feed (for 127.0.0.1 at 2011-01-28 15:01:35) [GET]
1224
+ Rendering test/feed
1225
+ Completed in 48ms (View: 47 | 200 OK [http://www.example.com/test/feed]
1226
+
1227
+
1228
+ Processing TestController#show (for 127.0.0.1 at 2011-01-28 15:01:35) [GET]
1229
+ Rendering test/show
1230
+ Completed in 4ms (View: 2 | 200 OK [http://www.example.com/test/show]
1231
+
1232
+
1233
+ Processing TestController#show (for 127.0.0.1 at 2011-02-16 16:46:22) [GET]
1234
+ Rendering test/show
1235
+ Completed in 8ms (View: 7 | 200 OK [http://www.example.com/test/show]
1236
+
1237
+
1238
+ Processing TestController#feed (for 127.0.0.1 at 2011-02-16 16:46:22) [GET]
1239
+ Rendering test/feed
1240
+ Completed in 55ms (View: 53 | 200 OK [http://www.example.com/test/feed]
1241
+
1242
+
1243
+ Processing TestController#show (for 127.0.0.1 at 2011-02-16 16:46:22) [GET]
1244
+ Rendering test/show
1245
+ Completed in 4ms (View: 2 | 200 OK [http://www.example.com/test/show]
@@ -1,7 +1,10 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- require 'ruby-debug'
4
3
  require "methodize"
5
4
 
5
+ begin
6
+ require 'ruby-debug'
7
+ rescue Exception => e; end
8
+
6
9
  require File.expand_path(File.dirname(__FILE__) + '/../lib/tokamak.rb')
7
10
 
@@ -24,6 +24,7 @@ class Tokamak::Builder::JsonTest < Test::Unit::TestCase
24
24
 
25
25
  assert_equal "an_id", hash.id
26
26
  assert_equal "bar" , hash.members.first.id
27
+ assert hash.members.kind_of?(Array)
27
28
  end
28
29
 
29
30
  def test_root_set_on_builder
@@ -69,6 +70,29 @@ class Tokamak::Builder::JsonTest < Test::Unit::TestCase
69
70
  assert_equal 4 , hash.members.size
70
71
  end
71
72
 
73
+ def test_collection_set_on_members_only_one
74
+ obj = { :foo => "bar" }
75
+ a_collection = [1]
76
+ json = Tokamak::Builder::Json.build(obj) do |collection|
77
+ collection.values do |values|
78
+ values.id "an_id"
79
+ end
80
+
81
+ collection.members(:collection => a_collection) do |member, number|
82
+ member.values do |values|
83
+ values.id number
84
+ end
85
+ end
86
+ end
87
+
88
+ hash = JSON.parse(json).extend(Methodize)
89
+
90
+ assert_equal "an_id", hash.id
91
+ assert_equal 1 , hash.members.first.id
92
+ assert_equal 1 , hash.members.size
93
+ assert hash.members.kind_of?(Array)
94
+ end
95
+
72
96
  def test_raise_exception_for_not_passing_a_collection_as_parameter_to_members
73
97
  obj = 42
74
98
 
@@ -131,6 +155,33 @@ class Tokamak::Builder::JsonTest < Test::Unit::TestCase
131
155
  assert_equal 2 , hash.body.legs.count
132
156
  assert_equal 4 , hash.body.legs.last.left.fingers_count
133
157
  end
158
+
159
+ def test_build_single_link_in_collection_and_member
160
+ obj = [{ :foo => "bar" }]
161
+ json = Tokamak::Builder::Json.build(obj) do |collection|
162
+ collection.values do |values|
163
+ values.id "an_id"
164
+ end
165
+
166
+ collection.link 'self', "http://example.com/an_id"
167
+
168
+ collection.members do |member, some_foos|
169
+ member.values do |values|
170
+ values.id some_foos[:foo]
171
+ end
172
+
173
+ member.link 'self', "http://example.com/an_id/#{some_foos[:foo]}"
174
+ end
175
+ end
176
+
177
+ hash = JSON.parse(json).extend(Methodize)
178
+
179
+ assert_equal "an_id", hash.id
180
+ assert_equal "bar" , hash.members.first.id
181
+ assert hash.members.kind_of?(Array)
182
+ assert hash.link.kind_of?(Array)
183
+ assert hash.members.first.link.kind_of?(Array)
184
+ end
134
185
 
135
186
  def test_build_full_collection
136
187
  time = Time.now
@@ -1,9 +1,12 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- require 'ruby-debug'
4
3
  require "methodize"
5
4
  require "rack/conneg"
6
5
 
6
+ begin
7
+ require 'ruby-debug'
8
+ rescue Exception => e; end
9
+
7
10
  require File.expand_path(File.dirname(__FILE__) + '/../../rails2_skel/config/environment.rb')
8
11
 
9
12
  # put the require below to use tokamak in your rails project
@@ -1,10 +1,13 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- require 'ruby-debug'
4
3
  require "methodize"
5
4
  require "sinatra"
6
5
  require "rack/conneg"
7
6
 
7
+ begin
8
+ require 'ruby-debug'
9
+ rescue Exception => e; end
10
+
8
11
  # requiring the hook for sinatra
9
12
  require "tokamak/hook/sinatra"
10
13
 
@@ -1,9 +1,12 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- require 'ruby-debug'
4
3
  require "methodize"
5
4
  require "tilt"
6
5
 
6
+ begin
7
+ require 'ruby-debug'
8
+ rescue Exception => e; end
9
+
7
10
  require "tokamak/hook/tilt"
8
11
 
9
12
  class Tokamak::Hook::TiltTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokamak
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luis Cipriani
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-06 00:00:00 -02:00
18
+ date: 2011-02-16 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency