AutoCommit Sam Sep 5 19:03:01 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-09-05 19:03:01 +02:00
parent a96e48fa36
commit 13f852cf48
4 changed files with 46 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ class Gremium < ActiveRecord::Base
has_many :memberships, dependent: :destroy # Mitgliedschaften bei dem Gremium has_many :memberships, dependent: :destroy # Mitgliedschaften bei dem Gremium
has_many :nlinks, as: :link, dependent: :destroy has_many :nlinks, as: :link, dependent: :destroy
# scope :search, ->(query) {where("gremien.name like ? or gremien.desc like ?", "%#{query}%", "%#{query}%")} # scope :search, ->(query) {where("gremien.name like ? or gremien.desc like ?", "%#{query}%", "%#{query}%")}
# has_many :members, through: :memberships
searchable do searchable do
text :desc text :desc
text :name, :boost=>4.0 text :name, :boost=>4.0

View File

@@ -7,5 +7,8 @@ FactoryGirl.define do
name "Kommission" name "Kommission"
desc "Das ist eine Kommission die sich mit irgendwas beschäftigt" desc "Das ist eine Kommission die sich mit irgendwas beschäftigt"
typ 1 typ 1
factory :gremium_with_fetprofile do
association :memberships, factory: :membership_with_fetprofile
end
end end
end end

View File

@@ -2,10 +2,15 @@
FactoryGirl.define do FactoryGirl.define do
factory :membership do factory :membership do
fetprofile_id 1
gremium_id 1
start "2013-08-19" start "2013-08-19"
stop "2013-08-23" stop "2013-08-23"
typ 1 typ 1
factory :membership_with_fetprofile do
association :fetprofile
end
factory :membership_with_gremium do
association :gremium
end
end end
end end

View File

@@ -1,5 +1,39 @@
require 'spec_helper' require 'spec_helper'
describe Gremium do describe Gremium do
pending "add some examples to (or delete) #{__FILE__}" 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
[:name,:typ].each do |attr|
it "should not be valid without #{attr}" do
g = FactoryGirl.build(:gremium)
g.send("#{attr}=".to_sym,nil)
expect(g).not_to be_valid
end
end
it "is in tabs if typ is 1 or 3" 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([])
end
it "destroys memberships if its destroyed" do
g=FactoryGirl.create(:gremium_with_fetprofile)
expect(Membership.count).to be(1)
g.delete
expect(Membership.count).to be(0)
end
it "responds to title" do
g=FactoryGirl.build(:gremium)
expect(g.responds_to?(:title)).to be true
end
end end