rails_commentable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/lib/commentable.rb +7 -0
  2. data/lib/commentable/controller.rb +82 -0
  3. data/lib/commentable/model.rb +54 -0
  4. data/lib/commentable/routes.rb +11 -0
  5. data/lib/rails_commentable.rb +1 -0
  6. data/test/comment_test.rb +43 -0
  7. data/test/comments_controller_test.rb +101 -0
  8. data/test/rails_app/app/controllers/application_controller.rb +3 -0
  9. data/test/rails_app/app/controllers/comments_controller.rb +3 -0
  10. data/test/rails_app/app/controllers/pages_controller.rb +13 -0
  11. data/test/rails_app/app/controllers/posts_controller.rb +13 -0
  12. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  13. data/test/rails_app/app/models/comment.rb +3 -0
  14. data/test/rails_app/app/models/page.rb +3 -0
  15. data/test/rails_app/app/models/post.rb +3 -0
  16. data/test/rails_app/config/application.rb +42 -0
  17. data/test/rails_app/config/boot.rb +6 -0
  18. data/test/rails_app/config/environment.rb +5 -0
  19. data/test/rails_app/config/environments/development.rb +26 -0
  20. data/test/rails_app/config/environments/production.rb +49 -0
  21. data/test/rails_app/config/environments/test.rb +35 -0
  22. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  23. data/test/rails_app/config/initializers/session_store.rb +8 -0
  24. data/test/rails_app/config/routes.rb +11 -0
  25. data/test/rails_app/db/migrate/20110417162758_create_comments.rb +24 -0
  26. data/test/rails_app/db/migrate/20110517071950_create_pages.rb +13 -0
  27. data/test/rails_app/db/migrate/20110517071954_create_posts.rb +13 -0
  28. data/test/rails_app/db/schema.rb +46 -0
  29. data/test/rails_app/db/seeds.rb +7 -0
  30. data/test/test_helper.rb +15 -0
  31. metadata +135 -0
@@ -0,0 +1,7 @@
1
+ require 'commentable/routes.rb'
2
+
3
+ module Commentable
4
+ autoload :Controller, File.expand_path('../commentable/controller.rb', __FILE__)
5
+ autoload :Model, File.expand_path('../commentable/model.rb', __FILE__)
6
+ end
7
+
@@ -0,0 +1,82 @@
1
+ module Commentable
2
+ class Controller < ApplicationController
3
+ before_filter :load_commentable
4
+
5
+ def index
6
+ @comments = @commentable.comments.all
7
+ respond_with(@commentable, @comments)
8
+ end
9
+
10
+ def show
11
+ @comment = @commentable.comments.find(params[:id])
12
+ respond_with(@commentable, @comment)
13
+ end
14
+
15
+ def new
16
+ @comment = build_comment
17
+ respond_with(@commentable, @comment)
18
+ end
19
+
20
+ def edit
21
+ @comment = @commentable.comments.find(params[:id])
22
+ end
23
+
24
+ def create
25
+ @comment = build_comment(params[:comment])
26
+ @comment.save
27
+
28
+ respond_with(@commentable, @comment) do |format|
29
+ format.html do
30
+ if @comment.persisted?
31
+ redirect_to comment_url
32
+ else
33
+ render 'new'
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def update
40
+ @comment = @commentable.comments.find(params[:id])
41
+ @comment.update_attributes(params[:comment])
42
+ respond_with(@commentable, @comment, :location => comment_url)
43
+ end
44
+
45
+ def spam
46
+ @comment = @commentable.comments.find(params[:id])
47
+ @comment.toggle!(:spam)
48
+ respond_with(@commentable, @comment, :location => comment_url)
49
+ end
50
+
51
+ def troll
52
+ @comment = @commentable.comments.find(params[:id])
53
+ @comment.toggle!(:troll)
54
+ respond_with(@commentable, @comment, :location => comment_url)
55
+ end
56
+
57
+ def destroy
58
+ @comment = @commentable.comments.find(params[:id])
59
+ @comment.destroy
60
+ respond_with(@commentable, @comment, :location => commentable_url)
61
+ end
62
+
63
+ def comment_url
64
+ polymorphic_url(@commentable, :anchor => "C#{@comment.to_param}")
65
+ end
66
+
67
+ def commentable_url
68
+ @commentable
69
+ end
70
+
71
+ def build_comment(params = nil)
72
+ comment = @commentable.comments.build(params)
73
+ comment.user_ip = request.remote_ip if comment.respond_to?(:user_ip)
74
+ comment
75
+ end
76
+
77
+ def load_commentable
78
+ id = params["#{params[:commentable]}_id"]
79
+ @commentable = params[:commentable].camelize.constantize.find(id)
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,54 @@
1
+ module Commentable
2
+ # Comment model.
3
+ #
4
+ # Example:
5
+ #
6
+ # class Comment < ActiveRecord::Base
7
+ # include Commentable::Model
8
+ #
9
+ # self.spam_quota = 5
10
+ # self.troll_quota = 10
11
+ # self.quota_time = 1.week
12
+ # end
13
+ #
14
+ # Class attributes:
15
+ #
16
+ # - spam_quota - how many spams are allowed for a single IP (defaults to 4)
17
+ # - troll_quota - how many trolls are allowed for a single IP (defaults to 4)
18
+ # - time_quota - since how long should we check for spams and trolls (defauls to 1 day)
19
+ module Model
20
+ extend ActiveSupport::Concern
21
+
22
+ included do
23
+ belongs_to :commentable, :polymorphic => true, :counter_cache => true
24
+
25
+ validates_presence_of :commentable
26
+ validates_presence_of :body
27
+
28
+ validate :spam_quota, :troll_quota
29
+ end
30
+
31
+ # Adds an error on base if current ip generated too much spams.
32
+ def spam_quota
33
+ errors[:base] << "spam_quota" if self.class.count_for_user_ip(user_ip, :spam) >= self.class.spam_quota
34
+ end
35
+
36
+ # Adds an error on base if current ip generated too much trolls.
37
+ def troll_quota
38
+ errors[:base] << "troll_quota" if self.class.count_for_user_ip(user_ip, :troll) >= self.class.troll_quota
39
+ end
40
+
41
+ module ClassMethods
42
+ mattr_accessor :spam_quota, :troll_quota, :quota_time
43
+
44
+ self.spam_quota = 4
45
+ self.troll_quota = 4
46
+ self.quota_time = 1.day
47
+
48
+ def count_for_user_ip(user_ip, field)
49
+ where("user_ip = ? AND #{field} = ? AND created_at >= ?",
50
+ user_ip, true, Time.now - quota_time).count
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module ActionDispatch # :nodoc:
2
+ module Routing # :nodoc:
3
+ class Mapper
4
+ def commentable(options = {})
5
+ resources :comments, options do
6
+ put :spam, :troll, :on => :member
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('../commentable', __FILE__)
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class CommentTest < ActiveSupport::TestCase
4
+ setup do
5
+ @attributes = {
6
+ :commentable => posts(:one),
7
+ :body => "lorem ipsum",
8
+ :user_ip => "127.0.0.1"
9
+ }
10
+ end
11
+
12
+ test "should validate body" do
13
+ assert Comment.create.errors[:body].any?
14
+ end
15
+
16
+ test "should validate commentable" do
17
+ assert Comment.create.errors[:commentable].any?
18
+ end
19
+
20
+ test "should be valid" do
21
+ assert Comment.new(:commentable => posts(:one), :body => "lorem ipsum").valid?
22
+ end
23
+
24
+ test "spam quota" do
25
+ (1..4).each { Comment.create!(@attributes.merge(:spam => true)) }
26
+ assert !Comment.new(@attributes).valid?
27
+ end
28
+
29
+ test "spam quota time lapse" do
30
+ (1..4).each { Comment.create!(@attributes.merge(:spam => true, :created_at => 2.days.ago)) }
31
+ assert Comment.new(@attributes).valid?
32
+ end
33
+
34
+ test "troll quota" do
35
+ (1..4).each { Comment.create!(@attributes.merge(:troll => true)) }
36
+ assert !Comment.new(@attributes).valid?
37
+ end
38
+
39
+ test "troll quota time lapse" do
40
+ (1..4).each { Comment.create!(@attributes.merge(:troll => true, :created_at => 2.days.ago)) }
41
+ assert Comment.new(@attributes).valid?
42
+ end
43
+ end
@@ -0,0 +1,101 @@
1
+ require 'test_helper'
2
+
3
+ class CommentsControllerTest < ActionController::TestCase
4
+ setup do
5
+ @post = posts(:one)
6
+ end
7
+
8
+ test "should get index (xml)" do
9
+ get :index, :post_id => @post.to_param, :commentable => 'post', :format => "xml"
10
+ assert_response :ok
11
+ assert_select "comment", @post.comments.count
12
+ end
13
+
14
+ test "should get show (xml)" do
15
+ get :show, :post_id => @post.to_param, :commentable => 'post',
16
+ :id => comments(:post_one_1).to_param, :format => "xml"
17
+ assert_response :ok
18
+ assert_select "comment", 1
19
+ end
20
+
21
+ test "should get new" do
22
+ get :new, :post_id => @post.to_param, :commentable => 'post'
23
+ assert_response :ok
24
+ end
25
+
26
+ test "should get edit" do
27
+ get :edit, :post_id => @post.to_param, :commentable => 'post',
28
+ :id => comments(:post_one_1).to_param
29
+ assert_response :ok
30
+ end
31
+
32
+ test "should create" do
33
+ assert_difference('Comment.count') do
34
+ post :create, :post_id => @post.to_param, :commentable => 'post',
35
+ :comment => { :body => "lorem ipsum dolor sit amet" }
36
+ assert_redirected_to post_url(@post, :anchor => "C#{assigns(:comment).to_param}")
37
+ end
38
+
39
+ assert_not_nil assigns(:comment).user_ip
40
+ end
41
+
42
+ test "should not create" do
43
+ assert_no_difference('Comment.count') do
44
+ post :create, :post_id => @post.to_param, :commentable => 'post',
45
+ :comment => { :body => " " }
46
+ assert_response :ok
47
+ assert_template "comments/new"
48
+ end
49
+ end
50
+
51
+ test "should update" do
52
+ put :update, :post_id => @post.to_param, :commentable => 'post',
53
+ :id => comments(:post_one_1).to_param, :comment => { :body => "lorem ipsum dolor sit amet" }
54
+ assert_redirected_to post_url(@post, :anchor => "C#{assigns(:comment).to_param}")
55
+ assert_equal "lorem ipsum dolor sit amet", comments(:post_one_1).reload.body
56
+ end
57
+
58
+ test "should not update" do
59
+ put :update, :post_id => @post.to_param, :commentable => 'post',
60
+ :id => comments(:post_one_1).to_param, :comment => { :body => " " }
61
+ assert_response :ok
62
+ assert_template "comments/edit"
63
+ assert_not_equal " ", comments(:post_one_1).reload.body
64
+ end
65
+
66
+ test "should spam" do
67
+ assert_difference('Comment.where(:spam => true).count') do
68
+ put :spam, :post_id => @post.to_param, :commentable => 'post', :id => comments(:post_one_1)
69
+ assert_redirected_to post_url(@post, :anchor => "C#{comments(:post_one_1).to_param}")
70
+ end
71
+ end
72
+
73
+ test "should troll" do
74
+ assert_difference('Comment.where(:troll => true).count') do
75
+ put :troll, :post_id => @post.to_param, :commentable => 'post', :id => comments(:post_one_1)
76
+ assert_redirected_to post_url(@post, :anchor => "C#{comments(:post_one_1).to_param}")
77
+ end
78
+ end
79
+
80
+ test "should unspam" do
81
+ assert_difference('Comment.where(:spam => true).count', -1) do
82
+ put :spam, :post_id => @post.to_param, :commentable => 'post', :id => comments(:post_one_spam)
83
+ assert_redirected_to post_url(@post, :anchor => "C#{comments(:post_one_spam).to_param}")
84
+ end
85
+ end
86
+
87
+ test "should untroll" do
88
+ assert_difference('Comment.where(:troll => true).count', -1) do
89
+ put :troll, :post_id => @post.to_param, :commentable => 'post', :id => comments(:post_one_troll)
90
+ assert_redirected_to post_url(@post, :anchor => "C#{comments(:post_one_troll).to_param}")
91
+ end
92
+ end
93
+
94
+ test "should destroy" do
95
+ assert_difference('Comment.count', -1) do
96
+ delete :destroy, :post_id => @post.to_param, :commentable => 'post',
97
+ :id => comments(:post_one_1).to_param
98
+ assert_redirected_to @post
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,3 @@
1
+ class CommentsController < Commentable::Controller
2
+ respond_to :html, :xml
3
+ end
@@ -0,0 +1,13 @@
1
+ class PagesController < ApplicationController
2
+ respond_to :html
3
+
4
+ def index
5
+ @pages = Page.all
6
+ respond_with(@pages)
7
+ end
8
+
9
+ def show
10
+ @page = Page.find(params[:id])
11
+ respond_with(@page)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class PostsController < ApplicationController
2
+ respond_to :html
3
+
4
+ def index
5
+ @posts = Post.all
6
+ respond_with(@posts)
7
+ end
8
+
9
+ def show
10
+ @post = Post.find(params[:id])
11
+ respond_with(@post)
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ include Commentable::Model
3
+ end
@@ -0,0 +1,3 @@
1
+ class Page < ActiveRecord::Base
2
+ has_many :comments, :as => :commentable, :order => :created_at
3
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :comments, :as => :commentable, :order => :created_at
3
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+ module RailsApp
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+
18
+ # Only load the plugins named here, in the order given (default is alphabetical).
19
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
+
22
+ # Activate observers that should always be running.
23
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
+
25
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
+ # config.time_zone = 'Central Time (US & Canada)'
28
+
29
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
+ # config.i18n.default_locale = :de
32
+
33
+ # JavaScript files you want as :defaults (application.js is always included).
34
+ config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
35
+
36
+ # Configure the default encoding used in templates for Ruby 1.9.
37
+ config.encoding = "utf-8"
38
+
39
+ # Configure sensitive parameters which will be filtered from the log file.
40
+ config.filter_parameters += [:password]
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1,26 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end
@@ -0,0 +1,35 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ RailsApp::Application.config.secret_token = 'd02d44431970edceef6bc7746a41b876e1e828e48c0fa76fb94f2e8d068bdc6ae4f0ee129adeb69e8649b4840ba8e7d83894f9be0567eb0151da9b2478dc393d'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ RailsApp::Application.config.session_store :cookie_store, :key => '_rails_app_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # RailsApp::Application.config.session_store :active_record_store
@@ -0,0 +1,11 @@
1
+ RailsApp::Application.routes.draw do
2
+ resources :posts, :only => [:show, :index] do
3
+ commentable
4
+ end
5
+
6
+ resources :pages, :only => [:show, :index] do
7
+ commentable
8
+ end
9
+
10
+ root :to => "home#index"
11
+ end
@@ -0,0 +1,24 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :comments do |t|
4
+ t.references :commentable, :polymorphic => true
5
+ t.text :body
6
+ # t.references :user
7
+ t.string :user_name
8
+ t.string :user_email
9
+ t.string :user_url
10
+ t.string :user_ip
11
+ t.boolean :spam
12
+ t.boolean :troll
13
+ t.timestamps
14
+ end
15
+
16
+ add_index :comments, [:commentable_type, :commentable_id]
17
+ add_index :comments, :user_ip
18
+ # add_index :comments, :user_id
19
+ end
20
+
21
+ def self.down
22
+ drop_table :comments
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePages < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :pages do |t|
4
+ t.string :title
5
+ t.integer :comments_count
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :pages
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.integer :comments_count
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :posts
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20110517071954) do
14
+
15
+ create_table "comments", :force => true do |t|
16
+ t.integer "commentable_id"
17
+ t.string "commentable_type"
18
+ t.text "body"
19
+ t.string "user_name"
20
+ t.string "user_email"
21
+ t.string "user_url"
22
+ t.string "user_ip"
23
+ t.boolean "spam"
24
+ t.boolean "troll"
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ end
28
+
29
+ add_index "comments", ["commentable_type", "commentable_id"], :name => "index_comments_on_commentable_type_and_commentable_id"
30
+ add_index "comments", ["user_ip"], :name => "index_comments_on_user_ip"
31
+
32
+ create_table "pages", :force => true do |t|
33
+ t.string "title"
34
+ t.integer "comments_count"
35
+ t.datetime "created_at"
36
+ t.datetime "updated_at"
37
+ end
38
+
39
+ create_table "posts", :force => true do |t|
40
+ t.string "title"
41
+ t.integer "comments_count"
42
+ t.datetime "created_at"
43
+ t.datetime "updated_at"
44
+ end
45
+
46
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Mayor.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require File.expand_path('../rails_app/config/environment', __FILE__)
4
+ require 'rails/test_help'
5
+ require 'capybara/rails'
6
+
7
+ class ActiveSupport::TestCase
8
+ self.fixture_path = File.expand_path('../fixtures', __FILE__)
9
+ fixtures :all
10
+ end
11
+
12
+ class ActionDispatch::IntegrationTest
13
+ self.fixture_path = File.expand_path('../fixtures', __FILE__)
14
+ include Capybara
15
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_commentable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Julien Portalier
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-17 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 9
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 7
34
+ version: 3.0.7
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: User comments engine for Ruby on Rails.
38
+ email: ysbaddaden@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - lib/commentable.rb
47
+ - lib/commentable/controller.rb
48
+ - lib/commentable/model.rb
49
+ - lib/commentable/routes.rb
50
+ - lib/rails_commentable.rb
51
+ - test/comment_test.rb
52
+ - test/comments_controller_test.rb
53
+ - test/rails_app/app/controllers/application_controller.rb
54
+ - test/rails_app/app/controllers/comments_controller.rb
55
+ - test/rails_app/app/controllers/pages_controller.rb
56
+ - test/rails_app/app/controllers/posts_controller.rb
57
+ - test/rails_app/app/helpers/application_helper.rb
58
+ - test/rails_app/app/models/comment.rb
59
+ - test/rails_app/app/models/page.rb
60
+ - test/rails_app/app/models/post.rb
61
+ - test/rails_app/config/application.rb
62
+ - test/rails_app/config/boot.rb
63
+ - test/rails_app/config/environment.rb
64
+ - test/rails_app/config/environments/development.rb
65
+ - test/rails_app/config/environments/production.rb
66
+ - test/rails_app/config/environments/test.rb
67
+ - test/rails_app/config/initializers/secret_token.rb
68
+ - test/rails_app/config/initializers/session_store.rb
69
+ - test/rails_app/config/routes.rb
70
+ - test/rails_app/db/migrate/20110417162758_create_comments.rb
71
+ - test/rails_app/db/migrate/20110517071950_create_pages.rb
72
+ - test/rails_app/db/migrate/20110517071954_create_posts.rb
73
+ - test/rails_app/db/schema.rb
74
+ - test/rails_app/db/seeds.rb
75
+ - test/test_helper.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/ysbaddaden/commentable
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.6.2
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: User comments engine for Ruby on Rails.
110
+ test_files:
111
+ - test/comment_test.rb
112
+ - test/comments_controller_test.rb
113
+ - test/rails_app/app/controllers/application_controller.rb
114
+ - test/rails_app/app/controllers/comments_controller.rb
115
+ - test/rails_app/app/controllers/pages_controller.rb
116
+ - test/rails_app/app/controllers/posts_controller.rb
117
+ - test/rails_app/app/helpers/application_helper.rb
118
+ - test/rails_app/app/models/comment.rb
119
+ - test/rails_app/app/models/page.rb
120
+ - test/rails_app/app/models/post.rb
121
+ - test/rails_app/config/application.rb
122
+ - test/rails_app/config/boot.rb
123
+ - test/rails_app/config/environment.rb
124
+ - test/rails_app/config/environments/development.rb
125
+ - test/rails_app/config/environments/production.rb
126
+ - test/rails_app/config/environments/test.rb
127
+ - test/rails_app/config/initializers/secret_token.rb
128
+ - test/rails_app/config/initializers/session_store.rb
129
+ - test/rails_app/config/routes.rb
130
+ - test/rails_app/db/migrate/20110417162758_create_comments.rb
131
+ - test/rails_app/db/migrate/20110517071950_create_pages.rb
132
+ - test/rails_app/db/migrate/20110517071954_create_posts.rb
133
+ - test/rails_app/db/schema.rb
134
+ - test/rails_app/db/seeds.rb
135
+ - test/test_helper.rb