AutoCommit Mon Aug 31 18:03:21 CEST 2015
This commit is contained in:
@@ -3,38 +3,6 @@ require 'spec_helper'
|
|||||||
describe FetprofilesController, :type => :controller do
|
describe FetprofilesController, :type => :controller do
|
||||||
let(:valid_update_attributes) { {"vorname"=>"Neuer Vorname"} }
|
let(:valid_update_attributes) { {"vorname"=>"Neuer Vorname"} }
|
||||||
# let(:valid_session) { {locale: :de} }
|
# 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
|
def self.create_fetprofile
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@@ -68,6 +36,10 @@ describe FetprofilesController, :type => :controller do
|
|||||||
it "renders the 'show' template" do
|
it "renders the 'show' template" do
|
||||||
expect(action).to render_template("show")
|
expect(action).to render_template("show")
|
||||||
end
|
end
|
||||||
|
it "assigns memberships" do
|
||||||
|
action
|
||||||
|
expect(assigns(:memberships)).to be_a(ActiveRecord::Relation)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -82,10 +54,7 @@ describe FetprofilesController, :type => :controller do
|
|||||||
logout_user
|
logout_user
|
||||||
it_behaves_like "it is restricted"
|
it_behaves_like "it is restricted"
|
||||||
end
|
end
|
||||||
# descibe "without fetuser" do
|
|
||||||
# login_user
|
|
||||||
# it_behaves_like "it is restricted"
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET edit" do
|
describe "GET edit" do
|
||||||
@@ -95,6 +64,10 @@ describe FetprofilesController, :type => :controller do
|
|||||||
create_fetprofile
|
create_fetprofile
|
||||||
it_behaves_like "it is success"
|
it_behaves_like "it is success"
|
||||||
it_behaves_like "it assigns object"
|
it_behaves_like "it assigns object"
|
||||||
|
it "assigns memberships" do
|
||||||
|
action
|
||||||
|
expect(assigns(:memberships)).to be_a(ActiveRecord::Relation)
|
||||||
|
end
|
||||||
|
|
||||||
it "assigns the requested fetprofile as @fetprofile" do
|
it "assigns the requested fetprofile as @fetprofile" do
|
||||||
expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile)
|
expect{action}.to change {assigns(:fetprofile)}.to(@fetprofile)
|
||||||
@@ -108,35 +81,36 @@ describe FetprofilesController, :type => :controller do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "POST create" do
|
describe "POST create" do
|
||||||
subject(:action){post :create, {:fetprofile => FactoryGirl.attributes_for(:fetprofile)},:format=>:html}
|
subject(:action){post :create, {:fetprofile => FactoryGirl.attributes_for(:fetprofile),:format=>:html}}
|
||||||
|
|
||||||
login_fet_user
|
login_fet_user
|
||||||
describe "with valid params" do
|
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 "has a 302 status code" do
|
||||||
|
expect(action.status).to eq(302)
|
||||||
|
end
|
||||||
it "creates a new Fetprofile" do
|
it "creates a new Fetprofile" do
|
||||||
expect{action}.to change(Fetprofile, :count).by(1)
|
expect{action}.to change(Fetprofile, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "assigns a newly created fetprofile as @fetprofile" do
|
it_behaves_like "it assigns persisted object"
|
||||||
|
|
||||||
|
it "assigns memberships" do
|
||||||
action
|
action
|
||||||
expect(assigns(:fetprofile)).to be_a(Fetprofile)
|
expect(assigns(:memberships)).to be_a(ActiveRecord::Relation)
|
||||||
expect(assigns(:fetprofile)).to be_persisted
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the created fetprofile" do
|
it "redirects to the created fetprofile" do
|
||||||
expect(action).to redirect_to action: "show"
|
expect(action).to redirect_to assigns(:fetprofile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with invalid params" do
|
describe "with invalid params" do
|
||||||
has_invalid_params
|
has_invalid_params
|
||||||
|
it "assigns memberships" do
|
||||||
|
action
|
||||||
|
expect(assigns(:memberships)).to be_a(ActiveRecord::Relation)
|
||||||
|
end
|
||||||
|
|
||||||
it "assigns a newly created but unsaved fetprofile as @fetprofile" do
|
it "assigns a newly created but unsaved fetprofile as @fetprofile" do
|
||||||
action
|
action
|
||||||
@@ -147,6 +121,11 @@ describe FetprofilesController, :type => :controller do
|
|||||||
expect(action).to render_template("new")
|
expect(action).to render_template("new")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
describe "without user" do
|
||||||
|
logout_user
|
||||||
|
it_behaves_like "it is restricted"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "PUT update" do
|
describe "PUT update" do
|
||||||
@@ -159,13 +138,9 @@ describe FetprofilesController, :type => :controller do
|
|||||||
it_behaves_like "it assigns object"
|
it_behaves_like "it assigns object"
|
||||||
|
|
||||||
it "updates the requested fetprofile" do
|
it "updates the requested fetprofile" do
|
||||||
expect { action }.to change{Fetprofile.find(@fetprofile.id).vorname}#.to("neuerName")
|
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
|
end
|
||||||
|
it_behaves_like "it assigns persisted object"
|
||||||
|
|
||||||
it "redirects to the fetprofile" do
|
it "redirects to the fetprofile" do
|
||||||
expect(action).to redirect_to(@fetprofile)
|
expect(action).to redirect_to(@fetprofile)
|
||||||
@@ -175,14 +150,13 @@ describe FetprofilesController, :type => :controller do
|
|||||||
describe "with invalid params" do
|
describe "with invalid params" do
|
||||||
has_invalid_params
|
has_invalid_params
|
||||||
it_behaves_like "it assigns object"
|
it_behaves_like "it assigns object"
|
||||||
|
|
||||||
it "re-renders the 'edit' template" do
|
it "re-renders the 'edit' template" do
|
||||||
expect(action).to render_template("edit")
|
expect(action).to render_template("edit")
|
||||||
end
|
end
|
||||||
# it "redirect to 'edit'" do
|
end
|
||||||
# is_expected.to redirect_to action: "edit"
|
describe "without user" do
|
||||||
# end
|
logout_user
|
||||||
|
it_behaves_like "it is restricted"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -201,6 +175,11 @@ describe FetprofilesController, :type => :controller do
|
|||||||
action
|
action
|
||||||
response.should redirect_to(fetprofiles_url)
|
response.should redirect_to(fetprofiles_url)
|
||||||
end
|
end
|
||||||
|
describe "without user" do
|
||||||
|
logout_user
|
||||||
|
it_behaves_like "it is restricted"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
42
spec/controllers/shared_examples/basic.rb
Normal file
42
spec/controllers/shared_examples/basic.rb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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)
|
||||||
|
expect(assigns(object_variable)).not_to be_persisted
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shared_examples "it assigns persisted object" do
|
||||||
|
it "assigns new object" do
|
||||||
|
action
|
||||||
|
expect(assigns(object_variable)).to be_a(object_class)
|
||||||
|
expect(assigns(object_variable)).to be_persisted
|
||||||
|
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
|
||||||
@@ -8,6 +8,11 @@ describe Fetprofile do
|
|||||||
fp.should_not be_valid
|
fp.should_not be_valid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
it "should be created" do
|
||||||
|
fp=Fetprofile.new(FactoryGirl.attributes_for(:fetprofile))
|
||||||
|
expect(fp.save).to be true
|
||||||
|
end
|
||||||
|
|
||||||
it "should be valid" do
|
it "should be valid" do
|
||||||
fp = FactoryGirl.build(:fetprofile)
|
fp = FactoryGirl.build(:fetprofile)
|
||||||
fp.should be_valid
|
fp.should be_valid
|
||||||
|
|||||||
Reference in New Issue
Block a user