Skip to content

Commit

Permalink
new rule specification right now works
Browse files Browse the repository at this point in the history
refac rspec's
  • Loading branch information
bledig-osp committed Aug 15, 2014
1 parent 4611410 commit 5999c3e
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 122 deletions.
14 changes: 0 additions & 14 deletions Gemfile.lock

This file was deleted.

4 changes: 2 additions & 2 deletions spec/acces_rules_storage_spec.rb
Expand Up @@ -31,11 +31,11 @@ class Todo; end
end

specify do
@path_rules.should have(5).items
expect(@path_rules.size).to eq(5)
end

specify do
@model_rules.should have(4).items
expect(@model_rules.size).to eq(4)
end

specify do
Expand Down
82 changes: 41 additions & 41 deletions spec/access_rules_spec.rb
Expand Up @@ -13,7 +13,7 @@ module Tuersteher
PathAccessRule.new('/status').method(:get).role(:system)
]
AccessRulesStorage.instance.stub(:path_rules).and_return(rules)
@user = stub('user')
@user = double('user')
end


Expand All @@ -23,15 +23,15 @@ module Tuersteher
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

Expand All @@ -42,15 +42,15 @@ module Tuersteher
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

Expand All @@ -61,25 +61,25 @@ module Tuersteher
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
Expand All @@ -100,7 +100,7 @@ class SampleModel2; end
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)
Expand All @@ -113,15 +113,15 @@ class SampleModel2; end
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

Expand All @@ -132,14 +132,14 @@ class SampleModel2; end
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

Expand All @@ -150,24 +150,24 @@ class SampleModel2; end
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?'
Expand All @@ -186,7 +186,7 @@ def owner?(user); false; end
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
Expand Down
32 changes: 16 additions & 16 deletions spec/model_access_rule_spec.rb
Expand Up @@ -10,12 +10,12 @@ module Tuersteher
end

it "should fired without user" do
@rule.fired?("test", :read, nil).should be_true
@rule.fired?("test", :read, nil).should be_truthy
end

it "should fired with user" do
@user = stub('user')
@rule.fired?("test", :read, @user).should be_true
@user = double('user')
@rule.fired?("test", :read, @user).should be_truthy
end
end

Expand All @@ -28,67 +28,67 @@ module Tuersteher

context "for User with role :admin" do
before do
@user = stub('user')
@user = double('user')
@user.stub(:has_role?) { |role| role==:admin }
end

it "should be fired for String-Object and access-type :read" do
@rule.fired?("test", :read, @user).should be_true
@rule.fired?("test", :read, @user).should be_truthy
end

it "should not be fired for Non-String-Object" do
@rule.fired?(12345, :read, @user).should_not be_true
@rule.fired?(12345, :read, @user).should_not be_truthy
end

it "should not be fired for String-Object and other access-method as :read" do
@rule.fired?("test", :delete, @user).should_not be_true
@rule.fired?("test", :delete, @user).should_not be_truthy
end
end

context "for User without role :admin" do
before do
@user = stub('user')
@user = double('user')
@user.stub(:has_role?).and_return(false)
end

specify do
@rule.fired?("test", :read, @user).should_not be_true
@rule.fired?("test", :read, @user).should_not be_truthy
end
end

context "for :all Model-Instances" do
before do
@rule_all = ModelAccessRule.new(:all).grant.role(:admin)
@user = stub('user')
@user = double('user')
end

it "should fired for user with role :admin" do
@user.stub(:has_role?) { |role| role==:admin }
@rule_all.fired?("test", :xyz, @user).should be_true
@rule_all.fired?("test", :xyz, @user).should be_truthy
end

it "should fired for user with role :admin" do
@user.stub(:has_role?).and_return(false)
@rule_all.fired?("test", :xyz, @user).should_not be_true
@rule_all.fired?("test", :xyz, @user).should_not be_truthy
end
end
end # of context "grant with roles"


context "deny with not.role" do
before(:all) do
before do
@rule = ModelAccessRule.new(String).deny.method(:append).not.role(:admin)
@user = stub('user')
@user = double('user')
end

it "should not fired for user with role :admin" do
@user.stub(:has_role?){|role| role==:admin}
@rule.fired?("/admin", :append, @user).should_not be_true
@rule.fired?("/admin", :append, @user).should_not be_truthy
end

it "should fired for user with role :user" do
@user.stub(:has_role?){|role| role==:user}
@rule.fired?("/admin", :append, @user).should be_true
@rule.fired?("/admin", :append, @user).should be_truthy
end
end # of context "deny with not.role"

Expand Down
2 changes: 1 addition & 1 deletion spec/model_extensions_spec.rb
Expand Up @@ -16,7 +16,7 @@ def deactived
before do
rules = [ModelAccessRule.new(SampleModel).grant.method(:deactived).role(:admin)]
AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
@user = stub('user')
@user = double('user')
Thread.current[:user] = @user
end

Expand Down

0 comments on commit 5999c3e

Please sign in to comment.