ncfoundry 4.9.2

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 (268) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +11 -0
  8. data/Checkfile +2 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE +987 -0
  11. data/NOTICE +10 -0
  12. data/README.md +9 -0
  13. data/Rakefile +14 -0
  14. data/VERSION +1 -0
  15. data/cfoundry.gemspec +41 -0
  16. data/config/locales/en.yml +168 -0
  17. data/lib/cc_api_stub/app_usage_events.rb +11 -0
  18. data/lib/cc_api_stub/applications.rb +57 -0
  19. data/lib/cc_api_stub/domains.rb +32 -0
  20. data/lib/cc_api_stub/events.rb +11 -0
  21. data/lib/cc_api_stub/frameworks.rb +22 -0
  22. data/lib/cc_api_stub/helper.rb +148 -0
  23. data/lib/cc_api_stub/login.rb +21 -0
  24. data/lib/cc_api_stub/organization_users.rb +27 -0
  25. data/lib/cc_api_stub/organizations.rb +82 -0
  26. data/lib/cc_api_stub/routes.rb +26 -0
  27. data/lib/cc_api_stub/runtimes.rb +22 -0
  28. data/lib/cc_api_stub/service_bindings.rb +22 -0
  29. data/lib/cc_api_stub/service_instances.rb +22 -0
  30. data/lib/cc_api_stub/services.rb +21 -0
  31. data/lib/cc_api_stub/space_users.rb +27 -0
  32. data/lib/cc_api_stub/spaces.rb +58 -0
  33. data/lib/cc_api_stub/users.rb +85 -0
  34. data/lib/cc_api_stub.rb +20 -0
  35. data/lib/cfoundry/auth_token.rb +62 -0
  36. data/lib/cfoundry/baseclient.rb +220 -0
  37. data/lib/cfoundry/chatty_hash.rb +46 -0
  38. data/lib/cfoundry/client.rb +42 -0
  39. data/lib/cfoundry/concerns/login_helpers.rb +14 -0
  40. data/lib/cfoundry/concerns/proxy_options.rb +14 -0
  41. data/lib/cfoundry/errors.rb +163 -0
  42. data/lib/cfoundry/rest_client.rb +316 -0
  43. data/lib/cfoundry/test_support.rb +3 -0
  44. data/lib/cfoundry/trace_helpers.rb +64 -0
  45. data/lib/cfoundry/uaaclient.rb +151 -0
  46. data/lib/cfoundry/upload_helpers.rb +222 -0
  47. data/lib/cfoundry/v2/app.rb +313 -0
  48. data/lib/cfoundry/v2/app_event.rb +13 -0
  49. data/lib/cfoundry/v2/app_instance.rb +74 -0
  50. data/lib/cfoundry/v2/app_usage_event.rb +14 -0
  51. data/lib/cfoundry/v2/base.rb +112 -0
  52. data/lib/cfoundry/v2/client.rb +104 -0
  53. data/lib/cfoundry/v2/domain.rb +20 -0
  54. data/lib/cfoundry/v2/event.rb +17 -0
  55. data/lib/cfoundry/v2/helper.rb +11 -0
  56. data/lib/cfoundry/v2/managed_service_instance.rb +13 -0
  57. data/lib/cfoundry/v2/model.rb +213 -0
  58. data/lib/cfoundry/v2/model_magic/attribute.rb +49 -0
  59. data/lib/cfoundry/v2/model_magic/client_extensions.rb +170 -0
  60. data/lib/cfoundry/v2/model_magic/has_summary.rb +49 -0
  61. data/lib/cfoundry/v2/model_magic/query_multi_value_helper.rb +21 -0
  62. data/lib/cfoundry/v2/model_magic/query_value_helper.rb +33 -0
  63. data/lib/cfoundry/v2/model_magic/queryable_by.rb +39 -0
  64. data/lib/cfoundry/v2/model_magic/to_many.rb +145 -0
  65. data/lib/cfoundry/v2/model_magic/to_one.rb +81 -0
  66. data/lib/cfoundry/v2/model_magic.rb +134 -0
  67. data/lib/cfoundry/v2/organization.rb +44 -0
  68. data/lib/cfoundry/v2/quota_definition.rb +12 -0
  69. data/lib/cfoundry/v2/route.rb +25 -0
  70. data/lib/cfoundry/v2/service.rb +22 -0
  71. data/lib/cfoundry/v2/service_auth_token.rb +9 -0
  72. data/lib/cfoundry/v2/service_binding.rb +10 -0
  73. data/lib/cfoundry/v2/service_broker.rb +12 -0
  74. data/lib/cfoundry/v2/service_instance.rb +14 -0
  75. data/lib/cfoundry/v2/service_plan.rb +16 -0
  76. data/lib/cfoundry/v2/space.rb +31 -0
  77. data/lib/cfoundry/v2/stack.rb +10 -0
  78. data/lib/cfoundry/v2/user.rb +97 -0
  79. data/lib/cfoundry/v2/user_provided_service_instance.rb +16 -0
  80. data/lib/cfoundry/validator.rb +41 -0
  81. data/lib/cfoundry/version.rb +4 -0
  82. data/lib/cfoundry/zip.rb +56 -0
  83. data/lib/cfoundry.rb +6 -0
  84. data/release_notes/release_1_5_3.md +177 -0
  85. data/release_notes/release_2.3.1.md +14 -0
  86. data/release_notes/release_2.3.3.md +38 -0
  87. data/release_notes/release_2.3.4.md +16 -0
  88. data/release_notes/release_2.3.5.md +14 -0
  89. data/release_notes/release_2.3.6.md +14 -0
  90. data/release_notes/release_2.3.6.rc1.md +29 -0
  91. data/release_notes/release_2.3.6.rc2.md +19 -0
  92. data/release_notes/release_2.3.7.rc1.md +14 -0
  93. data/release_notes/release_2.4.0.md +41 -0
  94. data/release_notes/release_2.4.1.rc1.md +58 -0
  95. data/release_notes/release_3.0.0.md +21 -0
  96. data/release_notes/release_3.0.1.md +16 -0
  97. data/release_notes/release_3.0.2.rc1.md +19 -0
  98. data/release_notes/release_4.0.0.md +19 -0
  99. data/release_notes/release_4.0.1.md +14 -0
  100. data/release_notes/release_4.0.2.rc1.md +14 -0
  101. data/release_notes/release_4.0.2.rc2.md +11 -0
  102. data/release_notes/release_4.0.2.rc3.md +11 -0
  103. data/release_notes/release_4.0.2.rc4.md +19 -0
  104. data/release_notes/release_4.0.2.rc5.md +14 -0
  105. data/release_notes/release_4.0.3.md +19 -0
  106. data/release_notes/release_4.0.4.rc1.md +14 -0
  107. data/release_notes/release_4.0.4.rc2.md +14 -0
  108. data/release_notes/release_4.1.0.md +19 -0
  109. data/release_notes/release_4.2.0.rc.md +24 -0
  110. data/release_notes/release_4.3.0.md +22 -0
  111. data/release_notes/release_4.3.1.md +14 -0
  112. data/release_notes/release_4.3.10.md +14 -0
  113. data/release_notes/release_4.3.11.md +14 -0
  114. data/release_notes/release_4.3.12.md +14 -0
  115. data/release_notes/release_4.3.2.rc1.md +21 -0
  116. data/release_notes/release_4.3.3.md +24 -0
  117. data/release_notes/release_4.3.4.md +11 -0
  118. data/release_notes/release_4.3.4.rc1.md +24 -0
  119. data/release_notes/release_4.3.5.md +36 -0
  120. data/release_notes/release_4.3.5.rc1.md +21 -0
  121. data/release_notes/release_4.3.6.md +14 -0
  122. data/release_notes/release_4.3.7.md +50 -0
  123. data/release_notes/release_4.3.8.md +19 -0
  124. data/release_notes/release_4.3.9.md +14 -0
  125. data/release_notes/release_4.4.0.md +16 -0
  126. data/release_notes/release_4.5.1.md +11 -0
  127. data/release_notes/release_4.5.2.md +14 -0
  128. data/release_notes/release_4.5.3.md +29 -0
  129. data/release_notes/release_4.6.0.md +24 -0
  130. data/release_notes/release_4.6.1.md +14 -0
  131. data/release_notes/release_4.6.2.md +16 -0
  132. data/release_notes/release_4.6.3.rc1.md +14 -0
  133. data/release_notes/release_4.6.3.rc2.md +14 -0
  134. data/release_notes/release_4.6.3.rc3.md +17 -0
  135. data/release_notes/release_4.7.0.md +11 -0
  136. data/release_notes/release_4.7.1.md +14 -0
  137. data/release_notes/release_4.7.1.rc.1.md +14 -0
  138. data/release_notes/release_4.7.1.rc1.md +19 -0
  139. data/script/gpp +3 -0
  140. data/spec/cc_api_stub/app_usage_events_spec.rb +12 -0
  141. data/spec/cc_api_stub/applications_spec.rb +69 -0
  142. data/spec/cc_api_stub/domains_spec.rb +40 -0
  143. data/spec/cc_api_stub/events_spec.rb +12 -0
  144. data/spec/cc_api_stub/frameworks_spec.rb +19 -0
  145. data/spec/cc_api_stub/login_spec.rb +20 -0
  146. data/spec/cc_api_stub/organization_users_spec.rb +35 -0
  147. data/spec/cc_api_stub/organizations_spec.rb +118 -0
  148. data/spec/cc_api_stub/routes_spec.rb +19 -0
  149. data/spec/cc_api_stub/runtimes_spec.rb +19 -0
  150. data/spec/cc_api_stub/service_bindings_spec.rb +13 -0
  151. data/spec/cc_api_stub/service_instances_spec.rb +19 -0
  152. data/spec/cc_api_stub/services_spec.rb +11 -0
  153. data/spec/cc_api_stub/space_users_spec.rb +35 -0
  154. data/spec/cc_api_stub/spaces_spec.rb +38 -0
  155. data/spec/cc_api_stub/users_spec.rb +107 -0
  156. data/spec/cfoundry/auth_token_spec.rb +153 -0
  157. data/spec/cfoundry/baseclient_spec.rb +284 -0
  158. data/spec/cfoundry/client_spec.rb +13 -0
  159. data/spec/cfoundry/errors_spec.rb +117 -0
  160. data/spec/cfoundry/rest_client_spec.rb +367 -0
  161. data/spec/cfoundry/trace_helpers_spec.rb +91 -0
  162. data/spec/cfoundry/uaaclient_spec.rb +421 -0
  163. data/spec/cfoundry/upload_helpers_spec.rb +182 -0
  164. data/spec/cfoundry/v2/app_event_spec.rb +97 -0
  165. data/spec/cfoundry/v2/app_instance_spec.rb +31 -0
  166. data/spec/cfoundry/v2/app_spec.rb +354 -0
  167. data/spec/cfoundry/v2/app_usage_event_spec.rb +15 -0
  168. data/spec/cfoundry/v2/base_spec.rb +375 -0
  169. data/spec/cfoundry/v2/client_spec.rb +121 -0
  170. data/spec/cfoundry/v2/domain_spec.rb +63 -0
  171. data/spec/cfoundry/v2/event_spec.rb +15 -0
  172. data/spec/cfoundry/v2/managed_service_instance_spec.rb +149 -0
  173. data/spec/cfoundry/v2/model_magic/attribute_spec.rb +123 -0
  174. data/spec/cfoundry/v2/model_magic/has_summary_spec.rb +17 -0
  175. data/spec/cfoundry/v2/model_magic/to_many_spec.rb +53 -0
  176. data/spec/cfoundry/v2/model_magic/to_one_spec.rb +106 -0
  177. data/spec/cfoundry/v2/model_magic_spec.rb +43 -0
  178. data/spec/cfoundry/v2/model_spec.rb +472 -0
  179. data/spec/cfoundry/v2/organization_spec.rb +282 -0
  180. data/spec/cfoundry/v2/quota_definition_spec.rb +50 -0
  181. data/spec/cfoundry/v2/route_spec.rb +42 -0
  182. data/spec/cfoundry/v2/service_plan_spec.rb +53 -0
  183. data/spec/cfoundry/v2/service_spec.rb +58 -0
  184. data/spec/cfoundry/v2/space_spec.rb +160 -0
  185. data/spec/cfoundry/v2/user_provided_service_instance_spec.rb +57 -0
  186. data/spec/cfoundry/v2/user_spec.rb +206 -0
  187. data/spec/cfoundry/validator_spec.rb +94 -0
  188. data/spec/factories/app_events_factory.rb +7 -0
  189. data/spec/factories/app_usage_events_factory.rb +32 -0
  190. data/spec/factories/apps_factory.rb +11 -0
  191. data/spec/factories/clients_factory.rb +7 -0
  192. data/spec/factories/domains_factory.rb +10 -0
  193. data/spec/factories/events_factory.rb +50 -0
  194. data/spec/factories/organizations_factory.rb +12 -0
  195. data/spec/factories/quota_definitions_factory.rb +8 -0
  196. data/spec/factories/routes_factory.rb +10 -0
  197. data/spec/factories/service_instances_factory.rb +10 -0
  198. data/spec/factories/service_plans_factory.rb +10 -0
  199. data/spec/factories/services_factory.rb +10 -0
  200. data/spec/factories/spaces_factory.rb +10 -0
  201. data/spec/factories/user_provided_service_instances_factory.rb +10 -0
  202. data/spec/factories/users_factory.rb +10 -0
  203. data/spec/fixtures/apps/with_cfignore/.cfignore +4 -0
  204. data/spec/fixtures/apps/with_cfignore/.hidden_file +1 -0
  205. data/spec/fixtures/apps/with_cfignore/ambiguous_ignored +0 -0
  206. data/spec/fixtures/apps/with_cfignore/ignored_dir/file_in_ignored_dir.txt +1 -0
  207. data/spec/fixtures/apps/with_cfignore/ignored_file.txt +1 -0
  208. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/file_in_non_ignored_dir.txt +1 -0
  209. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/ignored_file.txt +1 -0
  210. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/toplevel_ignored.txt +0 -0
  211. data/spec/fixtures/apps/with_cfignore/non_ignored_file.txt +1 -0
  212. data/spec/fixtures/apps/with_cfignore/toplevel_ignored.txt +0 -0
  213. data/spec/fixtures/apps/with_dotfiles/.dotfile +1 -0
  214. data/spec/fixtures/apps/with_dotfiles/xyz +1 -0
  215. data/spec/fixtures/apps/with_external_symlink/foo +1 -0
  216. data/spec/fixtures/apps/with_ignored_external_symlink/.cfignore +1 -0
  217. data/spec/fixtures/apps/with_ignored_external_symlink/foo +1 -0
  218. data/spec/fixtures/apps/with_nested_directories/foo/bar/baz/fizz +0 -0
  219. data/spec/fixtures/apps/with_nested_directories/xyz +0 -0
  220. data/spec/fixtures/empty_file +0 -0
  221. data/spec/fixtures/fake_cc_app_usage_events.json +152 -0
  222. data/spec/fixtures/fake_cc_application.json +20 -0
  223. data/spec/fixtures/fake_cc_application_summary.json +56 -0
  224. data/spec/fixtures/fake_cc_created_application.json +11 -0
  225. data/spec/fixtures/fake_cc_created_domain.json +15 -0
  226. data/spec/fixtures/fake_cc_created_organization.json +11 -0
  227. data/spec/fixtures/fake_cc_created_route.json +13 -0
  228. data/spec/fixtures/fake_cc_created_service_instance.json +11 -0
  229. data/spec/fixtures/fake_cc_created_space.json +11 -0
  230. data/spec/fixtures/fake_cc_created_user.json +11 -0
  231. data/spec/fixtures/fake_cc_domain.json +55 -0
  232. data/spec/fixtures/fake_cc_domain_spaces.json +27 -0
  233. data/spec/fixtures/fake_cc_empty_search.json +7 -0
  234. data/spec/fixtures/fake_cc_events.json +419 -0
  235. data/spec/fixtures/fake_cc_frameworks.json +20 -0
  236. data/spec/fixtures/fake_cc_managed_service_instance.json +83 -0
  237. data/spec/fixtures/fake_cc_organization.json +161 -0
  238. data/spec/fixtures/fake_cc_organization_domains.json +59 -0
  239. data/spec/fixtures/fake_cc_organization_search.json +37 -0
  240. data/spec/fixtures/fake_cc_organization_spaces.json +99 -0
  241. data/spec/fixtures/fake_cc_organization_summary.json +20 -0
  242. data/spec/fixtures/fake_cc_organization_users.json +81 -0
  243. data/spec/fixtures/fake_cc_route.json +16 -0
  244. data/spec/fixtures/fake_cc_runtimes.json +20 -0
  245. data/spec/fixtures/fake_cc_service_binding.json +22 -0
  246. data/spec/fixtures/fake_cc_service_bindings.json +24 -0
  247. data/spec/fixtures/fake_cc_service_instance.json +83 -0
  248. data/spec/fixtures/fake_cc_service_instances.json +72 -0
  249. data/spec/fixtures/fake_cc_services.json +160 -0
  250. data/spec/fixtures/fake_cc_space.json +45 -0
  251. data/spec/fixtures/fake_cc_space_apps.json +49 -0
  252. data/spec/fixtures/fake_cc_space_summary.json +84 -0
  253. data/spec/fixtures/fake_cc_spaces.json +92 -0
  254. data/spec/fixtures/fake_cc_stats.json +29 -0
  255. data/spec/fixtures/fake_cc_user.json +139 -0
  256. data/spec/fixtures/fake_cc_user_organizations.json +92 -0
  257. data/spec/fixtures/fake_cc_user_provided_service_instance.json +51 -0
  258. data/spec/fixtures/fake_cc_user_with_managers.json +85 -0
  259. data/spec/integration/client_spec.rb +38 -0
  260. data/spec/spec_helper.rb +22 -0
  261. data/spec/support/factory_girl.rb +6 -0
  262. data/spec/support/shared_examples/cc_api_stub_request_examples.rb +79 -0
  263. data/spec/support/shared_examples/client_login_examples.rb +46 -0
  264. data/spec/support/shared_examples/model_summary_examples.rb +34 -0
  265. data/spec/support/test_model_builder.rb +10 -0
  266. data/vendor/errors/v1.yml +189 -0
  267. data/vendor/errors/v2.yml +845 -0
  268. metadata +712 -0
