governor_comments 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Gemfile +3 -1
  2. data/Gemfile.lock +11 -3
  3. data/README.rdoc +5 -2
  4. data/Rakefile +1 -0
  5. data/VERSION +1 -1
  6. data/app/controllers/governor/comments_controller.rb +2 -14
  7. data/app/views/governor/articles/_comments.html.erb +1 -11
  8. data/app/views/governor/articles/edit_comments.html.erb +43 -0
  9. data/app/views/governor/comments/_form.html.erb +11 -0
  10. data/app/views/governor/comments/edit.html.erb +4 -0
  11. data/config/locales/en.yml +8 -2
  12. data/governor_comments.gemspec +28 -14
  13. data/lib/generators/governor/add_assets_generator.rb +15 -0
  14. data/lib/generators/governor/create_comments_generator.rb +2 -0
  15. data/lib/generators/governor/templates/assets/javascripts/governor-comments.js +7 -0
  16. data/lib/generators/governor/templates/assets/stylesheets/governor-comments.css +18 -0
  17. data/lib/generators/governor/templates/migrations/create_comments.rb +1 -1
  18. data/lib/generators/governor/templates/models/comment.rb +1 -0
  19. data/lib/governor/controllers/methods.rb +18 -0
  20. data/lib/governor_comments/comment.rb +13 -5
  21. data/lib/governor_comments/rails.rb +3 -1
  22. data/lib/governor_comments.rb +12 -3
  23. data/spec/controllers/governor/articles_controller_spec.rb +48 -0
  24. data/spec/controllers/governor/comments_controller_spec.rb +1 -1
  25. data/spec/rails_app/Gemfile +1 -1
  26. data/spec/rails_app/Gemfile.lock +10 -5
  27. data/spec/rails_app/app/models/comment.rb +1 -0
  28. data/spec/rails_app/app/views/layouts/application.html.erb +3 -2
  29. data/spec/rails_app/config/application.rb +11 -1
  30. data/spec/rails_app/db/migrate/{20110405030324_governor_create_comments.rb → 20110501055541_governor_create_comments.rb} +1 -1
  31. data/spec/rails_app/db/schema.rb +2 -2
  32. data/spec/rails_app/public/javascripts/jquery.js +16 -0
  33. data/spec/rails_app/public/javascripts/rails.js +255 -157
  34. data/spec/rails_app/spec/factories.rb +1 -0
  35. data/spec/views/governor/articles/show.html.erb_spec.rb +8 -1
  36. data/spec/views/layouts/application.html.erb_spec.rb +18 -0
  37. data/{log/development.log → tmp/.gitkeep} +0 -0
  38. metadata +66 -30
  39. data/spec/rails_app/public/javascripts/controls.js +0 -965
  40. data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
  41. data/spec/rails_app/public/javascripts/effects.js +0 -1123
  42. data/spec/rails_app/public/javascripts/prototype.js +0 -6001
data/Gemfile CHANGED
@@ -2,12 +2,14 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 3.0.5'
4
4
 
5
- gem 'governor', '>= 0.2.2'
5
+ gem 'governor', '>= 0.5.0'
6
6
 
7
7
  group :development, :test do
8
8
  gem 'jeweler', '~> 1.5.2'
9
9
  gem 'sqlite3'
10
10
  gem 'rspec-rails'
11
+ gem 'rcov'
12
+ gem 'webrat'
11
13
  gem 'mocha'
12
14
  gem 'factory_girl', '~> 2.0.0.beta'
13
15
  gem 'factory_girl_rails', '~> 1.1.beta'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor_comments (0.1.1)
4
+ governor_comments (0.1.2)
5
5
  governor (>= 0.2.2)
6
6
  rails (~> 3.0.5)
7
7
 
@@ -52,7 +52,7 @@ GEM
52
52
  factory_girl (~> 2.0.0.beta)
53
53
  rails (>= 3.0.0)
54
54
  git (1.2.5)
55
- governor (0.2.2)
55
+ governor (0.5.0)
56
56
  rails (~> 3.0.5)
57
57
  i18n (0.5.0)
58
58
  jeweler (1.5.2)
@@ -66,6 +66,7 @@ GEM
66
66
  treetop (~> 1.4.8)
67
67
  mime-types (1.16)
68
68
  mocha (0.9.12)
69
+ nokogiri (1.4.4)
69
70
  polyglot (0.3.1)
70
71
  rack (1.2.1)
71
72
  rack-mount (0.6.13)
@@ -87,6 +88,7 @@ GEM
87
88
  thor (~> 0.14.4)
88
89
  rake (0.8.7)
89
90
  rakismet (1.0.1)
91
+ rcov (0.9.9)
90
92
  rspec (2.5.0)
91
93
  rspec-core (~> 2.5.0)
92
94
  rspec-expectations (~> 2.5.0)
@@ -107,6 +109,10 @@ GEM
107
109
  tzinfo (0.3.24)
108
110
  warden (1.0.3)
109
111
  rack (>= 1.0.0)
112
+ webrat (0.7.3)
113
+ nokogiri (>= 1.2.0)
114
+ rack (>= 1.0)
115
+ rack-test (>= 0.5.3)
110
116
 
111
117
  PLATFORMS
112
118
  ruby
@@ -117,11 +123,13 @@ DEPENDENCIES
117
123
  dynamic_form
118
124
  factory_girl (~> 2.0.0.beta)
119
125
  factory_girl_rails (~> 1.1.beta)
120
- governor (>= 0.2.2)
126
+ governor (>= 0.5.0)
121
127
  governor_comments!
122
128
  jeweler (~> 1.5.2)
123
129
  mocha
124
130
  rails (~> 3.0.5)
125
131
  rakismet
132
+ rcov
126
133
  rspec-rails
127
134
  sqlite3
135
+ webrat
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = governor_comments
2
2
 
