Commit 42b86b79 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Model specs for DeployKeys

parent ff346c01
...@@ -158,8 +158,7 @@ FactoryGirl.define do ...@@ -158,8 +158,7 @@ FactoryGirl.define do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
end end
factory :deploy_key do factory :deploy_key, class: 'DeployKey' do
project
end end
factory :personal_key do factory :personal_key do
...@@ -222,4 +221,9 @@ FactoryGirl.define do ...@@ -222,4 +221,9 @@ FactoryGirl.define do
url url
service service
end end
factory :deploy_keys_project do
deploy_key
project
end
end end
# == Schema Information
#
# Table name: keys
#
# id :integer not null, primary key
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# key :text
# title :string(255)
# identifier :string(255)
# project_id :integer
#
require 'spec_helper'
describe DeployKey do
let(:project) { create(:project) }
let(:deploy_key) { create(:deploy_key, projects: [project]) }
describe "Associations" do
it { should have_many(:deploy_keys_projects) }
it { should have_many(:projects) }
end
end
require 'spec_helper'
describe DeployKeysProject do
describe "Associations" do
it { should belong_to(:deploy_key) }
it { should belong_to(:project) }
end
describe "Validation" do
it { should validate_presence_of(:project_id) }
it { should validate_presence_of(:deploy_key_id) }
end
end
...@@ -17,7 +17,6 @@ require 'spec_helper' ...@@ -17,7 +17,6 @@ require 'spec_helper'
describe Key do describe Key do
describe "Associations" do describe "Associations" do
it { should belong_to(:user) } it { should belong_to(:user) }
it { should belong_to(:project) }
end end
describe "Mass assignment" do describe "Mass assignment" do
...@@ -37,32 +36,15 @@ describe Key do ...@@ -37,32 +36,15 @@ describe Key do
end end
context "validation of uniqueness" do context "validation of uniqueness" do
let(:user) { create(:user) }
context "as a deploy key" do it "accepts the key once" do
let!(:deploy_key) { create(:deploy_key) } build(:key, user: user).should be_valid
it "does not accept the same key twice for a project" do
key = build(:key, project: deploy_key.project)
key.should_not be_valid
end
it "does not accept the same key for another project" do
key = build(:key, project_id: 0)
key.should_not be_valid
end
end end
context "as a personal key" do it "does not accepts the key twice" do
let(:user) { create(:user) } create(:key, user: user)
build(:key, user: user).should_not be_valid
it "accepts the key once" do
build(:key, user: user).should be_valid
end
it "does not accepts the key twice" do
create(:key, user: user)
build(:key, user: user).should_not be_valid
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment