mongoid_rateable 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  class Post
2
2
  include Mongoid::Document
3
3
  include Mongoid::Rateable
4
+ include Mongoid::Attributes::Dynamic if Mongoid::VERSION>='4'
4
5
 
5
6
  embeds_many :comments
6
7
  end
@@ -1,6 +1,7 @@
1
1
  class User
2
2
  include Mongoid::Document
3
3
 
4
+ field :id
4
5
  field :name
5
6
 
6
7
  end
@@ -12,7 +12,7 @@ describe Post do
12
12
 
13
13
  it "should have Mongoid::Rateable module" do
14
14
  #TODO: Refactor this
15
- @post.class.const_get("Mongoid").const_get("Rateable").should be_true
15
+ @post.class.const_get("Mongoid").const_get("Rateable").should_not be nil
16
16
  end
17
17
 
18
18
  subject { @post }
@@ -29,6 +29,7 @@ describe Post do
29
29
  it { should respond_to :unweighted_rating }
30
30
  it { should respond_to :rating_marks }
31
31
  it { should respond_to :user_mark }
32
+ it { should respond_to :user_marks }
32
33
 
33
34
  describe "#rating_marks" do
34
35
  it "should be proper Mongoid field" do
@@ -75,17 +76,17 @@ describe Post do
75
76
 
76
77
  describe "#rated?" do
77
78
  describe "for anyone" do
78
- specify { @post.rated?().should be_true }
79
+ specify { @post.rated?().should be true }
79
80
  end
80
81
  describe "for anyone" do
81
- specify { @article.rated?().should be_false }
82
+ specify { @article.rated?().should be false }
82
83
  end
83
84
 
84
85
  describe "for Bob" do
85
- specify { @post.rated_by?(@bob).should be_true }
86
+ specify { @post.rated_by?(@bob).should be true }
86
87
  end
87
88
  describe "for Bob" do
88
- specify { @article.rated_by?(@bob).should be_false }
89
+ specify { @article.rated_by?(@bob).should be false }
89
90
  end
90
91
 
91
92
  describe "when rated by someone else" do
@@ -94,13 +95,13 @@ describe Post do
94
95
  end
95
96
 
96
97
  describe "for Alice" do
97
- specify { @post.rated_by?(@alice).should be_true }
98
+ specify { @post.rated_by?(@alice).should be true }
98
99
  end
99
100
  end
100
101
 
101
102
  describe "when not rated by someone else" do
102
103
  describe "for Sally" do
103
- specify { @post.rated_by?(@sally).should be_false }
104
+ specify { @post.rated_by?(@sally).should be false }
104
105
  end
105
106
  end
106
107
  end
@@ -117,7 +118,7 @@ describe Post do
117
118
  end
118
119
 
119
120
  it "should be unrated" do
120
- @post.rated?.should be_false
121
+ @post.rated?.should be false
121
122
  end
122
123
  end
123
124
 
@@ -184,6 +185,9 @@ describe Post do
184
185
  describe "should give nil" do
185
186
  specify { @post.user_mark(@alice).should be_nil}
186
187
  end
188
+ describe "should give marks" do
189
+ specify { @post.user_marks([@bob, @alice]).should eq Hash[@bob.id,1] }
190
+ end
187
191
  end
188
192
  end
189
193
 
@@ -233,15 +237,15 @@ describe Post do
233
237
 
234
238
  describe "#rated_by?" do
235
239
  describe "for Bob" do
236
- specify { @f_post.rated_by?(@bob).should be_true }
240
+ specify { @f_post.rated_by?(@bob).should be true }
237
241
  end
238
242
 
239
243
  describe "for Sally" do
240
- specify { @f_post.rated_by?(@sally).should be_true }
244
+ specify { @f_post.rated_by?(@sally).should be true }
241
245
  end
242
246
 
243
247
  describe "for Alice" do
244
- specify { @f_post.rated_by?(@alice).should be_false}
248
+ specify { @f_post.rated_by?(@alice).should be false}
245
249
  end
