hunt 0.2 → 0.3

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.
@@ -18,10 +18,8 @@ module Hunt
18
18
  @search_keys = keys
19
19
  end
20
20
 
21
- def search(value)
22
- terms = Util.to_stemmed_words(value)
23
- return [] if terms.blank?
24
- where('searches.default' => terms)
21
+ def search(term)
22
+ where('searches.default' => Util.to_stemmed_words(term))
25
23
  end
26
24
  end
27
25
 
@@ -1,3 +1,3 @@
1
1
  module Hunt
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -5,9 +5,19 @@ class Note
5
5
 
6
6
  plugin Hunt
7
7
 
8
- key :title, String
9
- key :body, String
10
- key :tags, Array
8
+ scope :by_user, lambda { |user| where(:user_id => user.id) }
9
+
10
+ key :title, String
11
+ key :body, String
12
+ key :tags, Array
13
+ key :user_id, ObjectId
14
+
15
+ belongs_to :user
16
+ end
17
+
18
+ class User
19
+ include MongoMapper::Document
20
+ many :notes
11
21
  end
12
22
 
13
23
  describe Hunt do
@@ -22,17 +32,42 @@ describe Hunt do
22
32
  Note.searches(:title)
23
33
  end
24
34
 
25
- it "returns empty array if nil" do
26
- Note.search(nil).should == []
35
+ it "returns query that matches nothing if nil" do
36
+ Note.create(:title => 'Mongo')
37
+ Note.search(nil).count.should == 0
27
38
  end
28
39
 
29
- it "returns empty array if blank" do
30
- Note.search('').should == []
40
+ it "returns query that matches nothing if blank" do
41
+ Note.create(:title => 'Mongo')
42
+ Note.search('').count.should == 0
43
+ end
44
+
45
+ context "chained on scope" do
46
+ before(:each) do
47
+ @user = User.create
48
+ @note = Note.create(:title => 'Mongo', :user_id => @user.id)
49
+ end
50
+
51
+ it "works" do
52
+ Note.by_user(@user).search('Mongo').all.should == [@note]
53
+ end
54
+ end
55
+
56
+ context "chained on association" do
57
+ before(:each) do
58
+ @user = User.create
59
+ @note = Note.create(:title => 'Mongo', :user_id => @user.id)
60
+ end
61
+
62
+ it "works" do
63
+ @user.notes.search('Mongo').all.should == [@note]
64
+ @user.notes.search('Frank').all.should == []
65
+ end
31
66
  end
32
67
 
33
68
  context "with one search term" do
34
69
  before(:each) do
35
- @note = Note.create(:title => 'MongoDB is awesome!')
70
+ @note = Note.create(:title => 'MongoDB is awesome!')
36
71
  @result = Note.search('mongodb')
37
72
  end
38
73
 
@@ -59,7 +94,7 @@ describe Hunt do
59
94
 
60
95
  context "with multiple search terms" do
61
96
  before(:each) do
62
- @note = Note.create(:title => 'MongoDB is awesome!')
97
+ @note = Note.create(:title => 'MongoDB is awesome!')
63
98
  @result = Note.search('mongodb is awesome')
64
99
  end
65
100
 
@@ -1,15 +1,3 @@
1
- def growl(title, msg, img)
2
- %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
3
- end
4
-
5
- def form_growl_message(str)
6
- msg = str.split("\n").last
7
- if msg =~ /(\d)\sfailure/
8
- img = $1.to_i > 0 ? 'fail' : 'pass'
9
- end
10
- growl 'Results', msg, img
11
- end
12
-
13
1
  def run(cmd)
14
2
  puts cmd
15
3
  output = ""
@@ -20,7 +8,7 @@ def run(cmd)
20
8
  $stdout.flush
21
9
  end
22
10
  end
23
- form_growl_message output
11
+ output
24
12
  end
25
13
 
26
14
  def run_spec(path)
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hunt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-19 00:00:00 -05:00
17
+ date: 2010-12-29 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency