mongoid-likeable 2.0.1 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ 3.0
2
+ ---
3
+ * Touches model when liking
4
+ * Updated dependencies
5
+ * Improved Code Climate Badge
6
+
7
+ 2.1
8
+ ---
9
+ * Touches updated_at attribute when available
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # mongoid-likeable [![Build Status](https://secure.travis-ci.org/diowa/mongoid-likeable.png?branch=master)](https://travis-ci.org/diowa/mongoid-likeable) [![Dependency Status](https://gemnasium.com/diowa/mongoid-likeable.png)](https://gemnasium.com/diowa/mongoid-likeable) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/diowa/mongoid-likeable)
1
+ # mongoid-likeable [![Build Status](https://secure.travis-ci.org/diowa/mongoid-likeable.png?branch=master)](https://travis-ci.org/diowa/mongoid-likeable) [![Dependency Status](https://gemnasium.com/diowa/mongoid-likeable.png)](https://gemnasium.com/diowa/mongoid-likeable) [![Code Climate](https://codeclimate.com/github/diowa/mongoid-likeable.png)](https://codeclimate.com/github/diowa/mongoid-likeable)
2
2
 
3
3
  Add like to your Mongoid documents.
4
4
  This is a fork of `tombell/mongoid-voteable` for people who only need likes.
@@ -57,4 +57,5 @@ not called `_id` you can still pass the ID in as the second parameter instead.
57
57
  ## License
58
58
 
59
59
  mongoid-likeable is licensed under the BSD 2-Clause License
60
+
60
61
  mongoid-voteable is licensed under the MIT License - Copyright (c) 2012 Tom Bell
@@ -15,6 +15,7 @@ module Mongoid
15
15
  unless liked?(id)
16
16
  self.inc :likes, 1
17
17
  self.push :likers, id
18
+ self.touch
18
19
  end
19
20
  end
20
21
 
@@ -23,6 +24,7 @@ module Mongoid
23
24
  if liked?(id)
24
25
  self.inc :likes, -1
25
26
  self.pull :likers, id
27
+ self.touch
26
28
  end
27
29
  end
28
30
 
@@ -41,5 +43,4 @@ module Mongoid
41
43
  end
42
44
  end
43
45
  end
44
-
45
46
  end
@@ -1,25 +1,27 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "mongoid-likeable"
6
- s.version = "2.0.1"
5
+ s.name = 'mongoid-likeable'
6
+ s.version = '3.0'
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["Diowa"]
9
- s.email = ["dev@diowa.com"]
10
- s.homepage = "https://github.com/diowa/mongoid-likeable"
11
- s.summary = "Add likes to your Mongoid documents"
8
+ s.authors = ['Diowa']
9
+ s.email = ['dev@diowa.com']
10
+ s.homepage = 'https://github.com/diowa/mongoid-likeable'
11
+ s.summary = 'Add likes to your Mongoid documents'
12
12
  s.description = s.summary
13
13
 
14
- s.rubyforge_project = "mongoid-likeable"
14
+ s.rubyforge_project = 'mongoid-likeable'
15
15
 
16
- s.add_dependency "mongoid", "~> 3.0.11"
16
+ s.add_dependency 'mongoid', '~> 3.1.0'
17
17
 
18
- s.add_development_dependency "database_cleaner", "~> 0.9.1"
19
- s.add_development_dependency "rake", "~> 10.0.1"
18
+ s.add_development_dependency 'database_cleaner', '~> 0.9.1'
19
+ s.add_development_dependency 'rake', '~> 10.0.3'
20
+ s.add_development_dependency 'debugger'
21
+ s.add_development_dependency 'delorean'
20
22
 
21
23
  s.files = `git ls-files`.split("\n")
22
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
25
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
- s.require_paths = ["lib"]
26
+ s.require_paths = ['lib']
25
27
  end
@@ -0,0 +1,7 @@
1
+ class StoryWithTimestamps
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Likeable
5
+
6
+ field :name
7
+ end
@@ -1,4 +1,6 @@
1
1
  require 'test_helper'
2
+ require 'debugger'
3
+ require 'delorean'
2
4
 
3
5
  class TestMongoidLikeable < MiniTest::Unit::TestCase
4
6
  def setup
@@ -7,10 +9,12 @@ class TestMongoidLikeable < MiniTest::Unit::TestCase
7
9
  @simon = User.create name: 'Simon'
8
10
  @emily = User.create name: 'Emily'
9
11
  @story = Story.create name: 'Mongoid Rocks'
12
+ Delorean.time_travel_to(5.minutes.ago) { @story_with_timestamps = StoryWithTimestamps.create name: 'Mongoid Rocks' }
10
13
  end
11
14
 
12
15
  def teardown
13
16
  DatabaseCleaner.clean
17
+ Delorean.back_to_the_present
14
18
  end
15
19
 
16
20
  def test_add_likes_field_to_document
@@ -23,17 +27,17 @@ class TestMongoidLikeable < MiniTest::Unit::TestCase
23
27
 
24
28
  def test_defines_like_method
25
29
  story = Story.new
26
- refute_nil story.respond_to?('like')
30
+ assert story.respond_to?('like')
27
31
  end
28
32
 
29
33
  def test_defines_unlike_method
30
34
  story = Story.new
31
- refute_nil story.respond_to?('unlike')
35
+ assert story.respond_to?('unlike')
32
36
  end
33
37
 
34
38
  def test_defines_liked_method
35
39
  story = Story.new
36
- refute_nil story.respond_to?('liked?')
40
+ assert story.respond_to?('liked?')
37
41
  end
38
42
 
39
43
  def test_tracks_number_of_likers
@@ -84,4 +88,52 @@ class TestMongoidLikeable < MiniTest::Unit::TestCase
84
88
  refute story.liked? @simon
85
89
  assert story.liked? @emily
86
90
  end
91
+
92
+ def test_touches_updated_at_when_liking
93
+ updated_at = @story_with_timestamps.updated_at
94
+ Delorean.time_travel_to(1.month.from_now) { @story_with_timestamps.like @simon }
95
+ assert @story_with_timestamps.updated_at > updated_at
96
+ end
97
+
98
+ def test_does_not_touche_updated_at_when_liking_without_success
99
+ @story_with_timestamps.like @simon
100
+ updated_at = @story_with_timestamps.updated_at
101
+ Delorean.time_travel_to(1.month.from_now) { @story_with_timestamps.like @simon }
102
+ assert @story_with_timestamps.updated_at == updated_at
103
+ end
104
+
105
+ def test_touches_updated_at_when_unliking
106
+ @story_with_timestamps.like @simon
107
+ updated_at = @story_with_timestamps.updated_at
108
+ Delorean.time_travel_to(1.month.from_now) { @story_with_timestamps.unlike @simon }
109
+ assert @story_with_timestamps.updated_at > updated_at
110
+ end
111
+
112
+ def test_does_not_touche_updated_at_when_unliking_without_success
113
+ updated_at = @story_with_timestamps.updated_at
114
+ Delorean.time_travel_to(1.month.from_now) { @story_with_timestamps.unlike @simon }
115
+ assert @story_with_timestamps.updated_at == updated_at
116
+ end
117
+
118
+ def test_touches_updated_at_and_updates_collection_correctly
119
+ updated_at = @story_with_timestamps.updated_at
120
+ Delorean.time_travel_to(1.month.from_now) do
121
+ @story_with_timestamps.like @simon
122
+ @story_with_timestamps.like @emily
123
+ end
124
+ story = StoryWithTimestamps.where(:name => 'Mongoid Rocks').first
125
+ assert_equal 2, story.likes
126
+ assert story.liked? @simon
127
+ assert story.liked? @emily
128
+ assert story.updated_at > updated_at
129
+ updated_at = @story_with_timestamps.updated_at
130
+ Delorean.time_travel_to(1.month.from_now) do
131
+ story.unlike @simon
132
+ end
133
+ story = StoryWithTimestamps.where(:name => 'Mongoid Rocks').first
134
+ assert_equal 1, story.likes
135
+ refute story.liked? @simon
136
+ assert story.liked? @emily
137
+ assert story.updated_at > updated_at
138
+ end
87
139
  end
data/test/test_helper.rb CHANGED
@@ -6,6 +6,11 @@ require 'database_cleaner'
6
6
  require 'mongoid'
7
7
  require 'mongoid/likeable'
8
8
 
9
+ require 'debugger'
10
+ if defined?(Debugger)
11
+ ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
12
+ end
13
+
9
14
  Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |f| require f }
10
15
 
11
16
  Mongoid.connect_to('mongoid-likeable-test')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-likeable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: '3.0'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.11
21
+ version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.0.11
29
+ version: 3.1.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: database_cleaner
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 10.0.1
53
+ version: 10.0.3
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,39 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 10.0.1
61
+ version: 10.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: debugger
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: delorean
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
62
94
  description: Add likes to your Mongoid documents
63
95
  email:
64
96
  - dev@diowa.com
@@ -68,6 +100,7 @@ extra_rdoc_files: []
68
100
  files:
69
101
  - .gitignore
70
102
  - .travis.yml
103
+ - CHANGELOG.md
71
104
  - Gemfile
72
105
  - LICENSE
73
106
  - README.md
@@ -75,6 +108,7 @@ files:
75
108
  - lib/mongoid/likeable.rb
76
109
  - mongoid-likeable.gemspec
77
110
  - test/models/story.rb
111
+ - test/models/story_with_timestamps.rb
78
112
  - test/models/user.rb
79
113
  - test/mongoid_likeable_test.rb
80
114
  - test/test_helper.rb
@@ -102,8 +136,4 @@ rubygems_version: 1.8.24
102
136
  signing_key:
103
137
  specification_version: 3
104
138
  summary: Add likes to your Mongoid documents
105
- test_files:
106
- - test/models/story.rb
107
- - test/models/user.rb
108
- - test/mongoid_likeable_test.rb
109
- - test/test_helper.rb
139
+ test_files: []