From 4e5fb8f22e2c6488ecb46b6d881510ede7b53fd9 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 4 Aug 2013 16:15:46 +0200 Subject: [PATCH] =?UTF-8?q?einige=20Tests=20f=C3=BCr=20Modulgruppe=20hinzu?= =?UTF-8?q?gef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/factories/modulgruppen.rb | 5 +++++ spec/factories/studien.rb | 9 ++++++++- spec/models/modulgruppe_spec.rb | 34 +++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/spec/factories/modulgruppen.rb b/spec/factories/modulgruppen.rb index 0d43b62..90946d0 100644 --- a/spec/factories/modulgruppen.rb +++ b/spec/factories/modulgruppen.rb @@ -6,5 +6,10 @@ FactoryGirl.define do phase 1 name "Pflichtmodule 1" desc "ASDFASDF" + factory :other_modulgruppe do + name "PFlichtmodule 2" + desc "sdafaswdfsfr" + end end + end diff --git a/spec/factories/studien.rb b/spec/factories/studien.rb index 071a60e..5677904 100644 --- a/spec/factories/studien.rb +++ b/spec/factories/studien.rb @@ -3,10 +3,17 @@ FactoryGirl.define do factory :studium do - zahl "066.506" + zahl "066506" name "Automatisierung" desc "TEST DESC" typ "Master" + + factory :other_studium do + name "Telecommunication" + desc "frueher Telekommungikation" + zahl "066507" + typ "Master" + end end end diff --git a/spec/models/modulgruppe_spec.rb b/spec/models/modulgruppe_spec.rb index 7a39d6c..3a863e3 100644 --- a/spec/models/modulgruppe_spec.rb +++ b/spec/models/modulgruppe_spec.rb @@ -1,16 +1,46 @@ require 'spec_helper' describe Modulgruppe do - it "modulgruppe should not be valid without studium" do + it "should not be valid without studium" do mg=FactoryGirl.build(:modulgruppe) mg.should_not be_valid mg.should have(1).errors_on(:studium_id) end - it "modulgruppe should be valid with studium" do + it "should be valid with studium" do s=FactoryGirl.create(:studium) mg=FactoryGirl.build(:modulgruppe) mg.studium=s mg.should be_valid end + it "should not be valid without name" do + s=FactoryGirl.create(:studium) + mg=FactoryGirl.build(:modulgruppe) + mg.studium=s + mg.name=nil + mg.should_not be_valid + mg.should have_at_least(1).errors_on(:name) + end + xit "should not be valid with dubble name" do + s=FactoryGirl.create(:studium) + mg=FactoryGirl.build(:modulgruppe, name: "Gruppe 1", desc: "132") + mg.studium=s + mg.save + mg=FactoryGirl.build(:modulgruppe, name: "Gruppe 2", desc: "133") + mg.studium=s + mg.should_not be_valid + mg.should have_at_least(1).errors_on(:name) + end + + it "should be valid with same name on different studien" do + s=FactoryGirl.create(:studium) + s2=FactoryGirl.create(:other_studium) + mg=FactoryGirl.build(:modulgruppe, name: "Gruppe") + mg.studium=s + mg.save + mg=FactoryGirl.build(:other_modulgruppe, name: "Gruppe") + mg.studium=s2 + mg.should be_valid + + end end