has_comments 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{LICENSE.txt → MIT-LICENSE} +1 -1
- data/README +13 -0
- data/Rakefile +15 -38
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/generators/USAGE +8 -0
- data/lib/generators/has_comments_generator.rb +22 -0
- data/lib/generators/templates/comment.rb +3 -0
- data/lib/generators/templates/comments_controller.rb +42 -0
- data/lib/generators/templates/create_comments.rb +10 -0
- data/lib/has_comments.rb +29 -1
- data/test/database.yml +9 -0
- data/test/has_comments_test.rb +32 -0
- data/test/schema.rb +9 -0
- data/test/test_helper.rb +36 -0
- data/uninstall.rb +1 -0
- metadata +23 -40
- data/.document +0 -5
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -16
- data/README.rdoc +0 -19
- data/test/helper.rb +0 -17
- data/test/test_has_comments.rb +0 -7
data/{LICENSE.txt → MIT-LICENSE}
RENAMED
data/README
ADDED
data/Rakefile
CHANGED
@@ -1,46 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "has_comments"
|
18
|
-
gem.homepage = "http://github.com/johnfelix/has_comments"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = "comments gem"
|
21
|
-
gem.description = "comments"
|
22
|
-
gem.email = "felix1985@gmail.com"
|
23
|
-
gem.authors = ["John Felix"]
|
24
|
-
gem.version = "0.2.0"
|
25
|
-
# dependencies defined in Gemfile
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
1
|
+
#!/usr/bin/env rake
|
29
2
|
require 'rake/testtask'
|
30
|
-
|
31
|
-
test.libs << 'lib' << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
3
|
+
require 'rdoc/task'
|
35
4
|
|
5
|
+
desc 'Default: run unit tests.'
|
36
6
|
task :default => :test
|
37
7
|
|
38
|
-
|
39
|
-
Rake::
|
40
|
-
|
8
|
+
desc 'Test the has_comments plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
41
15
|
|
16
|
+
desc 'Generate documentation for the has_comments plugin.'
|
17
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
42
18
|
rdoc.rdoc_dir = 'rdoc'
|
43
|
-
rdoc.title
|
44
|
-
rdoc.
|
19
|
+
rdoc.title = 'HasComments'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
45
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
23
|
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/lib/has_comments.rb'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class HasCommentsGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def create_model_file
|
8
|
+
template "comment.rb","app/models/comment.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_migration_file
|
12
|
+
migration_template "create_comments.rb","db/migrate/create_comments.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_controller_file
|
16
|
+
template "comments_controller.rb","app/controllers/comments_controller.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.next_migration_number(path)
|
20
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class CommentsController < ActionController::Base
|
2
|
+
respond_to :html, :xml, :json
|
3
|
+
|
4
|
+
def index
|
5
|
+
@comments = Comment.where(:article_id => params[:article_id]).all
|
6
|
+
respond_with(@comments)
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@comment = Comment.new
|
11
|
+
respond_with(@comments)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@comment = Comment.new(params[:comment])
|
16
|
+
if @comment.save
|
17
|
+
redirect_to article_url(params[:article_id])
|
18
|
+
else
|
19
|
+
render :new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
@comment = Comment.find(params[:id])
|
25
|
+
respond_with(@comment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@comment = Comment.find( params[:id] )
|
30
|
+
if @comment.update_attributes(params[:comment])
|
31
|
+
redirect_to article_url(params[:article_id])
|
32
|
+
else
|
33
|
+
render :edit
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
@comment = Comment.find( params[:id] )
|
39
|
+
@comment.destroy
|
40
|
+
redirect_to article_url(params[:article_id])
|
41
|
+
end
|
42
|
+
end
|
data/lib/has_comments.rb
CHANGED
@@ -1 +1,29 @@
|
|
1
|
-
|
1
|
+
module HasComments
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def has_comments
|
8
|
+
has_many :comments, :as => :comment
|
9
|
+
send :include, InstanceMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
def method_missing(method, *args )
|
15
|
+
case method
|
16
|
+
when /first_\d+_comments/i
|
17
|
+
self.comments.limit($1)
|
18
|
+
when /last_\d+_comments/i
|
19
|
+
self.comments.limit($1).order("created_at desc")
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ActiveRecord::Base
|
28
|
+
include HasComments
|
29
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/test_helper'
|
2
|
+
|
3
|
+
class HasCommentsTest < ActiveSupport::TestCase
|
4
|
+
load_schema
|
5
|
+
|
6
|
+
class Article < ActiveRecord::Base
|
7
|
+
has_comments
|
8
|
+
end
|
9
|
+
|
10
|
+
class Comment < ActiveRecord::Base
|
11
|
+
belongs_to :comment, :polymorphic => true
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@article = Article.create!({:title => "title", :content => "content"})
|
16
|
+
@first_comment = Comment.create!({:title => "title", :content => "content", :comment => @article})
|
17
|
+
@second_comment = Comment.create!({:title => "title", :content => "content", :comment => @article})
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_existence_for_first_comments_method
|
21
|
+
assert_equal 2, @article.first_2_comments.count
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_existence_for_last_comments_method
|
25
|
+
assert_equal 2, @article.last_2_comments.count
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@article.comments.destroy_all
|
30
|
+
@article.destroy
|
31
|
+
end
|
32
|
+
end
|
data/test/schema.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# vendor/plugins/yaffle/test/test_helper.rb
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] = 'test'
|
4
|
+
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
|
8
|
+
|
9
|
+
def load_schema
|
10
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
11
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
12
|
+
|
13
|
+
db_adapter = ENV['DB']
|
14
|
+
|
15
|
+
# no db passed, try one of these fine config-free DBs before bombing.
|
16
|
+
db_adapter ||=
|
17
|
+
begin
|
18
|
+
require 'rubygems'
|
19
|
+
require 'sqlite'
|
20
|
+
'sqlite'
|
21
|
+
rescue MissingSourceFile
|
22
|
+
begin
|
23
|
+
require 'sqlite3'
|
24
|
+
'sqlite3'
|
25
|
+
rescue MissingSourceFile
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if db_adapter.nil?
|
30
|
+
raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.establish_connection(config[db_adapter])
|
34
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
35
|
+
require File.dirname(__FILE__) + '../../init'
|
36
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_comments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,50 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
name: bundler
|
16
|
-
requirement: &2161524820 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 1.0.0
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: *2161524820
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: jeweler
|
27
|
-
requirement: &2161524220 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.6.4
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2161524220
|
36
|
-
description: comments
|
12
|
+
date: 2011-08-22 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
37
15
|
email: felix1985@gmail.com
|
38
16
|
executables: []
|
39
17
|
extensions: []
|
40
18
|
extra_rdoc_files:
|
41
|
-
-
|
42
|
-
- README.rdoc
|
19
|
+
- README
|
43
20
|
files:
|
44
|
-
-
|
45
|
-
-
|
46
|
-
- Gemfile.lock
|
47
|
-
- LICENSE.txt
|
48
|
-
- README.rdoc
|
49
|
-
- Rakefile
|
21
|
+
- MIT-LICENSE
|
22
|
+
- README
|
50
23
|
- lib/has_comments.rb
|
51
|
-
-
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
-
|
24
|
+
- lib/generators/has_comments_generator.rb
|
25
|
+
- lib/generators/templates/comment.rb
|
26
|
+
- lib/generators/templates/comments_controller.rb
|
27
|
+
- lib/generators/templates/create_comments.rb
|
28
|
+
- lib/generators/USAGE
|
29
|
+
- Rakefile
|
30
|
+
- test/database.yml
|
31
|
+
- test/has_comments_test.rb
|
32
|
+
- test/schema.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
- uninstall.rb
|
35
|
+
- init.rb
|
36
|
+
- install.rb
|
37
|
+
homepage: http://github.com/has_comments
|
38
|
+
licenses: []
|
56
39
|
post_install_message:
|
57
40
|
rdoc_options: []
|
58
41
|
require_paths:
|
@@ -74,5 +57,5 @@ rubyforge_project:
|
|
74
57
|
rubygems_version: 1.8.8
|
75
58
|
signing_key:
|
76
59
|
specification_version: 3
|
77
|
-
summary:
|
60
|
+
summary: has_comments
|
78
61
|
test_files: []
|
data/.document
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= has_comments
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to has_comments
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* 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
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2011 John Felix. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
data/test/helper.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
|
12
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
require 'has_comments'
|
15
|
-
|
16
|
-
class Test::Unit::TestCase
|
17
|
-
end
|