opinio 0.3.4 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,13 +49,20 @@ If you want to display the comments for the item outside of the resource, you ca
49
49
  <%= comments_for @post %>
50
50
 
51
51
  And there you go, you can now comment in your post.
52
- Aditional options can be found on the {RDocs}[http://rubydoc.info/github/Draiken/opinio/master/frames]
53
52
 
54
53
  Alternatively you can render just the comments or just the form like this:
55
54
 
56
55
  <%= render_comments @post %>
57
56
  <%= render_comments_form @post %>
58
57
 
58
+ If you need to render the comments with a specific page or limit
59
+ you can use Kaminari's configurations like `paginates_per 10` on your comment model
60
+ or you can customize it for specific views on the helpers
61
+
62
+ <%= render_comments @post, :page => params[:page], :limit => 5 %>
63
+
64
+ This can also be used on the `comments_for` helper.
65
+
59
66
  == Customization
60
67
 
61
68
  === Views
@@ -113,13 +120,26 @@ Another example would be using the *CanCan*:
113
120
  You get the picture, you're inside your controller's methods on that block
114
121
  so you can call anything your normal controllers call on actions.
115
122
 
123
+ === Testing
124
+
125
+ Opinio provides a few shared examples for testing of your model with rspec
126
+ On your opinio model test case you can require opinio's shared examples and use them
127
+
128
+ require 'opinio/shared_examples'
129
+
130
+ describe Comment do
131
+ it_should_behave_like :opinio
132
+ end
133
+
134
+ describe Post do
135
+ it_should_behave_like :opinio_subjectum
136
+ end
137
+
116
138
  == Contribution
117
139
 
118
140
  If you want to help in any way with *Opinio* please message me or fork the project, make the changes and send me a pull request.
119
141
  For issues please use the github {issues tracker}[https://github.com/Draiken/opinio/issues]
120
142
 
121
- Remember this engine is still in development :)
122
-
123
143
  === TODO
124
144
 
125
145
  * Haml views
@@ -1,6 +1,6 @@
1
1
  <div id="new_comment">
2
2
  <% if send(Opinio.current_user_method) %>
3
- <h2>Send Comments</h3>
3
+ <h3>Send Comments</h3>
4
4
  <%= form_for Comment.new, :remote => true do |f| %>
5
5
  <p>
6
6
  <%= f.label :body, "Comment" %>
@@ -22,6 +22,10 @@ module Opinio
22
22
  route "opinio_model"
23
23
  end
24
24
 
25
+ def add_dependency_gem
26
+ gem "kaminari"
27
+ end
28
+
25
29
  def self.next_migration_number(dirname)
26
30
  if ActiveRecord::Base.timestamped_migrations
27
31
  Time.now.utc.strftime("%Y%m%d%H%M%S")
@@ -5,4 +5,13 @@ Opinio.setup do |config|
5
5
  # Use this to change the class that calls +opinio+ method
6
6
  config.model_name = "<%= class_name %>"
7
7
 
8
+ # This is the owner class of the comment (opinio model)
9
+ # config.owner_class_name = "User"
10
+
11
+ # Change this if you do not want to allow replies on your comments
12
+ # config.accept_replies = true
13
+
14
+ # Here you can change the method called to check who is the current user
15
+ # config.current_user_method = :current_user
16
+
8
17
  end
@@ -1,5 +1,4 @@
1
1
  module Opinio
2
- #autoload :Railtie, 'opinio/railtie'
3
2
  autoload :Schema, 'opinio/schema'
4
3
 
5
4
  module Controllers
@@ -1,12 +1,16 @@
1
1
  module Opinio
2
2
  module Controllers
3
3
  module Extensions
4
- extend ActiveSupport::Concern
5
4
 
6
- included do
7
- (class << self; self; end).instance_eval do
8
- define_method "#{Opinio.model_name.underscore}_destroy_conditions" do |&block|
9
- Opinio.set_destroy_conditions( &block )
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.send :include, InstanceMethods
8
+
9
+ base.class_eval do
10
+ (class << self; self; end).instance_eval do
11
+ define_method "#{Opinio.model_name.underscore}_destroy_conditions" do |&block|
12
+ Opinio.set_destroy_conditions( &block )
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -0,0 +1,51 @@
1
+ shared_examples_for :opinio do
2
+ let(:comment) { Comment.new }
3
+ before(:all) do
4
+ @post = Post.new(:title => "My first post", :body => "Damn I really suck at writing")
5
+ @post.save
6
+ end
7
+
8
+ it "should have the correct attributes" do
9
+ should respond_to(:owner)
10
+ should respond_to(:body)
11
+ should respond_to(:commentable)
12
+ end
13
+
14
+
15
+ it "should not allow comments of comments" do
16
+ Comment.class_eval do
17
+ include Opinio::OpinioModel::RepliesSupport
18
+ end
19
+
20
+ c = Comment.new(:body => "The Comment !")
21
+ c.commentable = @post
22
+ c.owner_id = 1
23
+ c.save
24
+
25
+ c2 = c.dup
26
+ c2.commentable = c
27
+ c.save.should == true
28
+
29
+ c3 = c2.dup
30
+ c3.commentable = c2
31
+ c3.save.should == false
32
+
33
+ c3.errors[:base].count.should == 1
34
+ end
35
+
36
+ it "should validate presence of body and commentable" do
37
+ comment.should be_invalid
38
+ comment.errors[:body].should be_present
39
+ comment.errors[:commentable].should be_present
40
+ end
41
+
42
+ end
43
+
44
+
45
+ shared_examples_for :opinio_subjectum do
46
+
47
+ it "and should add opinio_subjectum functionallity" do
48
+ should respond_to(:comments)
49
+ end
50
+
51
+ end
@@ -1,5 +1,5 @@
1
1
  module Opinio
2
2
  class Version
3
- VERSION = '0.3.4'
3
+ VERSION = '0.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opinio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-31 00:00:00.000000000Z
12
+ date: 2012-02-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2157268020 !ruby/object:Gem::Requirement
16
+ requirement: &2156948880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157268020
24
+ version_requirements: *2156948880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kaminari
27
- requirement: &2157267600 !ruby/object:Gem::Requirement
27
+ requirement: &2156948260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157267600
35
+ version_requirements: *2156948260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jquery-rails
38
- requirement: &2157267140 !ruby/object:Gem::Requirement
38
+ requirement: &2156947720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2157267140
46
+ version_requirements: *2156947720
47
47
  description: Opinio is an engine used to add comments functionallity to rails 3 applications.
48
48
  email:
49
49
  - luiz.felipe.gp@gmail.com
@@ -75,6 +75,7 @@ files:
75
75
  - lib/opinio/rails.rb
76
76
  - lib/opinio/railtie.rb
77
77
  - lib/opinio/schema.rb
78
+ - lib/opinio/shared_examples.rb
78
79
  - lib/opinio/version.rb
79
80
  - lib/opinio.rb
80
81
  - MIT-LICENSE