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.
- 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
|
@@ -1,49 +1,41 @@
|
|
|
1
|
-
shared_examples_for
|
|
1
|
+
shared_examples_for 'calling a closure in the api template' do
|
|
2
|
+
describe 'i.e. a proc (the record is passed as only parameter)' do
|
|
3
|
+
subject(:response) { @luke.as_api_response(:calling_a_proc) }
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
before(:each) do
|
|
6
|
-
@response = @luke.as_api_response(:calling_a_proc)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "returns a hash" do
|
|
10
|
-
@response.should be_kind_of(Hash)
|
|
5
|
+
it 'returns a hash' do
|
|
6
|
+
expect(response).to be_kind_of(Hash)
|
|
11
7
|
end
|
|
12
8
|
|
|
13
|
-
it
|
|
14
|
-
|
|
9
|
+
it 'returns the correct number of fields' do
|
|
10
|
+
expect(response).to have(2).keys
|
|
15
11
|
end
|
|
16
12
|
|
|
17
|
-
it
|
|
18
|
-
|
|
13
|
+
it 'returns all specified fields' do
|
|
14
|
+
expect(response.keys.sort_by(&:to_s)).to eql([:all_caps_name, :without_param])
|
|
19
15
|
end
|
|
20
16
|
|
|
21
|
-
it
|
|
22
|
-
|
|
17
|
+
it 'returns the correct values for the specified fields' do
|
|
18
|
+
expect(response.values.sort).to eql(['LUKE SKYWALKER', 'Time'])
|
|
23
19
|
end
|
|
24
20
|
end
|
|
25
21
|
|
|
26
|
-
describe
|
|
22
|
+
describe 'i.e. a lambda (the record is passed as only parameter)' do
|
|
23
|
+
subject(:response) { @luke.as_api_response(:calling_a_lambda) }
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
it 'returns a hash' do
|
|
26
|
+
expect(response).to be_kind_of(Hash)
|
|
30
27
|
end
|
|
31
28
|
|
|
32
|
-
it
|
|
33
|
-
|
|
29
|
+
it 'returns the correct number of fields' do
|
|
30
|
+
expect(response).to have(2).keys
|
|
34
31
|
end
|
|
35
32
|
|
|
36
|
-
it
|
|
37
|
-
|
|
33
|
+
it 'returns all specified fields' do
|
|
34
|
+
expect(response.keys.sort_by(&:to_s)).to eql([:all_caps_name, :without_param])
|
|
38
35
|
end
|
|
39
36
|
|
|
40
|
-
it
|
|
41
|
-
|
|
37
|
+
it 'returns the correct values for the specified fields' do
|
|
38
|
+
expect(response.values.sort).to eql(['LUKE SKYWALKER', 'Time'])
|
|
42
39
|
end
|
|
43
|
-
|
|
44
|
-
it "returns the correct values for the specified fields" do
|
|
45
|
-
@response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
|
|
46
|
-
end
|
|
47
|
-
|
|
48
40
|
end
|
|
49
41
|
end
|
|
@@ -1,165 +1,133 @@
|
|
|
1
|
-
shared_examples_for
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
before(:each) do
|
|
10
|
-
@response = @luke.as_api_response(:if_over_thirty)
|
|
1
|
+
shared_examples_for 'conditional if statements' do
|
|
2
|
+
describe 'using the :if option' do
|
|
3
|
+
describe 'passing a symbol' do
|
|
4
|
+
describe 'that returns false' do
|
|
5
|
+
subject(:response) { @luke.as_api_response(:if_over_thirty) }
|
|
6
|
+
|
|
7
|
+
it 'returns a hash' do
|
|
8
|
+
expect(response).to be_kind_of(Hash)
|
|
11
9
|
end
|
|
12
10
|
|
|
13
|
-
it
|
|
14
|
-
|
|
11
|
+
it 'returns the correct number of fields' do
|
|
12
|
+
expect(response).to have(1).keys
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
it
|
|
18
|
-
|
|
15
|
+
it 'will not add the conditional field but all others' do
|
|
16
|
+
expect(response.keys).to include(:first_name)
|
|
17
|
+
expect(response.keys).not_to include(:full_name)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
it
|
|
22
|
-
|
|
23
|
-
@response.keys.should_not include(:full_name)
|
|
20
|
+
it 'the other specified fields have the correct value' do
|
|
21
|
+
expect(response.values).to include(@luke.first_name)
|
|
24
22
|
end
|
|
25
|
-
|
|
26
|
-
it "the other specified fields have the correct value" do
|
|
27
|
-
@response.values.should include(@luke.first_name)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
23
|
end
|
|
31
24
|
|
|
32
|
-
describe
|
|
25
|
+
describe 'that returns nil' do
|
|
26
|
+
subject(:response) { @luke.as_api_response(:if_returns_nil) }
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
it 'returns a hash' do
|
|
29
|
+
expect(response).to be_kind_of(Hash)
|
|
36
30
|
end
|
|
37
31
|
|
|
38
|
-
it
|
|
39
|
-
|
|
32
|
+
it 'returns the correct number of fields' do
|
|
33
|
+
expect(response).to have(1).keys
|
|
40
34
|
end
|
|
41
35
|
|
|
42
|
-
it
|
|
43
|
-
|
|
36
|
+
it 'will not add the conditional field but all others' do
|
|
37
|
+
expect(response.keys).to include(:first_name)
|
|
38
|
+
expect(response.keys).not_to include(:full_name)
|
|
44
39
|
end
|
|
45
40
|
|
|
46
|
-
it
|
|
47
|
-
|
|
48
|
-
@response.keys.should_not include(:full_name)
|
|
41
|
+
it 'the other specified fields have the correct value' do
|
|
42
|
+
expect(response.values).to include(@luke.first_name)
|
|
49
43
|
end
|
|
50
|
-
|
|
51
|
-
it "the other specified fields have the correct value" do
|
|
52
|
-
@response.values.should include(@luke.first_name)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
44
|
end
|
|
56
45
|
|
|
57
|
-
describe
|
|
46
|
+
describe 'that returns true' do
|
|
47
|
+
subject(:response) { @han.as_api_response(:if_over_thirty) }
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
it 'returns a hash' do
|
|
50
|
+
expect(response).to be_kind_of(Hash)
|
|
61
51
|
end
|
|
62
52
|
|
|
63
|
-
it
|
|
64
|
-
|
|
53
|
+
it 'returns the correct number of fields' do
|
|
54
|
+
expect(response).to have(2).keys
|
|
65
55
|
end
|
|
66
56
|
|
|
67
|
-
it
|
|
68
|
-
|
|
57
|
+
it 'will not add the conditional field but all others' do
|
|
58
|
+
expect(response.keys).to include(:first_name)
|
|
59
|
+
expect(response.keys).to include(:last_name)
|
|
69
60
|
end
|
|
70
61
|
|
|
71
|
-
it
|
|
72
|
-
|
|
73
|
-
@response.keys.should include(:last_name)
|
|
62
|
+
it 'the other specified fields have the correct value' do
|
|
63
|
+
expect(response.values).to include(@han.first_name, @han.last_name)
|
|
74
64
|
end
|
|
75
|
-
|
|
76
|
-
it "the other specified fields have the correct value" do
|
|
77
|
-
@response.values.should include(@han.first_name, @han.last_name)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
65
|
end
|
|
81
|
-
|
|
82
66
|
end
|
|
83
|
-
|
|
84
67
|
end
|
|
85
68
|
|
|
86
|
-
describe
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
before(:each) do
|
|
91
|
-
@response = @luke.as_api_response(:if_over_thirty_proc)
|
|
92
|
-
end
|
|
69
|
+
describe 'passing a proc' do
|
|
70
|
+
describe 'that returns false' do
|
|
71
|
+
subject(:response) { @luke.as_api_response(:if_over_thirty_proc) }
|
|
93
72
|
|
|
94
|
-
it
|
|
95
|
-
|
|
73
|
+
it 'returns a hash' do
|
|
74
|
+
expect(response).to be_kind_of(Hash)
|
|
96
75
|
end
|
|
97
76
|
|
|
98
|
-
it
|
|
99
|
-
|
|
77
|
+
it 'returns the correct number of fields' do
|
|
78
|
+
expect(response).to have(1).keys
|
|
100
79
|
end
|
|
101
80
|
|
|
102
|
-
it
|
|
103
|
-
|
|
104
|
-
|
|
81
|
+
it 'will not add the conditional field but all others' do
|
|
82
|
+
expect(response.keys).to include(:first_name)
|
|
83
|
+
expect(response.keys).not_to include(:full_name)
|
|
105
84
|
end
|
|
106
85
|
|
|
107
|
-
it
|
|
108
|
-
|
|
86
|
+
it 'the other specified fields have the correct value' do
|
|
87
|
+
expect(response.values).to include(@luke.first_name)
|
|
109
88
|
end
|
|
110
|
-
|
|
111
89
|
end
|
|
112
90
|
|
|
113
|
-
describe
|
|
114
|
-
|
|
115
|
-
before(:each) do
|
|
116
|
-
@response = @luke.as_api_response(:if_returns_nil_proc)
|
|
117
|
-
end
|
|
91
|
+
describe 'that returns nil' do
|
|
92
|
+
subject(:response) { @luke.as_api_response(:if_returns_nil_proc) }
|
|
118
93
|
|
|
119
|
-
it
|
|
120
|
-
|
|
94
|
+
it 'returns a hash' do
|
|
95
|
+
expect(response).to be_kind_of(Hash)
|
|
121
96
|
end
|
|
122
97
|
|
|
123
|
-
it
|
|
124
|
-
|
|
98
|
+
it 'returns the correct number of fields' do
|
|
99
|
+
expect(response).to have(1).keys
|
|
125
100
|
end
|
|
126
101
|
|
|
127
|
-
it
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
it 'will not add the conditional field but all others' do
|
|
103
|
+
expect(response.keys).to include(:first_name)
|
|
104
|
+
expect(response.keys).not_to include(:full_name)
|
|
130
105
|
end
|
|
131
106
|
|
|
132
|
-
it
|
|
133
|
-
|
|
107
|
+
it 'the other specified fields have the correct value' do
|
|
108
|
+
expect(response.values).to include(@luke.first_name)
|
|
134
109
|
end
|
|
135
|
-
|
|
136
110
|
end
|
|
137
111
|
|
|
138
|
-
describe
|
|
139
|
-
|
|
140
|
-
before(:each) do
|
|
141
|
-
@response = @han.as_api_response(:if_over_thirty_proc)
|
|
142
|
-
end
|
|
112
|
+
describe 'that returns true' do
|
|
113
|
+
subject(:response) { @han.as_api_response(:if_over_thirty_proc) }
|
|
143
114
|
|
|
144
|
-
it
|
|
145
|
-
|
|
115
|
+
it 'returns a hash' do
|
|
116
|
+
expect(response).to be_kind_of(Hash)
|
|
146
117
|
end
|
|
147
118
|
|
|
148
|
-
it
|
|
149
|
-
|
|
119
|
+
it 'returns the correct number of fields' do
|
|
120
|
+
expect(response).to have(2).keys
|
|
150
121
|
end
|
|
151
122
|
|
|
152
|
-
it
|
|
153
|
-
|
|
154
|
-
|
|
123
|
+
it 'will not add the conditional field but all others' do
|
|
124
|
+
expect(response.keys).to include(:first_name)
|
|
125
|
+
expect(response.keys).to include(:last_name)
|
|
155
126
|
end
|
|
156
127
|
|
|
157
|
-
it
|
|
158
|
-
|
|
128
|
+
it 'the other specified fields have the correct value' do
|
|
129
|
+
expect(response.values).to include(@han.first_name, @han.last_name)
|
|
159
130
|
end
|
|
160
|
-
|
|
161
131
|
end
|
|
162
|
-
|
|
163
132
|
end
|
|
164
133
|
end
|
|
165
|
-
|
|
@@ -1,165 +1,133 @@
|
|
|
1
|
-
shared_examples_for
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
before(:each) do
|
|
10
|
-
@response = @luke.as_api_response(:unless_under_thirty)
|
|
1
|
+
shared_examples_for 'conditional unless statements' do
|
|
2
|
+
describe 'using the :unless option' do
|
|
3
|
+
describe 'passing a symbol' do
|
|
4
|
+
describe 'that returns false' do
|
|
5
|
+
subject(:response) { @luke.as_api_response(:unless_under_thirty) }
|
|
6
|
+
|
|
7
|
+
it 'returns a hash' do
|
|
8
|
+
expect(response).to be_kind_of(Hash)
|
|
11
9
|
end
|
|
12
10
|
|
|
13
|
-
it
|
|
14
|
-
|
|
11
|
+
it 'returns the correct number of fields' do
|
|
12
|
+
expect(response).to have(1).keys
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
it
|
|
18
|
-
|
|
15
|
+
it 'will not add the conditional field but all others' do
|
|
16
|
+
expect(response.keys).to include(:first_name)
|
|
17
|
+
expect(response.keys).not_to include(:full_name)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
it
|
|
22
|
-
|
|
23
|
-
@response.keys.should_not include(:full_name)
|
|
20
|
+
it 'the other specified fields have the correct value' do
|
|
21
|
+
expect(response.values).to include(@luke.first_name)
|
|
24
22
|
end
|
|
25
|
-
|
|
26
|
-
it "the other specified fields have the correct value" do
|
|
27
|
-
@response.values.should include(@luke.first_name)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
23
|
end
|
|
31
24
|
|
|
32
|
-
describe
|
|
25
|
+
describe 'that returns nil' do
|
|
26
|
+
subject(:response) { @luke.as_api_response(:unless_returns_nil) }
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
it 'returns a hash' do
|
|
29
|
+
expect(response).to be_kind_of(Hash)
|
|
36
30
|
end
|
|
37
31
|
|
|
38
|
-
it
|
|
39
|
-
|
|
32
|
+
it 'returns the correct number of fields' do
|
|
33
|
+
expect(response).to have(2).keys
|
|
40
34
|
end
|
|
41
35
|
|
|
42
|
-
it
|
|
43
|
-
|
|
36
|
+
it 'will not add the conditional field but all others' do
|
|
37
|
+
expect(response.keys).to include(:first_name)
|
|
38
|
+
expect(response.keys).to include(:last_name)
|
|
44
39
|
end
|
|
45
40
|
|
|
46
|
-
it
|
|
47
|
-
|
|
48
|
-
@response.keys.should include(:last_name)
|
|
41
|
+
it 'the other specified fields have the correct value' do
|
|
42
|
+
expect(response.values).to include(@luke.first_name, @luke.last_name)
|
|
49
43
|
end
|
|
50
|
-
|
|
51
|
-
it "the other specified fields have the correct value" do
|
|
52
|
-
@response.values.should include(@luke.first_name, @luke.last_name)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
44
|
end
|
|
56
45
|
|
|
57
|
-
describe
|
|
46
|
+
describe 'that returns true' do
|
|
47
|
+
subject(:response) { @han.as_api_response(:unless_under_thirty) }
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
it 'returns a hash' do
|
|
50
|
+
expect(response).to be_kind_of(Hash)
|
|
61
51
|
end
|
|
62
52
|
|
|
63
|
-
it
|
|
64
|
-
|
|
53
|
+
it 'returns the correct number of fields' do
|
|
54
|
+
expect(response).to have(2).keys
|
|
65
55
|
end
|
|
66
56
|
|
|
67
|
-
it
|
|
68
|
-
|
|
57
|
+
it 'will not add the conditional field but all others' do
|
|
58
|
+
expect(response.keys).to include(:first_name)
|
|
59
|
+
expect(response.keys).to include(:last_name)
|
|
69
60
|
end
|
|
70
61
|
|
|
71
|
-
it
|
|
72
|
-
|
|
73
|
-
@response.keys.should include(:last_name)
|
|
62
|
+
it 'the other specified fields have the correct value' do
|
|
63
|
+
expect(response.values).to include(@han.first_name, @han.last_name)
|
|
74
64
|
end
|
|
75
|
-
|
|
76
|
-
it "the other specified fields have the correct value" do
|
|
77
|
-
@response.values.should include(@han.first_name, @han.last_name)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
65
|
end
|
|
81
|
-
|
|
82
66
|
end
|
|
83
|
-
|
|
84
67
|
end
|
|
85
68
|
|
|
86
|
-
describe
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
before(:each) do
|
|
91
|
-
@response = @luke.as_api_response(:unless_under_thirty_proc)
|
|
92
|
-
end
|
|
69
|
+
describe 'passing a proc' do
|
|
70
|
+
describe 'that returns false' do
|
|
71
|
+
subject(:response) { @luke.as_api_response(:unless_under_thirty_proc) }
|
|
93
72
|
|
|
94
|
-
it
|
|
95
|
-
|
|
73
|
+
it 'returns a hash' do
|
|
74
|
+
expect(response).to be_kind_of(Hash)
|
|
96
75
|
end
|
|
97
76
|
|
|
98
|
-
it
|
|
99
|
-
|
|
77
|
+
it 'returns the correct number of fields' do
|
|
78
|
+
expect(response).to have(1).keys
|
|
100
79
|
end
|
|
101
80
|
|
|
102
|
-
it
|
|
103
|
-
|
|
104
|
-
|
|
81
|
+
it 'will not add the conditional field but all others' do
|
|
82
|
+
expect(response.keys).to include(:first_name)
|
|
83
|
+
expect(response.keys).not_to include(:full_name)
|
|
105
84
|
end
|
|
106
85
|
|
|
107
|
-
it
|
|
108
|
-
|
|
86
|
+
it 'the other specified fields have the correct value' do
|
|
87
|
+
expect(response.values).to include(@luke.first_name)
|
|
109
88
|
end
|
|
110
|
-
|
|
111
89
|
end
|
|
112
90
|
|
|
113
|
-
describe
|
|
114
|
-
|
|
115
|
-
before(:each) do
|
|
116
|
-
@response = @luke.as_api_response(:if_returns_nil_proc)
|
|
117
|
-
end
|
|
91
|
+
describe 'that returns nil' do
|
|
92
|
+
subject(:response) { @luke.as_api_response(:if_returns_nil_proc) }
|
|
118
93
|
|
|
119
|
-
it
|
|
120
|
-
|
|
94
|
+
it 'returns a hash' do
|
|
95
|
+
expect(response).to be_kind_of(Hash)
|
|
121
96
|
end
|
|
122
97
|
|
|
123
|
-
it
|
|
124
|
-
|
|
98
|
+
it 'returns the correct number of fields' do
|
|
99
|
+
expect(response).to have(1).keys
|
|
125
100
|
end
|
|
126
101
|
|
|
127
|
-
it
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
it 'will not add the conditional field but all others' do
|
|
103
|
+
expect(response.keys).to include(:first_name)
|
|
104
|
+
expect(response.keys).not_to include(:full_name)
|
|
130
105
|
end
|
|
131
106
|
|
|
132
|
-
it
|
|
133
|
-
|
|
107
|
+
it 'the other specified fields have the correct value' do
|
|
108
|
+
expect(response.values).to include(@luke.first_name)
|
|
134
109
|
end
|
|
135
|
-
|
|
136
110
|
end
|
|
137
111
|
|
|
138
|
-
describe
|
|
139
|
-
|
|
140
|
-
before(:each) do
|
|
141
|
-
@response = @han.as_api_response(:unless_under_thirty_proc)
|
|
142
|
-
end
|
|
112
|
+
describe 'that returns true' do
|
|
113
|
+
subject(:response) { @han.as_api_response(:unless_under_thirty_proc) }
|
|
143
114
|
|
|
144
|
-
it
|
|
145
|
-
|
|
115
|
+
it 'returns a hash' do
|
|
116
|
+
expect(response).to be_kind_of(Hash)
|
|
146
117
|
end
|
|
147
118
|
|
|
148
|
-
it
|
|
149
|
-
|
|
119
|
+
it 'returns the correct number of fields' do
|
|
120
|
+
expect(response).to have(2).keys
|
|
150
121
|
end
|
|
151
122
|
|
|
152
|
-
it
|
|
153
|
-
|
|
154
|
-
|
|
123
|
+
it 'will not add the conditional field but all others' do
|
|
124
|
+
expect(response.keys).to include(:first_name)
|
|
125
|
+
expect(response.keys).to include(:last_name)
|
|
155
126
|
end
|
|
156
127
|
|
|
157
|
-
it
|
|
158
|
-
|
|
128
|
+
it 'the other specified fields have the correct value' do
|
|
129
|
+
expect(response.values).to include(@han.first_name, @han.last_name)
|
|
159
130
|
end
|
|
160
|
-
|
|
161
131
|
end
|
|
162
|
-
|
|
163
132
|
end
|
|
164
|
-
|
|
165
133
|
end
|