neuron-client 0.2.6 → 0.3.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 (116) hide show
  1. data/README.md +11 -8
  2. data/lib/neuron-client/api.rb +5 -0
  3. data/lib/neuron-client/model/ad.rb +142 -0
  4. data/lib/neuron-client/model/ad_calculations.rb +325 -0
  5. data/lib/neuron-client/model/ad_zone.rb +45 -0
  6. data/lib/neuron-client/model/base.rb +233 -18
  7. data/lib/neuron-client/model/blocked_referer.rb +20 -0
  8. data/lib/neuron-client/model/blocked_user_agent.rb +21 -0
  9. data/lib/neuron-client/model/geo_target.rb +36 -0
  10. data/lib/neuron-client/model/pixel.rb +22 -0
  11. data/lib/neuron-client/model/report.rb +35 -0
  12. data/lib/neuron-client/model/s3_file.rb +30 -0
  13. data/lib/neuron-client/model/zone.rb +64 -0
  14. data/lib/neuron-client/model/zone_calculations.rb +37 -0
  15. data/lib/neuron-client/schema/ad.rb +406 -0
  16. data/lib/neuron-client/schema/ad_zone.rb +49 -0
  17. data/lib/neuron-client/schema/blocked_referer.rb +52 -0
  18. data/lib/neuron-client/schema/blocked_user_agent.rb +64 -0
  19. data/lib/neuron-client/schema/common.rb +220 -0
  20. data/lib/neuron-client/schema/event.rb +17 -0
  21. data/lib/neuron-client/schema/geo_target.rb +33 -0
  22. data/lib/neuron-client/schema/pixel.rb +39 -0
  23. data/lib/neuron-client/schema/report.rb +59 -0
  24. data/lib/neuron-client/schema/s3_file.rb +87 -0
  25. data/lib/neuron-client/schema/zone.rb +214 -0
  26. data/lib/neuron-client/version.rb +1 -1
  27. data/lib/neuron-client.rb +24 -59
  28. data/neuron-client.gemspec +3 -0
  29. data/spec/lib/admin_connection_spec.rb +234 -0
  30. data/spec/lib/api_spec.rb +41 -63
  31. data/spec/lib/model/ad_calculations_spec.rb +1146 -0
  32. data/spec/lib/model/ad_spec.rb +253 -0
  33. data/spec/lib/model/ad_zone_spec.rb +15 -0
  34. data/spec/lib/model/base_spec.rb +5 -83
  35. data/spec/lib/model/blocked_referer_spec.rb +36 -0
  36. data/spec/lib/model/blocked_user_agent_spec.rb +36 -0
  37. data/spec/lib/model/geo_target_spec.rb +28 -0
  38. data/spec/lib/model/pixel_spec.rb +36 -0
  39. data/spec/lib/model/report_spec.rb +17 -0
  40. data/spec/lib/{s3_file_spec.rb → model/s3_file_spec.rb} +6 -5
  41. data/spec/lib/model/zone_calculations_spec.rb +49 -0
  42. data/spec/lib/model/zone_spec.rb +155 -0
  43. data/spec/lib/schema/ad_spec.rb +515 -0
  44. data/spec/lib/schema/ad_zone_spec.rb +149 -0
  45. data/spec/lib/schema/blocked_referer_spec.rb +136 -0
  46. data/spec/lib/schema/blocked_user_agent_spec.rb +147 -0
  47. data/spec/lib/schema/geo_target_spec.rb +92 -0
  48. data/spec/lib/schema/pixel_spec.rb +125 -0
  49. data/spec/lib/schema/report_spec.rb +129 -0
  50. data/spec/lib/schema/s3_file_spec.rb +164 -0
  51. data/spec/lib/schema/zone_spec.rb +243 -0
  52. data/spec/spec_helper.rb +2 -1
  53. metadata +141 -121
  54. data/lib/neuron-client/model/admin/ad.rb +0 -22
  55. data/lib/neuron-client/model/admin/ad_zone.rb +0 -15
  56. data/lib/neuron-client/model/admin/base.rb +0 -91
  57. data/lib/neuron-client/model/admin/blocked_referer.rb +0 -12
  58. data/lib/neuron-client/model/admin/blocked_user_agent.rb +0 -12
  59. data/lib/neuron-client/model/admin/geo_target.rb +0 -16
  60. data/lib/neuron-client/model/admin/pixel.rb +0 -12
  61. data/lib/neuron-client/model/admin/report.rb +0 -15
  62. data/lib/neuron-client/model/admin/s3_file.rb +0 -12
  63. data/lib/neuron-client/model/admin/zone.rb +0 -15
  64. data/lib/neuron-client/model/common/ad.rb +0 -42
  65. data/lib/neuron-client/model/common/ad_calculations.rb +0 -329
  66. data/lib/neuron-client/model/common/ad_zone.rb +0 -17
  67. data/lib/neuron-client/model/common/base.rb +0 -67
  68. data/lib/neuron-client/model/common/blocked_referer.rb +0 -16
  69. data/lib/neuron-client/model/common/blocked_user_agent.rb +0 -16
  70. data/lib/neuron-client/model/common/geo_target.rb +0 -16
  71. data/lib/neuron-client/model/common/pixel.rb +0 -18
  72. data/lib/neuron-client/model/common/report.rb +0 -21
  73. data/lib/neuron-client/model/common/s3_file.rb +0 -16
  74. data/lib/neuron-client/model/common/zone.rb +0 -22
  75. data/lib/neuron-client/model/common/zone_calculations.rb +0 -41
  76. data/lib/neuron-client/model/membase/ad.rb +0 -49
  77. data/lib/neuron-client/model/membase/ad_zone.rb +0 -11
  78. data/lib/neuron-client/model/membase/blocked_referer.rb +0 -20
  79. data/lib/neuron-client/model/membase/blocked_user_agent.rb +0 -20
  80. data/lib/neuron-client/model/membase/geo_target.rb +0 -11
  81. data/lib/neuron-client/model/membase/pixel.rb +0 -22
  82. data/lib/neuron-client/model/membase/report.rb +0 -11
  83. data/lib/neuron-client/model/membase/s3_file.rb +0 -11
  84. data/lib/neuron-client/model/membase/zone.rb +0 -30
  85. data/lib/neuron-client/model/models.rb +0 -15
  86. data/spec/lib/model/admin/ad_spec.rb +0 -34
  87. data/spec/lib/model/admin/ad_zone_spec.rb +0 -19
  88. data/spec/lib/model/admin/base_spec.rb +0 -11
  89. data/spec/lib/model/admin/blocked_referer_spec.rb +0 -11
  90. data/spec/lib/model/admin/blocked_user_agent_spec.rb +0 -11
  91. data/spec/lib/model/admin/geo_target_spec.rb +0 -30
  92. data/spec/lib/model/admin/report_spec.rb +0 -21
  93. data/spec/lib/model/admin/s3_spec.rb +0 -11
  94. data/spec/lib/model/admin/zone_spec.rb +0 -21
  95. data/spec/lib/model/common/ad_calculations_spec.rb +0 -1151
  96. data/spec/lib/model/common/ad_spec.rb +0 -11
  97. data/spec/lib/model/common/ad_zone_spec.rb +0 -11
  98. data/spec/lib/model/common/base_spec.rb +0 -11
  99. data/spec/lib/model/common/blocked_referer_spec.rb +0 -11
  100. data/spec/lib/model/common/blocked_user_agent_spec.rb +0 -11
  101. data/spec/lib/model/common/geo_target_spec.rb +0 -11
  102. data/spec/lib/model/common/report_spec.rb +0 -11
  103. data/spec/lib/model/common/s3_spec.rb +0 -11
  104. data/spec/lib/model/common/zone_calculations_spec.rb +0 -54
  105. data/spec/lib/model/common/zone_spec.rb +0 -11
  106. data/spec/lib/model/membase/ad_spec.rb +0 -54
  107. data/spec/lib/model/membase/ad_zone_spec.rb +0 -11
  108. data/spec/lib/model/membase/base_spec.rb +0 -11
  109. data/spec/lib/model/membase/blocked_referer_spec.rb +0 -34
  110. data/spec/lib/model/membase/blocked_user_agent_spec.rb +0 -34
  111. data/spec/lib/model/membase/geo_target_spec.rb +0 -11
  112. data/spec/lib/model/membase/pixel_spec.rb +0 -34
  113. data/spec/lib/model/membase/report_spec.rb +0 -11
  114. data/spec/lib/model/membase/s3_spec.rb +0 -11
  115. data/spec/lib/model/membase/zone_spec.rb +0 -32
  116. data/spec/lib/old_spec.rb +0 -437
data/lib/neuron-client.rb CHANGED
@@ -2,52 +2,40 @@ require "rubygems"
2
2
  require "tzinfo"
3
3
  require "active_support" #TODO: when we upgrade to 3.x, this can be "active_support/core_ext"
4
4
  require "active_support/core_ext"
5
+ require "json-schema"
5
6
  require "neuron-client/version"
6
7
  require "neuron-client/admin_connection"
7
8
  require "neuron-client/membase_connection"
8
9
  require "neuron-client/api"
9
10
 
10
- require "neuron-client/model/common/base"
11
- require "neuron-client/model/common/ad_calculations"
12
- require "neuron-client/model/common/ad"
13
- require "neuron-client/model/common/ad_zone"
14
- require "neuron-client/model/common/blocked_referer"
15
- require "neuron-client/model/common/blocked_user_agent"
16
- require "neuron-client/model/common/geo_target"
17
- require "neuron-client/model/common/pixel"
18
- require "neuron-client/model/common/report"
19
- require "neuron-client/model/common/s3_file"
20
- require "neuron-client/model/common/zone_calculations"
21
- require "neuron-client/model/common/zone"
22
-
23
- require "neuron-client/model/admin/base"
24
- require "neuron-client/model/admin/ad"
25
- require "neuron-client/model/admin/ad_zone"
26
- require "neuron-client/model/admin/blocked_referer"
27
- require "neuron-client/model/admin/blocked_user_agent"
28
- require "neuron-client/model/admin/geo_target"
29
- require "neuron-client/model/admin/pixel"
30
- require "neuron-client/model/admin/report"
31
- require "neuron-client/model/admin/s3_file"
32
- require "neuron-client/model/admin/zone"
33
-
34
- require "neuron-client/model/membase/ad"
35
- require "neuron-client/model/membase/ad_zone"
36
- require "neuron-client/model/membase/blocked_referer"
37
- require "neuron-client/model/membase/blocked_user_agent"
38
- require "neuron-client/model/membase/geo_target"
39
- require "neuron-client/model/membase/pixel"
40
- require "neuron-client/model/membase/report"
41
- require "neuron-client/model/membase/s3_file"
42
- require "neuron-client/model/membase/zone"
43
-
44
11
  require "neuron-client/model/base"
45
- require "neuron-client/model/models"
12
+ require "neuron-client/model/ad_calculations"
13
+ require "neuron-client/model/ad"
14
+ require "neuron-client/model/ad_zone"
15
+ require "neuron-client/model/blocked_referer"
16
+ require "neuron-client/model/blocked_user_agent"
17
+ require "neuron-client/model/geo_target"
18
+ require "neuron-client/model/pixel"
19
+ require "neuron-client/model/report"
20
+ require "neuron-client/model/s3_file"
21
+ require "neuron-client/model/zone_calculations"
22
+ require "neuron-client/model/zone"
23
+
24
+ require "neuron-client/schema/common.rb"
25
+ require "neuron-client/schema/ad.rb"
26
+ require "neuron-client/schema/ad_zone.rb"
27
+ require "neuron-client/schema/blocked_referer.rb"
28
+ require "neuron-client/schema/blocked_user_agent.rb"
29
+ require "neuron-client/schema/geo_target.rb"
30
+ require "neuron-client/schema/pixel.rb"
31
+ require "neuron-client/schema/report.rb"
32
+ require "neuron-client/schema/s3_file.rb"
33
+ require "neuron-client/schema/zone.rb"
46
34
 
47
35
  class Object
48
36
  def blank?
49
37
  return true if self.nil?
50
- return true if self.respond_to?(:empty) && self.empty?
38
+ return true if self.respond_to?(:empty?) && self.empty?
51
39
  false
52
40
  end
53
41
 
@@ -55,26 +43,3 @@ class Object
55
43
  !self.blank?
56
44
  end
57
45
  end
58
-
59
- # lifted completely from the ruby facets gem source:
60
- # /lib/core-uncommon/facets/module/cattr.rb
61
- def Module
62
- def cattr_writer(*syms)
63
- syms.flatten.each do |sym|
64
- module_eval(<<-EOS, __FILE__, __LINE__)
65
- unless defined? @@#{sym}
66
- @@#{sym} = nil
67
- end
68
-
69
- def self.#{sym}=(obj)
70
- @@#{sym} = obj
71
- end
72
-
73
- def #{sym}=(obj)
74
- @@#{sym}=(obj)
75
- end
76
- EOS
77
- end
78
- return syms
79
- end
80
- end
@@ -24,6 +24,9 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency "i18n", ">= 0.5.0", "< 0.7"
25
25
  s.add_dependency "dalli", ">= 1.0.5", "< 1.2"
26
26
  s.add_dependency "lrucache", "~> 0.1.0"
27
+ s.add_dependency "map", ">= 4.2.0", "< 5"
28
+ s.add_dependency "deep_merge", "~> 1.0.0"
29
+ s.add_dependency "json-schema", "~> 0.9.12"
27
30
 
28
31
  s.add_development_dependency "rspec", "~> 2.7.0"
29
32
  s.add_development_dependency "simplecov", "~> 0.5.4"
@@ -1,5 +1,239 @@
1
1
  module Neuron
2
+ module Schema
3
+ class TestModel
4
+ SCHEMA = self.new
5
+ def index; {}; end
6
+ def show; {}; end
7
+ def create; {} end
8
+ def update; {} end
9
+ end
10
+ end
2
11
  module Client
12
+ class TestModel
13
+ include Base
14
+ def attributes
15
+ []
16
+ end
17
+ end
18
+
19
+ describe AdminConnection do
20
+ before(:each) do
21
+ @connection = stub(:connection)
22
+ API.stub(:default_api).and_return(stub(:default_api, :connection => @connection, :connection_type => :admin, :validate? => true))
23
+ end
24
+
25
+ describe "update_attributes" do
26
+ it "should return false when errors occur for updated objects" do
27
+ @connection.should_receive(:put).with("test_models/1", {'test_model' => {}}) do
28
+ throw :errors, {:error => "is required"}
29
+ end
30
+
31
+ TestModel.new(:id => 1).update_attributes({}).should be_false
32
+ end
33
+
34
+ it "should provide access to errors when validation fails" do
35
+ @connection.should_receive(:put).with("test_models/1", {'test_model' => {}}) do
36
+ throw :errors, {:error => "is required"}
37
+ end
38
+
39
+ c = TestModel.new(:id => 1)
40
+ c.update_attributes({}).should be_false
41
+ c.errors.should == {:error => "is required"}
42
+ end
43
+
44
+ it "should return true when errors do not occur for updated objects" do
45
+ @connection.should_receive(:put).with("test_models/1", {'test_model' => {}}).and_return({'test_model' => {}})
46
+
47
+ TestModel.new(:id => 1).update_attributes({}).should be_true
48
+ end
49
+ end
50
+
51
+ describe "save" do
52
+ it "should return false when errors occur for new objects" do
53
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}) do
54
+ throw :errors, {:error => "is required"}
55
+ end
56
+
57
+ TestModel.new.save.should be_false
58
+ end
59
+
60
+ it "should provide access to errors when validation fails" do
61
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}) do
62
+ throw :errors, {:error => "is required"}
63
+ end
64
+
65
+ c = TestModel.new
66
+ c.save.should be_false
67
+ c.errors.should == {:error => "is required"}
68
+ end
69
+
70
+ it "should return true when errors do not occur for new objects" do
71
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}).and_return({'test_model' => {:id => 1}})
72
+
73
+ TestModel.new.save.should be_true
74
+ end
75
+
76
+ it "should return false when errors occur for existing objects" do
77
+ @connection.should_receive(:put).with('test_models/1', {'test_model' => {}}) do
78
+ throw :errors, {:error => "is required"}
79
+ end
80
+
81
+ TestModel.new(:id => 1).save.should be_false
82
+ end
83
+
84
+ it "should provide access to errors when validation fails" do
85
+ @connection.should_receive(:put).with("test_models/1", {'test_model' => {}}) do
86
+ throw :errors, {:error => "is required"}
87
+ end
88
+
89
+ c = TestModel.new(:id => 1)
90
+ c.save.should be_false
91
+ c.errors.should == {:error => "is required"}
92
+ end
93
+
94
+ it "should return true when errors do not occur for existing objects" do
95
+ @connection.should_receive(:put).with("test_models/1", {'test_model' => {}}).and_return({'test_model' => {:id => 1}})
96
+
97
+ TestModel.new(:id => 1).save.should be_true
98
+ end
99
+ end
100
+
101
+ describe "create" do
102
+ it "should return nil when errors occur" do
103
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}) do
104
+ throw :errors, {:error => "is_required"}
105
+ end
106
+
107
+ TestModel.create({}).should be_nil
108
+ end
109
+
110
+ it "should return the created object when no errors occur" do
111
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}).and_return({'test_model' => {:id => 1}})
112
+
113
+ TestModel.create({}).should be_a TestModel
114
+ end
115
+ end
116
+
117
+ describe "create!" do
118
+ it "should return nil when errors occur" do
119
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}) do
120
+ throw :errors, {:error => "is_required"}
121
+ end
122
+
123
+ errors = catch(:errors) do
124
+ TestModel.create!({})
125
+ nil
126
+ end
127
+ errors.should_not be_nil
128
+ errors.should == {:error => 'is_required'}
129
+ end
130
+
131
+ it "should return the created object when no errors occur" do
132
+ @connection.should_receive(:post).with("test_models", {'test_model' => {}}).and_return({'test_model' => {:id => 1}})
133
+
134
+ TestModel.create!({}).should be_a TestModel
135
+ end
136
+ end
137
+ end
138
+
139
+ describe AdminConnection do
140
+ before(:each) do
141
+ @connection = AdminConnection.new('http://neuron.admin', "my_api_key")
142
+ end
143
+
144
+ it "should escape the passed api_key" do
145
+ connection = AdminConnection.new("http://neuron.admin", "an unescaped string")
146
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=an+unescaped+string", :body => Yajl.dump({"escaped" => true}))
147
+ connection.get("test").should == {"escaped" => true}
148
+ end
149
+
150
+ describe "get" do
151
+ it "should make a GET request to the specified url passing an API key" do
152
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
153
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}")
154
+ @connection.get("test").should == {}
155
+ end
156
+
157
+ it "should GET an error if the wrong api_key is passed" do
158
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}")
159
+ FakeWeb.register_uri(:get, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
160
+ lambda do
161
+ @connection.get("test")
162
+ end.should raise_error
163
+ end
164
+ end
165
+
166
+ describe "post" do
167
+ it "should make a POST request to the specified url passing an API key" do
168
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
169
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}", :status => ["201", "Created"])
170
+ @connection.post("test", {:data => 1}).should == {}
171
+ end
172
+
173
+ it "should POST an error if the wrong api_key is passed" do
174
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}", :status => ["201", "Created"])
175
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
176
+ lambda do
177
+ @connection.post("test", {:data => 1})
178
+ end.should raise_error
179
+ end
180
+
181
+ it "should throw :errors if validation fails" do
182
+ FakeWeb.register_uri(:post, "http://neuron.admin/test.json?api_key=my_api_key", :body => Yajl.dump({:my_field => 'is_required'}), :status => ["422", "Errors"])
183
+ errors = catch(:errors) do
184
+ value = @connection.post("test", {:data => 1})
185
+ nil
186
+ end
187
+ errors.should_not be_nil
188
+ errors.should == {'my_field' => 'is_required'}
189
+ end
190
+ end
191
+
192
+ describe "put" do
193
+ it "should make a PUT request to the specified url passing an API key" do
194
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
195
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}")
196
+ @connection.put("test", {:data => 1}).should == {}
197
+ end
198
+
199
+ it "should PUT an error if the wrong api_key is passed" do
200
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}")
201
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
202
+ lambda do
203
+ @connection.put("test", {:data => 1})
204
+ end.should raise_error
205
+ end
206
+
207
+ it "should throw :errors if validation fails" do
208
+ FakeWeb.register_uri(:put, "http://neuron.admin/test.json?api_key=my_api_key", :body => Yajl.dump({:my_field => 'is_required'}), :status => ["422", "Errors"])
209
+ errors = catch(:errors) do
210
+ value = @connection.put("test", {:data => 1})
211
+ nil
212
+ end
213
+ errors.should_not be_nil
214
+ errors.should == {'my_field' => 'is_required'}
215
+ end
216
+ end
217
+
218
+ describe "delete" do
219
+ it "should make a DELETE request to the specified url passing an API key" do
220
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json", :body => "ERROR", :status => ["403", "Unauthorized"])
221
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json?api_key=my_api_key", :body => "{}")
222
+ @connection.delete("test").should == {}
223
+ end
224
+
225
+ it "should DELETE an error if the wrong api_key is passed" do
226
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json?api_key=new_api_key", :body => "{}")
227
+ FakeWeb.register_uri(:delete, "http://neuron.admin/test.json?api_key=my_api_key", :body => "ERROR", :status => ["403", "Unauthorized"])
228
+ lambda do
229
+ @connection.delete("test")
230
+ end.should raise_error
231
+ end
232
+ end
233
+ end
234
+
235
+
236
+
3
237
  describe AdminConnection do
4
238
 
5
239
  def stub_rest_client(receive, with_args, yield_args)
data/spec/lib/api_spec.rb CHANGED
@@ -1,80 +1,58 @@
1
1
  module Neuron
2
2
  module Client
3
3
  describe API do
4
- describe "configure" do
5
- context "when connection_type is :admin" do
6
- it "should call the expected methods" do
7
- a = API.new
8
- c = stub(:config)
9
- a.should_receive(:config).exactly(4).times.and_return(c)
10
- c.should_receive(:connection_type=).with(:admin)
11
- a.should_receive(:inclusion).with(c, :connection_type, [:admin, :membase])
12
- c.should_receive(:connection_type).exactly(2).times.and_return(:admin)
13
- a.should_receive(:configure_admin_connection)
14
4
 
15
- a.configure do |conf|
16
- conf.connection_type = :admin
17
- end
5
+ describe "configure" do
6
+ it "creates a valid AdminConnection object" do
7
+ api = API.new
8
+ api.connection.should be_nil
9
+ api.configure do |config|
10
+ config.connection_type = :admin
11
+ config.admin_url = "https://example.com"
12
+ config.admin_key = "secret"
18
13
  end
14
+ api.connection.should be_a(AdminConnection)
19
15
  end
20
- context "when connection_type is :membase" do
21
- it "should call the expected methods" do
22
- a = API.new
23
- c = stub(:config)
24
- a.should_receive(:config).exactly(4).times.and_return(c)
25
- c.should_receive(:connection_type=).with(:membase)
26
- a.should_receive(:inclusion).with(c, :connection_type, [:admin, :membase])
27
- c.should_receive(:connection_type).exactly(2).times.and_return(:membase)
28
- a.should_receive(:configure_membase_connection)
29
16
 
30
- a.configure do |conf|
31
- conf.connection_type = :membase
32
- end
17
+ it "creates a valid MembaseConnection object" do
18
+ api = API.new
19
+ api.connection.should be_nil
20
+ api.configure do |config|
21
+ config.connection_type = :membase
22
+ config.membase_servers = '127.0.0.1:11211'
23
+ config.local_cache_size = 1000,
24
+ config.local_cache_expires = 60
33
25
  end
26
+ api.connection.should be_a(MembaseConnection)
34
27
  end
35
- end
36
-
37
- describe "connection_type" do
38
- it "should return the expected value"
39
- end
40
-
41
- describe "config" do
42
- it "should return the expected value"
43
- end
44
-
45
- describe "required(obj, attrib)" do
46
- context "when val is nil" do
47
- it "should call the expected methods and raise an error"
48
- end
49
- context "when val is not nil and val.empty? does not exist" do
50
- it "should call the expected methods and not raise an error"
51
- end
52
- context "when val is not nil and val.empty? exists and returns true" do
53
- it "should call the expected methods and raise an error"
54
- end
55
- end
56
28
 
57
- describe "inclusion(obj, attrib, valid_values)" do
58
- context "when valid_values includes the attribute value" do
59
- it "should not raise an error"
60
- end
61
- context "when valid_values does not include the attribute value" do
62
- it "should raise an error"
29
+ it "raises an exception when given an admin_url that is not a URL" do
30
+ api = API.new
31
+ expect do
32
+ api.configure do |config|
33
+ config.connection_type = :admin
34
+ config.admin_url = "not a url"
35
+ config.admin_key = "secret"
36
+ end
37
+ end.to raise_exception
63
38
  end
64
- end
65
39
 
66
- describe "configure_admin_connection" do
67
- context "when URI.parse raises an error" do
68
- it "should raise a custom error"
69
- end
70
- context "when URI.parse does not raise an error" do
71
- it "should call the expected methods"
40
+ it "turns on validations by default" do
41
+ api = API.new
42
+ api.validate?.should be_true
43
+ api.configure do |config|
44
+ config.connection_type = :admin
45
+ config.admin_url = "https://example.com"
46
+ config.admin_key = "secret"
47
+ config.validate = true
48
+ end
49
+ api.validate?.should be_true
50
+ api.configure do |config|
51
+ config.validate = false
52
+ end
53
+ api.validate?.should be_false
72
54
  end
73
55
  end
74
-
75
- describe "configure_membase_connection" do
76
- it "should call the expected methods"
77
- end
78
56
  end
79
57
  end
80
58
  end