soulheart 0.0.1

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.
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soulheart::Matcher do
4
+
5
+ describe :clean_opts do
6
+ it "Has the keys we need" do
7
+ target_keys = ['categories', 'query', 'page', 'per_page']
8
+ keys = Soulheart::Matcher.default_params_hash.keys
9
+ expect((target_keys - keys).count).to eq(0)
10
+ end
11
+
12
+ it "obeys stop words"
13
+ end
14
+
15
+ describe :category_id_from_opts do
16
+ it 'gets the id for one' do
17
+ Soulheart::Loader.new.reset_categories(['cool', 'test'])
18
+ matcher = Soulheart::Matcher.new('categories' => ['some_category'])
19
+ expect(matcher.category_id_from_opts).to eq(matcher.category_id('some_category'))
20
+ end
21
+
22
+ it 'gets the id for all of them' do
23
+ Soulheart::Loader.new.reset_categories(['cool', 'test', 'boo'])
24
+ matcher = Soulheart::Matcher.new('categories' => 'cool, boo, test')
25
+ expect(matcher.category_id_from_opts).to eq(matcher.category_id('all'))
26
+ end
27
+ end
28
+
29
+ describe :categories_string do
30
+ it 'does all if none' do
31
+ Soulheart::Loader.new.reset_categories(['cool', 'test'])
32
+ matcher = Soulheart::Matcher.new('categories' => '')
33
+ expect(matcher.categories_string).to eq('all')
34
+ end
35
+ it "correctly concats a string of categories" do
36
+ Soulheart::Loader.new.reset_categories(['cool', 'some_category', 'another cat', 'z9', 'stuff'])
37
+ matcher = Soulheart::Matcher.new({'categories' => 'some_category, another cat, z9'})
38
+ expect(matcher.categories_string).to eq('another catsome_categoryz9')
39
+ end
40
+ end
41
+
42
+
43
+ describe :matches do
44
+ it "With no params, gets all the matches, ordered by priority and name" do
45
+ store_terms_fixture
46
+ opts = { 'per_page' => 100, 'cache' => false }
47
+ matches = Soulheart::Matcher.new(opts).matches
48
+ expect(matches.count).to be > 10
49
+ expect(matches[0]['text']).to eq('Surly')
50
+ end
51
+
52
+ it "With no query but with categories, matches categories" do
53
+ store_terms_fixture
54
+ opts = { 'per_page' => 100, 'cache' => false, 'categories' => 'manufacturer' }
55
+ matches = Soulheart::Matcher.new(opts).matches
56
+ expect(matches.count).to eq(4)
57
+ expect(matches[0]['text']).to eq('Sram')
58
+ end
59
+
60
+ it "Gets the matches matching query and priority for one item in query, all categories" do
61
+ store_terms_fixture
62
+ opts = { 'per_page' => 100, 'query' => 'j', 'cache' => false }
63
+ matches = Soulheart::Matcher.new(opts).matches
64
+ expect(matches.count).to eq(3)
65
+ expect(matches[0]['text']).to eq('Jamis')
66
+ end
67
+
68
+ it "Gets the matches matching query and priority for one item in query, one category" do
69
+ store_terms_fixture
70
+ opts = { 'per_page' => 100, 'query' => 'j', 'cache' => false, 'categories' => 'manufacturer' }
71
+ matches = Soulheart::Matcher.new(opts).matches
72
+ expect(matches.count).to eq(2)
73
+ expect(matches[0]['text']).to eq('Jannd')
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soulheart::Server do
4
+
5
+ describe :search do
6
+ it "Has CORS headers, JSON Content-Type and it succeeds" do
7
+ get '/'
8
+ expect(last_response.headers['Access-Control-Allow-Origin']).to eq('*')
9
+ expect(last_response.headers['Access-Control-Request-Method']).to eq('*')
10
+ expect(last_response.headers['Content-Type']).to match('json')
11
+ expect(last_response.status).to eq(200)
12
+ end
13
+ end
14
+
15
+ describe :status do
16
+ it "Has cors headers and is valid JSON" do
17
+ get '/status'
18
+ expect(last_response.headers['Access-Control-Allow-Origin']).to eq('*')
19
+ expect(last_response.headers['Access-Control-Request-Method']).to eq('*')
20
+ expect(last_response.headers['Content-Type']).to match('json')
21
+ expect(JSON.parse(last_response.body)['soulheart']).to match(/\d/)
22
+ end
23
+ end
24
+
25
+
26
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soulheart do
4
+
5
+ it 'has a version number' do
6
+ expect(Soulheart::VERSION).not_to be nil
7
+ end
8
+
9
+ it "has a test base_id" do
10
+ expect(Soulheart::Base.new.base_id).to eq('soulheart_test:')
11
+ end
12
+
13
+ it "collates (? probably not the word I'm looking for) all the things" do
14
+ base = Soulheart::Base.new
15
+ base.redis.expire base.categories_id, 0
16
+ base.redis.sadd base.categories_id, ['George', 'category one', 'other thing ']
17
+ result = base.set_category_combos_array
18
+ expect(result.include?("category one")).to be_true
19
+ expect(result.include?("george")).to be_true
20
+ expect(result.include?("other thing")).to be_true
21
+ expect(result.include?("georgeother thing")).to be_true
22
+ expect(result.include?("category oneother thing")).to be_true
23
+ expect(result.include?("category onegeorge")).to be_true
24
+ expect(result.include?("georgecategory one")).to be_false
25
+ expect(result.include?("all")).to be_true
26
+ expect(result.include?("category onegeorgeother thing")).to be_false
27
+ end
28
+
29
+ end
@@ -0,0 +1,31 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+ require 'rack/test'
6
+ require 'rspec'
7
+
8
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
9
+ require 'soulheart'
10
+ require 'soulheart/server'
11
+
12
+ ENV['RACK_ENV'] = 'test'
13
+
14
+ module RSpecMixin
15
+ include Rack::Test::Methods
16
+ def app() Soulheart::Server end
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+ config.include RSpecMixin
22
+ end
23
+
24
+ def store_terms_fixture
25
+ items = []
26
+ file = File.read('spec/fixtures/multiple_categories.json')
27
+ file.each_line { |l| items << MultiJson.decode(l) }
28
+ loader = Soulheart::Loader.new
29
+ loader.delete_categories
30
+ loader.load(items)
31
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soulheart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Seth Herr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hiredis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: vegas
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-contrib
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Simple, fast autocomplete server for Ruby and Rails
140
+ email:
141
+ - seth.william.herr@gmail.com
142
+ executables:
143
+ - soulheart
144
+ - soulheart-web
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".rspec"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - Guardfile
153
+ - LICENSE.md
154
+ - README.markdown
155
+ - Rakefile
156
+ - bin/soulheart
157
+ - bin/soulheart-web
158
+ - lib/soulheart.rb
159
+ - lib/soulheart/base.rb
160
+ - lib/soulheart/config.rb
161
+ - lib/soulheart/helpers.rb
162
+ - lib/soulheart/loader.rb
163
+ - lib/soulheart/matcher.rb
164
+ - lib/soulheart/server.rb
165
+ - lib/soulheart/version.rb
166
+ - logo.png
167
+ - soulheart.gemspec
168
+ - spec/fixtures/multiple_categories.json
169
+ - spec/soulheart/loader_spec.rb
170
+ - spec/soulheart/matcher_spec.rb
171
+ - spec/soulheart/server_spec.rb
172
+ - spec/soulheart_spec.rb
173
+ - spec/spec_helper.rb
174
+ homepage: https://github.com/sethherr/soulheart
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.4.6
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Simple, fast autocomplete server for Ruby and Rails
198
+ test_files: []