spec/authority/authorizer_spec.rb in authority-3.0.0 vs spec/authority/authorizer_spec.rb in authority-3.1.0
- old
+ new
@@ -11,10 +11,24 @@
expect(authorizer.resource).to eq(model_instance)
end
describe "instance methods" do
+ it "calls the instance default method if no instance method is defined" do
+ expect(authorizer).to receive(:default)
+ authorizer.creatable_by?(user)
+ end
+
+ context "the instance default method" do
+
+ it "delegates to the class default method" do
+ expect(authorizer.class).to receive(:default)
+ authorizer.default(:creatable, user)
+ end
+
+ end
+
Authority.adjectives.each do |adjective|
method_name = "#{adjective}_by?"
it "responds to `#{method_name}`" do
expect(authorizer).to respond_to(method_name)
@@ -23,20 +37,20 @@
describe "#{method_name}" do
context "when given an options hash" do
it "delegates `#{method_name}` to the corresponding class method, passing the options" do
- authorizer.class.should_receive(method_name).with(user, :under => 'God')
+ expect(authorizer.class).to receive(method_name).with(user, :under => 'God')
authorizer.send(method_name, user, :under => 'God')
end
end
context "when not given an options hash" do
it "delegates `#{method_name}` to the corresponding class method, passing no options" do
- authorizer.class.should_receive(method_name).with(user)
+ expect(authorizer.class).to receive(method_name).with(user)
authorizer.send(method_name, user)
end
end
@@ -59,21 +73,21 @@
context "when given an options hash" do
it "delegates `#{method_name}` to the authorizer's `default` method, passing the options" do
able = method_name.sub('_by?', '').to_sym
- Authority::Authorizer.should_receive(:default).with(able, user, :with => 'gusto')
+ expect(Authority::Authorizer).to receive(:default).with(able, user, :with => 'gusto')
Authority::Authorizer.send(method_name, user, :with => 'gusto')
end
end
context "when not given an options hash" do
it "delegates `#{method_name}` to the authorizer's `default` method, passing no options" do
able = method_name.sub('_by?', '').to_sym
- Authority::Authorizer.should_receive(:default).with(able, user)
+ expect(Authority::Authorizer).to receive(:default).with(able, user)
Authority::Authorizer.send(method_name, user)
end
end
@@ -86,17 +100,17 @@
describe "the default method" do
context "when given an options hash" do
it "returns false" do
- expect(Authority::Authorizer.default(:implodable, user, {:for => "my_object"})).to be_false
+ expect(Authority::Authorizer.default(:implodable, user, {:for => "my_object"})).to eq(false)
end
end
context "when not given an options hash" do
it "returns false" do
- expect(Authority::Authorizer.default(:implodable, user)).to be_false
+ expect(Authority::Authorizer.default(:implodable, user)).to eq(false)
end
end
end