@@ -0,0 +1,149 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe ManagedServiceInstance do
6
+ let(:client) { build(:client) }
7
+ subject { build(:service_instance, :client => client) }
8
+
9
+ describe "space" do
10
+ let(:space) { build(:space) }
11
+
12
+ it "has a space" do
13
+ subject.space = space
14
+ expect(subject.space).to eq(space)
15
+ end
16
+
17
+ context "when an invalid value is assigned" do
18
+ it "raises a Mismatch exception" do
19
+ expect {
20
+ subject.space = [build(:organization)]
21
+ }.to raise_error(CFoundry::Mismatch)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "service_plan" do
27
+ let(:service_plan) { build(:service_plan) }
28
+
29
+ it "has a service plan" do
30
+ subject.service_plan = service_plan
31
+ expect(subject.service_plan).to eq(service_plan)
32
+ end
33
+
34
+ context "when an invalid value is assigned" do
35
+ it "raises a Mismatch exception" do
36
+ expect {
37
+ subject.space = [build(:organization)]
38
+ }.to raise_error(CFoundry::Mismatch)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "fetching the service instances" do
44
+ let(:example_response) do
45
+ '{
46
+ "total_results": 2,
47
+ "total_pages": 1,
48
+ "prev_url": null,
49
+ "next_url": null,
50
+ "resources": [
51
+ {
52
+ "metadata": {
53
+ "guid": "2148b3c4-3d3d-4361-87a3-1b4bf834cdea",
54
+ "url": "/v2/service_instances/2148b3c4-3d3d-4361-87a3-1b4bf834cdea",
55
+ "created_at": "2013-07-24 00:32:23 +0000",
56
+ "updated_at": null
57
+ },
58
+ "entity": {
59
+ "type": "user_provided_service_instance",
60
+ "name": "user-provided-6a19d",
61
+ "credentials": {
62
+ "thing": "a"
63
+ },
64
+ "space_guid": "15ee90c2-8654-40c9-a311-ecfef8cbc921",
65
+ "space_url": "/v2/spaces/15ee90c2-8654-40c9-a311-ecfef8cbc921",
66
+ "service_bindings_url": "/v2/service_instances/2148b3c4-3d3d-4361-87a3-1b4bf834cdea/service_bindings"
67
+ }
68
+ },
69
+ {
70
+ "metadata": {
71
+ "guid": "746c36b0-4b5f-4e46-876a-2948804ef464",
72
+ "url": "/v2/service_instances/746c36b0-4b5f-4e46-876a-2948804ef464",
73
+ "created_at": "2013-07-24 00:32:33 +0000",
74
+ "updated_at": null
75
+ },
76
+ "entity": {
77
+ "type": "managed_service_instance",
78
+ "name": "rds-mysql-3991f",
79
+ "credentials": {
80
+ "name": "da2f110d519d848a1a677f8df77890cc3",
81
+ "hostname": "mysql-service-public.cze9ndyywtkf.us-east-1.rds.amazonaws.com",
82
+ "host": "mysql-service-public.cze9ndyywtkf.us-east-1.rds.amazonaws.com",
83
+ "port": 3306,
84
+ "user": "ufZEqKvAXQogC",
85
+ "username": "ufZEqKvAXQogC",
86
+ "password": "p8QGNHykcSTu2",
87
+ "node_id": "rds_mysql_node_10mb_0"
88
+ },
89
+ "service_plan_guid": "2c7ab67d-4354-46b5-8423-b19ef6e4b50a",
90
+ "space_guid": "15ee90c2-8654-40c9-a311-ecfef8cbc921",
91
+ "gateway_data": {
92
+ "plan": "10mb",
93
+ "version": "n/a"
94
+ },
95
+ "dashboard_url": null,
96
+ "space_url": "/v2/spaces/15ee90c2-8654-40c9-a311-ecfef8cbc921",
97
+ "service_plan_url": "/v2/service_plans/2c7ab67d-4354-46b5-8423-b19ef6e4b50a",
98
+ "service_bindings_url": "/v2/service_instances/746c36b0-4b5f-4e46-876a-2948804ef464/service_bindings"
99
+ }
100
+ }
101
+ ]
102
+ }'
103
+ end
104
+
105
+ context "when there is a current org and a current space" do
106
+ let(:org) { build(:organization) }
107
+ let(:space) { build(:space, organization: org) }
108
+ let(:client) { build(:client, current_organization: org, current_space: space) }
109
+
110
+ it "gets both user-provided and cf-managed service instances" do
111
+ http_stub = stub_request(:get, "#{client.target}/v2/spaces/#{space.guid}/service_instances?inline-relations-depth=1&return_user_provided_service_instances=true").to_return(:status => 200, :body => example_response)
112
+ client.service_instances
113
+ expect(http_stub).to have_been_requested
114
+ end
115
+
116
+ describe "via service_instance_from" do
117
+ it "defaults to true when user_provided is set to a bogus value (not true or false)" do
118
+ http_stub = stub_request(:get, "#{client.target}/v2/spaces/#{space.guid}/service_instances?inline-relations-depth=1&return_user_provided_service_instances=true").to_return(:status => 200, :body => example_response)
119
+ client.service_instances(user_provided: 'some_non-boolean_value')
120
+ expect(http_stub).to have_been_requested
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ describe 'query params' do
127
+ it 'allows query by name' do
128
+ expect(client).to respond_to(:service_instance_by_name)
129
+ end
130
+
131
+ it 'allows query by space_guid' do
132
+ expect(client).to respond_to(:service_instance_by_space_guid)
133
+ end
134
+
135
+ it 'allows query by gateway_name' do
136
+ expect(client).to respond_to(:service_instance_by_gateway_name)
137
+ end
138
+
139
+ it 'allows query by service_plan_guid' do
140
+ expect(client).to respond_to(:service_instance_by_service_plan_guid)
141
+ end
142
+
143
+ it 'allows query by service_binding_guid' do
144
+ expect(client).to respond_to(:service_instance_by_service_binding_guid)
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe ModelMagic do
6
+ describe "attributes" do
7
+ let(:guid) { "test-model-guid-1" }
8
+ let(:client) { build(:client) }
9
+
10
+ describe "reading" do
11
+ context "when it exists in the manifest" do
12
+ let(:manifest) { {:metadata => {}, :entity => {:foo => "bar"}} }
13
+
14
+ let(:model) do
15
+ TestModelBuilder.build(guid, client, manifest) { attribute :foo, :object }
16
+ end
17
+
18
+ it "returns the value from the manifest" do
19
+ expect(model.foo).to eq "bar"
20
+ end
21
+
22
+ context "and the default is nil but the value is false" do
23
+ let(:model) do
24
+ TestModelBuilder.build(guid, client, manifest) { attribute :foo, :object, :default => nil }
25
+ end
26
+
27
+ before do
28
+ model.foo = false
29
+ end
30
+
31
+ it "returns false" do
32
+ expect(model.foo).to eq false
33
+ end
34
+ end
35
+
36
+ context "and the default is false but the value is nil" do
37
+ let(:model) do
38
+ TestModelBuilder.build(guid, client, manifest) { attribute :foo, :object, :default => false }
39
+ end
40
+
41
+ before do
42
+ model.foo = nil
43
+ end
44
+
45
+ it "returns nil" do
46
+ expect(model.foo).to eq nil
47
+ end
48
+ end
49
+ end
50
+
51
+ context "when the manifest has not been acquired" do
52
+ let(:model) do
53
+ TestModelBuilder.build(guid, client) { attribute :foo, :object }
54
+ end
55
+
56
+ it "retrieves the manifest the first time" do
57
+ expect(client.base).to receive(:test_model).with("test-model-guid-1") {
58
+ {:entity => {:foo => "fizz"}}
59
+ }.ordered
60
+
61
+ expect(model.foo).to eq "fizz"
62
+
63
+ expect(client.base).not_to receive(:model)
64
+
65
+ expect(model.foo).to eq "fizz"
66
+ end
67
+ end
68
+
69
+ context "when it does not exist in the manifest" do
70
+ let(:model) do
71
+ TestModelBuilder.build(guid, client, {:entity => {}}) { attribute :foo, :object, :default => "foo" }
72
+ end
73
+
74
+ it "returns the default value" do
75
+ expect(model.foo).to eq "foo"
76
+ end
77
+ end
78
+
79
+ context "when the attribute has a custom json key" do
80
+ let(:model) do
81
+ TestModelBuilder.build(guid, client) { attribute :foo, :object, :at => :not_foo }
82
+ end
83
+
84
+ before do
85
+ allow(client.base).to receive(:test_model).with("test-model-guid-1") {
86
+ {:entity => {:not_foo => "fizz"}}
87
+ }
88
+ end
89
+
90
+ it "retrieves the attribute using the custom key" do
91
+ expect(model.foo).to eq "fizz"
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "writing" do
97
+ context "when the attribute has a custom json key" do
98
+ let(:model) do
99
+ TestModelBuilder.build(guid, client) { attribute :foo, :object, :at => :not_foo }
100
+ end
101
+
102
+ it "uses the 'at' value in the update payload" do
103
+ expect(client.base).to receive(:put).with("v2", :test_models, model.guid, hash_including(:payload => {:not_foo => 123}))
104
+ model.foo = 123
105
+ model.update!
106
+ end
107
+
108
+ it "uses the 'at' value in the create payload" do
109
+ model.foo = 123
110
+ expect(client.base).to receive(:post).with("v2", :test_models, hash_including(:payload => {:not_foo => 123})) { {:metadata => {}} }
111
+ model.create!
112
+ end
113
+
114
+ it "is then readable via the attribute name" do
115
+ model.foo = 123
116
+ expect(model.foo).to eq 123
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ class TestModel < CFoundry::V2::Model
4
+ attribute :foo, :string
5
+ end
6
+
7
+ module CFoundry
8
+ module V2
9
+ describe ModelMagic do
10
+ it_behaves_like "a summarizeable model" do
11
+ let(:summary_attributes) { {:foo => "abcd"} }
12
+ let(:client) { build(:client) }
13
+ subject { TestModel.new("some-guid-1", client) }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ class AssociatedModel < CFoundry::V2::Model
4
+ attribute :attribute, String
5
+ end
6
+
7
+ module CFoundry
8
+ module V2
9
+ module ModelMagic
10
+ describe ToMany do
11
+ let(:client) { build(:client) }
12
+
13
+ describe "to_many relationships" do
14
+ describe "associated create" do
15
+ let(:model) do
16
+ TestModelBuilder.build("test-model-guid-1", client) { to_many :associated_models }
17
+ end
18
+
19
+ before do
20
+ WebMock.stub_request(:put, /v2\/test_models\/.*\/associated_models/).to_return(:body => {}.to_json)
21
+ WebMock.stub_request(:post, /v2\/associated_model/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json)
22
+ stub_request(:get, /v2\/test_models\/.*\/associated_models/)
23
+ model.associated_models = []
24
+ end
25
+
26
+ it "returns a new associated object" do
27
+ expect(model.create_associated_model).to be_a(AssociatedModel)
28
+ end
29
+
30
+ it "sets the relation" do
31
+ created = model.create_associated_model
32
+ expect(model.associated_models).to include(created)
33
+ end
34
+
35
+ context "with attributes for the association" do
36
+ it "sets these attributes on the association" do
37
+ created = model.create_associated_model(:attribute => "value")
38
+ expect(created.attribute).to eq("value")
39
+ end
40
+ end
41
+
42
+ context "when creation fails" do
43
+ it "raises an exception" do
44
+ WebMock.stub_request(:post, /v2\/associated_model/).to_raise(:not_authorized)
45
+ expect { model.create_associated_model }.to raise_error(StandardError)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,106 @@
1
+ require "spec_helper"
2
+
3
+ class AssociatedModel < CFoundry::V2::Model
4
+ attribute :attribute, String
5
+ end
6
+
7
+ module CFoundry
8
+ module V2
9
+ module ModelMagic
10
+ describe ToOne do
11
+ let(:client) { build(:client) }
12
+ let(:model) { model.new("my-object-guid-1", client) }
13
+
14
+ describe "to_one relationships" do
15
+ describe "writing" do
16
+ let(:model) do
17
+ TestModelBuilder.build("my-model-guid-1", client) { to_one :associated_model }
18
+ end
19
+
20
+ let(:other_model) do
21
+ AssociatedModel.new("my-model-guid-2", client)
22
+ end
23
+
24
+ before do
25
+ stub_request(:get, /v2\/test_models\/.*/).to_return(:body => {:entity => {}}.to_json)
26
+ end
27
+
28
+ it "sets the GUID in the manifest to the object's GUID" do
29
+ expect {
30
+ model.associated_model = other_model
31
+ }.to change { model.manifest[:entity][:associated_model_guid] }.to(other_model.guid)
32
+ end
33
+
34
+ it "tracks internal changes in the diff" do
35
+ expect {
36
+ model.associated_model = other_model
37
+ }.to change { model.diff }.to(:associated_model_guid => other_model.guid)
38
+ end
39
+
40
+ it "tracks high-level changes in .changes" do
41
+ previous_associated_model = AssociatedModel.new("my-model-guid-3", client)
42
+ model.associated_model = previous_associated_model
43
+
44
+ expect {
45
+ model.associated_model = other_model
46
+ }.to change { model.changes }.to(:associated_model => [previous_associated_model, other_model])
47
+ end
48
+
49
+ it "returns the assigned value" do
50
+ expect(model.send(:associated_model=, other_model)).to eq(other_model)
51
+ end
52
+
53
+ context "when there is a default" do
54
+ let(:model) { TestModelBuilder.build("my-model-guid-1", client) { to_one :associated_model, :default => nil } }
55
+
56
+ before do
57
+ model.associated_model = other_model
58
+ end
59
+
60
+ it "allows setting to the default" do
61
+ expect {
62
+ model.associated_model = nil
63
+ }.to change {
64
+ model.manifest[:entity][:associated_model_guid]
65
+ }.from(other_model.guid).to(nil)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "associated create" do
71
+ let(:model) do
72
+ TestModelBuilder.build("my-model-guid-1", client) { to_one :associated_model }
73
+ end
74
+
75
+ before do
76
+ WebMock.stub_request(:post, /v2\/associated_model/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json)
77
+ end
78
+
79
+ it "returns a new associated object" do
80
+ expect(model.create_associated_model).to be_a(AssociatedModel)
81
+ end
82
+
83
+ it "sets the relation" do
84
+ created = model.create_associated_model
85
+ expect(model.associated_model).to eq(created)
86
+ end
87
+
88
+ context "with attributes for the association" do
89
+ it "sets these attributes on the association" do
90
+ created = model.create_associated_model(:attribute => "value")
91
+ expect(created.attribute).to eq("value")
92
+ end
93
+ end
94
+
95
+ context "when creation fails" do
96
+ it "raises an exception" do
97
+ WebMock.stub_request(:post, /v2\/associated/).to_raise(:not_authorized)
98
+ expect { instance.create_associated }.to raise_error(StandardError)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe ModelMagic do
6
+ describe "params_from" do
7
+ describe "query" do
8
+ it "filters by a single key and value" do
9
+ params = ModelMagic.params_from({query: ['key', 'value']})
10
+ expect(params[:q]).to eq("key:value")
11
+ end
12
+
13
+ it "filters by a list of values for a key" do
14
+ params = ModelMagic.params_from({query: {key: ['value1', 'value2']}})
15
+ expect(params[:q]).to eq("key IN value1,value2")
16
+ end
17
+
18
+ it "filters by complex QueryValue" do
19
+ params = ModelMagic.params_from({query: {key: ModelMagic::QueryValue.new(comparator: '>', value:'value1')}})
20
+ expect(params[:q]).to eq("key>value1")
21
+ end
22
+
23
+ it "filters by multiple fields" do
24
+ params = ModelMagic.params_from({query: {key1: ModelMagic::QueryValue.new(comparator: '>=', value:'value1'), key2: 'value2', key3: ['value3a', 'value3b']}})
25
+ expect(params[:q]).to eq("key1>=value1;key2:value2;key3 IN value3a,value3b")
26
+ end
27
+
28
+ it "filters by multiple QueryValues" do
29
+ params = ModelMagic.params_from({query: {key: ModelMagic::QueryMultiValue.new({comparator: '>', value: 'value1'},{comparator: '<', value: 'value2'})}})
30
+ expect(params[:q]).to eq("key>value1;key<value2")
31
+ end
32
+ end
33
+
34
+ describe "other arguments" do
35
+ it "appends them to the params as is" do
36
+ params = ModelMagic.params_from({other_argument: 'something'})
37
+ expect(params[:other_argument]).to eq('something')
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end