1
1
shared_examples "periscopic" do
2
2
context "without a database" do
3
3
before do
4
- model . stub ( periscope_default_scope : model )
4
+ allow ( model ) . to receive ( :periscope_default_scope ) . and_return ( model )
5
5
end
6
6
7
7
def expect_scopes ( calls )
8
8
calls . each do |method , args |
9
- model . should_receive ( method ) . with ( *args ) . and_return ( model )
9
+ args << no_args if args . empty?
10
+ expect ( model ) . to receive ( method ) . with ( *args ) . and_return ( model )
10
11
end
11
12
end
12
13
13
14
it "uses the default scope for no params" do
14
15
scoped = double ( :scoped ) . as_null_object
15
- model . should_receive ( :periscope_default_scope ) . once . and_return ( scoped )
16
- model . periscope . should == scoped
16
+ expect ( model ) . to receive ( :periscope_default_scope ) . once . and_return ( scoped )
17
+ expect ( model . periscope ) . to eq ( scoped )
17
18
end
18
19
19
20
it "uses the default scope for empty params" do
20
21
scoped = double ( :scoped ) . as_null_object
21
- model . should_receive ( :periscope_default_scope ) . once . and_return ( scoped )
22
- model . periscope ( { } ) . should == scoped
22
+ expect ( model ) . to receive ( :periscope_default_scope ) . once . and_return ( scoped )
23
+ expect ( model . periscope ( { } ) ) . to eq ( scoped )
23
24
end
24
25
25
26
it "ignores protected scopes" do
26
- model . should_not_receive ( :foo )
27
+ expect ( model ) . not_to receive ( :foo )
27
28
model . periscope ( foo : "bar" )
28
29
end
29
30
@@ -41,7 +42,7 @@ def expect_scopes(calls)
41
42
42
43
it "ignores protected scopes when mixed with accessible scopes" do
43
44
expect_scopes ( foo : [ "baz" ] )
44
- model . should_not_receive ( :bar )
45
+ expect ( model ) . not_to receive ( :bar )
45
46
model . scope_accessible ( :foo )
46
47
model . periscope ( foo : "baz" , bar : "mitzvah" )
47
48
end
@@ -94,7 +95,7 @@ def expect_scopes(calls)
94
95
it "allows custom parameter parsing via custom parser" do
95
96
expect_scopes ( foo : [ "BAR" ] )
96
97
parser = double ( :parser ) . as_null_object
97
- parser . should_receive ( :call ) . once . with ( "bar" ) . and_return ( [ "BAR" ] )
98
+ expect ( parser ) . to receive ( :call ) . once . with ( "bar" ) . and_return ( [ "BAR" ] )
98
99
model . scope_accessible ( :foo , parser : parser )
99
100
model . periscope ( foo : "bar" )
100
101
end
@@ -106,19 +107,19 @@ def expect_scopes(calls)
106
107
end
107
108
108
109
it "allows accessible scope exclusion given a falsey param" do
109
- model . should_not_receive ( :foo )
110
+ expect ( model ) . not_to receive ( :foo )
110
111
model . scope_accessible ( :foo , boolean : true )
111
112
model . periscope ( foo : nil )
112
113
end
113
114
114
115
it "allows accessible scope exclusion given a falsey parsed value" do
115
- model . should_not_receive ( :foo )
116
+ expect ( model ) . not_to receive ( :foo )
116
117
model . scope_accessible ( :foo , boolean : true , parser : proc { [ nil ] } )
117
118
model . periscope ( foo : "bar" )
118
119
end
119
120
120
121
it "allows accessible scope exclusion given a blank param" do
121
- model . should_not_receive ( :foo )
122
+ expect ( model ) . not_to receive ( :foo )
122
123
model . scope_accessible ( :foo , ignore_blank : true )
123
124
model . periscope ( foo : nil )
124
125
model . periscope ( foo : "" )
@@ -133,7 +134,7 @@ def expect_scopes(calls)
133
134
end
134
135
135
136
it "allows accessible boolean scope exclusion given a blank param" do
136
- model . should_not_receive ( :foo )
137
+ expect ( model ) . not_to receive ( :foo )
137
138
model . scope_accessible ( :foo , boolean : true , ignore_blank : true )
138
139
model . periscope ( foo : nil )
139
140
model . periscope ( foo : "" )
0 commit comments