Files
fetsite/spec/controllers/fetprofiles_controller_spec.rb
2015-08-30 20:03:01 +02:00

162 lines
4.9 KiB
Ruby

require 'spec_helper'
describe FetprofilesController, :type=> :controller do
include Devise::TestHelpers, type: :contoller
let(:valid_attributes) { {"vorname"=>"Neuer Vorname"} }
let(:valid_session) { {locale: :de} }
describe "GET index" do
let(:action) { get :index, {}, valid_session}
it "has a 200 status code" do
action
expect(response.status).to eq(200)
end
it "assigns all fetprofiles as @fetprofiles" do
fetprofile = FactoryGirl.create(:fetprofile, :active=>true)
action
expect(assigns(:fetprofiles)).to eq([fetprofile])
end
end
describe "GET show" do
it "assigns the requested fetprofile as @fetprofile" do
fetprofile = FactoryGirl.create(:fetprofile)
get :show, {:id => fetprofile.to_param}, valid_session
assigns(:fetprofile).should eq(fetprofile)
end
end
describe "GET new" do
it "assigns a new fetprofile as @fetprofile" do
get :new, {}, valid_session
assigns(:fetprofile).should be_a_new(Fetprofile)
end
end
describe "GET edit" do
it "assigns the requested fetprofile as @fetprofile" do
fetprofile = FactoryGirl.create(:fetprofile)
get :edit, {:id => fetprofile.to_param}, valid_session
assigns(:fetprofile).should eq(fetprofile)
end
end
describe "POST create" do
let(:action){post :create, {:fetprofile => FactoryGirl.build(:fetprofile).attributes.slice(:vorname, :nachname,:desc)}}
before(:all) do
u= FactoryGirl.build(:user)
u=User.last
u.add_role(:fetuser)
sign_in u
end
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
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
it "assigns a newly created but unsaved fetprofile as @fetprofile" do
# Trigger the behavior that occurs when invalid params are submitted
Fetprofile.any_instance.stub(:save).and_return(false)
post :create, {:fetprofile => { "vorname" => "in", "nachname"=> "ssdf", "desc"=> "dffff" }}, valid_session
assigns(:fetprofile).should be_a_new(Fetprofile)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Fetprofile.any_instance.stub(:save).and_return(false)
post :create, {:fetprofile => { "vorname" => "invalid value" }}, valid_session
response.should render_template("new")
end
end
end
describe "PUT update" do
before(:all) do
@fetprofile = FactoryGirl.create(:fetprofile)
end
before(:each) do
u= FactoryGirl.create(:user)
u.add_role(:fetuser)
sign_in u
end
describe "with valid params" do
let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"neuerName"}} }
it "updates the requested fetprofile" do
expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName")
end
it "assigns the requested fetprofile as @fetprofile" do
action
expect(assigns(:fetprofile)).to eq(Fetprofile.find(@fetprofile.to_param))
end
it "redirects to the fetprofile" do
fetprofile = FactoryGirl.create(:fetprofile)
action
response.should redirect_to(fetprofile)
end
end
describe "with invalid params" do
let(:action) { put :update, {:id => @fetprofile.to_param, :fetprofile => {"vorname"=>"n"}} }
it "assigns the fetprofile as @fetprofile" do
Fetprofile.any_instance.stub(:save).and_return(false)
action
expect(assigns(:fetprofile)).to eq(@fetprofile)
end
it "re-renders the 'edit' template" do
Fetprofile.any_instance.stub(:save).and_return(false)
action
expect(response).to render_template("edit")
end
it "redirect to 'edit'" do
Fetprofile.any_instance.stub(:save).and_return(false)
expect(action).to redirect_to action: "edit"
end
end
end
describe "DELETE destroy" do
before(:each) do
u= FactoryGirl.create(:user)
u.add_role(:fetuser)
sign_in u
end
it "destroys the requested fetprofile" do
fetprofile = FactoryGirl.create(:fetprofile)
expect {
delete :destroy, {:id => fetprofile.to_param}, valid_session
}.to change(Fetprofile, :count).by(-1)
end
it "redirects to the fetprofiles list" do
fetprofile = FactoryGirl.create(:fetprofile)
delete :destroy, {:id => fetprofile.to_param}, valid_session
response.should redirect_to(fetprofiles_url)
end
end
end