Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

converted from paalapi2 for example purposes

  • Loading branch information...
commit 00c71ed8f591c271a4ea078060d55f8c834e93dc 1 parent 69af397
Trevor Menagh authored
Showing with 685 additions and 901 deletions.
  1. +5 −5 Gemfile
  2. +17 −274 README
  3. +12 −12 app/controllers/application_controller.rb
  4. +0 −36 app/controllers/clinician_session_controller.rb
  5. +0 −85 app/controllers/clinicians_controller.rb
  6. +36 −0 app/controllers/user_session_controller.rb
  7. +85 −0 app/controllers/users_controller.rb
  8. +0 −2  app/helpers/clinician_session_helper.rb
  9. +0 −2  app/helpers/clinicians_helper.rb
  10. +2 −0  app/helpers/user_session_helper.rb
  11. +2 −0  app/helpers/users_helper.rb
  12. +0 −2  app/models/clinician_session.rb
  13. +1 −1  app/models/{clinician.rb → user.rb}
  14. +2 −0  app/models/user_session.rb
  15. +0 −7 app/views/clinicians/edit.html.haml
  16. +0 −19 app/views/clinicians/index.html.haml
  17. +0 −5 app/views/clinicians/new.html.haml
  18. +0 −7 app/views/clinicians/show.html.haml
  19. +3 −3 app/views/layouts/application.html.erb
  20. +4 −4 app/views/{clinician_session → user_session}/_form.html.haml
  21. 0  app/views/{clinician_session → user_session}/new.html.haml
  22. +4 −4 app/views/{clinicians → users}/_form.html.haml
  23. +7 −0 app/views/users/edit.html.haml
  24. +19 −0 app/views/users/index.html.haml
  25. +5 −0 app/views/users/new.html.haml
  26. +7 −0 app/views/users/show.html.haml
  27. +1 −1  config.ru
  28. +1 −1  config/application.rb
  29. +1 −1  config/environment.rb
  30. +1 −1  config/environments/development.rb
  31. +1 −1  config/environments/production.rb
  32. +1 −1  config/environments/test.rb
  33. +2 −2 config/initializers/rspec_generator.rb
  34. +1 −1  config/initializers/session_store.rb
  35. +6 −6 config/routes.rb
  36. +0 −13 db/migrate/20100701043032_create_clinicians.rb
  37. +13 −0 db/migrate/20100701043032_create_users.rb
  38. +0 −35 db/migrate/20100701044600_add_authentication_to_clinician.rb
  39. +35 −0 db/migrate/20100701044600_add_authentication_to_user.rb
  40. +1 −1  db/schema.rb
  41. +24 −2 doc/README_FOR_APP
  42. +0 −109 spec/controllers/clinician_session_controller_spec.rb
  43. +0 −200 spec/controllers/clinicians_controller_spec.rb
  44. +109 −0 spec/controllers/user_session_controller_spec.rb
  45. +200 −0 spec/controllers/users_controller_spec.rb
  46. +2 −2 spec/factories/{clinicians.rb → users.rb}
  47. +3 −3 spec/helpers/{clinicians_helper_spec.rb → users_helper_spec.rb}
  48. +0 −4 spec/models/clinician_session_spec.rb
  49. +0 −11 spec/models/clinician_spec.rb
  50. +4 −0 spec/models/user_session_spec.rb
  51. +11 −0 spec/models/user_spec.rb
  52. +3 −3 spec/requests/{clinicians_spec.rb → users_spec.rb}
  53. +0 −35 spec/routing/clinicians_routing_spec.rb
  54. +19 −0 spec/routing/user_session_routing_spec.rb
  55. +35 −0 spec/routing/users_routing_spec.rb
View
10 Gemfile
@@ -12,11 +12,11 @@ gem 'haml'
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3' # TODO: test this with official version of authlogic
# Add support for paperclip (used for uploading content and profile pics)
-gem 'paperclip'
+# gem 'paperclip'
# Add S3 support for attaching files with paperclip
-gem 'aws-s3', :require => 'aws/s3'
-gem 'right_aws'
+# gem 'aws-s3', :require => 'aws/s3'
+# gem 'right_aws'
# Add support for sqlite3 for dev and test DBs
gem 'sqlite3-ruby', :require => 'sqlite3'
@@ -26,8 +26,8 @@ group :development do
gem 'rails3-generators'
# Add support for getting this on heroku
- gem 'taps'
- gem 'heroku'
+ # gem 'taps'
+ # gem 'heroku'
end
# Add support for RSpec in the test environment
View
291 README
@@ -1,281 +1,24 @@
-== Welcome to Rails
+This is an example application demonstrating Authlogic running on Rails 3.
-Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
+It also includes RSpec tests for the Authlogic controller.
-This pattern splits the view (also called the presentation) into "dumb"
-templates that are primarily responsible for inserting pre-built data in between
-HTML tags. The model contains the "smart" domain objects (such as Account,
-Product, Person, Post) that holds all the business logic and knows how to
-persist themselves to a database. The controller handles the incoming requests
-(such as Save New Account, Update Product, Show Post) by manipulating the model
-and directing data to the view.
+To run the app:
+bundle install
+rake db:migrate
+rails s
+open http://localhost:3000
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
+The root directory redirects to the login page.
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
+To run the tests:
+bundle install
+rake db:migrate
+rake db:test:prepare
+rake
+You can also run autotest for continual testing.
-== Getting Started
+The version of Authlogic used here is a fork that is at:
+git://github.com/odorcicd/authlogic.git branch 'rails3'
-1. At the command prompt, create a new Rails application:
- <tt>rails myapp</tt> (where <tt>myapp</tt> is the application name)
-
-2. Change directory to <tt>myapp</tt> and start the web server:
- <tt>cd myapp; rails server</tt> (run with --help for options)
-
-3. Go to http://localhost:3000/ and you'll see:
- "Welcome aboard: You're riding the Rails!"
-
-4. Follow the guidelines to start developing your application. You can find
-the following resources handy:
-
-* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
-* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
-
-
-== Web Servers
-
-By default, Rails will try to use Mongrel if it's installed when started with
-<tt>rails server</tt>, otherwise Rails will use WEBrick, the web server that
-ships with Ruby.
-
-Mongrel is a Ruby-based web server with a C component (which requires
-compilation) that is suitable for development. If you have Ruby Gems installed,
-getting up and running with mongrel is as easy as:
- <tt>sudo gem install mongrel</tt>.
-
-You can find more info at: http://mongrel.rubyforge.org
-
-You can alternatively run Rails applications with other Ruby web servers, e.g.,
-{Thin}[http://code.macournoyer.com/thin/], {Ebb}[http://ebb.rubyforge.org/], and
-Apache with {mod_rails}[http://www.modrails.com/]. However, <tt>rails server</tt>
-doesn't search for or start them.
-
-For production use, often a web/proxy server, e.g., {Apache}[http://apache.org],
-{Nginx}[http://nginx.net/], {LiteSpeed}[http://litespeedtech.com/],
-{Lighttpd}[http://www.lighttpd.net/], or {IIS}[http://www.iis.net/], is deployed
-as the front end server with the chosen Ruby web server running in the back end
-and receiving the proxied requests via one of several protocols (HTTP, CGI, FCGI).
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files. Have "tail -f" commands
-running on the server.log and development.log. Rails will automatically display
-debugging and runtime information to these files. Debugging info will also be
-shown in the browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code
-using the Ruby logger class from inside your controllers. Example:
-
- class WeblogController < ActionController::Base
- def destroy
- @weblog = Weblog.find(params[:id])
- @weblog.destroy
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
- end
- end
-
-The result will be a message in your log file along the lines of:
-
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
-several books available online as well:
-
-* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-
-These two books will bring you up to speed on the Ruby language and also on
-programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your
-Mongrel or WEBrick server with --debugger. This means that you can break out of
-execution at any point in the code, investigate and change the model, and then,
-resume execution! You need to install ruby-debug to run the server in debugging
-mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
-
- class WeblogController < ActionController::Base
- def index
- @posts = Post.find(:all)
- debugger
- end
- end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
- >> @posts.inspect
- => "[#<Post:0x14a6be8
- @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
- #<Post:0x14a6620
- @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
- >> @posts.first.title = "hello from a debugger"
- => "hello from a debugger"
-
-...and even better, you can examine how your runtime objects actually work:
-
- >> f = @posts.first
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
- >> f.
- Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you can enter "cont".
-
-
-== Console
-
-The console is a Ruby shell, which allows you to interact with your
-application's domain model. Here you'll have all parts of the application
-configured, just like it is when the application is running. You can inspect
-domain models, change values, and save to the database. Starting the script
-without arguments will launch it in the development environment.
-
-To start the console, run <tt>rails console</tt> from the application
-directory.
-
-Options:
-
-* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
- made to the database.
-* Passing an environment name as an argument will load the corresponding
- environment. Example: <tt>rails console production</tt>.
-
-To reload your controllers and models after launching the console run
-<tt>reload!</tt>
-
-More information about irb can be found at:
-link:http://www.rubycentral.com/pickaxe/irb.html
-
-
-== dbconsole
-
-You can go to the command line of your database directly through <tt>rails
-dbconsole</tt>. You would be connected to the database with the credentials
-defined in database.yml. Starting the script without arguments will connect you
-to the development database. Passing an argument will connect you to a different
-database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
-PostgreSQL and SQLite 3.
-
-== Description of Contents
-
-The default directory structure of a generated Ruby on Rails application:
-
- |-- app
- | |-- controllers
- | |-- helpers
- | |-- models
- | `-- views
- | `-- layouts
- |-- config
- | |-- environments
- | |-- initializers
- | `-- locales
- |-- db
- |-- doc
- |-- lib
- | `-- tasks
- |-- log
- |-- public
- | |-- images
- | |-- javascripts
- | `-- stylesheets
- |-- script
- | `-- performance
- |-- test
- | |-- fixtures
- | |-- functional
- | |-- integration
- | |-- performance
- | `-- unit
- |-- tmp
- | |-- cache
- | |-- pids
- | |-- sessions
- | `-- sockets
- `-- vendor
- `-- plugins
-
-app
- Holds all the code that's specific to this particular application.
-
-app/controllers
- Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from
- ApplicationController which itself descends from ActionController::Base.
-
-app/models
- Holds models that should be named like post.rb. Models descend from
- ActiveRecord::Base by default.
-
-app/views
- Holds the template files for the view that should be named like
- weblogs/index.html.erb for the WeblogsController#index action. All views use
- eRuby syntax by default.
-
-app/views/layouts
- Holds the template files for layouts to be used with views. This models the
- common header/footer method of wrapping views. In your views, define a layout
- using the <tt>layout :default</tt> and create a file named default.html.erb.
- Inside default.html.erb, call <% yield %> to render the view using this
- layout.
-
-app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are
- generated for you automatically when using generators for controllers.
- Helpers can be used to wrap functionality for your views into methods.
-
-config
- Configuration files for the Rails environment, the routing map, the database,
- and other dependencies.
-
-db
- Contains the database schema in schema.rb. db/migrate contains all the
- sequence of Migrations for your schema.
-
-doc
- This directory is where your application documentation will be stored when
- generated using <tt>rake doc:app</tt>
-
-lib
- Application specific libraries. Basically, any kind of custom code that
- doesn't belong under controllers, models, or helpers. This directory is in
- the load path.
-
-public
- The directory available for the web server. Contains subdirectories for
- images, stylesheets, and javascripts. Also contains the dispatchers and the
- default HTML files. This should be set as the DOCUMENT_ROOT of your web
- server.
-
-script
- Helper scripts for automation and generation.
-
-test
- Unit and functional tests along with fixtures. When using the rails generate
- command, template test files will be generated for you and placed in this
- directory.
-
-vendor
- External libraries that the application depends on. Also includes the plugins
- subdirectory. If the app has frozen rails, those gems also go here, under
- vendor/rails/. This directory is in the load path.
+I am using this because I got a "to_key" error with the official repo.
View
24 app/controllers/application_controller.rb
@@ -2,21 +2,21 @@ class ApplicationController < ActionController::Base
protect_from_forgery
layout 'application'
- helper_method :current_clinician_session, :current_clinician
+ helper_method :current_user_session, :current_user
private
- def current_clinician_session
- return @current_clinician_session if defined?(@current_clinician_session)
- @current_clinician_session = ClinicianSession.find
+ def current_user_session
+ return @current_user_session if defined?(@current_user_session)
+ @current_user_session = UserSession.find
end
- def current_clinician
- return @current_clinician if defined?(@current_clinician)
- @current_clinician = current_clinician_session && current_clinician_session.record
+ def current_user
+ return @current_user if defined?(@current_user)
+ @current_user = current_user_session && current_user_session.record
end
- def require_clinician
- unless current_clinician
+ def require_user
+ unless current_user
store_location
flash[:notice] = "You must be logged in to access this page"
redirect_to login_url
@@ -24,11 +24,11 @@ def require_clinician
end
end
- def require_no_clinician
- if current_clinician
+ def require_no_user
+ if current_user
store_location
flash[:notice] = "You must be logged out to access this page"
- redirect_to clinicians_url # TODO: change this to the main page
+ redirect_to users_url # TODO: change this to the main page
return false
end
end
View
36 app/controllers/clinician_session_controller.rb
@@ -1,36 +0,0 @@
-class ClinicianSessionController < ApplicationController
- before_filter :require_no_clinician, :only => [:new, :create]
- before_filter :require_clinician, :only => :destroy
-
- # GET /login
- # GET /login.xml
- def new
- @clinician_session = ClinicianSession.new
-
- respond_to do |format|
- format.html # new.html.haml
- format.xml { render :xml => @clinician_session }
- end
- end
-
- # POST /login
- # POST /login.xml
- def create
- @clinician_session = ClinicianSession.new(params[:clinician_session])
- if @clinician_session.save
- flash[:notice] = "Successfully logged in."
- redirect_to clinicians_path, :format => params[:format]
- else
- render :action => 'new', :format => params[:format]
- end
- end
-
- # DELETE /logout
- # DELETE /logout.xml
- def destroy
- @clinician_session = ClinicianSession.find
- @clinician_session.destroy
- flash[:notice] = "Successfully logged out."
- redirect_to login_path, :format => params[:format]
- end
-end
View
85 app/controllers/clinicians_controller.rb
@@ -1,85 +0,0 @@
-class CliniciansController < ApplicationController
- before_filter :require_clinician, :except => [:new, :create]
-
- # GET /clinicians
- # GET /clinicians.xml
- def index
- @clinicians = Clinician.all
-
- respond_to do |format|
- format.html # index.html.haml
- format.xml { render :xml => @clinicians }
- end
- end
-
- # GET /clinicians/1
- # GET /clinicians/1.xml
- def show
- @clinician = Clinician.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.haml
- format.xml { render :xml => @clinician }
- end
- end
-
- # GET /clinicians/new
- # GET /clinicians/new.xml
- def new
- @clinician = Clinician.new
-
- respond_to do |format|
- format.html # new.html.haml
- format.xml { render :xml => @clinician }
- end
- end
-
- # GET /clinicians/1/edit
- def edit
- @clinician = Clinician.find(params[:id])
- end
-
- # POST /clinicians
- # POST /clinicians.xml
- def create
- @clinician = Clinician.new(params[:clinician])
-
- respond_to do |format|
- if @clinician.save
- format.html { redirect_to(@clinician, :notice => 'Clinician was successfully created.') }
- format.xml { render :xml => @clinician, :status => :created, :location => @clinician }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @clinician.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # PUT /clinicians/1
- # PUT /clinicians/1.xml
- def update
- @clinician = Clinician.find(params[:id])
-
- respond_to do |format|
- if @clinician.update_attributes(params[:clinician])
- format.html { redirect_to(@clinician, :notice => 'Clinician was successfully updated.') }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @clinician.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # DELETE /clinicians/1
- # DELETE /clinicians/1.xml
- def destroy
- @clinician = Clinician.find(params[:id])
- @clinician.destroy
-
- respond_to do |format|
- format.html { redirect_to(clinicians_url) }
- format.xml { head :ok }
- end
- end
-end
View
36 app/controllers/user_session_controller.rb
@@ -0,0 +1,36 @@
+class UserSessionController < ApplicationController
+ before_filter :require_no_user, :only => [:new, :create]
+ before_filter :require_user, :only => :destroy
+
+ # GET /login
+ # GET /login.xml
+ def new
+ @user_session = UserSession.new
+
+ respond_to do |format|
+ format.html # new.html.haml
+ format.xml { render :xml => @user_session }
+ end
+ end
+
+ # POST /login
+ # POST /login.xml
+ def create
+ @user_session = UserSession.new(params[:user_session])
+ if @user_session.save
+ flash[:notice] = "Successfully logged in."
+ redirect_to users_path, :format => params[:format]
+ else
+ render :action => 'new', :format => params[:format]
+ end
+ end
+
+ # DELETE /logout
+ # DELETE /logout.xml
+ def destroy
+ @user_session = UserSession.find
+ @user_session.destroy
+ flash[:notice] = "Successfully logged out."
+ redirect_to login_path, :format => params[:format]
+ end
+end
View
85 app/controllers/users_controller.rb
@@ -0,0 +1,85 @@
+class UsersController < ApplicationController
+ before_filter :require_user, :except => [:new, :create]
+
+ # GET /users
+ # GET /users.xml
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.haml
+ format.xml { render :xml => @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.xml
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.haml
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.xml
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.haml
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.xml
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to(@user, :notice => 'User was successfully created.') }
+ format.xml { render :xml => @user, :status => :created, :location => @user }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.xml
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.xml
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(users_url) }
+ format.xml { head :ok }
+ end
+ end
+end
View
2  app/helpers/clinician_session_helper.rb
@@ -1,2 +0,0 @@
-module ClinicianSessionHelper
-end
View
2  app/helpers/clinicians_helper.rb
@@ -1,2 +0,0 @@
-module CliniciansHelper
-end
View
2  app/helpers/user_session_helper.rb
@@ -0,0 +1,2 @@
+module UserSessionHelper
+end
View
2  app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
2  app/models/clinician_session.rb
@@ -1,2 +0,0 @@
-class ClinicianSession < Authlogic::Session::Base
-end
View
2  app/models/clinician.rb → app/models/user.rb
@@ -1,4 +1,4 @@
-class Clinician < ActiveRecord::Base
+class User < ActiveRecord::Base
validates :name, :presence => true
validates :email, :presence => true, :uniqueness => true, :email_format => true
View
2  app/models/user_session.rb
@@ -0,0 +1,2 @@
+class UserSession < Authlogic::Session::Base
+end
View
7 app/views/clinicians/edit.html.haml
@@ -1,7 +0,0 @@
-%h1 Editing clinician
-
-= render 'form'
-
-= link_to 'Show', @clinician
-\|
-= link_to 'Back', clinicians_path
View
19 app/views/clinicians/index.html.haml
@@ -1,19 +0,0 @@
-%h1 Listing clinicians
-
-%table
- %tr
- %th Name
- %th
- %th
- %th
-
- - @clinicians.each do |clinician|
- %tr
- %td= clinician.name
- %td= link_to 'Show', clinician
- %td= link_to 'Edit', edit_clinician_path(clinician)
- %td= link_to 'Destroy', clinician, :confirm => 'Are you sure?', :method => :delete
-
-%br
-
-= link_to 'New clinician', new_clinician_path
View
5 app/views/clinicians/new.html.haml
@@ -1,5 +0,0 @@
-%h1 New clinician
-
-= render 'form'
-
-= link_to 'Back', clinicians_path
View
7 app/views/clinicians/show.html.haml
@@ -1,7 +0,0 @@
-%p
- %b Name:
- = @clinician.name
-
-= link_to 'Edit', edit_clinician_path(@clinician)
-\|
-= link_to 'Back', clinicians_path
View
6 app/views/layouts/application.html.erb
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Paalapi2</title>
+ <title>AuthlogicRails3Example</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
@@ -9,8 +9,8 @@
<body>
<p>
- <% if current_clinician %>
- Hello <%= current_clinician.name %> (<%= link_to 'Not you?', logout_path, :method => :delete %>)
+ <% if current_user %>
+ Hello <%= current_user.name %> (<%= link_to 'Not you?', logout_path, :method => :delete %>)
<% end %>
</p>
View
8 app/views/clinician_session/_form.html.haml → app/views/user_session/_form.html.haml
@@ -1,9 +1,9 @@
-= form_for @clinician_session, :url => login_path do |f|
- -if @clinician_session.errors.any?
+= form_for @user_session, :url => login_path do |f|
+ -if @user_session.errors.any?
#errorExplanation
- %h2= "#{pluralize(@clinician_session.errors.count, "error")} prohibited this clinician from being saved:"
+ %h2= "#{pluralize(@user_session.errors.count, "error")} prohibited this user from being saved:"
%ul
- - @clinician_session.errors.full_messages.each do |msg|
+ - @user_session.errors.full_messages.each do |msg|
%li= msg
.field
View
0  app/views/clinician_session/new.html.haml → app/views/user_session/new.html.haml
File renamed without changes
View
8 app/views/clinicians/_form.html.haml → app/views/users/_form.html.haml
@@ -1,9 +1,9 @@
-= form_for @clinician do |f|
- -if @clinician.errors.any?
+= form_for @user do |f|
+ -if @user.errors.any?
#errorExplanation
- %h2= "#{pluralize(@clinician.errors.count, "error")} prohibited this clinician from being saved:"
+ %h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:"
%ul
- - @clinician.errors.full_messages.each do |msg|
+ - @user.errors.full_messages.each do |msg|
%li= msg
.field
View
7 app/views/users/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing user
+
+= render 'form'
+
+= link_to 'Show', @user
+\|
+= link_to 'Back', users_path
View
19 app/views/users/index.html.haml
@@ -0,0 +1,19 @@
+%h1 Listing users
+
+%table
+ %tr
+ %th Name
+ %th
+ %th
+ %th
+
+ - @users.each do |user|
+ %tr
+ %td= user.name
+ %td= link_to 'Show', user
+ %td= link_to 'Edit', edit_user_path(user)
+ %td= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New user', new_user_path
View
5 app/views/users/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New user
+
+= render 'form'
+
+= link_to 'Back', users_path
View
7 app/views/users/show.html.haml
@@ -0,0 +1,7 @@
+%p
+ %b Name:
+ = @user.name
+
+= link_to 'Edit', edit_user_path(@user)
+\|
+= link_to 'Back', users_path
View
2  config.ru
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
-run Paalapi2::Application
+run AuthlogicRails3Example::Application
View
2  config/application.rb
@@ -6,7 +6,7 @@
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
-module Paalapi2
+module AuthlogicRails3Example
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
View
2  config/environment.rb
@@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__)
# Initialize the rails application
-Paalapi2::Application.initialize!
+AuthlogicRails3Example::Application.initialize!
View
2  config/environments/development.rb
@@ -1,4 +1,4 @@
-Paalapi2::Application.configure do
+AuthlogicRails3Example::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
View
2  config/environments/production.rb
@@ -1,4 +1,4 @@
-Paalapi2::Application.configure do
+AuthlogicRails3Example::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
View
2  config/environments/test.rb
@@ -1,4 +1,4 @@
-Paalapi2::Application.configure do
+AuthlogicRails3Example::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
View
4 config/initializers/rspec_generator.rb
@@ -1,6 +1,6 @@
-Paalapi2::Application.configure do
+AuthlogicRails3Example::Application.configure do
config.generators do |g|
g.integration_tool :rspec
g.test_framework :rspec
end
-end if defined? Paalapi2::Application
+end if defined? AuthlogicRails3Example::Application
View
2  config/initializers/session_store.rb
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.
-Rails.application.config.session_store :cookie_store, :key => '_paalapi2_session'
+Rails.application.config.session_store :cookie_store, :key => '_authlogic_rails3_example_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
View
12 config/routes.rb
@@ -1,11 +1,11 @@
-Paalapi2::Application.routes.draw do |map|
- resources :clinicians
+AuthlogicRails3Example::Application.routes.draw do |map|
+ resources :users
- get 'login(.:format)' => 'clinician_session#new', :as => :login
- post 'login(.:format)' => 'clinician_session#create', :as => :login
- delete 'logout(.:format)' => 'clinician_session#destroy', :as => :logout
+ get 'login(.:format)' => 'user_session#new', :as => :login
+ post 'login(.:format)' => 'user_session#create', :as => :login
+ delete 'logout(.:format)' => 'user_session#destroy', :as => :logout
- root :to => 'clinician_session#new' # login page
+ root :to => 'user_session#new' # login page
# The priority is based upon order of creation:
# first created -> highest priority.
View
13 db/migrate/20100701043032_create_clinicians.rb
@@ -1,13 +0,0 @@
-class CreateClinicians < ActiveRecord::Migration
- def self.up
- create_table :clinicians do |t|
- t.string :name
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :clinicians
- end
-end
View
13 db/migrate/20100701043032_create_users.rb
@@ -0,0 +1,13 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
View
35 db/migrate/20100701044600_add_authentication_to_clinician.rb
@@ -1,35 +0,0 @@
-class AddAuthenticationToClinician < ActiveRecord::Migration
- def self.up
- add_column :clinicians, :email, :string, :null => false, :default => '' # optional, you can use login instead, or both
- add_column :clinicians, :crypted_password, :string, :null => false, :default => '' # optional, see below
- add_column :clinicians, :password_salt, :string, :null => false, :default => '' # optional, but highly recommended
- add_column :clinicians, :persistence_token, :string, :null => false, :default => '' # required
- add_column :clinicians, :single_access_token, :string, :null => false, :default => '' # optional, see Authlogic::Session::Params
- add_column :clinicians, :perishable_token, :string, :null => false, :default => '' # optional, see Authlogic::Session::Perishability
-
- # Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
- add_column :clinicians, :login_count, :integer, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
- add_column :clinicians, :failed_login_count, :integer, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
- add_column :clinicians, :last_request_at, :datetime # optional, see Authlogic::Session::MagicColumns
- add_column :clinicians, :current_login_at, :datetime # optional, see Authlogic::Session::MagicColumns
- add_column :clinicians, :last_login_at, :datetime # optional, see Authlogic::Session::MagicColumns
- add_column :clinicians, :current_login_ip, :string # optional, see Authlogic::Session::MagicColumns
- add_column :clinicians, :last_login_ip, :string # optional, see Authlogic::Session::MagicColumns
- end
-
- def self.down
- remove_column :clinicians, :email
- remove_column :clinicians, :crypted_password
- remove_column :clinicians, :password_salt
- remove_column :clinicians, :persistence_token
- remove_column :clinicians, :single_access_token
- remove_column :clinicians, :perishable_token
- remove_column :clinicians, :login_count
- remove_column :clinicians, :failed_login_count
- remove_column :clinicians, :last_request_at
- remove_column :clinicians, :current_login_at
- remove_column :clinicians, :last_login_at
- remove_column :clinicians, :current_login_ip
- remove_column :clinicians, :last_login_ip
- end
-end
View
35 db/migrate/20100701044600_add_authentication_to_user.rb
@@ -0,0 +1,35 @@
+class AddAuthenticationToUser < ActiveRecord::Migration
+ def self.up
+ add_column :users, :email, :string, :null => false, :default => '' # optional, you can use login instead, or both
+ add_column :users, :crypted_password, :string, :null => false, :default => '' # optional, see below
+ add_column :users, :password_salt, :string, :null => false, :default => '' # optional, but highly recommended
+ add_column :users, :persistence_token, :string, :null => false, :default => '' # required
+ add_column :users, :single_access_token, :string, :null => false, :default => '' # optional, see Authlogic::Session::Params
+ add_column :users, :perishable_token, :string, :null => false, :default => '' # optional, see Authlogic::Session::Perishability
+
+ # Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
+ add_column :users, :login_count, :integer, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
+ add_column :users, :failed_login_count, :integer, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
+ add_column :users, :last_request_at, :datetime # optional, see Authlogic::Session::MagicColumns
+ add_column :users, :current_login_at, :datetime # optional, see Authlogic::Session::MagicColumns
+ add_column :users, :last_login_at, :datetime # optional, see Authlogic::Session::MagicColumns
+ add_column :users, :current_login_ip, :string # optional, see Authlogic::Session::MagicColumns
+ add_column :users, :last_login_ip, :string # optional, see Authlogic::Session::MagicColumns
+ end
+
+ def self.down
+ remove_column :users, :email
+ remove_column :users, :crypted_password
+ remove_column :users, :password_salt
+ remove_column :users, :persistence_token
+ remove_column :users, :single_access_token
+ remove_column :users, :perishable_token
+ remove_column :users, :login_count
+ remove_column :users, :failed_login_count
+ remove_column :users, :last_request_at
+ remove_column :users, :current_login_at
+ remove_column :users, :last_login_at
+ remove_column :users, :current_login_ip
+ remove_column :users, :last_login_ip
+ end
+end
View
2  db/schema.rb
@@ -11,7 +11,7 @@
ActiveRecord::Schema.define(:version => 20100701044600) do
- create_table "clinicians", :force => true do |t|
+ create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
View
26 doc/README_FOR_APP
@@ -1,2 +1,24 @@
-Use this README file to introduce your application and point to useful places in the API for learning more.
-Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
+This is an example application demonstrating Authlogic running on Rails 3.
+
+It also includes RSpec tests for the Authlogic controller.
+
+To run the app:
+bundle install
+rake db:migrate
+rails s
+open http://localhost:3000
+
+The root directory redirects to the login page.
+
+To run the tests:
+bundle install
+rake db:migrate
+rake db:test:prepare
+rake
+
+You can also run autotest for continual testing.
+
+The version of Authlogic used here is a fork that is at:
+git://github.com/odorcicd/authlogic.git branch 'rails3'
+
+I am using this because I got a "to_key" error with the official repo.
View
109 spec/controllers/clinician_session_controller_spec.rb
@@ -1,109 +0,0 @@
-require 'spec_helper'
-
-describe ClinicianSessionController do
- def mock_clinician_session(stubs={})
- @mock_clinician_session ||= mock_model(ClinicianSession, stubs).as_null_object
- end
-
- describe "when no clinician is authenticated" do
- before(:each) do
- ClinicianSession.should_receive(:find) { false }
- end
-
- describe "GET 'new'" do
- it "assigns a new clinician_session as @clinician_session" do
- ClinicianSession.stub(:new) { mock_clinician_session }
- get :new
- assigns(:clinician_session).should be(mock_clinician_session)
- end
- end
-
- describe "POST 'create'" do
- describe "with valid params" do
- it "assigns a newly created clinician_session as @clinician_session" do
- ClinicianSession.stub(:new).with({'these' => 'params'}) { mock_clinician_session(:save => true) }
- post :create, :clinician_session => {'these' => 'params'}
- assigns(:clinician_session).should be(mock_clinician_session)
- end
-
- it "redirects to the index page" do
- ClinicianSession.stub(:new) { mock_clinician_session(:save => true) }
- post :create, :clinician_session => {}
- response.should redirect_to(clinicians_url)
- end
- end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved clinician_session as @clinician_session" do
- ClinicianSession.stub(:new).with({'these' => 'params'}) { mock_clinician_session(:save => false) }
- post :create, :clinician_session => {'these' => 'params'}
- assigns(:clinician_session).should be(mock_clinician_session)
- end
-
- it "re-renders the 'new' template" do
- ClinicianSession.stub(:new) { mock_clinician_session(:save => false) }
- post :create, :clinician_session => {}
- response.should render_template("new")
- end
- end
- end
-
- describe "DELETE 'destroy'" do
- it "fails to load" do
- delete :destroy
- response.should_not be_success
- end
-
- it "redirects to the login page" do
- delete :destroy
- response.should redirect_to(login_url)
- end
- end
- end
-
- describe "when a clinician is authenticated" do
- before(:each) do
- activate_authlogic
- ClinicianSession.create Factory.build(:clinician)
- end
-
- describe "GET 'new'" do
- it "fails to load" do
- get :new
- response.should_not be_success
- end
-
- it "redirects to the clinicians page" do
- get :new
- response.should redirect_to(clinicians_url)
- end
- end
-
- describe "POST 'create'" do
- it "fails to load" do
- post :create
- response.should_not be_success
- end
-
- it "redirects to the clinicians page" do
- post :create
- response.should redirect_to(clinicians_url)
- end
- end
-
- describe "DELETE 'destroy'" do
- it "destroys the requested clinician_session" do
- ClinicianSession.should_receive(:find).twice { mock_clinician_session }
- mock_clinician_session.should_receive(:destroy)
- delete :destroy
- end
-
- it "redirects to the login page" do
- ClinicianSession.stub(:find) { mock_clinician_session }
- delete :destroy
- response.should redirect_to(login_url)
- end
- end
- end
-
-end
View
200 spec/controllers/clinicians_controller_spec.rb
@@ -1,200 +0,0 @@
-require 'spec_helper'
-
-describe CliniciansController do
-
- def mock_clinician(stubs={})
- @mock_clinician ||= mock_model(Clinician, stubs).as_null_object
- end
-
- share_examples_for "an application that can add new clinicians" do
- describe "GET new" do
- it "assigns a new clinician as @clinician" do
- Clinician.stub(:new) { mock_clinician }
- get :new
- assigns(:clinician).should be(mock_clinician)
- end
- end
-
- describe "POST create" do
-
- describe "with valid params" do
- it "assigns a newly created clinician as @clinician" do
- Clinician.stub(:new).with({'these' => 'params'}) { mock_clinician(:save => true) }
- post :create, :clinician => {'these' => 'params'}
- assigns(:clinician).should be(mock_clinician)
- end
-
- it "redirects to the created clinician" do
- Clinician.stub(:new) { mock_clinician(:save => true) }
- post :create, :clinician => {}
- response.should redirect_to(clinician_url(mock_clinician))
- end
- end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved clinician as @clinician" do
- Clinician.stub(:new).with({'these' => 'params'}) { mock_clinician(:save => false) }
- post :create, :clinician => {'these' => 'params'}
- assigns(:clinician).should be(mock_clinician)
- end
-
- it "re-renders the 'new' template" do
- Clinician.stub(:new) { mock_clinician(:save => false) }
- post :create, :clinician => {}
- response.should render_template("new")
- end
- end
-
- end
-
- end
-
- describe "when no clinician is authenticated" do
- it_should_behave_like "an application that can add new clinicians"
-
- describe "GET index" do
- it "fails to load" do
- get :index
- response.should_not be_success
- end
-
- it "redirects to the login page" do
- get :index
- response.should redirect_to(login_url)
- end
- end
-
- describe "GET show" do
- it "fails to load" do
- get :show, :id => "37"
- response.should_not be_success
- end
-
- it "redirects to the login page" do
- get :show, :id => "37"
- response.should redirect_to(login_url)
- end
- end
-
- describe "GET edit" do
- it "fails to load" do
- get :edit, :id => "37"
- response.should_not be_success
- end
-
- it "redirects to the login page" do
- get :edit, :id => "37"
- response.should redirect_to(login_url)
- end
- end
-
- describe "PUT update" do
- it "fails to load" do
- put :update, :id => "1"
- response.should_not be_success
- end
-
- it "redirects to the login page" do
- put :update, :id => "1"
- response.should redirect_to(login_url)
- end
- end
-
- describe "DELETE destroy" do
- it "fails to load" do
- delete :destroy, :id => "37"
- response.should_not be_success
- end
-
- it "redirects to the login page" do
- delete :destroy, :id => "37"
- response.should redirect_to(login_url)
- end
- end
- end
-
- describe "when a clinician is authenticated" do
- before(:each) do
- activate_authlogic
- ClinicianSession.create Factory.build(:clinician)
- end
-
- it_should_behave_like "an application that can add new clinicians"
-
- describe "GET index" do
- it "assigns all clinicians as @clinicians" do
- Clinician.stub(:all) { [mock_clinician] }
- get :index
- assigns(:clinicians).should eq([mock_clinician])
- end
- end
-
- describe "GET show" do
- it "assigns the requested clinician as @clinician" do
- Clinician.stub(:find).with("37") { mock_clinician }
- get :show, :id => "37"
- assigns(:clinician).should be(mock_clinician)
- end
- end
-
- describe "GET edit" do
- it "assigns the requested clinician as @clinician" do
- Clinician.stub(:find).with("37") { mock_clinician }
- get :edit, :id => "37"
- assigns(:clinician).should be(mock_clinician)
- end
- end
-
- describe "PUT update" do
-
- describe "with valid params" do
- it "updates the requested clinician" do
- Clinician.should_receive(:find).with("37") { mock_clinician }
- mock_clinician.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :id => "37", :clinician => {'these' => 'params'}
- end
-
- it "assigns the requested clinician as @clinician" do
- Clinician.stub(:find) { mock_clinician(:update_attributes => true) }
- put :update, :id => "1"
- assigns(:clinician).should be(mock_clinician)
- end
-
- it "redirects to the clinician" do
- Clinician.stub(:find) { mock_clinician(:update_attributes => true) }
- put :update, :id => "1"
- response.should redirect_to(clinician_url(mock_clinician))
- end
- end
-
- describe "with invalid params" do
- it "assigns the clinician as @clinician" do
- Clinician.stub(:find) { mock_clinician(:update_attributes => false) }
- put :update, :id => "1"
- assigns(:clinician).should be(mock_clinician)
- end
-
- it "re-renders the 'edit' template" do
- Clinician.stub(:find) { mock_clinician(:update_attributes => false) }
- put :update, :id => "1"
- response.should render_template("edit")
- end
- end
-
- end
-
- describe "DELETE destroy" do
- it "destroys the requested clinician" do
- Clinician.should_receive(:find).with("37") { mock_clinician }
- mock_clinician.should_receive(:destroy)
- delete :destroy, :id => "37"
- end
-
- it "redirects to the clinicians list" do
- Clinician.stub(:find) { mock_clinician }
- delete :destroy, :id => "1"
- response.should redirect_to(clinicians_url)
- end
- end
- end
-end
View
109 spec/controllers/user_session_controller_spec.rb
@@ -0,0 +1,109 @@
+require 'spec_helper'
+
+describe UserSessionController do
+ def mock_user_session(stubs={})
+ @mock_user_session ||= mock_model(UserSession, stubs).as_null_object
+ end
+
+ describe "when no user is authenticated" do
+ before(:each) do
+ UserSession.should_receive(:find) { false }
+ end
+
+ describe "GET 'new'" do
+ it "assigns a new user_session as @user_session" do
+ UserSession.stub(:new) { mock_user_session }
+ get :new
+ assigns(:user_session).should be(mock_user_session)
+ end
+ end
+
+ describe "POST 'create'" do
+ describe "with valid params" do
+ it "assigns a newly created user_session as @user_session" do
+ UserSession.stub(:new).with({'these' => 'params'}) { mock_user_session(:save => true) }
+ post :create, :user_session => {'these' => 'params'}
+ assigns(:user_session).should be(mock_user_session)
+ end
+
+ it "redirects to the index page" do
+ UserSession.stub(:new) { mock_user_session(:save => true) }
+ post :create, :user_session => {}
+ response.should redirect_to(users_url)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved user_session as @user_session" do
+ UserSession.stub(:new).with({'these' => 'params'}) { mock_user_session(:save => false) }
+ post :create, :user_session => {'these' => 'params'}
+ assigns(:user_session).should be(mock_user_session)
+ end
+
+ it "re-renders the 'new' template" do
+ UserSession.stub(:new) { mock_user_session(:save => false) }
+ post :create, :user_session => {}
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "DELETE 'destroy'" do
+ it "fails to load" do
+ delete :destroy
+ response.should_not be_success
+ end
+
+ it "redirects to the login page" do
+ delete :destroy
+ response.should redirect_to(login_url)
+ end
+ end
+ end
+
+ describe "when a user is authenticated" do
+ before(:each) do
+ activate_authlogic
+ UserSession.create Factory.build(:user)
+ end
+
+ describe "GET 'new'" do
+ it "fails to load" do
+ get :new
+ response.should_not be_success
+ end
+
+ it "redirects to the users page" do
+ get :new
+ response.should redirect_to(users_url)
+ end
+ end
+
+ describe "POST 'create'" do
+ it "fails to load" do
+ post :create
+ response.should_not be_success
+ end
+
+ it "redirects to the users page" do
+ post :create
+ response.should redirect_to(users_url)
+ end
+ end
+
+ describe "DELETE 'destroy'" do
+ it "destroys the requested user_session" do
+ UserSession.should_receive(:find).twice { mock_user_session }
+ mock_user_session.should_receive(:destroy)
+ delete :destroy
+ end
+
+ it "redirects to the login page" do
+ UserSession.stub(:find) { mock_user_session }
+ delete :destroy
+ response.should redirect_to(login_url)
+ end
+ end
+ end
+
+end
View
200 spec/controllers/users_controller_spec.rb
@@ -0,0 +1,200 @@
+require 'spec_helper'
+
+describe UsersController do
+
+ def mock_user(stubs={})
+ @mock_user ||= mock_model(User, stubs).as_null_object
+ end
+
+ share_examples_for "an application that can add new users" do
+ describe "GET new" do
+ it "assigns a new user as @user" do
+ User.stub(:new) { mock_user }
+ get :new
+ assigns(:user).should be(mock_user)
+ end
+ end
+
+ describe "POST create" do
+
+ describe "with valid params" do
+ it "assigns a newly created user as @user" do
+ User.stub(:new).with({'these' => 'params'}) { mock_user(:save => true) }
+ post :create, :user => {'these' => 'params'}
+ assigns(:user).should be(mock_user)
+ end
+
+ it "redirects to the created user" do
+ User.stub(:new) { mock_user(:save => true) }
+ post :create, :user => {}
+ response.should redirect_to(user_url(mock_user))
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved user as @user" do
+ User.stub(:new).with({'these' => 'params'}) { mock_user(:save => false) }
+ post :create, :user => {'these' => 'params'}
+ assigns(:user).should be(mock_user)
+ end
+
+ it "re-renders the 'new' template" do
+ User.stub(:new) { mock_user(:save => false) }
+ post :create, :user => {}
+ response.should render_template("new")
+ end
+ end
+
+ end
+
+ end
+
+ describe "when no user is authenticated" do
+ it_should_behave_like "an application that can add new users"
+
+ describe "GET index" do
+ it "fails to load" do
+ get :index
+ response.should_not be_success
+ end
+
+ it "redirects to the login page" do
+ get :index
+ response.should redirect_to(login_url)
+ end
+ end
+
+ describe "GET show" do
+ it "fails to load" do
+ get :show, :id => "37"
+ response.should_not be_success
+ end
+
+ it "redirects to the login page" do
+ get :show, :id => "37"
+ response.should redirect_to(login_url)
+ end
+ end
+
+ describe "GET edit" do
+ it "fails to load" do
+ get :edit, :id => "37"
+ response.should_not be_success
+ end
+
+ it "redirects to the login page" do
+ get :edit, :id => "37"
+ response.should redirect_to(login_url)
+ end
+ end
+
+ describe "PUT update" do
+ it "fails to load" do
+ put :update, :id => "1"
+ response.should_not be_success
+ end
+
+ it "redirects to the login page" do
+ put :update, :id => "1"
+ response.should redirect_to(login_url)
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "fails to load" do
+ delete :destroy, :id => "37"
+ response.should_not be_success
+ end
+
+ it "redirects to the login page" do
+ delete :destroy, :id => "37"
+ response.should redirect_to(login_url)
+ end
+ end
+ end
+
+ describe "when a user is authenticated" do
+ before(:each) do
+ activate_authlogic
+ UserSession.create Factory.build(:user)
+ end
+
+ it_should_behave_like "an application that can add new users"
+
+ describe "GET index" do
+ it "assigns all users as @users" do
+ User.stub(:all) { [mock_user] }
+ get :index
+ assigns(:users).should eq([mock_user])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested user as @user" do
+ User.stub(:find).with("37") { mock_user }
+ get :show, :id => "37"
+ assigns(:user).should be(mock_user)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested user as @user" do
+ User.stub(:find).with("37") { mock_user }
+ get :edit, :id => "37"
+ assigns(:user).should be(mock_user)
+ end
+ end
+
+ describe "PUT update" do
+
+ describe "with valid params" do
+ it "updates the requested user" do
+ User.should_receive(:find).with("37") { mock_user }
+ mock_user.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => "37", :user => {'these' => 'params'}
+ end
+
+ it "assigns the requested user as @user" do
+ User.stub(:find) { mock_user(:update_attributes => true) }
+ put :update, :id => "1"
+ assigns(:user).should be(mock_user)
+ end
+
+ it "redirects to the user" do
+ User.stub(:find) { mock_user(:update_attributes => true) }
+ put :update, :id => "1"
+ response.should redirect_to(user_url(mock_user))
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the user as @user" do
+ User.stub(:find) { mock_user(:update_attributes => false) }
+ put :update, :id => "1"
+ assigns(:user).should be(mock_user)
+ end
+
+ it "re-renders the 'edit' template" do
+ User.stub(:find) { mock_user(:update_attributes => false) }
+ put :update, :id => "1"
+ response.should render_template("edit")
+ end
+ end
+
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested user" do
+ User.should_receive(:find).with("37") { mock_user }
+ mock_user.should_receive(:destroy)
+ delete :destroy, :id => "37"
+ end
+
+ it "redirects to the users list" do
+ User.stub(:find) { mock_user }
+ delete :destroy, :id => "1"
+ response.should redirect_to(users_url)
+ end
+ end
+ end
+end
View
4 spec/factories/clinicians.rb → spec/factories/users.rb
@@ -1,6 +1,6 @@
# Read about factories at http://github.com/thoughtbot/factory_girl
-Factory.define :clinician, :class => Clinician do |f|
+Factory.define :user, :class => User do |f|
f.sequence(:name) {|l| "Testor#{l}"}
f.sequence(:email) {|l| "test#{l}@testor.com"}
f.password "123456"
@@ -8,5 +8,5 @@
f.sequence(:persistence_token) {|l| "#{Authlogic::Random.hex_token}"}
end
-Factory.define :invalid_clinician, :class => Clinician do |f|
+Factory.define :invalid_user, :class => User do |f|
end
View
6 spec/helpers/clinicians_helper_spec.rb → spec/helpers/users_helper_spec.rb
@@ -1,14 +1,14 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
-# the CliniciansHelper. For example:
+# the UsersHelper. For example:
#
-# describe CliniciansHelper do
+# describe UsersHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
-describe CliniciansHelper do
+describe UsersHelper do
end
View
4 spec/models/clinician_session_spec.rb
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe ClinicianSession do
-end
View
11 spec/models/clinician_spec.rb
@@ -1,11 +0,0 @@
-require 'spec_helper'
-
-describe Clinician do
- it "should succeed creating a new :clinician from the Factory" do
- Factory.create(:clinician)
- end
-
- it "should invalid :invalid_clinician factory" do
- Factory.build(:invalid_clinician).should be_invalid
- end
-end
View
4 spec/models/user_session_spec.rb
@@ -0,0 +1,4 @@
+require 'spec_helper'
+
+describe UserSession do
+end
View
11 spec/models/user_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe User do
+ it "should succeed creating a new :user from the Factory" do
+ Factory.create(:user)
+ end
+
+ it "should invalid :invalid_user factory" do
+ Factory.build(:invalid_user).should be_invalid
+ end
+end
View
6 spec/requests/clinicians_spec.rb → spec/requests/users_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-describe "Clinicians" do
- describe "GET /clinicians" do
+describe "Users" do
+ describe "GET /users" do
it "works! (now write some real specs)" do
- get clinicians_path
+ get users_path
end
end
end
View
35 spec/routing/clinicians_routing_spec.rb
@@ -1,35 +0,0 @@
-require "spec_helper"
-
-describe CliniciansController do
- describe "routing" do
-
- it "recognizes and generates #index" do
- { :get => "/clinicians" }.should route_to(:controller => "clinicians", :action => "index")
- end
-
- it "recognizes and generates #new" do
- { :get => "/clinicians/new" }.should route_to(:controller => "clinicians", :action => "new")
- end
-
- it "recognizes and generates #show" do
- { :get => "/clinicians/1" }.should route_to(:controller => "clinicians", :action => "show", :id => "1")
- end
-
- it "recognizes and generates #edit" do
- { :get => "/clinicians/1/edit" }.should route_to(:controller => "clinicians", :action => "edit", :id => "1")
- end
-
- it "recognizes and generates #create" do
- { :post => "/clinicians" }.should route_to(:controller => "clinicians", :action => "create")
- end
-
- it "recognizes and generates #update" do
- { :put => "/clinicians/1" }.should route_to(:controller => "clinicians", :action => "update", :id => "1")
- end
-
- it "recognizes and generates #destroy" do
- { :delete => "/clinicians/1" }.should route_to(:controller => "clinicians", :action => "destroy", :id => "1")
- end
-
- end
-end
View
19 spec/routing/user_session_routing_spec.rb
@@ -0,0 +1,19 @@
+require "spec_helper"
+
+describe UserSessionController do
+ describe "routing" do
+
+ it "recognizes and generates #new" do
+ { :get => "/login" }.should route_to(:controller => "user_session", :action => "new")
+ end
+
+ it "recognizes and generates #create" do
+ { :post => "/login" }.should route_to(:controller => "user_session", :action => "create")
+ end
+
+ it "recognizes and generates #destroy" do
+ { :delete => "/logout" }.should route_to(:controller => "user_session", :action => "destroy")
+ end
+
+ end
+end
View
35 spec/routing/users_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe UsersController do
+ describe "routing" do
+
+ it "recognizes and generates #index" do
+ { :get => "/users" }.should route_to(:controller => "users", :action => "index")
+ end
+
+ it "recognizes and generates #new" do
+ { :get => "/users/new" }.should route_to(:controller => "users", :action => "new")
+ end
+
+ it "recognizes and generates #show" do
+ { :get => "/users/1" }.should route_to(:controller => "users", :action => "show", :id => "1")
+ end
+
+ it "recognizes and generates #edit" do
+ { :get => "/users/1/edit" }.should route_to(:controller => "users", :action => "edit", :id => "1")
+ end
+
+ it "recognizes and generates #create" do
+ { :post => "/users" }.should route_to(:controller => "users", :action => "create")
+ end
+
+ it "recognizes and generates #update" do
+ { :put => "/users/1" }.should route_to(:controller => "users", :action => "update", :id => "1")
+ end
+
+ it "recognizes and generates #destroy" do
+ { :delete => "/users/1" }.should route_to(:controller => "users", :action => "destroy", :id => "1")
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.