gremium und studien factory und specs
This commit is contained in:
@@ -30,6 +30,9 @@ class Gremium < ActiveRecord::Base
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ FactoryGirl.define do
|
||||
|
||||
end
|
||||
|
||||
trait :with_meetingtyp do
|
||||
association :meetingtyp, factory: :meetingtyp
|
||||
end
|
||||
# trait :without_calentry do
|
||||
# calentry nil
|
||||
# end
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ FactoryGirl.define do
|
||||
|
||||
factory :other_studium do
|
||||
name "Telecommunication"
|
||||
desc "frueher Telekommungikation"
|
||||
desc "frueher Telekommunikation"
|
||||
zahl "066507"
|
||||
typ "Master"
|
||||
end
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
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
|
||||
end
|
||||
it "is in tabs if typ is 1 or 3" do
|
||||
|
||||
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([])
|
||||
|
||||
@@ -2,12 +2,18 @@ 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_behaves_like "a valid object"
|
||||
|
||||
it "should create studium with valid data" do
|
||||
s=FactoryGirl.build(:studium)
|
||||
lambda {
|
||||
@@ -15,16 +21,26 @@ describe Studium do
|
||||
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)
|
||||
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 "should expect zahl to be 000.000" do
|
||||
it "expect zahl to be 000.000" do
|
||||
s=FactoryGirl.build(:studium, :zahl=>"000.000")
|
||||
Sunspot.commit
|
||||
#Sunspot.commit
|
||||
s.should_not be_valid
|
||||
expect(s.errors.size).to be > 0
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user