mm-commentable 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,44 @@
1
- = mm-acts_as_commentable
1
+ = mm-commentable
2
2
 
3
- Description goes here.
3
+ A simple MongoMapper plugin to make adding comments to your models easy
4
4
 
5
- == Contributing to mm-acts_as_commentable
5
+ == Usage
6
+
7
+ Install the gem
8
+
9
+ gem install mm-commentable
10
+
11
+
12
+ Or add it to your Gemfile
13
+
14
+ gem 'mm-commentable'
15
+
16
+
17
+ Then add the commentable plugin to you MongoMapper::Document
18
+
19
+ class Post
20
+ include MongoMapper::Document
21
+ plugin MongoMapper::Plugins::Commentable
22
+
23
+ def on_add_comment(comment)
24
+ do something when a comment is added...
25
+ end
26
+ end
27
+
28
+ You must implement the on_add_comment callback! - however it can be an empty implementation
29
+
30
+ @post = Post.create
31
+ @commentor = User.create
32
+
33
+ @post.add_comment("great post..", @user)
34
+
35
+ @post.comments_count = 1
36
+ @posts.comments = [<Comment>]
37
+
38
+ The commentor association is polymorphic, so any class will probably work, but I expect the commentor would normally be a User object
39
+
40
+
41
+ == Contributing to mm-commentable
6
42
 
7
43
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
44
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -12,8 +48,9 @@ Description goes here.
12
48
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
49
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
50
 
51
+
15
52
  == Copyright
16
53
 
17
- Copyright (c) 2010 Luke. See LICENSE.txt for
54
+ Copyright (c) 2010 Luke Cunningham. See LICENSE.txt for
18
55
  further details.
19
56
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,7 +5,8 @@ class Comment
5
5
  key :body, String, :required => true
6
6
 
7
7
  key :commentor_id, ObjectId
8
- belongs_to :commentor, :class_name => 'User'
8
+ key :commentor_type, String
9
+ belongs_to :commentor, :polymorphic => true
9
10
 
10
11
  embedded_in :commentable
11
12
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mm-commentable}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Luke Cunningham"]
@@ -29,6 +29,14 @@ describe "MongoMapper::Plugins::ActsAsCommentable" do
29
29
  @commentable.comments.size.should equal 1
30
30
  end
31
31
 
32
+ it "should assign the commentor" do
33
+ @commentable.add_comment!("first comment", @luke)
34
+ comment = @commentable.comments.first
35
+ comment.commentor_id.should == @luke.id
36
+ comment.commentor_type.should == @luke.class.name
37
+ comment.commentor.should == @luke
38
+ end
39
+
32
40
  it "should throw NotImplementedError if the :on_add_vote callback has not inplemented" do
33
41
  commentable = CommentableWithoutCallback.new
34
42
  lambda {
@@ -67,6 +75,9 @@ describe "Comment" do
67
75
  it "should have a commentor association" do
68
76
  @comment.should respond_to(:commentor_id=)
69
77
  @comment.should respond_to(:commentor_id)
78
+ @comment.should respond_to(:commentor_type=)
79
+ @comment.should respond_to(:commentor_type)
80
+
70
81
  @comment.commentor.association.should be_belongs_to
71
82
  end
72
83
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-commentable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Cunningham