Skip to content

Instantly share code, notes, and snippets.

@rknLA
Created April 4, 2012 20:35
Show Gist options
  • Save rknLA/2305381 to your computer and use it in GitHub Desktop.
Save rknLA/2305381 to your computer and use it in GitHub Desktop.
capybara error?
-# app/views/layouts/admin.html.haml
!!! 5
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}/
%title= content_for?(:title) ? yield(:title) : "HammerSoundscapeServer"
= csrf_meta_tags
/ Le HTML5 shim, for IE6-8 support of HTML elements
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
/ Le styles
= stylesheet_link_tag "application", :media => "all"
/ Le fav and touch icons
%link{:href => "images/favicon.ico", :rel => "shortcut icon"}/
%link{:href => "images/apple-touch-icon.png", :rel => "apple-touch-icon"}/
%link{:href => "images/apple-touch-icon-72x72.png", :rel => "apple-touch-icon", :sizes => "72x72"}/
%link{:href => "images/apple-touch-icon-114x114.png", :rel => "apple-touch-icon", :sizes => "114x114"}/
%body
.navbar.navbar-fixed-top
.navbar-inner
.container-fluid
%a.btn.btn-navbar{"data-target" => ".nav-collapse", "data-toggle" => "collapse"}
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand{:href => "#"}HammerSoundscapeServer
.container-fluid.nav-collapse
%ul.nav
%li= link_to "Link 1", "/path1"
%li= link_to "Link 2", "/path2"
%li= link_to "Link 3", "/path3"
%ul.nav.pull-right
%li= link_to 'Log out', destroy_user_session_path, :method => :delete
.container-fluid
.row-fluid
.span3
.well.sidebar-nav
%ul.nav.nav-list
%li.nav-header Sidebar
%li= link_to "Link 1", "/path1"
%li= link_to "Link 2", "/path2"
%li= link_to "Link 3", "/path3"
.span9
= yield
%footer
%p © Company 2012
/
Le javascript
\==================================================
/ Placed at the end of the document so the pages load faster
= javascript_include_tag "application"
# app/controllers/admin/application_controller.rb
module Admin
class ApplicationController < ::ApplicationController
before_filter :authenticate_user!
layout 'admin'
end
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
def index
if user_signed_in?
redirect_to admin_dashboard_path
end
end
end
# app/controllers/admin/dashboards_controller.rb
class Admin::DashboardsController < Admin::ApplicationController
before_filter :authenticate_user!
def show
end
end
2:
3: describe Admin::ApplicationController do
4: it 'should display a logout button' do
5: user = sign_in_user
6: visit root_path
=> 7: binding.pry
8: page.should have_content('Log out')
9: end
10: end
[1] pry(#<RSpec::Core::ExampleGroup::Nested_1>)> page.html
=> "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>foo</p></body></html>\n"
[2] pry(#<RSpec::Core::ExampleGroup::Nested_1>)> page.current_path
=> "/admin/dashboard"
# spec/support/helpers.rb
module Helpers
def sign_in_user(email = '[email protected]',
password = 'testpw')
user = Fabricate(:user, :email => email, :password => password)
visit root_path
fill_in('Email', :with => email)
fill_in('Password', :with => password)
click_button 'Sign in'
user
end
end
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
root / application#index
admin_dashboard GET /admin/dashboard(.:format) admin/dashboards#show
HammerSoundscapeServer::Application.routes.draw do
devise_for :users
root :to => 'application#index'
namespace :admin do
resource :dashboard, :only => 'show'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment