mongoid_rateable 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,80 +2,76 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mongoid_rateable 0.3.3 ruby lib
5
+ # stub: mongoid_rateable 0.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "mongoid_rateable"
9
- s.version = "0.3.3"
8
+ s.name = "mongoid_rateable".freeze
9
+ s.version = "0.4.1"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Peter Savichev (proton)"]
14
- s.date = "2014-06-21"
15
- s.description = "Provides fields and methods for the rating manipulation on Mongoid documents."
16
- s.email = "psavichev@gmail.com"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Petr Savichev (proton)".freeze]
14
+ s.date = "2023-03-07"
15
+ s.description = "Provides fields and methods for the rating manipulation on Mongoid documents.".freeze
16
+ s.email = "psavichev@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
18
+ "CHANGELOG.md",
18
19
  "LICENSE.txt",
19
- "README.rdoc",
20
+ "README.md",
20
21
  "TODO"
21
22
  ]
22
23
  s.files = [
24
+ ".github/FUNDING.yml",
23
25
  ".rspec",
24
- ".rvmrc",
26
+ ".ruby-version",
25
27
  ".travis.yml",
28
+ "Appraisals",
26
29
  "CHANGELOG.md",
27
30
  "Gemfile",
28
- "Gemfile.lock",
29
31
  "LICENSE.txt",
30
- "README.rdoc",
32
+ "README.md",
31
33
  "Rakefile",
32
34
  "TODO",
33
35
  "VERSION",
36
+ "gemfiles/mongoid_3.gemfile",
37
+ "gemfiles/mongoid_3.gemfile.lock",
38
+ "gemfiles/mongoid_4.gemfile",
39
+ "gemfiles/mongoid_4.gemfile.lock",
40
+ "gemfiles/mongoid_5.gemfile",
41
+ "gemfiles/mongoid_5.gemfile.lock",
42
+ "gemfiles/mongoid_6.gemfile",
43
+ "gemfiles/mongoid_6.gemfile.lock",
44
+ "gemfiles/mongoid_7.gemfile",
45
+ "gemfiles/mongoid_7.gemfile.lock",
46
+ "gemfiles/mongoid_8.gemfile",
47
+ "gemfiles/mongoid_8.gemfile.lock",
34
48
  "lib/mongoid_rateable.rb",
35
49
  "lib/mongoid_rateable/rateable.rb",
36
50
  "lib/mongoid_rateable/rating.rb",
37
- "lib/mongoid_rateable/version.rb",
38
51
  "mongoid_rateable.gemspec",
39
52
  "spec/models/article.rb",
40
53
  "spec/models/comment.rb",
41
54
  "spec/models/post.rb",
42
55
  "spec/models/user.rb",
43
56
  "spec/rateable_spec.rb",
44
- "spec/spec_helper.rb"
57
+ "spec/spec_helper.rb",
58
+ "spec/support/database_cleaner.rb"
45
59
  ]
46
- s.homepage = "http://github.com/proton/mongoid_rateable"
47
- s.licenses = ["MIT"]
48
- s.rubygems_version = "2.2.2"
49
- s.summary = "Rating functionality for Mongoid documents"
60
+ s.homepage = "http://github.com/proton/mongoid_rateable".freeze
61
+ s.licenses = ["MIT".freeze]
62
+ s.rubygems_version = "3.4.6".freeze
63
+ s.summary = "Rating functionality for Mongoid documents".freeze
50
64
 
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 4
65
+ s.specification_version = 4
53
66
 
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<mongoid>, ["~> 3.0"])
56
- s.add_development_dependency(%q<bundler>, ["~> 1"])
57
- s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
58
- s.add_development_dependency(%q<simplecov>, ["~> 0.4"])
59
- s.add_development_dependency(%q<rdoc>, ["~> 3"])
60
- s.add_development_dependency(%q<rspec>, ["~> 2.0"])
61
- s.add_development_dependency(%q<database_cleaner>, ["~> 0"])
62
- else
63
- s.add_dependency(%q<mongoid>, ["~> 3.0"])
64
- s.add_dependency(%q<bundler>, ["~> 1"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.6"])
66
- s.add_dependency(%q<simplecov>, ["~> 0.4"])
67
- s.add_dependency(%q<rdoc>, ["~> 3"])
68
- s.add_dependency(%q<rspec>, ["~> 2.0"])
69
- s.add_dependency(%q<database_cleaner>, ["~> 0"])
70
- end
71
- else
72
- s.add_dependency(%q<mongoid>, ["~> 3.0"])
73
- s.add_dependency(%q<bundler>, ["~> 1"])
74
- s.add_dependency(%q<jeweler>, ["~> 1.6"])
75
- s.add_dependency(%q<simplecov>, ["~> 0.4"])
76
- s.add_dependency(%q<rdoc>, ["~> 3"])
77
- s.add_dependency(%q<rspec>, ["~> 2.0"])
78
- s.add_dependency(%q<database_cleaner>, ["~> 0"])
79
- end
67
+ s.add_runtime_dependency(%q<mongoid>.freeze, [">= 3.0"])
68
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
69
+ s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.1.1"])
70
+ s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.7"])
71
+ s.add_development_dependency(%q<yard>.freeze, [">= 0"])
72
+ s.add_development_dependency(%q<rspec>.freeze, [">= 3.0.0"])
73
+ s.add_development_dependency(%q<appraisal>.freeze, [">= 0"])
74
+ s.add_development_dependency(%q<coveralls>.freeze, [">= 0"])
75
+ s.add_development_dependency(%q<database_cleaner-mongoid>.freeze, ["~> 2.0", ">= 2.0.1"])
80
76
  end
81
77
 
data/spec/models/post.rb CHANGED
@@ -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
data/spec/models/user.rb CHANGED
@@ -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
data/spec/spec_helper.rb CHANGED
@@ -1,35 +1,43 @@
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/mongoid'
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
 
21
- DatabaseCleaner.orm = "mongoid"
25
+ if Mongoid::VERSION>'5'
26
+ Mongo::Logger.logger.level = ::Logger::FATAL
27
+ end
28
+
29
+ Dir["#{MODELS}/*.rb"].each { |f| require f }
22
30
 
23
31
  RSpec.configure do |config|
24
32
  config.before(:all) do
25
- DatabaseCleaner.strategy = :truncation
33
+ DatabaseCleaner[:mongoid].strategy = :deletion
26
34
  end
27
35
 
28
36
  config.before(:each) do
29
- DatabaseCleaner.start
37
+ DatabaseCleaner[:mongoid].start
30
38
  end
31
39
 
32
40
  config.after(:each) do
33
- DatabaseCleaner.clean
41
+ DatabaseCleaner[:mongoid].clean
34
42
  end
35
43
  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