From dceee11f9b6b2a1d8ce151a94743f765d4f72b5a Mon Sep 17 00:00:00 2001 From: mo Date: Sun, 3 Sep 2017 15:16:43 -0600 Subject: remove disqus --- app/assets/javascripts/cakeside.js.coffee | 5 -- app/assets/javascripts/views/disqus_view.js.coffee | 32 ---------- .../views/my/profiles/show_view.js.coffee | 5 -- app/controllers/comments_controller.rb | 17 ------ app/helpers/application_helper.rb | 9 --- app/views/cakes/show.html.erb | 2 - app/views/my/kitchens/show.html.erb | 12 +--- app/views/shared/_disqus.html.erb | 21 ------- config/routes.rb | 2 - spec/controllers/cakes_controller_spec.rb | 69 ---------------------- spec/controllers/comments_controller_spec.rb | 20 ------- spec/helpers/application_helper_spec.rb | 18 ------ spec/routing/comments_routing_spec.rb | 7 --- 13 files changed, 1 insertion(+), 218 deletions(-) delete mode 100644 app/assets/javascripts/views/disqus_view.js.coffee delete mode 100644 app/controllers/comments_controller.rb delete mode 100644 app/views/shared/_disqus.html.erb delete mode 100644 spec/controllers/cakes_controller_spec.rb delete mode 100644 spec/controllers/comments_controller_spec.rb delete mode 100644 spec/routing/comments_routing_spec.rb diff --git a/app/assets/javascripts/cakeside.js.coffee b/app/assets/javascripts/cakeside.js.coffee index 1b8dae24..bd4afe78 100644 --- a/app/assets/javascripts/cakeside.js.coffee +++ b/app/assets/javascripts/cakeside.js.coffee @@ -21,7 +21,6 @@ window.CakeSide = CakeSide.Application = new Marionette.Application() CakeSide.Application.addRegions content_region: '#backbone-content' - comment_region: '#disqus_thread' CakeSide.Application.addInitializer (options) -> new CakeSide.Routers.CakesRouter @@ -41,10 +40,6 @@ window.CakeSide = @categories = new CakeSide.Collections.CategoriesCollection() @tutorials = new CakeSide.Collections.TutorialsCollection() - #@disqus_view = new CakeSide.Views.DisqusView - #disqus_shortname: data.disqus_shortname - #CakeSide.Application.reqres.setHandler 'CommentView', => - #@disqus_view CakeSide.Application.reqres.setHandler 'CakesRepository', => @cakes CakeSide.Application.reqres.setHandler 'CategoriesRepository', => diff --git a/app/assets/javascripts/views/disqus_view.js.coffee b/app/assets/javascripts/views/disqus_view.js.coffee deleted file mode 100644 index 1379691a..00000000 --- a/app/assets/javascripts/views/disqus_view.js.coffee +++ /dev/null @@ -1,32 +0,0 @@ -class CakeSide.Views.DisqusView extends Backbone.View - el: "#disqus_thread" - initialize: (options) -> - disqus = document.createElement('script') - disqus.type = 'text/javascript' - disqus.async = true - disqus.src = "//#{options.disqus_shortname}.disqus.com/embed.js" - (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(disqus) - - render: (options) -> - try - @$el.removeClass('hidden') - that = @ - DISQUS.reset - reload: true, - config: -> - @page.identifier = options.identifier - @page.title = "CakeSide - #{options.title}" - @page.url = options.url - @callbacks.onNewComment = [that.saveComment] - @ - catch error - console.log(error) - finally - @ - - hide: -> - @$el.addClass('hidden') - - saveComment: (comment) -> - $.post Routes.comments_path(), { id: comment.id, url: document.URL, comment: comment }, (result) -> - console.log(result) diff --git a/app/assets/javascripts/views/my/profiles/show_view.js.coffee b/app/assets/javascripts/views/my/profiles/show_view.js.coffee index 91076e5e..a7010dc8 100644 --- a/app/assets/javascripts/views/my/profiles/show_view.js.coffee +++ b/app/assets/javascripts/views/my/profiles/show_view.js.coffee @@ -13,7 +13,6 @@ class CakeSide.Views.My.Profiles.ShowView extends Marionette.ItemView modelEvents: 'invalid': 'displayError' - 'sync': 'syncedUp' events: "submit #profile-form": "save" @@ -29,10 +28,6 @@ class CakeSide.Views.My.Profiles.ShowView extends Marionette.ItemView error: @couldNotSave ) - syncedUp: (event) -> - console.log(arguments) - console.log('syncd') - savedSuccessfully: (profile) => @disableSaveButton() @ui.status.removeClass('hide') diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb deleted file mode 100644 index 36c30126..00000000 --- a/app/controllers/comments_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CommentsController < ApplicationController - def create - creation = Creation.find(creation_id) - @comment = current_user.comment_on(creation, comment_params[:text], comment_params[:id]) - render json: @comment - end - - private - - def creation_id - params[:url].match(/\/(\d+)/)[0].gsub("/", "") - end - - def comment_params - params.require(:comment).permit(:id, :text) - end -end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a673e7c5..945a5562 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -13,15 +13,6 @@ module ApplicationHelper title.blank? ? "CakeSide - for cake lovers!" : "#{title} - CakeSide" end - def disqus_auth(user = current_user) - data = { id: user.id, username: user.name, email: user.email, url: "https://#{request.host_with_port}/profiles/#{user.to_param}" } - data[:avatar] = user.avatar.url_for(:thumb) if user.has_avatar? - message = Base64.encode64(data.to_json).gsub("\n", "") - timestamp = Time.now.to_i - signature = OpenSSL::HMAC.hexdigest('sha1', ENV['DISQUS_SECRET_KEY'] || '', "#{message} #{timestamp}") - "#{message} #{signature} #{timestamp}" - end - def controller?(name) params[:controller].include?(name.to_s) end diff --git a/app/views/cakes/show.html.erb b/app/views/cakes/show.html.erb index 9ffeb94d..8417be73 100644 --- a/app/views/cakes/show.html.erb +++ b/app/views/cakes/show.html.erb @@ -5,5 +5,3 @@
<%= render partial: 'show' %>
- -<%# render partial: "shared/disqus", locals: { id: "c-#{@creation.id}" } %> diff --git a/app/views/my/kitchens/show.html.erb b/app/views/my/kitchens/show.html.erb index 6946501e..92724690 100644 --- a/app/views/my/kitchens/show.html.erb +++ b/app/views/my/kitchens/show.html.erb @@ -2,16 +2,7 @@ <%= content_for :javascript do -%> <%= javascript_tag do %> var ALL_TAGS = <%= raw @tags.pluck(:name) %>; - var disqus_shortname = '<%= ENV['DISQUS_SHORTNAME'] %>'; - var disqus_identifier = 'u-<%= current_user.id %>'; - var disqus_config = function(){ - this.page.remote_auth_s3 = '<%= disqus_auth %>'; - this.page.api_key = '<%= ENV['DISQUS_API_KEY'] %>'; - }; - CakeSide.initialize({ - access_token: '<%= current_user.authentication_token %>', - disqus_shortname: disqus_shortname, - }); + CakeSide.initialize({ access_token: '<%= current_user.authentication_token %>' }); <% end %> <% end %> @@ -21,5 +12,4 @@
-
diff --git a/app/views/shared/_disqus.html.erb b/app/views/shared/_disqus.html.erb deleted file mode 100644 index e3f4def5..00000000 --- a/app/views/shared/_disqus.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -
- - -comments powered by Disqus diff --git a/config/routes.rb b/config/routes.rb index 61f597a3..381d2410 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,8 +4,6 @@ Cake::Application.routes.draw do get "about_us" => "home#about_us" get "why_cakeside" => "home#why_cakeside" - post 'comments', to: 'comments#create' - resources :tutorials, only: [:index, :show] do get 'page/:page', action: :index, on: :collection end diff --git a/spec/controllers/cakes_controller_spec.rb b/spec/controllers/cakes_controller_spec.rb deleted file mode 100644 index c1f80789..00000000 --- a/spec/controllers/cakes_controller_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'rails_helper' - -describe CakesController do - let(:user) { create(:user) } - - describe "#index" do - let!(:cakes) { create(:category, slug: "cakes") } - let!(:cookies) { create(:category, slug: "cookies") } - - it "returns all published cakes" do - cake = create(:published_cake, category: cakes) - cookie = create(:published_cake, category: cookies) - unpublished_cake = create(:cake, category: cakes) - get :index - expect(assigns(:cakes)).to match_array([cake, cookie]) - end - - it "returns all cakes in the category" do - cookie = create(:published_cake, name: "cookie", category: cookies) - get :index, category: cookie.category.slug - expect(assigns(:cakes)).to match_array([cookie]) - end - - it "returns all cakes matching the search query" do - cake = create(:published_cake, name: "cake", category: cakes) - get :index, q: cake.name[0..2] - expect(assigns(:cakes)).to match_array([cake]) - end - - it "returns all cakes tagged with the tag" do - cake = create(:published_cake, name: "cake", category: cakes) - cake.tag_list = "cakes" - cake.save! - - get :index, tags: "cakes" - expect(assigns(:cakes)).to match_array([cake]) - end - - describe "sorting" do - let!(:old_cake) { create(:published_cake, name: 'old', created_at: 2.days.ago) } - let!(:new_cake) { create(:published_cake, name: 'new', created_at: 1.day.ago) } - - it 'returns oldest cakes first' do - get :index, sort: "oldest" - expect(assigns(:cakes).to_a).to eql([ old_cake, new_cake ]) - end - - it 'returns newest cakes first' do - get :index, sort: "newest" - expect(assigns(:cakes).to_a).to eql([ new_cake, old_cake ]) - end - end - end - - describe "#show" do - let(:cake) { create(:cake, user: user) } - let(:photo) { create(:photo, imageable: cake) } - - it "loads the cake" do - get :show, id: cake.id - expect(assigns(:creation)).to eql(cake) - end - - it 'loads the selected image' do - get :show, id: cake.id, photo_id: photo.id - expect(assigns(:primary_image)).to eql(photo) - end - end -end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb deleted file mode 100644 index 55acf20d..00000000 --- a/spec/controllers/comments_controller_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "rails_helper" - -describe CommentsController do - context "#create" do - let(:creation) { create(:creation) } - let(:user) { create(:user) } - - before :each do - http_login(user) - end - - it "creates a new comment" do - post :create, id: 1207743539, url: "http://localhost:3000/creations/#{creation.to_param}", comment: { id: 1207743539, text: 'very nice' } - comment = Comment.last - expect(comment.disqus_id).to eql(1207743539) - expect(comment.creation).to eql(creation) - expect(comment.text).to eql('very nice') - end - end -end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 10efd8aa..b547f93f 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,22 +1,4 @@ require "rails_helper" describe ApplicationHelper do - describe "#disqus_auth" do - let(:user) { create(:user) } - let(:secret) { 'secret' } - - let(:expected) do - data = { id: user.id, username: user.name, email: user.email, url: "https://test.host/profiles/#{user.to_param}" }.to_json - message = Base64.encode64(data).gsub("\n", "") - timestamp = Time.now.to_i - signature = OpenSSL::HMAC.hexdigest('sha1', secret, "#{message} #{timestamp}") - "#{message} #{signature} #{timestamp}" - end - - before { ENV['DISQUS_SECRET_KEY'] = secret } - - it "should generate a single sign on token" do - expect(helper.disqus_auth(user)).to eql(expected) - end - end end diff --git a/spec/routing/comments_routing_spec.rb b/spec/routing/comments_routing_spec.rb deleted file mode 100644 index 36ce7511..00000000 --- a/spec/routing/comments_routing_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "rails_helper" - -describe "/comments" do - it "routes to the create action" do - expect({ :post => '/comments' }).to route_to(controller: 'comments', action: 'create') - end -end -- cgit v1.2.3