forked from elight/acts_as_commentable_with_threading
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
further conversion to arel. more specs. generators not updated yet.
we have it anyway. we might as well use it. update generators for rails 3
- Loading branch information
mpd
committed
Sep 25, 2010
1 parent
486c92d
commit f70a263
Showing
11 changed files
with
148 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
.bundle/ | ||
spec/debug.log | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Description: | ||
run ./script/generate acts_as_commentable_upgrade_migration | ||
run rails generate acts_as_commentable_upgrade_migration | ||
|
||
no need to specify any parameters after acts_as_commentable_upgrade_migration as the generator just creates a migration to update your existing comments table | ||
the acts_as_commentable_upgrade_migration file will be created in db/migrate |
21 changes: 14 additions & 7 deletions
21
.../acts_as_commentable_upgrade_migration/acts_as_commentable_upgrade_migration_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
class ActsAsCommentableUpgradeMigrationGenerator < Rails::Generator::Base | ||
def manifest | ||
record do |m| | ||
m.migration_template 'migration.rb', 'db/migrate' | ||
class ActsAsCommentableUpgradeMigrationGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
# *for the life of me*, i can't figure out why this isn't implemented elsewhere. | ||
def self.next_migration_number(dirname) | ||
if ActiveRecord::Base.timestamped_migrations | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
else | ||
"%.3d" % (current_migration_number(dirname) + 1) | ||
end | ||
end | ||
def file_name | ||
"acts_as_commentable_upgrade_migration" | ||
|
||
def manifest | ||
migration_template 'migration.rb', 'db/migrate/acts_as_commentable_upgrade_migration' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Description: | ||
run ./script/generate acts_as_commentable_with_threading_migration | ||
run rails generate acts_as_commentable_with_threading_migration | ||
|
||
no need to specify any parameters after acts_as_commentable_with_threading_migration as the plugin relies on the table being named "comments" | ||
the acts_as_commentable_with_threading_migration file will be created in db/migrate |
21 changes: 14 additions & 7 deletions
21
...ntable_with_threading_migration/acts_as_commentable_with_threading_migration_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
class ActsAsCommentableWithThreadingMigrationGenerator < Rails::Generator::Base | ||
def manifest | ||
record do |m| | ||
m.migration_template 'migration.rb', 'db/migrate' | ||
class ActsAsCommentableWithThreadingMigrationGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
# Complete wtf that this isn't provided elsewhere. | ||
def self.next_migration_number(dirname) | ||
if ActiveRecord::Base.timestamped_migrations | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
else | ||
"%.3d" % (current_migration_number(dirname) + 1) | ||
end | ||
end | ||
def file_name | ||
"acts_as_commentable_with_threading_migration" | ||
|
||
def manifest | ||
migration_template 'migration.rb', 'db/migrate/acts_as_commentable_with_threading_migration' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
require File.join(File.dirname(__FILE__), "spec_helper") | ||
require File.expand_path('./spec_helper', File.dirname(__FILE__)) | ||
|
||
describe "A class that is commentable" do | ||
it "can have many root comments" do | ||
Commentable.new.comment_threads.should be_a_kind_of(Enumerable) | ||
end | ||
end | ||
|
||
describe "special class finders" do | ||
before :each do | ||
@user = User.create! | ||
@commentable = Commentable.create! | ||
@other_commentable = Commentable.create! | ||
end | ||
|
||
describe "#find_comments_for" do | ||
before :each do | ||
@comment = Comment.create!(:user => @user, :commentable_type => @commentable.class, :commentable_id => @commentable.id, :body => 'blargh') | ||
|
||
@other_comment = Comment.create!(:user => @user, :commentable_type => @other_commentable.class, :commentable_id => @other_commentable.id, :body => 'hello') | ||
|
||
@comments = Commentable.find_comments_for(@commentable) | ||
end | ||
|
||
it "should return the comments for the passed commentable" do | ||
@comments.should include(@comment) | ||
end | ||
|
||
it "should not return the comments for other commentables" do | ||
@comments.should_not include(@other_comment) | ||
end | ||
end | ||
|
||
describe "#find_comments_by_user" do | ||
before :each do | ||
@user2 = User.create! | ||
|
||
@comment = Comment.create!(:user => @user, :commentable_type => @commentable.class, :commentable_id => @commentable.id, :body => 'blargh') | ||
|
||
@other_comment = Comment.create!(:user => @user2, :commentable_type => @other_commentable.class, :commentable_id => @other_commentable.id, :body => 'hello') | ||
|
||
@comments = Commentable.find_comments_by_user(@user) | ||
end | ||
|
||
it "should return comments by the passed user" do | ||
@comments.all? { |c| c.user == @user }.should be_true | ||
end | ||
|
||
|
||
it "should not return comments by other users" do | ||
@comments.any? { |c| c.user != @user }.should be_false | ||
end | ||
end | ||
end | ||
|
||
describe "instance methods" do | ||
describe "#comments_ordered_by_submitted" do | ||
before :each do | ||
@user = User.create! | ||
@commentable = Commentable.create! | ||
@other_commentable = Commentable.create! | ||
@comment = Comment.create!(:user => @user, :commentable_type => @commentable.class, :commentable_id => @commentable.id, :body => 'sup') | ||
@older_comment = Comment.create!(:user => @user, :commentable_type => @commentable.class, :commentable_id => @commentable.id, :body => 'sup', :created_at => 1.week.ago) | ||
@oldest_comment = Comment.create!(:user => @user, :commentable_type => @commentable.class, :commentable_id => @commentable.id, :body => 'sup', :created_at => 2.years.ago) | ||
@other_comment = Comment.create!(:user => @user, :commentable_type => @other_commentable.class, :commentable_id => @other_commentable.id, :body => 'sup') | ||
@comments = @commentable.comments_ordered_by_submitted | ||
end | ||
|
||
it "should return its own comments, ordered with the newest first" do | ||
@comments.all? { |c| c.commentable_type == @commentable.class.to_s and c.commentable_id == @commentable.id }.should be_true | ||
@comments.each_cons(2) { |c, c2| c.created_at.should > c2.created_at } | ||
end | ||
|
||
it "should not include comments for other commentables" do | ||
@comments.any? { |c| c.commentable_type != @commentable.class.to_s or c.commentable_id != @commentable.id }.should be_false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters