parole 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: def12cc4e8ebdfb3f39c397a95eef9443af3822f
4
- data.tar.gz: a7addb2a86084f9267e34de818f1f9f20d59745c
3
+ metadata.gz: 838fd260344d7edc5895fdb763bf4c620916096f
4
+ data.tar.gz: 38e7429fd0ea23bc0b95f92154c779624225c007
5
5
  SHA512:
6
- metadata.gz: 3d9e9c53c499ace305e53f61f1e2c2f0f6deebeff566bd1b4f7849e774f1ba8373e29ed3e3c52fe0e958863b6eeeb3b4c51c96874ff3e6e3b24a6d1378d32bfc
7
- data.tar.gz: cf0aea744c44063f9f4c15a35f9805e243071dc93433174026bd9d1bed125e106830c9bc3c3d695adde127b56198cd8af6730b9b07e3c5a74312f22902b033dd
6
+ metadata.gz: f0c2609fa1850536ceae8464d4ff7a2f4084ca7a2128715dfedc1ffc639f8957e2221153f5b883ebd436c111ccaa26d5d16203b5905146bb3a02e445c9a26c38
7
+ data.tar.gz: 0b45b10e8f8626506bb981e02ee5b7ff5feb362d112d0183a9c6692ad142972b23f072bc6738fd2efe0d2f90d17411294331746da1860941e67b9345de2aa8ef
@@ -8,3 +8,11 @@ gemfile:
8
8
  - gemfiles/Gemfile.activerecord-4.0
9
9
 
10
10
  script: "echo 'DO IT' && bundle exec rake spec"
11
+
12
+ notifications:
13
+ hipchat:
14
+ rooms:
15
+ secure: "kgVFUfn1gDlKVX9kIWC7AWaxhBa+nLI9R9I25BcvvbqstMVtQAEu5qfKYUvFGDlYU7R9lSNiwz55nGxAnr7izh1dLd40phlBTWH0tWx6QvjQ14M4xwWYoLjj+rif2izR3lEZS+rJdVYNfUjocVHUnDiFQqH3gZzyfETmQGOwR6k="
16
+ template:
17
+ - '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Build</a>/<a href="%{compare_url}">Changes</a>)'
18
+ format: 'html'
@@ -0,0 +1,5 @@
1
+ # Parole Changelog
2
+
3
+ ## v0.1.4
4
+
5
+ * Add cache counter for commenter model
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013, Mirego
1
+ Copyright (c) 2013-2015, Mirego
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -5,11 +5,12 @@
5
5
  <br />
6
6
  Parole adds the ability to comment on ActiveRecord records.
7
7
  <br /><br />
8
- <a href="https://rubygems.org/gems/parole"><img src="https://badge.fury.io/rb/parole.png" /></a>
9
- <a href="https://codeclimate.com/github/mirego/parole"><img src="https://codeclimate.com/github/mirego/parole.png" /></a>
10
- <a href="https://travis-ci.org/mirego/parole"><img src="https://travis-ci.org/mirego/parole.png?branch=master" /></a>
8
+ <a href="https://rubygems.org/gems/parole"><img src="http://img.shields.io/gem/v/parole.svg" /></a>
9
+ <a href="https://codeclimate.com/github/mirego/parole"><img src="http://img.shields.io/codeclimate/github/mirego/parole.svg" /></a>
10
+ <a href="https://travis-ci.org/mirego/parole"><img src="http://img.shields.io/travis/mirego/parole.svg" /></a>
11
11
  </p>
12
12
 
13
+
13
14
  ---
14
15
 
15
16
  ## Installation
@@ -63,17 +64,23 @@ article.comments.count # => 1
63
64
 
64
65
  ### Cache counters
65
66
 
66
- Whenever a comment is created or destroyed, Parole looks into the commentable record and check
67
- if there’s a `<role>_comments_count` column and/or a `comments_count` column. If so, it updates
68
- them so they reflect the total number of comments and the number of comments of this role for
69
- the record.
67
+ Whenever a comment is created or destroyed, Parole looks into the commentable record and the commenter
68
+ record and check if there’s a `<role>_comments_count` column and/or a `comments_count` column.
69
+ If so, it updates them so they reflect the total number of comments and the number of comments
70
+ of this role for the record.
71
+
72
+ _Note:_ The commenter model must implements a `has_many` relationship that fetch its comments.
70
73
 
71
- So let’s say the `Article` model has the following columns: `photos_comments_count`, `videos_comments_count` and `comments_count`.
74
+ So let’s say the `Article` model has the following columns: `photos_comments_count`, `videos_comments_count` and `comments_count`,
75
+ and the `User` model has the following column: `comments_count`.
72
76
 
73
77
  ```ruby
74
78
  class Article < ActiveRecord::Base
75
79
  acts_as_commentable roles: [:photos, :videos]
76
80
  end
81
+ class User < ActiveRecord::Base
82
+ has_many :comments, -> { where(commenter_type: 'User') }, foreign_key: :commenter_id
83
+ end
77
84
 
78
85
  user = User.find(1)
79
86
  article = Article.find(1)
@@ -82,19 +89,21 @@ article.photos_comments.create(commenter: user, comment: 'Hello world!')
82
89
  article.photos_comments_count # => 1
83
90
  article.videos_comments_count # => 0
84
91
  article.comments_count # => 1
92
+ user.comments_count # => 1
85
93
 
86
94
  article.videos_comments.create(commenter: user, comment: 'Hello world again!')
87
95
  article.photos_comments_count # => 1
88
96
  article.videos_comments_count # => 1
89
97
  article.comments_count # => 2
98
+ user.comments_count # => 2
90
99
  ```
91
100
 
92
101
  ## License
93
102
 
94
- `Parole` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/parole/blob/master/LICENSE.md) file.
103
+ `Parole` is © 2013-2015 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/parole/blob/master/LICENSE.md) file.
95
104
 
96
105
  ## About Mirego
97
106
 
98
- Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
107
+ [Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org).
99
108
 
100
- We also love [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community.
109
+ We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.
@@ -24,19 +24,28 @@ module Parole
24
24
  # Update the commentable cache counter columns
25
25
  #
26
26
  # Look for a `<role>_comments_count` and a `comments_count` column
27
- # in the commentable model and update their value with the count.
27
+ # in the commentable model and the commenter model and update their value with the count.
28
28
  def update_cache_counters
29
+ commenter_has_comments = commenter.respond_to?(:comments)
30
+
29
31
  role_method = :"#{self.role}_comments_count="
30
32
  if commentable.respond_to?(role_method)
31
33
  commentable.send role_method, commentable.comments.where(role: self.role).count
32
34
  end
35
+ if commenter_has_comments && commenter.respond_to?(role_method)
36
+ commenter.send role_method, commenter.comments.where(role: self.role).count
37
+ end
33
38
 
34
39
  total_method = :comments_count=
35
40
  if commentable.respond_to?(total_method)
36
41
  commentable.send total_method, commentable.comments.count
37
42
  end
43
+ if commenter_has_comments && commenter.respond_to?(total_method)
44
+ commenter.send total_method, commenter.comments.count
45
+ end
38
46
 
39
47
  commentable.save(validate: false)
48
+ commenter.save(validate: false)
40
49
  end
41
50
 
42
51
  # Make sure that the value of the `role` attribute is a valid role
@@ -1,3 +1,3 @@
1
1
  module Parole
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -124,13 +124,19 @@ describe Parole::Comment do
124
124
  describe :update_cache_counters do
125
125
  before do
126
126
  spawn_comment_model
127
- spawn_commenter_model 'User'
127
+ spawn_commenter_model 'User' do
128
+ has_many :comments, -> { where(commenter_type: 'User') }, foreign_key: :commenter_id
129
+ end
128
130
  spawn_commentable_model 'Article' do
129
131
  acts_as_commentable roles: [:photos, :videos]
130
132
  end
131
133
 
132
134
  run_migration do
133
- create_table(:users, force: true)
135
+ create_table(:users, force: true) do |t|
136
+ t.integer :photos_comments_count, default: 0
137
+ t.integer :videos_comments_count, default: 0
138
+ t.integer :comments_count, default: 0
139
+ end
134
140
  create_table(:articles, force: true) do |t|
135
141
  t.integer :photos_comments_count, default: 0
136
142
  t.integer :videos_comments_count, default: 0
@@ -143,9 +149,15 @@ describe Parole::Comment do
143
149
  let(:commentable) { Article.create }
144
150
  let(:create_comment!) { commentable.photos_comments.create(commenter: commenter, comment: 'Booya') }
145
151
 
152
+ # Commentable cache counter
146
153
  it { expect { create_comment! }.to change { commentable.reload.photos_comments_count }.from(0).to(1) }
147
154
  it { expect { create_comment! }.to_not change { commentable.reload.videos_comments_count } }
148
155
  it { expect { create_comment! }.to change { commentable.reload.comments_count }.from(0).to(1) }
156
+
157
+ # Commenter cache counter
158
+ it { expect { create_comment! }.to change { commenter.reload.photos_comments_count }.from(0).to(1) }
159
+ it { expect { create_comment! }.to_not change { commenter.reload.videos_comments_count } }
160
+ it { expect { create_comment! }.to change { commenter.reload.comments_count }.from(0).to(1) }
149
161
  end
150
162
  end
151
163
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
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: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
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
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.14'
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
68
  version: '2.14'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 4.0.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 4.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activesupport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 4.0.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 4.0.0
97
97
  description: Parole adds the ability to comment on ActiveRecord models.
@@ -101,9 +101,10 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - .gitignore
105
- - .rspec
106
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
107
108
  - Gemfile
108
109
  - LICENSE.md
109
110
  - README.md
@@ -133,17 +134,17 @@ require_paths:
133
134
  - lib
134
135
  required_ruby_version: !ruby/object:Gem::Requirement
135
136
  requirements:
136
- - - '>='
137
+ - - ">="
137
138
  - !ruby/object:Gem::Version
138
139
  version: '0'
139
140
  required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  requirements:
141
- - - '>='
142
+ - - ">="
142
143
  - !ruby/object:Gem::Version
143
144
  version: '0'
144
145
  requirements: []
145
146
  rubyforge_project:
146
- rubygems_version: 2.1.0
147
+ rubygems_version: 2.4.5
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: Parole adds the ability to comment on ActiveRecord models.