endeca 1.3.8 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,10 +26,8 @@ module Endeca
26
26
  # Use the mappings hash to replace domain level query query_options with
27
27
  # their Endeca equivalent.
28
28
  def transform_query_options(query_options)
29
- # {"apartments" => true}
30
29
  query = query_options.symbolize_keys
31
- # {:apartments => true}
32
- query.each do |key, _|
30
+ query.keys.each do |key|
33
31
  if mapping = mappings[key]
34
32
  new_options = mapping.perform(query)
35
33
  query.delete(key)
@@ -1,5 +1,25 @@
1
1
  require File.join(File.dirname(__FILE__), %w[spec_helper])
2
2
 
3
+ class TestClass
4
+ def self.desire_it
5
+ desire 'mylib'
6
+ end
7
+ end
8
+
9
+ describe TestClass do
10
+ describe "#desire" do
11
+ it "should require lib" do
12
+ TestClass.should_receive(:require).with('mylib').and_return(true)
13
+ TestClass.desire_it
14
+ end
15
+
16
+ it "should rescue LoadError and return false" do
17
+ TestClass.should_receive(:require).with('mylib').and_raise(LoadError.new('mylib not found'))
18
+ TestClass.desire_it.should == false
19
+ end
20
+ end
21
+ end
22
+
3
23
  describe Array do
4
24
  describe "#to_endeca_params" do
5
25
  it "should join the elements with ampersand" do
@@ -30,6 +50,12 @@ describe Benchmark do
30
50
  Benchmark.ms.should == 1000
31
51
  end
32
52
  end
53
+
54
+ describe "for version < 1.8.7" do
55
+ it "should remove realtime method" do
56
+ #Object.should_receive(:ruby_version).and_return('1.8.6')
57
+ end
58
+ end
33
59
  end
34
60
 
35
61
  describe Hash do
@@ -44,13 +44,6 @@ describe Endeca::Breadcrumb do
44
44
  end
45
45
  end
46
46
 
47
- describe ".to_proc" do
48
- it "should call create" do
49
- Endeca::Breadcrumb.should_receive(:create).with(:obj)
50
- [:obj].map(&Endeca::Breadcrumb)
51
- end
52
- end
53
-
54
47
  describe '#==' do
55
48
  it "should compare Breadcrumbs by name" do
56
49
  doc_1, doc_2 = Endeca::Breadcrumb.new, Endeca::Breadcrumb.new
@@ -1,6 +1,3 @@
1
- require 'rubygems'
2
- require 'fake_web'
3
- require 'json'
4
1
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
5
2
 
6
3
  describe Endeca::Request do
@@ -30,10 +27,18 @@ describe Endeca::Request do
30
27
  @request.perform
31
28
  end
32
29
 
30
+ describe "get response" do
31
+ it "shouse raise RequestError on exception" do
32
+ Curl::Easy.stub!(:perform).and_raise("Error happened")
33
+ lambda {@request.perform}.should raise_error(Endeca::RequestError, "Error happened")
34
+ end
35
+ end
33
36
  describe "when successful" do
34
37
  before do
38
+ @response_json = "{\"foo\":\"bar\"}"
35
39
  @response_hash = {"foo" => "bar"}
36
- FakeWeb.register_uri(@path, :string => @response_hash.to_json)
40
+ @curl_obj = mock(:response_code => 200, :body_str => @response_json)
41
+ Curl::Easy.stub!(:perform).and_return(@curl_obj)
37
42
  end
38
43
 
39
44
  it "should return the parsed JSON of the response body" do
@@ -44,16 +49,25 @@ describe Endeca::Request do
44
49
  lambda { @request.perform }.should_not raise_error
45
50
  end
46
51
  end
47
-
52
+
48
53
  describe "when unsuccessful" do
49
54
  before do
50
- FakeWeb.register_uri(@path, :status => ['404', 'Not Found'])
55
+ @curl_obj = mock(:response_code => 404)
56
+ Curl::Easy.stub!(:perform).and_return(@curl_obj)
51
57
  end
52
-
58
+
53
59
  it "should raise an Endeca::RequestError" do
54
- lambda {@request.perform}.should raise_error(Endeca::RequestError, '404 "Not Found"')
60
+ lambda {@request.perform}.should raise_error(Endeca::RequestError, "404 HTTP Error")
55
61
  end
62
+
63
+ end
56
64
 
65
+ describe "Yajl parser" do
66
+ it "should return Endeca::RequestError when malformed JSON is returned" do
67
+ @curl_obj = mock(:response_code => 200, :body_str => "!@!@#@SDSD}")
68
+ Curl::Easy.stub!(:perform).and_return(@curl_obj)
69
+ lambda {@request.perform}.should raise_error(Endeca::RequestError)
70
+ end
57
71
  end
58
72
 
59
73
  describe "when the response contains an error hash" do
@@ -63,45 +77,34 @@ describe Endeca::Request do
63
77
  "methodResponse"=>
64
78
  {"fault"=>
65
79
  {"value"=>
66
- {"faultCode"=>"-1",
67
- "faultString"=> @error_message}}}}
68
- @error_request = Endeca::Request.new(@path)
69
- @error_request.stub!(:handle_response).and_return(@error_response)
80
+ {"faultCode"=>"-1", "faultString"=> @error_message}
81
+ }
82
+ }
83
+ }
84
+ @error_request = Endeca::Request.new(@path)
85
+ @error_request.stub!(:handle_response).and_return(@error_response)
70
86
  end
71
-
87
+
72
88
  it "should raise an Endeca::RequestError" do
73
89
  lambda { @error_request.perform }.should raise_error(Endeca::RequestError, @error_message)
74
90
  end
75
91
  end
76
92
 
77
- end
93
+ end # perform
78
94
 
79
95
  describe '#uri' do
80
-
81
96
  describe "with a hash of query options" do
82
-
83
97
  it "should append the query options onto the url" do
84
98
  query = {:foo => :bar}
85
- Endeca::Request.new(@path, query).uri.query.should == query.to_endeca_params
86
- end
87
-
88
- end
89
-
90
- describe "with a query with '/_/' in it" do
91
-
92
- it "should not insert the ? before the query" do
93
- query = "/Beds-2/Baths-3/Dishwasher/_/N=324432/Ne=listing?test=true"
94
- Endeca::Request.new(@path, query).uri.to_s.should == "#{@path}#{query}"
99
+ URI.parse(Endeca::Request.new(@path, query).uri).query.should == query.to_endeca_params
95
100
  end
96
-
97
101
  end
98
-
99
102
  end
100
103
 
101
104
  describe "with a string of query options" do
102
105
  it "should append the query options string onto the url" do
103
106
  query = 'N=56'
104
- Endeca::Request.new(@path, query).uri.query.should == query.to_endeca_params
107
+ URI.parse(Endeca::Request.new(@path, query).uri).query.should == query.to_endeca_params
105
108
  end
106
109
  end
107
110
  end
@@ -14,24 +14,6 @@ describe Endeca do
14
14
  Endeca.escape(query).should == 'N=5875%205922&Nf=geocode%7CGCLT%2026.121900,-80.143600%2032.18688&Nu=mgtcoid&Ns=searchonly%7C0%7C%7Cisapartment%7C1%7C%7Csortorder%7C0&Ntk=showapartment%7Cmgtcologodisplay&F=cityseopath%3A1%7Cmediummgtcologo%3A1%7Cmgtcodescription%3A1%7Cmgtcoid%3A1%7Cmgtcologo%3A1%7Cmgtcologodisplay%3A1%7Cmgtconame%3A1%7Cmsa_code%3A1%7Cpropertycity%3A1%7Cpropertystatelong%3A1%7Csmallmgtcologo%3A1%7Cwebtollfree%3A1%7Cmvtphone%3A1&Ntt=1%7C1&M=recs_per_page%3A99999%7Cexpand_all_dims%3A0'
15
15
 
16
16
  end
17
-
18
- describe "#get_timer" do
19
- it "without system_timer available returns Timeout" do
20
- Endeca.should_receive(:require).
21
- with('system_timer').and_raise(LoadError)
22
- Endeca.should_receive(:require).
23
- with('timeout').and_return(true)
24
-
25
- Endeca.send(:get_timer).should == Timeout
26
- end
27
-
28
- it "will return SystemTimer if available" do
29
- Endeca.should_receive(:require).
30
- with('system_timer').and_return(true)
31
-
32
- Endeca.send(:get_timer).should == SystemTimer
33
- end
34
- end
35
17
  end
36
18
 
37
19
  # EOF
metadata CHANGED
@@ -1,47 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: endeca
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.8
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - Rein Henrichs
8
- - Andy Stone
7
+ - Primedia Team
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2009-11-13 00:00:00 -05:00
12
+ date: 2010-02-19 00:00:00 -05:00
14
13
  default_executable:
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
- name: bones
16
+ name: rspec
18
17
  type: :development
