Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Updated SDK #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tmp
.yardoc
_yardoc
doc/
.DS_Store
57 changes: 57 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
PATH
remote: .
specs:
cloudsearchable (0.0.3)
aws-sdk (~> 2)

GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.4)
activesupport (= 4.2.4)
builder (~> 3.1)
activesupport (4.2.4)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
aws-sdk (2.1.29)
aws-sdk-resources (= 2.1.29)
aws-sdk-core (2.1.29)
jmespath (~> 1.0)
aws-sdk-resources (2.1.29)
aws-sdk-core (= 2.1.29)
builder (3.2.2)
diff-lcs (1.2.5)
i18n (0.7.0)
jmespath (1.1.3)
json (1.8.3)
minitest (5.8.1)
rake (10.4.2)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.4)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
yard (0.8.7.6)

PLATFORMS
ruby

DEPENDENCIES
activemodel
bundler (~> 1.3)
cloudsearchable!
rake
rspec (~> 2)
yard

BUNDLED WITH
1.10.6
2 changes: 1 addition & 1 deletion cloudsearchable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "yard"
spec.add_dependency 'aws-sdk-v1'
spec.add_dependency "aws-sdk", "~> 2"

# testing dependencies
spec.add_development_dependency "rspec", '~> 2'
Expand Down
6 changes: 3 additions & 3 deletions lib/cloudsearchable/cloud_search.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'aws-sdk-v1'
require 'aws-sdk'
require 'json'

module CloudSearch
API_VERSION = "2011-02-01"
API_VERSION = "2013-01-01"

def self.client
@client ||= AWS::CloudSearch::Client.new
@client ||= Aws::CloudSearch::Client.new
end

def self.client=(client)
Expand Down
4 changes: 2 additions & 2 deletions spec/cloudsearchable/cloud_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def initialize; end
let(:success_response){ MockHTTPOK.new( {"status" => "success", "adds" => 1, "deletes" => 0}.to_json ) }

it 'json parses the response' do
Net::HTTP.any_instance.stub(:start).and_return{success_response}
Net::HTTP.any_instance.stub(:start).and_return(success_response)

response = described_class.post_sdf endpoint, sdf_document
response.should eq JSON.parse success_response.body
end

it 'triggers error! on response its no not a Net::HTTPSuccess' do
response = MockHTTPBadRequest.new
Net::HTTP.any_instance.stub(:start).and_return{response}
Net::HTTP.any_instance.stub(:start).and_return(response)

response.should_receive(:error!)
described_class.post_sdf endpoint, sdf_document
Expand Down
11 changes: 6 additions & 5 deletions spec/cloudsearchable/cloudsearchable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
it 'can describe an index that returns ids for the class type' do
test_index = clazz.cloudsearch_index
test_index.should be_kind_of(Cloudsearchable::Domain)
test_index.fields.should have(4).items #3 explicit + 1 for the id of the object
# test_index.fields.should have(4).items #3 explicit + 1 for the id of the object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the comment to the new line, and remove the commented-out line of code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this comment. Sorry, I have removed the comment. I didn't mean to commit with the comment. I only had it during testing the change as reference.

expect(test_index.fields.size).to eq(4)
end

it 'has a default index' do
clazz.cloudsearch_index.should be_kind_of(Cloudsearchable::Domain)
clazz.cloudsearch_index(:test_index).should_not be(clazz.cloudsearch_index)
end

it 'names domains consistent with CloudSearch limitations' do
clazz.cloudsearch_index(:test_index).name.should =~ /^[a-z][a-z0-9\-]+$/
end
Expand All @@ -39,13 +40,13 @@
test_index.fields[:test_name].value_for(inst).should be(inst.name)
test_index.fields[:helpfulness].value_for(inst).should be(1234)
end

it 'reindexes when told to' do
clazz.cloudsearch_index( ).should_receive(:post_record).with(inst, inst.id, inst.lock_version)
clazz.cloudsearch_index(:test_index).should_receive(:post_record).with(inst, inst.id, inst.lock_version)
inst.update_indexes
end

it 'generates a sensible addition sdf document' do
sdf = clazz.cloudsearch_index.send :addition_sdf, inst, inst.id, inst.lock_version
sdf[:fields][:helpfulness].should be(1234)
Expand Down
6 changes: 5 additions & 1 deletion spec/cloudsearchable/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require 'ostruct'

describe Cloudsearchable::Field do
before(:each) do
ENV['AWS_REGION'] = 'us-test-1'
end

it 'has a name' do
field = described_class.new 'fnord', :literal
field.name.should eq(:fnord)
Expand All @@ -23,7 +27,7 @@
field = described_class.new('fnord', :literal, :search_enabled => true)
CloudSearch.client.should_receive(:define_index_field) do |call|
call[:domain_name].should eq(domain_name)
call[:index_field][:literal_options][:search_enabled].should be_true
call[:index_field][:literal_options][:search_enabled].should be_truthy
end
field.define_in_domain domain_name
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
require 'cloudsearchable'

RSpec.configure do |config|
end
end