Added Signup

This commit is contained in:
Saurabh Bhatia 2014-04-10 12:01:34 +08:00
parent 0ee2820cbd
commit 30ab17eb82
16 changed files with 170 additions and 81 deletions

70
Gemfile
View File

@ -1,47 +1,51 @@
source 'https://rubygems.org' source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' #rails gem
gem 'rails', '4.1.0.rc2' gem 'rails', '4.1.0.rc2'
gem 'mongoid', github: 'mongoid/mongoid'
# Use SCSS for stylesheets #assets and templates
gem 'sass-rails', '~> 4.0.0' gem 'sass-rails', '~> 4.0.2'
gem 'nokogiri'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0' gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0' gem 'coffee-rails', '~> 4.0.0'
gem 'announcement', path: '/Users/saurabhbhatia/announcement-test'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails' gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks' gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder #password
gem 'jbuilder', '~> 1.2' gem 'bcrypt-ruby', '~> 3.1.5'
gem "active_model_serializers"
group :doc do #json
# bundle exec rake doc:rails generates the API under doc/api. gem 'jbuilder', '~> 2.0'
gem 'sdoc', require: false gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', group: :development
gem 'active_model_serializers'
#parser
gem 'nokogiri'
#database
gem 'mongoid', github: "mongoid/mongoid"
#built in modules
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))
#modules installed from the store
eval(File.read(File.dirname(__FILE__) + '/downloaded_extensions.rb'))
#development related gems
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'guard-bundler'
gem 'guard-rails'
gem 'rails_layout'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
end end
# Use ActiveModel has_secure_password #testing gems
# gem 'bcrypt-ruby', '~> 3.1.2' group :test do
gem "minitest"
gem 'minitest-spec-rails'
end
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
gem 'debugger', '>= 1.6.6', group: [:development, :test] gem 'debugger', '>= 1.6.6', group: [:development, :test]

View File

@ -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://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,21 @@
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
redirect_to root_url, :notice => "Signed Up Successfully!"
else
render "new"
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :user_name)
end
end

17
app/models/user.rb Normal file
View File

@ -0,0 +1,17 @@
class User
include Mongoid::Document
include Mongoid::Timestamps
include ActiveModel::SecurePassword
field :user_name, type: String
field :email, type: String
field :password_digest, type:
has_secure_password
VALID_EMAIL_FORMAT = /\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z/
validates :user_name, presence: true, uniqueness: true
validates :password, presence: true, :on => :create, length: {:in => 8..20}
validates :email, presence: true, uniqueness: true, format: { with: VALID_EMAIL_FORMAT }
end

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>OrbitStore</title> <title>RulingOrbit</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "jquery11" %> <%= javascript_include_tag "jquery11" %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>

View File

@ -0,0 +1,2 @@
<h1>Users#create</h1>
<p>Find me in app/views/users/create.html.erb</p>

View File

@ -0,0 +1,33 @@
<h1>Sign Up</h1>
<%= form_for @user do |f| %>
<% if @user.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<ul>
<% for message in @user.errors.full_messages %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :user_name %>
<%= f.text_field :user_name %>
</div>
<div class="field">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions"><%= f.submit %></div>
<% end %>

1
built_in_extensions.rb Normal file
View File

@ -0,0 +1 @@
gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'

View File

@ -1,6 +1,6 @@
class KeywordConstraint class KeywordConstraint
def matches?(request) def matches?(request)
keywords = %w{admin member desktop} keywords = %w{admin member desktop user}
keywords.all? { |k| !request.url.include?(k) } keywords.all? { |k| !request.url.include?(k) }
end end
end end

View File

@ -1,5 +1,7 @@
OrbitStore::Application.routes.draw do OrbitStore::Application.routes.draw do
resources :users
get "/pages/edit_view" => "pages#edit_view" get "/pages/edit_view" => "pages#edit_view"
get "/pages/preview" => "pages#preview" get "/pages/preview" => "pages#preview"

0
downloaded_extensions.rb Normal file
View File

View File

@ -39,6 +39,4 @@ module SideBarRenderer
@active_for_controllers.include? controller @active_for_controllers.include? controller
end end
end end

View File

@ -1,49 +1,14 @@
require 'test_helper' require 'test_helper'
class UsersControllerTest < ActionController::TestCase class UsersControllerTest < ActionController::TestCase
setup do
@user = users(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:users)
end
test "should get new" do test "should get new" do
get :new get :new
assert_response :success assert_response :success
end end
test "should create user" do test "should get create" do
assert_difference('User.count') do get :create
post :create, user: { first_name: @user.first_name, last_name: @user.last_name }
end
assert_redirected_to user_path(assigns(:user))
end
test "should show user" do
get :show, id: @user
assert_response :success assert_response :success
end end
test "should get edit" do
get :edit, id: @user
assert_response :success
end
test "should update user" do
patch :update, id: @user, user: { first_name: @user.first_name, last_name: @user.last_name }
assert_redirected_to user_path(assigns(:user))
end
test "should destroy user" do
assert_difference('User.count', -1) do
delete :destroy, id: @user
end
assert_redirected_to users_path
end
end end

View File

@ -1,9 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: one:
first_name: MyString user_name: MyString
last_name: MyString email: MyString
password_digest: MyString
two: two:
first_name: MyString user_name: MyString
last_name: MyString email: MyString
password_digest: MyString

View File

@ -1,7 +1,45 @@
#this is a class to test the signup
require 'test_helper' require 'test_helper'
require 'minitest/autorun'
class UserTest < ActiveSupport::TestCase class UserTest < ActiveSupport::TestCase
# test "the truth" do def valid_params
# assert true { user_name: "johndoe", email: "john@example.com", password: "password123", password_confirmation: "password123" }
# end end
let(:user) { User.new valid_params }
it "should fail when password and password confirmation do not match" do
def user.password_confirmation
"password456"
end
user.wont_be :valid?
end
it "should not pass when email not supplied" do
def user.email
nil
end
user.wont_be :valid?
user.errors[:email].must_be :present?
end
it "should not pass when user_name not supplied" do
def user.user_name
nil
end
user.wont_be :valid?
user.errors[:user_name].must_be :present?
end
it "should pass when password and password confirmation are same" do
assert user.must_be :valid?, "Can't create with valid params: #{user.errors.messages}"
end
it "should check the email format" do
def user.email
"fsdnjgsjk@lo;;sdfd"
end
user.wont_be :valid?
end
end end