gremium und studien factory und specs

This commit is contained in:
2019-01-13 15:13:31 +01:00
parent 92d63b71ed
commit f52ec0411d
7 changed files with 66 additions and 37 deletions

View File

@@ -30,6 +30,9 @@ class Gremium < ActiveRecord::Base
end end
belongs_to :thema # Gehört zu einem Thema belongs_to :thema # Gehört zu einem Thema
validates :name, :presence=>true
validates :typ, :presence=>true
validates :typ, :inclusion =>{ in: Gremium::TYPEN.keys()}
scope :tabs, -> { where(:typ => [1,3]).order(:typ).order(:name) } # Gremien die in Tabs angezeigt werden (Alle Anderen nur in der Liste scope :tabs, -> { where(:typ => [1,3]).order(:typ).order(:name) } # Gremien die in Tabs angezeigt werden (Alle Anderen nur in der Liste

View File

@@ -12,6 +12,9 @@ FactoryGirl.define do
end end
trait :with_meetingtyp do
association :meetingtyp, factory: :meetingtyp
end
# trait :without_calentry do # trait :without_calentry do
# calentry nil # calentry nil
# end # end

View File

@@ -15,7 +15,7 @@ FactoryGirl.define do
end end
trait :with_meeting do trait :with_meeting do
after(:build) do |n| after(:build) do |n|
n.meeting=FactoryGirl.build(:meeting) n.meeting=FactoryGirl.build(:meeting, :with_meetingtyp)
end end

View File

@@ -10,7 +10,7 @@ FactoryGirl.define do
factory :other_studium do factory :other_studium do
name "Telecommunication" name "Telecommunication"
desc "frueher Telekommungikation" desc "frueher Telekommunikation"
zahl "066507" zahl "066507"
typ "Master" typ "Master"
end end

View File

@@ -1 +0,0 @@

View File

@@ -1,27 +1,35 @@
require 'spec_helper' require 'spec_helper'
describe Gremium do describe Gremium do
it "can be created" do let(:gremium) {FactoryGirl.build(:gremium)}
g=FactoryGirl.build(:gremium) let(:object_variable){gremium}
expect(g.save).to be true it_behaves_like "a valid object"
end
it "is valid with all attributes" do
g = FactoryGirl.build(:gremium)
g.should be_valid
end
[:name,:typ].each do |attr| [:name,:typ].each do |attr|
it "should not be valid without #{attr}" do it "is not valid without #{attr}" do
g = FactoryGirl.build(:gremium) g = FactoryGirl.build(:gremium,attr.to_sym => nil)
g.send("#{attr}=".to_sym,nil)
expect(g).not_to be_valid expect(g).not_to be_valid
expect(g.errors[attr]).to have_at_least(1).items expect(g.errors[attr]).to have_at_least(1).items
end end
end end
it "is in tabs if typ is 1 or 3" do
pending "only accepts valid types"
pending "only accepts valid geschlecht"
it "is not valid with wrong typ" do
((-5..30).to_a-Gremium::TYPEN.keys()).each do |i|
g = FactoryGirl.build(:gremium, typ: i)
expect(g).not_to be_valid
end
end
it "is in tabs if typ is 1" do
g = FactoryGirl.create(:gremium, typ: 1) g = FactoryGirl.create(:gremium, typ: 1)
expect(Gremium.tabs).to eq([g]) expect(Gremium.tabs).to eq([g])
end end
it "is not in tabs if typ is not 1 or 3" do it "is not in tabs if typ is not 1 or 3" do
g = FactoryGirl.create(:gremium, typ: 2) g = FactoryGirl.create(:gremium, typ: 2)
expect(Gremium.tabs).to eq([]) expect(Gremium.tabs).to eq([])

View File

@@ -2,29 +2,45 @@ require 'spec_helper'
describe Studium do describe Studium do
# test if it is invalid if certain attributes are missing # test if it is invalid if certain attributes are missing
let(:studium) { FactoryGirl.build(:studium)}
let(:object_variable) {studium}
[:name, :zahl].each do |attr| [:name, :zahl].each do |attr|
it "should not be valid without #{attr}" do it "should not be valid without #{attr}" do
s = FactoryGirl.build(:studium, attr=>nil) s = FactoryGirl.build(:studium, attr=>nil)
s.should_not be_valid expect(s).not_to be_valid
end end
end end
it "should create studium with valid data" do
s=FactoryGirl.build(:studium) it_behaves_like "a valid object"
lambda {
s.save!; Sunspot.commit}.should change {Studium.count()}.by(1) it "should create studium with valid data" do
end s=FactoryGirl.build(:studium)
it "should not accept double entrys" do lambda {
FactoryGirl.create(:studium) s.save!; Sunspot.commit}.should change {Studium.count()}.by(1)
Sunspot.commit end
s=FactoryGirl.build(:studium) it "should not accept double entrys" do
s.should_not be_valid FactoryGirl.create(:studium)
s.should have_at_least(1).error_on(:name) expect(studium).not_to be_valid
s.should have_at_least(1).error_on(:zahl)
end
it "should expect zahl to be 000.000" do expect(studium).to have_at_least(1).error_on(:name)
s=FactoryGirl.build(:studium, :zahl=>"000.000") expect(studium).to have_at_least(1).error_on(:zahl)
Sunspot.commit end
s.should_not be_valid it "expect zahl to be 000.000" do
s=FactoryGirl.build(:studium, :zahl=>"000.000")
#Sunspot.commit
s.should_not be_valid
expect(s.errors.size).to be > 0 expect(s.errors.size).to be > 0
end end
it "is not valid with a short zahl" do
s=FactoryGirl.build(:studium, :zahl=>"123")
expect(s).not_to be_valid
end
it "has a alias title for name" do
expect(studium.title).to eq(studium.name)
end
end end