Skip to content

Instantly share code, notes, and snippets.

View andreaseriksson's full-sized avatar

Andreas Eriksson andreaseriksson

View GitHub Profile
@andreaseriksson
andreaseriksson / gist:5604219
Created May 18, 2013 12:14
BOOTSTRAP Popover & Tooltip
<script>
$(function(){
//Tooltip
$("a[data-toggle=tooltip], span[data-toggle=tooltip], .tip").tooltip();
//Popover
$("a[data-toggle=popover], .info").popover().click(function(e) {
e.preventDefault()
});
});
@andreaseriksson
andreaseriksson / gist:5604408
Last active December 17, 2015 11:39
RSPEC Controller spec #INDEX
describe 'GET#index' do
it "populates an array of messages" do
message = create(:message)
get :index
expect(assigns(:messages)).to match_array [message]
end
it "renders the :index view" do
get :index
response.should render_template :index
@andreaseriksson
andreaseriksson / gist:5604414
Last active December 17, 2015 11:39
RSPEC Controller spec #SHOW
describe 'GET#show' do
it "assigns the requested message to @message" do
message = create(:message)
get :show, id: message
expect(assigns(:message)).to eq message
end
it "renders the :show template" do
message = create(:message)
get :show, id: message
@andreaseriksson
andreaseriksson / gist:5604417
Created May 18, 2013 13:38
RSPEC Controller spec #NEW
describe 'GET#new' do
it "assigns a new Message to @message" do
get :new
expect(assigns(:message)).to be_a_new(Message)
end
it "renders the :new template" do
get :new
expect(response).to render_template :new
end
@andreaseriksson
andreaseriksson / gist:5604420
Created May 18, 2013 13:39
RSPEC Controller spec #EDIT
describe 'GET#edit' do
it "assigns the requested message to @message" do
message = create(:message)
get :edit, id: message
expect(assigns(:message)).to eq message
end
it "renders the :edit template" do
message = create(:message)
get :edit, id: message
@andreaseriksson
andreaseriksson / gist:5604424
Created May 18, 2013 13:40
RSPEC Controller spec #CREATE
describe "POST#create" do
context "with valid attributes" do
it "saves the new message in the database" do
expect{
post :create, message: attributes_for(:message)
}.to change(Message, :count).by(1)
end
it "redirects to the home page" do
@andreaseriksson
andreaseriksson / gist:5604428
Created May 18, 2013 13:41
RSPEC Controller spec #UPDATE
describe 'PUT#update' do
before :each do
@message = create(:message, name: "Aaron Sumner",
email: "[email protected]")
end
it "locates the requested @message" do
put :update, id: @message, message: attributes_for(:message)
expect(assigns(:message)).to eq(@message)
end
@andreaseriksson
andreaseriksson / gist:5604430
Created May 18, 2013 13:41
RSPEC Controller spec #DESTROY
describe 'DELETEdestroy' do
before :each do
@message = create(:message)
end
it "deletes the message" do
expect{
delete :destroy, id: @message
}.to change(Message,:count).by(-1)
end
@andreaseriksson
andreaseriksson / gist:5604434
Created May 18, 2013 13:42
RSPEC Controller spec #CUSTOM ACTION
describe "PUT flag_as_inappropriate" do
before :each do
@message = create(:message)
end
it "marks the message as inappropriate" do
put :flag_as_inappropriate, id: @message
@message.reload.is_inappropriate?.should be_true
expect(@message.reload.is_inappropriate?).to be_true
end
@andreaseriksson
andreaseriksson / gist:5604436
Created May 18, 2013 13:43
RSPEC Controller spec #NESTED ROUTE
describe 'GET#show' do
it "renders the :show template for the appointment" do
contact = create(:contact)
appointment = create(:appointment, contact: contact)
get :show, id: appointment, contact_id: contact.id
expect(response).to render_template :show
end
end