From eeae723994e29003f657156482e3d4e2cf6104c7 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 26 Jul 2013 01:09:26 +0200 Subject: [PATCH] =?UTF-8?q?Tests=20f=C3=BCr=20studium?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RSPEC Tests für studium hinzugefügt verwende bundle exec rspec spec/models um Model-Tests auszuführen --- spec/factories/studien.rb | 2 +- spec/models/studium_spec.rb | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/spec/factories/studien.rb b/spec/factories/studien.rb index 4608747..071a60e 100644 --- a/spec/factories/studien.rb +++ b/spec/factories/studien.rb @@ -3,7 +3,7 @@ FactoryGirl.define do factory :studium do - zahl "066 506" + zahl "066.506" name "Automatisierung" desc "TEST DESC" typ "Master" diff --git a/spec/models/studium_spec.rb b/spec/models/studium_spec.rb index 1e34d74..0297604 100644 --- a/spec/models/studium_spec.rb +++ b/spec/models/studium_spec.rb @@ -1,9 +1,27 @@ require 'spec_helper' describe Studium do - it "should not be valid without name" do - s = FactoryGirl.build(:studium, :name=>nil) - s.should_not be_valid - + [:name, :zahl].each do |attr| + it "should not be valid without #{attr}" do + s = FactoryGirl.build(:studium, attr=>nil) + s.should_not be_valid + end end + it "should create studium with valid data" do + s=FactoryGirl.build(:studium) + lambda { + s.save!}.should change {Studium.count()}.by(1) + end + it "should not accept double entrys" do + FactoryGirl.create(:studium) + s=FactoryGirl.build(:studium) + s.should_not be_valid + s.should have_at_least(1).error_on(:name) + s.should have_at_least(1).error_on(:zahl) + end + it "should expect zahl to be 000.000" do + s=FactoryGirl.build(:studium, :zahl=>"000000") + s.should_not be_valid + s.should have_at_least(1).error_on(:zahl) + end end