246
250
  end
247
251
 
@@ -283,15 +287,15 @@ describe Post do
283
287
 
284
288
  describe "#rated?" do
285
289
  it "should be #rated? by Bob" do
286
- @f_post.rated_by?(@bob).should be_true
290
+ @f_post.rated_by?(@bob).should be true
287
291
  end
288
292
 
289
293
  it "should be #rated? by Sally" do
290
- @f_post.rated_by?(@sally).should be_true
294
+ @f_post.rated_by?(@sally).should be true
291
295
  end
292
296
 
293
297
  it "should be not #rated? by Alice" do
294
- @f_post.rated_by?(@alice).should be_false
298
+ @f_post.rated_by?(@alice).should be false
295
299
  end
296
300
  end
297
301
 
@@ -331,15 +335,15 @@ describe Post do
331
335
 
332
336
  describe "#rated?" do
333
337
  it "should be #rated? by Sally" do
334
- @f_post.rated_by?(@sally).should be_true
338
+ @f_post.rated_by?(@sally).should be true
335
339
  end
336
340
 
337
341
  it "should be not #rated? by Bob" do
338
- @f_post.rated_by?(@bob).should be_false
342
+ @f_post.rated_by?(@bob).should be false
339
343
  end
340
344
 
341
345
  it "should be #rated?" do
342
- @f_post.rated?.should be_true
346
+ @f_post.rated?.should be true
343
347
  end
344
348
  end
345
349
 
@@ -464,7 +468,7 @@ describe Comment do
464
468
 
465
469
  it "should have Mongoid::Rateable module" do
466
470
  #TODO: Refactor this
467
- @comment1.class.const_get("Mongoid").const_get("Rateable").should be_true
471
+ @comment1.class.const_get("Mongoid").const_get("Rateable").should_not be nil
468
472
  end
469
473
 
470
474
  subject { @comment1 }
@@ -512,7 +516,7 @@ describe Comment do
512
516
  context "when rate_value in rating range" do
513
517
  it { expect { @comment1.rate 1, @sally }.not_to raise_error }
514
518
  end
515
-
519
+
516
520
  context "when rate_value not in rating range" do
517
521
  it { expect { @comment1.rate 9, @sally }.to raise_error(ArgumentError) }
518
522
  end
@@ -527,17 +531,17 @@ describe Comment do
527
531
 
528
532
  describe "#rated?" do
529
533
  describe "for anyone" do
530
- specify { @comment1.rated?().should be_true }
534
+ specify { @comment1.rated?().should be true }
531
535
  end
532
536
  describe "for anyone" do
533
- specify { @comment2.rated?().should be_false }
537
+ specify { @comment2.rated?().should be false }
534
538
  end
535
539
 
536
540
  describe "for Bob" do
537
- specify { @comment1.rated_by?(@bob).should be_true }
541
+ specify { @comment1.rated_by?(@bob).should be true }
538
542
  end
539
543
  describe "for Bob" do
540
- specify { @comment2.rated_by?(@bob).should be_false }
544
+ specify { @comment2.rated_by?(@bob).should be false }
541
545
  end
542
546
 
543
547
  describe "when rated by someone else" do
@@ -546,13 +550,13 @@ describe Comment do
546
550
  end
547
551
 
548
552
  describe "for Alice" do
549
- specify { @comment1.rated_by?(@alice).should be_true }
553
+ specify { @comment1.rated_by?(@alice).should be true }
550
554
  end
551
555
  end
552
556
 
553
557
  describe "when not rated by someone else" do
554
558
  describe "for Sally" do
555
- specify { @comment1.rated_by?(@sally).should be_false }
559
+ specify { @comment1.rated_by?(@sally).should be false }
556
560
  end
557
561
  end
558
562
  end
@@ -569,7 +573,7 @@ describe Comment do
569
573
  end
570
574
 
571
575
  it "should be unrated" do
572
- @comment1.rated?.should be_false
576
+ @comment1.rated?.should be false
573
577
  end
