acts_as_api 0.4.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -7
- data/History.txt +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +0 -25
- data/Rakefile +5 -12
- data/acts_as_api.gemspec +14 -13
- data/{examples/introduction → docs}/docco.css +0 -0
- data/{examples/introduction → docs}/index.html +18 -21
- data/{examples/introduction → docs}/index.rb +0 -0
- data/{examples/introduction → docs}/layout.mustache +0 -0
- data/lib/acts_as_api.rb +9 -12
- data/lib/acts_as_api/adapters.rb +1 -1
- data/lib/acts_as_api/api_template.rb +23 -25
- data/lib/acts_as_api/base.rb +11 -20
- data/lib/acts_as_api/collection.rb +1 -2
- data/lib/acts_as_api/config.rb +0 -5
- data/lib/acts_as_api/exceptions.rb +2 -2
- data/lib/acts_as_api/rails_renderer.rb +0 -2
- data/lib/acts_as_api/rendering.rb +5 -12
- data/lib/acts_as_api/responder.rb +8 -13
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/README.md +15 -6
- data/spec/active_record_dummy/Gemfile +2 -10
- data/spec/active_record_dummy/app/models/user.rb +31 -32
- data/spec/active_record_dummy/config.ru +1 -1
- data/spec/active_record_dummy/config/application.rb +2 -2
- data/spec/active_record_dummy/config/boot.rb +1 -1
- data/spec/active_record_dummy/config/environments/test.rb +2 -2
- data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/active_record_dummy/config/routes.rb +1 -57
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
- data/spec/active_record_dummy/db/schema.rb +27 -29
- data/spec/active_record_dummy/script/rails +2 -2
- data/spec/controllers/plain_objects_controller_spec.rb +11 -12
- data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
- data/spec/controllers/users_controller_spec.rb +2 -3
- data/spec/models/model_spec.rb +17 -19
- data/spec/mongoid_dummy/Gemfile +3 -12
- data/spec/mongoid_dummy/app/models/profile.rb +6 -6
- data/spec/mongoid_dummy/app/models/task.rb +10 -10
- data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
- data/spec/mongoid_dummy/app/models/user.rb +12 -14
- data/spec/mongoid_dummy/config.ru +1 -1
- data/spec/mongoid_dummy/config/application.rb +7 -7
- data/spec/mongoid_dummy/config/boot.rb +1 -1
- data/spec/mongoid_dummy/config/environments/development.rb +0 -1
- data/spec/mongoid_dummy/config/environments/production.rb +0 -1
- data/spec/mongoid_dummy/config/environments/test.rb +2 -2
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
- data/spec/mongoid_dummy/config/routes.rb +1 -57
- data/spec/mongoid_dummy/script/rails +2 -2
- data/spec/shared_engine/Gemfile +1 -1
- data/spec/shared_engine/Rakefile +1 -4
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
- data/spec/shared_engine/app/models/plain_object.rb +3 -1
- data/spec/shared_engine/app/models/user_template.rb +28 -29
- data/spec/shared_engine/lib/shared_engine.rb +1 -1
- data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
- data/spec/shared_engine/shared_engine.gemspec +10 -12
- data/spec/spec_helper.rb +5 -13
- data/spec/support/api_test_helpers.rb +0 -2
- data/spec/support/controller_examples.rb +128 -173
- data/spec/support/it_supports.rb +1 -1
- data/spec/support/model_examples/associations.rb +119 -128
- data/spec/support/model_examples/callbacks.rb +17 -27
- data/spec/support/model_examples/closures.rb +21 -29
- data/spec/support/model_examples/conditional_if.rb +71 -103
- data/spec/support/model_examples/conditional_unless.rb +71 -103
- data/spec/support/model_examples/enabled.rb +5 -6
- data/spec/support/model_examples/extending.rb +49 -56
- data/spec/support/model_examples/methods.rb +11 -15
- data/spec/support/model_examples/options.rb +19 -25
- data/spec/support/model_examples/renaming.rb +21 -30
- data/spec/support/model_examples/simple.rb +10 -14
- data/spec/support/model_examples/sub_nodes.rb +47 -59
- data/spec/support/model_examples/undefined.rb +4 -6
- data/spec/support/model_examples/untouched.rb +6 -8
- data/spec/support/simple_fixtures.rb +11 -38
- metadata +22 -159
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
- data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
- data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/active_record_dummy/public/404.html +0 -26
- data/spec/active_record_dummy/public/422.html +0 -26
- data/spec/active_record_dummy/public/500.html +0 -25
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +0 -241
- data/spec/active_record_dummy/public/robots.txt +0 -5
- data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/mongoid_dummy/README.rdoc +0 -261
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +0 -26
- data/spec/mongoid_dummy/public/422.html +0 -26
- data/spec/mongoid_dummy/public/500.html +0 -25
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +0 -241
- data/spec/mongoid_dummy/public/robots.txt +0 -5
- data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
- data/spec/shared_engine/dummy/README.rdoc +0 -261
- data/spec/shared_engine/dummy/Rakefile +0 -7
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/shared_engine/dummy/config.ru +0 -4
- data/spec/shared_engine/dummy/config/application.rb +0 -56
- data/spec/shared_engine/dummy/config/boot.rb +0 -10
- data/spec/shared_engine/dummy/config/database.yml +0 -25
- data/spec/shared_engine/dummy/config/environment.rb +0 -5
- data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
- data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
- data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
- data/spec/shared_engine/dummy/config/routes.rb +0 -4
- data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
- data/spec/shared_engine/dummy/log/.gitkeep +0 -0
- data/spec/shared_engine/dummy/public/404.html +0 -26
- data/spec/shared_engine/dummy/public/422.html +0 -26
- data/spec/shared_engine/dummy/public/500.html +0 -25
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +0 -6
data/spec/support/it_supports.rb
CHANGED
@@ -1,271 +1,262 @@
|
|
1
|
-
shared_examples_for
|
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
|
-
|
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
|
10
|
-
|
9
|
+
it 'returns the correct number of fields' do
|
10
|
+
expect(response).to have(1).keys
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
|
13
|
+
it 'returns all specified fields' do
|
14
|
+
expect(response.keys).to include(:tasks)
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
|
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
|
22
|
-
|
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
|
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
|
-
|
45
|
-
|
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
|
49
|
-
|
43
|
+
it 'returns the correct number of fields' do
|
44
|
+
expect(response).to have(1).keys
|
50
45
|
end
|
51
46
|
|
52
|
-
it
|
53
|
-
|
47
|
+
it 'returns all specified fields' do
|
48
|
+
expect(response.keys).to include(:tasks)
|
54
49
|
end
|
55
50
|
|
56
|
-
it
|
57
|
-
|
58
|
-
|
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
|
62
|
-
|
63
|
-
task.keys.
|
64
|
-
task.keys.
|
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
|
69
|
-
task_hash = [
|
70
|
-
|
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
|
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
|
-
|
86
|
-
@response.should be_kind_of(Hash)
|
87
|
-
end
|
78
|
+
subject(:response) { @luke.as_api_response(:include_profile) }
|
88
79
|
|
89
|
-
it
|
90
|
-
|
80
|
+
it 'returns a hash' do
|
81
|
+
expect(response).to be_kind_of(Hash)
|
91
82
|
end
|
92
83
|
|
93
|
-
it
|
94
|
-
|
84
|
+
it 'returns the correct number of fields' do
|
85
|
+
expect(response).to have(1).keys
|
95
86
|
end
|
96
87
|
|
97
|
-
it
|
98
|
-
|
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
|
103
|
-
|
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
|
107
|
-
|
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
|
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
|
-
|
126
|
-
|
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
|
130
|
-
|
123
|
+
it 'returns the correct number of fields' do
|
124
|
+
expect(response).to have(2).keys
|
131
125
|
end
|
132
126
|
|
133
|
-
it
|
134
|
-
|
127
|
+
it 'returns all specified fields' do
|
128
|
+
expect(response.keys).to include(:first_name)
|
135
129
|
end
|
136
130
|
|
137
|
-
it
|
138
|
-
|
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
|
142
|
-
|
135
|
+
it 'returns all specified fields' do
|
136
|
+
expect(response.keys).to include(:tasks)
|
143
137
|
end
|
144
138
|
|
145
|
-
it
|
146
|
-
|
147
|
-
|
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
|
151
|
-
|
152
|
-
task.keys.
|
153
|
-
task.keys.
|
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
|
158
|
-
task_hash = [
|
159
|
-
|
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
|
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(:
|
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
|
-
|
181
|
-
|
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
|
185
|
-
|
176
|
+
it 'returns the correct number of fields' do
|
177
|
+
expect(response.size).to eq(1)
|
186
178
|
end
|
187
179
|
|
188
|
-
it
|
189
|
-
|
180
|
+
it 'returns all specified fields' do
|
181
|
+
expect(response.keys).to include(:completed_tasks)
|
190
182
|
end
|
191
183
|
|
192
|
-
it
|
193
|
-
|
194
|
-
|
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
|
198
|
-
|
199
|
-
task.keys.
|
200
|
-
task.keys.
|
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
|
205
|
-
task_hash = [
|
206
|
-
|
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
|
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
|
-
|
224
|
-
@response.should be_kind_of(Hash)
|
225
|
-
end
|
212
|
+
subject(:response) { @han.as_api_response(:include_tasks) }
|
226
213
|
|
227
|
-
it
|
228
|
-
|
214
|
+
it 'returns a hash' do
|
215
|
+
expect(response).to be_kind_of(Hash)
|
229
216
|
end
|
230
217
|
|
231
|
-
it
|
232
|
-
|
218
|
+
it 'returns the correct number of fields' do
|
219
|
+
expect(response).to have(1).keys
|
233
220
|
end
|
234
221
|
|
235
|
-
it
|
236
|
-
|
222
|
+
it 'returns all specified fields' do
|
223
|
+
expect(response.keys).to include(:tasks)
|
237
224
|
end
|
238
225
|
|
239
|
-
it
|
240
|
-
|
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
|
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
|
-
|
256
|
-
|
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
|
260
|
-
|
250
|
+
it 'returns the correct number of fields' do
|
251
|
+
expect(response).to have(1).keys
|
261
252
|
end
|
262
253
|
|
263
|
-
it
|
264
|
-
|
254
|
+
it 'returns all specified fields' do
|
255
|
+
expect(response.keys).to include(:profile)
|
265
256
|
end
|
266
257
|
|
267
|
-
it
|
268
|
-
|
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
|
2
|
-
|
3
|
-
|
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.
|
6
|
+
expect(@luke.as_api_response(:name_only).keys).to include(:skipped)
|
10
7
|
end
|
11
|
-
|
12
|
-
it
|
13
|
-
@luke.as_api_response(:name_only).keys.
|
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
|
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
|
17
|
+
expect(@luke.before_api_response_called?).to eql(true)
|
23
18
|
end
|
24
|
-
|
25
19
|
end
|
26
|
-
|
27
|
-
describe
|
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
|
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
|