acts_as_api 0.3.5 → 0.3.6

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.
Files changed (54) hide show
  1. data/Gemfile +1 -1
  2. data/History.txt +5 -0
  3. data/README.rdoc +9 -2
  4. data/Rakefile +15 -1
  5. data/acts_as_api.gemspec +1 -0
  6. data/examples/introduction/index.html +7 -6
  7. data/examples/introduction/index.rb +9 -8
  8. data/lib/acts_as_api.rb +12 -5
  9. data/lib/acts_as_api/adapters.rb +5 -0
  10. data/lib/acts_as_api/adapters/mongoid.rb +11 -0
  11. data/lib/acts_as_api/array.rb +4 -8
  12. data/lib/acts_as_api/responder.rb +40 -0
  13. data/lib/acts_as_api/version.rb +1 -1
  14. data/spec/controllers/respond_with_users_controller_spec.rb +30 -2
  15. data/spec/controllers/users_controller_spec.rb +17 -235
  16. data/spec/models/active_record_spec.rb +28 -0
  17. data/spec/models/mongoid_spec.rb +28 -0
  18. data/spec/rails_app/app/controllers/respond_with_users_controller.rb +19 -8
  19. data/spec/rails_app/app/controllers/users_controller.rb +13 -4
  20. data/spec/rails_app/app/models/mongo_profile.rb +10 -0
  21. data/spec/rails_app/app/models/mongo_task.rb +12 -0
  22. data/spec/rails_app/app/models/mongo_untouched.rb +7 -0
  23. data/spec/rails_app/app/models/mongo_user.rb +149 -0
  24. data/spec/rails_app/app/models/user.rb +6 -6
  25. data/spec/rails_app/config/initializers/acts_as_api_mongoid.rb +6 -0
  26. data/spec/rails_app/config/mongoid.yml +23 -0
  27. data/spec/support/controller_examples.rb +246 -0
  28. data/spec/support/it_supports.rb +3 -0
  29. data/spec/support/model_examples/associations.rb +272 -0
  30. data/spec/support/model_examples/closures.rb +49 -0
  31. data/spec/support/model_examples/conditional_if.rb +165 -0
  32. data/spec/support/model_examples/conditional_unless.rb +165 -0
  33. data/spec/support/model_examples/enabled.rb +10 -0
  34. data/spec/support/model_examples/extending.rb +112 -0
  35. data/spec/support/model_examples/methods.rb +23 -0
  36. data/spec/support/model_examples/renaming.rb +50 -0
  37. data/spec/support/model_examples/simple.rb +23 -0
  38. data/spec/support/model_examples/sub_nodes.rb +105 -0
  39. data/spec/support/model_examples/undefined.rb +7 -0
  40. data/spec/support/model_examples/untouched.rb +13 -0
  41. data/spec/support/simple_fixtures.rb +39 -8
  42. metadata +67 -28
  43. data/spec/models/base/associations_spec.rb +0 -284
  44. data/spec/models/base/closures_spec.rb +0 -62
  45. data/spec/models/base/conditional_if_spec.rb +0 -178
  46. data/spec/models/base/conditional_unless_spec.rb +0 -178
  47. data/spec/models/base/enabled_spec.rb +0 -15
  48. data/spec/models/base/extending_spec.rb +0 -125
  49. data/spec/models/base/methods_spec.rb +0 -33
  50. data/spec/models/base/renaming_spec.rb +0 -63
  51. data/spec/models/base/simple_spec.rb +0 -33
  52. data/spec/models/base/sub_nodes_spec.rb +0 -118
  53. data/spec/models/base/undefined_spec.rb +0 -20
  54. data/spec/models/base/untouched_spec.rb +0 -18
