From 5bf63421a63e3dbccf63d5042ed21f9a8fa35ea9 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 30 Aug 2015 14:03:01 +0200 Subject: [PATCH] AutoCommit Son Aug 30 14:03:01 CEST 2015 --- Gemfile | 7 ++++++- app/models/studium.rb | 2 +- spec/factories/beispiele.rb | 3 +++ spec/factories/lvas.rb | 8 ++++++++ spec/factories/moduls.rb | 1 + spec/models/beispiel_spec.rb | 17 ++++++++++++++++- spec/models/lva_spec.rb | 22 ++++++++++++++++++++++ spec/models/studium_spec.rb | 9 ++++++--- spec/spec_helper.rb | 1 + 9 files changed, 64 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 486db40..9166ff8 100755 --- a/Gemfile +++ b/Gemfile @@ -86,6 +86,9 @@ gem 'carrierwave', "~>0.9.0" group :development, :test do gem 'factory_girl_rails' gem 'rspec-rails' +gem 'minitest' +gem 'rspec-collection_matchers' +gem 'rspec-expectations' end gem "simple_calendar", "~> 0.1.9" @@ -124,4 +127,6 @@ gem 'opengraph_parser' gem 'blueimp-gallery' gem 'blueimp-gallery-rails' -gem 'shareable' \ No newline at end of file +gem 'shareable' + +gem 'sunspot_test' \ No newline at end of file diff --git a/app/models/studium.rb b/app/models/studium.rb index 2355ae6..1fd5866 100755 --- a/app/models/studium.rb +++ b/app/models/studium.rb @@ -34,7 +34,7 @@ class Studium < ActiveRecord::Base has_many :lvas, :through=>:moduls has_many :semester, :dependent => :destroy has_many :attachments, :as=>:parent -validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} + validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} validates :typ, :inclusion => {:in => ["Bachelor","Master"] } validates :name, :uniqueness => true, :presence=>true validates :zahl, :presence=>true, :format=>{:with=>/^[0-9A-Z]{4,10}$/}, :uniqueness => true diff --git a/spec/factories/beispiele.rb b/spec/factories/beispiele.rb index f9cfcdf..c6f6dd6 100644 --- a/spec/factories/beispiele.rb +++ b/spec/factories/beispiele.rb @@ -2,5 +2,8 @@ FactoryGirl.define do factory :beispiel do + name "BSP1" + desc "sdf" + datum Date.today end end diff --git a/spec/factories/lvas.rb b/spec/factories/lvas.rb index 7a0091b..5e9442f 100644 --- a/spec/factories/lvas.rb +++ b/spec/factories/lvas.rb @@ -2,5 +2,13 @@ FactoryGirl.define do factory :lva do + name "Vorlesung 1" + desc "Das ist eine Vorlesung" + lvanr "001.002" + ects 3 + stunden 2 + pruefungsinformation "sdf" + lernaufwand "sdf" + typ 'VO' end end diff --git a/spec/factories/moduls.rb b/spec/factories/moduls.rb index 4bfd34f..20497fd 100644 --- a/spec/factories/moduls.rb +++ b/spec/factories/moduls.rb @@ -1,6 +1,7 @@ # Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do + factory :modul do name "" factory :other_modul do diff --git a/spec/models/beispiel_spec.rb b/spec/models/beispiel_spec.rb index cfaeb19..a848229 100644 --- a/spec/models/beispiel_spec.rb +++ b/spec/models/beispiel_spec.rb @@ -1,5 +1,20 @@ require 'spec_helper' describe Beispiel do - pending "add some examples to (or delete) #{__FILE__}" + + it "should be created" do + b=FactoryGirl.build(:beispiel) + l=FactoryGirl.create(:lva) + b.lva=l + expect{b.save!; Sunspot.commit}.to change{Beispiel.count}.by(1) + end + it "should not be valid without lva" do + b=FactoryGirl.build(:beispiel) + expect(b.valid?).to be false + end + it "shout respond to comments" do + b=FactoryGirl.create(:beispiel) + expect(b.responds_to?(:comments)).to be true + end + pending "should be flagable" end diff --git a/spec/models/lva_spec.rb b/spec/models/lva_spec.rb index 4209553..dde366c 100644 --- a/spec/models/lva_spec.rb +++ b/spec/models/lva_spec.rb @@ -2,4 +2,26 @@ require 'spec_helper' describe Lva do pending "add some examples to (or delete) #{__FILE__}" + it "should be created" do + l=FactoryGirl.build(:lva) + mg=FactoryGirl.build(:modulgruppe) + s=FactoryGirl.create(:studium) + mg.studium= s + mg.save! + + m=FactoryGirl.build(:other_modul) + m.modulgruppe=mg + m.save! + + l.modul= m + expect{l.save!; Sunspot.commit}.to change{Lva.count}.by(1) + end + it "should not be valid without module" do + l=FactoryGirl.build(:lva) + expect(l.valid?).to be false + expect(l.errors[:modul].size).to be(1) + end + pending "should not be valid without modul" + pending "should have beispiele" + pending "should be flagable" end diff --git a/spec/models/studium_spec.rb b/spec/models/studium_spec.rb index 0297604..ab9a349 100644 --- a/spec/models/studium_spec.rb +++ b/spec/models/studium_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Studium do + # test if it is invalid if certain attributes are missing [:name, :zahl].each do |attr| it "should not be valid without #{attr}" do s = FactoryGirl.build(:studium, attr=>nil) @@ -10,18 +11,20 @@ describe Studium do it "should create studium with valid data" do s=FactoryGirl.build(:studium) lambda { - s.save!}.should change {Studium.count()}.by(1) + 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=>"000000") + s=FactoryGirl.build(:studium, :zahl=>"000.000") + Sunspot.commit s.should_not be_valid - s.should have_at_least(1).error_on(:zahl) + expect(s.errors.size).to be > 0 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d2cbea7..871dc71 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' +require 'sunspot_test/rspec' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories.