Permalink
Browse files

Created User Controller, Model and View for Sign Up or Create User, c…

…reated two integration tests, changed spec_helper due issues between the database_claner and sprok
  • Loading branch information...
xajler committed Oct 24, 2012
1 parent e4517a6 commit 7ee07ec64ca652f4840da8463ad3ce0d1efe64c6
@@ -0,0 +1,5 @@
class UsersController < ApplicationController
def new
@user = User.new
end
end
View
@@ -0,0 +1,5 @@
class User < ActiveRecord::Base
has_secure_password
attr_accessible :email, :password, :password_confirmation, :full_name
end
@@ -0,0 +1,10 @@
!!! 5
%html
%head
%title JustToDoIt
= stylesheet_link_tag 'application', media: 'all'
= javascript_include_tag 'application'
= csrf_meta_tags
%body
= yield
@@ -0,0 +1,25 @@
= form_for @user do |f|
- if @user.errors.any?
%div.error_messages
%h2 Form is invalid
%ul
- @user.errors.full_messages.each do |message|
%li= message
= f.label :email, 'Email:'
= f.text_field :email
%br
= f.label :password, 'Password:'
= f.text_field :password
%br
= f.label :password_confirmation, 'Confirm Password:'
= f.text_field :password_confirmation
%br
= f.label :full_name, 'Full Name:'
= f.text_field :full_name
%br
= f.submit 'Sign Up'
@@ -0,0 +1,3 @@
%h1 Sign Up
= render partial: 'form'
View
@@ -1,58 +1,4 @@
JustToDoIt::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
resources :users
get 'signup', to: 'users#new', as: 'signup'
end
@@ -0,0 +1,11 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email
t.string :password_digest
t.string :full_name
t.timestamps
end
end
end
View
@@ -0,0 +1,24 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121023234400) do
create_table "users", :force => true do |t|
t.string "email"
t.string "password_digest"
t.string "full_name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
View
@@ -0,0 +1,8 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :user do
email "MyString"
password_digest "MyString"
end
end
View
@@ -0,0 +1,5 @@
require 'spec_helper'
describe User do
pending "add some examples to (or delete) #{__FILE__}"
end
@@ -0,0 +1,35 @@
require 'spec_helper'
describe 'Users' do
context 'GET /users/new' do
it 'displays the create new user page' do
visit new_user_path
page.should have_content 'Email'
page.should have_content 'Full Name'
page.should have_content 'Password'
page.should have_content 'Confirm Password'
page.has_field? 'email'
page.has_field? 'full_name'
page.has_field? 'password'
page.has_field? 'password_confirmation'
page.has_button? 'Sign Up'
end
end
context 'GET /signup' do
it 'displays the sign up page' do
visit signup_path
page.should have_content 'Email'
page.should have_content 'Full Name'
page.should have_content 'Password'
page.should have_content 'Confirm Password'
page.has_field? 'email'
page.has_field? 'full_name'
page.has_field? 'password'
page.has_field? 'password_confirmation'
page.has_button? 'Sign Up'
end
end
end
View
@@ -1,5 +1,6 @@
require 'rubygems'
require 'spork'
require 'database_cleaner'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
@@ -9,28 +10,19 @@
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.mock_with :rspec
config.include FactoryGirl::Syntax::Methods
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.before :suite do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before do
DatabaseCleaner.start
end
config.after do
DatabaseCleaner.clean
end
end
end
end
Spork.each_run do
FactoryGirl.reload
DatabaseCleaner.clean
end

0 comments on commit 7ee07ec

Please sign in to comment.