acts_as_api 0.4.4 → 1.0.0

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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -7
  3. data/History.txt +5 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +0 -25
  6. data/Rakefile +5 -12
  7. data/acts_as_api.gemspec +14 -13
  8. data/{examples/introduction → docs}/docco.css +0 -0
  9. data/{examples/introduction → docs}/index.html +18 -21
  10. data/{examples/introduction → docs}/index.rb +0 -0
  11. data/{examples/introduction → docs}/layout.mustache +0 -0
  12. data/lib/acts_as_api.rb +9 -12
  13. data/lib/acts_as_api/adapters.rb +1 -1
  14. data/lib/acts_as_api/api_template.rb +23 -25
  15. data/lib/acts_as_api/base.rb +11 -20
  16. data/lib/acts_as_api/collection.rb +1 -2
  17. data/lib/acts_as_api/config.rb +0 -5
  18. data/lib/acts_as_api/exceptions.rb +2 -2
  19. data/lib/acts_as_api/rails_renderer.rb +0 -2
  20. data/lib/acts_as_api/rendering.rb +5 -12
  21. data/lib/acts_as_api/responder.rb +8 -13
  22. data/lib/acts_as_api/version.rb +1 -1
  23. data/spec/README.md +15 -6
  24. data/spec/active_record_dummy/Gemfile +2 -10
  25. data/spec/active_record_dummy/app/models/user.rb +31 -32
  26. data/spec/active_record_dummy/config.ru +1 -1
  27. data/spec/active_record_dummy/config/application.rb +2 -2
  28. data/spec/active_record_dummy/config/boot.rb +1 -1
  29. data/spec/active_record_dummy/config/environments/test.rb +2 -2
  30. data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
  31. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
  32. data/spec/active_record_dummy/config/routes.rb +1 -57
  33. data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
  34. data/spec/active_record_dummy/db/schema.rb +27 -29
  35. data/spec/active_record_dummy/script/rails +2 -2
  36. data/spec/controllers/plain_objects_controller_spec.rb +11 -12
  37. data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
  38. data/spec/controllers/users_controller_spec.rb +2 -3
  39. data/spec/models/model_spec.rb +17 -19
  40. data/spec/mongoid_dummy/Gemfile +3 -12
  41. data/spec/mongoid_dummy/app/models/profile.rb +6 -6
  42. data/spec/mongoid_dummy/app/models/task.rb +10 -10
  43. data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
  44. data/spec/mongoid_dummy/app/models/user.rb +12 -14
  45. data/spec/mongoid_dummy/config.ru +1 -1
  46. data/spec/mongoid_dummy/config/application.rb +7 -7
  47. data/spec/mongoid_dummy/config/boot.rb +1 -1
  48. data/spec/mongoid_dummy/config/environments/development.rb +0 -1
  49. data/spec/mongoid_dummy/config/environments/production.rb +0 -1
  50. data/spec/mongoid_dummy/config/environments/test.rb +2 -2
  51. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
  52. data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
  53. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
  54. data/spec/mongoid_dummy/config/routes.rb +1 -57
  55. data/spec/mongoid_dummy/script/rails +2 -2
  56. data/spec/shared_engine/Gemfile +1 -1
  57. data/spec/shared_engine/Rakefile +1 -4
  58. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
  59. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
  60. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
  61. data/spec/shared_engine/app/models/plain_object.rb +3 -1
  62. data/spec/shared_engine/app/models/user_template.rb +28 -29
  63. data/spec/shared_engine/lib/shared_engine.rb +1 -1
  64. data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
  65. data/spec/shared_engine/shared_engine.gemspec +10 -12
  66. data/spec/spec_helper.rb +5 -13
  67. data/spec/support/api_test_helpers.rb +0 -2
  68. data/spec/support/controller_examples.rb +128 -173
  69. data/spec/support/it_supports.rb +1 -1
  70. data/spec/support/model_examples/associations.rb +119 -128
  71. data/spec/support/model_examples/callbacks.rb +17 -27
  72. data/spec/support/model_examples/closures.rb +21 -29
  73. data/spec/support/model_examples/conditional_if.rb +71 -103
  74. data/spec/support/model_examples/conditional_unless.rb +71 -103
  75. data/spec/support/model_examples/enabled.rb +5 -6
  76. data/spec/support/model_examples/extending.rb +49 -56
  77. data/spec/support/model_examples/methods.rb +11 -15
  78. data/spec/support/model_examples/options.rb +19 -25
  79. data/spec/support/model_examples/renaming.rb +21 -30
  80. data/spec/support/model_examples/simple.rb +10 -14
  81. data/spec/support/model_examples/sub_nodes.rb +47 -59
  82. data/spec/support/model_examples/undefined.rb +4 -6
  83. data/spec/support/model_examples/untouched.rb +6 -8
  84. data/spec/support/simple_fixtures.rb +11 -38
  85. metadata +22 -159
  86. data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
  87. data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
  88. data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
  89. data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
  90. data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
  91. data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
  92. data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
  94. data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
  95. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  96. data/spec/active_record_dummy/public/404.html +0 -26
  97. data/spec/active_record_dummy/public/422.html +0 -26
  98. data/spec/active_record_dummy/public/500.html +0 -25
  99. data/spec/active_record_dummy/public/favicon.ico +0 -0
  100. data/spec/active_record_dummy/public/index.html +0 -241
  101. data/spec/active_record_dummy/public/robots.txt +0 -5
  102. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  103. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  104. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  105. data/spec/mongoid_dummy/README.rdoc +0 -261
  106. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  107. data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
  108. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
  109. data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
  110. data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
  111. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  112. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
  113. data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
  114. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  115. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  116. data/spec/mongoid_dummy/public/404.html +0 -26
  117. data/spec/mongoid_dummy/public/422.html +0 -26
  118. data/spec/mongoid_dummy/public/500.html +0 -25
  119. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  120. data/spec/mongoid_dummy/public/index.html +0 -241
  121. data/spec/mongoid_dummy/public/robots.txt +0 -5
  122. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  123. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  124. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  125. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  126. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
  127. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
  128. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
  129. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
  130. data/spec/shared_engine/dummy/README.rdoc +0 -261
  131. data/spec/shared_engine/dummy/Rakefile +0 -7
  132. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
  133. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
  134. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
  135. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
  136. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  137. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  138. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
  139. data/spec/shared_engine/dummy/config.ru +0 -4
  140. data/spec/shared_engine/dummy/config/application.rb +0 -56
  141. data/spec/shared_engine/dummy/config/boot.rb +0 -10
  142. data/spec/shared_engine/dummy/config/database.yml +0 -25
  143. data/spec/shared_engine/dummy/config/environment.rb +0 -5
  144. data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
  145. data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
  146. data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
  147. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
  148. data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
  149. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
  150. data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
  151. data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
  152. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
  153. data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
  154. data/spec/shared_engine/dummy/config/routes.rb +0 -4
  155. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  156. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  157. data/spec/shared_engine/dummy/public/404.html +0 -26
  158. data/spec/shared_engine/dummy/public/422.html +0 -26
  159. data/spec/shared_engine/dummy/public/500.html +0 -25
  160. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  161. data/spec/shared_engine/dummy/script/rails +0 -6
