cfoundry 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -98,7 +98,14 @@ module CFoundry
98
98
  def stream_url(url, &blk)
99
99
  uri = URI.parse(url)
100
100
 
101
- Net::HTTP.start(uri.host, uri.port) do |http|
101
+ opts = {}
102
+
103
+ if uri.scheme == "https"
104
+ opts[:use_ssl] = true
105
+ opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
106
+ end
107
+
108
+ Net::HTTP.start(uri.host, uri.port, opts) do |http|
102
109
  http.read_timeout = 5
103
110
 
104
111
  req = Net::HTTP::Get.new(uri.request_uri)
@@ -64,9 +64,22 @@ module CFoundry
64
64
  elsif klass.scoped_organization && current_organization
65
65
  current_organization.send(plural, *args)
66
66
  else
67
- @base.send(plural, *args).collect do |json|
67
+ prefiltered = @base.send(plural, *args).collect do |json|
68
68
  send(:"make_#{singular}", json)
69
69
  end
70
+
71
+ filtered = prefiltered
72
+ if args && args[0]
73
+ opts = args[0]
74
+ if opts[:query]
75
+ filtered.select! do |obj|
76
+ key = opts[:query][0].to_s
77
+ value = opts[:query][1]
78
+ obj.send(key) == value
79
+ end
80
+ end
81
+ end
82
+ filtered
70
83
  end
71
84
  end
72
85
 
@@ -121,4 +134,4 @@ module CFoundry
121
134
  end
122
135
  end
123
136
  end
124
- end
137
+ end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "2.3.2".freeze
3
+ VERSION = "2.3.3".freeze
4
4
  end
@@ -7,6 +7,7 @@ namespace :gem do
7
7
  old_version = gem_version
8
8
 
9
9
  sh! "gem bump --version #{version} --no-commit"
10
+ sh! "git add lib/cfoundry/version.rb"
10
11
 
11
12
  print_with_purpose "Bumping to version #{gem_version}"
12
13
  generate_release_notes(old_version)
@@ -38,4 +39,4 @@ namespace :gem do
38
39
  end
39
40
  Gem::Specification.load("cfoundry.gemspec").version.to_s
40
41
  end
41
- end
42
+ end
@@ -206,6 +206,18 @@ describe CFoundry::BaseClient do
206
206
  expect(chunks).to eq(["result"])
207
207
  end
208
208
 
209
+ it "handles https" do
210
+ stub_request(:get, "https://example.com/something").to_return(
211
+ :body => "https result")
212
+
213
+ chunks = []
214
+ subject.stream_url("https://example.com/something") do |chunk|
215
+ chunks << chunk
216
+ end
217
+
218
+ expect(chunks).to eq(["https result"])
219
+ end
220
+
209
221
  it "raises NotFound if response is 404" do
210
222
  stub_request(:get, "http://example.com/something").to_return(
211
223
  :status => 404, :body => "result")
@@ -11,6 +11,126 @@ module CFoundry
11
11
  let(:summary_attributes) { {:name => "fizzbuzz"} }
12
12
  end
13
13
 
14
+ describe "Querying" do
15
+ describe "by :name" do
16
+ let(:query_param) { "My Org" }
17
+
18
+ let(:matching_org) do
19
+ org = CcApiStub::Helper.load_fixtures("fake_cc_organization").symbolize_keys
20
+ org[:metadata] = org[:metadata].symbolize_keys
21
+ org[:entity] = org[:entity].symbolize_keys
22
+
23
+ org[:entity][:name] = query_param
24
+ org
25
+ end
26
+
27
+ let(:non_matching_org) do
28
+ org = CcApiStub::Helper.load_fixtures("fake_cc_organization").symbolize_keys
29
+ org[:metadata] = org[:metadata].symbolize_keys
30
+ org[:entity] = org[:entity].symbolize_keys
31
+ org[:metadata][:guid] = "organization-id-2"
32
+
33
+ org[:entity][:name] = "organization-name-2"
34
+ org
35
+ end
36
+
37
+ context "when there are two orgs and one match" do
38
+ before do
39
+ client.base.stub(:organizations).and_return([non_matching_org, matching_org])
40
+ end
41
+
42
+ context "when queried with #organizations" do
43
+ subject { client.organizations(:query => [:name, query_param]) }
44
+
45
+ it "returns the org with the given name" do
46
+ expect(subject.size).to eq 1
47
+ expect(subject[0].name).to eq query_param
48
+ end
49
+ end
50
+
51
+ context "when queried with #organzations_by_name" do
52
+ subject { client.organizations_by_name(query_param) }
53
+
54
+ it "returns the org with the given name" do
55
+ expect(subject.size).to eq 1
56
+ expect(subject[0].name).to eq query_param
57
+ end
58
+ end
59
+
60
+ context "when queried with #organization_by_name" do
61
+ subject { client.organization_by_name(query_param) }
62
+
63
+ it "returns the org with the given name" do
64
+ expect(subject).to be_a CFoundry::V2::Organization
65
+ expect(subject.name).to eq query_param
66
+ end
67
+ end
68
+ end
69
+
70
+ context "when there are orgs but no matches" do
71
+ before do
72
+ client.base.stub(:organizations).and_return([non_matching_org])
73
+ end
74
+
75
+ context "when queried with #organizations" do
76
+ subject { client.organizations(:query => [:name, query_param]) }
77
+
78
+ it "returns an empty list" do
79
+ expect(subject).to be_empty
80
+ end
81
+ end
82
+
83
+ context "when queried with #organzations_by_name" do
84
+ subject { client.organizations_by_name(query_param) }
85
+
86
+ it "returns an empty list" do
87
+ expect(subject).to be_empty
88
+ end
89
+ end
90
+
91
+ context "when queried with #organization_by_name" do
92
+ subject { client.organization_by_name(query_param) }
93
+
94
+ it "returns nil" do
95
+ expect(subject).to be nil
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ context "when there are no orgs" do
102
+ before do
103
+ client.base.stub(:organizations).and_return([])
104
+ end
105
+
106
+ context "when queried with #organizations" do
107
+ subject { client.organizations(:query => [:name, query_param]) }
108
+
109
+ it "returns an empty list" do
110
+ expect(subject).to be_empty
111
+ end
112
+ end
113
+
114
+ context "when queried with #organzations_by_name" do
115
+ subject { client.organizations_by_name(query_param) }
116
+
117
+ it "returns an empty list" do
118
+ expect(subject).to be_empty
119
+ end
120
+ end
121
+
122
+ context "when queried with #organization_by_name" do
123
+ subject { client.organization_by_name(query_param) }
124
+
125
+ it "returns nil" do
126
+ expect(subject).to be nil
127
+ end
128
+ end
129
+
130
+ end
131
+ end
132
+ end
133
+
14
134
  it "has quota_definition" do
15
135
  quota = build(:quota_definition)
16
136
  organization.quota_definition = quota
@@ -49,6 +49,7 @@
49
49
  },
50
50
  "entity": {}
51
51
  }],
52
+ "billing_enabled": true,
52
53
  "quota_definition": {
53
54
  "metadata": {
54
55
  "guid": "quota-definition-id-1",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-03 00:00:00.000000000 Z
13
+ date: 2013-07-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -413,12 +413,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
413
413
  - - ! '>='
414
414
  - !ruby/object:Gem::Version
415
415
  version: '0'
416
+ segments:
417
+ - 0
418
+ hash: -4193450621271924723
416
419
  required_rubygems_version: !ruby/object:Gem::Requirement
417
420
  none: false
418
421
  requirements:
419
422
  - - ! '>='
420
423
  - !ruby/object:Gem::Version
421
424
  version: '0'
425
+ segments:
426
+ - 0
427
+ hash: -4193450621271924723
422
428
  requirements: []
423
429
  rubyforge_project: cfoundry
424
430
  rubygems_version: 1.8.25