-
Notifications
You must be signed in to change notification settings - Fork 398
Expand file tree
/
Copy pathshared_examples_for_finders.rb
More file actions
132 lines (112 loc) · 8.13 KB
/
shared_examples_for_finders.rb
File metadata and controls
132 lines (112 loc) · 8.13 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
shared_examples_for :finders do |param_name, param_method|
context "using #{param_name} as parameter" do
describe ".with_role" do
it { should respond_to(:with_role).with(1).argument }
it { should respond_to(:with_role).with(2).arguments }
context "with a global role" do
it { subject.with_role("admin".send(param_method)).should eq([ root ]) }
it { subject.with_role("moderator".send(param_method)).should be_empty }
it { subject.with_role("visitor".send(param_method)).should be_empty }
end
context "with a class scoped role" do
context "on Forum class" do
it { subject.with_role("admin".send(param_method), Forum).should eq([ root ]) }
it { subject.with_role("moderator".send(param_method), Forum).should eq([ modo ]) }
it { subject.with_role("visitor".send(param_method), Forum).should be_empty }
end
context "on Group class" do
it { subject.with_role("admin".send(param_method), Group).should eq([ root ]) }
it { subject.with_role("moderator".send(param_method), Group).should eq([ root ]) }
it { subject.with_role("visitor".send(param_method), Group).should be_empty }
end
end
context "with an instance scoped role" do
context "on Forum.first instance" do
it { subject.with_role("admin".send(param_method), Forum.first).should eq([ root ]) }
it { subject.with_role("moderator".send(param_method), Forum.first).should eq([ modo ]) }
it { subject.with_role("visitor".send(param_method), Forum.first).should be_empty }
end
context "on Forum.last instance" do
it { subject.with_role("admin".send(param_method), Forum.last).should eq([ root ]) }
it { subject.with_role("moderator".send(param_method), Forum.last).should eq([ modo ]) }
it { subject.with_role("visitor".send(param_method), Forum.last).should include(root, visitor) } # =~ doesn't pass using mongoid, don't know why...
end
context "on Group.first instance" do
it { subject.with_role("admin".send(param_method), Group.first).should eq([ root ]) }
it { subject.with_role("moderator".send(param_method), Group.first).should eq([ root ]) }
it { subject.with_role("visitor".send(param_method), Group.first).should eq([ modo ]) }
end
context "on Company.first_instance" do
it { subject.with_role("owner".send(param_method), Company.first).should eq([ owner ]) }
end
end
end
describe ".without_role" do
it { should respond_to(:without_role).with(1).argument }
it { should respond_to(:without_role).with(2).arguments }
context "with a global role" do
it { subject.without_role("admin".send(param_method)).should_not eq([ root ]) }
it { subject.without_role("moderator".send(param_method)).should_not be_empty }
it { subject.without_role("visitor".send(param_method)).should_not be_empty }
end
context "with a class scoped role" do
context "on Forum class" do
it { subject.without_role("admin".send(param_method), Forum).should_not eq([ root ]) }
it { subject.without_role("moderator".send(param_method), Forum).should_not eq([ modo ]) }
it { subject.without_role("visitor".send(param_method), Forum).should_not be_empty }
end
context "on Group class" do
it { subject.without_role("admin".send(param_method), Group).should_not eq([ root ]) }
it { subject.without_role("moderator".send(param_method), Group).should_not eq([ root ]) }
it { subject.without_role("visitor".send(param_method), Group).should_not be_empty }
end
end
context "with an instance scoped role" do
context "on Forum.first instance" do
it { subject.without_role("admin".send(param_method), Forum.first).should_not eq([ root ]) }
it { subject.without_role("moderator".send(param_method), Forum.first).should_not eq([ modo ]) }
it { subject.without_role("visitor".send(param_method), Forum.first).should_not be_empty }
end
context "on Forum.last instance" do
it { subject.without_role("admin".send(param_method), Forum.last).should_not eq([ root ]) }
it { subject.without_role("moderator".send(param_method), Forum.last).should_not eq([ modo ]) }
it { subject.without_role("visitor".send(param_method), Forum.last).should_not include(root, visitor) } # =~ doesn't pass using mongoid, don't know why...
end
context "on Group.first instance" do
it { subject.without_role("admin".send(param_method), Group.first).should_not eq([ root ]) }
it { subject.without_role("moderator".send(param_method), Group.first).should_not eq([ root ]) }
it { subject.without_role("visitor".send(param_method), Group.first).should_not eq([ modo ]) }
end
context "on Company.first_instance" do
it { subject.without_role("owner".send(param_method), Company.first).should_not eq([ owner ]) }
end
end
end
describe ".with_all_roles" do
it { should respond_to(:with_all_roles) }
it { subject.with_all_roles("admin".send(param_method), :staff).should eq([ root ]) }
it { subject.with_all_roles("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
it { subject.with_all_roles("admin".send(param_method), "moderator".send(param_method)).should be_empty }
it { subject.with_all_roles("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Forum }).should be_empty }
it { subject.with_all_roles({ :name => "moderator".send(param_method), :resource => Forum }, { :name => :manager, :resource => Group }).should eq([ modo ]) }
it { subject.with_all_roles("moderator".send(param_method), :manager).should be_empty }
it { subject.with_all_roles({ :name => "visitor".send(param_method), :resource => Forum.last }, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
it { subject.with_all_roles({ :name => "visitor".send(param_method), :resource => Group.first }, { :name => "moderator".send(param_method), :resource => Forum }).should eq([ modo ]) }
it { subject.with_all_roles({ :name => "visitor".send(param_method), :resource => :any }, { :name => "moderator".send(param_method), :resource => :any }).should =~ [ root, modo ] }
end
describe ".with_any_role" do
it { should respond_to(:with_any_role) }
it { subject.with_any_role().should eq(subject.joins(:roles).all)}
it { subject.with_any_role("admin".send(param_method), :staff).should eq([ root ]) }
it { subject.with_any_role("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
it { subject.with_any_role("admin".send(param_method), "moderator".send(param_method)).should eq([ root ]) }
it { subject.with_any_role("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Forum }).should =~ [ root, modo ] }
it { subject.with_any_role({ :name => "moderator".send(param_method), :resource => Forum }, { :name => :manager, :resource => Group }).should eq([ modo ]) }
it { subject.with_any_role({ :name => "moderator".send(param_method), :resource => Group }, { :name => :manager, :resource => Group }).should =~ [ root, modo ] }
it { subject.with_any_role("moderator".send(param_method), :manager).should be_empty }
it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => Forum.last }, { :name => "moderator".send(param_method), :resource => Group }).should =~ [ root, visitor ] }
it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => Group.first }, { :name => "moderator".send(param_method), :resource => Forum }).should eq([ modo ]) }
it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => :any }, { :name => "moderator".send(param_method), :resource => :any }).should =~ [ root, modo, visitor ] }
end
end
end