574
578
  end
575
579
 
@@ -686,15 +690,15 @@ describe Comment do
686
690
 
687
691
  describe "#rated_by?" do
688
692
  describe "for Bob" do
689
- specify { @f_comment.rated_by?(@bob).should be_true }
693
+ specify { @f_comment.rated_by?(@bob).should be true }
690
694
  end
691
695
 
692
696
  describe "for Sally" do
693
- specify { @f_comment.rated_by?(@sally).should be_true }
697
+ specify { @f_comment.rated_by?(@sally).should be true }
694
698
  end
695
699
 
696
700
  describe "for Alice" do
697
- specify { @f_comment.rated_by?(@alice).should be_false}
701
+ specify { @f_comment.rated_by?(@alice).should be false}
698
702
  end
699
703
  end
700
704
 
@@ -733,15 +737,15 @@ describe Comment do
733
737
 
734
738
  describe "#rated?" do
735
739
  it "should be #rated? by Bob" do
736
- @f_comment.rated_by?(@bob).should be_true
740
+ @f_comment.rated_by?(@bob).should be true
737
741
  end
738
742
 
739
743
  it "should be #rated? by Sally" do
740
- @f_comment.rated_by?(@sally).should be_true
744
+ @f_comment.rated_by?(@sally).should be true
741
745
  end
742
746
 
743
747
  it "should be not #rated? by Alice" do
744
- @f_comment.rated_by?(@alice).should be_false
748
+ @f_comment.rated_by?(@alice).should be false
745
749
  end
746
750
  end
747
751
 
@@ -782,15 +786,15 @@ describe Comment do
782
786
 
783
787
  describe "#rated?" do
784
788
  it "should be #rated? by Sally" do
785
- @f_comment.rated_by?(@sally).should be_true
789
+ @f_comment.rated_by?(@sally).should be true
786
790
  end
787
791
 
788
792
  it "should be not #rated? by Bob" do
789
- @f_comment.rated_by?(@bob).should be_false
793
+ @f_comment.rated_by?(@bob).should be false
790
794
  end
791
795
 
792
796
  it "should be #rated?" do
793
- @f_comment.rated?.should be_true
797
+ @f_comment.rated?.should be true
794
798
  end
795
799
  end
796
800
 
@@ -901,4 +905,4 @@ describe Comment do
901
905
  # end
902
906
  end
903
907
  end
904
- end
908
+ end
@@ -1,23 +1,33 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
- MODELS = File.join(File.dirname(__FILE__), "models")
4
+ MODELS = File.join(File.dirname(__FILE__), 'models')
5
5
 
6
- require "rubygems"
7
- require "mongoid"
8
- require "mongoid_rateable"
9
- require "database_cleaner"
10
- require "simplecov"
6
+ require 'rubygems'
7
+ require 'mongoid'
8
+ require 'mongoid_rateable'
9
+ require 'simplecov'
10
+ require 'database_cleaner'
11
+ require 'coveralls'
11
12
 
13
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ Coveralls::SimpleCov::Formatter
16
+ ])
12
17
  SimpleCov.start
13
18
 
14
- Dir["#{MODELS}/*.rb"].each { |f| require f }
15
-
16
19
  Mongoid.configure do |config|
17
20
  config.connect_to "mongoid_rateable_test"
18
21
  end
22
+
19
23
  Mongoid.logger = Logger.new($stdout)
20
24
 
25
+ if Mongoid::VERSION>'5'
26
+ Mongo::Logger.logger.level = ::Logger::FATAL
27
+ end
28
+
29
+ Dir["#{MODELS}/*.rb"].each { |f| require f }
30
+
21
31
  DatabaseCleaner.orm = "mongoid"
22
32
 
23
33
  RSpec.configure do |config|
@@ -32,4 +42,4 @@ RSpec.configure do |config|
32
42
  config.after(:each) do
33
43
  DatabaseCleaner.clean
34
44
  end
35
- end
45
+ end
@@ -0,0 +1,36 @@
1
+ class DatabaseCleaner
2
+ class << self
3
+ def clean
4
+ new.clean
5
+ end
6
+ end
7
+
8
+ def clean
9
+ if mongoid4?
10
+ collections.each { |c| database[c].find.remove_all }
11
+ else
12
+ collections.each { |c| database[c].find.delete_many }
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def mongoid4?
19
+ Mongoid::VERSION.start_with? '4'
20
+ end
21
+
22
+ def database
23
+ if mongoid4?
24
+ Mongoid.default_session
25
+ else
26
+ Mongoid::Clients.default
27
+ end
28
+ end
29
+
30
+ def collections
31
+ database['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
32
+ _, name = collection['name'].split('.', 2)
33
+ name
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,113 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_rateable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Savichev (proton)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-21 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jeweler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: 2.1.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: 2.1.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.4'
61
+ version: '0.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.4'
68
+ version: '0.7'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rdoc
70
+ name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.0'
89
+ version: 3.0.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '2.0'
96
+ version: 3.0.0
97
97
  - !ruby/object:Gem::Dependency
98
- name: database_cleaner
98
+ name: appraisal
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: coveralls
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ~>
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ~>
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: database_cleaner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 0.8.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.8.0
111
139
  description: Provides fields and methods for the rating manipulation on Mongoid documents.
112
140
  email: psavichev@gmail.com
113
141
  executables: []
@@ -117,21 +145,28 @@ extra_rdoc_files:
117
145
  - README.rdoc
118
146
  - TODO
119
147
  files:
120
- - .rspec
121
- - .rvmrc
122
- - .travis.yml
148
+ - ".rspec"
149
+ - ".ruby-version"
150
+ - ".travis.yml"
151
+ - Appraisals
123
152
  - CHANGELOG.md
124
153
  - Gemfile
125
- - Gemfile.lock
126
154
  - LICENSE.txt
127
155
  - README.rdoc
128
156
  - Rakefile
129
157
  - TODO
130
158
  - VERSION
159
+ - gemfiles/mongoid_3.gemfile
160
+ - gemfiles/mongoid_3.gemfile.lock
161
+ - gemfiles/mongoid_4.gemfile
162
+ - gemfiles/mongoid_4.gemfile.lock
163
+ - gemfiles/mongoid_5.gemfile
164
+ - gemfiles/mongoid_5.gemfile.lock
165
+ - gemfiles/mongoid_6.gemfile
166
+ - gemfiles/mongoid_6.gemfile.lock
131
167
  - lib/mongoid_rateable.rb
132
168
  - lib/mongoid_rateable/rateable.rb
133
169
  - lib/mongoid_rateable/rating.rb
134
- - lib/mongoid_rateable/version.rb
135
170
  - mongoid_rateable.gemspec
136
171
  - spec/models/article.rb
137
172
  - spec/models/comment.rb
@@ -139,6 +174,7 @@ files:
139
174
  - spec/models/user.rb
140
175
  - spec/rateable_spec.rb
141
176
  - spec/spec_helper.rb
177
+ - spec/support/database_cleaner.rb
142
178
  homepage: http://github.com/proton/mongoid_rateable
143
179
  licenses:
144
180
  - MIT
@@ -149,17 +185,17 @@ require_paths:
149
185
  - lib
150
186
  required_ruby_version: !ruby/object:Gem::Requirement
151
187
  requirements:
152
- - - ! '>='
188
+ - - ">="
153
189
  - !ruby/object:Gem::Version
154
190
  version: '0'
155
191
  required_rubygems_version: !ruby/object:Gem::Requirement
156
192
  requirements:
157
- - - ! '>='
193
+ - - ">="
158
194
  - !ruby/object:Gem::Version
159
195
  version: '0'
160
196
  requirements: []
161
197
  rubyforge_project:
162
- rubygems_version: 2.2.2
198
+ rubygems_version: 2.5.2
163
199
  signing_key:
164
200
  specification_version: 4
165
201
  summary: Rating functionality for Mongoid documents