@@ -1,3 +1,3 @@
1
1
  RSpec.configure do |c|
2
2
  c.alias_it_should_behave_like_to :it_supports, 'supports:'
3
- end
3
+ end
@@ -1,271 +1,262 @@
1
- shared_examples_for "including an association in the api template" do
1
+ shared_examples_for 'including an association in the api template' do
2
+ describe 'which does not acts_as_api' do
3
+ subject(:response) { @luke.as_api_response(:include_tasks) }
2
4
 
3
- describe "which doesn't acts_as_api" do
4
-
5
- before(:each) do
6
- @response = @luke.as_api_response(:include_tasks)
5
+ it 'returns a hash' do
6
+ expect(response).to be_kind_of(Hash)
7
7
  end
8
8
 
9
- it "returns a hash" do
10
- @response.should be_kind_of(Hash)
9
+ it 'returns the correct number of fields' do
10
+ expect(response).to have(1).keys
11
11
  end
12
12
 
13
- it "returns the correct number of fields" do
14
- @response.should have(1).keys
13
+ it 'returns all specified fields' do
14
+ expect(response.keys).to include(:tasks)
15
15
  end
16
16
 
17
- it "returns all specified fields" do
18
- @response.keys.should include(:tasks)
17
+ it 'returns the correct values for the specified fields' do
18
+ expect(response[:tasks]).to be_an Array
19
+ expect(response[:tasks].size).to eq(3)
19
20
  end
