Commit 38f171f7
Changed files (22)
app
admin
models
services
views
creations
sitemap
config
db
spec
controllers
models
routing
services
app/admin/comments.rb
@@ -1,3 +0,0 @@
-ActiveAdmin.register Comment, :as => "PostComment" do
-
-end
app/controllers/comments_controller.rb
@@ -1,12 +0,0 @@
-class CommentsController < ApplicationController
- before_filter :authenticate_user!
-
- def new
- @comment = Comment.new
- end
-
- def create
- comment = resolve(CommentOnCreationCommand).run(params)
- redirect_to comment.commentable, :notice => 'Nice Comment!'
- end
-end
app/controllers/creations_controller.rb
@@ -8,7 +8,6 @@ class CreationsController < ApplicationController
def show
@creation = Creation.find(params[:id])
@primary_photo = @creation.primary_image
- @comments = @creation.comment_threads.includes(:user)
end
def new
app/controllers/sitemap_controller.rb
@@ -10,12 +10,4 @@ class SitemapController < ApplicationController
format.xml
end
end
-
- def comments
- headers['Content-Type'] = 'application/xml'
- @comments = Comment.all
- respond_to do |format|
- format.xml
- end
- end
end
app/models/comment.rb
@@ -1,57 +0,0 @@
-class Comment < ActiveRecord::Base
- include PublicActivity::Model
- tracked owner: Proc.new{ |controller, model| controller.current_user }
-
- acts_as_nested_set :scope => [:commentable_id, :commentable_type]
-
- validates_presence_of :body
- validates_presence_of :user
-
- # NOTE: install the acts_as_votable plugin if you
- # want user to vote on the quality of comments.
- #acts_as_voteable
-
- belongs_to :commentable, :polymorphic => true
-
- # NOTE: Comments belong to a user
- belongs_to :user
-
- # Helper class method that allows you to build a comment
- # by passing a commentable object, a user_id, and comment text
- # example in readme
- def self.build_from(obj, user_id, comment)
- c = self.new
- c.commentable_id = obj.id
- c.commentable_type = obj.class.base_class.name
- c.body = comment
- c.user_id = user_id
- c
- end
-
- def self.create_for(user,creation,body)
- self.build_from(creation, user.id, body)
- end
-
- #helper method to check if a comment has children
- def has_children?
- self.children.size > 0
- end
-
- # Helper class method to lookup all comments assigned
- # to all commentable types for a given user.
- scope :find_comments_by_user, lambda { |user|
- where(:user_id => user.id).order('created_at DESC')
- }
-
- # Helper class method to look up all comments for
- # commentable class name and commentable id.
- scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
- where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC')
- }
-
- # Helper class method to look up a commentable object
- # given the commentable class name and id
- def self.find_commentable(commentable_str, commentable_id)
- commentable_str.constantize.find(commentable_id)
- end
-end
app/models/creation.rb
@@ -1,7 +1,6 @@
class Creation < ActiveRecord::Base
include PublicActivity::Model
tracked owner: Proc.new{ |controller, model| controller.current_user if controller }
- acts_as_commentable
validates :name, :presence => true
attr_accessible :user_id, :story, :name, :category_ids, :is_restricted, :watermark
belongs_to :user, :counter_cache => true
@@ -17,10 +16,6 @@ class Creation < ActiveRecord::Base
"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
end
- def has_comments
- self.comment_threads.length > 0
- end
-
def primary_image
if photos.any?
photos.first
app/models/user.rb
@@ -34,10 +34,6 @@ class User < ActiveRecord::Base
creation.user == self
end
- def comment_on(creation, comment)
- Comment.create_for(self, creation, comment)
- end
-
def change_password(password, confirmation)
return false unless password == confirmation
self.password = password
app/services/commands/comment_on_creation_command.rb
@@ -1,10 +0,0 @@
-class CommentOnCreationCommand
- def initialize(user)
- @current_user = user
- end
- def run(message)
- comment = @current_user.comment_on(Creation.find(message[:creation_id]), message[:comment][:body])
- comment.save
- comment
- end
-end
app/services/dto/display_creation_dto.rb
@@ -1,5 +1,5 @@
class DisplayCreationDTO
- attr_accessor :id, :name, :story, :primary_image, :thumb_url, :user, :favorites, :comment_threads
+ attr_accessor :id, :name, :story, :primary_image, :thumb_url, :user, :favorites
def self.model_name
ActiveModel::Name.new(self, nil, 'Creation')
end
app/services/mappers/creation_to_display_creation_dto_mapper.rb
@@ -8,7 +8,6 @@ class CreationToDisplayCreationDTOMapper
dto.thumb_url = creation.primary_image.image.thumb.url
dto.user = creation.user
dto.favorites = creation.favorites
- dto.comment_threads = creation.comment_threads
dto
end
end
app/views/creations/show.html.erb
@@ -4,7 +4,6 @@
<script type="text/javascript">
$(function() {
Creations.Show.initialize();
- mixpanel.track_forms(".form-horizontal", "commented");
});
</script>
<% end -%>
app/views/sitemap/comments.xml.erb
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dsq="http://www.disqus.com/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.0/">
- <channel>
- <% @comments.each do |comment| %>
- <item>
- <!-- title of article -->
- <title><%= comment.commentable.name %></title>
- <!-- absolute URI to article -->
- <link>https://www.cakeside.com/creations/<%= comment.commentable.to_param %></link>
- <!-- body of the page or post; use cdata; html allowed (though will be formatted to DISQUS specs) -->
- <content:encoded><![CDATA[<%= comment.commentable.story %>]]></content:encoded>
- <!-- value used within disqus_identifier; usually internal identifier of article -->
- <dsq:thread_identifier>c-<%= comment.commentable.id %></dsq:thread_identifier>
- <!-- creation date of thread (article), in GMT. Must be YYYY-MM-DD HH:MM:SS 24-hour format. -->
- <wp:post_date_gmt><%= comment.commentable.created_at.strftime("%Y-%m-%d %H:%M:%S") %></wp:post_date_gmt>
- <!-- open/closed values are acceptable -->
- <wp:comment_status>open</wp:comment_status>
- <wp:comment>
- <!-- sso only; see docs -->
- <dsq:remote>
- <!-- unique internal identifier; username, user id, etc. -->
- <dsq:id><%= comment.user.id %></dsq:id>
- <!-- avatar -->
- <dsq:avatar><%= "https://secure.gravatar.com/avatar/#{Digest::MD5::hexdigest(comment.user.email.downcase)}?s=260&d=mm" %></dsq:avatar>
- </dsq:remote>
- <!-- internal id of comment -->
- <wp:comment_id><%= comment.id %></wp:comment_id>
- <!-- author display name -->
- <wp:comment_author><%= comment.user.name %></wp:comment_author>
- <!-- author email address -->
- <wp:comment_author_email><%= comment.user.email %></wp:comment_author_email>
- <!-- author url, optional -->
- <wp:comment_author_url>https://www.cakeside.com/profiles/<%= comment.user.to_param %></wp:comment_author_url>
- <!-- author ip address -->
- <wp:comment_author_IP><%= comment.user.last_sign_in_ip %></wp:comment_author_IP>
- <!-- comment datetime, in GMT. Must be YYYY-MM-DD HH:MM:SS 24-hour format. -->
- <wp:comment_date_gmt><%= comment.created_at.strftime("%Y-%m-%d %H:%M:%S") %></wp:comment_date_gmt>
- <!-- comment body; use cdata; html allowed (though will be formatted to DISQUS specs) -->
- <wp:comment_content><![CDATA[<%= comment.body %>]]></wp:comment_content>
- <!-- is this comment approved? 0/1 -->
- <wp:comment_approved>1</wp:comment_approved>
- <!-- parent id (match up with wp:comment_id) -->
- <wp:comment_parent>0</wp:comment_parent>
- </wp:comment>
- </item>
- <% end %>
- </channel>
-</rss>
config/routes.rb
@@ -14,7 +14,6 @@ Cake::Application.routes.draw do
resources :creations do
resources :photos, :only => [:index, :new, :create, :destroy]
resources :favorites, :only => [:index, :create]
- resources :comments, :only => [:index, :new, :create]
get 'page/:page', :action => :index, :on => :collection
get 'mine', :action => :mine, :on => :collection
end
@@ -44,7 +43,6 @@ Cake::Application.routes.draw do
# sitemap
match "/sitemap.xml", :to => "sitemap#index", :defaults => {:format => :xml}
- match "/comments.xml", :to => "sitemap#comments", :defaults => {:format => :xml}
resources :settings, :only => [:index, :update]
resources :passwords, :only => [:index, :update]
db/migrate/20130719222352_drop_comments.rb
@@ -0,0 +1,5 @@
+class DropComments < ActiveRecord::Migration
+ def change
+ drop_table :comments
+ end
+end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130706103848) do
+ActiveRecord::Schema.define(:version => 20130719222352) do
create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
@@ -79,25 +79,6 @@ ActiveRecord::Schema.define(:version => 20130706103848) do
t.string "slug"
end
- create_table "comments", :force => true do |t|
- t.integer "commentable_id", :default => 0
- t.string "commentable_type", :default => ""
- t.string "title", :default => ""
- t.text "body", :default => ""
- t.string "subject", :default => ""
- t.integer "user_id", :default => 0, :null => false
- t.integer "parent_id"
- t.integer "lft"
- t.integer "rgt"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
- add_index "comments", ["commentable_id", "commentable_type"], :name => "index_comments_on_commentable_id_and_commentable_type"
- add_index "comments", ["commentable_id"], :name => "index_comments_on_commentable_id"
- add_index "comments", ["parent_id"], :name => "index_comments_on_parent_id"
- add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
-
create_table "creations", :force => true do |t|
t.string "name"
t.text "story"
spec/controllers/comments_controller_spec.rb
@@ -1,50 +0,0 @@
-require 'spec_helper'
-
-describe CommentsController do
- describe "when signed in" do
- let(:user) { FactoryGirl.create(:user) }
-
- context "when logged in" do
- before(:each) do
- http_login(user)
- end
-
- describe "POST create" do
- let(:creation) { FactoryGirl.create(:creation) }
-
- before(:each) do
- post :create, { :creation_id => creation.id, :comment => { :body => 'blah' } }
- end
-
- it "should display a message indicated that the comment was saved" do
- flash[:notice].should_not be_nil
- end
-
- it "should redirect to the creation#show page" do
- response.should redirect_to(creation)
- end
-
- it "should create a new comment" do
- creation.comment_threads.count.should == 1
- end
-
- it "should include the person who made the comment" do
- creation.comment_threads.first.user.should == user
- end
- end
- end
- end
-
- context "when not logged in" do
- let(:creation) { FactoryGirl.create(:creation) }
-
- before :each do
- post :create, { :creation_id => creation.id, :comment => { :body => 'hi' } }
- end
-
- #need to figure out how to get the devise helpers working
- it "should not let you comment" do
- response.should_not redirect_to(creation)
- end
- end
-end
spec/models/comment_spec.rb
@@ -1,18 +0,0 @@
-require_relative '../../app/models/comment.rb'
-
-describe Comment do
- describe "when creating a new comment" do
- it "should return a comment with the correct body" do
- @result.body.should == "blah"
- end
- it "should track the user id" do
- @result.user_id.should == user.id
- end
- before(:each) do
- @result = Comment.create_for(user, creation, 'blah')
- end
-
- let(:user) { fake }
- let(:creation) { Creation.new }
- end
-end
spec/models/user_spec.rb
@@ -47,20 +47,6 @@ describe User do
end
end
- describe "when commenting on a creation" do
- let(:comment) { fake }
- let(:creation) { fake }
- let(:sut) { User.new }
-
- it "should create a new comment" do
- @result.should == comment
- end
- before(:each) do
- Comment.stub(:create_for).with(sut, creation, "cool cake").and_return(comment)
- @result = sut.comment_on(creation, "cool cake")
- end
- end
-
describe "when checking if a user already likes a creation" do
let(:sut) { FactoryGirl.create(:user) }
let(:cake) { FactoryGirl.create(:creation) }
spec/routing/comments_routing_spec.rb
@@ -1,15 +0,0 @@
-require "spec_helper"
-
-describe CommentsController do
- describe "routing" do
- it "routes to index" do
- get('/creations/1/comments').should route_to('comments#index', :creation_id => "1")
- end
- it "routes to new" do
- get('/creations/1/comments/new').should route_to("comments#new", :creation_id => "1")
- end
- it "routes to create" do
- post('/creations/1/comments').should route_to("comments#create", :creation_id => "1")
- end
- end
-end
spec/services/command_on_creation_command_spec.rb
@@ -1,20 +0,0 @@
-describe CommentOnCreationCommand do
- let(:sut) { CommentOnCreationCommand.new(user) }
- let(:user) { fake }
- describe "when run" do
- let(:creation) { fake }
- let(:comment) { fake }
- it "should add the new comment to the creation" do
- user.should have_received(:comment_on, creation, "wow")
- end
- it "should save the comment" do
- comment.should have_received(:save)
- end
- before(:each) do
- params = {:creation_id => 8, :comment => { :body => "wow" }}
- Creation.stub(:find).with(8).and_return(creation)
- user.stub(:comment_on).with(creation, "wow").and_return(comment)
- sut.run(params)
- end
- end
-end
Gemfile
@@ -12,7 +12,6 @@ gem "formtastic"
gem 'activeadmin'
gem 'sass-rails'
gem 'bootstrap-sass'
-gem 'acts_as_commentable_with_threading'
gem 'acts-as-taggable-on'
gem 'delayed_job_active_record'
gem 'daemons'
Gemfile.lock
@@ -42,10 +42,6 @@ GEM
multi_json (~> 1.0)
acts-as-taggable-on (2.3.3)
rails (~> 3.0)
- acts_as_commentable_with_threading (1.1.2)
- activerecord (>= 3.0)
- activesupport (~> 3.0)
- awesome_nested_set (>= 2.0)
airbrake (3.1.12)
activesupport
builder
@@ -56,8 +52,6 @@ GEM
asset_sync (0.5.4)
activemodel
fog
- awesome_nested_set (2.1.6)
- activerecord (>= 3.0.0)
bcrypt-ruby (3.0.1)
better_errors (0.8.0)
coderay (>= 1.0.0)
@@ -306,7 +300,6 @@ PLATFORMS
DEPENDENCIES
activeadmin
acts-as-taggable-on
- acts_as_commentable_with_threading
airbrake
asset_sync
better_errors