cloud_search 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,8 +26,10 @@ module CloudSearch
26
26
  run_id_validations
27
27
  run_version_validations
28
28
  run_type_validations
29
- run_lang_validations
30
- run_fields_validations
29
+ if type == "add"
30
+ run_lang_validations
31
+ run_fields_validations
32
+ end
31
33
  errors.empty?
32
34
  end
33
35
 
@@ -1,3 +1,3 @@
1
1
  module CloudSearch
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -142,54 +142,74 @@ describe CloudSearch::Document do
142
142
  end
143
143
 
144
144
  context "lang validation" do
145
- it "is invalid if lang is nil" do
146
- document = described_class.new :lang => nil
147
- document.valid?
148
- expect(document.errors[:lang]).to eql(["can't be blank"])
149
- end
145
+ context "when type is 'add'" do
146
+ it "is invalid if lang is nil" do
147
+ document = described_class.new :lang => nil, :type => "add"
148
+ document.valid?
149
+ expect(document.errors[:lang]).to eql(["can't be blank"])
150
+ end
150
151
 
151
- it "is invalid if lang contains digits" do
152
- document = described_class.new :lang => "a1"
153
- document.valid?
154
- expect(document.errors[:lang]).to eql(["is invalid"])
155
- end
152
+ it "is invalid if lang contains digits" do
153
+ document = described_class.new :lang => "a1", :type => "add"
154
+ document.valid?
155
+ expect(document.errors[:lang]).to eql(["is invalid"])
156
+ end
156
157
 
157
- it "is invalid if lang contains more than 2 characters" do
158
- document = described_class.new :lang => "abc"
159
- document.valid?
160
- expect(document.errors[:lang]).to eql(["is invalid"])
161
- end
158
+ it "is invalid if lang contains more than 2 characters" do
159
+ document = described_class.new :lang => "abc", :type => "add"
160
+ document.valid?
161
+ expect(document.errors[:lang]).to eql(["is invalid"])
162
+ end
162
163
 
163
- it "is invalid if lang contains upper case characters" do
164
- document = described_class.new :lang => "Ab"
165
- document.valid?
166
- expect(document.errors[:lang]).to eql(["is invalid"])
164
+ it "is invalid if lang contains upper case characters" do
165
+ document = described_class.new :lang => "Ab", :type => "add"
166
+ document.valid?
167
+ expect(document.errors[:lang]).to eql(["is invalid"])
168
+ end
169
+
170
+ it "is valid if lang contains 2 lower case characters" do
171
+ document = described_class.new :lang => "en", :type => "add"
172
+ document.valid?
173
+ expect(document.errors[:lang]).to be_nil
174
+ end
167
175
  end
168
176
 
169
- it "is valid if lang contains 2 lower case characters" do
170
- document = described_class.new :lang => "en"
171
- document.valid?
172
- expect(document.errors[:lang]).to be_nil
177
+ context "when type is 'delete'" do
178
+ it "is optional" do
179
+ document = described_class.new :type => "delete"
180
+ document.valid?
181
+ expect(document.errors[:lang]).to be_nil
182
+ end
173
183
  end
174
184
  end
175
185
 
176
186
  context "fields validation" do
177
- it "is invalid if fields is nil" do
178
- document = described_class.new :fields => nil
179
- document.valid?
180
- expect(document.errors[:fields]).to eql(["can't be empty"])
181
- end
187
+ context "when type is 'add'" do
188
+ it "is invalid if fields is nil" do
189
+ document = described_class.new :fields => nil, :type => "add"
190
+ document.valid?
191
+ expect(document.errors[:fields]).to eql(["can't be empty"])
192
+ end
182
193
 
183
- it "is invalid if fields is not a hash" do
184
- document = described_class.new :fields => []
185
- document.valid?
186
- expect(document.errors[:fields]).to eql(["must be an instance of Hash"])
194
+ it "is invalid if fields is not a hash" do
195
+ document = described_class.new :fields => [], :type => "add"
196
+ document.valid?
197
+ expect(document.errors[:fields]).to eql(["must be an instance of Hash"])
198
+ end
199
+
200
+ it "is valid with a Hash" do
201
+ document = described_class.new :fields => {}, :type => "add"
202
+ document.valid?
203
+ expect(document.errors[:fields]).to be_nil
204
+ end
187
205
  end
188
206
 
189
- it "is valid with a Hash" do
190
- document = described_class.new :fields => {}
191
- document.valid?
192
- expect(document.errors[:fields]).to be_nil
207
+ context "when type is 'delete'" do
208
+ it "is optional" do
209
+ document = described_class.new :type => "delete"
210
+ document.valid?
211
+ expect(document.errors[:fields]).to be_nil
212
+ end
193
213
  end
194
214
  end
195
215
 
@@ -4,6 +4,6 @@ describe CloudSearch::InvalidDocument do
4
4
  let(:document) { CloudSearch::Document.new }
5
5
 
6
6
  it "has a message with the document errors" do
7
- expect(described_class.new(document).message).to eq("id: can't be blank; version: can't be blank; type: can't be blank; lang: can't be blank; fields: can't be empty")
7
+ expect(described_class.new(document).message).to eq("id: can't be blank; version: can't be blank; type: can't be blank")
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -175,18 +175,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
175
  - - ! '>='
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
- segments:
179
- - 0
180
- hash: 4455518161793254465
181
178
  required_rubygems_version: !ruby/object:Gem::Requirement
182
179
  none: false
183
180
  requirements:
184
181
  - - ! '>='
185
182
  - !ruby/object:Gem::Version
186
183
  version: '0'
187
- segments:
188
- - 0
189
- hash: 4455518161793254465
190
184
  requirements: []
191
185
  rubyforge_project:
192
186
  rubygems_version: 1.8.24
@@ -210,3 +204,4 @@ test_files:
210
204
  - spec/fixtures/vcr_cassettes/search/request/paginated_second_page.yml
211
205
  - spec/spec_helper.rb
212
206
  - spec/support/vcr.rb
207
+ has_rdoc: