generic_app 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'generic_app'
3
+ require 'string_in_file'
4
+
5
+ describe GenericApp do
6
+ it "SQLite version should execute" do
7
+ puts
8
+ puts "****************************"
9
+ puts "Testing the SQLite procedure"
10
+ system("rm -rf tmp1")
11
+ GenericApp.sq("tmp1")
12
+ GenericApp.git_init("tmp1")
13
+
14
+ end
15
+
16
+ it "Bash scripts should be provided" do
17
+ expect(StringInFile.present("heroku run rake db:migrate", "tmp1/heroku_upload.sh")).to eq(true)
18
+ expect(StringInFile.present("pkill", "tmp1/kill_spring.sh")).to eq(true)
19
+ expect(StringInFile.present("ls -R1 -I concerns app/controllers", "tmp1/list_files.sh")).to eq(true)
20
+ expect(StringInFile.present("rails console --sandbox", "tmp1/sandbox.sh")).to eq(true)
21
+ expect(StringInFile.present("rake db:seed", "tmp1/seed.sh")).to eq(true)
22
+ expect(StringInFile.present("rails server -b 0.0.0.0", "tmp1/server.sh")).to eq(true)
23
+ expect(StringInFile.present("bundle install", "tmp1/test.sh")).to eq(true)
24
+ end
25
+
26
+ it "New README.md file should be provided" do
27
+ expect(StringInFile.present("list_files.sh", "tmp1/README.md")).to eq(true)
28
+ end
29
+
30
+ it "Guardfile should be set to automatically run tests upon startup" do
31
+ expect(StringInFile.present("all_on_start: true", "tmp1/Guardfile")).to eq(true)
32
+ end
33
+
34
+ it "Suggestions to use password management software should be provided" do
35
+ expect(StringInFile.present("KeePassX", "tmp1/app/views/users/new.html.erb")).to eq(true)
36
+ expect(StringInFile.present("KeePassX", "tmp1/app/views/users/edit.html.erb")).to eq(true)
37
+ expect(StringInFile.present("KeePassX", "tmp1/app/views/password_resets/new.html.erb")).to eq(true)
38
+ expect(StringInFile.present("KeePassX", "tmp1/app/views/password_resets/edit.html.erb")).to eq(true)
39
+ end
40
+
41
+ it "The .gitignore file includes tmp, tmp*, and ,DS_Store" do
42
+ expect(StringInFile.present("tmp", "tmp1/.gitignore")).to eq(true)
43
+ expect(StringInFile.present("tmp*", "tmp1/.gitignore")).to eq(true)
44
+ expect(StringInFile.present(".DS_Store", "tmp1/.gitignore")).to eq(true)
45
+ end
46
+
47
+ it "The notes/1-file_list.txt file should be in place" do
48
+ expect(StringInFile.present("app/models", "tmp1/notes/1-file_list.txt")).to eq(true)
49
+ expect(StringInFile.present("app/views", "tmp1/notes/1-file_list.txt")).to eq(true)
50
+ expect(StringInFile.present("app/controllers", "tmp1/notes/1-file_list.txt")).to eq(true)
51
+ end
52
+
53
+ it "The notes/mvc-users.txt file should be in place" do
54
+ expect(StringInFile.present("app/controllers/users_controller.rb", "tmp1/notes/mvc-users.txt")).to eq(true)
55
+ expect(StringInFile.present("test/controllers/users_controller_test.rb", "tmp1/notes/mvc-users.txt")).to eq(true)
56
+ expect(StringInFile.present("app/helpers/users_helper.rb", "tmp1/notes/mvc-users.txt")).to eq(true)
57
+ expect(StringInFile.present("def index", "tmp1/notes/mvc-users.txt")).to eq(true)
58
+ expect(StringInFile.present("def show", "tmp1/notes/mvc-users.txt")).to eq(true)
59
+ end
60
+
61
+ end
62
+
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'generic_app'
3
+ require 'string_in_file'
4
+
5
+ describe GenericApp do
6
+ it "PostgreSQL version should execute" do
7
+ puts
8
+ puts "********************************"
9
+ puts "Testing the PostgreSQL procedure"
10
+ system("rm -rf tmp2")
11
+
12
+ n = Time.now.to_i
13
+
14
+ GenericApp.pg("tmp2", "db_tmp2_#{n}", "eu_tmp2_#{n}", "ep_tmp2_#{n}", "u_tmp2_#{n}", "abcdef")
15
+
16
+ GenericApp.git_init("tmp2")
17
+
18
+ expect(StringInFile.present("sqlite", "tmp2/Gemfile")).to eq(false)
19
+ expect(StringInFile.present("gem 'pg'", "tmp2/Gemfile")).to eq(true)
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'generic_app'
3
+ require 'string_in_file'
4
+
5
+ describe GenericApp do
6
+ it "PostgreSQL version works with changed parameters" do
7
+ puts
8
+ puts "************************************************************************************"
9
+ puts "Testing the PostgreSQL procedure given new databases, a new user, and a new password"
10
+ puts "Copying the PostgreSQL-based Rails app previously created."
11
+ system("rm -rf tmp3")
12
+ t1 = Thread.new {
13
+ system("cp -rf tmp2 tmp3")
14
+ }
15
+ t1.join
16
+ n = (Time.now.to_i ) * 2
17
+
18
+ GenericApp.set_pg_params("tmp3", "db_tmp3_#{n}", "eu_tmp3_#{n}", "ep_tmp3_#{n}", "u_tmp3_#{n}", "fedcba")
19
+
20
+ expect(StringInFile.present("sqlite", "tmp3/Gemfile")).to eq(false)
21
+ expect(StringInFile.present("gem 'pg'", "tmp3/Gemfile")).to eq(true)
22
+ expect(StringInFile.present("u_tmp3_#{n}", "tmp3/config/application.yml")).to eq(true)
23
+ expect(StringInFile.present("fedcba", "tmp3/config/application.yml")).to eq(true)
24
+ expect(StringInFile.present("eu_tmp3_#{n}", "tmp3/config/application.yml")).to eq(true)
25
+ expect(StringInFile.present("ep_tmp3_#{n}", "tmp3/config/application.yml")).to eq(true)
26
+ expect(StringInFile.present("db_tmp3_#{n}_dev", "tmp3/config/database.yml")).to eq(true)
27
+ expect(StringInFile.present("db_tmp3_#{n}_test", "tmp3/config/database.yml")).to eq(true)
28
+ expect(StringInFile.present("db_tmp3_#{n}_pro", "tmp3/config/database.yml")).to eq(true)
29
+ expect(StringInFile.present("eu_tmp3_#{n}", "tmp3/config/database.yml")).to eq(true)
30
+ expect(StringInFile.present("ep_tmp3_#{n}", "tmp3/config/database.yml")).to eq(true)
31
+ end
32
+ end
33
+
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'generic_app'
3
+ require 'string_in_file'
4
+
5
+ describe GenericApp do
6
+
7
+ it "Adding scripts to an existing app should work" do
8
+ puts
9
+ puts "********************************************************"
10
+ puts "Testing the addition of scripts to an existing Rails app"
11
+ system("rm -rf tmp4")
12
+ t1 = Thread.new {
13
+ system("git clone https://github.com/mhartl/sample_app_3rd_edition.git tmp4")
14
+ }
15
+ t1.join
16
+ GenericApp.add_scripts ("tmp4")
17
+ GenericApp.update_gitignore ("tmp4")
18
+ end
19
+
20
+ it "Bash scripts should be provided" do
21
+ expect(StringInFile.present("heroku run rake db:migrate", "tmp4/heroku_upload.sh")).to eq(true)
22
+ expect(StringInFile.present("pkill", "tmp4/kill_spring.sh")).to eq(true)
23
+ expect(StringInFile.present("ls -R1 -I concerns app/controllers", "tmp4/list_files.sh")).to eq(true)
24
+ expect(StringInFile.present("rails console --sandbox", "tmp4/sandbox.sh")).to eq(true)
25
+ expect(StringInFile.present("rake db:seed", "tmp4/seed.sh")).to eq(true)
26
+ expect(StringInFile.present("rails server -b 0.0.0.0", "tmp4/server.sh")).to eq(true)
27
+ expect(StringInFile.present("bundle install", "tmp4/test.sh")).to eq(true)
28
+ end
29
+
30
+ it "The .gitignore file includes tmp, tmp*, and ,DS_Store" do
31
+ expect(StringInFile.present("tmp", "tmp4/.gitignore")).to eq(true)
32
+ expect(StringInFile.present("tmp*", "tmp4/.gitignore")).to eq(true)
33
+ expect(StringInFile.present(".DS_Store", "tmp4/.gitignore")).to eq(true)
34
+ end
35
+
36
+ it "The notes/1-file_list.txt file should be in place" do
37
+ expect(StringInFile.present("app/models", "tmp4/notes/1-file_list.txt")).to eq(true)
38
+ expect(StringInFile.present("app/views", "tmp4/notes/1-file_list.txt")).to eq(true)
39
+ expect(StringInFile.present("app/controllers", "tmp4/notes/1-file_list.txt")).to eq(true)
40
+ end
41
+
42
+ end
43
+
data/to_add/README.md CHANGED
@@ -1,13 +1,8 @@
1
1
  # Generic App
2
2
 
3
- This is the generic Rails app created with the use of the generic_app Ruby
4
- gem. More details on the generic_app Ruby gem are available at
5
- https://github.com/jhsu802701/generic_app .
3
+ This is the generic Rails app created with the use of the generic_app Ruby gem. More details on the generic_app Ruby gem are available at https://github.com/jhsu802701/generic_app .
6
4
 
7
- This app consists of all of the features of the Rails Tutorial Sample App
8
- except for microposts and relationships. The basic elements essential to
9
- most Rails apps are included. It is up to you to customize this app and
10
- add the features and capabilities specific to your endeavor.
5
+ This app consists of all of the features of the Rails Tutorial Sample App except for microposts and relationships. The basic elements essential to most Rails apps are included. It is up to you to customize this app and add the features and capabilities specific to your endeavor.
11
6
 
12
7
  The original Rails Tutorial Sample App provides the following features:
13
8
 
@@ -17,41 +12,21 @@ The original Rails Tutorial Sample App provides the following features:
17
12
  4. Twitter bootstrap
18
13
  5. Databases: SQLite3 for development and PostgreSQL for production
19
14
  6. Ready for Heroku deployment
20
- 7. User functionality: includes hashed passwords, administrative users,
21
- account activations, and password resets
22
-
23
- This generic Rails app provides the above features PLUS these additional
24
- features:
25
-
26
- 1. Bash scripts in the root directory that allow you to perform routine
27
- tasks in only one step. (These scripts are likely to be useful in Rails
28
- apps that were not created with this generic_app Ruby gem.)
29
- 2. Recommendations that the user make use of password management software
30
- to generate and store secure passwords
31
- 3. Outlines of the MVC, test suite, and database seeding process in the
32
- notes folder
15
+ 7. User functionality: includes hashed passwords, administrative users, account activations, and password resets
16
+
17
+ This generic Rails app provides the above features PLUS these additional features:
18
+
19
+ 1. Bash scripts in the root directory that allow you to perform routine tasks in only one step. (These scripts are likely to be useful in Rails apps that were not created with this generic_app Ruby gem.)
20
+ 2. Recommendations that the user make use of password management software to generate and store secure passwords
21
+ 3. Outlines of the MVC, test suite, and database seeding process in the notes folder
33
22
  4. Guard automatically runs tests upon startup.
34
23
 
35
- To execute the Bash (*.sh) scripts, enter the command "sh (name of script)".
36
- The Bash scripts provided are:
37
-
38
- 1. setup.sh: When you first create the app, or anytime that you clone
39
- this app, you must run the setup.sh script to set up the app. This is a
40
- prerequisite for running Guard, running the local server, and many other
41
- basic tasks.
42
- 2. server.sh: This script runs your local Rails server. Note that it
43
- specifies port 0.0.0.0 so that you can view your Rails app in your web
44
- browser when you do your Rails development in Vagrant.
45
- 3. seed.sh: This script populates the database in the development environment
46
- with simulated data.
24
+ To execute the Bash (*.sh) scripts, enter the command "sh (name of script)". The Bash scripts provided are:
25
+
26
+ 1. test.sh: When you first create the app, or anytime that you clone this app, you must run the setup.sh script to set up the app. This is a prerequisite for running Guard, running the local server, and many other basic tasks.
27
+ 2. server.sh: This script runs your local Rails server. Note that it specifies port 0.0.0.0 so that you can view your Rails app in your web browser when you do your Rails development in Vagrant.
28
+ 3. seed.sh: This script populates the database in the development environment with simulated data.
47
29
  4. sandbox.sh: This script gives you the Rails console sandbox environment.
48
- 5. heroku_upload.sh: This script uploads your Rails source code to Heroku
49
- AND runs the "rake db:migrate" command in the Heroku environment.
50
- 6. kill_spring.sh: The Spring tool is useful but may occasionally slow
51
- down your Rails app. If you believe that this is happening, run this script
52
- to kill the Spring tool.
53
- 7. list_files.sh: This script prints outlines of the path structure of
54
- the MVC and testing architectures in your Rails app into the file
55
- notes/list_files.txt. While this script has no impact on how your Rails
56
- app runs, it aids the process of outlining the MVC structure and the testing
57
- procedure in your app.
30
+ 5. heroku_upload.sh: This script uploads your Rails source code to Heroku AND runs the "rake db:migrate" command in the Heroku environment.
31
+ 6. kill_spring.sh: The Spring tool is useful but may occasionally slow down your Rails app. If you believe that this is happening, run this script to kill the Spring tool.
32
+ 7. list_files.sh: This script prints outlines of the path structure of the MVC and testing architectures in your Rails app into the file notes/1-list_files.txt. While this script has no impact on how your Rails app runs, it aids the process of outlining the MVC structure and the testing procedure in your app.
data/to_add/list_files.sh CHANGED
@@ -1,25 +1,42 @@
1
1
  #!/bin/bash
2
2
  # Proper header for a Bash script.
3
3
 
4
- echo "This file was AUTOMATICALLY generated by the list_files.sh script." > notes/file_list.txt
4
+ echo "****************************************************************"
5
+ echo "BEGIN compiling the list of files that make up the MVC structure"
5
6
 
6
- echo "" >> notes/file_list.txt
7
- ls -R1 -I concerns app/controllers >> notes/file_list.txt
7
+ mkdir -p notes
8
8
 
9
- echo "" >> notes/file_list.txt
10
- ls -R1 -I concerns app/helpers >> notes/file_list.txt
9
+ echo "This file was AUTOMATICALLY generated by the list_files.sh script." > notes/1-file_list.txt
11
10
 
12
- echo "" >> notes/file_list.txt
13
- ls -R1 -I concerns app/mailers >> notes/file_list.txt
11
+ echo "" >> notes/1-file_list.txt
12
+ ls -R1 -I concerns app/controllers >> notes/1-file_list.txt
14
13
 
15
- echo "" >> notes/file_list.txt
16
- ls -R1 -I concerns app/models >> notes/file_list.txt
14
+ echo "" >> notes/1-file_list.txt
15
+ ls -R1 -I concerns app/helpers >> notes/1-file_list.txt
17
16
 
18
- echo "" >> notes/file_list.txt
19
- ls -R1 -I concerns app/views >> notes/file_list.txt
17
+ echo "" >> notes/1-file_list.txt
18
+ ls -R1 -I concerns app/mailers >> notes/1-file_list.txt
20
19
 
21
- echo "" >> notes/file_list.txt
22
- ls -R1 -I concerns db >> notes/file_list.txt
20
+ echo "" >> notes/1-file_list.txt
21
+ ls -R1 -I concerns app/models >> notes/1-file_list.txt
23
22
 
24
- echo "" >> notes/file_list.txt
25
- ls -R1 -I concerns test >> notes/file_list.txt
23
+ echo "" >> notes/1-file_list.txt
24
+ ls -R1 -I concerns app/views >> notes/1-file_list.txt
25
+
26
+ echo "" >> notes/1-file_list.txt
27
+ ls -R1 -I concerns db >> notes/1-file_list.txt
28
+
29
+ echo "" >> notes/1-file_list.txt
30
+ ls -R1 -I concerns features >> notes/1-file_list.txt
31
+
32
+ echo "" >> notes/1-file_list.txt
33
+ ls -R1 -I concerns spec >> notes/1-file_list.txt
34
+
35
+ echo "" >> notes/1-file_list.txt
36
+ ls -R1 -I concerns test >> notes/1-file_list.txt
37
+
38
+ echo "" >> notes/1-file_list.txt
39
+ cat config/routes.rb >> notes/1-file_list.txt
40
+
41
+ echo "FINISHED compiling the list of files that make up the MVC structure"
42
+ echo "*******************************************************************"
@@ -0,0 +1,9 @@
1
+ # NOTES DIRECTORY
2
+
3
+ ## 1-file_list.txt
4
+
5
+ * The file 1-file_list.txt lists the contents of the app/controllers, app/helpers, app/mailers, app/views, db, features, spec, and test directories.
6
+
7
+ * The file 1-file_list.txt is AUTOMATICALLY generated by the list_files.sh script. Please do NOT manually edit the 1-file_list.txt file, because your changes will be wiped out the next time you run the list_files.sh script.
8
+
9
+ * The purpose of this file is to aid the process of outlining the MVC structure of this Rails app.
@@ -0,0 +1,77 @@
1
+ ============
2
+ db/schema.rb
3
+ create_table "users", force: :cascade do |t|
4
+ t.string "name"
5
+ t.string "email"
6
+ t.datetime "created_at", null: false
7
+ t.datetime "updated_at", null: false
8
+ t.string "password_digest"
9
+ t.string "remember_digest"
10
+ t.boolean "admin", default: false
11
+ t.string "activation_digest"
12
+ t.boolean "activated", default: false
13
+ t.datetime "activated_at"
14
+ t.string "reset_digest"
15
+ t.datetime "reset_sent_at"
16
+ end
17
+
18
+ add_index "users", ["email"], name: "index_users_on_email", unique: true
19
+
20
+ ===========
21
+ db/migrate:
22
+ 20141014183645_create_users.rb
23
+ def change
24
+ create_table :users do |t|
25
+ t.string :name
26
+ t.string :email
27
+
28
+ t.timestamps null: false
29
+ end
30
+ end
31
+ 20141014205756_add_index_to_users_email.rb
32
+ def change
33
+ add_index :users, :email, unique: true
34
+ end
35
+ 20141014234032_add_password_digest_to_users.rb
36
+ def change
37
+ add_column :users, :password_digest, :string
38
+ end
39
+ 20141030174712_add_remember_digest_to_users.rb
40
+ def change
41
+ add_column :users, :remember_digest, :string
42
+ end
43
+ 20141104004736_add_admin_to_users.rb
44
+ def change
45
+ add_column :users, :admin, :boolean, default: false
46
+ end
47
+ 20141106193737_add_activation_to_users.rb
48
+ def change
49
+ add_column :users, :activation_digest, :string
50
+ add_column :users, :activated, :boolean, default: false
51
+ add_column :users, :activated_at, :datetime
52
+ end
53
+ 20141107180258_add_reset_to_users.rb
54
+ def change
55
+ add_column :users, :reset_digest, :string
56
+ add_column :users, :reset_sent_at, :datetime
57
+ end
58
+ ===========
59
+ db/seeds.rb
60
+ User.create!(name: "Example User",
61
+ email: "example@railstutorial.org",
62
+ password: "foobar",
63
+ password_confirmation: "foobar",
64
+ admin: true,
65
+ activated: true,
66
+ activated_at: Time.zone.now)
67
+ 99.times do |n|
68
+ name = Faker::Name.name
69
+ email = "example-#{n+1}@railstutorial.org"
70
+ password = "password"
71
+ User.create!(name: name,
72
+ email: email,
73
+ password: password,
74
+ password_confirmation: password,
75
+ activated: true,
76
+ activated_at: Time.zone.now)
77
+ end
@@ -0,0 +1,19 @@
1
+ TABLES
2
+ users (name, email, created_at, updated_at, timestamps, password_digest, remember_digest, admin, activation_digest, activated, activated_at, reset_digest, reset_sent_at)
3
+ index: named "index_users_on_email", based on email (must be unique)
4
+
5
+ SEED
6
+ Create user
7
+ name: "Example User",
8
+ email: "example@railstutorial.org",
9
+ password: "foobar",
10
+ password_confirmation: "foobar",
11
+ admin: true,
12
+ activated: true,
13
+ activated_at: Time.zone.now
14
+ Create users example-1@railstutorial.org to example-99@railstutorial.org
15
+ name = Faker::Name.name
16
+ email = "example-#{n+1}@railstutorial.org",
17
+ password, password_confirmation = "password"
18
+ activated: true,
19
+ activated_at: Time.zone.now)
@@ -0,0 +1,10 @@
1
+ ACCOUNT ACTIVATIONS
2
+ app/controllers/account_activations_controller.rb
3
+ def edit
4
+ test/controllers/account_activations_controller_test.rb
5
+ app/helpers/account_activations_helper.rb
6
+ app/views/user_mailer/account_activation.html.erb
7
+ app/views/user_mailer/account_activation.text.erb
8
+ config/routes.rb
9
+ get 'account_activations/edit'
10
+ resources :account_activations, only: [:edit]
@@ -0,0 +1,7 @@
1
+ APPLICATION
2
+ app/controllers/application_controller.rb
3
+ include SessionsHelper
4
+ app/helpers/application_helper.rb
5
+ def full_title(page_title = '')
6
+ app/mailers/application_mailer.rb
7
+ app/views/layouts/application.html.erb
@@ -0,0 +1,9 @@
1
+ LAYOUTS
2
+
3
+ app/views/layouts
4
+ application.html.erb
5
+ _footer.html.erb
6
+ _header.html.erb
7
+ mailer.html.erb
8
+ mailer.text.erb
9
+ _shim.html.erb
@@ -0,0 +1,25 @@
1
+ app/controllers/password_resets_controller.rb
2
+ before_action :get_user, only: [:edit, :update]
3
+ before_action :valid_user, only: [:edit, :update]
4
+ before_action :check_expiration, only: [:edit, :update]
5
+ def new
6
+ def create
7
+ def edit
8
+ def update
9
+ private
10
+ def user_params
11
+ def both_passwords_blank?
12
+ def get_user
13
+ def valid_user
14
+ def check_expiration
15
+ app/helpers/password_resets_helper.rb
16
+ app/views/password_resets
17
+ edit.html.erb
18
+ new.html.erb
19
+ app/views/user_mailer
20
+ password_reset.html.erb
21
+ password_reset.text.erb
22
+ config/routes.rb
23
+ get 'password_resets/new'
24
+ get 'password_resets/edit'
25
+ resources :password_resets, only: [:new, :create, :edit, :update]
@@ -0,0 +1,27 @@
1
+ SESSIONS
2
+ app/controllers/sessions_controller.rb
3
+ def new
4
+ def create
5
+ def destroy
6
+ test/controllers/sessions_controller_test.rb
7
+ test "should get new" do
8
+ app/helpers/sessions_helper.rb
9
+ def log_in(user)
10
+ def remember(user)
11
+ def current_user?(user)
12
+ def current_user
13
+ def logged_in?
14
+ def forget(user)
15
+ def log_out
16
+ def redirect_back_or(default)
17
+ def store_location
18
+ test/helpers/sessions_helper_test.rb
19
+ def setup
20
+ test "current_user returns right user when session is nil" do
21
+ test "current_user returns nil when remember digest is wrong" do
22
+ app/views/sessions/new.html.erb
23
+ config/routes.rb
24
+ get 'sessions/new'
25
+ get 'login' => 'sessions#new'
26
+ post 'login' => 'sessions#create'
27
+ delete 'logout' => 'sessions#destroy'
@@ -0,0 +1,4 @@
1
+ SHARED VIEWS
2
+
3
+ app/views/shared
4
+ _error_messages.html.erb
@@ -0,0 +1,22 @@
1
+ STATIC PAGES
2
+ app/controllers/static_pages_controller.rb
3
+ def home
4
+ def help
5
+ def about
6
+ def contact
7
+ test/controllers/static_pages_controller_test.rb
8
+ test "should get home" do
9
+ test "should get help" do
10
+ test "should get about" do
11
+ test "should get contact" do
12
+ app/helpers/static_pages_helper.rb
13
+ app/views/static_pages
14
+ about.html.erb
15
+ contact.html.erb
16
+ help.html.erb
17
+ home.html.erb
18
+ config/routes.rb
19
+ root 'static_pages#home'
20
+ get 'help' => 'static_pages#help'
21
+ get 'about' => 'static_pages#about'
22
+ get 'contact' => 'static_pages#contact'
@@ -0,0 +1,96 @@
1
+ USERS
2
+
3
+ app/controllers/users_controller.rb
4
+ before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
5
+ before_action :correct_user, only: [:edit, :update]
6
+ before_action :admin_user, only: :destroy
7
+ def index
8
+ def show
9
+ def new
10
+ def create
11
+ def edit
12
+ def update
13
+ def destroy
14
+ private
15
+ def user_params
16
+ def logged_in_user
17
+ def correct_user
18
+ def admin_user
19
+ test/controllers/users_controller_test.rb
20
+ users_controller_test.rb
21
+ def setup
22
+ test "should redirect index when not logged in" do
23
+ test "should get new" do
24
+ test "should redirect edit when not logged in" do
25
+ test "should redirect update when not logged in" do
26
+ test "should redirect edit when logged in as wrong user" do
27
+ test "should redirect update when logged in as wrong user" do
28
+ test "should redirect destroy when not logged in" do
29
+ test "should redirect destroy when logged in as a non-admin" do
30
+ app/helpers/users_helper.rb
31
+ def gravatar_for(user, options = { size: 80 })
32
+ app/mailers/user_mailer.rb
33
+ def account_activation(user)
34
+ def password_reset(user)
35
+ test/mailers/user_mailer_test.rb
36
+ test "account_activation" do
37
+ test "password_reset" do
38
+ test/mailers/previews/user_mailer_preview.rb
39
+ # Preview this email at http://localhost:3000/rails/mailers/user_mailer/account_activation
40
+ def account_activation
41
+ # Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset
42
+ def password_reset
43
+ app/models/user.rb
44
+ attr_accessor :remember_token, :activation_token, :reset_token
45
+ before_save :downcase_email
46
+ before_create :create_activation_digest
47
+ validates :name, presence: true, length: { maximum: 50 }
48
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\-.]+\.[a-z]+\z/i
49
+ validates :email, presence: true, length: { maximum: 255 },
50
+ format: { with: VALID_EMAIL_REGEX },
51
+ uniqueness: { case_sensitive: false }
52
+ has_secure_password
53
+ validates :password, length: { minimum: 6 }, allow_blank: true
54
+ def User.digest(string)
55
+ def User.new_token
56
+ def remember
57
+ def forget
58
+ def authenticated?(attribute, token)
59
+ def activate
60
+ def send_activation_email
61
+ def create_reset_digest
62
+ def send_password_reset_email
63
+ def password_reset_expired?
64
+ private
65
+ def downcase_email
66
+ def create_activation_digest
67
+ test/models/user_test.rb
68
+ def setup
69
+ test "should be valid" do
70
+ test "name should be present" do
71
+ test "email should be present" do
72
+ test "name should not be too long" do
73
+ test "email should not be too long" do
74
+ test "email validation should accept valid addresses" do
75
+ test "email validation should reject invalid addresses" do
76
+ test "email address should be unique" do
77
+ test "password should have a minimum length" do
78
+ test "authenticated? should return false for a user with nil digest" do
79
+ app/views/user_mailer
80
+ account_activation.html.erb
81
+ account_activation.text.erb
82
+ password_reset.html.erb
83
+ password_reset.text.erb
84
+ app/views/users
85
+ edit.html.erb
86
+ index.html.erb
87
+ new.html.erb
88
+ show.html.erb
89
+ _user.html.erb
90
+ config/routes.rb
91
+ get 'signup' => 'users#new'
92
+ resources :users
93
+
94
+ DATABASE
95
+ users (name, email, created_at, updated_at, timestamps, password_digest, remember_digest, admin, activation_digest, activated, activated_at, reset_digest, reset_sent_at)
96
+ index: named "index_users_on_email", based on email (must be unique)