permissioner 0.2.0.beta → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,26 +19,26 @@ describe Permissioner::Matchers::ExactlyAllowResources do
19
19
 
20
20
  it 'should return true if given resources exaclty allowed' do
21
21
  matcher = create_matcher :user, :comment, :post
22
- matcher.matches?(permission_service).should be_true
22
+ expect(matcher.matches?(permission_service)).to be_truthy
23
23
  end
24
24
 
25
25
  it 'should return false if at least one resource is not allowed' do
26
26
  matcher = create_matcher :user, :comment, :account
27
- matcher.matches?(permission_service).should be_false
27
+ expect(matcher.matches?(permission_service)).to be_falsey
28
28
  end
29
29
 
30
30
  it 'should return false if more resources allowed than expected' do
31
31
  matcher = create_matcher :user, :comment
32
- matcher.matches?(permission_service).should be_false
32
+ expect(matcher.matches?(permission_service)).to be_falsey
33
33
  end
34
34
 
35
35
  it 'should work if no resource is allowed' do
36
36
  matcher = create_matcher :user, :comment
37
- matcher.matches?(PermissionService.new).should be_false
37
+ expect(matcher.matches?(PermissionService.new)).to be_falsey
38
38
  end
39
39
  end
40
40
 
41
- describe '#failure_message_for_should' do
41
+ describe '#failure_message' do
42
42
 
43
43
  it 'should be available' do
44
44
  matcher = create_matcher(:user, :comment)
@@ -48,30 +48,30 @@ describe Permissioner::Matchers::ExactlyAllowResources do
48
48
  "[:comment, :post, :user] allowed"
49
49
  #call is necessary because matches sets @permission_service
50
50
  matcher.matches?(permission_service)
51
- matcher.failure_message_for_should.should eq expected_messages
51
+ expect(matcher.failure_message).to eq expected_messages
52
52
  end
53
53
 
54
54
  it 'should work if no controller allowed' do
55
55
  matcher = create_matcher(:user, :comment)
56
56
  #call is necessary because matches sets @permission_service
57
57
  matcher.matches?((PermissionService.new))
58
- matcher.failure_message_for_should.should be_kind_of(String)
58
+ expect(matcher.failure_message).to be_kind_of(String)
59
59
  end
60
60
  end
61
61
 
62
- describe '#failure_message_for_should_not' do
62
+ describe '# failure_message_when_negated' do
63
63
 
64
64
  it 'should be available' do
65
65
  matcher = create_matcher(:user, :comment)
66
66
  expected_messages =
67
67
  "expected to exactly not allow resources \n" \
68
68
  "[:comment, :user], but these resources are exactly allowed\n"
69
- matcher.failure_message_for_should_not.should eq expected_messages
69
+ expect(matcher. failure_message_when_negated).to eq expected_messages
70
70
  end
71
71
 
72
72
  it 'should work if no controller allowed' do
73
73
  matcher = create_matcher(:comment, :user)
74
- matcher.failure_message_for_should_not.should be_kind_of(String)
74
+ expect(matcher. failure_message_when_negated).to be_kind_of(String)
75
75
  end
76
76
  end
77
77
 
@@ -18,9 +18,9 @@ describe Permissioner::Matchers::ExactlyExpectActions do
18
18
 
19
19
  it 'should transform expected_actions into string array' do
20
20
  matcher = create_matcher [:controller, :action]
21
- matcher.instance_variable_get(:@all_expected_actions).should eq [['controller', ['action']]]
21
+ expect(matcher.instance_variable_get(:@all_expected_actions)).to eq [['controller', ['action']]]
22
22
  matcher = create_matcher [:controller, [:action_1, :action_2]]
23
- matcher.instance_variable_get(:@all_expected_actions).should eq [['controller', ['action_1', 'action_2']]]
23
+ expect(matcher.instance_variable_get(:@all_expected_actions)).to eq [['controller', ['action_1', 'action_2']]]
24
24
  end
25
25
 
26
26
  it 'should raise an exception if multiple actions not stated as array' do
@@ -40,7 +40,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
40
40
  [:users, [:show, :new, :create]],
41
41
  [:posts, [:show, :edit, :update]]
42
42
  )
43
- matcher.matches?(permission_service).should be_true
43
+ expect(matcher.matches?(permission_service)).to be_truthy
44
44
  end
45
45
 
46
46
  it 'should return true if for a given controller all actions are allowed and all is expected' do
@@ -50,7 +50,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
50
50
  [:users, [:show, :new, :create]],
51
51
  [:posts, [:show, :edit, :update]]
52
52
  )
53
- matcher.matches?(permission_service).should be_true
53
+ expect(matcher.matches?(permission_service)).to be_truthy
54
54
  end
55
55
  end
56
56
 
@@ -62,7 +62,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
62
62
  [:users, [:show, :new, :create]],
63
63
  [:accounts, [:show, :edit, :update]]
64
64
  )
65
- matcher.matches?(permission_service).should be_false
65
+ expect(matcher.matches?(permission_service)).to be_falsey
66
66
  end
67
67
 
68
68
  it 'should return false if at least one controller is allowed but no expected' do
@@ -70,7 +70,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
70
70
  [:comments, [:index, :show, :new, :create]],
71
71
  [:users, [:show, :new, :create]]
72
72
  )
73
- matcher.matches?(permission_service).should be_false
73
+ expect(matcher.matches?(permission_service)).to be_falsey
74
74
  end
75
75
  end
76
76
 
@@ -82,7 +82,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
82
82
  [:users, [:show, :new, :create]],
83
83
  [:posts, [:show, :edit, :update]]
84
84
  )
85
- matcher.matches?(permission_service).should be_false
85
+ expect(matcher.matches?(permission_service)).to be_falsey
86
86
  end
87
87
 
88
88
  it 'should return false if at least one action is not allowed but no expected' do
@@ -91,7 +91,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
91
91
  [:users, [:show, :new, :create]],
92
92
  [:posts, [:show, :edit, :update]]
93
93
  )
94
- matcher.matches?(permission_service).should be_false
94
+ expect(matcher.matches?(permission_service)).to be_falsey
95
95
  end
96
96
  end
97
97
 
@@ -101,11 +101,11 @@ describe Permissioner::Matchers::ExactlyExpectActions do
101
101
  [:users, [:show, :new, :create]],
102
102
  [:posts, [:show, :edit, :update]]
103
103
  )
104
- matcher.matches?(PermissionService.new).should be_false
104
+ expect(matcher.matches?(PermissionService.new)).to be_falsey
105
105
  end
106
106
  end
107
107
 
108
- describe '#failure_message_for_should' do
108
+ describe '#failure_message' do
109
109
 
110
110
  context 'if controllers did not match' do
111
111
 
@@ -120,7 +120,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
120
120
  "[\"comments\", \"posts\", \"users\"]"
121
121
  #call is necessary because matches sets @permission_service
122
122
  matcher.matches?(permission_service)
123
- matcher.failure_message_for_should.should eq expected_messages
123
+ expect(matcher.failure_message).to eq expected_messages
124
124
  end
125
125
 
126
126
  it 'should work if no controller allowed' do
@@ -130,7 +130,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
130
130
  )
131
131
  #call is necessary because matches sets @permission_service
132
132
  matcher.matches?(PermissionService.new)
133
- matcher.failure_message_for_should.should be_kind_of(String)
133
+ expect(matcher.failure_message).to be_kind_of(String)
134
134
  end
135
135
  end
136
136
 
@@ -152,7 +152,7 @@ describe Permissioner::Matchers::ExactlyExpectActions do
152
152
  "[\"create\", \"new\", \"show\"]\n"
153
153
  #call is necessary because matches sets @permission_service
154
154
  matcher.matches?(permission_service)
155
- matcher.failure_message_for_should.should eq expected_messages
155
+ expect(matcher.failure_message).to eq expected_messages
156
156
  end
157
157
 
158
158
 
@@ -164,24 +164,24 @@ describe Permissioner::Matchers::ExactlyExpectActions do
164
164
  )
165
165
  #call is necessary because matches sets @permission_service
166
166
  matcher.matches?(PermissionService.new)
167
- matcher.failure_message_for_should.should be_kind_of(String)
167
+ expect(matcher.failure_message).to be_kind_of(String)
168
168
  end
169
169
  end
170
170
  end
171
171
 
172
172
 
173
- describe '#failure_message_for_should_not' do
173
+ describe '# failure_message_when_negated' do
174
174
 
175
175
  it 'should be available' do
176
176
  matcher = create_matcher
177
177
  expected_messages = 'given actions are exactly match although this is not expected'
178
- matcher.failure_message_for_should_not.should eq expected_messages
178
+ expect(matcher. failure_message_when_negated).to eq expected_messages
179
179
  end
180
180
 
181
181
  it 'should be available' do
182
182
  matcher = create_matcher
183
183
  matcher.matches?(PermissionService.new)
184
- matcher.failure_message_for_should_not.should be_kind_of(String)
184
+ expect(matcher. failure_message_when_negated).to be_kind_of(String)
185
185
  end
186
186
  end
187
187
 
@@ -13,39 +13,39 @@ describe Permissioner::Matchers do
13
13
  describe '#allow_action' do
14
14
 
15
15
  it 'should delegate call to PermissionService#allow_action? and pass when is returns true' do
16
- permission_service.should_receive(:allow_action?).with(:comments, :index, resource: 'resource', params: 'params').and_return(true)
17
- permission_service.should allow_action :comments, :index, resource: 'resource', params: 'params'
16
+ expect(permission_service).to receive(:allow_action?).with(:comments, :index, resource: 'resource', params: 'params').and_return(true)
17
+ expect(permission_service).to allow_action :comments, :index, resource: 'resource', params: 'params'
18
18
  end
19
19
 
20
20
  it 'should fail when PermissionService#allow_action? returns false' do
21
- permission_service.should_receive(:allow_action?).and_return(false)
22
- permission_service.should_not allow_action
21
+ expect(permission_service).to receive(:allow_action?).and_return(false)
22
+ expect(permission_service).not_to allow_action
23
23
  end
24
24
  end
25
25
 
26
26
  describe '#allow_attribute' do
27
27
 
28
28
  it 'should delegate call to PermissionService#allow_action? and pass when is returns true' do
29
- permission_service.should_receive(:allow_attribute?).with(:comment, :user_id, :text).and_return(true)
30
- permission_service.should allow_attribute :comment, :user_id, :text
29
+ expect(permission_service).to receive(:allow_attribute?).with(:comment, :user_id, :text).and_return(true)
30
+ expect(permission_service).to allow_attribute :comment, :user_id, :text
31
31
  end
32
32
 
33
33
  it 'should fail when PermissionService#allow_action? returns false' do
34
- permission_service.should_receive(:allow_attribute?).and_return(false)
35
- permission_service.should_not allow_attribute
34
+ expect(permission_service).to receive(:allow_attribute?).and_return(false)
35
+ expect(permission_service).not_to allow_attribute
36
36
  end
37
37
  end
38
38
 
39
39
  describe '#pass_filters' do
40
40
 
41
41
  it 'should delegate call to PermissionService#passed_filters? and pass when is returns true' do
42
- permission_service.should_receive(:passed_filters?).with(:comment, :user_id, resource: 'resource', params: 'params').and_return(true)
43
- permission_service.should pass_filters :comment, :user_id, resource: 'resource', params: 'params'
42
+ expect(permission_service).to receive(:passed_filters?).with(:comment, :user_id, resource: 'resource', params: 'params').and_return(true)
43
+ expect(permission_service).to pass_filters :comment, :user_id, resource: 'resource', params: 'params'
44
44
  end
45
45
 
46
46
  it 'should fail when PermissionService#passed_filters? returns false' do
47
- permission_service.should_receive(:passed_filters?).and_return(false)
48
- permission_service.should_not pass_filters
47
+ expect(permission_service).to receive(:passed_filters?).and_return(false)
48
+ expect(permission_service).not_to pass_filters
49
49
  end
50
50
  end
51
51
 
@@ -53,8 +53,8 @@ describe Permissioner::Matchers do
53
53
 
54
54
  it 'should return correctly instantiated instance of ExactlyExpectActions' do
55
55
  expected_actions = [:controller_1, :actions_1], [:controller_2, :actions_2]
56
- Permissioner::Matchers::ExactlyExpectActions.should_receive(:new).with(:@allowed_actions, *expected_actions).and_call_original
57
- matcher_helper.exactly_allow_actions(*expected_actions).should be_kind_of(Permissioner::Matchers::ExactlyExpectActions)
56
+ expect(Permissioner::Matchers::ExactlyExpectActions).to receive(:new).with(:@allowed_actions, *expected_actions).and_call_original
57
+ expect(matcher_helper.exactly_allow_actions(*expected_actions)).to be_kind_of(Permissioner::Matchers::ExactlyExpectActions)
58
58
  end
59
59
  end
60
60
 
@@ -62,8 +62,8 @@ describe Permissioner::Matchers do
62
62
 
63
63
  it 'should return correctly instantiated instance of ExactlyExpectActions' do
64
64
  expected_actions = [:controller_1, :actions_1], [:controller_2, :actions_2]
65
- Permissioner::Matchers::ExactlyExpectActions.should_receive(:new).with(:@filters, *expected_actions).and_call_original
66
- matcher_helper.exactly_have_filters_for(*expected_actions).should be_kind_of(Permissioner::Matchers::ExactlyExpectActions)
65
+ expect(Permissioner::Matchers::ExactlyExpectActions).to receive(:new).with(:@filters, *expected_actions).and_call_original
66
+ expect(matcher_helper.exactly_have_filters_for(*expected_actions)).to be_kind_of(Permissioner::Matchers::ExactlyExpectActions)
67
67
  end
68
68
  end
69
69
 
@@ -71,24 +71,24 @@ describe Permissioner::Matchers do
71
71
 
72
72
  it 'should return correctly instantiated instance of ExactlyAllowAttributes' do
73
73
  expected_attributes = [:resource_1, :attribute_1], [:resource_2, :attribute_2]
74
- Permissioner::Matchers::ExactlyAllowAttributes.should_receive(:new).with(*expected_attributes).and_call_original
75
- matcher_helper.exactly_allow_attributes(*expected_attributes).should be_kind_of(Permissioner::Matchers::ExactlyAllowAttributes)
74
+ expect(Permissioner::Matchers::ExactlyAllowAttributes).to receive(:new).with(*expected_attributes).and_call_original
75
+ expect(matcher_helper.exactly_allow_attributes(*expected_attributes)).to be_kind_of(Permissioner::Matchers::ExactlyAllowAttributes)
76
76
  end
77
77
  end
78
78
 
79
79
  describe '#exactly_allow_controllers' do
80
80
 
81
81
  it 'should return correctly instantiated instance of ExactlyAllowControllers' do
82
- Permissioner::Matchers::ExactlyAllowControllers.should_receive(:new).with(:controller_1, :controller_2).and_call_original
83
- matcher_helper.exactly_allow_controllers(:controller_1, :controller_2).should be_kind_of(Permissioner::Matchers::ExactlyAllowControllers)
82
+ expect(Permissioner::Matchers::ExactlyAllowControllers).to receive(:new).with(:controller_1, :controller_2).and_call_original
83
+ expect(matcher_helper.exactly_allow_controllers(:controller_1, :controller_2)).to be_kind_of(Permissioner::Matchers::ExactlyAllowControllers)
84
84
  end
85
85
  end
86
86
 
87
87
  describe '#exactly_allow_resources' do
88
88
 
89
89
  it 'should return correctly instantiated instance of ExactlyAllowControllers' do
90
- Permissioner::Matchers::ExactlyAllowResources.should_receive(:new).with(:resource_1, :resource_2).and_call_original
91
- matcher_helper.exactly_allow_resources(:resource_1, :resource_2).should be_kind_of(Permissioner::Matchers::ExactlyAllowResources)
90
+ expect(Permissioner::Matchers::ExactlyAllowResources).to receive(:new).with(:resource_1, :resource_2).and_call_original
91
+ expect(matcher_helper.exactly_allow_resources(:resource_1, :resource_2)).to be_kind_of(Permissioner::Matchers::ExactlyAllowResources)
92
92
  end
93
93
  end
94
94
 
@@ -13,13 +13,13 @@ describe Permissioner::ServiceAdditions do
13
13
  describe '#initialize' do
14
14
 
15
15
  it 'should call configure_permissions' do
16
- permission_service_class.any_instance.should_receive(:configure_permissions).once
16
+ expect_any_instance_of(permission_service_class).to receive(:configure_permissions).once
17
17
  permission_service_class.new
18
18
  end
19
19
 
20
20
  it 'should set current_user' do
21
21
  permission_service = permission_service_class.new 'current_user'
22
- permission_service.current_user.should eq 'current_user'
22
+ expect(permission_service.current_user).to eq 'current_user'
23
23
  end
24
24
  end
25
25
 
@@ -29,21 +29,21 @@ describe Permissioner::ServiceAdditions do
29
29
 
30
30
  it 'should return true if action is allowed' do
31
31
  permission_service.allow_actions :comments, :index
32
- permission_service.allow_action?(:comments, :index).should be_true
32
+ expect(permission_service.allow_action?(:comments, :index)).to be_truthy
33
33
  end
34
34
 
35
35
  it 'should return true for every action if all actions of controller are allowed' do
36
36
  permission_service.allow_actions :comments, :all
37
- permission_service.allow_action?(:comments, :index).should be_true
37
+ expect(permission_service.allow_action?(:comments, :index)).to be_truthy
38
38
  end
39
39
 
40
40
  it 'should return true if allow_all is true' do
41
41
  permission_service.allow_all
42
- permission_service.allow_action?(:comments, :index).should be_true
42
+ expect(permission_service.allow_action?(:comments, :index)).to be_truthy
43
43
  end
44
44
 
45
45
  it 'should return false if actions is not allowed' do
46
- permission_service.allow_action?(:comments, :index).should be_false
46
+ expect(permission_service.allow_action?(:comments, :index)).to be_falsey
47
47
  end
48
48
  end
49
49
 
@@ -52,48 +52,48 @@ describe Permissioner::ServiceAdditions do
52
52
  it 'should return true if action is allowed and all filters return true' do
53
53
  permission_service.allow_actions :comments, :index, &Proc.new { true }
54
54
  permission_service.add_filter :comments, :index, &Proc.new { true }
55
- permission_service.allow_action?(:comments, :index).should be_true
55
+ expect(permission_service.allow_action?(:comments, :index)).to be_truthy
56
56
  end
57
57
 
