Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

I5

  • Loading branch information...
commit 19a1695368079603c0d35553e3c85ed087e11ab8 1 parent 6d164a9
@steveklabnik steveklabnik authored
Showing with 813 additions and 6 deletions.
  1. +1 −0  Gemfile
  2. +17 −0 Gemfile.lock
  3. +3 −0  app/assets/javascripts/authors.js.coffee
  4. +3 −0  app/assets/stylesheets/authors.css.scss
  5. +56 −0 app/assets/stylesheets/scaffolds.css.scss
  6. +2 −0  app/controllers/articles_controller.rb
  7. +19 −0 app/controllers/author_sessions_controller.rb
  8. +94 −0 app/controllers/authors_controller.rb
  9. +2 −0  app/controllers/comments_controller.rb
  10. +2 −0  app/helpers/authors_helper.rb
  11. +5 −0 app/models/author.rb
  12. +4 −2 app/views/articles/show.html.erb
  13. +16 −0 app/views/author_sessions/new.html.haml
  14. +34 −0 app/views/authors/_form.html.erb
  15. +6 −0 app/views/authors/edit.html.erb
  16. +29 −0 app/views/authors/index.html.erb
  17. +5 −0 app/views/authors/new.html.erb
  18. +14 −0 app/views/authors/show.html.erb
  19. +10 −1 app/views/layouts/application.html.haml
  20. +386 −0 config/initializers/sorcery.rb
  21. +8 −2 config/routes.rb
  22. +16 −0 db/migrate/20120415170552_sorcery_core.rb
  23. +10 −1 db/schema.rb
  24. +11 −0 test/fixtures/authors.yml
  25. +49 −0 test/functional/authors_controller_test.rb
  26. +7 −0 test/unit/author_test.rb
  27. +4 −0 test/unit/helpers/authors_helper_test.rb
View
1  Gemfile
@@ -6,6 +6,7 @@ gem 'jquery-rails'
gem 'paperclip'
gem 'haml'
+gem 'sorcery'
# Gems used only for assets and not required
# in production environments by default.
View
17 Gemfile.lock
@@ -28,7 +28,9 @@ GEM
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
+ addressable (2.2.7)
arel (3.0.2)
+ bcrypt-ruby (3.0.1)
builder (3.0.0)
cocaine (0.2.1)
coffee-rails (3.2.2)
@@ -41,6 +43,10 @@ GEM
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ faraday (0.7.6)
+ addressable (~> 2.2)
+ multipart-post (~> 1.1)
+ rack (~> 1.1)
haml (3.1.4)
hike (1.2.1)
i18n (0.6.0)
@@ -55,6 +61,11 @@ GEM
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.2.0)
+ multipart-post (1.1.5)
+ oauth (0.4.5)
+ oauth2 (0.5.2)
+ faraday (~> 0.7)
+ multi_json (~> 1.0)
paperclip (3.0.2)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
@@ -92,6 +103,11 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ sorcery (0.7.7)
+ bcrypt-ruby (~> 3.0.0)
+ oauth (~> 0.4.4)
+ oauth2 (~> 0.5.1)
+ sorcery
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -117,5 +133,6 @@ DEPENDENCIES
paperclip
rails (= 3.2.2)
sass-rails (~> 3.2.3)
+ sorcery
sqlite3
uglifier (>= 1.0.3)
View
3  app/assets/javascripts/authors.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/authors.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Authors controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
View
2  app/controllers/articles_controller.rb
@@ -1,4 +1,6 @@
class ArticlesController < ApplicationController
+ before_filter :require_login, :except => [:index, :show]
+
def index
@articles = Article.all
end
View
19 app/controllers/author_sessions_controller.rb
@@ -0,0 +1,19 @@
+class AuthorSessionsController < ApplicationController
+ def new
+ @author = Author.new
+ end
+
+ def create
+ if @author = login(params[:username], params[:password])
+ redirect_back_or_to(articles_path, :message => 'Logged in successfully.')
+ else
+ flash.now[:alert] = "Login failed."
+ render :action => :new
+ end
+ end
+
+ def destroy
+ logout
+ redirect_to(:authors, :message => 'Logged out!')
+ end
+end
View
94 app/controllers/authors_controller.rb
@@ -0,0 +1,94 @@
+class AuthorsController < ApplicationController
+ before_filter :zero_authors_or_authenticated, :only => [:new, :create]
+ before_filter :require_login, :except => [:new, :create]
+
+
+ # GET /authors
+ # GET /authors.json
+ def index
+ @authors = Author.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @authors }
+ end
+ end
+
+ # GET /authors/1
+ # GET /authors/1.json
+ def show
+ @author = Author.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @author }
+ end
+ end
+
+ # GET /authors/new
+ # GET /authors/new.json
+ def new
+ @author = Author.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @author }
+ end
+ end
+
+ # GET /authors/1/edit
+ def edit
+ @author = Author.find(params[:id])
+ end
+
+ # POST /authors
+ # POST /authors.json
+ def create
+ @author = Author.new(params[:author])
+
+ respond_to do |format|
+ if @author.save
+ format.html { redirect_to @author, notice: 'Author was successfully created.' }
+ format.json { render json: @author, status: :created, location: @author }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @author.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /authors/1
+ # PUT /authors/1.json
+ def update
+ @author = Author.find(params[:id])
+
+ respond_to do |format|
+ if @author.update_attributes(params[:author])
+ format.html { redirect_to @author, notice: 'Author was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @author.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /authors/1
+ # DELETE /authors/1.json
+ def destroy
+ @author = Author.find(params[:id])
+ @author.destroy
+
+ respond_to do |format|
+ format.html { redirect_to authors_url }
+ format.json { head :no_content }
+ end
+ end
+
+ def zero_authors_or_authenticated
+ unless Author.count == 0 || current_user
+ redirect_to root_path
+ return false
+ end
+ end
+end
View
2  app/controllers/comments_controller.rb
@@ -1,4 +1,6 @@
class CommentsController < ApplicationController
+ before_filter :require_login, :except => [:create]
+
def create
article_id = params[:comment].delete(:article_id)
View
2  app/helpers/authors_helper.rb
@@ -0,0 +1,2 @@
+module AuthorsHelper
+end
View
5 app/models/author.rb
@@ -0,0 +1,5 @@
+class Author < ActiveRecord::Base
+ authenticates_with_sorcery!
+ validates_confirmation_of :password, :message => "should match confirmation", :if => :password
+
+end
View
6 app/views/articles/show.html.erb
@@ -15,6 +15,8 @@
<%= link_to "<< Back to Articles List", articles_path %>
-<%= link_to "edit", edit_article_path(@article) %>
+<% if logged_in? %>
+ <%= link_to "edit", edit_article_path(@article) %>
-<%= link_to "delete", article_path(@article), :method => :delete, :confirm => "Really delete the article?" %>
+ <%= link_to "delete", article_path(@article), :method => :delete, :confirm => "Really delete the article?" %>
+<% end %>
View
16 app/views/author_sessions/new.html.haml
@@ -0,0 +1,16 @@
+%h1 Login
+
+= form_tag author_sessions_path, :method => :post do
+ .field
+ = label_tag :username
+ = text_field_tag :username
+ %br/
+ .field
+ = label_tag :password
+ = password_field_tag :password
+ %br/
+ .actions
+ = submit_tag "Login"
+
+= link_to 'Back', articles_path
+
View
34 app/views/authors/_form.html.erb
@@ -0,0 +1,34 @@
+<%= form_for(@author) do |f| %>
+ <% if @author.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@author.errors.count, "error") %> prohibited this author from being saved:</h2>
+
+ <ul>
+ <% @author.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :username %><br />
+ <%= f.text_field :username %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.text_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %><br />
+ <%= f.text_field :password_confirmation %>
+ </div>
+ <div class="a
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/authors/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing author</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @author %> |
+<%= link_to 'Back', authors_path %>
View
29 app/views/authors/index.html.erb
@@ -0,0 +1,29 @@
+<h1>Listing authors</h1>
+
+<table>
+ <tr>
+ <th>Username</th>
+ <th>Email</th>
+ <th>Crypted password</th>
+ <th>Salt</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @authors.each do |author| %>
+ <tr>
+ <td><%= author.username %></td>
+ <td><%= author.email %></td>
+ <td><%= author.crypted_password %></td>
+ <td><%= author.salt %></td>
+ <td><%= link_to 'Show', author %></td>
+ <td><%= link_to 'Edit', edit_author_path(author) %></td>
+ <td><%= link_to 'Destroy', author, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Author', new_author_path %>
View
5 app/views/authors/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New author</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', authors_path %>
View
14 app/views/authors/show.html.erb
@@ -0,0 +1,14 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Username:</b>
+ <%= @author.username %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @author.email %>
+</p>
+
+<%= link_to 'Edit', edit_author_path(@author) %> |
+<%= link_to 'Back', authors_path %>
View
11 app/views/layouts/application.html.haml
@@ -8,5 +8,14 @@
%body
%p.flash
= flash[:message]
- = yield
+ #container
+ #content
+ = yield
+ %hr
+ %h6
+ - if logged_in?
+ = "Logged in as #{current_user.username}"
+ = link_to "(logout)", logout_path
+ - else
+ = link_to "(login)", login_path
View
386 config/initializers/sorcery.rb
@@ -0,0 +1,386 @@
+# The first thing you need to configure is which modules you need in your app.
+# The default is nothing which will include only core features (password encryption, login/logout).
+# Available submodules are: :user_activation, :http_basic_auth, :remember_me,
+# :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external
+Rails.application.config.sorcery.submodules = []
+
+# Here you can configure each submodule's features.
+Rails.application.config.sorcery.configure do |config|
+ # -- core --
+ # What controller action to call for non-authenticated users. You can also
+ # override the 'not_authenticated' method of course.
+ # Default: `:not_authenticated`
+ #
+ # config.not_authenticated_action =
+
+
+ # When a non logged in user tries to enter a page that requires login, save
+ # the URL he wanted to reach, and send him there after login, using 'redirect_back_or_to'.
+ # Default: `true`
+ #
+ # config.save_return_to_url =
+
+
+ # Set domain option for cookies; Useful for remember_me submodule.
+ # Default: `nil`
+ #
+ # config.cookie_domain =
+
+
+ # -- session timeout --
+ # How long in seconds to keep the session alive.
+ # Default: `3600`
+ #
+ # config.session_timeout =
+
+
+ # Use the last action as the beginning of session timeout.
+ # Default: `false`
+ #
+ # config.session_timeout_from_last_action =
+
+
+ # -- http_basic_auth --
+ # What realm to display for which controller name. For example {"My App" => "Application"}
+ # Default: `{"application" => "Application"}`
+ #
+ # config.controller_to_realm_map =
+
+
+ # -- activity logging --
+ # will register the time of last user login, every login.
+ # Default: `true`
+ #
+ # config.register_login_time =
+
+
+ # will register the time of last user logout, every logout.
+ # Default: `true`
+ #
+ # config.register_logout_time =
+
+
+ # will register the time of last user action, every action.
+ # Default: `true`
+ #
+ # config.register_last_activity_time =
+
+
+ # -- external --
+ # What providers are supported by this app, i.e. [:twitter, :facebook, :github, :google, :liveid] .
+ # Default: `[]`
+ #
+ # config.external_providers =
+
+
+ # You can change it by your local ca_file. i.e. '/etc/pki/tls/certs/ca-bundle.crt'
+ # Path to ca_file. By default use a internal ca-bundle.crt.
+ # Default: `'path/to/ca_file'`
+ #
+ # config.ca_file =
+
+
+ # Twitter wil not accept any requests nor redirect uri containing localhost,
+ # make sure you use 0.0.0.0:3000 to access your app in development
+ #
+ # config.twitter.key = ""
+ # config.twitter.secret = ""
+ # config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
+ # config.twitter.user_info_mapping = {:email => "screen_name"}
+ #
+ # config.facebook.key = ""
+ # config.facebook.secret = ""
+ # config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
+ # config.facebook.user_info_mapping = {:email => "name"}
+ #
+ # config.github.key = ""
+ # config.github.secret = ""
+ # config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
+ # config.github.user_info_mapping = {:email => "name"}
+ #
+ # config.google.key = ""
+ # config.google.secret = ""
+ # config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
+ # config.google.user_info_mapping = {:email => "email", :username => "name"}
+ #
+ # To use liveid in development mode you have to replace mydomain.com with
+ # a valid domain even in development. To use a valid domain in development
+ # simply add your domain in your /etc/hosts file in front of 127.0.0.1
+ #
+ # config.liveid.key = ""
+ # config.liveid.secret = ""
+ # config.liveid.callback_url = "http://mydomain.com:3000/oauth/callback?provider=liveid"
+ # config.liveid.user_info_mapping = {:username => "name"}
+
+
+ # --- user config ---
+ config.user_config do |user|
+ # -- core --
+ # specify username attributes, for example: [:username, :email].
+ # Default: `[:username]`
+ #
+ # user.username_attribute_names =
+
+
+ # change *virtual* password attribute, the one which is used until an encrypted one is generated.
+ # Default: `:password`
+ #
+ # user.password_attribute_name =
+
+
+ # downcase the username before trying to authenticate, default is false
+ # Default: `false`
+ #
+ # user.downcase_username_before_authenticating =
+
+
+ # change default email attribute.
+ # Default: `:email`
+ #
+ # user.email_attribute_name =
+
+
+ # change default crypted_password attribute.
+ # Default: `:crypted_password`
+ #
+ # user.crypted_password_attribute_name =
+
+
+ # what pattern to use to join the password with the salt
+ # Default: `""`
+ #
+ # user.salt_join_token =
+
+
+ # change default salt attribute.
+ # Default: `:salt`
+ #
+ # user.salt_attribute_name =
+
+
+ # how many times to apply encryption to the password.
+ # Default: `nil`
+ #
+ # user.stretches =
+
+
+ # encryption key used to encrypt reversible encryptions such as AES256.
+ # WARNING: If used for users' passwords, changing this key will leave passwords undecryptable!
+ # Default: `nil`
+ #
+ # user.encryption_key =
+
+
+ # use an external encryption class.
+ # Default: `nil`
+ #
+ # user.custom_encryption_provider =
+
+
+ # encryption algorithm name. See 'encryption_algorithm=' for available options.
+ # Default: `:bcrypt`
+ #
+ # user.encryption_algorithm =
+
+
+ # make this configuration inheritable for subclasses. Useful for ActiveRecord's STI.
+ # Default: `false`
+ #
+ # user.subclasses_inherit_config =
+
+
+ # -- user_activation --
+ # the attribute name to hold activation state (active/pending).
+ # Default: `:activation_state`
+ #
+ # user.activation_state_attribute_name =
+
+
+ # the attribute name to hold activation code (sent by email).
+ # Default: `:activation_token`
+ #
+ # user.activation_token_attribute_name =
+
+
+ # the attribute name to hold activation code expiration date.
+ # Default: `:activation_token_expires_at`
+ #
+ # user.activation_token_expires_at_attribute_name =
+
+
+ # how many seconds before the activation code expires. nil for never expires.
+ # Default: `nil`
+ #
+ # user.activation_token_expiration_period =
+
+
+ # your mailer class. Required.
+ # Default: `nil`
+ #
+ # user.user_activation_mailer =
+
+
+ # when true sorcery will not automatically
+ # email activation details and allow you to
+ # manually handle how and when email is sent.
+ # Default: `false`
+ #
+ # user.activation_mailer_disabled =
+
+
+ # activation needed email method on your mailer class.
+ # Default: `:activation_needed_email`
+ #
+ # user.activation_needed_email_method_name =
+
+
+ # activation success email method on your mailer class.
+ # Default: `:activation_success_email`
+ #
+ # user.activation_success_email_method_name =
+
+
+ # do you want to prevent or allow users that did not activate by email to login?
+ # Default: `true`
+ #
+ # user.prevent_non_active_users_to_login =
+
+
+ # -- reset_password --
+ # reset password code attribute name.
+ # Default: `:reset_password_token`
+ #
+ # user.reset_password_token_attribute_name =
+
+
+ # expires at attribute name.
+ # Default: `:reset_password_token_expires_at`
+ #
+ # user.reset_password_token_expires_at_attribute_name =
+
+
+ # when was email sent, used for hammering protection.
+ # Default: `:reset_password_email_sent_at`
+ #
+ # user.reset_password_email_sent_at_attribute_name =
+
+
+ # mailer class. Needed.
+ # Default: `nil`
+ #
+ # user.reset_password_mailer =
+
+
+ # reset password email method on your mailer class.
+ # Default: `:reset_password_email`
+ #
+ # user.reset_password_email_method_name =
+
+
+ # when true sorcery will not automatically
+ # email password reset details and allow you to
+ # manually handle how and when email is sent
+ # Default: `false`
+ #
+ # user.reset_password_mailer_disabled =
+
+
+ # reset password email
+ # method on your mailer
+ # class.
+ # Default: `:reset_password_email`
+ #
+ # user.reset_password_email_method_name =
+
+
+ # how many seconds before the reset request expires. nil for never expires.
+ # Default: `nil`
+ #
+ # user.reset_password_expiration_period =
+
+
+ # hammering protection, how long to wait before allowing another email to be sent.
+ # Default: `5 * 60`
+ #
+ # user.reset_password_time_between_emails =
+
+
+ # -- brute_force_protection --
+ # Failed logins attribute name.
+ # Default: `:failed_logins_count`
+ #
+ # user.failed_logins_count_attribute_name =
+
+
+ # This field indicates whether user is banned and when it will be active again.
+ # Default: `:lock_expires_at`
+ #
+ # user.lock_expires_at_attribute_name =
+
+
+ # How many failed logins allowed.
+ # Default: `50`
+ #
+ # user.consecutive_login_retries_amount_limit =
+
+
+ # How long the user should be banned. in seconds. 0 for permanent.
+ # Default: `60 * 60`
+ #
+ # user.login_lock_time_period =
+
+
+ # -- activity logging --
+ # Last login attribute name.
+ # Default: `:last_login_at`
+ #
+ # user.last_login_at_attribute_name =
+
+
+ # Last logout attribute name.
+ # Default: `:last_logout_at`
+ #
+ # user.last_logout_at_attribute_name =
+
+
+ # Last activity attribute name.
+ # Default: `:last_activity_at`
+ #
+ # user.last_activity_at_attribute_name =
+
+
+ # How long since last activity is he user defined logged out?
+ # Default: `10 * 60`
+ #
+ # user.activity_timeout =
+
+
+ # -- external --
+ # Class which holds the various external provider data for this user.
+ # Default: `nil`
+ #
+ # user.authentications_class =
+
+
+ # User's identifier in authentications class.
+ # Default: `:user_id`
+ #
+ # user.authentications_user_id_attribute_name =
+
+
+ # Provider's identifier in authentications class.
+ # Default: `:provider`
+ #
+ # user.provider_attribute_name =
+
+
+ # User's external unique identifier in authentications class.
+ # Default: `:uid`
+ #
+ # user.provider_uid_attribute_name =
+ end
+
+ # This line must come after the 'user config' block.
+ # Define which model authenticates with sorcery.
+ config.user_class = "Author"
+end
View
10 config/routes.rb
@@ -1,7 +1,13 @@
Blogger::Application.routes.draw do
- resources :articles
+ root :to => "articles#index"
+ resources :authors
+ resources :articles
resources :comments
-
resources :tags
+ resources :author_sessions
+
+ match 'login' => 'author_sessions#new', :as => :login
+ match 'logout' => 'author_sessions#destroy', :as => :logout
+
end
View
16 db/migrate/20120415170552_sorcery_core.rb
@@ -0,0 +1,16 @@
+class SorceryCore < ActiveRecord::Migration
+ def self.up
+ create_table :authors do |t|
+ t.string :username, :null => false # if you use another field as a username, for example email, you can safely remove this field.
+ t.string :email, :default => nil # if you use this field as a username, you might want to make it :null => false.
+ t.string :crypted_password, :default => nil
+ t.string :salt, :default => nil
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :authors
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120415163746) do
+ActiveRecord::Schema.define(:version => 20120415170552) do
create_table "articles", :force => true do |t|
t.string "title"
@@ -24,6 +24,15 @@
t.datetime "image_updated_at"
end
+ create_table "authors", :force => true do |t|
+ t.string "username", :null => false
+ t.string "email"
+ t.string "crypted_password"
+ t.string "salt"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "comments", :force => true do |t|
t.integer "article_id"
t.string "author_name"
View
11 test/fixtures/authors.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
View
49 test/functional/authors_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class AuthorsControllerTest < ActionController::TestCase
+ setup do
+ @author = authors(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:authors)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create author" do
+ assert_difference('Author.count') do
+ post :create, author: @author.attributes
+ end
+
+ assert_redirected_to author_path(assigns(:author))
+ end
+
+ test "should show author" do
+ get :show, id: @author
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @author
+ assert_response :success
+ end
+
+ test "should update author" do
+ put :update, id: @author, author: @author.attributes
+ assert_redirected_to author_path(assigns(:author))
+ end
+
+ test "should destroy author" do
+ assert_difference('Author.count', -1) do
+ delete :destroy, id: @author
+ end
+
+ assert_redirected_to authors_path
+ end
+end
View
7 test/unit/author_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AuthorTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/authors_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class AuthorsHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.