@@ -0,0 +1,7 @@
1
+ shared_examples_for "trying to render an api template that is not defined" do
2
+
3
+ it "raises an descriptive error" do
4
+ lambda{ @luke.as_api_response(:does_not_exist) }.should raise_error(ActsAsApi::TemplateNotFoundError)
5
+ end
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ shared_examples_for "untouched models" do
2
+
3
+ describe "has disabled acts_as_api by default" do
4
+ it "indicates that acts_as_api is disabled" do
5
+ @untouched_model.acts_as_api?.should be_false
6
+ end
7
+
8
+ it "does not respond to api_accessible" do
9
+ @untouched_model.should_not respond_to :api_accessible
10
+ end
11
+ end
12
+
13
+ end
@@ -1,22 +1,53 @@
1
1
  module SimpleFixtures
2
2
 
3
- def setup_models
4
- @luke = User.create({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true })
5
- @han = User.create({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true })
6
- @leia = User.create({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false })
3
+ def setup_active_record_models
4
+ @orm_for_testing = :active_record
5
+ @user_model = User
6
+ @task_model = Task
7
+ @profile_model = Profile
8
+ @untouched_model = Untouched
7
9
 
8
- @luke.profile = Profile.create({ :avatar => 'picard.jpg', :homepage => 'lukasarts.com' })
10
+ @luke = @user_model.create({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true })
11
+ @han = @user_model.create({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true })
12
+ @leia = @user_model.create({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false })
13
+
14
+ @luke.profile = @profile_model.create({ :avatar => 'picard.jpg', :homepage => 'lukasarts.com' })
9
15
 
10
16
  @destroy_deathstar = @luke.tasks.create({ :heading => "Destroy Deathstar", :description => "XWing, Shoot, BlowUp", :time_spent => 30, :done => true })
11
17
  @study_with_yoda = @luke.tasks.create({ :heading => "Study with Yoda", :description => "Jedi Stuff, ya know", :time_spent => 60, :done => true })
12
18
  @win_rebellion = @luke.tasks.create({ :heading => "Win Rebellion", :description => "no idea yet...", :time_spent => 180, :done => false })
13
19
  end
14
20
 
15
- def clean_up
16
- User.delete_all
17
- Task.delete_all
21
+ def clean_up_active_record_models
22
+ @user_model.delete_all
23
+ @task_model.delete_all
24
+ end
25
+
26
+ def setup_mongoid_models
27
+ @orm_for_testing = :mongoid
28
+ @user_model = MongoUser
29
+ @task_model = MongoTask
30
+ @profile_model = MongoProfile
31
+ @untouched_model = MongoUntouched
32
+
33
+ @luke = @user_model.new({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true })
34
+ @han = @user_model.new({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true })
35
+ @leia = @user_model.new({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false })
36
+
37
+ @luke.build_profile({ :avatar => 'picard.jpg', :homepage => 'lukasarts.com' })
38
+
39
+ @destroy_deathstar = @luke.tasks.new({ :heading => "Destroy Deathstar", :description => "XWing, Shoot, BlowUp", :time_spent => 30, :done => true })
40
+ @study_with_yoda = @luke.tasks.new({ :heading => "Study with Yoda", :description => "Jedi Stuff, ya know", :time_spent => 60, :done => true })
41
+ @win_rebellion = @luke.tasks.new({ :heading => "Win Rebellion", :description => "no idea yet...", :time_spent => 180, :done => false })
42
+
43
+ @luke.save!
44
+ @han.save!
45
+ @leia.save!
18
46
  end
19
47
 
48
+ def clean_up_mongoid_models
49
+ @user_model.delete_all
50
+ end
20
51
 
21
52
  end
22
53
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Christian B\xC3\xA4uerlein"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-26 00:00:00 +02:00
18
+ date: 2011-05-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,22 @@ dependencies:
82
82
  version: 3.0.0
83
83
  type: :development
84
84
  version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: mongoid
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 15
94
+ segments:
95
+ - 2
96
+ - 0
97
+ - 0
98
+ version: 2.0.0
99
+ type: :development
100
+ version_requirements: *id005
85
101
  description: acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your XML/JSON API responses should look like.
86
102
  email:
87
103
  - christian@ffwdme.com
@@ -103,6 +119,8 @@ files:
103
119
  - examples/introduction/index.rb
104
120
  - examples/introduction/layout.mustache
105
121
  - lib/acts_as_api.rb
