diff --git a/.circleci/config.yml b/.circleci/config.yml index 34c0947..aea3d60 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/ruby:2.4.6 + - image: circleci/ruby:2.6.3 working_directory: ~/intercom-rails diff --git a/intercom-rails.gemspec b/intercom-rails.gemspec index 44d9c83..bd0dc5b 100644 --- a/intercom-rails.gemspec +++ b/intercom-rails.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '~> 3.1' s.add_development_dependency 'rspec-rails', '~> 3.1' s.add_development_dependency 'pry' - s.add_development_dependency 'sinatra', '~> 1.4.5' + s.add_development_dependency 'sinatra', '~> 2.0.0' s.add_development_dependency 'thin', '~> 1.7.0' s.add_development_dependency 'tzinfo' s.add_development_dependency 'gem-release' diff --git a/spec/action_controller_spec_helper.rb b/spec/action_controller_spec_helper.rb index 59038a0..8277b33 100644 --- a/spec/action_controller_spec_helper.rb +++ b/spec/action_controller_spec_helper.rb @@ -11,11 +11,6 @@ def self.env end end -TestRoutes = ActionDispatch::Routing::RouteSet.new -TestRoutes.draw do - get ':controller(/:action)' -end - module IntercomRails class Application < Rails::Application config.secret_key_base = 'secret_key_base' @@ -34,7 +29,18 @@ class ActionController::Base else after_filter :intercom_rails_auto_include end +end + +require 'test_controller' + +TestRoutes = ActionDispatch::Routing::RouteSet.new +TestRoutes.draw do + TestController.public_instance_methods.each do |method| + get "test/#{method}", to: "test##{method}" + end +end +class ActionController::Base include TestRoutes.url_helpers include TestRoutes.mounted_helpers end diff --git a/spec/auto_include_filter_spec.rb b/spec/auto_include_filter_spec.rb index eda6537..280ac0f 100644 --- a/spec/auto_include_filter_spec.rb +++ b/spec/auto_include_filter_spec.rb @@ -1,90 +1,5 @@ require 'action_controller_spec_helper' -class TestController < ActionController::Base - if respond_to? :skip_after_action - skip_after_action :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped - else - skip_after_filter :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped - end - - def without_user - render_content("Hello world") - end - - def with_user_instance_variable - @user = dummy_user - render_content("Hello world") - end - - def with_user_instance_variable_no_body_tag - render_content("Hello world") - end - - def with_user_instance_variable_after_filter_skipped - with_user_instance_variable - end - - def with_user_and_app_instance_variables - @user = dummy_user - @app = dummy_company - render_content("Hello world") - end - - def with_user_instance_variable_and_custom_data - @user = dummy_user - intercom_custom_data.user['testing_stuff'] = true - render_content("Hello world") - end - - def with_unusable_user_instance_variable - @user = Object.new - render_content("Hello world") - end - - def with_mongo_like_user - @user = Struct.new(:id).new.tap do |user| - user.id = DummyBSONId.new('deadbeaf1234mongo') - end - render_content("Hello world") - end - - def with_numeric_user_id - @user = Struct.new(:id).new.tap do |user| - user.id = 123 - end - render_content("Hello world") - end - - def with_current_user_method - render_content("Hello world") - end - - def with_admin_instance_variable - @admin = dummy_user(:email => 'eoghan@intercom.io', :name => 'Eoghan McCabe') - render_content("Hello world") - end - - def with_some_tricky_string - @user = dummy_user(:email => "\\\"foo\"") - render_content("Hello world") - end - - private - - def render_content(body) - if Rails::VERSION::MAJOR >= 5 - render :body => body, :content_type => 'text/html' - else - render :text => body, :content_type => 'text/html' - end - end - - def current_user - raise NameError if params[:action] != 'with_current_user_method' - dummy_user(:email => 'ciaran@intercom.io', :name => 'Ciaran Lee') - end -end - describe TestController, type: :controller do it 'has no intercom script if no user present' do get :without_user diff --git a/spec/test_controller.rb b/spec/test_controller.rb new file mode 100644 index 0000000..4060087 --- /dev/null +++ b/spec/test_controller.rb @@ -0,0 +1,84 @@ +class TestController < ActionController::Base + if respond_to? :skip_after_action + skip_after_action :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped + else + skip_after_filter :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped + end + + def without_user + render_content("Hello world") + end + + def with_user_instance_variable + @user = dummy_user + render_content("Hello world") + end + + def with_user_instance_variable_no_body_tag + render_content("Hello world") + end + + def with_user_instance_variable_after_filter_skipped + with_user_instance_variable + end + + def with_user_and_app_instance_variables + @user = dummy_user + @app = dummy_company + render_content("Hello world") + end + + def with_user_instance_variable_and_custom_data + @user = dummy_user + intercom_custom_data.user['testing_stuff'] = true + render_content("Hello world") + end + + def with_unusable_user_instance_variable + @user = Object.new + render_content("Hello world") + end + + def with_mongo_like_user + @user = Struct.new(:id).new.tap do |user| + user.id = DummyBSONId.new('deadbeaf1234mongo') + end + render_content("Hello world") + end + + def with_numeric_user_id + @user = Struct.new(:id).new.tap do |user| + user.id = 123 + end + render_content("Hello world") + end + + def with_current_user_method + render_content("Hello world") + end + + def with_admin_instance_variable + @admin = dummy_user(:email => 'eoghan@intercom.io', :name => 'Eoghan McCabe') + render_content("Hello world") + end + + def with_some_tricky_string + @user = dummy_user(:email => "\\\"foo\"") + render_content("Hello world") + end + + private + + def render_content(body) + if Rails::VERSION::MAJOR >= 5 + render :body => body, :content_type => 'text/html' + else + render :text => body, :content_type => 'text/html' + end + end + + def current_user + raise NameError if params[:action] != 'with_current_user_method' + dummy_user(:email => 'ciaran@intercom.io', :name => 'Ciaran Lee') + end +end