forked from 3scale/porta
/
application_helper_test.rb
70 lines (50 loc) · 1.77 KB
/
application_helper_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
attr_accessor :current_user
delegate :can?, to: :ability
def test_link_to_export_widget_for
self.current_user = FactoryBot.build_stubbed(:member, account: account)
link = link_to_export_widget_for('Accounts')
assert_nil link
self.current_user = FactoryBot.build_stubbed(:admin, account: account)
link = link_to_export_widget_for('Accounts')
assert_match /a/, link
end
def test_css_class
assert_equal 'some class', css_class('some', 'class')
assert_equal 'yes maybe', css_class('yes' => true, 'no' => false, maybe: 'yeah')
assert_equal 'one two three', css_class('one', ['two'], three: true)
end
class AssetHostTest < ApplicationHelperTest
setup do
@request = ActionDispatch::TestRequest.create
@asset_host = 'cdn.3scale.test.localhost'
end
attr_reader :request
test 'asset host is not configured' do
Rails.configuration.asset_host = nil
Rails.configuration.three_scale.asset_host = @asset_host
result = rails_asset_host_url
assert_equal '', result
end
test "asset host is configured but it's value is empty" do
Rails.configuration.asset_host = -> {}
Rails.configuration.three_scale.asset_host = ''
result = rails_asset_host_url
assert_equal '', result
end
test 'asset host is configured and has a proper value' do
Rails.configuration.asset_host = -> {}
Rails.configuration.three_scale.asset_host = @asset_host
result = rails_asset_host_url
assert_equal "#{request.protocol}#{@asset_host}", result
end
end
private
def ability
Ability.new(current_user)
end
def account
@account ||= FactoryBot.build_stubbed(:simple_provider)
end
end