122
+ - lib/acts_as_api/adapters.rb
123
+ - lib/acts_as_api/adapters/mongoid.rb
106
124
  - lib/acts_as_api/api_template.rb
107
125
  - lib/acts_as_api/array.rb
108
126
  - lib/acts_as_api/base.rb
@@ -110,27 +128,22 @@ files:
110
128
  - lib/acts_as_api/exceptions.rb
111
129
  - lib/acts_as_api/rails_renderer.rb
112
130
  - lib/acts_as_api/rendering.rb
131
+ - lib/acts_as_api/responder.rb
113
132
  - lib/acts_as_api/version.rb
114
133
  - spec/controllers/respond_with_users_controller_spec.rb
115
134
  - spec/controllers/users_controller_spec.rb
116
- - spec/models/base/associations_spec.rb
117
- - spec/models/base/closures_spec.rb
118
- - spec/models/base/conditional_if_spec.rb
119
- - spec/models/base/conditional_unless_spec.rb
120
- - spec/models/base/enabled_spec.rb
121
- - spec/models/base/extending_spec.rb
122
- - spec/models/base/methods_spec.rb
123
- - spec/models/base/renaming_spec.rb
124
- - spec/models/base/simple_spec.rb
125
- - spec/models/base/sub_nodes_spec.rb
126
- - spec/models/base/undefined_spec.rb
127
- - spec/models/base/untouched_spec.rb
135
+ - spec/models/active_record_spec.rb
136
+ - spec/models/mongoid_spec.rb
128
137
  - spec/rails_app/.gitignore
129
138
  - spec/rails_app/Rakefile
130
139
  - spec/rails_app/app/controllers/application_controller.rb
131
140
  - spec/rails_app/app/controllers/respond_with_users_controller.rb
132
141
  - spec/rails_app/app/controllers/users_controller.rb
133
142
  - spec/rails_app/app/helpers/application_helper.rb
143
+ - spec/rails_app/app/models/mongo_profile.rb
144
+ - spec/rails_app/app/models/mongo_task.rb
145
+ - spec/rails_app/app/models/mongo_untouched.rb
146
+ - spec/rails_app/app/models/mongo_user.rb
134
147
  - spec/rails_app/app/models/profile.rb
135
148
  - spec/rails_app/app/models/task.rb
136
149
  - spec/rails_app/app/models/untouched.rb
@@ -144,12 +157,14 @@ files:
144
157
  - spec/rails_app/config/environments/development.rb
145
158
  - spec/rails_app/config/environments/production.rb
146
159
  - spec/rails_app/config/environments/test.rb
160
+ - spec/rails_app/config/initializers/acts_as_api_mongoid.rb
147
161
  - spec/rails_app/config/initializers/backtrace_silencers.rb
148
162
  - spec/rails_app/config/initializers/inflections.rb
149
163
  - spec/rails_app/config/initializers/mime_types.rb
150
164
  - spec/rails_app/config/initializers/secret_token.rb
151
165
  - spec/rails_app/config/initializers/session_store.rb
152
166
  - spec/rails_app/config/locales/en.yml
167
+ - spec/rails_app/config/mongoid.yml
153
168
  - spec/rails_app/config/routes.rb
154
169
  - spec/rails_app/db/migrate/20110214201640_create_tables.rb
155
170
  - spec/rails_app/db/schema.rb
@@ -173,6 +188,20 @@ files:
173
188
  - spec/spec.opts
174
189
  - spec/spec_helper.rb
175
190
  - spec/support/api_test_helpers.rb
191
+ - spec/support/controller_examples.rb
192
+ - spec/support/it_supports.rb
193
+ - spec/support/model_examples/associations.rb
194
+ - spec/support/model_examples/closures.rb
195
+ - spec/support/model_examples/conditional_if.rb
196
+ - spec/support/model_examples/conditional_unless.rb
197
+ - spec/support/model_examples/enabled.rb
198
+ - spec/support/model_examples/extending.rb
199
+ - spec/support/model_examples/methods.rb
200
+ - spec/support/model_examples/renaming.rb
201
+ - spec/support/model_examples/simple.rb
202
+ - spec/support/model_examples/sub_nodes.rb
203
+ - spec/support/model_examples/undefined.rb
204
+ - spec/support/model_examples/untouched.rb
176
205
  - spec/support/simple_fixtures.rb
177
206
  has_rdoc: true
178
207
  homepage: https://github.com/fabrik42/acts_as_api
@@ -213,24 +242,18 @@ summary: Makes creating XML/JSON responses in Rails 3 easy and fun.
213
242
  test_files:
214
243
  - spec/controllers/respond_with_users_controller_spec.rb
215
244
  - spec/controllers/users_controller_spec.rb
216
- - spec/models/base/associations_spec.rb
217
- - spec/models/base/closures_spec.rb
218
- - spec/models/base/conditional_if_spec.rb
219
- - spec/models/base/conditional_unless_spec.rb
220
- - spec/models/base/enabled_spec.rb
221
- - spec/models/base/extending_spec.rb
222
- - spec/models/base/methods_spec.rb
223
- - spec/models/base/renaming_spec.rb
224
- - spec/models/base/simple_spec.rb
225
- - spec/models/base/sub_nodes_spec.rb
226
- - spec/models/base/undefined_spec.rb
227
- - spec/models/base/untouched_spec.rb
245
+ - spec/models/active_record_spec.rb
246
+ - spec/models/mongoid_spec.rb
228
247
  - spec/rails_app/.gitignore
229
248
  - spec/rails_app/Rakefile
230
249
  - spec/rails_app/app/controllers/application_controller.rb
231
250
  - spec/rails_app/app/controllers/respond_with_users_controller.rb
232
251
  - spec/rails_app/app/controllers/users_controller.rb
233
252
  - spec/rails_app/app/helpers/application_helper.rb
253
+ - spec/rails_app/app/models/mongo_profile.rb
254
+ - spec/rails_app/app/models/mongo_task.rb
255
+ - spec/rails_app/app/models/mongo_untouched.rb
256
+ - spec/rails_app/app/models/mongo_user.rb
234
257
  - spec/rails_app/app/models/profile.rb
235
258
  - spec/rails_app/app/models/task.rb
236
259
  - spec/rails_app/app/models/untouched.rb
@@ -244,12 +267,14 @@ test_files:
244
267
  - spec/rails_app/config/environments/development.rb
245
268
  - spec/rails_app/config/environments/production.rb
246
269
  - spec/rails_app/config/environments/test.rb
270
+ - spec/rails_app/config/initializers/acts_as_api_mongoid.rb
247
271
  - spec/rails_app/config/initializers/backtrace_silencers.rb
248
272
  - spec/rails_app/config/initializers/inflections.rb
249
273
  - spec/rails_app/config/initializers/mime_types.rb
250
274
  - spec/rails_app/config/initializers/secret_token.rb
251
275
  - spec/rails_app/config/initializers/session_store.rb
252
276
  - spec/rails_app/config/locales/en.yml
277
+ - spec/rails_app/config/mongoid.yml
253
278
  - spec/rails_app/config/routes.rb
254
279
  - spec/rails_app/db/migrate/20110214201640_create_tables.rb
255
280
  - spec/rails_app/db/schema.rb
@@ -273,4 +298,18 @@ test_files:
273
298
  - spec/spec.opts
274
299
  - spec/spec_helper.rb
275
300
  - spec/support/api_test_helpers.rb
301
+ - spec/support/controller_examples.rb
302
+ - spec/support/it_supports.rb
303
+ - spec/support/model_examples/associations.rb
304
+ - spec/support/model_examples/closures.rb
305
+ - spec/support/model_examples/conditional_if.rb
306
+ - spec/support/model_examples/conditional_unless.rb
307
+ - spec/support/model_examples/enabled.rb
308
+ - spec/support/model_examples/extending.rb
309
+ - spec/support/model_examples/methods.rb
310
+ - spec/support/model_examples/renaming.rb
311
+ - spec/support/model_examples/simple.rb
312
+ - spec/support/model_examples/sub_nodes.rb
313
+ - spec/support/model_examples/undefined.rb
314
+ - spec/support/model_examples/untouched.rb
276
315
  - spec/support/simple_fixtures.rb
