radiant-comments-extension 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +40 -0
  3. data/HELP_admin.markdown +52 -0
  4. data/HELP_designer.markdown +36 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +53 -0
  7. data/Rakefile +133 -0
  8. data/TODO +6 -0
  9. data/VERSION +1 -0
  10. data/app/controllers/admin/comments_controller.rb +130 -0
  11. data/app/controllers/comments_controller.rb +59 -0
  12. data/app/helpers/admin/comments_helper.rb +7 -0
  13. data/app/models/akismet_spam_filter.rb +37 -0
  14. data/app/models/comment.rb +121 -0
  15. data/app/models/comment_mailer.rb +24 -0
  16. data/app/models/mollom_spam_filter.rb +52 -0
  17. data/app/models/simple_spam_filter.rb +38 -0
  18. data/app/models/spam_filter.rb +43 -0
  19. data/app/views/admin/comments/_comment.rhtml +34 -0
  20. data/app/views/admin/comments/_form.rhtml +36 -0
  21. data/app/views/admin/comments/edit.rhtml +5 -0
  22. data/app/views/admin/comments/index.rhtml +55 -0
  23. data/app/views/admin/pages/_comments.rhtml +0 -0
  24. data/app/views/admin/pages/_edit_comments_enabled.rhtml +8 -0
  25. data/app/views/admin/pages/_index_head_view_comments.rhtml +1 -0
  26. data/app/views/admin/pages/_index_view_comments.rhtml +11 -0
  27. data/app/views/comment_mailer/comment_notification.rhtml +21 -0
  28. data/app/views/comments/_comment.rhtml +1 -0
  29. data/app/views/comments/_form.rhtml +23 -0
  30. data/app/views/comments/_new.rhtml +5 -0
  31. data/autotest/discover.rb +3 -0
  32. data/comments_extension.rb +81 -0
  33. data/cucumber.yml +1 -0
  34. data/db/migrate/001_create_comments.rb +29 -0
  35. data/db/migrate/002_create_snippets.rb +115 -0
  36. data/db/migrate/003_change_filter_id_from_integer_to_string.rb +10 -0
  37. data/db/migrate/004_add_approval_columns.rb +13 -0
  38. data/db/migrate/005_add_mollomid_column.rb +11 -0
  39. data/db/migrate/006_move_config_to_migrations.rb +22 -0
  40. data/db/migrate/007_add_preference_for_simple_spamcheck.rb +12 -0
  41. data/features/support/env.rb +16 -0
  42. data/features/support/paths.rb +16 -0
  43. data/lib/akismet.rb +134 -0
  44. data/lib/comment_page_extensions.rb +41 -0
  45. data/lib/comment_tags.rb +338 -0
  46. data/lib/mollom.rb +246 -0
  47. data/lib/radiant-comments-extension.rb +0 -0
  48. data/lib/tasks/comments_extension_tasks.rake +68 -0
  49. data/public/images/admin/accept.png +0 -0
  50. data/public/images/admin/comment_edit.png +0 -0
  51. data/public/images/admin/comments.png +0 -0
  52. data/public/images/admin/comments_delete.png +0 -0
  53. data/public/images/admin/delete.png +0 -0
  54. data/public/images/admin/email.png +0 -0
  55. data/public/images/admin/error.png +0 -0
  56. data/public/images/admin/link.png +0 -0
  57. data/public/images/admin/page_white_edit.png +0 -0
  58. data/public/images/admin/table_save.png +0 -0
  59. data/public/images/admin/tick.png +0 -0
  60. data/public/stylesheets/admin/comments.css +41 -0
  61. data/radiant-comments-extension.gemspec +133 -0
  62. data/spec/controllers/admin/comments_controller_spec.rb +57 -0
  63. data/spec/controllers/admin/comments_routing_spec.rb +43 -0
  64. data/spec/controllers/page_postback_spec.rb +51 -0
  65. data/spec/datasets/comments_dataset.rb +7 -0
  66. data/spec/models/akismet_spam_filter_spec.rb +61 -0
  67. data/spec/models/comment_spec.rb +148 -0
  68. data/spec/models/comment_tags_spec.rb +55 -0
  69. data/spec/models/mollom_spam_filter_spec.rb +103 -0
  70. data/spec/models/simple_spam_filter_spec.rb +44 -0
  71. data/spec/models/spam_filter_spec.rb +38 -0
  72. data/spec/spec.opts +6 -0
  73. data/spec/spec_helper.rb +36 -0
  74. data/test/fixtures/users.yml +6 -0
  75. data/test/integration/comment_enabling_test.rb +18 -0
  76. data/test/test_helper.rb +24 -0
  77. data/test/unit/comment_test.rb +52 -0
  78. metadata +177 -0
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SimpleSpamFilter do
4
+ dataset :comments
5
+
6
+ before :each do
7
+ @comment = comments(:first)
8
+ Radiant::Config['comments.simple_spam_filter_required?'] = true
9
+ end
10
+
11
+ it "should always approve comments (they passed validation already)" do
12
+ SimpleSpamFilter.should be_approved(@comment)
13
+ end
14
+
15
+ it "should validate the comment when the challenge is not defined and not required" do
16
+ Radiant::Config['comments.simple_spam_filter_required?'] = false
17
+ @comment.valid_spam_answer.should be_nil
18
+ @comment.spam_answer.should be_nil
19
+ SimpleSpamFilter.valid?(@comment).should be_true
20
+ end
21
+
22
+ it "should not validate the comment when the response does not match the challenge" do
23
+ @comment.valid_spam_answer = 'TRUE'
24
+ @comment.spam_answer = 'FALSE'
25
+ SimpleSpamFilter.valid?(@comment).should be_false
26
+ @comment.errors.full_messages.to_sentence.should =~ /Spam answer/
27
+ end
28
+
29
+ it "should validate the comment when the response matches the challenge" do
30
+ correct_answer = "that's THE way it ought to be!".to_slug
31
+ hashed_answer = Digest::MD5.hexdigest(correct_answer)
32
+ @comment.valid_spam_answer = hashed_answer
33
+ @comment.spam_answer = correct_answer
34
+ SimpleSpamFilter.valid?(@comment).should be_true
35
+ end
36
+
37
+ it "should allow differing capitalization and punctuation in the response" do
38
+ correct_answer = "that's THE way it ought to be!".to_slug
39
+ hashed_answer = Digest::MD5.hexdigest(correct_answer)
40
+ @comment.valid_spam_answer = hashed_answer
41
+ @comment.spam_answer = "That's the way it ought to be!"
42
+ SimpleSpamFilter.valid?(@comment).should be_true
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SpamFilter do
4
+ dataset :comments
5
+
6
+ it "should be a Simpleton" do
7
+ SpamFilter.included_modules.should include(Simpleton)
8
+ end
9
+
10
+ it "should require subclasses to implement the approved? method" do
11
+ lambda { SpamFilter.approved?(comments(:first)) }.should raise_error(NotImplementedError)
12
+ end
13
+
14
+ it "should accept a comment as spam and do nothing" do
15
+ lambda { SpamFilter.spam!(comments(:first)) }.should_not raise_error
16
+ end
17
+
18
+ it "should not be configured by default" do
19
+ SpamFilter.should_not be_configured
20
+ end
21
+
22
+ describe "selecting an appropriate subclass" do
23
+ it "should select the Simple filter if no other filters are configured" do
24
+ SpamFilter.descendants.without(SimpleSpamFilter).each do |f|
25
+ f.stub!(:configured?).and_return(false)
26
+ end
27
+ SpamFilter.select.should == SimpleSpamFilter
28
+ end
29
+
30
+ it "should select the first properly configured filter" do
31
+ MollomSpamFilter.stub!(:configured?).and_return(true)
32
+ SpamFilter.descendants.without(MollomSpamFilter).each do |f|
33
+ f.stub!(:configured?).and_return(false)
34
+ end
35
+ SpamFilter.select.should == MollomSpamFilter
36
+ end
37
+ end
38
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
@@ -0,0 +1,6 @@
1
+ admin:
2
+ id: 3
3
+ name: Admin User
4
+ login: admin
5
+ password: <%= User.new.sha1 'password' %>
6
+ admin: true
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class CommentEnablingTest < ActionController::IntegrationTest
4
+ fixtures :users
5
+
6
+ def test_should_enable_comments
7
+ post '/admin/welcome/login', :user => {:login => 'admin', :password => 'password'}
8
+ assert_redirected_to '/admin/welcome'
9
+
10
+ page = Page.create!(:title => "FOO", :slug => "foo", :breadcrumb => "FOO", :class_name => "Page")
11
+ assert !page.enable_comments
12
+
13
+ post "/admin/pages/#{page.id}/comments/enable"
14
+ assert_redirected_to '/admin/pages'
15
+
16
+ assert page.reload.enable_comments
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'test/unit'
2
+ # Load the environment
3
+ unless defined? RADIANT_ROOT
4
+ ENV["RAILS_ENV"] = "test"
5
+ case
6
+ when ENV["RADIANT_ENV_FILE"]
7
+ require ENV["RADIANT_ENV_FILE"]
8
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
10
+ else
11
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
12
+ end
13
+ end
14
+ require "#{RADIANT_ROOT}/test/test_helper"
15
+
16
+ class Test::Unit::TestCase
17
+ self.use_transactional_fixtures = true
18
+ self.use_instantiated_fixtures = false
19
+ self.fixture_path << File.expand_path(File.dirname(__FILE__)) + '/fixtures'
20
+ end
21
+
22
+ class ActionController::IntegrationTest < Test::Unit::TestCase
23
+ self.fixture_path = File.expand_path(File.dirname(__FILE__)) + '/fixtures'
24
+ end
@@ -0,0 +1,52 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+
4
+ class CommentTest < Test::Unit::TestCase
5
+ def test_valid_comment
6
+ comment = Comment.new do |c|
7
+ c.author = "Foo Bar"
8
+ c.author_email = "foo@bar.com"
9
+ c.author_url = "http://www.test.com/"
10
+ c.content = "This is a comment"
11
+ end
12
+
13
+ assert_valid comment
14
+
15
+ comment.save
16
+
17
+ comment_stored = Comment.find_by_author("Foo Bar")
18
+
19
+ assert_not_nil(comment)
20
+ assert_equal(comment.author, comment_stored.author)
21
+ assert_equal(comment.author_email, comment_stored.author_email)
22
+ assert_equal(comment.author_url, comment_stored.author_url)
23
+ assert_equal(comment.content, comment_stored.content)
24
+ end
25
+
26
+ def test_download_csv_routes
27
+ assert_routing "admin/comments/all",
28
+ {:controller => "admin/comments", :action => "index", :status => "all"}
29
+ assert_routing "admin/comments/all.csv",
30
+ {:controller => "admin/comments", :action => "index", :status => "all", :format => 'csv'}
31
+
32
+ assert_routing "admin/pages/6/comments/all.csv",
33
+ {:controller => "admin/comments", :action => "index", :status => "all", :format => 'csv', :page_id => "6"}
34
+ assert_generates "admin/pages/6/comments/all.csv",
35
+ {:controller => "admin/comments", :action => "index", :format => 'csv', :page_id => "6"}
36
+ end
37
+
38
+ def test_not_allowing_update_of_protected_attribs
39
+ @comment = Comment.create(
40
+ :author => "Evil Approve",
41
+ :author_email => "foo@bar.com",
42
+ :author_url => "http://www.test.com/",
43
+ :content => "Comment approved?",
44
+ :approved_at => Time.now,
45
+ :approved_by => 1
46
+ );
47
+ @comment = Comment.find_by_author('Evil Approve')
48
+ assert_nil(@comment.approved_at)
49
+ assert_nil(@comment.approved_by)
50
+ end
51
+
52
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-comments-extension
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
10
+ platform: ruby
11
+ authors:
12
+ - Jim Gay
13
+ - Ryan Heneise
14
+ - Sean Cribbs
15
+ - John Muhl
16
+ - Sven Schwyn
17
+ - Gerrit Kaiser
18
+ - Stephen Lombardo
19
+ - Benny Degezelle
20
+ - Frank Louwers
21
+ - Michael Hale
22
+ - Nathaniel Talbott
23
+ - John Croisant
24
+ - Jon Leighton
25
+ - Witter Cheng
26
+ - Keith Bingman
27
+ autorequire:
28
+ bindir: bin
29
+ cert_chain: []
30
+
31
+ date: 2010-04-01 00:00:00 -04:00
32
+ default_executable:
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: radiant
36
+ prerelease: false
37
+ requirement: &id001 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id001
46
+ description: Adds blog-like comment functionality to Radiant.
47
+ email: jim@saturnflyer.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ - TODO
55
+ files:
56
+ - .gitignore
57
+ - CHANGELOG
58
+ - HELP_admin.markdown
59
+ - HELP_designer.markdown
60
+ - MIT-LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - TODO
64
+ - VERSION
65
+ - app/controllers/admin/comments_controller.rb
66
+ - app/controllers/comments_controller.rb
67
+ - app/helpers/admin/comments_helper.rb
68
+ - app/models/akismet_spam_filter.rb
69
+ - app/models/comment.rb
70
+ - app/models/comment_mailer.rb
71
+ - app/models/mollom_spam_filter.rb
72
+ - app/models/simple_spam_filter.rb
73
+ - app/models/spam_filter.rb
74
+ - app/views/admin/comments/_comment.rhtml
75
+ - app/views/admin/comments/_form.rhtml
76
+ - app/views/admin/comments/edit.rhtml
77
+ - app/views/admin/comments/index.rhtml
78
+ - app/views/admin/pages/_comments.rhtml
79
+ - app/views/admin/pages/_edit_comments_enabled.rhtml
80
+ - app/views/admin/pages/_index_head_view_comments.rhtml
81
+ - app/views/admin/pages/_index_view_comments.rhtml
82
+ - app/views/comment_mailer/comment_notification.rhtml
83
+ - app/views/comments/_comment.rhtml
84
+ - app/views/comments/_form.rhtml
85
+ - app/views/comments/_new.rhtml
86
+ - autotest/discover.rb
87
+ - comments_extension.rb
88
+ - cucumber.yml
89
+ - db/migrate/001_create_comments.rb
90
+ - db/migrate/002_create_snippets.rb
91
+ - db/migrate/003_change_filter_id_from_integer_to_string.rb
92
+ - db/migrate/004_add_approval_columns.rb
93
+ - db/migrate/005_add_mollomid_column.rb
94
+ - db/migrate/006_move_config_to_migrations.rb
95
+ - db/migrate/007_add_preference_for_simple_spamcheck.rb
96
+ - features/support/env.rb
97
+ - features/support/paths.rb
98
+ - lib/akismet.rb
99
+ - lib/comment_page_extensions.rb
100
+ - lib/comment_tags.rb
101
+ - lib/mollom.rb
102
+ - lib/radiant-comments-extension.rb
103
+ - lib/tasks/comments_extension_tasks.rake
104
+ - public/images/admin/accept.png
105
+ - public/images/admin/comment_edit.png
106
+ - public/images/admin/comments.png
107
+ - public/images/admin/comments_delete.png
108
+ - public/images/admin/delete.png
109
+ - public/images/admin/email.png
110
+ - public/images/admin/error.png
111
+ - public/images/admin/link.png
112
+ - public/images/admin/page_white_edit.png
113
+ - public/images/admin/table_save.png
114
+ - public/images/admin/tick.png
115
+ - public/stylesheets/admin/comments.css
116
+ - radiant-comments-extension.gemspec
117
+ - spec/controllers/admin/comments_controller_spec.rb
118
+ - spec/controllers/admin/comments_routing_spec.rb
119
+ - spec/controllers/page_postback_spec.rb
120
+ - spec/datasets/comments_dataset.rb
121
+ - spec/models/akismet_spam_filter_spec.rb
122
+ - spec/models/comment_spec.rb
123
+ - spec/models/comment_tags_spec.rb
124
+ - spec/models/mollom_spam_filter_spec.rb
125
+ - spec/models/simple_spam_filter_spec.rb
126
+ - spec/models/spam_filter_spec.rb
127
+ - spec/spec.opts
128
+ - spec/spec_helper.rb
129
+ - test/fixtures/users.yml
130
+ - test/integration/comment_enabling_test.rb
131
+ - test/test_helper.rb
132
+ - test/unit/comment_test.rb
133
+ has_rdoc: true
134
+ homepage: http://github.com/saturnflyer/radiant-comments-extension
135
+ licenses: []
136
+
137
+ post_install_message:
138
+ rdoc_options:
139
+ - --charset=UTF-8
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirements: []
157
+
158
+ rubyforge_project:
159
+ rubygems_version: 1.3.6
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Comments Extension for Radiant CMS
163
+ test_files:
164
+ - spec/controllers/admin/comments_controller_spec.rb
165
+ - spec/controllers/admin/comments_routing_spec.rb
166
+ - spec/controllers/page_postback_spec.rb
167
+ - spec/datasets/comments_dataset.rb
168
+ - spec/models/akismet_spam_filter_spec.rb
169
+ - spec/models/comment_spec.rb
170
+ - spec/models/comment_tags_spec.rb
171
+ - spec/models/mollom_spam_filter_spec.rb
172
+ - spec/models/simple_spam_filter_spec.rb
173
+ - spec/models/spam_filter_spec.rb
174
+ - spec/spec_helper.rb
175
+ - test/integration/comment_enabling_test.rb
176
+ - test/test_helper.rb
177
+ - test/unit/comment_test.rb