Commit 42b86b79d0547d8d6f9f3fc8bc3414f7eb4a3964

Authored by Dmitriy Zaporozhets
1 parent ff346c01

Model specs for DeployKeys

spec/factories.rb
... ... @@ -158,8 +158,7 @@ FactoryGirl.define do
158 158 "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
159 159 end
160 160  
161   - factory :deploy_key do
162   - project
  161 + factory :deploy_key, class: 'DeployKey' do
163 162 end
164 163  
165 164 factory :personal_key do
... ... @@ -222,4 +221,9 @@ FactoryGirl.define do
222 221 url
223 222 service
224 223 end
  224 +
  225 + factory :deploy_keys_project do
  226 + deploy_key
  227 + project
  228 + end
225 229 end
... ...
spec/models/deploy_key_spec.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: keys
  4 +#
  5 +# id :integer not null, primary key
  6 +# user_id :integer
  7 +# created_at :datetime not null
  8 +# updated_at :datetime not null
  9 +# key :text
  10 +# title :string(255)
  11 +# identifier :string(255)
  12 +# project_id :integer
  13 +#
  14 +
  15 +require 'spec_helper'
  16 +
  17 +describe DeployKey do
  18 + let(:project) { create(:project) }
  19 + let(:deploy_key) { create(:deploy_key, projects: [project]) }
  20 +
  21 + describe "Associations" do
  22 + it { should have_many(:deploy_keys_projects) }
  23 + it { should have_many(:projects) }
  24 + end
  25 +end
... ...
spec/models/deploy_keys_project_spec.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require 'spec_helper'
  2 +
  3 +describe DeployKeysProject do
  4 + describe "Associations" do
  5 + it { should belong_to(:deploy_key) }
  6 + it { should belong_to(:project) }
  7 + end
  8 +
  9 + describe "Validation" do
  10 + it { should validate_presence_of(:project_id) }
  11 + it { should validate_presence_of(:deploy_key_id) }
  12 + end
  13 +end
... ...
spec/models/key_spec.rb
... ... @@ -17,7 +17,6 @@ require 'spec_helper'
17 17 describe Key do
18 18 describe "Associations" do
19 19 it { should belong_to(:user) }
20   - it { should belong_to(:project) }
21 20 end
22 21  
23 22 describe "Mass assignment" do
... ... @@ -37,32 +36,15 @@ describe Key do
37 36 end
38 37  
39 38 context "validation of uniqueness" do
  39 + let(:user) { create(:user) }
40 40  
41   - context "as a deploy key" do
42   - let!(:deploy_key) { create(:deploy_key) }
43   -
44   - it "does not accept the same key twice for a project" do
45   - key = build(:key, project: deploy_key.project)
46   - key.should_not be_valid
47   - end
48   -
49   - it "does not accept the same key for another project" do
50   - key = build(:key, project_id: 0)
51   - key.should_not be_valid
52   - end
  41 + it "accepts the key once" do
  42 + build(:key, user: user).should be_valid
53 43 end
54 44  
55   - context "as a personal key" do
56   - let(:user) { create(:user) }
57   -
58   - it "accepts the key once" do
59   - build(:key, user: user).should be_valid
60   - end
61   -
62   - it "does not accepts the key twice" do
63   - create(:key, user: user)
64   - build(:key, user: user).should_not be_valid
65   - end
  45 + it "does not accepts the key twice" do
  46 + create(:key, user: user)
  47 + build(:key, user: user).should_not be_valid
66 48 end
67 49 end
68 50  
... ...