58
58
  it 'should return true for every action if all actions of controller are allowed and filters return true' do
59
59
  permission_service.allow_actions :comments, :all
60
60
  permission_service.add_filter :comments, :index, &Proc.new { true }
61
- permission_service.allow_action?(:comments, :index).should be_true
61
+ expect(permission_service.allow_action?(:comments, :index)).to be_truthy
62
62
  end
63
63
 
64
64
  it 'should return true if allow_all is true but filters return false' do
65
65
  permission_service.allow_all
66
66
  permission_service.allow_actions :comments, :index, &Proc.new { false }
67
67
  permission_service.add_filter :comments, :index, &Proc.new { false }
68
- permission_service.allow_action?(:comments, :index).should be_true
68
+ expect(permission_service.allow_action?(:comments, :index)).to be_truthy
69
69
  end
70
70
 
71
71
  it 'should return false if given action allowed but filters return false' do
72
72
  permission_service.allow_actions :comments, :index, &Proc.new { false }
73
- permission_service.allow_action?(:comments, :index).should be_false
73
+ expect(permission_service.allow_action?(:comments, :index)).to be_falsey
74
74
  end
75
75
 
76
76
  it 'should return false if given action allowed but at least one filter returns false' do
77
77
  permission_service.allow_actions :comments, :index, &Proc.new { true }
78
78
  permission_service.add_filter :comments, :index, &Proc.new { false }
79
- permission_service.allow_action?(:comments, :index).should be_false
79
+ expect(permission_service.allow_action?(:comments, :index)).to be_falsey
80
80
  end
81
81
 
82
82
  it 'should return false for every action if all actions of controller are allowed but filters return false' do
83
83
  permission_service.allow_actions :comments, :all
84
84
  permission_service.add_filter :comments, :index, &Proc.new { false }
85
- permission_service.allow_action?(:comments, :index).should be_false
85
+ expect(permission_service.allow_action?(:comments, :index)).to be_falsey
86
86
  end
87
87
  end
88
88
 
89
89
  it 'should also except arguments as string' do
90
90
  permission_service.allow_actions :comments, :index
91
- permission_service.allow_action?('comments', 'index').should be_true
91
+ expect(permission_service.allow_action?('comments', 'index')).to be_truthy
92
92
  end
93
93
 
94
94
  it 'should pass arguments to passed_filters? if action is principally allowed' do
95
95
  permission_service.allow_actions :comments, :index
96
- permission_service.should_receive(:passed_filters?).with(:comments, :index, resource: :resource, params: :params)
96
+ expect(permission_service).to receive(:passed_filters?).with(:comments, :index, resource: :resource, params: :params)
97
97
  permission_service.allow_action?(:comments, :index, resource: :resource, params: :params)
98
98
  end
99
99
  end
@@ -102,51 +102,51 @@ describe Permissioner::ServiceAdditions do
102
102
 
103
103
  it 'should return true when all blocks for given controller and action returns true' do
104
104
  permission_service.add_filter(:comments, :create, &Proc.new { true })
105
- permission_service.passed_filters?(:comments, :create).should be_true
105
+ expect(permission_service.passed_filters?(:comments, :create)).to be_truthy
106
106
  end
107
107
 
108
108
  it 'should return true when no filters are added at all' do
109
- permission_service.passed_filters?(:comments, :create).should be_true
109
+ expect(permission_service.passed_filters?(:comments, :create)).to be_truthy
110
110
  end
111
111
 
112
112
  it 'should return true when for given controller and action no filters has been added' do
113
113
  permission_service.add_filter(:comments, :update, &Proc.new {})
114
- permission_service.passed_filters?(:comments, :create).should be_true
114
+ expect(permission_service.passed_filters?(:comments, :create)).to be_truthy
115
115
  end
116
116
 
117
117
  it 'should return false when at least one block for given controller and action returns false' do
118
118
  permission_service.add_filter(:comments, :create, &Proc.new { true })
119
119
  permission_service.add_filter(:comments, :create, &Proc.new { false })
120
120
  permission_service.add_filter(:comments, :create, &Proc.new { true })
121
- permission_service.passed_filters?(:comments, :create).should be_false
121
+ expect(permission_service.passed_filters?(:comments, :create)).to be_falsey
122
122
  end
123
123
 
124
124
  it 'should pass resource to the given block' do
125
125
  resource = Object.new
126
- permission_service.add_filter(:comments, :create, &Proc.new { |r, p| r.should be resource })
126
+ permission_service.add_filter(:comments, :create, &Proc.new { |r, p| expect(r).to be resource })
127
127
  permission_service.passed_filters?(:comments, :create, resource: resource)
128
128
  end
129
129
 
130
130
  it 'should pass params to the given block' do
131
131
  params = Object.new
132
- permission_service.add_filter(:comments, :create, &Proc.new { |r, p| p.should be params })
132
+ permission_service.add_filter(:comments, :create, &Proc.new { |r, p| expect(p).to be params })
133
133
  permission_service.passed_filters?(:comments, :create, params: params)
134
134
  end
135
135
 
136
136
  it 'should set params to {} if not given' do
137
- permission_service.add_filter(:comments, :create, &Proc.new { |r, p| p.should eq({}) })
137
+ permission_service.add_filter(:comments, :create, &Proc.new { |r, p| expect(p).to eq({}) })
138
138
  permission_service.passed_filters?(:comments, :create)
139
139
  end
140
140
 
141
141
  it 'should set params to {} if nil' do
142
- permission_service.add_filter(:comments, :create, &Proc.new { |r, p| p.should eq({}) })
142
+ permission_service.add_filter(:comments, :create, &Proc.new { |r, p| expect(p).to eq({}) })
143
143
  permission_service.passed_filters?(:comments, :create, params: nil)
144
144
  end
145
145
 
146
146
  it 'should set default values for params and current resource' do
147
147
  block = Proc.new do |current_resource, params|
148
- current_resource.should be_nil
149
- params.should eq({})
148
+ expect(current_resource).to be_nil
149
+ expect(params).to eq({})
150
150
  end
151
151
  permission_service.add_filter(:comments, :create, &block)
152
152
  permission_service.passed_filters?(:comments, :create)
@@ -157,16 +157,16 @@ describe Permissioner::ServiceAdditions do
157
157
 
158
158
  it 'should return true when @allow_all is true' do
159
159
  permission_service.allow_all
160
- permission_service.allow_attribute?(:comment, :user_id).should be_true
160
+ expect(permission_service.allow_attribute?(:comment, :user_id)).to be_truthy
161
161
  end
162
162
 
163
163
  it 'should return true when attribute is allowed' do
164
164
  permission_service.allow_attributes(:comment, :user_id)
165
- permission_service.allow_attribute?(:comment, :user_id).should be_true
165
+ expect(permission_service.allow_attribute?(:comment, :user_id)).to be_truthy
166
166
  end
167
167
 
168
168
  it 'should return false when attribute not allowed' do
169
- permission_service.allow_attribute?(:comment, :user_id).should be_false
169
+ expect(permission_service.allow_attribute?(:comment, :user_id)).to be_falsey
170
170
  end
171
171
  end
172
172
 
@@ -176,7 +176,7 @@ describe Permissioner::ServiceAdditions do
176
176
 
177
177
  it 'should call permit! on given params when @allow_all is true' do
178
178
  params = double('params')
179
- params.should_receive(:permit!)
179
+ expect(params).to receive(:permit!)
180
180
  permission_service.allow_all
181
181
  permission_service.permit_params!(params)
182
182
  end
@@ -195,11 +195,11 @@ describe Permissioner::ServiceAdditions do
195
195
 
196
196
  permission_service.permit_params!(params)
197
197
 
198
- params[:comment].should be_permitted
199
- params[:comment].should include :user_id, :text
200
- params[:comment].should_not include :date
201
- params[:post].should be_permitted
202
- params[:post].should include :title, :content
198
+ expect(params[:comment]).to be_permitted
199
+ expect(params[:comment]).to include :user_id, :text
200
+ expect(params[:comment]).not_to include :date
201
+ expect(params[:post]).to be_permitted
202
+ expect(params[:post]).to include :title, :content
203
203
  end
204
204
  end
205
205
 
@@ -209,7 +209,7 @@ describe Permissioner::ServiceAdditions do
209
209
 
210
210
  it 'should set @allow_all to true' do
211
211
  permission_service.allow_all
212
- permission_service.instance_variable_get(:@allow_all).should be_true
212
+ expect(permission_service.instance_variable_get(:@allow_all)).to be_truthy
213
213
  end
214
214
  end
215
215
 
@@ -220,24 +220,24 @@ describe Permissioner::ServiceAdditions do
220
220
  it 'should add actions to @allowed_actions when one action is given' do
221
221
  permission_service.allow_actions :comments, :index
222
222
  allowed_actions = permission_service.instance_variable_get(:@allowed_actions)
223
- allowed_actions.count.should eq 1
224
- allowed_actions[['comments', 'index']].should be_true
223
+ expect(allowed_actions.count).to eq 1
224
+ expect(allowed_actions[['comments', 'index']]).to be_truthy
225
225
  end
226
226
 
227
227
  it 'should add actions to @allowed_actions when multiple actions are given' do
228
228
  permission_service.allow_actions([:comments, :users], [:index, :create])
229
229
  allowed_actions = permission_service.instance_variable_get(:@allowed_actions)
230
- allowed_actions.count.should eq 4
231
- allowed_actions[['comments', 'index']].should be_true
232
- allowed_actions[['comments', 'create']].should be_true
233
- allowed_actions[['users', 'index']].should be_true
234
- allowed_actions[['users', 'create']].should be_true
230
+ expect(allowed_actions.count).to eq 4
231
+ expect(allowed_actions[['comments', 'index']]).to be_truthy
232
+ expect(allowed_actions[['comments', 'create']]).to be_truthy
233
+ expect(allowed_actions[['users', 'index']]).to be_truthy
234
+ expect(allowed_actions[['users', 'create']]).to be_truthy
235
235
  end
236
236
 
237
237
  it 'should not add any filters' do
238
238
  permission_service.allow_actions :comments, :index
239
239
  filters = permission_service.instance_variable_get(:@filters)
240
- filters.count.should eq 0
240
+ expect(filters.count).to eq 0
241
241
  end
242
242
  end
243
243
 
@@ -247,19 +247,19 @@ describe Permissioner::ServiceAdditions do
247
247
  block = Proc.new {}
248
248
  permission_service.allow_actions :comments, :index, &block
249
249
  filters = permission_service.instance_variable_get(:@filters)
250
- filters.count.should eq 1
251
- filters[['comments', 'index']].should eq [block]
250
+ expect(filters.count).to eq 1
251
+ expect(filters[['comments', 'index']]).to eq [block]
252
252
  end
253
253
 
254
254
  it 'should add block to @filters when multiple actions are given' do
255
255
  block = Proc.new {}
256
256
  permission_service.allow_actions([:comments, :users], [:index, :create], &block)
257
257
  filters = permission_service.instance_variable_get(:@filters)
258
- filters.count.should eq 4
259
- filters[['comments', 'index']].should eq [block]
260
- filters[['comments', 'create']].should eq [block]
261
- filters[['users', 'index']].should eq [block]
262
- filters[['users', 'create']].should eq [block]
258
+ expect(filters.count).to eq 4
259
+ expect(filters[['comments', 'index']]).to eq [block]
260
+ expect(filters[['comments', 'create']]).to eq [block]
261
+ expect(filters[['users', 'index']]).to eq [block]
262
+ expect(filters[['users', 'create']]).to eq [block]
263
263
  end
264
264
 
265
265
  it 'should add multiple blocks to @filters fore every actions' do
@@ -268,15 +268,15 @@ describe Permissioner::ServiceAdditions do
268
268
  permission_service.allow_actions :comments, :index, &block_1
269
269
  permission_service.allow_actions :comments, :index, &block_2
270
270
  filters = permission_service.instance_variable_get(:@filters)
271
- filters.count.should eq 1
272
- filters[['comments', 'index']].should eq [block_1, block_2]
271
+ expect(filters.count).to eq 1
272
+ expect(filters[['comments', 'index']]).to eq [block_1, block_2]
273
273
  end
274
274
 
275
275
  it 'should add actions to @allowed_actions' do
276
276
  permission_service.allow_actions :comments, :index, &Proc.new {}
277
277
  allowed_actions = permission_service.instance_variable_get(:@allowed_actions)
278
- allowed_actions.count.should eq 1
279
- allowed_actions[['comments', 'index']].should be_true
278
+ expect(allowed_actions.count).to eq 1
279
+ expect(allowed_actions[['comments', 'index']]).to be_truthy
280
280
  end
281
281
 
282
282
  it 'should raise error if block is given for all actions' do
@@ -296,23 +296,23 @@ describe Permissioner::ServiceAdditions do
296
296
  it 'should add resource and attribute to @allowed_params' do
297
297
  permission_service.allow_attributes :comment, :text
298
298
  allowed_params = permission_service.instance_variable_get(:@allowed_attributes)
299
- allowed_params.count.should eq 1
300
- allowed_params[:comment].should eq [:text]
299
+ expect(allowed_params.count).to eq 1
300
+ expect(allowed_params[:comment]).to eq [:text]
301
301
  end
302
302
 
303
303
  it 'should add resource and attributes to @allowed_params if multiple given' do
304
304
  permission_service.allow_attributes [:comment, :post], [:user, :text]
305
305
  allowed_params = permission_service.instance_variable_get(:@allowed_attributes)
306
- allowed_params.count.should eq 2
307
- allowed_params[:comment].should eq [:user, :text]
308
- allowed_params[:post].should eq [:user, :text]
306
+ expect(allowed_params.count).to eq 2
307
+ expect(allowed_params[:comment]).to eq [:user, :text]
308
+ expect(allowed_params[:post]).to eq [:user, :text]
309
309
  end
310
310
 
311
311
  it 'should add resource and attributes to @allowed_params if attributes is a Hash' do
