forked from saurabh/orbit4-5
Added Signup
This commit is contained in:
parent
0ee2820cbd
commit
30ab17eb82
70
Gemfile
70
Gemfile
|
@ -1,47 +1,51 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||
#rails gem
|
||||
gem 'rails', '4.1.0.rc2'
|
||||
gem 'mongoid', github: 'mongoid/mongoid'
|
||||
|
||||
# Use SCSS for stylesheets
|
||||
gem 'sass-rails', '~> 4.0.0'
|
||||
gem 'nokogiri'
|
||||
|
||||
|
||||
# Use Uglifier as compressor for JavaScript assets
|
||||
#assets and templates
|
||||
gem 'sass-rails', '~> 4.0.2'
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
|
||||
# Use CoffeeScript for .js.coffee assets and views
|
||||
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'
|
||||
|
||||
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
||||
gem 'turbolinks'
|
||||
|
||||
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
||||
gem 'jbuilder', '~> 1.2'
|
||||
gem "active_model_serializers"
|
||||
#password
|
||||
gem 'bcrypt-ruby', '~> 3.1.5'
|
||||
|
||||
group :doc do
|
||||
# bundle exec rake doc:rails generates the API under doc/api.
|
||||
gem 'sdoc', require: false
|
||||
#json
|
||||
gem 'jbuilder', '~> 2.0'
|
||||
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
|
||||
|
||||
# Use ActiveModel has_secure_password
|
||||
# gem 'bcrypt-ruby', '~> 3.1.2'
|
||||
#testing gems
|
||||
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]
|
|
@ -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/
|
|
@ -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/
|
|
@ -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
|
|
@ -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
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OrbitStore</title>
|
||||
<title>RulingOrbit</title>
|
||||
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
||||
<%= javascript_include_tag "jquery11" %>
|
||||
<%= csrf_meta_tags %>
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
<h1>Users#create</h1>
|
||||
<p>Find me in app/views/users/create.html.erb</p>
|
|
@ -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 %>
|
|
@ -0,0 +1 @@
|
|||
gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'
|
|
@ -1,6 +1,6 @@
|
|||
class KeywordConstraint
|
||||
def matches?(request)
|
||||
keywords = %w{admin member desktop}
|
||||
keywords = %w{admin member desktop user}
|
||||
keywords.all? { |k| !request.url.include?(k) }
|
||||
end
|
||||
end
|
|
@ -1,5 +1,7 @@
|
|||
OrbitStore::Application.routes.draw do
|
||||
|
||||
resources :users
|
||||
|
||||
get "/pages/edit_view" => "pages#edit_view"
|
||||
get "/pages/preview" => "pages#preview"
|
||||
|
||||
|
|
|
@ -39,6 +39,4 @@ module SideBarRenderer
|
|||
@active_for_controllers.include? controller
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -1,49 +1,14 @@
|
|||
require 'test_helper'
|
||||
|
||||
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
|
||||
get :new
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create user" do
|
||||
assert_difference('User.count') do
|
||||
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
|
||||
test "should get create" do
|
||||
get :create
|
||||
assert_response :success
|
||||
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
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
first_name: MyString
|
||||
last_name: MyString
|
||||
user_name: MyString
|
||||
email: MyString
|
||||
password_digest: MyString
|
||||
|
||||
two:
|
||||
first_name: MyString
|
||||
last_name: MyString
|
||||
user_name: MyString
|
||||
email: MyString
|
||||
password_digest: MyString
|
||||
|
|
|
@ -1,7 +1,45 @@
|
|||
#this is a class to test the signup
|
||||
require 'test_helper'
|
||||
require 'minitest/autorun'
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
def valid_params
|
||||
{ user_name: "johndoe", email: "john@example.com", password: "password123", password_confirmation: "password123" }
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue