mongoid-tags 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e16991bc166551e1c70fdbe5b781ff6edbf17fb
4
+ data.tar.gz: 6deab071b460375bbc13871deef11fb14c1555bf
5
+ SHA512:
6
+ metadata.gz: 7aef5b385ec4b0552fa1d715c8923f330d010386923073298977c95cebba3fa4c8a0392885aa17ef10149b6667b9bb65d2e9c85fcf7c1bae2fce5b93546f7e07
7
+ data.tar.gz: b9e22c6b8200cbc3cbd68ae7ce72c58917aeb41754a012376de471b918e26bce5d271bf4e8cd182443cd18825e6386b50907b1d35f358849ea81a3941c765140
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.3.0 (February 12, 2014)
2
+ * Use Rake::FileList.
3
+ * Removes Gemfile warning.
4
+ * Simplifies tests a lot.
5
+
6
+ # 0.2.0 (December 31, 2012)
7
+ * Use require_relative.
8
+
1
9
  # 0.1.1 (December 22, 2012)
2
10
  * Updated gemspec.
3
11
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
data/README.md CHANGED
@@ -22,17 +22,17 @@ end
22
22
  ```
23
23
 
24
24
  ```ruby
25
- # Documents tagged foo || bar
25
+ # Documents tagged foo || bar
26
26
  Document.tagged('foo bar')
27
27
 
28
- # Documents tagged foo && bar
28
+ # Documents tagged foo && bar
29
29
  Document.tagged('+foo bar')
30
30
 
31
31
  # Documents tagged foo, but !bar
32
32
  Document.tagged('foo -bar')
33
33
  ```
34
34
 
35
- Be sure to checkout spec/integration_spec.rb for more examples. By the way, `tagged` returns a `Mongoid::Criteria` object so you can chain it to your existing criteria, e.g: `Document.where(published: true).tagged('foo').desc(:created_at)`
35
+ Be sure to checkout spec/integration_spec.rb for more examples. By the way, `tagged` returns a `Mongoid::Criteria` object so you can chain it to your existing criteria, e.g: `Document.where(published: true).tagged('foo').desc(:created_at)`
36
36
 
37
37
  ## Contributing
38
38
 
@@ -46,7 +46,7 @@ Be sure to checkout spec/integration_spec.rb for more examples. By the way, `tag
46
46
 
47
47
  (The MIT license)
48
48
 
49
- Copyright (c) 2012 Mario Uher
49
+ Copyright (c) 2012-2014 Mario Uher
50
50
 
51
51
  Permission is hereby granted, free of charge, to any person obtaining
