mongoid_search 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem "jeweler"
4
+ gem "database_cleaner"
5
+ gem "mongoid", "2.0.0.beta.18"
6
+ gem "rspec", "2.0.0.beta.22"
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.0)
5
+ activesupport (= 3.0.0)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4.1)
8
+ activesupport (3.0.0)
9
+ bson (1.0.4)
10
+ builder (2.1.2)
11
+ database_cleaner (0.5.2)
12
+ diff-lcs (1.1.2)
13
+ gemcutter (0.6.1)
14
+ git (1.2.5)
15
+ i18n (0.4.1)
16
+ jeweler (1.4.0)
17
+ gemcutter (>= 0.1.0)
18
+ git (>= 1.2.5)
19
+ rubyforge (>= 2.0.0)
20
+ json_pure (1.4.6)
21
+ mongo (1.0.7)
22
+ bson (>= 1.0.4)
23
+ mongoid (2.0.0.beta.18)
24
+ activemodel (~> 3.0.0)
25
+ bson (= 1.0.4)
26
+ mongo (= 1.0.7)
27
+ tzinfo (~> 0.3.22)
28
+ will_paginate (~> 3.0.pre)
29
+ rspec (2.0.0.beta.22)
30
+ rspec-core (= 2.0.0.beta.22)
31
+ rspec-expectations (= 2.0.0.beta.22)
32
+ rspec-mocks (= 2.0.0.beta.22)
33
+ rspec-core (2.0.0.beta.22)
34
+ rspec-expectations (2.0.0.beta.22)
35
+ diff-lcs (>= 1.1.2)
36
+ rspec-mocks (2.0.0.beta.22)
37
+ rspec-core (= 2.0.0.beta.22)
38
+ rspec-expectations (= 2.0.0.beta.22)
39
+ rubyforge (2.0.4)
40
+ json_pure (>= 1.1.7)
41
+ tzinfo (0.3.23)
42
+ will_paginate (3.0.pre2)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ database_cleaner
49
+ jeweler
50
+ mongoid (= 2.0.0.beta.18)
51
+ rspec (= 2.0.0.beta.22)
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "mauricio@papodenerd.net"
11
11
  gem.homepage = "http://github.com/mauriciozaffari/mongoid_search"
12
12
  gem.authors = ["Mauricio Zaffari"]
13
+ gem.add_dependency("mongoid", ["~> 2.0.0.beta"])
13
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
@@ -24,22 +25,4 @@ Spec::Rake::SpecTask.new(:spec) do |spec|
24
25
  spec.spec_files = FileList['spec/**/*_spec.rb']
25
26
  end
26
27
 
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- end
32
-
33
- task :spec => :check_dependencies
34
-
35
28
  task :default => :spec
36
-
37
- require 'rake/rdoctask'
38
- Rake::RDocTask.new do |rdoc|
39
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
-
41
- rdoc.rdoc_dir = 'rdoc'
42
- rdoc.title = "mongoid_search #{version}"
43
- rdoc.rdoc_files.include('README*')
44
- rdoc.rdoc_files.include('lib/**/*.rb')
45
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_search}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mauricio Zaffari"]
12
- s.date = %q{2010-09-16}
12
+ s.date = %q{2010-09-17}
13
13
  s.description = %q{Simple full text search implementation.}
14
14
  s.email = %q{mauricio@papodenerd.net}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ "Gemfile",
23
+ "Gemfile.lock",
22
24
  "LICENSE",
23
25
  "README.md",
24
26
  "Rakefile",
@@ -27,6 +29,9 @@ Gem::Specification.new do |s|
27
29
  "lib/mongoid_search/keywords_extractor.rb",
28
30
  "lib/mongoid_search/mongoid_search.rb",
29
31
  "mongoid_search.gemspec",
32
+ "spec/keywords_extractor_spec.rb",
33
+ "spec/models/product.rb",
34
+ "spec/models/tag.rb",
30
35
  "spec/mongoid_search_spec.rb",
31
36
  "spec/spec.opts",
32
37
  "spec/spec_helper.rb"
@@ -37,7 +42,10 @@ Gem::Specification.new do |s|
37
42
  s.rubygems_version = %q{1.3.7}
38
43
  s.summary = %q{Search implementation for Mongoid ORM}
39
44
  s.test_files = [
40
- "spec/mongoid_search_spec.rb",
45
+ "spec/keywords_extractor_spec.rb",
46
+ "spec/models/product.rb",
47
+ "spec/models/tag.rb",
48
+ "spec/mongoid_search_spec.rb",
41
49
  "spec/spec_helper.rb"
42
50
  ]
43
51
 
@@ -46,11 +54,14 @@ Gem::Specification.new do |s|
46
54
  s.specification_version = 3
47
55
 
48
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta"])
49
58
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
59
  else
60
+ s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta"])
51
61
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
62
  end
53
63
  else
64
+ s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta"])
54
65
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
55
66
  end
56
67
  end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe KeywordsExtractor do
5
+ it "should return if no text is passed" do
6
+ KeywordsExtractor.extract("").should == nil
7
+ end
8
+
9
+ it "should return an array of keywords" do
10
+ KeywordsExtractor.extract("keyword").class.should == Array
11
+ end
12
+
13
+ it "should return an array of strings" do
14
+ KeywordsExtractor.extract("keyword").first.class.should == String
15
+ end
16
+
17
+ it "should remove accents from the text passed" do
18
+ KeywordsExtractor.extract("café").should == ["cafe"]
19
+ end
20
+
21
+ it "should downcase the text passed" do
22
+ KeywordsExtractor.extract("CaFé").should == ["cafe"]
23
+ end
24
+
25
+ it "should split whitespaces, hifens, dots and underlines" do
26
+ KeywordsExtractor.extract("CaFé-express.com delicious").should == ["cafe", "express", "com", "delicious"]
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ class Product
2
+ include Mongoid::Document
3
+ include Mongoid::Search
4
+ field :brand
5
+ field :name
6
+
7
+ references_many :tags
8
+
9
+ search_in :brand, :name, :tags => :name
10
+ end
@@ -0,0 +1,6 @@
1
+ class Tag
2
+ include Mongoid::Document
3
+ field :name
4
+
5
+ referenced_in :product
6
+ end
@@ -1,7 +1,40 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
4
 
3
- describe "MongoidSearch" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
5
+ describe Mongoid::Search do
6
+
7
+ before(:each) do
8
+ @product = Product.create :brand => "Apple", :name => "iPhone", :tags => ["Amazing", "Awesome", "Olé"].map { |tag| Tag.new(:name => tag) }
9
+ end
10
+
11
+ it "should set the _keywords field" do
12
+ @product._keywords.should == ["apple", "iphone", "amazing", "awesome", "ole"]
13
+ end
14
+
15
+ it "should return results in search" do
16
+ Product.search("apple").size.should == 1
17
+ end
18
+
19
+ it "should return results in search even searching a accented word" do
20
+ Product.search("Ole").size.should == 1
21
+ Product.search("Olé").size.should == 1
22
+ end
23
+
24
+ it "should return results in search even if the case doesn't match" do
25
+ Product.search("oLe").size.should == 1
26
+ end
27
+
28
+ it "should return results in search with a partial word" do
29
+ Product.search("iph").size.should == 1
30
+ end
31
+
32
+ it "should return results for any matching word with default search" do
33
+ Product.search("apple motorola").size.should == 1
34
+ end
35
+
36
+ it "should not return results when all words do not match, if using :match => :all" do
37
+ Product.match = :all
38
+ Product.search("apple motorola").size.should == 0
6
39
  end
7
40
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,28 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mongoid'
4
+ require 'database_cleaner'
3
5
  require 'mongoid_search'
4
- require 'spec'
5
- require 'spec/autorun'
6
+
7
+ Mongoid.configure do |config|
8
+ name = "mongoid_search_test"
9
+ config.master = Mongo::Connection.new.db(name)
10
+ end
11
+
12
+ Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |file| require file }
13
+
14
+ DatabaseCleaner.orm = "mongoid"
6
15
 
7
16
  Spec::Runner.configure do |config|
8
-
17
+ config.before(:all) do
18
+ DatabaseCleaner.strategy = :truncation
19
+ end
20
+
21
+ config.before(:each) do
22
+ DatabaseCleaner.start
23
+ end
24
+
25
+ config.after(:each) do
26
+ DatabaseCleaner.clean
27
+ end
9
28
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mauricio Zaffari
@@ -14,13 +14,29 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-16 00:00:00 -03:00
17
+ date: 2010-09-17 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
21
+ name: mongoid
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ version: 2.0.0.beta
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
24
40
  none: false
25
41
  requirements:
26
42
  - - ">="
@@ -31,7 +47,7 @@ dependencies:
31
47
  - 9
32
48
  version: 1.2.9
33
49
  type: :development
34
- version_requirements: *id001
50
+ version_requirements: *id002
35
51
  description: Simple full text search implementation.
36
52
  email: mauricio@papodenerd.net
37
53
  executables: []
@@ -44,6 +60,8 @@ extra_rdoc_files:
44
60
  files:
45
61
  - .document
46
62
  - .gitignore
63
+ - Gemfile
64
+ - Gemfile.lock
47
65
  - LICENSE
48
66
  - README.md
49
67
  - Rakefile
@@ -52,6 +70,9 @@ files:
52
70
  - lib/mongoid_search/keywords_extractor.rb
53
71
  - lib/mongoid_search/mongoid_search.rb
54
72
  - mongoid_search.gemspec
73
+ - spec/keywords_extractor_spec.rb
74
+ - spec/models/product.rb
75
+ - spec/models/tag.rb
55
76
  - spec/mongoid_search_spec.rb
56
77
  - spec/spec.opts
57
78
  - spec/spec_helper.rb
@@ -88,5 +109,8 @@ signing_key:
88
109
  specification_version: 3
89
110
  summary: Search implementation for Mongoid ORM
90
111
  test_files:
112
+ - spec/keywords_extractor_spec.rb
113
+ - spec/models/product.rb
114
+ - spec/models/tag.rb
91
115
  - spec/mongoid_search_spec.rb
92
116
  - spec/spec_helper.rb