diff options
author | Ariejan de Vroom <ariejan@ariejan.net> | 2012-03-01 16:00:14 +0100 |
---|---|---|
committer | Ariejan de Vroom <ariejan@ariejan.net> | 2012-03-01 16:00:14 +0100 |
commit | b0ce61c4f20abe1ca5c99631517b49c99f8b23ef (patch) | |
tree | f43439eba70d0815da2528d8110c456440a3ff12 /spec | |
parent | bfe0906f2ff7a79064c1866c0278cd0c9440b246 (diff) | |
parent | f5a16663f0b038aeb397bda19ebdefa6ad873955 (diff) | |
download | gitlab-ce-b0ce61c4f20abe1ca5c99631517b49c99f8b23ef.tar.gz |
Merge branch 'deploy_keys_nonunique' of https://github.com/miks/gitlabhq into miks-deploy_keys_nonunique
Added/fixed specs
Update spec/factory to allow Factory#new without opts
Conflicts:
app/models/key.rb
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factory.rb | 4 | ||||
-rw-r--r-- | spec/models/key_spec.rb | 36 |
2 files changed, 36 insertions, 4 deletions
diff --git a/spec/factory.rb b/spec/factory.rb index 5edef358abc..1758b4d69d7 100644 --- a/spec/factory.rb +++ b/spec/factory.rb @@ -10,8 +10,8 @@ class Factory new(name, opts).tap(&:save!) end - def new(name, opts) - factory = @factories[name] + def new(name, opts = {}) + factory= @factories[name] factory[0].new.tap do |obj| factory[1].call(obj) end.tap do |obj| diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 44963e3cea7..b24f22cad96 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -14,8 +14,40 @@ describe Key do it { should respond_to :projects } end - it { Factory.create(:key, - :user => Factory(:user)).should be_valid } + context "validation of uniqueness" do + + context "as a deploy key" do + let(:project) { Factory.create(:project, path: 'alpha', code: 'alpha') } + let(:another_project) { Factory.create(:project, path: 'beta', code: 'beta') } + + before do + deploy_key = Factory.create(:key, project: project) + end + + it "does not accept the same key twice for a project" do + key = Factory.new(:key, project: project) + key.should_not be_valid + end + + it "does accept the same key for another project" do + key = Factory.new(:key, project: another_project) + key.should be_valid + end + end + + context "as a personal key" do + let(:user) { Factory.create(:user) } + + it "accepts the key once" do + Factory.new(:key, user: user).should be_valid + end + + it "does not accepts the key twice" do + Factory.create(:key, user: user) + Factory.new(:key, user: user).should_not be_valid + end + end + end end # == Schema Information # |