52
52
  a copy of this software and associated documentation files (the
@@ -65,4 +65,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
65
65
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
66
66
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
67
67
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
68
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
- require 'rake'
2
1
  require 'rake/testtask'
3
2
 
4
3
  Rake::TestTask.new do |t|
5
- t.test_files = Dir.glob('spec/**/*_spec.rb')
4
+ t.pattern = 'test/*_test.rb'
6
5
  end
7
6
 
8
- task(default: :test)
7
+ task default: :test
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Tags
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
data/lib/mongoid/tags.rb CHANGED
@@ -33,7 +33,7 @@ module Mongoid
33
33
  {}.tap do |criteria|
34
34
  (tags.presence || elements).each do |tag|
35
35
  (criteria[tag.operator.selector] ||= []) << tag.to_criteria if tag.is_a? Tag
36
-
36
+
37
37
  criteria.merge!(to_criteria(tag.elements)) { |key, first, second| first + second } if tag.elements.present?
38
38
  end
39
39
  end
@@ -0,0 +1,120 @@
1
+ require_relative 'test_helper'
2
+
3
+ # Create all possible combinations of tags.
4
+ 3.times do |i|
5
+ %w[foo bar baz].combination(i + 1).each do |tags|
6
+ Document.create tags: tags
7
+ end
8
+ end
9
+
10
+ # Litte helper which helps to DRY tests.
11
+ def include?(*tags)
12
+ proc do |document|
13
+ tags.any? do |tag|
14
+ document.tags.include?(tag)
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ class IntegrationTest < Minitest::Test
21
+ def test_documents_including_foo
22
+ assert Document.tagged('foo').all? &include?('foo')
23
+ end
24
+
25
+
26
+ def test_documents_including_at_least_foo
27
+ assert Document.tagged('+foo').all? &include?('foo')
28
+ end
29
+
30
+
31
+ def test_documents_not_including_foo
32
+ assert Document.tagged('-foo').none? &include?('foo')
33
+ end
34
+
35
+
36
+ def test_documents_including_foo_or_bar
37
+ assert Document.tagged('foo bar').all? &include?('foo', 'bar')
38
+ end
39
+
40
+
41
+ def test_documents_including_foo_and_bar
42
+ documents = Document.tagged('+foo bar')
43
+
44
+ assert documents.all? &include?('foo')
45
+ assert documents.all? &include?('bar')
46
+ end
47
+
48
+
49
+ def test_documents_not_including_foo_but_bar
50
+ documents = Document.tagged('-foo bar')
51
+
52
+ assert documents.none? &include?('foo')
53
+ assert documents.all? &include?('bar')
54
+ end
55
+
56
+
57
+ def test_documents_not_including_foo_and_bar
58
+ documents = Document.tagged('-foo -bar')
59
+
60
+ assert documents.none? &include?('foo')
61
+ assert documents.none? &include?('bar')
62
+ end
63
+
64
+
65
+ def test_documents_including_foo_or_bar_or_baz
66
+ assert Document.tagged('foo bar baz').all? &include?('foo', 'bar', 'baz')
67
+ end
68
+
69
+
70
+ def test_documents_including_at_foo_and_maybe_bar_or_baz
71
+ documents = Document.tagged('+foo bar baz')
72
+
73
+ assert documents.all? &include?('foo')
74
+ assert documents.all? &include?('bar', 'baz')
75
+ end
76
+
77
+
78
+ def test_documents_including_at_least_foo_and_bar_maybe_baz
79
+ documents = Document.tagged('+foo +bar baz')
80
+
81
+ assert documents.all? &include?('foo')
82
+ assert documents.all? &include?('bar')
83
+ assert documents.all? &include?('baz')
84
+ end
85
+
86
+
87
+ def test_documents_not_including_foo_but_bar_or_baz
88
+ documents = Document.tagged('-foo bar baz')
89
+
90
+ assert documents.none? &include?('foo')
91
+ assert documents.all? &include?('bar', 'baz')
92
+ end
93
+
94
+
95
+ def test_documents_not_including_foo_but_bar_and_maybe_baz
96
+ documents = Document.tagged('-foo +bar baz')
97
+
98
+ assert documents.none? &include?('foo')
99
+ assert documents.all? &include?('bar')
100
+ assert documents.any? &include?('baz')
101
+ end
102
+
103
+
104
+ def test_documents_not_including_foo_and_bar_but_baz
105
+ documents = Document.tagged('-foo -bar baz')
106
+
107
+ assert documents.none? &include?('foo')
108
+ assert documents.none? &include?('bar')
109
+ assert documents.all? &include?('baz')
110
+ end
111
+
112
+
113
+ def test_documents_not_including_foo_and_bar_and_baz
114
+ documents = Document.tagged('-foo -bar -baz')
115
+
116
+ assert documents.none? &include?('foo')
117
+ assert documents.none? &include?('bar')
118
+ assert documents.none? &include?('baz')
119
+ end
120
+ end
File without changes
data/test/tags_test.rb ADDED
@@ -0,0 +1,36 @@
1
+ require_relative 'test_helper'
2
+
3
+ class TagsTest < Minitest::Test
4
+ def assert_selector(query, selector)
5
+ assert_equal selector, Document.selector(query)
6
+ end
7
+
8
+ def test_valid_queries
9
+ assert_selector 'foo', '$in' => %w[foo]
10
+ assert_selector '+foo', '$all' => %w[foo]
11
+ assert_selector '-foo', '$nin' => %w[foo]
12
+ assert_selector 'foo bar', '$in' => %w[foo bar]
13
+ assert_selector 'foo +bar', '$in' => %w[foo], '$all' => %w[bar]
14
+ assert_selector 'foo +bar +baz', '$in' => %w[foo], '$all' => %w[bar baz]
15
+ assert_selector 'foo +bar baz', '$in' => %w[foo baz], '$all' => %w[bar]
16
+ assert_selector 'foo +bar -baz', '$in' => %w[foo], '$all' => %w[bar], '$nin' => %w[baz]
17
+ end
18
+
19
+ def test_invalid_queries
20
+ assert_raises Mongoid::Tags::Error do
21
+ Document.selector('+ foo')
22
+ end
23
+
24
+ assert_raises Mongoid::Tags::Error do
25
+ Document.selector('- foo')
26
+ end
27
+
28
+ assert_raises Mongoid::Tags::Error do
29
+ Document.selector('/ foo')
30
+ end
31
+
32
+ assert_raises Mongoid::Tags::Error do
33
+ Document.selector('foo + bar')
34
+ end
35
+ end
36
+ end
@@ -6,5 +6,9 @@ require 'minitest/spec'
6
6
 
7
7
  require 'mongoid/tags'
8
8
 
9
- # Load support *.rb files in ./support
10
- Dir[File.expand_path('../support/*.rb', __FILE__)].each { |file| require_relative file }
9
+ class Document
10
+ include Mongoid::Document
11
+ include Mongoid::Tags
12
+ end
13
+
14
+ Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), 'test')
metadata CHANGED
@@ -1,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tags
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mario Uher
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- none: false
21
- name: activesupport
22
20
  type: :runtime
23
21
  prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
22
+ version_requirements: !ruby/object:Gem::Requirement
25
23
  requirements:
26
- - - ! '>='
24
+ - - ">="
27
25
  - !ruby/object:Gem::Version
28
26
  version: '0'
29
- none: false
30
27
  - !ruby/object:Gem::Dependency
31
- version_requirements: !ruby/object:Gem::Requirement
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
32
30
  requirements:
33
- - - ! '>='
31
+ - - ">="
34
32
  - !ruby/object:Gem::Version
35
33
  version: '0'
36
- none: false
37
- name: mongoid
38
34
  type: :runtime
39
35
  prerelease: false
40
- requirement: !ruby/object:Gem::Requirement
36
+ version_requirements: !ruby/object:Gem::Requirement
41
37
  requirements:
42
- - - ! '>='
38
+ - - ">="
43
39
  - !ruby/object:Gem::Version
44
40
  version: '0'
45
- none: false
46
41
  - !ruby/object:Gem::Dependency
47
- version_requirements: !ruby/object:Gem::Requirement
42
+ name: treetop
43
+ requirement: !ruby/object:Gem::Requirement
48
44
  requirements:
49
- - - ! '>='
45
+ - - ">="
50
46
  - !ruby/object:Gem::Version
51
47
  version: '0'
52
- none: false
53
- name: treetop
54
48
  type: :runtime
55
49
  prerelease: false
56
- requirement: !ruby/object:Gem::Requirement
50
+ version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
- - - ! '>='
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
54
  version: '0'
61
- none: false
62
55
  description: Mongoid::Tags adds a simple tagging system to your Mongoid documents,
63
56
  and allows you to query them using a boolean search syntax.
64
57
  email: uher.mario@gmail.com
@@ -66,7 +59,7 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
62
+ - ".gitignore"
70
63
  - CHANGELOG.md
71
64
  - Gemfile
72
65
  - README.md
@@ -75,34 +68,31 @@ files:
75
68
  - lib/mongoid/tags.tt
76
69
  - lib/mongoid/tags/version.rb
77
70
  - mongoid-tags.gemspec
