acts_as_api 0.4.3 → 0.4.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.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/History.txt +8 -0
- data/README.md +2 -2
- data/acts_as_api.gemspec +2 -2
- data/examples/introduction/index.html +6 -6
- data/examples/introduction/index.rb +1 -1
- data/examples/introduction/layout.mustache +4 -4
- data/lib/acts_as_api.rb +18 -2
- data/lib/acts_as_api/collection.rb +17 -0
- data/lib/acts_as_api/config.rb +15 -15
- data/lib/acts_as_api/rails_renderer.rb +6 -2
- data/lib/acts_as_api/rendering.rb +4 -4
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/active_record_dummy/Gemfile +1 -1
- data/spec/active_record_dummy/app/models/profile.rb +2 -3
- data/spec/active_record_dummy/app/models/task.rb +2 -3
- data/spec/active_record_dummy/app/models/user.rb +6 -7
- data/spec/active_record_dummy/config/application.rb +0 -6
- data/spec/active_record_dummy/config/environments/development.rb +4 -7
- data/spec/active_record_dummy/config/environments/production.rb +0 -4
- data/spec/active_record_dummy/config/environments/test.rb +3 -3
- data/spec/controllers/plain_objects_controller_spec.rb +2 -1
- data/spec/controllers/respond_with_users_controller_spec.rb +8 -8
- data/spec/mongoid_dummy/Gemfile +2 -2
- data/spec/mongoid_dummy/config/application.rb +0 -7
- data/spec/mongoid_dummy/config/environments/development.rb +4 -0
- data/spec/mongoid_dummy/config/environments/test.rb +3 -1
- data/spec/mongoid_dummy/config/mongoid.yml +4 -112
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +1 -1
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +6 -6
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +8 -4
- data/spec/shared_engine/dummy/config/application.rb +0 -6
- data/spec/shared_engine/dummy/config/environments/development.rb +4 -7
- data/spec/shared_engine/dummy/config/environments/production.rb +0 -4
- data/spec/shared_engine/dummy/config/environments/test.rb +3 -3
- data/spec/shared_engine/shared_engine.gemspec +1 -1
- data/spec/spec_helper.rb +7 -5
- data/spec/support/controller_examples.rb +23 -47
- data/spec/support/model_examples/associations.rb +59 -59
- metadata +4 -8
- data/lib/acts_as_api/array.rb +0 -21
- data/spec/shared_engine/lib/magic/rails/engine.rb +0 -69
- data/spec/support/routing.rb +0 -4
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
|
16
16
|
|
17
|
-
s.add_dependency "rails", "~>
|
17
|
+
s.add_dependency "rails", "~> 5.0.0.1"
|
18
18
|
# s.add_dependency "jquery-rails"
|
19
19
|
|
20
20
|
s.add_development_dependency "sqlite3"
|
data/spec/spec_helper.rb
CHANGED
@@ -3,11 +3,9 @@ ENV["RAILS_ENV"] = "test"
|
|
3
3
|
if ENV['ACTS_AS_API_ORM'] == 'active_record'
|
4
4
|
require "active_record_dummy/config/environment"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
silence_stream(STDOUT, &load_schema)
|
6
|
+
load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default
|
7
|
+
# ActiveRecord::Migrator.up('db/migrate') # use migrations
|
8
|
+
|
11
9
|
|
12
10
|
elsif ENV['ACTS_AS_API_ORM'] == 'mongoid'
|
13
11
|
|
@@ -20,3 +18,7 @@ require 'rspec/rails'
|
|
20
18
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
21
19
|
# in spec/support/ and its subdirectories.
|
22
20
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file }
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
24
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
shared_examples_for "a controller with ActsAsApi responses" do
|
2
|
-
|
3
2
|
include ApiTestHelpers
|
3
|
+
routes { SharedEngine::Engine.routes }
|
4
4
|
|
5
5
|
describe 'xml responses' do
|
6
6
|
|
7
7
|
describe 'get all users' do
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
get :index, :
|
10
|
+
get :index, format: 'xml', params: { api_template: :name_only }
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should have a root node named users" do
|
@@ -30,7 +30,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
30
30
|
describe 'get a single user' do
|
31
31
|
|
32
32
|
before(:each) do
|
33
|
-
get :show, :
|
33
|
+
get :show, format: 'xml', params: { api_template: :name_only, id: @luke.id }
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should have a root node named user" do
|
@@ -43,28 +43,6 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
46
|
-
|
47
|
-
describe 'get a user without specifying an api template' do
|
48
|
-
|
49
|
-
before(:each) do
|
50
|
-
get :show_default, :format => 'xml', :id => @luke.id
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should respond with HTTP 200" do
|
54
|
-
response.code.should == "200"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should render the model with standard to_xml" do
|
58
|
-
# TODO: figure out how to compare xml generated by mongo models.
|
59
|
-
|
60
|
-
# This line works fine with ActiveRecord, but not Mongoid:
|
61
|
-
# response.body.should == @luke.to_xml
|
62
|
-
|
63
|
-
response.body.length.should == @luke.to_xml.length
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
46
|
end
|
69
47
|
|
70
48
|
describe 'json responses' do
|
@@ -72,7 +50,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
72
50
|
describe 'get all users' do
|
73
51
|
|
74
52
|
before(:each) do
|
75
|
-
get :index, :
|
53
|
+
get :index, format: 'json', params: { api_template: :name_only }
|
76
54
|
end
|
77
55
|
|
78
56
|
it "should have a root node named users" do
|
@@ -98,7 +76,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
98
76
|
describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do
|
99
77
|
|
100
78
|
before(:each) do
|
101
|
-
get :index_relation, :
|
79
|
+
get :index_relation, format: 'json', params: { api_template: :name_only }
|
102
80
|
end
|
103
81
|
|
104
82
|
it "should have a root node named users" do
|
@@ -124,7 +102,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
124
102
|
describe 'get a single user' do
|
125
103
|
|
126
104
|
before(:each) do
|
127
|
-
get :show, :
|
105
|
+
get :show, format: 'json', params: { api_template: :name_only, id: @luke.id }
|
128
106
|
end
|
129
107
|
|
130
108
|
it "should have a root node named user" do
|
@@ -152,7 +130,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
152
130
|
t.add :homepage
|
153
131
|
end
|
154
132
|
|
155
|
-
get :show, :
|
133
|
+
get :show, format: 'json', params: { api_template: :include_profile, id: @han.id }
|
156
134
|
end
|
157
135
|
|
158
136
|
it "should have a root node named user" do
|
@@ -173,7 +151,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
173
151
|
describe 'get a user without specifying an api template' do
|
174
152
|
|
175
153
|
before(:each) do
|
176
|
-
get :show_default, :
|
154
|
+
get :show_default, format: 'json', params: { id: @luke.id }
|
177
155
|
end
|
178
156
|
|
179
157
|
it "should respond with HTTP 200" do
|
@@ -202,7 +180,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
202
180
|
describe 'get all users' do
|
203
181
|
|
204
182
|
before(:each) do
|
205
|
-
get :index, :
|
183
|
+
get :index, format: 'json', params: { api_template: :name_only }
|
206
184
|
end
|
207
185
|
|
208
186
|
it "should have a root node named users" do
|
@@ -232,7 +210,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
232
210
|
describe 'get a single user' do
|
233
211
|
|
234
212
|
before(:each) do
|
235
|
-
get :show, :
|
213
|
+
get :show, format: 'json', params: { api_template: :name_only, id: @luke.id }
|
236
214
|
end
|
237
215
|
|
238
216
|
it "should have a root node named user" do
|
@@ -256,7 +234,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
256
234
|
|
257
235
|
it "should be disabled by default" do
|
258
236
|
@callback = "mycallback"
|
259
|
-
get :index, :
|
237
|
+
get :index, format: 'json', params: { api_template: :name_only, callback: @callback }
|
260
238
|
response_body_jsonp(@callback).should be_nil
|
261
239
|
end
|
262
240
|
|
@@ -280,7 +258,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
280
258
|
describe 'get all users' do
|
281
259
|
|
282
260
|
before(:each) do
|
283
|
-
get :index, :
|
261
|
+
get :index, format: 'json', params: { api_template: :name_only, callback: @callback }
|
284
262
|
end
|
285
263
|
|
286
264
|
it "should wrap the response in the callback" do
|
@@ -292,7 +270,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
292
270
|
describe 'get a single user' do
|
293
271
|
|
294
272
|
before(:each) do
|
295
|
-
get :show, :
|
273
|
+
get :show, format: 'json', params: { api_template: :name_only, id: @luke.id, callback: @callback }
|
296
274
|
end
|
297
275
|
|
298
276
|
it "should wrap the response in the callback" do
|
@@ -302,17 +280,14 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
302
280
|
end
|
303
281
|
|
304
282
|
describe 'Requesting the JSONP content as JavaScript' do
|
305
|
-
|
306
283
|
before(:each) do
|
307
|
-
get :index, :
|
284
|
+
get :index, format: :json, params: { api_template: :name_only, callback: @callback }
|
308
285
|
end
|
309
286
|
|
310
287
|
it "should set the content type to JavaScript" do
|
311
|
-
response.content_type.should == Mime
|
288
|
+
response.content_type.should == Mime[:js]
|
312
289
|
end
|
313
|
-
|
314
290
|
end
|
315
|
-
|
316
291
|
end
|
317
292
|
end
|
318
293
|
|
@@ -328,7 +303,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
328
303
|
|
329
304
|
describe 'get all users' do
|
330
305
|
before(:each) do
|
331
|
-
get :index, :
|
306
|
+
get :index, format: 'json', params: { api_template: :name_only, callback: @callback }
|
332
307
|
end
|
333
308
|
|
334
309
|
its "response has no named root node" do
|
@@ -338,7 +313,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
338
313
|
|
339
314
|
describe 'get a single user' do
|
340
315
|
before(:each) do
|
341
|
-
get :show, :
|
316
|
+
get :show, format: 'json', params: { api_template: :name_only, id: @luke.id }
|
342
317
|
end
|
343
318
|
|
344
319
|
its "response has no named root node" do
|
@@ -352,7 +327,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
352
327
|
|
353
328
|
describe 'get all users' do
|
354
329
|
before(:each) do
|
355
|
-
get :index_meta, :
|
330
|
+
get :index_meta, format: 'json', params: { api_template: :name_only }
|
356
331
|
end
|
357
332
|
|
358
333
|
it "shows model response fields" do
|
@@ -372,7 +347,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
372
347
|
|
373
348
|
describe 'get a single user' do
|
374
349
|
before(:each) do
|
375
|
-
get :show_meta, :
|
350
|
+
get :show_meta, format: 'json', params: { api_template: :name_only, id: @luke.id }
|
376
351
|
end
|
377
352
|
|
378
353
|
it "shows model response fields" do
|
@@ -397,7 +372,8 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
397
372
|
describe 'get single user' do
|
398
373
|
|
399
374
|
before(:each) do
|
400
|
-
get :show_prefix_postfix, :
|
375
|
+
get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, id: @luke.id }
|
376
|
+
|
401
377
|
end
|
402
378
|
|
403
379
|
it "should have a root node named user" do
|
@@ -423,7 +399,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
423
399
|
describe 'get single user' do
|
424
400
|
|
425
401
|
before(:each) do
|
426
|
-
get :show_prefix_postfix, :
|
402
|
+
get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_postfix: :with_postfix, id: @luke.id }
|
427
403
|
end
|
428
404
|
|
429
405
|
it "should have a root node named user" do
|
@@ -449,7 +425,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
449
425
|
describe 'get single user' do
|
450
426
|
|
451
427
|
before(:each) do
|
452
|
-
get :show_prefix_postfix, :
|
428
|
+
get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, api_postfix: :with_postfix, :id => @luke.id }
|
453
429
|
end
|
454
430
|
|
455
431
|
it "should have a root node named user" do
|
@@ -1,37 +1,37 @@
|
|
1
1
|
shared_examples_for "including an association in the api template" do
|
2
|
-
|
2
|
+
|
3
3
|
describe "which doesn't acts_as_api" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:each) do
|
6
6
|
@response = @luke.as_api_response(:include_tasks)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "returns a hash" do
|
10
10
|
@response.should be_kind_of(Hash)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "returns the correct number of fields" do
|
14
14
|
@response.should have(1).keys
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "returns all specified fields" do
|
18
18
|
@response.keys.should include(:tasks)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "returns the correct values for the specified fields" do
|
22
22
|
@response[:tasks].should be_an Array
|
23
23
|
@response[:tasks].should have(3).tasks
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should contain the associated sub models" do
|
27
27
|
@response[:tasks].should include(@destroy_deathstar, @study_with_yoda, @win_rebellion)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
describe "which does acts_as_api" do
|
32
|
-
|
32
|
+
|
33
33
|
context "has_many" do
|
34
|
-
|
34
|
+
|
35
35
|
before(:each) do
|
36
36
|
Task.acts_as_api
|
37
37
|
Task.api_accessible :include_tasks do |t|
|
@@ -40,39 +40,39 @@ shared_examples_for "including an association in the api template" do
|
|
40
40
|
end
|
41
41
|
@response = @luke.as_api_response(:include_tasks)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "returns a hash" do
|
45
45
|
@response.should be_kind_of(Hash)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "returns the correct number of fields" do
|
49
49
|
@response.should have(1).keys
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "returns all specified fields" do
|
53
53
|
@response.keys.should include(:tasks)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "returns the correct values for the specified fields" do
|
57
57
|
@response[:tasks].should be_an Array
|
58
58
|
@response[:tasks].should have(3).tasks
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "contains the associated child models with the determined api template" do
|
62
62
|
@response[:tasks].each do |task|
|
63
63
|
task.keys.should include(:heading, :done)
|
64
64
|
task.keys.should have(2).attributes
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "contains the correct data of the child models" do
|
69
69
|
task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :done => t.done, :heading => t.heading } }
|
70
70
|
@response[:tasks].should eql task_hash
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
context "has_one" do
|
75
|
-
|
75
|
+
|
76
76
|
before(:each) do
|
77
77
|
Profile.acts_as_api
|
78
78
|
Profile.api_accessible :include_profile do |t|
|
@@ -81,38 +81,38 @@ shared_examples_for "including an association in the api template" do
|
|
81
81
|
end
|
82
82
|
@response = @luke.as_api_response(:include_profile)
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it "returns a hash" do
|
86
86
|
@response.should be_kind_of(Hash)
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "returns the correct number of fields" do
|
90
90
|
@response.should have(1).keys
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "returns all specified fields" do
|
94
94
|
@response.keys.should include(:profile)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
it "returns the correct values for the specified fields" do
|
98
98
|
@response[:profile].should be_a Hash
|
99
99
|
@response[:profile].should have(2).attributes
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it "contains the associated child models with the determined api template" do
|
103
103
|
@response[:profile].keys.should include(:avatar, :homepage)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it "contains the correct data of the child models" do
|
107
107
|
profile_hash = { :avatar => @luke.profile.avatar, :homepage => @luke.profile.homepage }
|
108
108
|
@response[:profile].should eql profile_hash
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
describe "which does acts_as_api, but with using another template name" do
|
115
|
-
|
115
|
+
|
116
116
|
before(:each) do
|
117
117
|
Task.acts_as_api
|
118
118
|
Task.api_accessible :other_template do |t|
|
@@ -121,96 +121,96 @@ shared_examples_for "including an association in the api template" do
|
|
121
121
|
end
|
122
122
|
@response = @luke.as_api_response(:other_sub_template)
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it "returns a hash" do
|
126
126
|
@response.should be_kind_of(Hash)
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
it "returns the correct number of fields" do
|
130
130
|
@response.should have(2).keys
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
it "returns all specified fields" do
|
134
134
|
@response.keys.should include(:first_name)
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
it "returns the correct values for the specified fields" do
|
138
138
|
@response.values.should include(@luke.first_name)
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
it "returns all specified fields" do
|
142
142
|
@response.keys.should include(:tasks)
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "returns the correct values for the specified fields" do
|
146
146
|
@response[:tasks].should be_an Array
|
147
147
|
@response[:tasks].should have(3).tasks
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
it "contains the associated child models with the determined api template" do
|
151
151
|
@response[:tasks].each do |task|
|
152
152
|
task.keys.should include(:description, :time_spent)
|
153
153
|
task.keys.should have(2).attributes
|
154
154
|
end
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
it "contains the correct data of the child models" do
|
158
158
|
task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } }
|
159
159
|
@response[:tasks].should eql task_hash
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
describe "that is scoped" do
|
164
|
-
|
164
|
+
|
165
165
|
before(:each) do
|
166
166
|
# extend task model with scope
|
167
167
|
#class Task < ActiveRecord::Base
|
168
168
|
Task.class_eval do
|
169
|
-
scope :completed, where(:done => true)
|
169
|
+
scope :completed, -> { where(:done => true) }
|
170
170
|
end
|
171
171
|
Task.acts_as_api
|
172
172
|
Task.api_accessible :include_completed_tasks do |t|
|
173
173
|
t.add :heading
|
174
174
|
t.add :done
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
@response = @luke.as_api_response(:include_completed_tasks)
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
it "returns a hash" do
|
181
181
|
@response.should be_kind_of(Hash)
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
it "returns the correct number of fields" do
|
185
185
|
@response.should have(1).keys
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it "returns all specified fields" do
|
189
189
|
@response.keys.should include(:completed_tasks)
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
it "returns the correct values for the specified fields" do
|
193
193
|
@response[:completed_tasks].should be_an Array
|
194
194
|
@response[:completed_tasks].should have(2).tasks
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
it "contains the associated child models with the determined api template" do
|
198
198
|
@response[:completed_tasks].each do |task|
|
199
199
|
task.keys.should include(:heading, :done)
|
200
200
|
task.keys.should have(2).attributes
|
201
201
|
end
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
it "contains the correct data of the child models" do
|
205
205
|
task_hash = [ @destroy_deathstar, @study_with_yoda ].collect{|t| { :done => t.done, :heading => t.heading } }
|
206
206
|
@response[:completed_tasks].should eql task_hash
|
207
207
|
end
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
describe "handling nil values" do
|
211
|
-
|
211
|
+
|
212
212
|
context "has_many" do
|
213
|
-
|
213
|
+
|
214
214
|
before(:each) do
|
215
215
|
Task.acts_as_api
|
216
216
|
Task.api_accessible :include_tasks do |t|
|
@@ -219,29 +219,29 @@ shared_examples_for "including an association in the api template" do
|
|
219
219
|
end
|
220
220
|
@response = @han.as_api_response(:include_tasks)
|
221
221
|
end
|
222
|
-
|
222
|
+
|
223
223
|
it "returns a hash" do
|
224
224
|
@response.should be_kind_of(Hash)
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
it "returns the correct number of fields" do
|
228
228
|
@response.should have(1).keys
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
it "returns all specified fields" do
|
232
232
|
@response.keys.should include(:tasks)
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
it "returns the correct values for the specified fields" do
|
236
236
|
@response[:tasks].should be_kind_of(Array)
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
it "contains no associated child models" do
|
240
240
|
@response[:tasks].should have(0).items
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
context "has one" do
|
246
246
|
before(:each) do
|
247
247
|
Profile.acts_as_api
|
@@ -251,19 +251,19 @@ shared_examples_for "including an association in the api template" do
|
|
251
251
|
end
|
252
252
|
@response = @han.as_api_response(:include_profile)
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
it "returns a hash" do
|
256
256
|
@response.should be_kind_of(Hash)
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
it "returns the correct number of fields" do
|
260
260
|
@response.should have(1).keys
|
261
261
|
end
|
262
|
-
|
262
|
+
|
263
263
|
it "returns all specified fields" do
|
264
264
|
@response.keys.should include(:profile)
|
265
265
|
end
|
266
|
-
|
266
|
+
|
267
267
|
it "returns nil for the association" do
|
268
268
|
@response[:profile].should be_nil
|
269
269
|
end
|