mongoid_socializer_actions 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mongoid_socializer_actions
2
2
 
3
- mongoid_socializer_actions gives ability to like, comment mongoid documents
3
+ mongoid_socializer_actions gives ability to like, comment, share mongoid documents
4
4
 
5
5
 
6
6
  ## Installation
@@ -22,6 +22,13 @@ Or install it yourself as:
22
22
 
23
23
  This gem has been tested with [MongoID](http://mongoid.org/) version 3.0.21
24
24
 
25
+ ## Configuration
26
+
27
+ Set the user(commenter, liker, sharer) class name. By default its 'User'. In some cases, the class name will be 'Customer' or 'Administrator', etc. In the following examples the 'User' class should be same as this Configuration user_class_name
28
+
29
+ Socializer.configure do |configuration|
30
+ configuration.user_class_name = 'User'
31
+ end
25
32
 
26
33
  ## Usage
27
34
 
@@ -93,7 +100,13 @@ You can now comment objects like this:
93
100
  user = User.create
94
101
  photo = Photo.create
95
102
 
96
- user.comment_on(photo, "Beautiful")
103
+ @comment = user.comment_on(photo, "Beautiful")
104
+
105
+ @comment.persisted?
106
+ # => true
107
+
108
+ @comment.errors
109
+ # => []
97
110
 
98
111
  Load the commets with eager loaded user(Enable [Identity map](http://mongoid.org/en/mongoid/docs/identity_map.html))
99
112
 
@@ -140,14 +153,14 @@ Add the Sharer module in User model and Sharable in Photo, Album etc.
140
153
  include Mongoid::Sharable
141
154
  end
142
155
 
143
- You can now comment objects like this:
156
+ You can now share objects like this:
144
157
 
145
158
  user = User.create
146
159
  photo = Photo.create
147
160
 
148
161
  user.share(photo)
149
162
 
150
- You can query for comments like that:
163
+ You can query for shares like that:
151
164
 
152
165
  photo.sharers
153
166
  # => [user]
@@ -6,7 +6,7 @@ module Mongoid
6
6
  field :body, type: String
7
7
  validates :body, presence: true
8
8
 
9
- belongs_to :commenter, :class_name => 'User', :inverse_of => :comments
9
+ belongs_to :commenter, :class_name => Socializer.user_class_name, :inverse_of => :comments
10
10
  belongs_to :commentable, :polymorphic => true
11
11
 
12
12
  def commentabled_obj
data/app/models/like.rb CHANGED
@@ -3,7 +3,7 @@ module Mongoid
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps::Created
5
5
 
6
- belongs_to :liker, :class_name => 'User', :inverse_of => :likes
6
+ belongs_to :liker, :class_name => Socializer.user_class_name, :inverse_of => :likes
7
7
  belongs_to :likable, :polymorphic => true
8
8
  end
9
9
  end
data/app/models/share.rb CHANGED
@@ -2,7 +2,7 @@ module Mongoid
2
2
  class Share
3
3
  include Mongoid::Document
4
4
 
5
- belongs_to :sharer, :class_name => 'User', :inverse_of => :shares
5
+ belongs_to :sharer, :class_name => Socializer.user_class_name, :inverse_of => :shares
6
6
  belongs_to :sharable, :polymorphic => true
7
7
  end
8
8
  end
@@ -1,3 +1,8 @@
1
+ require 'mongoid_socializer_actions/config'
2
+ module Socializer
3
+ extend Configuration
4
+ end
5
+
1
6
  require 'mongoid_socializer_actions/likeable'
2
7
  require 'mongoid_socializer_actions/liker'
3
8
  require 'mongoid_socializer_actions/helper'
@@ -9,4 +14,5 @@ require 'models/comment'
9
14
 
10
15
  require 'mongoid_socializer_actions/sharable'
11
16
  require 'mongoid_socializer_actions/sharer'
12
- require 'models/share'
17
+ require 'models/share'
18
+
@@ -10,10 +10,10 @@ module Mongoid
10
10
  # Comment on a model
11
11
  #
12
12
  # Example:
13
- # => @john.comment_on(@photo, { with: "Beautiful" } )
13
+ # => @john.comment_on(@photo, "Beautiful")
14
14
  def comment_on(model, comment_body)
15
15
  model.before_commented_by(self) if model.respond_to?('before_commented_by')
16
- comment = model.comments.create!(body: comment_body)
16
+ comment = model.comments.create(body: comment_body)
17
17
  comments << comment
18
18
  model.inc(:comments_count, 1)
19
19
  self.inc(:comments_count, 1)
@@ -0,0 +1,20 @@
1
+ module Socializer
2
+ # Configuration settings
3
+ module Configuration
4
+ attr_writer :user_class_name
5
+
6
+ # Example:
7
+ #
8
+ # Socializer.configure do |configuration|
9
+ # configuration.user_class_name = 'User'
10
+ # end
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
16
+ def user_class_name
17
+ @user_class_name ||= 'User'
18
+ end
19
+ end
20
+ end
@@ -5,7 +5,7 @@ module Mongoid
5
5
  included do |base|
6
6
  base.field :likers_count, :type => Integer, :default => 0
7
7
  base.has_many :likes, :class_name => 'Mongoid::Like', :as => :likable, :dependent => :destroy
8
- base.has_and_belongs_to_many :likers, :class_name => 'User', :inverse_of => nil
8
+ base.has_and_belongs_to_many :likers, :class_name => Socializer.user_class_name, :inverse_of => nil
9
9
  end
10
10
 
11
11
  # know if self is liked by model
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module MongoidSocializerActions
3
- VERSION = "1.2.3"
3
+ VERSION = "1.2.4"
4
4
  end
5
5
  end
@@ -21,6 +21,13 @@ describe Mongoid::Commenter do
21
21
  expect{ @john.comment_on(@photo1, "Beautiful") }.to change(Mongoid::Comment, :count).by(1)
22
22
  end
23
23
 
24
+ it "comment body should not be empty" do
25
+ comment = @john.comment_on(@photo1, '')
26
+ comment.errors.present?.should be_true
27
+ comment.errors[:body].should == ["can't be blank"]
28
+ comment.persisted?.should be_false
29
+ end
30
+
24
31
  it "should be commented by commenter" do
25
32
  @john.comment_on(@photo1, 'Beautiful')
26
33
  @photo1.commenters.should include @john
@@ -46,8 +53,8 @@ describe Mongoid::Commenter do
46
53
  end
47
54
 
48
55
  it "should have the correct comments count" do
49
- @jashua.comment_on(@photo1, '')
50
- @john.comment_on(@photo1, '')
56
+ @jashua.comment_on(@photo1, 'test1')
57
+ @john.comment_on(@photo1, 'test2')
51
58
  @photo1.comments_count.should be 2
52
59
  @jashua.comments_count.should be 1
53
60
  @john.comments_count.should be 1
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Socializer::Configuration do
4
+ describe '#configure' do
5
+ it 'should have default attributes' do
6
+ Socializer.configure do |configuration|
7
+ configuration.user_class_name.should eql('User')
8
+ end
9
+ end
10
+
11
+ it 'should have default attributes' do
12
+ Socializer.user_class_name.should eql('User')
13
+ end
14
+
15
+ it 'should accept user settings' do
16
+ Socializer.configure do |configuration|
17
+ configuration.user_class_name = 'Customer'
18
+ end
19
+
20
+ Socializer.user_class_name.should eql('Customer')
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_socializer_actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &2152177240 !ruby/object:Gem::Requirement
16
+ requirement: &2164461600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152177240
24
+ version_requirements: *2164461600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2152175860 !ruby/object:Gem::Requirement
27
+ requirement: &2164461020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '3.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152175860
35
+ version_requirements: *2164461020
36
36
  description: Add liking, commentable, sharabel, tagabel ability to Mongoid documents.
37
37
  email:
38
38
  - sreehari@activesphere.com
@@ -52,6 +52,7 @@ files:
52
52
  - lib/mongoid_socializer_actions.rb
53
53
  - lib/mongoid_socializer_actions/commentable.rb
54
54
  - lib/mongoid_socializer_actions/commenter.rb
55
+ - lib/mongoid_socializer_actions/config.rb
55
56
  - lib/mongoid_socializer_actions/helper.rb
56
57
  - lib/mongoid_socializer_actions/likeable.rb
57
58
  - lib/mongoid_socializer_actions/liker.rb
@@ -64,6 +65,7 @@ files:
64
65
  - spec/mongoid/models/photo.rb
65
66
  - spec/mongoid/models/user.rb
66
67
  - spec/mongoid/mongoid_socializer_actions/comments_spec.rb
68
+ - spec/mongoid/mongoid_socializer_actions/config_spec.rb
67
69
  - spec/mongoid/mongoid_socializer_actions/likes_spec.rb
68
70
  - spec/mongoid/mongoid_socializer_actions/shares_spec.rb
69
71
  - spec/spec_helper.rb
@@ -98,6 +100,7 @@ test_files:
98
100
  - spec/mongoid/models/photo.rb
99
101
  - spec/mongoid/models/user.rb
100
102
  - spec/mongoid/mongoid_socializer_actions/comments_spec.rb
103
+ - spec/mongoid/mongoid_socializer_actions/config_spec.rb
101
104
  - spec/mongoid/mongoid_socializer_actions/likes_spec.rb
102
105
  - spec/mongoid/mongoid_socializer_actions/shares_spec.rb
103
106
  - spec/spec_helper.rb