macros.rb
1.32 KB
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
def it_requires_authentication(options = {})
default_options = {
for: {
index: :get,
show: :get,
new: :get,
create: :post,
edit: :get,
update: :put,
destroy: :delete
},
params: { id: '4c6c760494df2a18cc000015' }
}
options.reverse_merge!(default_options)
context 'when signed out' do
before do
sign_out :user
end
options[:for].each do |action, method|
it "#{method.to_s.upcase} #{action} redirects to the sign in page" do
send(method, action, options[:params])
expect(response).to redirect_to(new_user_session_path)
end
end
end
end
def it_requires_admin_privileges(options = {})
default_options = {
for: {
index: :get,
show: :get,
new: :get,
create: :post,
edit: :get,
update: :put,
destroy: :delete
},
params: { id: 'dummyid' }
}
options.reverse_merge!(default_options)
context 'when signed in as a regular user' do
before do
sign_out :user
sign_in Fabricate(:user)
end
options[:for].each do |action, method|
it "#{method.to_s.upcase} #{action} redirects to the root path" do
send(method, action, options[:params])
expect(response).to redirect_to(root_path)
end
end
end
end