19
18
  version_requirement:
20
19
  version_requirements: !ruby/object:Gem::Requirement
21
20
  requirements:
22
21
  - - ">="
23
22
  - !ruby/object:Gem::Version
24
- version: 2.4.0
23
+ version: "0"
25
24
  version:
26
- description: An Endeca client library for Ruby.
25
+ description:
27
26
  email: ""
28
27
  executables: []
29
28
 
30
29
  extensions: []
31
30
 
32
31
  extra_rdoc_files:
33
- - History.txt
34
- - Manifest.txt
35
32
  - README.rdoc
36
33
  files:
37
- - History.txt
34
+ - .gitignore
38
35
  - Manifest.txt
39
36
  - README.rdoc
40
37
  - Rakefile
41
38
  - endeca.gemspec
42
39
  - example/benchmark.rb
43
40
  - example/listing.rb
44
- - lib/class_to_proc.rb
45
41
  - lib/core_ext.rb
46
42
  - lib/endeca.rb
47
43
  - lib/endeca/benchmarking.rb
@@ -73,26 +69,13 @@ files:
73
69
  - spec/rcov.opts
74
70
  - spec/spec.opts
75
71
  - spec/spec_helper.rb
76
- - tasks/ann.rake
77
- - tasks/bones.rake
78
- - tasks/gem.rake
79
- - tasks/git.rake
80
- - tasks/notes.rake
81
- - tasks/post_load.rake
82
- - tasks/rdoc.rake
83
- - tasks/rubyforge.rake
84
- - tasks/setup.rb
85
- - tasks/spec.rake
86
- - tasks/svn.rake
87
- - tasks/test.rake
88
72
  has_rdoc: true
89
73
  homepage: http://github.com/primedia/endeca-ruby
90
74
  licenses: []
91
75
 
92
76
  post_install_message:
93
77
  rdoc_options:
94
- - --main
95
- - README.rdoc
78
+ - --charset=UTF-8
96
79
  require_paths:
97
80
  - lib
98
81
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -109,10 +92,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
92
  version:
110
93
  requirements: []
111
94
 
112
- rubyforge_project: endeca
95
+ rubyforge_project:
113
96
  rubygems_version: 1.3.5
114
97
  signing_key:
115
98
  specification_version: 3
