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

@@ -28,8 +28,11 @@ class Gremium < ActiveRecord::Base
text :desc
text :name
end
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

View File

@@ -11,7 +11,10 @@ FactoryGirl.define do
c.calentry=FactoryGirl.build(:calentry, typ: 2)
end
trait :with_meetingtyp do
association :meetingtyp, factory: :meetingtyp
end
# trait :without_calentry do
# calentry nil
# end

View File

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

View File

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

View File

@@ -1 +0,0 @@

View File

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

View File

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