gremium und studien factory und specs
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
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
|
||||||
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)
|
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([])
|
||||||
|
|||||||
@@ -2,12 +2,18 @@ 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_behaves_like "a valid object"
|
||||||
|
|
||||||
it "should create studium with valid data" do
|
it "should create studium with valid data" do
|
||||||
s=FactoryGirl.build(:studium)
|
s=FactoryGirl.build(:studium)
|
||||||
lambda {
|
lambda {
|
||||||
@@ -15,16 +21,26 @@ describe Studium do
|
|||||||
end
|
end
|
||||||
it "should not accept double entrys" do
|
it "should not accept double entrys" do
|
||||||
FactoryGirl.create(:studium)
|
FactoryGirl.create(:studium)
|
||||||
Sunspot.commit
|
expect(studium).not_to be_valid
|
||||||
s=FactoryGirl.build(:studium)
|
|
||||||
s.should_not be_valid
|
|
||||||
s.should have_at_least(1).error_on(:name)
|
expect(studium).to have_at_least(1).error_on(:name)
|
||||||
s.should have_at_least(1).error_on(:zahl)
|
expect(studium).to have_at_least(1).error_on(:zahl)
|
||||||
end
|
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")
|
s=FactoryGirl.build(:studium, :zahl=>"000.000")
|
||||||
Sunspot.commit
|
#Sunspot.commit
|
||||||
s.should_not be_valid
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user