forked from bofh/fetsite
207 lines
5.9 KiB
Ruby
207 lines
5.9 KiB
Ruby
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
|
|
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(assigned_object_variable)
|
|
end
|
|
end
|
|
|
|
def self.create_fetprofile
|
|
before(:each) do
|
|
@fetprofile = FactoryGirl.create(:fetprofile)
|
|
end
|
|
end
|
|
describe "GET index" do
|
|
create_fetprofile
|
|
let(:action) { get :index, {} }
|
|
before(:each) do
|
|
|
|
end
|
|
it_behaves_like "it is success"
|
|
it "assigns all fetprofiles as @fetprofiles" do
|
|
@fetprofile = FactoryGirl.create(:fetprofile)
|
|
action
|
|
expect(assigns(:fetprofiles)).to eq(Fetprofile.active)
|
|
end
|
|
end
|
|
|
|
describe "GET show" do
|
|
before(:each) do
|
|
end
|
|
subject(:action) { get :show, {:id => fetprofile.to_param}}
|
|
let(:object_variable) {:fetprofile}
|
|
let(:assigned_object_variable) {@fetprofile}
|
|
end
|
|
|
|
describe "GET new" do
|
|
describe "with fetuser" do
|
|
login_fet_user
|
|
subject(:action) { get :new, {}}
|
|
let(:object_variable) {:fetprofile}
|
|
let(:assigned_object_variable) {Fetprofile}
|
|
|
|
it_behaves_like "it assigns new object"
|
|
it_behaves_like "it is success"
|
|
|
|
end
|
|
describe "without fetuser" do
|
|
before(:each) do
|
|
sign_out :user
|
|
end
|
|
pending "doesn't assign @fetprofile"
|
|
it "is expected to raise error" do
|
|
bypass_rescue
|
|
expect { get :new }.to raise_error(CanCan::AccessDenied)
|
|
end
|
|
it "is not success" do
|
|
get :new, {}
|
|
expect(response).not_to be_success
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "GET edit" do
|
|
login_fet_user
|
|
before(:each) do
|
|
@fetprofile = FactoryGirl.create(:fetprofile)
|
|
end
|
|
subject(:action) {get :edit, :id=>@fetprofile.to_param}
|
|
it "assigns the requested fetprofile as @fetprofile" do
|
|
expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile)
|
|
# expect(assigns(:fetprofile)).to eq(@fetprofile)
|
|
end
|
|
|
|
end
|
|
|
|
describe "POST create" do
|
|
let(: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
|
|
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
|
|
before(:each) do
|
|
Fetprofile.any_instance.stub(:save).and_return(false)
|
|
end
|
|
it "assigns a newly created but unsaved fetprofile as @fetprofile" do
|
|
# Trigger the behavior that occurs when invalid params are submitted
|
|
|
|
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
|
|
login_fet_user
|
|
|
|
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
|