-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
class APIRoutes < Grape::API | ||
use ActionDispatch::Session::CookieStore, key: '_sbhacks_session' | ||
format :json | ||
|
||
helpers APIHelpers | ||
|
||
mount API::Auth | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class User < ApplicationRecord | ||
has_secure_password | ||
|
||
validates :name, presence: true | ||
validates :email, format: { | ||
with: URI::MailTo::EMAIL_REGEXP, | ||
message: 'is not a valid email address' | ||
} | ||
validates :password, length: { in: 8..72 } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateUsers < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :users do |t| | ||
t.string :name, nil: false | ||
t.string :email, index: { unique: true }, nil: false | ||
t.string :password_digest, nil: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | ||
# Character.create(name: 'Luke', movie: movies.first) | ||
User.create!( | ||
name: 'SBHacks Admin', | ||
email: '[email protected]', | ||
password: 'password' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryBot.define do | ||
factory :user do | ||
name { 'Akshay Heda' } | ||
sequence :email do |n| | ||
"akshay.#{n}@example.com" | ||
end | ||
password { 'ilovesbhacks' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'test_helper' | ||
|
||
class UserTest < ActiveSupport::TestCase | ||
test 'factory is valid' do | ||
assert_predicate build(:user), :valid? | ||
end | ||
|
||
test 'requires a name' do | ||
user = build(:user) | ||
user.name = nil | ||
assert_not_predicate user, :valid? | ||
|
||
user.name = '' | ||
assert_not_predicate user, :valid? | ||
end | ||
|
||
test 'requires a valid email address' do | ||
user = build(:user) | ||
user.email = 'not an email' | ||
assert_not_predicate user, :valid? | ||
end | ||
|
||
test 'requires a password' do | ||
user = build(:user) | ||
user.password = nil | ||
assert_not_predicate user, :valid? | ||
|
||
user.password = 'short' | ||
assert_not_predicate user, :valid? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters