acts_as_commentable_with_threading 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -5
- data/Gemfile.lock +85 -69
- data/README.md +74 -62
- data/Rakefile +4 -5
- data/acts_as_commentable_with_threading.gemspec +6 -6
- data/lib/acts_as_commentable_with_threading.rb +1 -1
- data/lib/generators/acts_as_commentable_upgrade_migration/comment.rb +15 -13
- data/lib/generators/acts_as_commentable_with_threading_migration/templates/comment.rb +15 -13
- data/rails/init.rb +0 -4
- data/spec/commentable_spec.rb +11 -11
- data/spec/db/schema.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +123 -132
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Generated from /Users/light/work/my/acts_as_commentable_with_threading/acts_as_commentable_with_threading.gemspec
|
2
2
|
source :gemcutter
|
3
|
-
gem "activerecord", "~> 3.
|
4
|
-
gem "activesupport", "~> 3.
|
5
|
-
gem "
|
3
|
+
gem "activerecord", "~> 3.2"
|
4
|
+
gem "activesupport", "~> 3.2"
|
5
|
+
gem "awesome_nested_set", "~> 2.0.0"
|
6
6
|
|
7
7
|
group :development do
|
8
8
|
gem "rake", ">= 0"
|
9
|
-
gem "bundler"
|
9
|
+
gem "bundler"
|
10
10
|
gem "rspec", "~> 1.3"
|
11
11
|
gem "sqlite3-ruby", ">= 0"
|
12
|
-
gem "rails", "~> 3.
|
12
|
+
gem "rails", "~> 3.2"
|
13
13
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,82 +1,98 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rack (~> 1.
|
15
|
-
rack-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
arel (
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
rack-
|
4
|
+
actionmailer (3.2.2)
|
5
|
+
actionpack (= 3.2.2)
|
6
|
+
mail (~> 2.4.0)
|
7
|
+
actionpack (3.2.2)
|
8
|
+
activemodel (= 3.2.2)
|
9
|
+
activesupport (= 3.2.2)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.1)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.1)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.2)
|
17
|
+
activemodel (3.2.2)
|
18
|
+
activesupport (= 3.2.2)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.2)
|
21
|
+
activemodel (= 3.2.2)
|
22
|
+
activesupport (= 3.2.2)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.2)
|
26
|
+
activemodel (= 3.2.2)
|
27
|
+
activesupport (= 3.2.2)
|
28
|
+
activesupport (3.2.2)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
awesome_nested_set (2.0.2)
|
33
|
+
activerecord (>= 3.0.0)
|
34
|
+
builder (3.0.0)
|
35
|
+
erubis (2.7.0)
|
36
|
+
hike (1.2.1)
|
37
|
+
i18n (0.6.0)
|
38
|
+
journey (1.0.3)
|
39
|
+
json (1.6.5)
|
40
|
+
mail (2.4.4)
|
41
|
+
i18n (>= 0.4.0)
|
42
|
+
mime-types (~> 1.16)
|
43
|
+
treetop (~> 1.4.8)
|
44
|
+
mime-types (1.18)
|
45
|
+
multi_json (1.1.0)
|
46
|
+
polyglot (0.3.3)
|
47
|
+
rack (1.4.1)
|
48
|
+
rack-cache (1.2)
|
49
|
+
rack (>= 0.4)
|
50
|
+
rack-ssl (1.3.2)
|
51
|
+
rack
|
52
|
+
rack-test (0.6.1)
|
49
53
|
rack (>= 1.0)
|
50
|
-
rails (3.
|
51
|
-
actionmailer (= 3.
|
52
|
-
actionpack (= 3.
|
53
|
-
activerecord (= 3.
|
54
|
-
activeresource (= 3.
|
55
|
-
activesupport (= 3.
|
56
|
-
bundler (~> 1.0
|
57
|
-
railties (= 3.
|
58
|
-
railties (3.
|
59
|
-
actionpack (= 3.
|
60
|
-
activesupport (= 3.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
54
|
+
rails (3.2.2)
|
55
|
+
actionmailer (= 3.2.2)
|
56
|
+
actionpack (= 3.2.2)
|
57
|
+
activerecord (= 3.2.2)
|
58
|
+
activeresource (= 3.2.2)
|
59
|
+
activesupport (= 3.2.2)
|
60
|
+
bundler (~> 1.0)
|
61
|
+
railties (= 3.2.2)
|
62
|
+
railties (3.2.2)
|
63
|
+
actionpack (= 3.2.2)
|
64
|
+
activesupport (= 3.2.2)
|
65
|
+
rack-ssl (~> 1.3.2)
|
66
|
+
rake (>= 0.8.7)
|
67
|
+
rdoc (~> 3.4)
|
68
|
+
thor (~> 0.14.6)
|
69
|
+
rake (0.9.2.2)
|
70
|
+
rdoc (3.12)
|
71
|
+
json (~> 1.4)
|
72
|
+
rspec (1.3.2)
|
73
|
+
sprockets (2.1.2)
|
74
|
+
hike (~> 1.2)
|
75
|
+
rack (~> 1.0)
|
76
|
+
tilt (~> 1.1, != 1.3.0)
|
77
|
+
sqlite3 (1.3.5)
|
78
|
+
sqlite3-ruby (1.3.3)
|
79
|
+
sqlite3 (>= 1.3.3)
|
80
|
+
thor (0.14.6)
|
81
|
+
tilt (1.3.3)
|
82
|
+
treetop (1.4.10)
|
83
|
+
polyglot
|
68
84
|
polyglot (>= 0.3.1)
|
69
|
-
tzinfo (0.3.
|
85
|
+
tzinfo (0.3.32)
|
70
86
|
|
71
87
|
PLATFORMS
|
72
88
|
ruby
|
73
89
|
|
74
90
|
DEPENDENCIES
|
75
|
-
activerecord (~> 3.
|
76
|
-
activesupport (~> 3.
|
77
|
-
|
78
|
-
|
79
|
-
rails (~> 3.
|
91
|
+
activerecord (~> 3.2)
|
92
|
+
activesupport (~> 3.2)
|
93
|
+
awesome_nested_set (~> 2.0.0)
|
94
|
+
bundler
|
95
|
+
rails (~> 3.2)
|
80
96
|
rake
|
81
97
|
rspec (~> 1.3)
|
82
98
|
sqlite3-ruby
|
data/README.md
CHANGED
@@ -1,98 +1,110 @@
|
|
1
|
-
Acts As Commentable (now with comment threads
|
1
|
+
Acts As Commentable (now with comment threads(TM)!!! -- kidding on the (TM))
|
2
2
|
===================
|
3
3
|
|
4
|
-
Allows for threaded comments to be added to multiple and different models.
|
4
|
+
Allows for threaded comments to be added to multiple and different models.
|
5
|
+
Drop-in compatible for acts_as_commentable (however requiring a database
|
6
|
+
schema change)
|
5
7
|
|
6
8
|
Requirements
|
7
9
|
------------
|
8
|
-
|
9
10
|
This gem is for Rails 3 and later versions only.
|
10
11
|
|
11
|
-
This gem depends on
|
12
|
+
This gem depends on CollectiveIdea's Awesome Nested Set gem. It is installed if
|
13
|
+
not already present when you install this gem.
|
14
|
+
|
15
|
+
You can find the gem on GitHub at [collectiveidea/awesome_nested_set]
|
12
16
|
|
13
|
-
|
17
|
+
[collectiveidea/awesome_nested_set]: https://github.com/collectiveidea/awesome_nested_set
|
14
18
|
|
15
19
|
Install
|
16
20
|
-------
|
21
|
+
In your Gemfile, add:
|
17
22
|
|
18
|
-
In your Gemfile, add
|
19
23
|
gem 'acts_as_commentable_with_threading'
|
20
24
|
|
21
25
|
and run `bundle install`.
|
22
|
-
|
26
|
+
|
23
27
|
Migrations
|
24
28
|
----------
|
25
|
-
|
26
29
|
* To install from scratch:
|
27
30
|
|
28
|
-
|
31
|
+
rails generate acts_as_commentable_with_threading_migration
|
32
|
+
|
33
|
+
This will generate the migration script necessary for the table
|
34
|
+
|
35
|
+
* To upgrade to acts_as_commentable_with_threading from the
|
36
|
+
old acts_as_commentable:
|
37
|
+
|
38
|
+
rails generate acts_as_commentable_upgrade_migration
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
* To upgrade to acts_as_commentable_with_threading from the old acts_as_commentable:
|
40
|
+
This will generate the necessary migration to upgrade your comments
|
41
|
+
table to work with acts_as_commentable_with_threading
|
33
42
|
|
34
|
-
|
43
|
+
If the generators fail, you can just as easily create the migrations by hand.
|
44
|
+
See the templates in the generators under [`lib/generators`].
|
35
45
|
|
36
|
-
|
46
|
+
[`lib/generators`]: https://github.com/elight/acts_as_commentable_with_threading/tree/master/lib/generators
|
37
47
|
|
38
|
-
If the generators fail, you can just as easily create the migrations by hand. See the templates in the generators under `lib/generators`.
|
39
|
-
|
40
48
|
Usage
|
41
49
|
-----
|
42
50
|
class Article < ActiveRecord::Base
|
43
51
|
acts_as_commentable
|
44
52
|
end
|
45
|
-
|
46
|
-
* Add a comment to a model instance, for example an Article
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
* To make a newly created comment into a child/reply of another comment
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
* To retrieve all comments for an article, including child comments
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
* To retrieve only the root comments without their
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
* To check if a comment has children
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
* To verify the number of children a comment has
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
* To retrieve a
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
53
|
+
|
54
|
+
* Add a comment to a model instance, for example an Article:
|
55
|
+
|
56
|
+
@article = Article.find(params[:id])
|
57
|
+
@user_who_commented = @current_user
|
58
|
+
@comment = Comment.build_from( @article, @user_who_commented.id, "Hey guys this is my comment!" )
|
59
|
+
|
60
|
+
* To make a newly created comment into a child/reply of another comment:
|
61
|
+
|
62
|
+
comment.move_to_child_of(the_desired_parent_comment)
|
63
|
+
|
64
|
+
* To retrieve all comments for an article, including child comments:
|
65
|
+
|
66
|
+
@all_comments = @article.comment_threads
|
67
|
+
|
68
|
+
* To retrieve only the root comments without their child comments:
|
69
|
+
|
70
|
+
@root_comments = @article.root_comments
|
71
|
+
|
72
|
+
* To check if a comment has children:
|
73
|
+
|
74
|
+
@comment.has_children?
|
75
|
+
|
76
|
+
* To verify the number of children a comment has:
|
77
|
+
|
78
|
+
@comment.children.size
|
79
|
+
|
80
|
+
* To retrieve a comment's children:
|
81
|
+
|
82
|
+
@comment.children
|
83
|
+
|
84
|
+
* If you plan to use the `acts_as_voteable` plugin with your comment system be
|
85
|
+
sure to uncomment two things:
|
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.
|
91
|
+
|
92
|
+
[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
|
+
|
83
95
|
Credits
|
84
96
|
-------
|
85
|
-
xxx - For contributing the updates for Rails 3!
|
97
|
+
* [xxx](https://github.com/xxx) - For contributing the updates for Rails 3!
|
98
|
+
* [Jack Dempsey](https://github.com/jackdempsey) - This plugin/gem is heavily
|
99
|
+
influenced/liberally borrowed/stolen from [acts_as_commentable].
|
86
100
|
|
87
|
-
|
101
|
+
And in turn...
|
88
102
|
|
89
|
-
|
103
|
+
* Xelipe - Because acts_as_commentable was heavily influenced by Acts As Taggable.
|
90
104
|
|
91
|
-
|
105
|
+
[acts_as_commentable]: https://github.com/jackdempsey/acts_as_commentable
|
92
106
|
|
93
107
|
More
|
94
108
|
----
|
95
|
-
|
96
|
-
[http://
|
97
|
-
|
98
|
-
[http://evan.tiggerpalace.com](http://evan.tiggerpalace.com)
|
109
|
+
* [http://tripledogdare.net](http://tripledogdare.net)
|
110
|
+
* [http://evan.tiggerpalace.com](http://evan.tiggerpalace.com)
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rubygems/package_task'
|
3
4
|
require 'spec'
|
4
5
|
require 'spec/rake/spectask'
|
5
|
-
require 'bundler/setup'
|
6
6
|
|
7
7
|
PLUGIN = "acts_as_commentable_with_threading"
|
8
8
|
NAME = "acts_as_commentable_with_threading"
|
@@ -11,10 +11,9 @@ AUTHOR = "Evan Light"
|
|
11
11
|
EMAIL = "evan@tripledogdare.net"
|
12
12
|
SUMMARY = "Plugin/gem that provides threaded comment functionality"
|
13
13
|
|
14
|
-
|
15
|
-
spec = ACTS_AS_COMMENTABLE_WITH_THREADING
|
14
|
+
spec = eval(File.read('acts_as_commentable_with_threading.gemspec'))
|
16
15
|
|
17
|
-
|
16
|
+
Gem::PackageTask.new(spec) do |pkg|
|
18
17
|
pkg.gem_spec = spec
|
19
18
|
end
|
20
19
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
Gem::Specification.new do |s|
|
2
2
|
s.name = "acts_as_commentable_with_threading"
|
3
|
-
s.version = "1.1.
|
4
|
-
s.date = "
|
3
|
+
s.version = "1.1.2"
|
4
|
+
s.date = "2012-03-23"
|
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"
|
8
8
|
s.description = "Polymorphic threaded comments Rails gem for Rails 3+"
|
9
|
-
s.authors = ["Evan Light", "Jack Dempsey", "Xelipe", "xxx"]
|
9
|
+
s.authors = ["Evan Light", "Jack Dempsey", "Xelipe", "xxx"]
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.test_files = ["spec/commentable_spec.rb", "spec/comment_spec.rb", "spec/spec_helper.rb", "spec/db/database.yml", "spec/db/schema.rb"]
|
12
12
|
|
@@ -16,7 +16,7 @@ ACTS_AS_COMMENTABLE_WITH_THREADING = Gem::Specification.new do |s|
|
|
16
16
|
s.add_development_dependency 'sqlite3-ruby'
|
17
17
|
s.add_development_dependency 'rails', '~> 3.0'
|
18
18
|
|
19
|
-
s.add_dependency 'activerecord', '
|
19
|
+
s.add_dependency 'activerecord', '>= 3.0'
|
20
20
|
s.add_dependency 'activesupport', '~> 3.0'
|
21
|
-
s.add_dependency '
|
21
|
+
s.add_dependency 'awesome_nested_set', '>= 2.0'
|
22
22
|
end
|
@@ -28,7 +28,7 @@ module Acts #:nodoc:
|
|
28
28
|
# Helper method to lookup for comments for a given object.
|
29
29
|
# This method is equivalent to obj.comments.
|
30
30
|
def find_comments_for(obj)
|
31
|
-
Comment.where(:commentable_id => obj.id, :commentable_type => obj.class).order('created_at DESC')
|
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
|
@@ -1,47 +1,49 @@
|
|
1
1
|
class Comment < ActiveRecord::Base
|
2
2
|
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
|
3
|
-
|
3
|
+
|
4
4
|
validates_presence_of :body
|
5
5
|
validates_presence_of :user
|
6
|
-
|
7
|
-
# NOTE: install the acts_as_votable plugin if you
|
6
|
+
|
7
|
+
# NOTE: install the acts_as_votable plugin if you
|
8
8
|
# want user to vote on the quality of comments.
|
9
9
|
#acts_as_voteable
|
10
|
-
|
10
|
+
|
11
|
+
belongs_to :commentable, :polymorphic => true
|
12
|
+
|
11
13
|
# NOTE: Comments belong to a user
|
12
14
|
belongs_to :user
|
13
|
-
|
15
|
+
|
14
16
|
# Helper class method that allows you to build a comment
|
15
17
|
# by passing a commentable object, a user_id, and comment text
|
16
18
|
# example in readme
|
17
19
|
def self.build_from(obj, user_id, comment)
|
18
20
|
c = self.new
|
19
|
-
c.commentable_id = obj.id
|
20
|
-
c.commentable_type = obj.class.name
|
21
|
-
c.body = comment
|
21
|
+
c.commentable_id = obj.id
|
22
|
+
c.commentable_type = obj.class.base_class.name
|
23
|
+
c.body = comment
|
22
24
|
c.user_id = user_id
|
23
25
|
c
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
#helper method to check if a comment has children
|
27
29
|
def has_children?
|
28
|
-
self.children.size > 0
|
30
|
+
self.children.size > 0
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
# Helper class method to lookup all comments assigned
|
32
34
|
# to all commentable types for a given user.
|
33
35
|
scope :find_comments_by_user, lambda { |user|
|
34
36
|
where(:user_id => user.id).order('created_at DESC')
|
35
37
|
}
|
36
38
|
|
37
|
-
# Helper class method to look up all comments for
|
39
|
+
# Helper class method to look up all comments for
|
38
40
|
# commentable class name and commentable id.
|
39
41
|
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
|
40
42
|
where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC')
|
41
43
|
}
|
42
44
|
|
43
45
|
# Helper class method to look up a commentable object
|
44
|
-
# given the commentable class name and id
|
46
|
+
# given the commentable class name and id
|
45
47
|
def self.find_commentable(commentable_str, commentable_id)
|
46
48
|
commentable_str.constantize.find(commentable_id)
|
47
49
|
end
|
@@ -1,47 +1,49 @@
|
|
1
1
|
class Comment < ActiveRecord::Base
|
2
2
|
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
|
3
|
-
|
3
|
+
|
4
4
|
validates_presence_of :body
|
5
5
|
validates_presence_of :user
|
6
|
-
|
7
|
-
# NOTE: install the acts_as_votable plugin if you
|
6
|
+
|
7
|
+
# NOTE: install the acts_as_votable plugin if you
|
8
8
|
# want user to vote on the quality of comments.
|
9
9
|
#acts_as_voteable
|
10
|
-
|
10
|
+
|
11
|
+
belongs_to :commentable, :polymorphic => true
|
12
|
+
|
11
13
|
# NOTE: Comments belong to a user
|
12
14
|
belongs_to :user
|
13
|
-
|
15
|
+
|
14
16
|
# Helper class method that allows you to build a comment
|
15
17
|
# by passing a commentable object, a user_id, and comment text
|
16
18
|
# example in readme
|
17
19
|
def self.build_from(obj, user_id, comment)
|
18
20
|
c = self.new
|
19
|
-
c.commentable_id = obj.id
|
20
|
-
c.commentable_type = obj.class.name
|
21
|
-
c.body = comment
|
21
|
+
c.commentable_id = obj.id
|
22
|
+
c.commentable_type = obj.class.base_class.name
|
23
|
+
c.body = comment
|
22
24
|
c.user_id = user_id
|
23
25
|
c
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
#helper method to check if a comment has children
|
27
29
|
def has_children?
|
28
|
-
self.children.size > 0
|
30
|
+
self.children.size > 0
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
# Helper class method to lookup all comments assigned
|
32
34
|
# to all commentable types for a given user.
|
33
35
|
scope :find_comments_by_user, lambda { |user|
|
34
36
|
where(:user_id => user.id).order('created_at DESC')
|
35
37
|
}
|
36
38
|
|
37
|
-
# Helper class method to look up all comments for
|
39
|
+
# Helper class method to look up all comments for
|
38
40
|
# commentable class name and commentable id.
|
39
41
|
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
|
40
42
|
where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC')
|
41
43
|
}
|
42
44
|
|
43
45
|
# Helper class method to look up a commentable object
|
44
|
-
# given the commentable class name and id
|
46
|
+
# given the commentable class name and id
|
45
47
|
def self.find_commentable(commentable_str, commentable_id)
|
46
48
|
commentable_str.constantize.find(commentable_id)
|
47
49
|
end
|
data/rails/init.rb
CHANGED
data/spec/commentable_spec.rb
CHANGED
@@ -14,9 +14,9 @@ describe "A class that is commentable" do
|
|
14
14
|
|
15
15
|
describe "#find_comments_for" do
|
16
16
|
before :each do
|
17
|
-
@comment = Comment.create!(:user => @user, :
|
17
|
+
@comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'blargh')
|
18
18
|
|
19
|
-
@other_comment = Comment.create!(:user => @user, :
|
19
|
+
@other_comment = Comment.create!(:user => @user, :commentable => @other_commentable, :body => 'hello')
|
20
20
|
|
21
21
|
@comments = Commentable.find_comments_for(@commentable)
|
22
22
|
end
|
@@ -34,9 +34,9 @@ describe "A class that is commentable" do
|
|
34
34
|
before :each do
|
35
35
|
@user2 = User.create!
|
36
36
|
|
37
|
-
@comment = Comment.create!(:user => @user, :
|
37
|
+
@comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'blargh')
|
38
38
|
|
39
|
-
@other_comment = Comment.create!(:user => @user2, :
|
39
|
+
@other_comment = Comment.create!(:user => @user2, :commentable => @other_commentable, :body => 'hello')
|
40
40
|
|
41
41
|
@comments = Commentable.find_comments_by_user(@user)
|
42
42
|
end
|
@@ -51,25 +51,25 @@ describe "A class that is commentable" do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
describe "instance methods" do
|
56
56
|
describe "#comments_ordered_by_submitted" do
|
57
57
|
before :each do
|
58
58
|
@user = User.create!
|
59
59
|
@commentable = Commentable.create!
|
60
60
|
@other_commentable = Commentable.create!
|
61
|
-
@comment = Comment.create!(:user => @user, :
|
62
|
-
@older_comment = Comment.create!(:user => @user, :
|
63
|
-
@oldest_comment = Comment.create!(:user => @user, :
|
64
|
-
@other_comment = Comment.create!(:user => @user, :
|
61
|
+
@comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'sup')
|
62
|
+
@older_comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'sup', :created_at => 1.week.ago)
|
63
|
+
@oldest_comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'sup', :created_at => 2.years.ago)
|
64
|
+
@other_comment = Comment.create!(:user => @user, :commentable => @other_commentable, :body => 'sup')
|
65
65
|
@comments = @commentable.comments_ordered_by_submitted
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should return its own comments, ordered with the newest first" do
|
69
69
|
@comments.all? { |c| c.commentable_type == @commentable.class.to_s and c.commentable_id == @commentable.id }.should be_true
|
70
70
|
@comments.each_cons(2) { |c, c2| c.created_at.should > c2.created_at }
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should not include comments for other commentables" do
|
74
74
|
@comments.any? { |c| c.commentable_type != @commentable.class.to_s or c.commentable_id != @commentable.id }.should be_false
|
75
75
|
end
|
data/spec/db/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,7 @@ ActiveRecord::Migration.verbose = false
|
|
12
12
|
load(File.join(plugin_test_dir, "db", "schema.rb"))
|
13
13
|
|
14
14
|
require File.join(plugin_test_dir, '..', 'init')
|
15
|
+
require File.join(plugin_test_dir, '..', 'lib', 'generators', 'acts_as_commentable_with_threading_migration', 'templates', 'comment')
|
15
16
|
|
16
17
|
class User < ActiveRecord::Base
|
17
18
|
has_many :comments
|
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_commentable_with_threading
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 1.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.2
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Evan Light
|
14
9
|
- Jack Dempsey
|
15
10
|
- Xelipe
|
@@ -17,136 +12,142 @@ authors:
|
|
17
12
|
autorequire:
|
18
13
|
bindir: bin
|
19
14
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
dependencies:
|
24
|
-
- !ruby/object:Gem::Dependency
|
15
|
+
date: 2012-03-23 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
25
18
|
name: rake
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
hash: 3
|
33
|
-
segments:
|
34
|
-
- 0
|
35
|
-
version: "0"
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
36
25
|
type: :development
|
37
|
-
version_requirements: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: bundler
|
40
26
|
prerelease: false
|
41
|
-
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
28
|
none: false
|
43
|
-
requirements:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
44
38
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
segments:
|
48
|
-
- 1
|
49
|
-
- 0
|
50
|
-
version: "1.0"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
51
41
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rspec
|
55
42
|
prerelease: false
|
56
|
-
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
44
|
none: false
|
58
|
-
requirements:
|
45
|
+
requirements:
|
59
46
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.0'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.3'
|
66
57
|
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: sqlite3-ruby
|
70
58
|
prerelease: false
|
71
|
-
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '1.3'
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: sqlite3-ruby
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
80
73
|
type: :development
|
81
|
-
version_requirements: *id004
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: rails
|
84
74
|
prerelease: false
|
85
|
-
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rails
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
86
84
|
none: false
|
87
|
-
requirements:
|
85
|
+
requirements:
|
88
86
|
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
|
91
|
-
segments:
|
92
|
-
- 3
|
93
|
-
- 0
|
94
|
-
version: "3.0"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
95
89
|
type: :development
|
96
|
-
version_requirements: *id005
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: activerecord
|
99
90
|
prerelease: false
|
100
|
-
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
92
|
none: false
|
102
|
-
requirements:
|
93
|
+
requirements:
|
103
94
|
- - ~>
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.0'
|
110
105
|
type: :runtime
|
111
|
-
version_requirements: *id006
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: activesupport
|
114
106
|
prerelease: false
|
115
|
-
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
116
108
|
none: false
|
117
|
-
requirements:
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '3.0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: activesupport
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
118
|
- - ~>
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
segments:
|
122
|
-
- 3
|
123
|
-
- 0
|
124
|
-
version: "3.0"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '3.0'
|
125
121
|
type: :runtime
|
126
|
-
version_requirements: *id007
|
127
|
-
- !ruby/object:Gem::Dependency
|
128
|
-
name: moretea-awesome_nested_set
|
129
122
|
prerelease: false
|
130
|
-
|
131
|
-
none: false
|
132
|
-
requirements:
|
133
|
-
- -
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ~>
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '3.0'
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
name: awesome_nested_set
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '2.0'
|
139
137
|
type: :runtime
|
140
|
-
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '2.0'
|
141
145
|
description: Polymorphic threaded comments Rails gem for Rails 3+
|
142
146
|
email: evan@tripledogdare.net
|
143
147
|
executables: []
|
144
|
-
|
145
148
|
extensions: []
|
146
|
-
|
147
149
|
extra_rdoc_files: []
|
148
|
-
|
149
|
-
files:
|
150
|
+
files:
|
150
151
|
- .gitignore
|
151
152
|
- CHANGELOG
|
152
153
|
- Gemfile
|
@@ -172,41 +173,31 @@ files:
|
|
172
173
|
- spec/db/database.yml
|
173
174
|
- spec/db/schema.rb
|
174
175
|
- spec/spec_helper.rb
|
175
|
-
has_rdoc: true
|
176
176
|
homepage: http://github.com/elight/acts_as_commentable_with_threading
|
177
177
|
licenses: []
|
178
|
-
|
179
178
|
post_install_message:
|
180
179
|
rdoc_options: []
|
181
|
-
|
182
|
-
require_paths:
|
180
|
+
require_paths:
|
183
181
|
- lib
|
184
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
183
|
none: false
|
186
|
-
requirements:
|
187
|
-
- -
|
188
|
-
- !ruby/object:Gem::Version
|
189
|
-
|
190
|
-
|
191
|
-
- 0
|
192
|
-
version: "0"
|
193
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
189
|
none: false
|
195
|
-
requirements:
|
196
|
-
- -
|
197
|
-
- !ruby/object:Gem::Version
|
198
|
-
|
199
|
-
segments:
|
200
|
-
- 0
|
201
|
-
version: "0"
|
190
|
+
requirements:
|
191
|
+
- - ! '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
202
194
|
requirements: []
|
203
|
-
|
204
195
|
rubyforge_project:
|
205
|
-
rubygems_version: 1.
|
196
|
+
rubygems_version: 1.8.21
|
206
197
|
signing_key:
|
207
198
|
specification_version: 3
|
208
199
|
summary: Polymorphic comments Rails gem - Rails 3+ only
|
209
|
-
test_files:
|
200
|
+
test_files:
|
210
201
|
- spec/commentable_spec.rb
|
211
202
|
- spec/comment_spec.rb
|
212
203
|
- spec/spec_helper.rb
|