acts_as_commentable_with_threading 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -8,6 +8,6 @@ group :development do
8
8
  gem "rake", ">= 0"
9
9
  gem "bundler"
10
10
  gem "rspec", "~> 1.3"
11
- gem "sqlite3-ruby", ">= 0"
11
+ gem "sqlite3", ">= 0"
12
12
  gem "rails", "~> 3.2"
13
13
  end
@@ -75,8 +75,6 @@ GEM
75
75
  rack (~> 1.0)
76
76
  tilt (~> 1.1, != 1.3.0)
77
77
  sqlite3 (1.3.5)
78
- sqlite3-ruby (1.3.3)
79
- sqlite3 (>= 1.3.3)
80
78
  thor (0.14.6)
81
79
  tilt (1.3.3)
82
80
  treetop (1.4.10)
@@ -95,4 +93,4 @@ DEPENDENCIES
95
93
  rails (~> 3.2)
96
94
  rake
97
95
  rspec (~> 1.3)
98
- sqlite3-ruby
96
+ sqlite3
data/README.md CHANGED
@@ -81,16 +81,12 @@ Usage
81
81
 
82
82
  @comment.children
83
83
 
84
- * If you plan to use the `acts_as_voteable` plugin with your comment system be
84
+ * If you plan to use the `acts_as_votable` plugin with your comment system be
85
85
  sure to uncomment two things:
86
86
 
87
- * In `lib/comment.rb` uncomment the line [`acts_as_voteable`][L9].
88
-
89
- * In `lib/acts_as_commentable_with_threading.rb` uncomment the line
90
- [`include Juixe::Acts::Voteable`][L5] near the top.
87
+ * In `lib/comment.rb` uncomment the line [`acts_as_votable`][L9].
91
88
 
92
89
  [L9]: https://github.com/elight/acts_as_commentable_with_threading/blob/master/lib/generators/acts_as_commentable_with_threading_migration/templates/comment.rb#L9
93
- [L5]: https://github.com/elight/acts_as_commentable_with_threading/blob/master/lib/acts_as_commentable_with_threading.rb#L5
94
90
 
95
91
  Credits
96
92
  -------
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "acts_as_commentable_with_threading"
3
- s.version = "1.1.2"
4
- s.date = "2012-03-23"
3
+ s.version = "1.1.3"
4
+ s.date = "2013-04-18"
5
5
  s.summary = "Polymorphic comments Rails gem - Rails 3+ only"
6
6
  s.email = "evan@tripledogdare.net"
7
7
  s.homepage = "http://github.com/elight/acts_as_commentable_with_threading"
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.add_development_dependency 'rake'
14
14
  s.add_development_dependency 'bundler', '~> 1.0'
15
15
  s.add_development_dependency 'rspec', '~> 1.3'
16
- s.add_development_dependency 'sqlite3-ruby'
16
+ s.add_development_dependency 'sqlite3'
17
17
  s.add_development_dependency 'rails', '~> 3.0'
18
18
 
19
19
  s.add_dependency 'activerecord', '>= 3.0'
@@ -2,12 +2,11 @@ require 'active_record'
2
2
  require 'awesome_nested_set'
3
3
  ActiveRecord::Base.class_eval do
4
4
  include CollectiveIdea::Acts::NestedSet
5
- #include Juixe::Acts::Voteable #<-- uncomment this if you have installed and wish to use the acts_as_voteable plugin
6
5
  end
7
6
 
8
7
  #
9
8
  unless ActiveRecord::Base.respond_to?(:acts_as_nested_set)
10
- ActiveRecord::Base.send(:include, CollectiveIdea::Acts::NestedSet::Base)
9
+ ActiveRecord::Base.send(:include, CollectiveIdea::Acts::NestedSet::Base)
11
10
  end
12
11
 
13
12
  # ActsAsCommentableWithThreading
@@ -17,12 +16,13 @@ module Acts #:nodoc:
17
16
 
18
17
  module ClassMethods
19
18
  def acts_as_commentable
20
- has_many :comment_threads, :class_name => "Comment", :as => :commentable, :dependent => :destroy
19
+ has_many :comment_threads, :class_name => "Comment", :as => :commentable
20
+ before_destroy { |record| record.root_comments.destroy_all }
21
21
  include Acts::CommentableWithThreading::LocalInstanceMethods
22
22
  extend Acts::CommentableWithThreading::SingletonMethods
23
23
  end
24
24
  end
25
-
25
+
26
26
  # This module contains class methods
27
27
  module SingletonMethods
28
28
  # Helper method to lookup for comments for a given object.
@@ -30,34 +30,34 @@ module Acts #:nodoc:
30
30
  def find_comments_for(obj)
31
31
  Comment.where(:commentable_id => obj.id, :commentable_type => obj.class.base_class).order('created_at DESC')
32
32
  end
33
-
33
+
34
34
  # Helper class method to lookup comments for
35
- # the mixin commentable type written by a given user.
35
+ # the mixin commentable type written by a given user.
36
36
  # This method is NOT equivalent to Comment.find_comments_for_user
37
37
  def find_comments_by_user(user)
38
38
  commentable = self.base_class.name.to_s
39
39
  Comment.where(:user_id => user.id, :commentable_type => commentable).order('created_at DESC')
40
40
  end
41
41
  end
42
-
42
+
43
43
  module LocalInstanceMethods
44
-
44
+
45
45
  # Helper method to display only root threads, no children/replies
46
46
  def root_comments
47
47
  self.comment_threads.where(:parent_id => nil)
48
48
  end
49
-
49
+
50
50
  # Helper method to sort comments by date
51
51
  def comments_ordered_by_submitted
52
52
  Comment.where(:commentable_id => id, :commentable_type => self.class.name).order('created_at DESC')
53
53
  end
54
-
54
+
55
55
  # Helper method that defaults the submitted time.
56
56
  def add_comment(comment)
57
57
  comments << comment
58
58
  end
59
59
  end
60
-
60
+
61
61
  end
62
62
  end
63
63
 
@@ -1,12 +1,12 @@
1
1
  class Comment < ActiveRecord::Base
2
2
  acts_as_nested_set :scope => [:commentable_id, :commentable_type]
3
3
 
4
- validates_presence_of :body
5
- validates_presence_of :user
4
+ validates :body, :presence => true
5
+ validates :user, :presence => true
6
6
 
7
7
  # NOTE: install the acts_as_votable plugin if you
8
8
  # want user to vote on the quality of comments.
9
- #acts_as_voteable
9
+ #acts_as_votable
10
10
 
11
11
  belongs_to :commentable, :polymorphic => true
12
12
 
@@ -17,12 +17,10 @@ class Comment < ActiveRecord::Base
17
17
  # by passing a commentable object, a user_id, and comment text
18
18
  # example in readme
19
19
  def self.build_from(obj, user_id, comment)
20
- c = self.new
21
- c.commentable_id = obj.id
22
- c.commentable_type = obj.class.base_class.name
23
- c.body = comment
24
- c.user_id = user_id
25
- c
20
+ new \
21
+ :commentable => obj,
22
+ :body => comment,
23
+ :user_id => user_id
26
24
  end
27
25
 
28
26
  #helper method to check if a comment has children
@@ -1,12 +1,12 @@
1
1
  class Comment < ActiveRecord::Base
2
2
  acts_as_nested_set :scope => [:commentable_id, :commentable_type]
3
3
 
4
- validates_presence_of :body
5
- validates_presence_of :user
4
+ validates :body, :presence => true
5
+ validates :user, :presence => true
6
6
 
7
7
  # NOTE: install the acts_as_votable plugin if you
8
8
  # want user to vote on the quality of comments.
9
- #acts_as_voteable
9
+ #acts_as_votable
10
10
 
11
11
  belongs_to :commentable, :polymorphic => true
12
12
 
@@ -17,17 +17,15 @@ class Comment < ActiveRecord::Base
17
17
  # by passing a commentable object, a user_id, and comment text
18
18
  # example in readme
19
19
  def self.build_from(obj, user_id, comment)
20
- c = self.new
21
- c.commentable_id = obj.id
22
- c.commentable_type = obj.class.base_class.name
23
- c.body = comment
24
- c.user_id = user_id
25
- c
20
+ new \
21
+ :commentable => obj,
22
+ :body => comment,
23
+ :user_id => user_id
26
24
  end
27
25
 
28
26
  #helper method to check if a comment has children
29
27
  def has_children?
30
- self.children.size > 0
28
+ self.children.any?
31
29
  end
32
30
 
33
31
  # Helper class method to lookup all comments assigned
@@ -12,7 +12,7 @@ class ActsAsCommentableWithThreadingMigration < ActiveRecord::Migration
12
12
  end
13
13
 
14
14
  add_index :comments, :user_id
15
- add_index :comments, :commentable_id
15
+ add_index :comments, [:commentable_id, :commentable_type]
16
16
  end
17
17
 
18
18
  def self.down
@@ -5,6 +5,29 @@ describe "A class that is commentable" do
5
5
  Commentable.new.comment_threads.should be_a_kind_of(Enumerable)
6
6
  end
7
7
 
8
+ describe "when is destroyed" do
9
+ before :each do
10
+ @user = User.create!
11
+ @commentable = Commentable.create!
12
+ @comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'blargh')
13
+ end
14
+
15
+ it "also destroys its root comments" do
16
+ @commentable.destroy
17
+ Comment.all.should_not include(@comment)
18
+ end
19
+
20
+ it "also destroys its nested comments" do
21
+ child = Comment.new(:body => "This is a child", :commentable => @commentable, :user => @user)
22
+ child.save!
23
+ child.move_to_child_of(@comment)
24
+
25
+ @commentable.destroy
26
+ Comment.all.should_not include(@comment)
27
+ Comment.all.should_not include(child)
28
+ end
29
+ end
30
+
8
31
  describe "special class finders" do
9
32
  before :each do
10
33
  @user = User.create!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_commentable_with_threading
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-03-23 00:00:00.000000000 Z
15
+ date: 2013-04-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -63,7 +63,7 @@ dependencies:
63
63
  - !ruby/object:Gem::Version
64
64
  version: '1.3'
65
65
  - !ruby/object:Gem::Dependency
66
- name: sqlite3-ruby
66
+ name: sqlite3
67
67
  requirement: !ruby/object:Gem::Requirement
68
68
  none: false
69
69
  requirements:
@@ -185,6 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  - - ! '>='
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
+ segments:
189
+ - 0
190
+ hash: -1968228787496291367
188
191
  required_rubygems_version: !ruby/object:Gem::Requirement
189
192
  none: false
190
193
  requirements:
@@ -193,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
196
  version: '0'
194
197
  requirements: []
195
198
  rubyforge_project:
196
- rubygems_version: 1.8.21
199
+ rubygems_version: 1.8.25
197
200
  signing_key:
198
201
  specification_version: 3
199
202
  summary: Polymorphic comments Rails gem - Rails 3+ only