spec/model_user_spec.rb in gritano-0.5.3 vs spec/model_user_spec.rb in gritano-0.5.4
- old
+ new
@@ -1,68 +1,96 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-describe Gritano::User do
- it 'should have a login' do
- user = Gritano::User.new
- user.should be_invalid
- user = Gritano::User.new(login: 'login')
- user.should be_valid
+module Gritano
+ describe User do
+ before(:each) do
+ Repository.any_instance.stub(:create_bare_repo).and_return(:create_bare_repo)
+ Repository.any_instance.stub(:destroy_bare_repo).and_return(:destroy_bare_repo)
+ end
+
+ it "should have a login" do
+ user = User.new()
+ user.should be_invalid
+ end
+
+ it "should have an unique login" do
+ User.create(login: 'user')
+ user = User.new(login: 'user')
+ user.should be_invalid
+ end
+
+ it "can have many repositories" do
+ user = User.create(login: 'user')
+ user.repositories.count.should == 0
+ user.repositories.create(name:'myrepo', path: 'path')
+ user.repositories.count.should == 1
+ user.repositories.create(name:'myrepo2', path: 'path2')
+ user.repositories.count.should == 2
+ user.repositories.create(name:'myrepo3', path: 'path3')
+ user.repositories.count.should == 3
+ end
+
+ it "can have many keys" do
+ user = User.create(login: 'user')
+ user.keys.count.should == 0
+ user.keys.create(name: "mykey", key: "sshkey")
+ user.keys.count.should == 1
+ user.keys.create(name: "mykey2", key: "sshkey2")
+ user.keys.count.should == 2
+ user.keys.create(name: "mykey3", key: "sshkey3")
+ user.keys.count.should == 3
+ end
+
+ it "can be admin" do
+ user = User.create(login: 'user', admin: true)
+ user.should be_admin
+ user = User.create(login: 'user')
+ user.should_not be_admin
+ end
+
+ it "should add READ access to a reporitory" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.add_access(repo, :read).should be_true
+ end
+
+ it "should add WRTIE access to a reporitory" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.add_access(repo, :write).should be_true
+ end
+
+ it "should not add an UNKNOWN access to a repository" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.add_access(repo, :wrong).should be_false
+ end
+
+ it "should remove READ access to a reporitory" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.remove_access(repo, :read).should be_true
+ end
+
+ it "should remove WRTIE access to a reporitory" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.remove_access(repo, :write).should be_true
+ end
+
+ it "should check READ access" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.check_access(repo, :read).should be_false
+ user.add_access(repo, :read).should be_true
+ user.check_access(repo, :read).should be_true
+ end
+
+ it "should check WRITE access" do
+ user = User.create(login: 'user')
+ repo = Repository.create(name:'myrepo', path: 'path')
+ user.check_access(repo, :write).should be_false
+ user.add_access(repo, :write).should be_true
+ user.check_access(repo, :write).should be_true
+ end
end
-
- it 'should have a unique login' do
- user1 = Gritano::User.create(login: 'test')
- user2 = Gritano::User.new(login: 'test')
- user2.should be_invalid
- end
-
- it 'can be a administrator' do
- user = Gritano::User.new(login: 'login', admin: true)
- user.should be_admin
- end
-
- it 'can not be a administrator' do
- user = Gritano::User.new(login: 'login', admin: false)
- user.should_not be_admin
- end
-
- it 'should add read access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.add_access(repo, :read).should be_true
- end
-
- it 'should add write access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.add_access(repo, :read).should be_true
- end
-
- it 'should not add an wrong type access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.add_access(repo, :wrong).should be_false
- end
-
- it 'should not remove an wrong type access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.remove_access(repo, :wrong).should be_false
- end
-
- it 'should not have read access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.check_access(repo, :read).should be_false
- end
-
- it 'should not have write access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.check_access(repo, :write).should be_false
- end
-
- it 'should not have wrong access to a repository' do
- user = Gritano::User.create(login: 'test')
- repo = Gritano::Repository.create(name: 'tmp/repo.git')
- user.check_access(repo, :wrong).should be_false
- end
-end
+end
\ No newline at end of file