From 3ad51f82964a935a850bc64c4c97027d3be6056d Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Sun, 18 Oct 2015 19:27:22 -0500 Subject: [PATCH] Made the dummy app a bit better for testing the gem (you can now visit it on the browser) --- README.md | 2 +- lib/commontator.rb | 2 +- .../{controller_includes.rb => controllers.rb} | 4 ++-- .../app/controllers/application_controller.rb | 2 ++ .../app/controllers/dummy_models_controller.rb | 18 +++--------------- .../show.html.erb | 0 spec/dummy/config/environment.rb | 2 ++ spec/dummy/config/routes.rb | 6 ++++-- spec/dummy/lib/dummy_controllers.rb | 10 ++++++++++ ...er_includes_spec.rb => controllers_spec.rb} | 2 +- 10 files changed, 26 insertions(+), 22 deletions(-) rename lib/commontator/{controller_includes.rb => controllers.rb} (91%) rename spec/dummy/app/views/{dummy_model => dummy_models}/show.html.erb (100%) create mode 100644 spec/dummy/lib/dummy_controllers.rb rename spec/lib/commontator/{controller_includes_spec.rb => controllers_spec.rb} (92%) diff --git a/README.md b/README.md index 6571d8c..4b0aa12 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Follow the steps below to add commontator to your models and views: In that case, just add the following method call to the controller action that displays the page in question: ```rb - commontator_thread_show(commontable) + commontator_thread_show(@commontable) ``` Note that the call to `commontator_thread` in the view is still necessary in either case. diff --git a/lib/commontator.rb b/lib/commontator.rb index c74826d..3e76ce1 100644 --- a/lib/commontator.rb +++ b/lib/commontator.rb @@ -1,5 +1,5 @@ require 'commontator/engine' -require 'commontator/controller_includes' +require 'commontator/controllers' module Commontator # Attributes diff --git a/lib/commontator/controller_includes.rb b/lib/commontator/controllers.rb similarity index 91% rename from lib/commontator/controller_includes.rb rename to lib/commontator/controllers.rb index 0283f87..727a0d9 100644 --- a/lib/commontator/controller_includes.rb +++ b/lib/commontator/controllers.rb @@ -2,7 +2,7 @@ require 'commontator/security_transgression' module Commontator - module ControllerIncludes + module Controllers def self.included(base) base.helper Commontator::SharedHelper end @@ -30,4 +30,4 @@ def commontator_thread_show(commontable) end end -ActionController::Base.send :include, Commontator::ControllerIncludes +ActionController::Base.send :include, Commontator::Controllers diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index 45eef3a..b2b4f38 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ class ApplicationController < ActionController::Base protect_from_forgery + + helper_method :current_user end diff --git a/spec/dummy/app/controllers/dummy_models_controller.rb b/spec/dummy/app/controllers/dummy_models_controller.rb index 0e3e406..062c0dd 100644 --- a/spec/dummy/app/controllers/dummy_models_controller.rb +++ b/spec/dummy/app/controllers/dummy_models_controller.rb @@ -1,31 +1,19 @@ -class DummyModelsController < ActionController::Base +class DummyModelsController < ApplicationController before_filter :get_dummy - # Workaround for https://github.com/rails/rails/issues/11662 - def self.params - {} + def show + commontator_thread_show(@dummy_model) end def hide render :show end - def show - commontator_thread_show(@dummy_model) - end - def url_options return Hash.new if request.nil? super end - def view_context - view_context = view_context_class.new - view_context.view_paths = view_paths - view_context.controller = self - view_context - end - protected def get_dummy diff --git a/spec/dummy/app/views/dummy_model/show.html.erb b/spec/dummy/app/views/dummy_models/show.html.erb similarity index 100% rename from spec/dummy/app/views/dummy_model/show.html.erb rename to spec/dummy/app/views/dummy_models/show.html.erb diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index 963aee0..ce93d0e 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -1,6 +1,8 @@ # Load the Rails application. require File.expand_path('../application', __FILE__) +require 'dummy_controllers' + # Initialize the Rails application. Dummy::Application.initialize! diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index dbbd735..b4f4c16 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,6 +1,8 @@ Rails.application.routes.draw do - resources :dummy_models, :only => [:show] do - get :hide, :on => :member + root to: "dummy_models#show", id: 1 + + resources :dummy_models, only: :show do + get :hide, on: :member end mount Commontator::Engine => "/commontator" diff --git a/spec/dummy/lib/dummy_controllers.rb b/spec/dummy/lib/dummy_controllers.rb new file mode 100644 index 0000000..4776409 --- /dev/null +++ b/spec/dummy/lib/dummy_controllers.rb @@ -0,0 +1,10 @@ +module DummyControllers + def current_user + @current_user ||= DummyUser.first_or_create! + @current_user.can_read = true + @current_user.can_edit = true + @current_user + end +end + +ActionController::Base.send :include, DummyControllers diff --git a/spec/lib/commontator/controller_includes_spec.rb b/spec/lib/commontator/controllers_spec.rb similarity index 92% rename from spec/lib/commontator/controller_includes_spec.rb rename to spec/lib/commontator/controllers_spec.rb index 135a8c3..66c18dc 100644 --- a/spec/lib/commontator/controller_includes_spec.rb +++ b/spec/lib/commontator/controllers_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Commontator - RSpec.describe ControllerIncludes, type: :lib do + RSpec.describe Controllers, type: :lib do it 'must add commontator_thread_show to ActionController instances' do expect(ActionController::Base.new.respond_to?(:commontator_thread_show, true)).to eq true