diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-06 16:09:26 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-06 16:09:26 +0400 |
commit | 42b86b79d0547d8d6f9f3fc8bc3414f7eb4a3964 (patch) | |
tree | d540a8e70183c34f1ed4af26e853e872c9193874 /spec/models | |
parent | ff346c01fac3eb0c588d493ac4c848340b4ec0c4 (diff) |
Model specs for DeployKeys
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/deploy_key_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/deploy_keys_project_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/key_spec.rb | 30 |
3 files changed, 44 insertions, 24 deletions
diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb new file mode 100644 index 00000000000..3658a6ff1d0 --- /dev/null +++ b/spec/models/deploy_key_spec.rb @@ -0,0 +1,25 @@ +# == 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 diff --git a/spec/models/deploy_keys_project_spec.rb b/spec/models/deploy_keys_project_spec.rb new file mode 100644 index 00000000000..bb62c48bbcc --- /dev/null +++ b/spec/models/deploy_keys_project_spec.rb @@ -0,0 +1,13 @@ +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 diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index a9ab2f05a34..9ccad18248c 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -17,7 +17,6 @@ require 'spec_helper' describe Key do describe "Associations" do it { should belong_to(:user) } - it { should belong_to(:project) } end describe "Mass assignment" do @@ -37,32 +36,15 @@ describe Key do end context "validation of uniqueness" do + let(:user) { create(:user) } - context "as a deploy key" do - let!(:deploy_key) { create(:deploy_key) } - - 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 + it "accepts the key once" do + build(:key, user: user).should be_valid end - context "as a personal key" do - let(:user) { create(:user) } - - 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 + it "does not accepts the key twice" do + create(:key, user: user) + build(:key, user: user).should_not be_valid end end |