|
1 | 1 | require 'action_controller_spec_helper' |
2 | 2 |
|
3 | | -class TestController < ActionController::Base |
4 | | - if respond_to? :skip_after_action |
5 | | - skip_after_action :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped |
6 | | - else |
7 | | - skip_after_filter :intercom_rails_auto_include, :only => :with_user_instance_variable_after_filter_skipped |
8 | | - end |
9 | | - |
10 | | - def without_user |
11 | | - render_content("<body>Hello world</body>") |
12 | | - end |
13 | | - |
14 | | - def with_user_instance_variable |
15 | | - @user = dummy_user |
16 | | - render_content("<body>Hello world</body>") |
17 | | - end |
18 | | - |
19 | | - def with_user_instance_variable_no_body_tag |
20 | | - render_content("Hello world") |
21 | | - end |
22 | | - |
23 | | - def with_user_instance_variable_after_filter_skipped |
24 | | - with_user_instance_variable |
25 | | - end |
26 | | - |
27 | | - def with_user_and_app_instance_variables |
28 | | - @user = dummy_user |
29 | | - @app = dummy_company |
30 | | - render_content("<body>Hello world</body>") |
31 | | - end |
32 | | - |
33 | | - def with_user_instance_variable_and_custom_data |
34 | | - @user = dummy_user |
35 | | - intercom_custom_data.user['testing_stuff'] = true |
36 | | - render_content("<body>Hello world</body>") |
37 | | - end |
38 | | - |
39 | | - def with_unusable_user_instance_variable |
40 | | - @user = Object.new |
41 | | - render_content("<body>Hello world</body>") |
42 | | - end |
43 | | - |
44 | | - def with_mongo_like_user |
45 | | - @user = Struct.new(:id).new.tap do |user| |
46 | | - user.id = DummyBSONId.new('deadbeaf1234mongo') |
47 | | - end |
48 | | - render_content("<body>Hello world</body>") |
49 | | - end |
50 | | - |
51 | | - def with_numeric_user_id |
52 | | - @user = Struct.new(:id).new.tap do |user| |
53 | | - user.id = 123 |
54 | | - end |
55 | | - render_content("<body>Hello world</body>") |
56 | | - end |
57 | | - |
58 | | - def with_current_user_method |
59 | | - render_content("<body>Hello world</body>") |
60 | | - end |
61 | | - |
62 | | - def with_admin_instance_variable |
63 | | - @admin = dummy_user(:email => 'eoghan@intercom.io', :name => 'Eoghan McCabe') |
64 | | - render_content("<body>Hello world</body>") |
65 | | - end |
66 | | - |
67 | | - def with_some_tricky_string |
68 | | - @user = dummy_user(:email => "\\\"foo\"") |
69 | | - render_content("<body>Hello world</body>") |
70 | | - end |
71 | | - |
72 | | - private |
73 | | - |
74 | | - def render_content(body) |
75 | | - if Rails::VERSION::MAJOR >= 5 |
76 | | - render :body => body, :content_type => 'text/html' |
77 | | - else |
78 | | - render :text => body, :content_type => 'text/html' |
79 | | - end |
80 | | - end |
81 | | - |
82 | | - def current_user |
83 | | - raise NameError if params[:action] != 'with_current_user_method' |
84 | | - dummy_user(:email => 'ciaran@intercom.io', :name => 'Ciaran Lee') |
85 | | - end |
86 | | -end |
87 | | - |
88 | 3 | describe TestController, type: :controller do |
89 | 4 | it 'has no intercom script if no user present' do |
90 | 5 | get :without_user |
|
0 commit comments