@@ -1,284 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- describe ActsAsApi::Base do
4
-
5
- describe "including an association in the api template", :orm => :active_record do
6
-
7
- before(:each) do
8
- setup_models
9
- end
10
-
11
- after(:each) do
12
- clean_up
13
- end
14
-
15
- describe "which doesn't acts_as_api" do
16
-
17
- before(:each) do
18
- @response = @luke.as_api_response(:include_tasks)
19
- end
20
-
21
- it "returns a hash" do
22
- @response.should be_kind_of(Hash)
23
- end
24
-
25
- it "returns the correct number of fields" do
26
- @response.should have(1).key
27
- end
28
-
29
- it "returns all specified fields" do
30
- @response.keys.should include(:tasks)
31
- end
32
-
33
- it "returns the correct values for the specified fields" do
34
- @response[:tasks].should be_an Array
35
- @response[:tasks].should have(3).tasks
36
- end
37
-
38
- it "should contain the associated sub models" do
39
- @response[:tasks].should include(@destroy_deathstar, @study_with_yoda, @win_rebellion)
40
- end
41
- end
42
-
43
- describe "which does acts_as_api" do
44
-
45
- context "has_many" do
46
-
47
- before(:each) do
48
- Task.acts_as_api
49
- Task.api_accessible :include_tasks do |t|
50
- t.add :heading
51
- t.add :done
52
- end
53
- @response = @luke.as_api_response(:include_tasks)
54
- end
55
-
56
- it "returns a hash" do
57
- @response.should be_kind_of(Hash)
58
- end
59
-
60
- it "returns the correct number of fields" do
61
- @response.should have(1).key
62
- end
63
-
64
- it "returns all specified fields" do
65
- @response.keys.should include(:tasks)
66
- end
67
-
68
- it "returns the correct values for the specified fields" do
69
- @response[:tasks].should be_an Array
70
- @response[:tasks].should have(3).tasks
71
- end
72
-
73
- it "contains the associated child models with the determined api template" do
74
- @response[:tasks].each do |task|
75
- task.keys.should include(:heading, :done)
76
- task.keys.should have(2).attributes
77
- end
78
- end
79
-
80
- it "contains the correct data of the child models" do
81
- task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :done => t.done, :heading => t.heading } }
82
- @response[:tasks].should eql task_hash
83
- end
84
- end
85
-
86
- context "has_one" do
87
-
88
- before(:each) do
89
- Profile.acts_as_api
90
- Profile.api_accessible :include_profile do |t|
91
- t.add :avatar
92
- t.add :homepage
93
- end
94
- @response = @luke.as_api_response(:include_profile)
95
- end
96
-
97
- it "returns a hash" do
98
- @response.should be_kind_of(Hash)
99
- end
100
-
101
- it "returns the correct number of fields" do
102
- @response.should have(1).key
103
- end
104
-
105
- it "returns all specified fields" do
106
- @response.keys.should include(:profile)
107
- end
108
-
109
- it "returns the correct values for the specified fields" do
110
- @response[:profile].should be_a Hash
111
- @response[:profile].should have(2).attributes
112
- end
113
-
114
- it "contains the associated child models with the determined api template" do
115
- @response[:profile].keys.should include(:avatar, :homepage)
116
- end
117
-
118
- it "contains the correct data of the child models" do
119
- profile_hash = { :avatar => @luke.profile.avatar, :homepage => @luke.profile.homepage }
120
- @response[:profile].should eql profile_hash
121
- end
122
-
123
- end
124
- end
125
-
126
- describe "which does acts_as_api, but with using another template name" do
127
-
128
- before(:each) do
129
- Task.acts_as_api
130
- Task.api_accessible :other_template do |t|
131
- t.add :description
132
- t.add :time_spent
133
- end
134
- @response = @luke.as_api_response(:other_sub_template)
135
- end
136
-
137
- it "returns a hash" do
138
- @response.should be_kind_of(Hash)
139
- end
140
-
141
- it "returns the correct number of fields" do
142
- @response.should have(2).keys
143
- end
144
-
145
- it "returns all specified fields" do
146
- @response.keys.should include(:first_name)
147
- end
148
-
149
- it "returns the correct values for the specified fields" do
150
- @response.values.should include(@luke.first_name)
151
- end
152
-
153
- it "returns all specified fields" do
154
- @response.keys.should include(:tasks)
155
- end
156
-
157
- it "returns the correct values for the specified fields" do
158
- @response[:tasks].should be_an Array
159
- @response[:tasks].should have(3).tasks
160
- end
161
-
162
- it "contains the associated child models with the determined api template" do
163
- @response[:tasks].each do |task|
164
- task.keys.should include(:description, :time_spent)
165
- task.keys.should have(2).attributes
166
- end
167
- end
168
-
169
- it "contains the correct data of the child models" do
170
- task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } }
171
- @response[:tasks].should eql task_hash
172
- end
173
- end
174
-
175
- describe "that is scoped" do
176
-
177
- before(:each) do
178
- # extend task model with scope
179
- class Task < ActiveRecord::Base
180
- scope :completed, where(:done => true)
181
- end
182
- Task.acts_as_api
183
- Task.api_accessible :include_completed_tasks do |t|
184
- t.add :heading
185
- t.add :done
186
- end
187
-
188
- @response = @luke.as_api_response(:include_completed_tasks)
189
- end
190
-
191
- it "returns a hash" do
192
- @response.should be_kind_of(Hash)
193
- end
194
-
195
- it "returns the correct number of fields" do
196
- @response.should have(1).key
197
- end
198
-
199
- it "returns all specified fields" do
200
- @response.keys.should include(:completed_tasks)
201
- end
202
-
203
- it "returns the correct values for the specified fields" do
204
- @response[:completed_tasks].should be_an Array
205
- @response[:completed_tasks].should have(2).tasks
206
- end
207
-
208
- it "contains the associated child models with the determined api template" do
209
- @response[:completed_tasks].each do |task|
210
- task.keys.should include(:heading, :done)
211
- task.keys.should have(2).attributes
212
- end
213
- end
214
-
215
- it "contains the correct data of the child models" do
216
- task_hash = [ @destroy_deathstar, @study_with_yoda ].collect{|t| { :done => t.done, :heading => t.heading } }
217
- @response[:completed_tasks].should eql task_hash
218
- end
219
- end
220
-
221
- describe "handling nil values" do
222
-
223
- context "has_many" do
224
-
225
- before(:each) do
226
- Task.acts_as_api
227
- Task.api_accessible :include_tasks do |t|
228
- t.add :heading
229
- t.add :done
230
- end
231
- @response = @han.as_api_response(:include_tasks)
232
- end
233
-
234
- it "returns a hash" do
235
- @response.should be_kind_of(Hash)
236
- end
237
-
238
- it "returns the correct number of fields" do
239
- @response.should have(1).key
240
- end
241
-
242
- it "returns all specified fields" do
243
- @response.keys.should include(:tasks)
244
- end
245
-
246
- it "returns the correct values for the specified fields" do
247
- @response[:tasks].should be_kind_of(Array)
248
- end
249
-
250
- it "contains no associated child models" do
251
- @response[:tasks].should have(0).items
252
- end
253
-
254
- end
255
-
256
- context "has one" do
257
- before(:each) do
258
- Profile.acts_as_api
259
- Profile.api_accessible :include_profile do |t|
260
- t.add :avatar
261
- t.add :homepage
262
- end
263
- @response = @han.as_api_response(:include_profile)
264
- end
265
-
266
- it "returns a hash" do
267
- @response.should be_kind_of(Hash)
268
- end
269
-
270
- it "returns the correct number of fields" do
271
- @response.should have(1).key
272
- end
273
-
274
- it "returns all specified fields" do
275
- @response.keys.should include(:profile)
276
- end
277
-
278
- it "returns nil for the association" do
279
- @response[:profile].should be_nil
280
- end
281
- end
282
- end
283
- end
284
- end