78
- - spec/integration_spec.rb
79
- - spec/spec_helper.rb
80
- - spec/support/connection.rb
81
- - spec/support/document.rb
82
- - spec/support/mongoid.yml
83
- - spec/tags_spec.rb
71
+ - test/integration_test.rb
72
+ - test/mongoid.yml
73
+ - test/tags_test.rb
74
+ - test/test_helper.rb
84
75
  homepage: https://github.com/haihappen/mongoid-tags
85
76
  licenses: []
77
+ metadata: {}
86
78
  post_install_message:
87
79
  rdoc_options: []
88
80
  require_paths:
89
81
  - lib
90
82
  required_ruby_version: !ruby/object:Gem::Requirement
91
83
  requirements:
92
- - - ! '>='
84
+ - - ">="
93
85
  - !ruby/object:Gem::Version
94
86
  version: '0'
95
- none: false
96
87
  required_rubygems_version: !ruby/object:Gem::Requirement
97
88
  requirements:
98
- - - ! '>='
89
+ - - ">="
99
90
  - !ruby/object:Gem::Version
100
91
  version: '0'
101
- none: false
102
92
  requirements: []
103
93
  rubyforge_project:
104
- rubygems_version: 1.8.23
94
+ rubygems_version: 2.2.0
105
95
  signing_key:
106
- specification_version: 3
96
+ specification_version: 4
107
97
  summary: Simple tagging system with boolean search.
108
98
  test_files: []
