diff --git a/app/controllers/fetprofiles_controller.rb b/app/controllers/fetprofiles_controller.rb index ae58913..d7d99a7 100644 --- a/app/controllers/fetprofiles_controller.rb +++ b/app/controllers/fetprofiles_controller.rb @@ -9,18 +9,17 @@ class FetprofilesController < ApplicationController @fetprofiles = Fetprofile.order(:vorname,:nachname) if params[:filter]== "all" @fetprofiles = Fetprofile.where(:active=>false).order(:nachname,:vorname) if params[:filter]== "notactive" - @gremientabs = Gremium.tabs - @toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('profile.new_profile'),:path => new_fetprofile_path(@fetprofile) } if can? :new, @fetprofile + @toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('profile.new_profile'),:path => new_fetprofile_path(@fetprofile) } if can? :new, @fetprofile respond_to do |format| format.html # index.html.erb - end + end end def internlist @fetprofiles = Fetprofile.order(:vorname,:nachname) - end + end # GET /fetprofiles/1 # GET /fetprofiles/1.json diff --git a/app/models/fetprofile.rb b/app/models/fetprofile.rb index 804995e..19bbd0e 100644 --- a/app/models/fetprofile.rb +++ b/app/models/fetprofile.rb @@ -32,13 +32,13 @@ class Fetprofile < ActiveRecord::Base has_many :nlinks, as: :link def validate_birthday unless birth_month.nil? || birth_day.nil? - unless Date.valid_date?((birth_year.nil?) ? Date.today.year : birth_year, birth_month, birth_day) - errors.add(:birth_month, "Invalides Datum") - errors.add(:birth_day, "Invalides Datum") - v= false - else - v= true - end + unless Date.valid_date?((birth_year.nil?) ? Date.today.year : birth_year, birth_month, birth_day) + errors.add(:birth_month, "Invalides Datum") + errors.add(:birth_day, "Invalides Datum") + v= false + else + v= true + end else v= false end diff --git a/spec/controllers/fetprofiles_controller_spec.rb b/spec/controllers/fetprofiles_controller_spec.rb index 2d3dc7c..c7bd94c 100644 --- a/spec/controllers/fetprofiles_controller_spec.rb +++ b/spec/controllers/fetprofiles_controller_spec.rb @@ -65,6 +65,10 @@ describe FetprofilesController, :type => :controller do subject(:action) { get :show, {:id => @fetprofile.to_param}} it_behaves_like "it is success" it_behaves_like "it assigns object" + it "renders the 'show' template" do + expect(action).to render_template("show") + end + end describe "GET new" do @@ -104,22 +108,30 @@ describe FetprofilesController, :type => :controller do end describe "POST create" do - subject(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} + subject(:action){post :create, {:fetprofile => FactoryGirl.attributes_for(:fetprofile)},:format=>:html} login_fet_user describe "with valid params" do +# login_fet_user + it "uses valid params" do + expect(Fetprofile.new({:vorname => "sdfsdf", :nachname=>"sdfefw",:desc=>"sdfsdfe"}).save).to be true + end +# before(:each) do +# Fetprofile.any_instance.stub(:save).and_return(true) +# end + it "creates a new Fetprofile" do expect{action}.to change(Fetprofile, :count).by(1) end - + it "assigns a newly created fetprofile as @fetprofile" do action expect(assigns(:fetprofile)).to be_a(Fetprofile) - assigns(:fetprofile).should be_persisted + expect(assigns(:fetprofile)).to be_persisted end - + it "redirects to the created fetprofile" do - expect(action).to redirect_to(Fetprofile.last) + expect(action).to redirect_to action: "show" end end @@ -129,6 +141,7 @@ describe FetprofilesController, :type => :controller do it "assigns a newly created but unsaved fetprofile as @fetprofile" do action assigns(:fetprofile).should be_a_new(Fetprofile) + expect(assigns(:fetprofile)).not_to be_persisted end it "re-renders the 'new' template" do expect(action).to render_template("new") @@ -148,6 +161,12 @@ describe FetprofilesController, :type => :controller do it "updates the requested fetprofile" do expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName") end + it "assigns a created fetprofile as @fetprofile" do + action + expect(assigns(:fetprofile)).to be_a(Fetprofile) + expect(assigns(:fetprofile)).to be_persisted + end + it "redirects to the fetprofile" do expect(action).to redirect_to(@fetprofile) end diff --git a/spec/factories/fetprofiles.rb b/spec/factories/fetprofiles.rb index 8576a20..c9c56a3 100644 --- a/spec/factories/fetprofiles.rb +++ b/spec/factories/fetprofiles.rb @@ -9,5 +9,7 @@ FactoryGirl.define do desc "MyText" picture "MyString" active false + birth_month 4 + birth_day 2 end end