3
- *Governor[http://carpeliam.github.com/governor/]* (named after Rod
3
+ <b>Governor[http://carpeliam.github.com/governor/]</b> (named after Rod
4
4
  Blagojevich) is the pluggable blogging platform for Rails, built for people
5
5
  who want to build their blog into their website, not build their website into
6
6
  their blog.
@@ -30,7 +30,10 @@ Once you've installed the gem into your app, you need to run the generator:
30
30
 
31
31
  If you've only created one type of resource (which is typical), then you won't
32
32
  need any arguments. Otherwise, you'll need to specify which model you want to
33
- add comments to. This will create a Comment class and associated migration.
33
+ add comments to. This will create a Comment class and associated migration. If
34
+ you've created multiple resource types and you'd like to use comments with
35
+ multiple types, then specify <code>--polymorphic</code> as an option.
36
+
34
37
  Make sure to add the +name+, +email+, and +website+ fields to your User model
35
38
  if they don't exist already.
36
39
 
data/Rakefile CHANGED
@@ -35,6 +35,7 @@ end
35
35
  RSpec::Core::RakeTask.new(:rcov) do |spec|
36
36
  spec.pattern = 'spec/**/*_spec.rb'
37
37
  spec.rcov = true
38
+ spec.rcov_opts = %w{--exclude gems\/,spec\/}
38
39
  end
39
40
 
40
41
  task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -56,24 +56,12 @@ module Governor
56
56
  end
57
57
 
58
58
  def mark_spam
59
- @comment.update_attribute(:hidden, true)
60
- if @comment.respond_to?(:spam!)
61
- @comment.spam!
62
- flash[:notice] = 'That comment has been marked as spam, and will no longer be visible to other viewers. To remove it completely, you can delete it.'
63
- else
64
- flash[:warning] = 'Spam protection has not been installed. Please install and configure rakismet before continuing.'
65
- end
59
+ @comment.mark_spam
66
60
  redirect_to resource
67
61
  end
68
62
 
69
63
  def not_spam
70
- @comment.update_attribute(:hidden, false)
71
- if @comment.respond_to?(:ham!)
72
- @comment.ham!
73
- flash[:notice] = 'That comment has been marked as not spam, and will now be visible to other viewers.'
74
- else
75
- flash[:warning] = 'Spam protection has not been installed. Please install and configure rakismet before continuing.'
76
- end
64
+ @comment.not_spam
77
65
  redirect_to resource
78
66
  end
79
67
 
@@ -2,16 +2,6 @@
2
2
  <p><%= link_to 'add a comment', '#new_comment' %></p>
3
3
  <% unless resource.comments.empty? %><ul><%= render resource.comments %></ul><% end %>
4
4
  <p><%= form_for [resource, resource.comments.new] do |f| %>
5
- <%= f.error_messages %>
6
- <% unless governor_logged_in? %>
7
- <%= fields_for :commenter, Guest.new do |gf| %>
8
- <%= gf.text_field :name %> <%= gf.label :name, 'Name (required)' %><br/>
9
- <%= gf.text_field :email %> <%= gf.label :email, 'E-Mail (required, will not be published)' %><br/>
10
- <%= gf.text_field :website %> <%= gf.label :website %><br/>
11
- <% end %>
12
- <% end %>
13
- <%= f.text_field :title %> <%= f.label :title %><br/>
14
- <%= f.text_area :content, :size => '50x7' %>
15
- <p><%= f.submit 'New Comment' %></p>
5
+ <%= render :partial => 'governor/comments/form', :locals => {:f => f} %>
16
6
  <% end %></p>
17
7
  </div>
@@ -0,0 +1,43 @@
1
+ <h1>Comments Management</h1>
2
+
3
+ <%= form_tag polymorphic_path(mapping.plural, :action => :update_comments), :method => :put do %>
4
+ <div class="bulkActions">
5
+ <% options = %w(mark_spam not_spam destroy).inject([]) {|a,action| a << [t("governor_comments.#{action}"), action] } %>
6
+ <%= select_tag :bulk_operation, options_for_select([['Action', ''], *options]) %>
7
+ <%= submit_tag t('governor_comments.submit') %>
8
+ </div>
9
+ <table class="comments">
10
+ <tr>
11
+ <th></th>
12
+ <th>Author</th>
13
+ <th>Comment</th>
14
+ <th>Article</th>
15
+ </tr>
16
+ <% @comments.each do |c| %>
17
+ <tr>
18
+ <td class="checkbox">
19
+ <%= check_box_tag "comments[#{c.id}]" %>
20
+ </td>
21
+ <td class="author">
22
+ <%= link_to_if c.commenter.website.present?, c.commenter.name, c.commenter.website %>
23
+ <% if c.commenter.email.present? %>
24
+ <br><%= mail_to c.commenter.email, 'Contact', :encode => :javascript %>
25
+ <% end %>
26
+ </td>
27
+ <td class="comment">
28
+ <% if c.title %><strong><%= c.title %></strong><br><% end -%>
29
+ <%= c.content %>
30
+ <div class="commentActions">
31
+ <%= link_to t('governor_comments.reply'), polymorphic_path(c.resource, :anchor => :new_comment) %> |
32
+ <%= link_to t('governor_comments.edit'), polymorphic_path([c.resource, c], :action => :edit) %> |
33
+ <% spam_action = (c.hidden? ? 'not' : 'mark') + '_spam' %>
34
+ <%= link_to t(spam_action, :scope => 'governor_comments'), polymorphic_path([c.resource, c], :action => spam_action), :method => :put %> |
35
+ <%= link_to t('governor_comments.destroy'), polymorphic_path([c.resource, c]), :method => :delete, :confirm => 'Are you sure you want to remove this comment? It has not been marked as spam.' %>
36
+ </div>
37
+ </td>
38
+ <td class="article"><%= link_to c.resource.title, c.resource %></td>
39
+ </tr>
40
+ <% end %>
41
+ </table>
42
+
43
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <%= f.error_messages %>
2
+ <% if f.object.new_record? && !governor_logged_in? %>
3
+ <%= fields_for :commenter, Guest.new do |gf| %>
4
+ <%= gf.text_field :name %> <%= gf.label :name, 'Name (required)' %><br/>
5
+ <%= gf.text_field :email %> <%= gf.label :email, 'E-Mail (required, will not be published)' %><br/>
6
+ <%= gf.text_field :website %> <%= gf.label :website %><br/>
7
+ <% end %>
8
+ <% end %>
9
+ <%= f.text_field :title %> <%= f.label :title %><br/>
10
+ <%= f.text_area :content, :size => '50x7' %>
11
+ <p><%= f.submit "#{action_name.capitalize} Comment" %></p>
@@ -0,0 +1,4 @@
1
+ <h1>edit comment</h1>
2
+ <%= form_for [resource, @comment] do |f| %>
3
+ <% render :partial => 'governor/comments/form', :locals => {:f => f} %>
4
+ <% end %>
@@ -2,5 +2,11 @@
2
2
  # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
- hello: "Hello world"
6
- unauthorized_edit: "You're not allowed to edit this %{resource_type}."
5
+ governor_comments:
6
+ manage_comments: "Manage Comments"
7
+ reply: "Reply"
8
+ edit: "Edit"
9
+ mark_spam: "Mark as Spam"
10
+ not_spam: "Not Spam"
11
+ destroy: "Delete"
12
+ submit: "Apply"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{governor_comments}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Liam Morley"]
12
- s.date = %q{2011-04-12}
12
+ s.date = %q{2011-05-05}
13
13
  s.description = %q{Comments plugin for the Rails 3-based Governor blogging system.}
14
14
  s.email = %q{liam@carpeliam.com}
15
15
  s.extra_rdoc_files = [
@@ -29,19 +29,26 @@ Gem::Specification.new do |s|
29
29
  "app/helpers/governor_comments_helper.rb",
30
30
  "app/views/governor/articles/_comment_link.html.erb",
31
31
  "app/views/governor/articles/_comments.html.erb",
32
+ "app/views/governor/articles/edit_comments.html.erb",
32
33
  "app/views/governor/comments/_comment.html.erb",
34
+ "app/views/governor/comments/_form.html.erb",
35
+ "app/views/governor/comments/edit.html.erb",
33
36
  "app/views/governor/comments/new.html.erb",
34
37
  "config/locales/en.yml",
35
38
  "governor_comments.gemspec",
39
+ "lib/generators/governor/add_assets_generator.rb",
36
40
  "lib/generators/governor/create_comments_generator.rb",
41
+ "lib/generators/governor/templates/assets/javascripts/governor-comments.js",
42
+ "lib/generators/governor/templates/assets/stylesheets/governor-comments.css",
37
43
  "lib/generators/governor/templates/migrations/create_comments.rb",
38
44
  "lib/generators/governor/templates/models/comment.rb",
39
45
  "lib/generators/governor/templates/models/guest.rb",
46
+ "lib/governor/controllers/methods.rb",
40
47
  "lib/governor_comments.rb",
41
48
  "lib/governor_comments/comment.rb",
42
49
  "lib/governor_comments/rails.rb",
43
- "log/development.log",
44
50
  "script/rails",
51
+ "spec/controllers/governor/articles_controller_spec.rb",
45
52
  "spec/controllers/governor/comments_controller_spec.rb",
46
53
  "spec/governor_comments_spec.rb",
47
54
  "spec/models/article_spec.rb",
@@ -81,7 +88,7 @@ Gem::Specification.new do |s|
81
88
  "spec/rails_app/config/routes.rb",
82
89
  "spec/rails_app/db/migrate/20110329032256_devise_create_users.rb",
83
90
  "spec/rails_app/db/migrate/20110330020108_governor_create_articles.rb",
84
- "spec/rails_app/db/migrate/20110405030324_governor_create_comments.rb",
91
+ "spec/rails_app/db/migrate/20110501055541_governor_create_comments.rb",
85
92
  "spec/rails_app/db/schema.rb",
86
93
  "spec/rails_app/db/seeds.rb",
87
94
  "spec/rails_app/lib/tasks/.gitkeep",
@@ -91,10 +98,7 @@ Gem::Specification.new do |s|
91
98
  "spec/rails_app/public/favicon.ico",
92
99
  "spec/rails_app/public/images/rails.png",
93
100
  "spec/rails_app/public/javascripts/application.js",
94
- "spec/rails_app/public/javascripts/controls.js",
95
- "spec/rails_app/public/javascripts/dragdrop.js",
96
- "spec/rails_app/public/javascripts/effects.js",
97
- "spec/rails_app/public/javascripts/prototype.js",
101
+ "spec/rails_app/public/javascripts/jquery.js",
98
102
  "spec/rails_app/public/javascripts/rails.js",
99
103
  "spec/rails_app/public/robots.txt",
100
104
  "spec/rails_app/public/stylesheets/.gitkeep",
@@ -102,7 +106,9 @@ Gem::Specification.new do |s|
102
106
  "spec/rails_app/spec/factories.rb",
103
107
  "spec/rails_app/vendor/plugins/.gitkeep",
104
108
  "spec/spec_helper.rb",
105
- "spec/views/governor/articles/show.html.erb_spec.rb"
109
+ "spec/views/governor/articles/show.html.erb_spec.rb",
110
+ "spec/views/layouts/application.html.erb_spec.rb",
111
+ "tmp/.gitkeep"
106
112
  ]
107
113
  s.homepage = %q{http://carpeliam.github.com/governor}
108
114
  s.licenses = ["MIT"]
@@ -110,6 +116,7 @@ Gem::Specification.new do |s|
110
116
  s.rubygems_version = %q{1.3.7}
111
117
  s.summary = %q{Comments plugin for the Rails 3-based Governor blogging system.}
112
118
  s.test_files = [
119
+ "spec/controllers/governor/articles_controller_spec.rb",
113
120
  "spec/controllers/governor/comments_controller_spec.rb",
114
121
  "spec/governor_comments_spec.rb",
115
122
  "spec/models/article_spec.rb",
@@ -138,12 +145,13 @@ Gem::Specification.new do |s|
138
145
  "spec/rails_app/config/routes.rb",
139
146
  "spec/rails_app/db/migrate/20110329032256_devise_create_users.rb",
140
147
  "spec/rails_app/db/migrate/20110330020108_governor_create_articles.rb",
141
- "spec/rails_app/db/migrate/20110405030324_governor_create_comments.rb",
148
+ "spec/rails_app/db/migrate/20110501055541_governor_create_comments.rb",
142
149
  "spec/rails_app/db/schema.rb",
143
150
  "spec/rails_app/db/seeds.rb",
144
151
  "spec/rails_app/spec/factories.rb",
145
152
  "spec/spec_helper.rb",
146
- "spec/views/governor/articles/show.html.erb_spec.rb"
153
+ "spec/views/governor/articles/show.html.erb_spec.rb",
154
+ "spec/views/layouts/application.html.erb_spec.rb"
147
155
  ]
148
156
 
149
157
  if s.respond_to? :specification_version then
@@ -152,10 +160,12 @@ Gem::Specification.new do |s|
152
160
 
153
161
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
154
162
  s.add_runtime_dependency(%q<rails>, ["~> 3.0.5"])
155
- s.add_runtime_dependency(%q<governor>, [">= 0.2.2"])
163
+ s.add_runtime_dependency(%q<governor>, [">= 0.5.0"])
156
164
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
157
165
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
158
166
  s.add_development_dependency(%q<rspec-rails>, [">= 0"])
167
+ s.add_development_dependency(%q<rcov>, [">= 0"])
168
+ s.add_development_dependency(%q<webrat>, [">= 0"])
159
169
  s.add_development_dependency(%q<mocha>, [">= 0"])
160
170
  s.add_development_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
161
171
  s.add_development_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
@@ -166,10 +176,12 @@ Gem::Specification.new do |s|
166
176
  s.add_development_dependency(%q<rakismet>, [">= 0"])
167
177
  else
168
178
  s.add_dependency(%q<rails>, ["~> 3.0.5"])
169
- s.add_dependency(%q<governor>, [">= 0.2.2"])
179
+ s.add_dependency(%q<governor>, [">= 0.5.0"])
170
180
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
171
181
  s.add_dependency(%q<sqlite3>, [">= 0"])
172
182
  s.add_dependency(%q<rspec-rails>, [">= 0"])
183
+ s.add_dependency(%q<rcov>, [">= 0"])
184
+ s.add_dependency(%q<webrat>, [">= 0"])
173
185
  s.add_dependency(%q<mocha>, [">= 0"])
174
186
  s.add_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
175
187
  s.add_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
@@ -181,10 +193,12 @@ Gem::Specification.new do |s|
181
193
  end
182
194
  else
183
195
  s.add_dependency(%q<rails>, ["~> 3.0.5"])
184
- s.add_dependency(%q<governor>, [">= 0.2.2"])
196
+ s.add_dependency(%q<governor>, [">= 0.5.0"])
185
197
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
186
198
  s.add_dependency(%q<sqlite3>, [">= 0"])
187
199
  s.add_dependency(%q<rspec-rails>, [">= 0"])
200
+ s.add_dependency(%q<rcov>, [">= 0"])
201
+ s.add_dependency(%q<webrat>, [">= 0"])
188
202
  s.add_dependency(%q<mocha>, [">= 0"])
189
203
  s.add_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
190
204
  s.add_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+ module Governor
3
+ class AddAssetsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ desc 'Installs assets into your public directory.'
6
+
7
+ def install_javascripts
8
+ copy_file 'assets/javascripts/governor-comments.js', 'public/javascripts/governor-comments.js'
9
+ end
10
+
11
+ def install_stylesheets
12
+ copy_file 'assets/stylesheets/governor-comments.css', 'public/stylesheets/governor-comments.css'
13
+ end
14
+ end
15
+ end
@@ -5,6 +5,8 @@ module Governor
5
5
  include Rails::Generators::Migration
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
  argument :resource, :type => :string, :default => Governor.default_resource.plural.to_s
8
+ class_option :polymorphic, :type => :boolean, :default => false, :desc => 'Set to true if you want to associate comments with multiple object types. False by default.'
9
+ desc 'Adds Comment and Guest models and accompanying migrations to your application.'
8
10
 
9
11
  def self.next_migration_number(dirname)
10
12
  if ActiveRecord::Base.timestamped_migrations
@@ -0,0 +1,7 @@
1
+ $(document).ready(function() {
2
+ $('td.comment').hover(function() {
3
+ $(this).children('.commentActions').show();
4
+ }, function() {
5
+ $(this).children('.commentActions').hide();
6
+ });
7
+ });
@@ -0,0 +1,18 @@
1
+ table.comments th {
2
+ text-align: left;
3
+ }
4
+ table.comments td {
5
+ vertical-align: top;
6
+ }
7
+
8
+ .author {
9
+ width: 8em;
10
+ }
11
+
12
+ .comment {
13
+ width: 15em;
14
+ }
15
+
16
+ .comment .commentActions {
17
+ display: none;
18
+ }
@@ -4,7 +4,7 @@ class GovernorCreateComments < ActiveRecord::Migration
4
4
  t.string :title, :content
5
5
  t.boolean :hidden, :default => false
6
6
  t.references :commenter, :polymorphic => true
7
- t.references :<%= mapping.singular %>
7
+ t.references :resource<%= ', :polymorphic => :true' if options[:polymorphic] %>
8
8
  t.timestamps
9
9
  end
10
10
 
@@ -1,3 +1,4 @@
1
1
  class Comment < ActiveRecord::Base
2
2
  include GovernorComments::Comment
3
+ belongs_to :resource, :<%= options[:polymorphic] ? 'polymorphic => :true' : %Q{class_name => "#{mapping.to.name}"} %>
3
4
  end
@@ -0,0 +1,18 @@
1
+ module Governor
2
+ module Controllers
3
+ module Methods
4
+ def edit_comments
5
+ @comments = Comment.all(:include => [:resource, :commenter])
6
+ end
7
+ def update_comments
8
+ action = params[:bulk_operation]
9
+ ids = params[:comments].try(:keys) || []
10
+ result = true
11
+ Comment.all(:conditions => {:id => ids}).each do |comment|
12
+ result &= comment.send(action)
13
+ end
14
+ redirect_to mapping.plural
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,11 +2,6 @@ module GovernorComments
2
2
  module Comment
3
3
  require 'md5'
4
4
  def self.included(base)
5
- if Governor.resources.size == 1
6
- base.belongs_to Governor.default_resource.singular
7
- else
8
- base.belongs_to :resource, :polymorphic => true
9
- end
10
5
  base.belongs_to :commenter, :polymorphic => true
11
6
  if defined?(Rakismet)
12
7
  base.send :include, Rakismet::Model
@@ -16,9 +11,22 @@ module GovernorComments
16
11
  :comment_type => 'comment'
17
12
  end
18
13
 
14
+ base.scope :hidden, base.where(:hidden => true)
15
+ base.scope :public, base.where(:hidden => false)
16
+
19
17
  base.validates_presence_of :content
20
18
  end
21
19
 
20
+ def mark_spam
21
+ update_attribute(:hidden, true)
22
+ spam! if respond_to?(:spam!)
23
+ end
24
+
25
+ def not_spam
26
+ update_attribute(:hidden, false)
27
+ ham! if respond_to?(:ham!)
28
+ end
29
+
22
30
  def gravatar_url(size = 48, default = "http://github.com/images/gravatars/gravatar-#{size}.png")
23
31
  if commenter.respond_to? :email
24
32
  hash = MD5::md5 commenter.email.downcase
@@ -1,5 +1,7 @@
1
1
  module GovernorComments
2
2
  class Engine < ::Rails::Engine
3
-
3
+ config.to_prepare do
4
+ Governor::ArticlesController.helper GovernorCommentsHelper
5
+ end
4
6
  end
5
7
  end
@@ -1,20 +1,29 @@
1
+ require File.expand_path('../governor/controllers/methods.rb', __FILE__)
1
2
  require 'governor_comments/comment'
2
3
  require 'governor_comments/rails'
3
4
 
4
5
  comments = Governor::Plugin.new('comments')
5
6
  comments.add_migration(File.join(File.dirname(__FILE__), 'templates', 'create_comments.rb'))
6
7
  comments.set_routes do
8
+ collection do
9
+ get 'edit_comments'
10
+ put 'update_comments'
11
+ end
7
12
  resources :comments, :module => :governor do
8
13
  member do
9
- put 'mark_spam', 'not_spam'
14
+ post 'mark_spam', 'not_spam'
10
15
  end
11
16
  end
12
17
  end
13
18
  comments.register_model_callback do |base|
14
- base.has_many :comments, :dependent => :destroy
19
+ association = Comment.reflect_on_association(:resource)
20
+ comment_args = (association.options[:polymorphic]) ? {:as => 'resource'} : {:foreign_key => 'resource_id'}
21
+ base.has_many :comments, comment_args.merge(:dependent => :destroy)
15
22
  end
16
- comments.add_helper "GovernorCommentsHelper"
17
23
  comments.register_partial :after_article_whole, 'articles/comments'
18
24
  comments.register_partial :after_article_description, 'articles/comment_link'
25
+ comments.add_to_navigation do |resource|
26
+ concat(link_to(t('governor_comments.manage_comments'), polymorphic_path(resource, :action => :edit_comments)))
27
+ end
19
28
 
20
29
  Governor::PluginManager.register comments
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ module Governor
4
+ describe ArticlesController do
5
+ include Devise::TestHelpers
6
+ render_views
7
+
8
+ before(:each) do
9
+ @user = Factory(:user)
10
+ @article = Factory(:article, :author => @user)
11
+ @comments = [Factory(:comment, :resource => @article, :commenter => @user),
12
+ Factory(:comment, :resource => @article, :commenter => @user),
13
+ Factory(:comment, :resource => @article, :commenter => @user)]
14
+ end
15
+
16
+ it "loads GovernorCommentsHelper" do
17
+ get :show, :governor_mapping => :articles, :id => @article.id
18
+ response.body.should =~ /3 comments/
19
+ end
20
+
21
+ context "comments management" do
22
+ it "renders the form" do
23
+ get :edit_comments, :governor_mapping => :articles
24
+ response.body.should =~ /Comments Management/
25
+ end
26
+
27
+ it "marks 2 comments as spam" do
28
+ post :update_comments, :governor_mapping => :articles, :bulk_operation => 'mark_spam',
29
+ :comments => {@comments[0].id.to_s => '1', @comments[2].id.to_s => '1'}
30
+ Comment.count.should == 3
31
+ Comment.hidden.count.should == 2
32
+ end
33
+
34
+ it "unmarks all comments as spam" do
35
+ Comment.update_all(:hidden => true)
36
+ post :update_comments, :governor_mapping => :articles, :bulk_operation => 'not_spam',
37
+ :comments => {@comments[0].id.to_s => '1', @comments[1].id.to_s => '1', @comments[2].id.to_s => '1'}
38
+ Comment.public.count.should == 3
39
+ end
40
+
41
+ it "deletes all comments" do
42
+ post :update_comments, :governor_mapping => :articles, :bulk_operation => 'destroy',
43
+ :comments => {@comments[0].id.to_s => '1', @comments[1].id.to_s => '1', @comments[2].id.to_s => '1'}
44
+ Comment.count.should == 0
45
+ end
46
+ end
47
+ end
48
+ end
@@ -7,7 +7,7 @@ module Governor
7
7
  before(:each) do
8
8
  @user = Factory(:user)
9
9
  @article = Factory(:article, :author => @user)
10
- @comment = Factory(:comment, :article => @article, :commenter => @user)
10
+ @comment = Factory(:comment, :resource => @article, :commenter => @user)
11
11
  sign_in @user
12
12
  end
13
13
 
@@ -9,7 +9,7 @@ gem 'sqlite3'
9
9
 
10
10
  gem 'devise'
11
11
  gem 'rakismet'
12
- gem 'governor', '>= 0.2.2'
12
+ gem 'governor', :git => 'git://github.com/carpeliam/governor.git'
13
13
  gem 'governor_comments', :path => '../..'
14
14
 
15
15
  gem 'dynamic_form'
@@ -1,8 +1,15 @@
1
+ GIT
2
+ remote: git://github.com/carpeliam/governor.git
3
+ revision: 02e939cd0d8bb4c33549dc5c293996c049e37e6c
4
+ specs:
5
+ governor (0.4.0)
6
+ rails (~> 3.0.5)
7
+
1
8
  PATH
2
9
  remote: ../..
3
10
  specs:
4
- governor_comments (0.1.0)
5
- governor (>= 0.2.0)
11
+ governor_comments (0.1.2)
12
+ governor (>= 0.2.2)
6
13
  rails (~> 3.0.5)
7
14
 
8
15
  GEM
@@ -44,8 +51,6 @@ GEM
44
51
  dynamic_form (1.1.3)
45
52
  erubis (2.6.6)
46
53
  abstract (>= 1.0.0)
47
- governor (0.2.2)
48
- rails (~> 3.0.5)
49
54
  i18n (0.5.0)
50
55
  mail (2.2.15)
51
56
  activesupport (>= 2.3.6)
@@ -89,7 +94,7 @@ PLATFORMS
89
94
  DEPENDENCIES
90
95
  devise
91
96
  dynamic_form
92
- governor (>= 0.2.2)
97
+ governor!
93
98
  governor_comments!
94
99
  rails (= 3.0.5)
95
100
  rakismet
@@ -1,3 +1,4 @@
1
1
  class Comment < ActiveRecord::Base
2
2
  include GovernorComments::Comment
3
+ belongs_to :resource, :class_name => "Article"
3
4
  end