forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
external_url_spec.rb
43 lines (38 loc) · 1.18 KB
/
external_url_spec.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
RSpec.describe ExternalUrlMixin do
let(:test_class) do
Class.new(ActiveRecord::Base) do
def self.name = 'TestClass'
self.table_name = 'vms'
include ExternalUrlMixin
end
end
describe '#external_url=' do
before do
User.current_user = FactoryBot.create(:user)
end
let(:test_instance) do
test_class.create.tap { |i| i.external_url = 'https://www.other.example.com' }
end
it 'sets url for the current user' do
expect(ExternalUrl.where(
:user => User.current_user,
:resource_type => 'TestClass',
:resource_id => test_instance.id
).first.attributes).to include(
'url' => 'https://www.other.example.com'
)
end
it 'removes previously set url for the current user' do
test_instance.external_url = 'https://www.example.com'
test_instance.reload
expect(test_instance.external_urls.count).to eq(1)
expect(ExternalUrl.where(
:user => User.current_user,
:resource_type => 'TestClass',
:resource_id => test_instance.id
).first.attributes).to include(
'url' => 'https://www.example.com'
)
end
end
end