116
- summary: An Endeca client library for Ruby
117
- test_files: []
118
-
99
+ summary: Endeca adapter for use with the Endeca Bridge
100
+ test_files:
101
+ - spec/endeca_spec.rb
102
+ - spec/core_ext_spec.rb
103
+ - spec/endeca/document_collection_spec.rb
104
+ - spec/endeca/readers_spec.rb
105
+ - spec/endeca/request_spec.rb
106
+ - spec/endeca/transformer_spec.rb
107
+ - spec/endeca/breadcrumb_spec.rb
108
+ - spec/endeca/document_spec.rb
109
+ - spec/endeca/refinement_spec.rb
110
+ - spec/endeca/map_spec.rb
111
+ - spec/endeca/refinement_dimension_spec.rb
112
+ - spec/endeca/dimension_spec.rb
113
+ - spec/endeca/benchmarking_spec.rb
114
+ - spec/spec_helper.rb
@@ -1,4 +0,0 @@
1
- == 0.1.0 / 2009-01-20
2
-
3
- * 1 major enhancement
4
- * Birthday!
@@ -1,5 +0,0 @@
1
- module ClassToProc
2
- def to_proc
3
- proc(&method(:new))
4
- end
5
- end
@@ -1,80 +0,0 @@
1
-
2
- begin
3
- require 'bones/smtp_tls'
4
- rescue LoadError
5
- require 'net/smtp'
6
- end
7
- require 'time'
8
-
9
- namespace :ann do
10
-
11
- # A prerequisites task that all other tasks depend upon
12
- task :prereqs
13
-
14
- file PROJ.ann.file do
15
- ann = PROJ.ann
16
- puts "Generating #{ann.file}"
17
- File.open(ann.file,'w') do |fd|
18
- fd.puts("#{PROJ.name} version #{PROJ.version}")
19
- fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
20
- fd.puts(" #{PROJ.url}") if PROJ.url.valid?
21
- fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
22
- fd.puts
23
- fd.puts("== DESCRIPTION")
24
- fd.puts
25
- fd.puts(PROJ.description)
26
- fd.puts
27
- fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
28
- fd.puts
29
- ann.paragraphs.each do |p|
30
- fd.puts "== #{p.upcase}"
31
- fd.puts
32
- fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
33
- fd.puts
34
- end
35
- fd.puts ann.text if ann.text
36
- end
37
- end
38
-
39
- desc "Create an announcement file"
40
- task :announcement => ['ann:prereqs', PROJ.ann.file]
41
-
42
- desc "Send an email announcement"
43
- task :email => ['ann:prereqs', PROJ.ann.file] do
44
- ann = PROJ.ann
45
- from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
46
- to = Array(ann.email[:to])
47
-
48
- ### build a mail header for RFC 822
49
- rfc822msg = "From: #{from}\n"
50
- rfc822msg << "To: #{to.join(',')}\n"
51
- rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
52
- rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
53
- rfc822msg << "\n"
54
- rfc822msg << "Date: #{Time.new.rfc822}\n"
55
- rfc822msg << "Message-Id: "
56
- rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
57
- rfc822msg << File.read(ann.file)
58
-
59
- params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
60
- ann.email[key]
61
- end
62
-
63
- params[3] = PROJ.email if params[3].nil?
64
-
65
- if params[4].nil?
66
- STDOUT.write "Please enter your e-mail password (#{params[3]}): "
67
- params[4] = STDIN.gets.chomp
68
- end
69
-
70
- ### send email
71
- Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
72
- end
73
- end # namespace :ann
74
-
75
- desc 'Alias to ann:announcement'
76
- task :ann => 'ann:announcement'
77
-
78
- CLOBBER << PROJ.ann.file
79
-
80
- # EOF
@@ -1,20 +0,0 @@
1
-
2
- if HAVE_BONES
3
-
4
- namespace :bones do
5
-
6
- desc 'Show the PROJ open struct'
7
- task :debug do |t|
8
- atr = if t.application.top_level_tasks.length == 2
9
- t.application.top_level_tasks.pop
10
- end
11
-
12
- if atr then Bones::Debug.show_attr(PROJ, atr)
13
- else Bones::Debug.show PROJ end
14
- end
15
-
16
- end # namespace :bones
17
-
18
- end # HAVE_BONES
19
-
20
- # EOF
@@ -1,201 +0,0 @@
1
-
2
- require 'find'
3
- require 'rake/packagetask'
4
- require 'rubygems/user_interaction'
5
- require 'rubygems/builder'
6
-
7
- module Bones
8
- class GemPackageTask < Rake::PackageTask
9
- # Ruby GEM spec containing the metadata for this package. The
10
- # name, version and package_files are automatically determined
11
- # from the GEM spec and don't need to be explicitly provided.
12
- #
13
- attr_accessor :gem_spec
14
-
15
- # Tasks from the Bones gem directory
16
- attr_reader :bones_files
17
-
18
- # Create a GEM Package task library. Automatically define the gem
19
- # if a block is given. If no block is supplied, then +define+
20
- # needs to be called to define the task.
21
- #
22
- def initialize(gem_spec)
23
- init(gem_spec)
24
- yield self if block_given?
25
- define if block_given?
26
- end
27
-
28
- # Initialization tasks without the "yield self" or define
29
- # operations.
30
- #
31
- def init(gem)
32
- super(gem.name, gem.version)
33
- @gem_spec = gem
34
- @package_files += gem_spec.files if gem_spec.files
35
- @bones_files = []
36
-
37
- local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
38
- if !test(?e, local_setup)
39
- Dir.glob(::Bones.path(%w[lib bones tasks *])).each {|fn| bones_files << fn}
40
- end
41
- end
42
-
43
- # Create the Rake tasks and actions specified by this
44
- # GemPackageTask. (+define+ is automatically called if a block is
45
- # given to +new+).
46
- #
47
- def define
48
- super
49
- task :prereqs
50
- task :package => ['gem:prereqs', "#{package_dir_path}/#{gem_file}"]
51
- file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files + bones_files do
52
- when_writing("Creating GEM") {
53
- chdir(package_dir_path) do
54
- Gem::Builder.new(gem_spec).build
55
- verbose(true) {
56
- mv gem_file, "../#{gem_file}"
57
- }
58
- end
59
- }
60
- end
61
-
62
- file package_dir_path => bones_files do
63
- mkdir_p package_dir rescue nil
64
-
65
- gem_spec.files = (gem_spec.files +
66
- bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
67
-
68
- bones_files.each do |fn|
69
- base_fn = File.join('tasks', File.basename(fn))
70
- f = File.join(package_dir_path, base_fn)
71
- fdir = File.dirname(f)
72
- mkdir_p(fdir) if !File.exist?(fdir)
73
- if File.directory?(fn)
74
- mkdir_p(f)
75
- else
76
- raise "file name conflict for '#{base_fn}' (conflicts with '#{fn}')" if test(?e, f)
77
- safe_ln(fn, f)
78
- end
79
- end
80
- end
81
- end
82
-
83
- def gem_file
84
- if @gem_spec.platform == Gem::Platform::RUBY
85
- "#{package_name}.gem"
86
- else
87
- "#{package_name}-#{@gem_spec.platform}.gem"
88
- end
89
- end
90
- end # class GemPackageTask
91
- end # module Bones
92
-
93
- namespace :gem do
94
-
95
- PROJ.gem._spec = Gem::Specification.new do |s|
96
- s.name = PROJ.name
97
- s.version = PROJ.version
98
- s.summary = PROJ.summary
99
- s.authors = Array(PROJ.authors)
100
- s.email = PROJ.email
101
- s.homepage = Array(PROJ.url).first
102
- s.rubyforge_project = PROJ.rubyforge.name
103
-
104
- s.description = PROJ.description
105
-
106
- PROJ.gem.dependencies.each do |dep|
107
- s.add_dependency(*dep)
108
- end
109
-
110
- PROJ.gem.development_dependencies.each do |dep|
111
- s.add_development_dependency(*dep)
112
- end
113
-
114
- s.files = PROJ.gem.files
115
- s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
116
- s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
117
-
118
- s.bindir = 'bin'
119
- dirs = Dir["{#{PROJ.libs.join(',')}}"]
120
- s.require_paths = dirs unless dirs.empty?
121
-
122
- incl = Regexp.new(PROJ.rdoc.include.join('|'))
123
- excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
124
- excl = Regexp.new(excl.join('|'))
125
- rdoc_files = PROJ.gem.files.find_all do |fn|
126
- case fn
127
- when excl; false
128
- when incl; true
129
- else false end
130
- end
131
- s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
132
- s.extra_rdoc_files = rdoc_files
133
- s.has_rdoc = true
134
-
135
- if test ?f, PROJ.test.file
136
- s.test_file = PROJ.test.file
137
- else
138
- s.test_files = PROJ.test.files.to_a
139
- end
140
-
141
- # Do any extra stuff the user wants
142
- PROJ.gem.extras.each do |msg, val|
143
- case val
144
- when Proc
145
- val.call(s.send(msg))
146
- else
147
- s.send "#{msg}=", val
148
- end
149
- end
150
- end # Gem::Specification.new
151
-
152
- Bones::GemPackageTask.new(PROJ.gem._spec) do |pkg|
153
- pkg.need_tar = PROJ.gem.need_tar
154
- pkg.need_zip = PROJ.gem.need_zip
155
- end
156
-
157
- desc 'Show information about the gem'
158
- task :debug => 'gem:prereqs' do
159
- puts PROJ.gem._spec.to_ruby
160
- end
161
-
162
- desc 'Write the gemspec '
163
- task :spec => 'gem:prereqs' do
164
- File.open("#{PROJ.name}.gemspec", 'w') do |f|
165
- f.write PROJ.gem._spec.to_ruby
166
- end
167
- end
168
-
169
- desc 'Install the gem'
170
- task :install => [:clobber, 'gem:package'] do
171
- sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
172
-
173
- # use this version of the command for rubygems > 1.0.0
174
- #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
175
- end
176
-
177
- desc 'Uninstall the gem'
178
- task :uninstall do
179
- installed_list = Gem.source_index.find_name(PROJ.name)
180
- if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
181
- sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
182
- end
183
- end
184
-
185
- desc 'Reinstall the gem'
186
- task :reinstall => [:uninstall, :install]
187
-
188
- desc 'Cleanup the gem'
189
- task :cleanup do
190
- sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
191
- end
192
- end # namespace :gem
193
-
194
-
195
- desc 'Alias to gem:package'
196
- task :gem => 'gem:package'
197
-
198
- task :clobber => 'gem:clobber_package'
199
- remove_desc_for_task 'gem:clobber_package'
200
-
201
- # EOF