@@ -1,121 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'Mongoid::Tags integration' do
4
- before do
5
- # Create all possible combinations
6
- 3.times do |i|
7
- %w[foo bar baz].combination(i + 1).each do |tags|
8
- Document.create(tags: tags)
9
- end
10
- end
11
- end
12
-
13
-
14
- let(:query) { self.class.name.demodulize } # Use description as query ;)
15
- subject { Document.tagged(query) }
16
-
17
-
18
- describe 'foo' do
19
- it 'returns documents including foo' do
20
- subject.all? { |d| d.tags.include?('foo') }.must_equal true
21
- end
22
- end
23
-
24
-
25
- describe '+foo' do
26
- it 'returns documents including at least foo' do
27
- subject.all? { |d| d.tags.include?('foo') }.must_equal true
28
- end
29
- end
30
-
31
-
32
- describe '-foo' do
33
- it 'returns documents not including foo' do
34
- subject.none? { |d| d.tags.include?('foo') }.must_equal true
35
- end
36
- end
37
-
38
-
39
- describe 'foo bar' do
40
- it 'returns documents including foo or bar' do
41
- subject.all? { |d| d.tags.include?('foo') || d.tags.include?('bar') }.must_equal true
42
- end
43
- end
44
-
45
-
46
- describe '+foo bar' do
47
- it 'returns documents including foo and bar' do
48
- subject.all? { |d| d.tags.include?('foo') }.must_equal true
49
- subject.all? { |d| d.tags.include?('bar') }.must_equal true
50
- end
51
- end
52
-
53
-
54
- describe '-foo bar' do
55
- it 'returns documents not including foo, but bar' do
56
- subject.none? { |d| d.tags.include?('foo') }.must_equal true
57
- subject.all? { |d| d.tags.include?('bar') }.must_equal true
58
- end
59
- end
60
-
61
-
62
- describe '-foo -bar' do
63
- it 'returns documents not including foo and bar' do
64
- subject.none? { |d| d.tags.include?('foo') }.must_equal true
65
- subject.none? { |d| d.tags.include?('bar') }.must_equal true
66
- end
67
- end
68
-
69
-
70
- describe 'foo bar baz' do
71
- it 'returns documents including foo or bar' do
72
- subject.all? { |d| d.tags.include?('foo') || d.tags.include?('bar') || d.tags.include?('baz') }.must_equal true
73
- end
74
- end
75
-
76
-
77
- describe '+foo bar baz' do
78
- it 'returns documents including at least foo and bar or baz' do
79
- subject.all? { |d| d.tags.include?('foo') }.must_equal true
80
- subject.all? { |d| d.tags.include?('bar') || d.tags.include?('baz') }.must_equal true
81
- end
82
- end
83
-
84
-
85
- describe '+foo +bar baz' do
86
- it 'returns documents including at least foo, bar and baz' do
87
- subject.all? { |d| d.tags.include?('foo') }.must_equal true
88
- subject.all? { |d| d.tags.include?('bar') }.must_equal true
89
- subject.all? { |d| d.tags.include?('baz') }.must_equal true
90
- end
91
- end
92
-
93
-
94
- describe '-foo bar baz' do
95
- it 'returns documents not including foo, but bar or baz' do
96
- subject.none? { |d| d.tags.include?('foo') }.must_equal true
97
- subject.all? { |d| d.tags.include?('bar') || d.tags.include?('baz') }.must_equal true
98
- end
99
- end
100
-
101
-
102
- describe '-foo -bar baz' do
103
- it 'returns documents not including foo and bar, but baz' do
104
- subject.none? { |d| d.tags.include?('foo') }.must_equal true
105
- subject.none? { |d| d.tags.include?('bar') }.must_equal true
106
- subject.all? { |d| d.tags.include?('baz') }.must_equal true
107
- end
108
- end
109
-
110
-
111
- describe '-foo -bar -baz' do
112
- it 'returns documents not including foo, bar and baz' do
113
- subject.none? { |d| d.tags.include?('foo') }.must_equal true
114
- subject.none? { |d| d.tags.include?('bar') }.must_equal true
115
- subject.none? { |d| d.tags.include?('baz') }.must_equal true
116
- end
117
- end
118
-
119
-
120
- after { Document.destroy_all }
121
- end
@@ -1 +0,0 @@
1
- Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), 'test')
@@ -1,4 +0,0 @@
1
- class Document
2
- include Mongoid::Document
3
- include Mongoid::Tags
4
- end
data/spec/tags_spec.rb DELETED
@@ -1,76 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Mongoid::Tags do
4
- describe :selector do
5
- let(:query) { @__name__.match(/test_\d+_(.*)/).to_a.last } # Use description as query ;)
6
- subject { Document.selector(query) }
7
-
8
-
9
- it 'foo' do
10
- subject.must_equal '$in' => %w[foo]
11
- end
12
-
13
-
14
- it '+foo' do
15
- subject.must_equal '$all' => %w[foo]
16
- end
17
-
18
-
19
- it '- foo' do
20
- proc { subject }.must_raise Mongoid::Tags::Error
21
- end
22
-
23
-
24
- it '-foo' do
25
- subject.must_equal '$nin' => %w[foo]
26
- end
27
-
28
-
29
- it '- foo' do
30
- proc { subject }.must_raise Mongoid::Tags::Error
31
- end
32
-
33
-
34
- it '/foo' do
35
- proc { subject }.must_raise Mongoid::Tags::Error
36
- end
37
-
38
-
39
- it 'foo bar' do
40
- subject.must_equal '$in' => %w[foo bar]
41
- end
42
-
43
-
44
- it 'foo +bar' do
45
- subject.must_equal '$in' => %w[foo], '$all' => %w[bar]
46
- end
47
-
48
-
49
- it 'foo + bar' do
50
- proc { subject }.must_raise Mongoid::Tags::Error
51
- end
52
-
53
-
54
- it 'foo +bar +baz' do
55
- subject.must_equal '$in' => %w[foo], '$all' => %w[bar baz]
56
- end
57
-
58
-
59
- it 'foo +bar baz' do
60
- subject.must_equal '$in' => %w[foo baz], '$all' => %w[bar]
61
- end
62
-
63
-
64
- it 'foo +bar -baz' do
65
- subject.must_equal '$in' => %w[foo], '$all' => %w[bar], '$nin' => %w[baz]
66
- end
67
-
68
-
69
- it 'foo foo foo' do
70
- # Removing duplicates does not gain any
71
- # performance improvements.
72
- skip
73
- subject.must_equal '$in' => %w[foo]
74
- end
75
- end
76
- end