312
312
  permission_service.allow_attributes :comment, {attributes: [:user, :text]}
313
313
  allowed_params = permission_service.instance_variable_get(:@allowed_attributes)
314
- allowed_params.count.should eq 1
315
- allowed_params[:comment].should eq [{attributes: [:user, :text]}]
314
+ expect(allowed_params.count).to eq 1
315
+ expect(allowed_params[:comment]).to eq [{attributes: [:user, :text]}]
316
316
  end
317
317
  end
318
318
 
@@ -322,17 +322,17 @@ describe Permissioner::ServiceAdditions do
322
322
  block = Proc.new {}
323
323
  permission_service.add_filter(:comments, :create, &block)
324
324
  filter_list = permission_service.instance_variable_get(:@filters)[['comments', 'create']]
325
- filter_list.count.should eq 1
326
- filter_list.should include block
325
+ expect(filter_list.count).to eq 1
326
+ expect(filter_list).to include block
327
327
  end
328
328
 
329
329
  it 'should add given block to @filters addressed by controller and action when multiple given' do
330
330
  block = Proc.new {}
331
331
  permission_service.add_filter([:comments, :posts], [:create, :update], &block)
332
- permission_service.instance_variable_get(:@filters)[['comments', 'create']].should include block
333
- permission_service.instance_variable_get(:@filters)[['comments', 'update']].should include block
334
- permission_service.instance_variable_get(:@filters)[['posts', 'create']].should include block
335
- permission_service.instance_variable_get(:@filters)[['posts', 'update']].should include block
332
+ expect(permission_service.instance_variable_get(:@filters)[['comments', 'create']]).to include block
333
+ expect(permission_service.instance_variable_get(:@filters)[['comments', 'update']]).to include block
334
+ expect(permission_service.instance_variable_get(:@filters)[['posts', 'create']]).to include block
335
+ expect(permission_service.instance_variable_get(:@filters)[['posts', 'update']]).to include block
336
336
  end
337
337
 
338
338
  it 'should add multiple blocks to @filters addressed by controller and action' do
@@ -341,9 +341,9 @@ describe Permissioner::ServiceAdditions do
341
341
  permission_service.add_filter(:comments, :create, &block_1)
342
342
  permission_service.add_filter(:comments, :create, &block_2)
343
343
  filter_list = permission_service.instance_variable_get(:@filters)[['comments', 'create']]
344
- filter_list.count.should eq 2
345
- filter_list.should include block_1
346
- filter_list.should include block_2
344
+ expect(filter_list.count).to eq 2
345
+ expect(filter_list).to include block_1
346
+ expect(filter_list).to include block_2
347
347
  end
348
348
 
349
349
  it 'should rails exception when no block given' do
@@ -370,14 +370,14 @@ describe Permissioner::ServiceAdditions do
370
370
  it 'should delete filters for actions if one controller and action are given' do
371
371
  permission_service.clear_filters :users, :edit
372
372
  filters = permission_service.instance_variable_get(:@filters)
373
- filters.count.should eq 3
374
- filters.should_not have_key([:users, :edit])
373
+ expect(filters.count).to eq 3
374
+ expect(filters).not_to have_key([:users, :edit])
375
375
  end
376
376
 
377
377
  it 'should delete filters for actions if multiple controllers and actions are given' do
378
378
  permission_service.clear_filters [:users, :comments], [:edit, :update]
379
379
  filters = permission_service.instance_variable_get(:@filters)
380
- filters.should be_empty
380
+ expect(filters).to be_empty
381
381
  end
382
382
 
383
383
  end
@@ -386,18 +386,18 @@ describe Permissioner::ServiceAdditions do
386
386
 
387
387
  it 'should set @filters to nil' do
388
388
  permission_service.add_filter(:comments, :create, &Proc.new {})
389
- permission_service.instance_variable_get(:@filters).should_not be_nil
389
+ expect(permission_service.instance_variable_get(:@filters)).not_to be_nil
390
390
  permission_service.clear_all_filters
391
- permission_service.instance_variable_get(:@filters).should be_nil
391
+ expect(permission_service.instance_variable_get(:@filters)).to be_nil
392
392
  end
393
393
  end
394
394
 
395
395
  describe '#configure' do
396
396
 
397
397
  it 'should create new instance of given configurer class' do
398
- permission_service.stub(:current_user).and_return('current_user')
398
+ allow(permission_service).to receive(:current_user).and_return('current_user')
399
399
  configurer_class = double('permission_configurer')
400
- configurer_class.should_receive(:new).with(permission_service, 'current_user')
400
+ expect(configurer_class).to receive(:new).with(permission_service, 'current_user')
401
401
  permission_service.configure(configurer_class)
402
402
  end
403
403
  end