Skip to content

Commit

Permalink
update test dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek committed Sep 4, 2019
1 parent 9b1533d commit 7ca5850
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion intercom-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 11 additions & 5 deletions spec/action_controller_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
85 changes: 0 additions & 85 deletions spec/auto_include_filter_spec.rb
Original file line number Diff line number Diff line change
@@ -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("<body>Hello world</body>")
end

def with_user_instance_variable
@user = dummy_user
render_content("<body>Hello world</body>")
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("<body>Hello world</body>")
end

def with_user_instance_variable_and_custom_data
@user = dummy_user
intercom_custom_data.user['testing_stuff'] = true
render_content("<body>Hello world</body>")
end

def with_unusable_user_instance_variable
@user = Object.new
render_content("<body>Hello world</body>")
end

def with_mongo_like_user
@user = Struct.new(:id).new.tap do |user|
user.id = DummyBSONId.new('deadbeaf1234mongo')
end
render_content("<body>Hello world</body>")
end

def with_numeric_user_id
@user = Struct.new(:id).new.tap do |user|
user.id = 123
end
render_content("<body>Hello world</body>")
end

def with_current_user_method
render_content("<body>Hello world</body>")
end

def with_admin_instance_variable
@admin = dummy_user(:email => '[email protected]', :name => 'Eoghan McCabe')
render_content("<body>Hello world</body>")
end

def with_some_tricky_string
@user = dummy_user(:email => "\\\"foo\"")
render_content("<body>Hello world</body>")
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 => '[email protected]', :name => 'Ciaran Lee')
end
end

describe TestController, type: :controller do
it 'has no intercom script if no user present' do
get :without_user
Expand Down
84 changes: 84 additions & 0 deletions spec/test_controller.rb
Original file line number Diff line number Diff line change
@@ -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("<body>Hello world</body>")
end

def with_user_instance_variable
@user = dummy_user
render_content("<body>Hello world</body>")
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("<body>Hello world</body>")
end

def with_user_instance_variable_and_custom_data
@user = dummy_user
intercom_custom_data.user['testing_stuff'] = true
render_content("<body>Hello world</body>")
end

def with_unusable_user_instance_variable
@user = Object.new
render_content("<body>Hello world</body>")
end

def with_mongo_like_user
@user = Struct.new(:id).new.tap do |user|
user.id = DummyBSONId.new('deadbeaf1234mongo')
end
render_content("<body>Hello world</body>")
end

def with_numeric_user_id
@user = Struct.new(:id).new.tap do |user|
user.id = 123
end
render_content("<body>Hello world</body>")
end

def with_current_user_method
render_content("<body>Hello world</body>")
end

def with_admin_instance_variable
@admin = dummy_user(:email => '[email protected]', :name => 'Eoghan McCabe')
render_content("<body>Hello world</body>")
end

def with_some_tricky_string
@user = dummy_user(:email => "\\\"foo\"")
render_content("<body>Hello world</body>")
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 => '[email protected]', :name => 'Ciaran Lee')
end
end

0 comments on commit 7ca5850

Please sign in to comment.