20
21
 
21
- it "returns the correct values for the specified fields" do
22
- @response[:tasks].should be_an Array
23
- @response[:tasks].should have(3).tasks
24
- end
25
-
26
- it "should contain the associated sub models" do
27
- @response[:tasks].should include(@destroy_deathstar, @study_with_yoda, @win_rebellion)
22
+ it 'should contain the associated sub models' do
23
+ expect(response[:tasks]).to include(@destroy_deathstar, @study_with_yoda, @win_rebellion)
28
24
  end
29
25
  end
30
26
 
31
- describe "which does acts_as_api" do
32
-
33
- context "has_many" do
34
-
27
+ describe 'which does acts_as_api' do
28
+ context 'has_many' do
35
29
  before(:each) do
36
30
  Task.acts_as_api
37
31
  Task.api_accessible :include_tasks do |t|
38
32
  t.add :heading
39
33
  t.add :done
40
34
  end
41
- @response = @luke.as_api_response(:include_tasks)
42
35
  end
43
36
 
44
- it "returns a hash" do
45
- @response.should be_kind_of(Hash)
37
+ subject(:response) { @luke.as_api_response(:include_tasks) }
38
+
39
+ it 'returns a hash' do
40
+ expect(response).to be_kind_of(Hash)
46
41
  end
47
42
 
48
- it "returns the correct number of fields" do
49
- @response.should have(1).keys
43
+ it 'returns the correct number of fields' do
44
+ expect(response).to have(1).keys
50
45
  end
51
46
 
52
- it "returns all specified fields" do
53
- @response.keys.should include(:tasks)
47
+ it 'returns all specified fields' do
48
+ expect(response.keys).to include(:tasks)
54
49
  end
55
50
 
56
- it "returns the correct values for the specified fields" do
57
- @response[:tasks].should be_an Array
58
- @response[:tasks].should have(3).tasks
51
+ it 'returns the correct values for the specified fields' do
52
+ expect(response[:tasks]).to be_an Array
53
+ expect(response[:tasks].size).to eq(3)
59
54
  end
60
55
 
61
- it "contains the associated child models with the determined api template" do
62
- @response[:tasks].each do |task|
63
- task.keys.should include(:heading, :done)
64
- task.keys.should have(2).attributes
56
+ it 'contains the associated child models with the determined api template' do
57
+ response[:tasks].each do |task|
58
+ expect(task.keys).to include(:heading, :done)
59
+ expect(task.keys.size).to eq(2)
65
60
  end
66
61
  end
67
62
 
68
- it "contains the correct data of the child models" do
69
- task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :done => t.done, :heading => t.heading } }
70
- @response[:tasks].should eql task_hash
63
+ it 'contains the correct data of the child models' do
64
+ task_hash = [@destroy_deathstar, @study_with_yoda, @win_rebellion].collect { |t| { done: t.done, heading: t.heading } }
65
+ expect(response[:tasks]).to eql task_hash
71
66
  end
72
67
  end
73
68
 
74
- context "has_one" do
75
-
69
+ context 'has_one' do
76
70
  before(:each) do
77
71
  Profile.acts_as_api
78
72
  Profile.api_accessible :include_profile do |t|
79
73
  t.add :avatar
80
74
  t.add :homepage
81
75
  end
82
- @response = @luke.as_api_response(:include_profile)
83
76
  end
84
77
 
85
- it "returns a hash" do
86
- @response.should be_kind_of(Hash)
87
- end
78
+ subject(:response) { @luke.as_api_response(:include_profile) }
88
79
 
89
- it "returns the correct number of fields" do
90
- @response.should have(1).keys
80
+ it 'returns a hash' do
81
+ expect(response).to be_kind_of(Hash)
91
82
  end
92
83
 
93
- it "returns all specified fields" do
94
- @response.keys.should include(:profile)
84
+ it 'returns the correct number of fields' do
85
+ expect(response).to have(1).keys
95
86
  end
96
87
 
97
- it "returns the correct values for the specified fields" do
98
- @response[:profile].should be_a Hash
99
- @response[:profile].should have(2).attributes
88
+ it 'returns all specified fields' do
89
+ expect(response.keys).to include(:profile)
100
90
  end
101
91
 
102
- it "contains the associated child models with the determined api template" do
103
- @response[:profile].keys.should include(:avatar, :homepage)
92
+ it 'returns the correct values for the specified fields' do
93
+ expect(response[:profile]).to be_a Hash
94
+ expect(response[:profile].size).to eq(2)
104
95
  end
105
96
 
106
- it "contains the correct data of the child models" do
107
- profile_hash = { :avatar => @luke.profile.avatar, :homepage => @luke.profile.homepage }
108
- @response[:profile].should eql profile_hash
97
+ it 'contains the associated child models with the determined api template' do
98
+ expect(response[:profile].keys).to include(:avatar, :homepage)
109
99
  end
110
100
 
101
+ it 'contains the correct data of the child models' do
102
+ profile_hash = { avatar: @luke.profile.avatar, homepage: @luke.profile.homepage }
103
+ expect(response[:profile]).to eql profile_hash
104
+ end
111
105
  end
112
106
  end
113
107
 
114
- describe "which does acts_as_api, but with using another template name" do
115
-
108
+ describe 'which does acts_as_api, but with using another template name' do
116
109
  before(:each) do
117
110
  Task.acts_as_api
118
111
  Task.api_accessible :other_template do |t|
119
112
  t.add :description
120
113
  t.add :time_spent
121
114
  end
122
- @response = @luke.as_api_response(:other_sub_template)
123
115
  end
124
116
 
125
- it "returns a hash" do
126
- @response.should be_kind_of(Hash)
117
+ subject(:response) { @luke.as_api_response(:other_sub_template) }
118
+
119
+ it 'returns a hash' do
120
+ expect(response).to be_kind_of(Hash)
127
121
  end
128
122
 
129
- it "returns the correct number of fields" do
130
- @response.should have(2).keys
123
+ it 'returns the correct number of fields' do
124
+ expect(response).to have(2).keys
131
125
  end
132
126
 
133
- it "returns all specified fields" do
134
- @response.keys.should include(:first_name)
127
+ it 'returns all specified fields' do
128
+ expect(response.keys).to include(:first_name)
135
129
  end
136
130
 
137
- it "returns the correct values for the specified fields" do
138
- @response.values.should include(@luke.first_name)
131
+ it 'returns the correct values for the specified fields' do
132
+ expect(response.values).to include(@luke.first_name)
139
133
  end
140
134
 
141
- it "returns all specified fields" do
142
- @response.keys.should include(:tasks)
135
+ it 'returns all specified fields' do
136
+ expect(response.keys).to include(:tasks)
143
137
  end
144
138
 
145
- it "returns the correct values for the specified fields" do
146
- @response[:tasks].should be_an Array
147
- @response[:tasks].should have(3).tasks
139
+ it 'returns the correct values for the specified fields' do
140
+ expect(response[:tasks]).to be_an Array
141
+ expect(response[:tasks].size).to eq(3)
148
142
  end
149
143
 
150
- it "contains the associated child models with the determined api template" do
151
- @response[:tasks].each do |task|
152
- task.keys.should include(:description, :time_spent)
153
- task.keys.should have(2).attributes
144
+ it 'contains the associated child models with the determined api template' do
145
+ response[:tasks].each do |task|
146
+ expect(task.keys).to include(:description, :time_spent)
147
+ expect(task.keys.size).to eq(2)
154
148
  end
155
149
  end
156
150
 
157
- it "contains the correct data of the child models" do
158
- task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } }
159
- @response[:tasks].should eql task_hash
151
+ it 'contains the correct data of the child models' do
152
+ task_hash = [@destroy_deathstar, @study_with_yoda, @win_rebellion].collect { |t| { description: t.description, time_spent: t.time_spent } }
153
+ expect(response[:tasks]).to eql task_hash
160
154
  end
161
155
  end
162
156
 
163
- describe "that is scoped" do
164
-
157
+ describe 'that is scoped' do
165
158
  before(:each) do
166
159
  # extend task model with scope
167
- #class Task < ActiveRecord::Base
168
160
  Task.class_eval do
169
- scope :completed, -> { where(:done => true) }
161
+ scope :completed, -> { where(done: true) }
170
162
  end
171
163
  Task.acts_as_api
172
164
  Task.api_accessible :include_completed_tasks do |t|
173
165
  t.add :heading
174
166
  t.add :done
175
167
  end
176
-
177
- @response = @luke.as_api_response(:include_completed_tasks)
178
168
  end
179
169
 
180
- it "returns a hash" do
181
- @response.should be_kind_of(Hash)
170
+ subject(:response) { @luke.as_api_response(:include_completed_tasks) }
171
+
172
+ it 'returns a hash' do
173
+ expect(response).to be_kind_of(Hash)
182
174
  end
183
175
 
184
- it "returns the correct number of fields" do
185
- @response.should have(1).keys
176
+ it 'returns the correct number of fields' do
177
+ expect(response.size).to eq(1)
186
178
  end
187
179
 
188
- it "returns all specified fields" do
189
- @response.keys.should include(:completed_tasks)
180
+ it 'returns all specified fields' do
181
+ expect(response.keys).to include(:completed_tasks)
190
182
  end
191
183
 
192
- it "returns the correct values for the specified fields" do
193
- @response[:completed_tasks].should be_an Array
194
- @response[:completed_tasks].should have(2).tasks
184
+ it 'returns the correct values for the specified fields' do
185
+ expect(response[:completed_tasks]).to be_an Array
186
+ expect(response[:completed_tasks].size).to eq(2)
195
187
  end
196
188
 
197
- it "contains the associated child models with the determined api template" do
198
- @response[:completed_tasks].each do |task|
199
- task.keys.should include(:heading, :done)
200
- task.keys.should have(2).attributes
189
+ it 'contains the associated child models with the determined api template' do
190
+ response[:completed_tasks].each do |task|
191
+ expect(task.keys).to include(:heading, :done)
192
+ expect(task.keys.size).to eq(2)
201
193
  end
202
194
  end
203
195
 
204
- it "contains the correct data of the child models" do
205
- task_hash = [ @destroy_deathstar, @study_with_yoda ].collect{|t| { :done => t.done, :heading => t.heading } }
206
- @response[:completed_tasks].should eql task_hash
196
+ it 'contains the correct data of the child models' do
197
+ task_hash = [@destroy_deathstar, @study_with_yoda].collect { |t| { done: t.done, heading: t.heading } }
198
+ expect(response[:completed_tasks]).to eql task_hash
207
199
  end
208
200
  end
209
201
 
210
- describe "handling nil values" do
211
-
212
- context "has_many" do
213
-
202
+ describe 'handling nil values' do
203
+ context 'has_many' do
214
204
  before(:each) do
215
205
  Task.acts_as_api
216
206
  Task.api_accessible :include_tasks do |t|
217
207
  t.add :heading
218
208
  t.add :done
219
209
  end
220
- @response = @han.as_api_response(:include_tasks)
221
210
  end
222
211
 
223
- it "returns a hash" do
224
- @response.should be_kind_of(Hash)
225
- end
212
+ subject(:response) { @han.as_api_response(:include_tasks) }
226
213
 
227
- it "returns the correct number of fields" do
228
- @response.should have(1).keys
214
+ it 'returns a hash' do
215
+ expect(response).to be_kind_of(Hash)
229
216
  end
230
217
 
231
- it "returns all specified fields" do
232
- @response.keys.should include(:tasks)
218
+ it 'returns the correct number of fields' do
219
+ expect(response).to have(1).keys
233
220
  end
234
221
 
235
- it "returns the correct values for the specified fields" do
236
- @response[:tasks].should be_kind_of(Array)
222
+ it 'returns all specified fields' do
223
+ expect(response.keys).to include(:tasks)
237
224
  end
238
225
 
239
- it "contains no associated child models" do
240
- @response[:tasks].should have(0).items
226
+ it 'returns the correct values for the specified fields' do
227
+ expect(response[:tasks]).to be_kind_of(Array)
241
228
  end
242
229
 
230
+ it 'contains no associated child models' do
231
+ expect(response[:tasks]).to have(0).items
232
+ end
243
233
  end
244
234
 
245
- context "has one" do
235
+ context 'has one' do
246
236
  before(:each) do
247
237
  Profile.acts_as_api
248
238
  Profile.api_accessible :include_profile do |t|
249
239
  t.add :avatar
250
240
  t.add :homepage
251
241
  end
252
- @response = @han.as_api_response(:include_profile)
253
242
  end
254
243
 
255
- it "returns a hash" do
256
- @response.should be_kind_of(Hash)
244
+ subject(:response) { @han.as_api_response(:include_profile) }
245
+
246
+ it 'returns a hash' do
247
+ expect(response).to be_kind_of(Hash)
257
248
  end
258
249
 
259
- it "returns the correct number of fields" do
260
- @response.should have(1).keys
250
+ it 'returns the correct number of fields' do
251
+ expect(response).to have(1).keys
261
252
  end
262
253
 
263
- it "returns all specified fields" do
264
- @response.keys.should include(:profile)
254
+ it 'returns all specified fields' do
255
+ expect(response.keys).to include(:profile)
265
256
  end
266
257
 
267
- it "returns nil for the association" do
268
- @response[:profile].should be_nil
258
+ it 'returns nil for the association' do
259
+ expect(response[:profile]).to be_nil
269
260
  end
270
261
  end
271
262
  end
@@ -1,38 +1,28 @@
1
- shared_examples_for "defining a model callback" do
2
-
3
- describe "for a" do
4
-
5
- describe "around_api_response" do
6
-
7
- it "skips rendering if not yielded" do
1
+ shared_examples_for 'defining a model callback' do
2
+ describe 'for a' do
3
+ describe 'around_api_response' do
4
+ it 'skips rendering if not yielded' do
8
5
  @luke.skip_api_response = true
9
- @luke.as_api_response(:name_only).keys.should include(:skipped)
6
+ expect(@luke.as_api_response(:name_only).keys).to include(:skipped)
10
7
  end
11
-
12
- it "renders if yielded" do
13
- @luke.as_api_response(:name_only).keys.should_not include(:skipped)
8
+
9
+ it 'renders if yielded' do
10
+ expect(@luke.as_api_response(:name_only).keys).not_to include(:skipped)
14
11
  end
15
-
16
12
  end
17
-
18
- describe "before_api_response" do
19
-
20
- it "is called properly" do
13
+
14
+ describe 'before_api_response' do
15
+ it 'is called properly' do
21
16
  @luke.as_api_response(:name_only)
22
- @luke.before_api_response_called?.should eql(true)
17
+ expect(@luke.before_api_response_called?).to eql(true)
23
18
  end
24
-
25
19
  end
26
-
27
- describe "after_api_response" do
28
-
29
- it "is called properly" do
20
+
21
+ describe 'after_api_response' do
22
+ it 'is called properly' do
30
23
  @luke.as_api_response(:name_only)
31
- @luke.after_api_response_called?.should eql(true)
24
+ expect(@luke.after_api_response_called?).to eql(true)
32
25
  end
33
-
34
26
  end
35
-
36
27
  end
37
-
38
- end
28
+ end