require 'spec_helper' describe FetprofilesController, :type => :controller do let(:valid_update_attributes) { {"vorname"=>"Neuer Vorname"} } # let(:valid_session) { {locale: :de} } shared_examples "it is success" do it "has a 200 status code" do action expect(response.status).to eq(200) end it "is success" do action expect(response).to be_success end end shared_examples "it assigns object" do it "assigns object variable" do action expect(assigns(object_variable)).to eq(assigned_object_variable) end end shared_examples "it assigns new object" do it "assigns new object" do action expect(assigns(object_variable)).to be_a_new(object_class) end end shared_examples "it is restricted" do it "is expected to raise error" do bypass_rescue expect { action }.to raise_error(CanCan::AccessDenied) end it "is not success" do action expect(response).not_to be_success end end def self.create_fetprofile before(:each) do @fetprofile = FactoryGirl.create(:fetprofile) end end def self.create_active_fetprofile before(:each) do @fetprofile = FactoryGirl.create(:fetprofile, active: true) end end let(:object_variable) {:fetprofile} let(:assigned_object_variable) {@fetprofile} let(:object_class) {Fetprofile} describe "GET index" do create_active_fetprofile subject(:action) { get :index, {} } let(:object_variable) {:fetprofiles} let(:assigned_object_variable) {[@fetprofile]} it_behaves_like "it is success" it_behaves_like "it assigns object" end describe "GET show" do create_fetprofile subject(:action) { get :show, {:id => @fetprofile.to_param}} it_behaves_like "it is success" it_behaves_like "it assigns object" end describe "GET new" do subject(:action) { get :new, {}} describe "with fetuser" do login_fet_user it_behaves_like "it assigns new object" it_behaves_like "it is success" end describe "without user" do logout_user it_behaves_like "it is restricted" end # descibe "without fetuser" do # login_user # it_behaves_like "it is restricted" # end end describe "GET edit" do subject(:action) {get :edit, :id=>@fetprofile.to_param} login_fet_user create_fetprofile it_behaves_like "it is success" it_behaves_like "it assigns object" it "assigns the requested fetprofile as @fetprofile" do expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile) # expect(assigns(:fetprofile)).to eq(@fetprofile) end describe "without user" do logout_user it_behaves_like "it is restricted" end end describe "POST create" do subject(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}} login_fet_user describe "with valid params" do 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 end it "redirects to the created fetprofile" do expect(action).to redirect_to(Fetprofile.last) end end describe "with invalid params" do has_invalid_params it "assigns a newly created but unsaved fetprofile as @fetprofile" do action assigns(:fetprofile).should be_a_new(Fetprofile) end it "re-renders the 'new' template" do expect(action).to render_template("new") end end end describe "PUT update" do let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}} } create_fetprofile login_fet_user describe "with valid params" do it_behaves_like "it assigns object" it "updates the requested fetprofile" do expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName") end it "redirects to the fetprofile" do expect(action).to redirect_to(@fetprofile) end end describe "with invalid params" do has_invalid_params it_behaves_like "it assigns object" it "re-renders the 'edit' template" do expect(action).to render_template("edit") end # it "redirect to 'edit'" do # is_expected.to redirect_to action: "edit" # end end end describe "DELETE destroy" do login_fet_user create_fetprofile subject(:action) { delete :destroy, {:id => @fetprofile.to_param}} it "destroys the requested fetprofile" do expect { action }.to change(Fetprofile, :count).by(-1) end it "redirects to the fetprofiles list" do action response.should redirect_to(fetprofiles_url) end end end