generic_app 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +7 -0
- data/bin/generic_app +12 -0
- data/generic_app.gemspec +26 -0
- data/lib/generic_app/version.rb +3 -0
- data/lib/generic_app.rb +62 -0
- data/setup.sh +5 -0
- data/spec/lib/generic_app_spec.rb +45 -0
- data/spec/spec_helper.rb +1 -0
- data/to_add/README.md +57 -0
- data/to_add/heroku_upload.sh +5 -0
- data/to_add/kill_spring.sh +4 -0
- data/to_add/list_files.sh +25 -0
- data/to_add/notes/mvc_by_object.txt +160 -0
- data/to_add/notes/seed.txt +18 -0
- data/to_add/notes/tests.txt +109 -0
- data/to_add/sandbox.sh +4 -0
- data/to_add/seed.sh +5 -0
- data/to_add/server.sh +4 -0
- data/to_add/setup.sh +6 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1114674038b10667980e9b42e27cbab74446215c
|
4
|
+
data.tar.gz: 4342aa70fe18a6306776dda16e40b203c718be1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa23ee68dba82f8542b407a7dda33016f03335f83da3b6d4cc15a110a8d784eafc6c25a3499f1b3cdc3976fffcda95a64f3cc3aa32e81cb6fe455634d646b80d
|
7
|
+
data.tar.gz: a71e65ad38b9aec7e19d30866bab3ccf3c08d5549a1cb5150bd89d7906cb9382b5b2f60b1d1b88031ab4ca41611d75693260d2b0c1fe1b2f200cd0dd43bd4fd0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# GenericApp
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Install it yourself with the command:
|
6
|
+
|
7
|
+
$ gem install generic_app
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Once you have installed this Ruby gem, just go to the directory where you
|
12
|
+
keep your Rails projects and enter the command "generic_app". You will be
|
13
|
+
asked to provide a name for the subdirectory you wish to have created and
|
14
|
+
used for your new Rails app.
|
15
|
+
|
16
|
+
## What's the point?
|
17
|
+
|
18
|
+
Welcome to Ruby On HIGH SPEED Rails! The GenericApp gem saves you time by automatically providing the basic
|
19
|
+
elements and features that nearly all Rails apps require. Instead of spending hours reinventing the wheel, you
|
20
|
+
can spend more of your time on the more advanced features and capabilities that are unique to your specific Rails
|
21
|
+
app. Modifying a generic app takes far less time than creating an app completely from scratch.
|
22
|
+
<br><br>
|
23
|
+
Creating a basic generic web site with user capability and testing is a long and slow process that spans chapters
|
24
|
+
3 through 10 at railstutorial.org. The GenericApp Ruby gem allows you to create such a site in seconds instead of
|
25
|
+
hours. This is valuable for any project and essential for events like Startup Weekend and 24-hour website
|
26
|
+
challenges.
|
27
|
+
<br><br>
|
28
|
+
The GenericApp gem copies the railstutorial.org Sample App for use as a template for starting a new project.
|
29
|
+
(Note that the microposts and followers features are not included, because they are specific to the Sample App.)
|
30
|
+
Starting a Rails app completely from scratch (by using the "rails new" command) requires manually installing and
|
31
|
+
configuring MiniTest, Guard, Twitter bootstrap, the user model, user sign-ups, user login/logout, user
|
32
|
+
authorization, administrative users, account activations, and password resets. People are often tempted to "save
|
33
|
+
time" by omitting testing. Using the GenericApp gem allows you to have all of the essential basic elements of a
|
34
|
+
generic app as soon as you start it. It's a shortcut that actually complies with best practices.
|
35
|
+
<br><br>
|
36
|
+
The original Rails Tutorial Sample App provides the following features:
|
37
|
+
|
38
|
+
1. Static pages
|
39
|
+
2. Tests
|
40
|
+
3. Automated tests through Guard
|
41
|
+
4. Twitter bootstrap
|
42
|
+
5. Databases: SQLite3 for development and PostgreSQL for production
|
43
|
+
6. Ready for Heroku deployment
|
44
|
+
7. User functionality: includes hashed passwords, administrative users,
|
45
|
+
account activations, and password resets
|
46
|
+
|
47
|
+
This generic Rails app provides the above features PLUS these additional
|
48
|
+
features:
|
49
|
+
|
50
|
+
1. Bash scripts in the root directory that allow you to perform routine
|
51
|
+
tasks in only one step. (These scripts are likely to be useful in Rails
|
52
|
+
apps that were not created with this generic_app Ruby gem.)
|
53
|
+
2. Recommendations that the user make use of password management software
|
54
|
+
to generate and store secure passwords
|
55
|
+
3. Outlines of the MVC, test suite, and database seeding process in the
|
56
|
+
notes folder
|
57
|
+
4. Guard automatically runs tests upon startup.
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it ( https://github.com/jhsu802701/generic_app/fork )
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/generic_app
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'generic_app'
|
4
|
+
|
5
|
+
generic_app = GenericApp.new
|
6
|
+
puts "***********************"
|
7
|
+
puts "Welcome to Generic App!"
|
8
|
+
puts
|
9
|
+
puts "DEFAULT VALUE: sample_app_3rd_edition"
|
10
|
+
puts "Enter the directory name you wish to use for your generic app:"
|
11
|
+
subdir_name = gets.chomp
|
12
|
+
generic_app.create(subdir_name)
|
data/generic_app.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'generic_app/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "generic_app"
|
8
|
+
spec.version = GenericApp::VERSION
|
9
|
+
spec.authors = ["Jason Hsu"]
|
10
|
+
spec.email = ["rubyist@jasonhsu.com"]
|
11
|
+
spec.summary = %q{Save time by instantly create a generic Rails app.}
|
12
|
+
spec.description = %q{Instead of creating your Rails app from scratch, start with a generic app.}
|
13
|
+
spec.homepage = "https://github.com/jhsu802701/generic_app"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "string_in_file"
|
25
|
+
spec.add_runtime_dependency "string_in_path"
|
26
|
+
end
|
data/lib/generic_app.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "generic_app/version"
|
4
|
+
require "string_in_file"
|
5
|
+
|
6
|
+
class GenericApp
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def create (subdir_name)
|
12
|
+
dir_main = File.expand_path("../../", __FILE__)
|
13
|
+
subdir_name_final = subdir_name
|
14
|
+
subdir_name_final = "sample_app_3rd_edition" if subdir_name == ""
|
15
|
+
t1 = Thread.new {
|
16
|
+
puts "*************************************************"
|
17
|
+
puts "Downloading the Sample App from railstutorial.org"
|
18
|
+
system("git clone https://github.com/mhartl/sample_app_3rd_edition.git #{subdir_name}")
|
19
|
+
system("cd #{subdir_name} && git checkout remotes/origin/account-activation-password-reset")
|
20
|
+
}
|
21
|
+
t1.join
|
22
|
+
t1 = Thread.new {
|
23
|
+
puts "*******************************"
|
24
|
+
puts "Modifying the Rails source code"
|
25
|
+
|
26
|
+
# Changing Guardfile settings
|
27
|
+
str_guard_orig = "all_on_start: false"
|
28
|
+
str_guard_new = "all_on_start: true"
|
29
|
+
StringInFile.replace(str_guard_orig, str_guard_new, "#{subdir_name}/Guardfile")
|
30
|
+
|
31
|
+
# Advise users to use a password management program when choosing a password
|
32
|
+
str1 = "</h1>"
|
33
|
+
str2a = "</h1>"
|
34
|
+
str2b = "\nUsing the same password for all of your accounts is risky."
|
35
|
+
str2b += "\nLimiting yourself to passwords that you can easily remember is risky."
|
36
|
+
str2b += "\nYou should use a password management program like <a href='http://www.keepassx.org/'>KeePassX</a>"
|
37
|
+
str2b += "\nto create much better passwords AND store them in encrypted form.<br>"
|
38
|
+
str2 = str2a + str2b
|
39
|
+
StringInFile.replace(str1, str2, "#{subdir_name}/app/views/users/new.html.erb")
|
40
|
+
StringInFile.replace(str1, str2, "#{subdir_name}/app/views/users/edit.html.erb")
|
41
|
+
StringInFile.replace(str1, str2, "#{subdir_name}/app/views/password_resets/new.html.erb")
|
42
|
+
StringInFile.replace(str1, str2, "#{subdir_name}/app/views/password_resets/edit.html.erb")
|
43
|
+
|
44
|
+
# Adding notes and special scripts
|
45
|
+
system("cp -r #{dir_main}/to_add/* #{subdir_name}")
|
46
|
+
|
47
|
+
# Adding automated list of files
|
48
|
+
system("cd #{subdir_name} && sh list_files.sh >> notes/list_files.txt")
|
49
|
+
|
50
|
+
# Initializing Git
|
51
|
+
system("cd #{subdir_name} && rm -rf .git")
|
52
|
+
system("cd #{subdir_name} && git init")
|
53
|
+
}
|
54
|
+
t1.join
|
55
|
+
puts "*************************************************************"
|
56
|
+
puts "Enter the following commands to set up and test your new app:"
|
57
|
+
puts "cd #{subdir_name}"
|
58
|
+
puts "sh setup.sh"
|
59
|
+
puts "***********"
|
60
|
+
puts
|
61
|
+
end
|
62
|
+
end
|
data/setup.sh
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generic_app'
|
3
|
+
require 'string_in_file'
|
4
|
+
require 'string_in_path'
|
5
|
+
|
6
|
+
describe GenericApp do
|
7
|
+
it "should copy the Rails tutorial" do
|
8
|
+
puts "*********************************"
|
9
|
+
puts "Clearing space for Rails tutorial"
|
10
|
+
system("rm -rf tmp")
|
11
|
+
|
12
|
+
t1 = Thread.new {
|
13
|
+
generic_app = GenericApp.new
|
14
|
+
generic_app.create("tmp")
|
15
|
+
}
|
16
|
+
t1.join
|
17
|
+
|
18
|
+
t1 = Thread.new {
|
19
|
+
puts "\nChecking Bash scripts"
|
20
|
+
expect(StringInFile.present("heroku run rake db:migrate", "tmp/heroku_upload.sh")).to eq(true)
|
21
|
+
expect(StringInFile.present("pkill", "tmp/kill_spring.sh")).to eq(true)
|
22
|
+
expect(StringInFile.present("ls -R1 -I concerns app/controllers", "tmp/list_files.sh")).to eq(true)
|
23
|
+
expect(StringInFile.present("rails console --sandbox", "tmp/sandbox.sh")).to eq(true)
|
24
|
+
expect(StringInFile.present("rake db:seed", "tmp/seed.sh")).to eq(true)
|
25
|
+
expect(StringInFile.present("rails server -b 0.0.0.0", "tmp/server.sh")).to eq(true)
|
26
|
+
expect(StringInFile.present("bundle install", "tmp/setup.sh")).to eq(true)
|
27
|
+
|
28
|
+
puts "\nChecking README.md"
|
29
|
+
expect(StringInFile.present("list_files.sh", "tmp/README.md")).to eq(true)
|
30
|
+
|
31
|
+
puts "\nChecking Guardfile"
|
32
|
+
expect(StringInFile.present("all_on_start: true", "tmp/Guardfile")).to eq(true)
|
33
|
+
|
34
|
+
|
35
|
+
puts "\nChecking for suggestion to use password management software"
|
36
|
+
expect(StringInFile.present("KeePassX", "tmp/app/views/users/new.html.erb")).to eq(true)
|
37
|
+
expect(StringInFile.present("KeePassX", "tmp/app/views/users/edit.html.erb")).to eq(true)
|
38
|
+
expect(StringInFile.present("KeePassX", "tmp/app/views/password_resets/new.html.erb")).to eq(true)
|
39
|
+
expect(StringInFile.present("KeePassX", "tmp/app/views/password_resets/edit.html.erb")).to eq(true)
|
40
|
+
}
|
41
|
+
t1.join
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'spec_helper'
|
data/to_add/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generic App
|
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 .
|
6
|
+
|
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.
|
11
|
+
|
12
|
+
The original Rails Tutorial Sample App provides the following features:
|
13
|
+
|
14
|
+
1. Static pages
|
15
|
+
2. Tests
|
16
|
+
3. Automated tests through Guard
|
17
|
+
4. Twitter bootstrap
|
18
|
+
5. Databases: SQLite3 for development and PostgreSQL for production
|
19
|
+
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
|
33
|
+
4. Guard automatically runs tests upon startup.
|
34
|
+
|
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.
|
47
|
+
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.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Proper header for a Bash script.
|
3
|
+
|
4
|
+
echo "This file was AUTOMATICALLY generated by the list_files.sh script."
|
5
|
+
|
6
|
+
echo
|
7
|
+
ls -R1 -I concerns app/controllers
|
8
|
+
|
9
|
+
echo
|
10
|
+
ls -R1 -I concerns app/helpers
|
11
|
+
|
12
|
+
echo
|
13
|
+
ls -R1 -I concerns app/mailers
|
14
|
+
|
15
|
+
echo
|
16
|
+
ls -R1 -I concerns app/models
|
17
|
+
|
18
|
+
echo
|
19
|
+
ls -R1 -I concerns app/views
|
20
|
+
|
21
|
+
echo
|
22
|
+
ls -R1 -I concerns db
|
23
|
+
|
24
|
+
echo
|
25
|
+
ls -R1 -I concerns test
|
@@ -0,0 +1,160 @@
|
|
1
|
+
MIGRATIONS
|
2
|
+
db/migrate
|
3
|
+
20141014183645_create_users.rb
|
4
|
+
create_table :users (name, email)
|
5
|
+
20141014205756_add_index_to_users_email.rb
|
6
|
+
add_index :users, :email
|
7
|
+
20141014234032_add_password_digest_to_users.rb
|
8
|
+
add_column :users, :password_digest, :string
|
9
|
+
20141030174712_add_remember_digest_to_users.rb
|
10
|
+
add_column :users, :remember_digest, :string
|
11
|
+
20141104004736_add_admin_to_users.rb
|
12
|
+
add_column :users, :admin, :boolean, default: false
|
13
|
+
20141106193737_add_activation_to_users.rb
|
14
|
+
add_column :users, :activation_digest, :string
|
15
|
+
add_column :users, :activated, :boolean, default: false
|
16
|
+
add_column :users, :activated_at, :datetime
|
17
|
+
20141107180258_add_reset_to_users.rb
|
18
|
+
add_column :users, :reset_digest, :string
|
19
|
+
add_column :users, :reset_sent_at, :datetime
|
20
|
+
|
21
|
+
ACCOUNT ACTIVATIONS
|
22
|
+
app/controllers/account_activations_controller.rb
|
23
|
+
def edit
|
24
|
+
app/helpers/account_activations_helper.rb
|
25
|
+
config/routes.rb
|
26
|
+
get 'account_activations/edit'
|
27
|
+
resources :account_activations, only: [:edit]
|
28
|
+
|
29
|
+
APPLICATION
|
30
|
+
app/controllers/application_controller.rb
|
31
|
+
include SessionsHelper
|
32
|
+
app/helpers/application_helper.rb
|
33
|
+
def full_title(page_title = '')
|
34
|
+
|
35
|
+
PASSWORD RESETS
|
36
|
+
app/controllers/password_resets_controller.rb
|
37
|
+
before_action :get_user, only: [:edit, :update]
|
38
|
+
before_action :valid_user, only: [:edit, :update]
|
39
|
+
before_action :check_expiration, only: [:edit, :update]
|
40
|
+
def new
|
41
|
+
def create
|
42
|
+
def edit
|
43
|
+
def update
|
44
|
+
private
|
45
|
+
def user_params
|
46
|
+
def both_passwords_blank?
|
47
|
+
def get_user
|
48
|
+
def valid_user
|
49
|
+
def check_expiration
|
50
|
+
app/views/password_resets
|
51
|
+
edit.html.erb
|
52
|
+
new.html.erb
|
53
|
+
config/routes.rb
|
54
|
+
get 'password_resets/new'
|
55
|
+
get 'password_resets/edit'
|
56
|
+
resources :password_resets, only: [:new, :create, :edit, :update]
|
57
|
+
|
58
|
+
SESSIONS
|
59
|
+
app/controllers/sessions_controller.rb
|
60
|
+
def new
|
61
|
+
def create
|
62
|
+
def destroy
|
63
|
+
app/views/sessions/new.html.erb
|
64
|
+
config/routes.rb
|
65
|
+
get 'sessions/new'
|
66
|
+
get 'login' => 'sessions#new'
|
67
|
+
post 'login' => 'sessions#create'
|
68
|
+
delete 'logout' => 'sessions#destroy'
|
69
|
+
|
70
|
+
STATIC PAGES
|
71
|
+
app/controllers/static_pages_controller.rb
|
72
|
+
def home
|
73
|
+
def help
|
74
|
+
def about
|
75
|
+
def contact
|
76
|
+
app/views/static_pages
|
77
|
+
about.html.erb
|
78
|
+
contact.html.erb
|
79
|
+
help.html.erb
|
80
|
+
home.html.erb
|
81
|
+
config/routes.rb
|
82
|
+
root 'static_pages#home'
|
83
|
+
get 'help' => 'static_pages#help'
|
84
|
+
get 'about' => 'static_pages#about'
|
85
|
+
get 'contact' => 'static_pages#contact'
|
86
|
+
|
87
|
+
USERS
|
88
|
+
app/controllers/users_controller.rb
|
89
|
+
before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
|
90
|
+
before_action :correct_user, only: [:edit, :update]
|
91
|
+
before_action :admin_user, only: :destroy
|
92
|
+
def index
|
93
|
+
def show
|
94
|
+
def new
|
95
|
+
def create
|
96
|
+
def edit
|
97
|
+
def update
|
98
|
+
def destroy
|
99
|
+
private
|
100
|
+
def user_params
|
101
|
+
def logged_in_user
|
102
|
+
def correct_user
|
103
|
+
def admin_user
|
104
|
+
app/models/user.rb
|
105
|
+
attr_accessor :remember_token, :activation_token, :reset_token
|
106
|
+
before_save :downcase_email
|
107
|
+
before_create :create_activation_digest
|
108
|
+
validates :name, presence: true, length: { maximum: 50 }
|
109
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\-.]+\.[a-z]+\z/i
|
110
|
+
validates :email, presence: true, length: { maximum: 255 },
|
111
|
+
format: { with: VALID_EMAIL_REGEX },
|
112
|
+
uniqueness: { case_sensitive: false }
|
113
|
+
has_secure_password
|
114
|
+
validates :password, length: { minimum: 6 }, allow_blank: true
|
115
|
+
def User.digest(string)
|
116
|
+
def User.new_token
|
117
|
+
def remember
|
118
|
+
def forget
|
119
|
+
def authenticated?(attribute, token)
|
120
|
+
def activate
|
121
|
+
def send_activation_email
|
122
|
+
def create_reset_digest
|
123
|
+
def send_password_reset_email
|
124
|
+
def password_reset_expired?
|
125
|
+
private
|
126
|
+
def downcase_email
|
127
|
+
def create_activation_digest
|
128
|
+
app/views/users
|
129
|
+
edit.html.erb
|
130
|
+
index.html.erb
|
131
|
+
new.html.erb
|
132
|
+
show.html.erb
|
133
|
+
_user.html.erb
|
134
|
+
database params:
|
135
|
+
users (name, email, index, password_digest, remember_digest, admin,
|
136
|
+
activation_digest, activated, activated_at, reset_digest, reset_sent_at)
|
137
|
+
config/routes.rb
|
138
|
+
get 'signup' => 'users#new'
|
139
|
+
resources :users
|
140
|
+
|
141
|
+
MAILERS
|
142
|
+
app/mailers/user_mailer.rb
|
143
|
+
def account_activation(user)
|
144
|
+
def password_reset(user)
|
145
|
+
app/views/user_mailer
|
146
|
+
account_activation.html.erb
|
147
|
+
account_activation.text.erb
|
148
|
+
password_reset.html.erb
|
149
|
+
password_reset.text.erb
|
150
|
+
|
151
|
+
LAYOUTS
|
152
|
+
app/views/layouts
|
153
|
+
application.html.erb
|
154
|
+
_footer.html.erb
|
155
|
+
_header.html.erb
|
156
|
+
_shim.html.erb
|
157
|
+
|
158
|
+
SHARED VIEWS
|
159
|
+
app/views/shared
|
160
|
+
_error_messages.html.erb
|
@@ -0,0 +1,18 @@
|
|
1
|
+
User.create!(name: "Example User",
|
2
|
+
email: "example@railstutorial.org",
|
3
|
+
password: "foobar",
|
4
|
+
password_confirmation: "foobar",
|
5
|
+
admin: true,
|
6
|
+
activated: true,
|
7
|
+
activated_at: Time.zone.now)
|
8
|
+
99.times do |n|
|
9
|
+
name = Faker::Name.name
|
10
|
+
email = "example-#{n+1}@railstutorial.org"
|
11
|
+
password = "password"
|
12
|
+
User.create!(name: name,
|
13
|
+
email: email,
|
14
|
+
password: password,
|
15
|
+
password_confirmation: password,
|
16
|
+
activated: true,
|
17
|
+
activated_at: Time.zone.now)
|
18
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
test_helper.rb
|
2
|
+
fixtures :all
|
3
|
+
def is_logged_in?
|
4
|
+
def log_in_as(user, options = {})
|
5
|
+
private
|
6
|
+
def integration_test?
|
7
|
+
|
8
|
+
test/fixtures:
|
9
|
+
users.yml
|
10
|
+
michael
|
11
|
+
archer
|
12
|
+
lana
|
13
|
+
mallory
|
14
|
+
<% 30.times do |n| %>
|
15
|
+
user_<%= n %>:
|
16
|
+
|
17
|
+
test/controllers:
|
18
|
+
account_activations_controller_test.rb
|
19
|
+
sessions_controller_test.rb
|
20
|
+
test "should get new" do
|
21
|
+
static_pages_controller_test.rb
|
22
|
+
test "should get home" do
|
23
|
+
test "should get help" do
|
24
|
+
test "should get about" do
|
25
|
+
test "should get contact" do
|
26
|
+
users_controller_test.rb
|
27
|
+
def setup
|
28
|
+
test "should redirect index when not logged in" do
|
29
|
+
test "should get new" do
|
30
|
+
test "should redirect edit when not logged in" do
|
31
|
+
test "should redirect update when not logged in" do
|
32
|
+
test "should redirect edit when logged in as wrong user" do
|
33
|
+
test "should redirect update when logged in as wrong user" do
|
34
|
+
test "should redirect destroy when not logged in" do
|
35
|
+
test "should redirect destroy when logged in as a non-admin" do
|
36
|
+
|
37
|
+
test/helpers:
|
38
|
+
sessions_helper_test.rb
|
39
|
+
def setup
|
40
|
+
test "current_user returns right user when session is nil" do
|
41
|
+
test "current_user returns nil when remember digest is wrong" do
|
42
|
+
|
43
|
+
test/integration:
|
44
|
+
password_resets_test.rb
|
45
|
+
def setup
|
46
|
+
test "password resets" do
|
47
|
+
# Invalid email
|
48
|
+
# Valid email
|
49
|
+
# Password reset form
|
50
|
+
# Wrong email
|
51
|
+
# Inactive user
|
52
|
+
# Right email, wrong token
|
53
|
+
# Right email, right token
|
54
|
+
# Invalid password & confirmation
|
55
|
+
# Blank password & confirmation
|
56
|
+
# Valid password & confirmation
|
57
|
+
site_layout_test.rb
|
58
|
+
test "layout links" do
|
59
|
+
users_edit_test.rb
|
60
|
+
def setup
|
61
|
+
test "unsuccessful edit" do
|
62
|
+
test "successful edit with friendly forwarding" do
|
63
|
+
users_index_test.rb
|
64
|
+
def setup
|
65
|
+
test "index as admin including pagination and delete links" do
|
66
|
+
test "index as non-admin" do
|
67
|
+
users_login_test.rb
|
68
|
+
def setup
|
69
|
+
test "login with invalid information" do
|
70
|
+
test "login with valid information followed by logout" do
|
71
|
+
test "login with remembering" do
|
72
|
+
test "login without remembering" do
|
73
|
+
users_signup_test.rb
|
74
|
+
def setup
|
75
|
+
test "invalid signup information" do
|
76
|
+
test "valid signup information" do
|
77
|
+
|
78
|
+
test/mailers:
|
79
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/account_activation
|
80
|
+
def account_activation
|
81
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset
|
82
|
+
def password_reset
|
83
|
+
previews
|
84
|
+
user_mailer_test.rb
|
85
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/account_activation
|
86
|
+
def account_activation
|
87
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset
|
88
|
+
def password_reset
|
89
|
+
|
90
|
+
test/mailers/previews:
|
91
|
+
user_mailer_preview.rb
|
92
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/account_activation
|
93
|
+
def account_activation
|
94
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset
|
95
|
+
def password_reset
|
96
|
+
|
97
|
+
test/models:
|
98
|
+
user_test.rb
|
99
|
+
def setup
|
100
|
+
test "should be valid" do
|
101
|
+
test "name should be present" do
|
102
|
+
test "email should be present" do
|
103
|
+
test "name should not be too long" do
|
104
|
+
test "email should not be too long" do
|
105
|
+
test "email validation should accept valid addresses" do
|
106
|
+
test "email validation should reject invalid addresses" do
|
107
|
+
test "email address should be unique" do
|
108
|
+
test "password should have a minimum length" do
|
109
|
+
test "authenticated? should return false for a user with nil digest" do
|
data/to_add/sandbox.sh
ADDED
data/to_add/seed.sh
ADDED
data/to_add/server.sh
ADDED
data/to_add/setup.sh
ADDED
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: generic_app
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Hsu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: string_in_file
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: string_in_path
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Instead of creating your Rails app from scratch, start with a generic
|
70
|
+
app.
|
71
|
+
email:
|
72
|
+
- rubyist@jasonhsu.com
|
73
|
+
executables:
|
74
|
+
- generic_app
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/generic_app
|
84
|
+
- generic_app.gemspec
|
85
|
+
- lib/generic_app.rb
|
86
|
+
- lib/generic_app/version.rb
|
87
|
+
- setup.sh
|
88
|
+
- spec/lib/generic_app_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- to_add/README.md
|
91
|
+
- to_add/heroku_upload.sh
|
92
|
+
- to_add/kill_spring.sh
|
93
|
+
- to_add/list_files.sh
|
94
|
+
- to_add/notes/mvc_by_object.txt
|
95
|
+
- to_add/notes/seed.txt
|
96
|
+
- to_add/notes/tests.txt
|
97
|
+
- to_add/sandbox.sh
|
98
|
+
- to_add/seed.sh
|
99
|
+
- to_add/server.sh
|
100
|
+
- to_add/setup.sh
|
101
|
+
homepage: https://github.com/jhsu802701/generic_app
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Save time by instantly create a generic Rails app.
|
125
|
+
test_files:
|
126
|
+
- spec/lib/generic_app_spec.rb
|
127
|
+
- spec/spec_helper.rb
|