spec/access_rules_spec.rb in tuersteher-0.6.7 vs spec/access_rules_spec.rb in tuersteher-0.7.0
- old
+ new
@@ -11,77 +11,77 @@
PathAccessRule.new('/admin').role(:admin),
PathAccessRule.new('/images').method(:get),
PathAccessRule.new('/status').method(:get).role(:system)
]
AccessRulesStorage.instance.stub(:path_rules).and_return(rules)
- @user = stub('user')
+ @user = double('user')
end
context "User with role :user" do
before do
@user.stub(:has_role?){|role| role==:user}
end
it "should be true for this paths" do
- AccessRules.path_access?(@user, '/', :get).should be_true
- AccessRules.path_access?(@user, '/', :post).should be_true
- AccessRules.path_access?(@user, '/images', :get).should be_true
+ AccessRules.path_access?(@user, '/', :get).should be_truthy
+ AccessRules.path_access?(@user, '/', :post).should be_truthy
+ AccessRules.path_access?(@user, '/images', :get).should be_truthy
end
it "should not be true for this paths" do
- AccessRules.path_access?(@user, '/admin', :get).should_not be_true
- AccessRules.path_access?(@user, '/images', :post).should_not be_true
- AccessRules.path_access?(@user, '/status', :get).should_not be_true
+ AccessRules.path_access?(@user, '/admin', :get).should_not be_truthy
+ AccessRules.path_access?(@user, '/images', :post).should_not be_truthy
+ AccessRules.path_access?(@user, '/status', :get).should_not be_truthy
end
end
context "User with role :admin" do
before do
@user.stub(:has_role?){|role| role==:admin}
end
it "should be true for this paths" do
- AccessRules.path_access?(@user, '/', :get).should be_true
- AccessRules.path_access?(@user, '/admin', :post).should be_true
- AccessRules.path_access?(@user, '/images', :get).should be_true
+ AccessRules.path_access?(@user, '/', :get).should be_truthy
+ AccessRules.path_access?(@user, '/admin', :post).should be_truthy
+ AccessRules.path_access?(@user, '/images', :get).should be_truthy
end
it "should not be true for this paths" do
- AccessRules.path_access?(@user, '/xyz', :get).should_not be_true
- AccessRules.path_access?(@user, '/images', :post).should_not be_true
- AccessRules.path_access?(@user, '/status', :get).should_not be_true
+ AccessRules.path_access?(@user, '/xyz', :get).should_not be_truthy
+ AccessRules.path_access?(@user, '/images', :post).should_not be_truthy
+ AccessRules.path_access?(@user, '/status', :get).should_not be_truthy
end
end
context "User with role :system" do
before do
@user.stub(:has_role?){|role| role==:system}
end
it "should be true for this paths" do
- AccessRules.path_access?(@user, '/', :get).should be_true
- AccessRules.path_access?(@user, '/status', :get).should be_true
+ AccessRules.path_access?(@user, '/', :get).should be_truthy
+ AccessRules.path_access?(@user, '/status', :get).should be_truthy
end
it "should not be true for this paths" do
- AccessRules.path_access?(@user, '/xyz', :get).should_not be_true
- AccessRules.path_access?(@user, '/admin', :post).should_not be_true
+ AccessRules.path_access?(@user, '/xyz', :get).should_not be_truthy
+ AccessRules.path_access?(@user, '/admin', :post).should_not be_truthy
end
end
context "without user" do
it "should be true for this paths" do
- AccessRules.path_access?(nil, '/', :get).should be_true
+ AccessRules.path_access?(nil, '/', :get).should be_truthy
end
it "should not be true for this paths" do
- AccessRules.path_access?(nil, '/xyz', :get).should_not be_true
- AccessRules.path_access?(nil, '/admin', :post).should_not be_true
+ AccessRules.path_access?(nil, '/xyz', :get).should_not be_truthy
+ AccessRules.path_access?(nil, '/admin', :post).should_not be_truthy
end
end
end
@@ -98,11 +98,11 @@
ModelAccessRule.new(SampleModel2).grant.method(:update).role(:user).extension(:owner?),
ModelAccessRule.new(SampleModel2).deny.method(:create),
ModelAccessRule.new(SampleModel2).grant.method(:all).role(:admin),
]
AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
- @user = stub('user')
+ @user = double('user')
@model1 = SampleModel1.new
@model2 = SampleModel2.new
@model2.stub(:owner?).and_return(false)
end
@@ -111,65 +111,65 @@
before do
@user.stub(:has_role?){|role| role==:user}
end
it "should be true for this" do
- AccessRules.model_access?(@user, @model1, :xyz).should be_true
+ AccessRules.model_access?(@user, @model1, :xyz).should be_truthy
@model2.stub(:owner?).and_return true
- AccessRules.model_access?(@user, @model2, :read).should be_true
- AccessRules.model_access?(@user, @model2, :update).should be_true
+ AccessRules.model_access?(@user, @model2, :read).should be_truthy
+ AccessRules.model_access?(@user, @model2, :update).should be_truthy
end
it "should not be true for this" do
- AccessRules.model_access?(@user, @model2, :update).should_not be_true
- AccessRules.model_access?(@user, @model2, :delete).should_not be_true
+ AccessRules.model_access?(@user, @model2, :update).should_not be_truthy
+ AccessRules.model_access?(@user, @model2, :delete).should_not be_truthy
end
end
context "User with role :admin" do
before do
@user.stub(:has_role?){|role| role==:admin}
end
it "should be true for this" do
- AccessRules.model_access?(@user, @model1, :xyz).should be_true
- AccessRules.model_access?(@user, @model2, :read).should be_true
- AccessRules.model_access?(@user, @model2, :update).should be_true
- AccessRules.model_access?(@user, @model2, :delete).should be_true
+ AccessRules.model_access?(@user, @model1, :xyz).should be_truthy
+ AccessRules.model_access?(@user, @model2, :read).should be_truthy
+ AccessRules.model_access?(@user, @model2, :update).should be_truthy
+ AccessRules.model_access?(@user, @model2, :delete).should be_truthy
end
it "should not be true for this" do
- AccessRules.model_access?(@user, @model2, :create).should_not be_true
+ AccessRules.model_access?(@user, @model2, :create).should_not be_truthy
end
end
context "User with role :sysadmin" do
before do
@user.stub(:has_role?){|role| role==:sysadmin}
end
it "should be true for this" do
- AccessRules.model_access?(@user, "test", :xyz).should be_true
- AccessRules.model_access?(@user, @model1, :xyz).should be_true
- AccessRules.model_access?(@user, @model2, :read).should be_true
- AccessRules.model_access?(@user, @model2, :update).should be_true
- AccessRules.model_access?(@user, @model2, :delete).should be_true
- AccessRules.model_access?(@user, @model2, :create).should be_true
+ AccessRules.model_access?(@user, "test", :xyz).should be_truthy
+ AccessRules.model_access?(@user, @model1, :xyz).should be_truthy
+ AccessRules.model_access?(@user, @model2, :read).should be_truthy
+ AccessRules.model_access?(@user, @model2, :update).should be_truthy
+ AccessRules.model_access?(@user, @model2, :delete).should be_truthy
+ AccessRules.model_access?(@user, @model2, :create).should be_truthy
end
end
context "without user" do
it "should be true for this models" do
- AccessRules.model_access?(nil, @model1, :xyz).should be_true
- AccessRules.model_access?(nil, @model2, :read).should be_true
+ AccessRules.model_access?(nil, @model1, :xyz).should be_truthy
+ AccessRules.model_access?(nil, @model2, :read).should be_truthy
end
it "should not be true for this models" do
- AccessRules.model_access?(nil, @model2, :update).should_not be_true
+ AccessRules.model_access?(nil, @model2, :update).should_not be_truthy
end
end
end # of context 'model_access?'
@@ -184,10 +184,10 @@
rules = [
ModelAccessRule.new(SampleModel).method(:update).role(:admin),
ModelAccessRule.new(SampleModel).method(:update).role(:user).extension(:owner?),
]
AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
- @user = stub('user')
+ @user = double('user')
@model1 = SampleModel.new
@model2 = SampleModel.new
@model3 = SampleModel.new
@model3.stub(:owner?).and_return(true)
@collection = [@model1, @model2, @model3]