95 |
96 | You'll need "git":http://git-scm.com/ on your machine. See "Rails and Git":http://railsapps.github.io/rails-git.html.
97 |
98 | h4. Generate
99 |
100 | If you want to use the project as a starter application, use the "Rails Composer":http://railsapps.github.io/rails-composer/ tool to generate a new version of the example app. You'll be able to give it your own project name when you generate the app. Generating the application gives you additional options.
101 |
102 | To build the example application, Rails 5.0 must be installed in your development environment. Run the command:
103 |
104 |
105 | $ rails new rails-signup-download -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
106 |
107 |
108 | The @$@ character indicates a shell prompt; don't include it when you run the command.
109 |
110 | This creates a new Rails app named @rails-signup-download@ on your computer. You can use a different name if you wish.
111 |
112 | You'll see a prompt:
113 |
114 |
115 | option Build a starter application?
116 | 1) Build a RailsApps example application
117 | 2) Contributed applications
118 | 3) Custom application
119 |
120 |
121 | Enter "1" to select *Build a RailsApps example application*. You'll see a prompt:
122 |
123 |
136 |
137 | Choose *rails-signup-download*. The Rails Composer tool may give you other options (other applications may have been added since these notes were written).
138 |
139 | The application generator template will ask you for additional preferences:
140 |
141 |
142 | question Web server for development?
143 | 1) WEBrick (default)
144 | 2) Thin
145 | 3) Unicorn
146 | 4) Puma
147 | 5) Phusion Passenger (Apache/Nginx)
148 | 6) Phusion Passenger (Standalone)
149 | question Web server for production?
150 | 1) Same as development
151 | 2) Thin
152 | 3) Unicorn
153 | 4) Puma
154 | 5) Phusion Passenger (Apache/Nginx)
155 | 6) Phusion Passenger (Standalone)
156 | question Database used in development?
157 | 1) SQLite
158 | 2) PostgreSQL
159 | 3) MySQL
160 | question Template engine?
161 | 1) ERB
162 | 2) Haml
163 | 3) Slim
164 | question Test framework?
165 | 1) None
166 | 2) RSpec with Capybara
167 | question Front-end framework?
168 | 1) None
169 | 2) Twitter Bootstrap 3.3
170 | 3) Twitter Bootstrap 2.3
171 | 4) Zurb Foundation 5.5
172 | 5) Zurb Foundation 4.0
173 | 6) Simple CSS
174 | setup The Devise 'forgot password' feature requires email.
175 | question Add support for sending email?
176 | 1) None
177 | 2) Gmail
178 | 3) SMTP
179 | 4) SendGrid
180 | 5) Mandrill
181 | extras Set a robots.txt file to ban spiders? (y/n)
182 | extras Create a GitHub repository? (y/n)
183 | extras Use or create a project-specific rvm gemset? (y/n)
184 |
185 |
186 | h4. Web Servers
187 |
188 | If you plan to deploy to Heroku, select Unicorn as your production webserver. Unicorn is recommended by Heroku.
189 |
190 | h4. Database
191 |
192 | Use SQLite for development on Mac or Linux, unless you already have PostgreSQL installed locally. Use PostgreSQL if you plan to deploy to Heroku. You can easily change the database later if you select SQLite to start.
193 |
194 | h4. Template Engine
195 |
196 | The example application uses the default "ERB" Rails template engine. Optionally, you can use another template engine, such as Haml or Slim. See instructions for "Haml and Rails":http://railsapps.github.io/rails-haml.html.
197 |
198 | h4. Testing
199 |
200 | If you are a beginner, select "None."
201 |
202 | h4. Front-end Framework
203 |
204 | The example in the GitHub repository was built with the Bootstrap 3 front-end framework. Use Zurb Foundation 5.0 if you like. Choosing either Bootstrap or Foundation will automatically install views with attractive styling.
205 |
206 | h4. Email
207 |
208 | Choose Gmail for development if you already have a Gmail account. Choose SendGrid or Mandrill for production if your site will be heavily used.
209 |
210 | h4. Other Choices
211 |
212 | Set a robots.txt file to ban spiders if you want to keep your new site out of Google search results.
213 |
214 | If you choose to create a GitHub repository, the generator will prompt you for a GitHub username and password.
215 |
216 | It is a good idea to use "RVM":https://rvm.io/, the Ruby Version Manager, and create a project-specific RVM gemset (not available on Windows). See "Installing Rails":http://railsapps.github.io/installing-rails.html.
217 |
218 | h4. Troubleshooting
219 |
220 | If you get an error "OpenSSL certificate verify failed" or "Gem::RemoteFetcher::FetchError: SSL_connect" see the article "OpenSSL errors and Rails":http://railsapps.github.io/openssl-certificate-verify-failed.html.
221 |
222 | h3. Edit the README
223 |
224 | If you're storing the app in a GitHub repository, please edit the README files to add a description of the app and your contact info. If you don't change the README, people will think I am the author of your version of the application.
225 |
226 | h2. Getting Started
227 |
228 | See the article "Installing Rails":http://railsapps.github.io/installing-rails.html to make sure your development environment is prepared properly.
229 |
230 | h3. Use RVM
231 |
232 | I recommend using "RVM":https://rvm.io/, the Ruby Version Manager, to create a project-specific gemset for the application. If you generate the application with the Rails Composer tool, you can create a project-specific gemset.
233 |
234 | h3. Gems
235 |
236 | Here are the gems used by the application:
237 |
238 | * "Devise":http://github.com/plataformatec/devise for authentication and user management
239 |
240 | These gems make development easier:
241 |
242 | * "better_errors":https://github.com/charliesome/better_errors - helps when things go wrong
243 | * "rails_layout":https://github.com/RailsApps/rails_layout - generates files for an application layout
244 |
245 | Your choice of front-end framework:
246 |
247 | * "bootstrap-sass":https://github.com/thomas-mcdonald/bootstrap-sass - Bootstrap for CSS and JavaScript
248 | * "foundation-rails":https://github.com/zurb/foundation-rails - Zurb Foundation for CSS and JavaScript
249 |
250 | h3. Install the Required Gems
251 |
252 | If you used the "Rails Composer":http://railsapps.github.io/rails-composer/ tool to generate the example app, the application template script has already run the @bundle install@ command.
253 |
254 | If not, you should run the @bundle install@ command to install the required gems on your computer:
255 |
256 |
257 | $ bundle install
258 |
259 |
260 | You can check which gems are installed on your computer with:
261 |
262 |
263 | $ gem list
264 |
265 |
266 | Keep in mind that you have installed these gems locally. When you deploy the app to another server, the same gems (and versions) must be available.
267 |
268 | h3. Front-end Framework
269 |
270 | If you generate the application using the "Rails Composer":http://railsapps.github.io/rails-composer/ tool, you have the option to install either Bootstrap or Foundation. The folder *app/views/devise/* will contain attractive view files that override the views provided in the Devise gem.
271 |
272 | h4. Changing the Front-end Framework
273 |
274 | The version of the application in the repository includes Bootstrap. If you wish to install Foundation instead, use the "rails_layout":https://github.com/RailsApps/rails_layout gem to generate new files. First add a gem to the Gemfile:
275 |
276 |
277 | gem 'foundation-rails'
278 |
279 |
280 | Use Bundler to install the gem:
281 |
282 |
283 | $ bundle install
284 |
285 |
286 | To create layout files for use with Zurb Foundation 5.5:
287 |
288 |
291 |
292 | h4. The "layout:devise" Command
293 |
294 | Devise provides a utility command @rails generate devise:views@. The Devise command creates view files for signup, login, and related features. However, the views generated by Devise lack CSS styling.
295 |
296 | Use the RailsLayout gem to generate Devise views with styling for Bootstrap or Foundation.
297 |
298 | * @$ rails generate layout:devise bootstrap3@
299 | * @$ rails generate layout:devise foundation5@
300 |
301 | The command will create these files:
302 |
303 | * app/views/devise/sessions/new.html.erb
304 | * app/views/devise/passwords/new.html.erb
305 | * app/views/devise/registrations/edit.html.erb
306 | * app/views/devise/registrations/new.html.erb
307 |
308 | Additionally, the command will update a file to append Sass mixins to accommodate Bootstrap or Foundation:
309 |
310 | * app/assets/stylesheets/framework_and_overrides.css.scss
311 |
312 | The Sass mixins allow any view to be used with either Bootstrap or Foundation (so we don't have to maintain separate views for each front-end framework).
313 |
314 | h3. Configuration File
315 |
316 | To consolidate configuration settings in a single location, we store credentials in the *config/secrets.yml* file. To keep your credentials private, use Unix environment variables to set your credentials. See the article "Rails Environment Variables":http://railsapps.github.io/rails-environment-variables.html for more information.
317 |
318 | Add your credentials to the file *config/secrets.yml*:
319 |
320 |
321 | # Make sure the secrets in this file are kept private
322 | # if you're sharing your code publicly.
323 |
324 | development:
325 | admin_name: First User
326 | admin_email: user@example.com
327 | admin_password: changeme
328 | email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
329 | email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
330 | domain_name: example.com
331 | secret_key_base: very_long_random_string
332 |
333 | test:
334 | secret_key_base: very_long_random_string
335 |
336 | # Do not keep production secrets in the repository,
337 | # instead read values from the environment.
338 | production:
339 | admin_name: <%= ENV["ADMIN_NAME"] %>
340 | admin_email: <%= ENV["ADMIN_EMAIL"] %>
341 | admin_password: <%= ENV["ADMIN_PASSWORD"] %>
342 | email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
343 | email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
344 | domain_name: <%= ENV["DOMAIN_NAME"] %>
345 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
346 |
347 |
348 | All configuration values in the *config/secrets.yml* file are available anywhere in the application as variables. For example, @Rails.application.secrets.email_provider_username@ will return the string set in the Unix environment variable @GMAIL_USERNAME@.
349 |
350 | For the Gmail username and password, enter the credentials you use to log in to Gmail when you check your inbox. See the article "Send Email with Rails":http://railsapps.github.io/rails-send-email.html if you are using Google two factor authentication.
351 |
352 | The values for @admin_email@ and @admin_password@ are used when the database is seeded. You will be able to log in to the application with these credentials. Note that it's not necessary to personalize the *config/secrets.yml* file before you deploy your app. You can deploy the app with an example user and then use the application's "Edit Account" feature to change email address and password after you log in. Use this feature to log in as an administrator and change the email and password to your own.
353 |
354 | The variable @domain_name@ is used for sending email. You can use @example.com@ in development. If you already have a custom domain name you'll use when you deploy the application, you can set @domain_name@. If you deploy the application to Heroku, you'll set @domain_name@ with the unique name you've given your application on Heroku. You'll have to wait until you deploy to know the name you'll use on Heroku.
355 |
356 | If you don't want to use Unix environment variables, you can set each value directly in the *config/secrets.yml* file. The file must be in your git repository when you deploy to Heroku. However, you shouldn't save the file to a public GitHub repository where other people can see your credentials.
357 |
358 | h3. Roles
359 |
360 | Roles are defined in the *app/models/user.rb* file (the @User@ model).
361 |
362 |
376 |
377 | You can change the available roles by changing the array @[:user, :vip, :admin]@.
378 |
379 | The application uses the ActiveRecord @enum@ method to manage roles. ActiveRecord provides convenient methods to query the role attribute:
380 |
381 |
382 | user.admin! # sets the role to "admin"
383 | user.admin? # => true
384 | user.role # => "admin"
385 |
386 |
387 | See documentation for "ActiveRecord::Enum":http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html for details.
388 |
389 | h3. Database Seed File
390 |
391 | The *db/seeds.rb* file initializes the database with default values.
392 |
393 |
394 | # This file should contain all the record creation needed to seed the database with its default values.
395 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
396 | #
397 | # Examples:
398 | #
399 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
400 | # Mayor.create(name: 'Emanuel', city: cities.first)
401 | user = CreateAdminService.new.call
402 | puts 'CREATED ADMIN USER: ' << user.email
403 |
404 |
405 | @CreateAdminService@ is a service object that obtains @admin_email@ and @admin_password@ values from the *config/secrets.yml* file. You can examine the file *app/services/create_admin_service.rb* to see how a new user is created.
406 |
407 | h3. Set the Database
408 |
409 | If you've used the Rails Composer tool to generate the application, the database is already set up with @rake db:migrate@ and @rake db:seed@.
410 |
411 | If you've cloned the repo, prepare the database and add the default user to the database by running the commands:
412 |
413 |
417 |
418 | Use @rake db:reset@ if you want to empty and reseed the database.
419 |
420 | h3. Change your Application's Secret Token
421 |
422 | If you've used the Rails Composer tool to generate the application, the application's secret token will be unique, just as with any Rails application generated with the @rails new@ command.
423 |
424 | However, if you've cloned the application directly from GitHub, it is crucial that you change the application's secret token before deploying your application in production mode. Otherwise, people could change their session information, and potentially access your site without permission. Your secret token should be at least 30 characters long and completely random.
425 |
426 | Get a unique secret token:
427 |
428 |
429 | rake secret
430 |
431 |
432 | Edit the *config/secrets.yml* file to change the secret token.
433 |
434 | h2. Test the App
435 |
436 | You can check that your application runs properly by entering the command:
437 |
438 |
439 | $ rails server
440 |
441 |
442 | To see your application in action, open a browser window and navigate to "http://localhost:3000/":http://localhost:3000.
443 |
444 | You should see a home page with a navigation bar.
445 |
446 | Click the "Sign up" button to download a free book.
447 |
448 | You'll see a page with a form that is used to register a new account. Fill in and submit the form with a name, email address, and password. You'll see a page with the text, "You've signed up. Download a free book." Click the button "Download PDF" to download a file.
449 |
450 | Sign out and sign in as the administrator (with the credentials in the *config/secrets.yml* file). You'll be able to see a list of users.
451 |
452 | Stop the server with Control-C. If you test the app by starting the web server and then leave the server running while you install new gems, you’ll have to restart the server to see any changes. The same is true for changes to configuration files in the config folder. This can be confusing to new Rails developers because you can change files in the app folders without restarting the server. Stop the server each time after testing and you will avoid this issue.
453 |
454 | h3. RSpec Test Suite
455 |
456 | The application contains a suite of RSpec tests. To run:
457 |
458 |
459 | $ rspec
460 |
461 |
462 | h2. Deploy to Heroku
463 |
464 | Heroku provides low cost, easily configured Rails application hosting.
465 |
466 | h4. From the Command Line
467 |
468 | You can deploy from the command line.
469 |
470 |
471 | $ git push origin master
472 |
473 |
474 | If you've set configuration values in the *config/secrets.yml* file, you'll need to set them as Heroku environment variables. You can set Heroku environment variables directly with @heroku config:add@. For example:
475 |
476 |
4 | This web application was created with
5 | <%= link_to('Rails Composer', 'http://railsapps.github.io/rails-composer/') %>
6 | from the <%= link_to('RailsApps project', 'http://railsapps.github.io/') %>.
7 |
12 | <%= link_to 'Sign up', new_user_registration_path, class: 'btn btn-primary btn-large' %>
13 | <% end %>
14 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../config/application', __dir__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/bin/rspec:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require 'bundler/setup'
8 | load Gem.bin_path('rspec-core', 'rspec')
9 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 | require 'fileutils'
4 | include FileUtils
5 |
6 | # path to your application root.
7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8 |
9 | def system!(*args)
10 | system(*args) || abort("\n== Command #{args} failed ==")
11 | end
12 |
13 | chdir APP_ROOT do
14 | # This script is a starting point to setup your application.
15 | # Add necessary setup steps to this file.
16 |
17 | puts '== Installing dependencies =='
18 | system! 'gem install bundler --conservative'
19 | system('bundle check') || system!('bundle install')
20 |
21 | # puts "\n== Copying sample files =="
22 | # unless File.exist?('config/database.yml')
23 | # cp 'config/database.yml.sample', 'config/database.yml'
24 | # end
25 |
26 | puts "\n== Preparing database =="
27 | system! 'bin/rails db:setup'
28 |
29 | puts "\n== Removing old logs and tempfiles =="
30 | system! 'bin/rails log:clear tmp:clear'
31 |
32 | puts "\n== Restarting application server =="
33 | system! 'bin/rails restart'
34 | end
35 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
13 | gem 'spring', spring.version
14 | require 'spring/binstub'
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/bin/update:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 | require 'fileutils'
4 | include FileUtils
5 |
6 | # path to your application root.
7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8 |
9 | def system!(*args)
10 | system(*args) || abort("\n== Command #{args} failed ==")
11 | end
12 |
13 | chdir APP_ROOT do
14 | # This script is a way to update your development environment automatically.
15 | # Add necessary update steps to this file.
16 |
17 | puts '== Installing dependencies =='
18 | system! 'gem install bundler --conservative'
19 | system('bundle check') || system!('bundle install')
20 |
21 | puts "\n== Updating database =="
22 | system! 'bin/rails db:migrate'
23 |
24 | puts "\n== Removing old logs and tempfiles =="
25 | system! 'bin/rails log:clear tmp:clear'
26 |
27 | puts "\n== Restarting application server =="
28 | system! 'bin/rails restart'
29 | end
30 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative 'config/environment'
4 |
5 | run Rails.application
6 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative 'boot'
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module RailsSignupDownload
10 | class Application < Rails::Application
11 |
12 | config.generators do |g|
13 | g.test_framework :rspec,
14 | fixtures: true,
15 | view_specs: false,
16 | helper_specs: false,
17 | routing_specs: false,
18 | controller_specs: false,
19 | request_specs: false
20 | g.fixture_replacement :factory_girl, dir: "spec/factories"
21 | end
22 |
23 | # Settings in config/environments/* take precedence over those specified here.
24 | # Application configuration should go into files in config/initializers
25 | # -- all .rb files in that directory are automatically loaded.
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: async
6 |
7 | production:
8 | adapter: redis
9 | url: redis://localhost:6379/1
10 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative 'application'
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports.
13 | config.consider_all_requests_local = true
14 |
15 | # Enable/disable caching. By default caching is disabled.
16 | if Rails.root.join('tmp/caching-dev.txt').exist?
17 | config.action_controller.perform_caching = true
18 |
19 | config.cache_store = :memory_store
20 | config.public_file_server.headers = {
21 | 'Cache-Control' => 'public, max-age=172800'
22 | }
23 | else
24 | config.action_controller.perform_caching = false
25 |
26 | config.cache_store = :null_store
27 | end
28 |
29 | # Don't care if the mailer can't send.
30 | config.action_mailer.raise_delivery_errors = false
31 |
32 | config.action_mailer.perform_caching = false
33 |
34 | # Print deprecation notices to the Rails logger.
35 | config.active_support.deprecation = :log
36 |
37 | # Raise an error on page load if there are pending migrations.
38 | config.active_record.migration_error = :page_load
39 |
40 | # Debug mode disables concatenation and preprocessing of assets.
41 | # This option may cause significant delays in view rendering with a large
42 | # number of complex assets.
43 | config.assets.debug = true
44 |
45 | config.action_mailer.smtp_settings = {
46 | address: "smtp.gmail.com",
47 | port: 587,
48 | domain: Rails.application.secrets.domain_name,
49 | authentication: "plain",
50 | enable_starttls_auto: true,
51 | user_name: Rails.application.secrets.email_provider_username,
52 | password: Rails.application.secrets.email_provider_password
53 | }
54 | # ActionMailer Config
55 | config.action_mailer.default_url_options = { :host => 'localhost:3000' }
56 | config.action_mailer.delivery_method = :smtp
57 | config.action_mailer.raise_delivery_errors = true
58 | # Send email in development mode?
59 | config.action_mailer.perform_deliveries = true
60 |
61 |
62 | # Suppress logger output for asset requests.
63 | config.assets.quiet = true
64 |
65 | # Raises error for missing translations
66 | # config.action_view.raise_on_missing_translations = true
67 |
68 | # Use an evented file watcher to asynchronously detect changes in source code,
69 | # routes, locales, etc. This feature depends on the listen gem.
70 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
71 | end
72 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Disable serving static files from the `/public` folder by default since
18 | # Apache or NGINX already handles this.
19 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
20 |
21 | # Compress JavaScripts and CSS.
22 | config.assets.js_compressor = :uglifier
23 | # config.assets.css_compressor = :sass
24 |
25 | # Do not fallback to assets pipeline if a precompiled asset is missed.
26 | config.assets.compile = false
27 |
28 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
29 |
30 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
31 | # config.action_controller.asset_host = 'http://assets.example.com'
32 |
33 | # Specifies the header that your server uses for sending files.
34 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
35 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
36 |
37 | # Mount Action Cable outside main process or domain
38 | # config.action_cable.mount_path = nil
39 | # config.action_cable.url = 'wss://example.com/cable'
40 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
41 |
42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43 | # config.force_ssl = true
44 |
45 | # Use the lowest log level to ensure availability of diagnostic information
46 | # when problems arise.
47 | config.log_level = :debug
48 |
49 | # Prepend all log lines with the following tags.
50 | config.log_tags = [ :request_id ]
51 |
52 | # Use a different cache store in production.
53 | # config.cache_store = :mem_cache_store
54 |
55 | # Use a real queuing backend for Active Job (and separate queues per environment)
56 | # config.active_job.queue_adapter = :resque
57 | # config.active_job.queue_name_prefix = "rails-signup-download_#{Rails.env}"
58 | config.action_mailer.perform_caching = false
59 |
60 | # Ignore bad email addresses and do not raise email delivery errors.
61 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
62 | # config.action_mailer.raise_delivery_errors = false
63 |
64 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
65 | # the I18n.default_locale when a translation cannot be found).
66 | config.i18n.fallbacks = true
67 |
68 | # Send deprecation notices to registered listeners.
69 | config.active_support.deprecation = :notify
70 |
71 | config.action_mailer.smtp_settings = {
72 | address: "smtp.gmail.com",
73 | port: 587,
74 | domain: Rails.application.secrets.domain_name,
75 | authentication: "plain",
76 | enable_starttls_auto: true,
77 | user_name: Rails.application.secrets.email_provider_username,
78 | password: Rails.application.secrets.email_provider_password
79 | }
80 | # ActionMailer Config
81 | config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name }
82 | config.action_mailer.delivery_method = :smtp
83 | config.action_mailer.perform_deliveries = true
84 | config.action_mailer.raise_delivery_errors = false
85 |
86 |
87 | # Use default logging formatter so that PID and timestamp are not suppressed.
88 | config.log_formatter = ::Logger::Formatter.new
89 |
90 | # Use a different logger for distributed setups.
91 | # require 'syslog/logger'
92 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
93 |
94 | if ENV["RAILS_LOG_TO_STDOUT"].present?
95 | logger = ActiveSupport::Logger.new(STDOUT)
96 | logger.formatter = config.log_formatter
97 | config.logger = ActiveSupport::TaggedLogging.new(logger)
98 | end
99 |
100 | # Do not dump schema after migrations.
101 | config.active_record.dump_schema_after_migration = false
102 | end
103 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure public file server for tests with Cache-Control for performance.
16 | config.public_file_server.enabled = true
17 | config.public_file_server.headers = {
18 | 'Cache-Control' => 'public, max-age=3600'
19 | }
20 |
21 | # Show full error reports and disable caching.
22 | config.consider_all_requests_local = true
23 | config.action_controller.perform_caching = false
24 |
25 | # Raise exceptions instead of rendering exception templates.
26 | config.action_dispatch.show_exceptions = false
27 |
28 | # Disable request forgery protection in test environment.
29 | config.action_controller.allow_forgery_protection = false
30 | config.action_mailer.perform_caching = false
31 |
32 | # Tell Action Mailer not to deliver emails to the real world.
33 | # The :test delivery method accumulates sent emails in the
34 | # ActionMailer::Base.deliveries array.
35 | config.action_mailer.delivery_method = :test
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/config/initializers/active_job.rb:
--------------------------------------------------------------------------------
1 | # ActiveJob::Base.queue_adapter = :inline
2 | ActiveJob::Base.queue_adapter = :sucker_punch
3 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # ApplicationController.renderer.defaults.merge!(
4 | # http_host: 'example.org',
5 | # https: false
6 | # )
7 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | # Rails.application.config.assets.precompile += %w( search.js )
12 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Specify a serializer for the signed and encrypted cookie jars.
4 | # Valid options are :json, :marshal, and :hybrid.
5 | Rails.application.config.action_dispatch.cookies_serializer = :json
6 |
--------------------------------------------------------------------------------
/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | # Use this hook to configure devise mailer, warden hooks and so forth.
2 | # Many of these configuration options can be set straight in your model.
3 | Devise.setup do |config|
4 | # The secret key used by Devise. Devise uses this key to generate
5 | # random tokens. Changing this key will render invalid all existing
6 | # confirmation, reset password and unlock tokens in the database.
7 | # Devise will use the `secret_key_base` as its `secret_key`
8 | # by default. You can change it below and use your own secret key.
9 | # config.secret_key = '5efaebfaff41f60225cfe2cf1e97d66139d52c2b489d0905da14e82bf496bfaad400930cf223e46a269822724cf60c51555493bb5616962a84f0f545d7c62d9b'
10 |
11 | # ==> Mailer Configuration
12 | # Configure the e-mail address which will be shown in Devise::Mailer,
13 | # note that it will be overwritten if you use your own mailer class
14 | # with default "from" parameter.
15 | config.mailer_sender = 'no-reply@' + Rails.application.secrets.domain_name
16 |
17 | # Configure the class responsible to send e-mails.
18 | # config.mailer = 'Devise::Mailer'
19 |
20 | # Configure the parent class responsible to send e-mails.
21 | # config.parent_mailer = 'ActionMailer::Base'
22 |
23 | # ==> ORM configuration
24 | # Load and configure the ORM. Supports :active_record (default) and
25 | # :mongoid (bson_ext recommended) by default. Other ORMs may be
26 | # available as additional gems.
27 | require 'devise/orm/active_record'
28 |
29 | # ==> Configuration for any authentication mechanism
30 | # Configure which keys are used when authenticating a user. The default is
31 | # just :email. You can configure it to use [:username, :subdomain], so for
32 | # authenticating a user, both parameters are required. Remember that those
33 | # parameters are used only when authenticating and not when retrieving from
34 | # session. If you need permissions, you should implement that in a before filter.
35 | # You can also supply a hash where the value is a boolean determining whether
36 | # or not authentication should be aborted when the value is not present.
37 | # config.authentication_keys = [:email]
38 |
39 | # Configure parameters from the request object used for authentication. Each entry
40 | # given should be a request method and it will automatically be passed to the
41 | # find_for_authentication method and considered in your model lookup. For instance,
42 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
43 | # The same considerations mentioned for authentication_keys also apply to request_keys.
44 | # config.request_keys = []
45 |
46 | # Configure which authentication keys should be case-insensitive.
47 | # These keys will be downcased upon creating or modifying a user and when used
48 | # to authenticate or find a user. Default is :email.
49 | config.case_insensitive_keys = [:email]
50 |
51 | # Configure which authentication keys should have whitespace stripped.
52 | # These keys will have whitespace before and after removed upon creating or
53 | # modifying a user and when used to authenticate or find a user. Default is :email.
54 | config.strip_whitespace_keys = [:email]
55 |
56 | # Tell if authentication through request.params is enabled. True by default.
57 | # It can be set to an array that will enable params authentication only for the
58 | # given strategies, for example, `config.params_authenticatable = [:database]` will
59 | # enable it only for database (email + password) authentication.
60 | # config.params_authenticatable = true
61 |
62 | # Tell if authentication through HTTP Auth is enabled. False by default.
63 | # It can be set to an array that will enable http authentication only for the
64 | # given strategies, for example, `config.http_authenticatable = [:database]` will
65 | # enable it only for database authentication. The supported strategies are:
66 | # :database = Support basic authentication with authentication key + password
67 | # config.http_authenticatable = false
68 |
69 | # If 401 status code should be returned for AJAX requests. True by default.
70 | # config.http_authenticatable_on_xhr = true
71 |
72 | # The realm used in Http Basic Authentication. 'Application' by default.
73 | # config.http_authentication_realm = 'Application'
74 |
75 | # It will change confirmation, password recovery and other workflows
76 | # to behave the same regardless if the e-mail provided was right or wrong.
77 | # Does not affect registerable.
78 | # config.paranoid = true
79 |
80 | # By default Devise will store the user in session. You can skip storage for
81 | # particular strategies by setting this option.
82 | # Notice that if you are skipping storage for all authentication paths, you
83 | # may want to disable generating routes to Devise's sessions controller by
84 | # passing skip: :sessions to `devise_for` in your config/routes.rb
85 | config.skip_session_storage = [:http_auth]
86 |
87 | # By default, Devise cleans up the CSRF token on authentication to
88 | # avoid CSRF token fixation attacks. This means that, when using AJAX
89 | # requests for sign in and sign up, you need to get a new CSRF token
90 | # from the server. You can disable this option at your own risk.
91 | # config.clean_up_csrf_token_on_authentication = true
92 |
93 | # When false, Devise will not attempt to reload routes on eager load.
94 | # This can reduce the time taken to boot the app but if your application
95 | # requires the Devise mappings to be loaded during boot time the application
96 | # won't boot properly.
97 | # config.reload_routes = true
98 |
99 | # ==> Configuration for :database_authenticatable
100 | # For bcrypt, this is the cost for hashing the password and defaults to 11. If
101 | # using other algorithms, it sets how many times you want the password to be hashed.
102 | #
103 | # Limiting the stretches to just one in testing will increase the performance of
104 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
105 | # a value less than 10 in other environments. Note that, for bcrypt (the default
106 | # algorithm), the cost increases exponentially with the number of stretches (e.g.
107 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
108 | config.stretches = Rails.env.test? ? 1 : 11
109 |
110 | # Set up a pepper to generate the hashed password.
111 | # config.pepper = 'cf57591ddab96de73b7014b7517a3a4e8bea48b0d4cff1919c23de08892a6ea04f67d5aef996c4d606774263f9750e951c0253bd07a6f63ceef7ab8787942126'
112 |
113 | # Send a notification email when the user's password is changed
114 | # config.send_password_change_notification = false
115 |
116 | # ==> Configuration for :confirmable
117 | # A period that the user is allowed to access the website even without
118 | # confirming their account. For instance, if set to 2.days, the user will be
119 | # able to access the website for two days without confirming their account,
120 | # access will be blocked just in the third day. Default is 0.days, meaning
121 | # the user cannot access the website without confirming their account.
122 | # config.allow_unconfirmed_access_for = 2.days
123 |
124 | # A period that the user is allowed to confirm their account before their
125 | # token becomes invalid. For example, if set to 3.days, the user can confirm
126 | # their account within 3 days after the mail was sent, but on the fourth day
127 | # their account can't be confirmed with the token any more.
128 | # Default is nil, meaning there is no restriction on how long a user can take
129 | # before confirming their account.
130 | # config.confirm_within = 3.days
131 |
132 | # If true, requires any email changes to be confirmed (exactly the same way as
133 | # initial account confirmation) to be applied. Requires additional unconfirmed_email
134 | # db field (see migrations). Until confirmed, new email is stored in
135 | # unconfirmed_email column, and copied to email column on successful confirmation.
136 | config.reconfirmable = true
137 |
138 | # Defines which key will be used when confirming an account
139 | # config.confirmation_keys = [:email]
140 |
141 | # ==> Configuration for :rememberable
142 | # The time the user will be remembered without asking for credentials again.
143 | # config.remember_for = 2.weeks
144 |
145 | # Invalidates all the remember me tokens when the user signs out.
146 | config.expire_all_remember_me_on_sign_out = true
147 |
148 | # If true, extends the user's remember period when remembered via cookie.
149 | # config.extend_remember_period = false
150 |
151 | # Options to be passed to the created cookie. For instance, you can set
152 | # secure: true in order to force SSL only cookies.
153 | # config.rememberable_options = {}
154 |
155 | # ==> Configuration for :validatable
156 | # Range for password length.
157 | config.password_length = 6..128
158 |
159 | # Email regex used to validate email formats. It simply asserts that
160 | # one (and only one) @ exists in the given string. This is mainly
161 | # to give user feedback and not to assert the e-mail validity.
162 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
163 |
164 | # ==> Configuration for :timeoutable
165 | # The time you want to timeout the user session without activity. After this
166 | # time the user will be asked for credentials again. Default is 30 minutes.
167 | # config.timeout_in = 30.minutes
168 |
169 | # ==> Configuration for :lockable
170 | # Defines which strategy will be used to lock an account.
171 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
172 | # :none = No lock strategy. You should handle locking by yourself.
173 | # config.lock_strategy = :failed_attempts
174 |
175 | # Defines which key will be used when locking and unlocking an account
176 | # config.unlock_keys = [:email]
177 |
178 | # Defines which strategy will be used to unlock an account.
179 | # :email = Sends an unlock link to the user email
180 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
181 | # :both = Enables both strategies
182 | # :none = No unlock strategy. You should handle unlocking by yourself.
183 | # config.unlock_strategy = :both
184 |
185 | # Number of authentication tries before locking an account if lock_strategy
186 | # is failed attempts.
187 | # config.maximum_attempts = 20
188 |
189 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
190 | # config.unlock_in = 1.hour
191 |
192 | # Warn on the last attempt before the account is locked.
193 | # config.last_attempt_warning = true
194 |
195 | # ==> Configuration for :recoverable
196 | #
197 | # Defines which key will be used when recovering the password for an account
198 | # config.reset_password_keys = [:email]
199 |
200 | # Time interval you can reset your password with a reset password key.
201 | # Don't put a too small interval or your users won't have the time to
202 | # change their passwords.
203 | config.reset_password_within = 6.hours
204 |
205 | # When set to false, does not sign a user in automatically after their password is
206 | # reset. Defaults to true, so a user is signed in automatically after a reset.
207 | # config.sign_in_after_reset_password = true
208 |
209 | # ==> Configuration for :encryptable
210 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
211 | # You can use :sha1, :sha512 or algorithms from others authentication tools as
212 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
213 | # for default behavior) and :restful_authentication_sha1 (then you should set
214 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
215 | #
216 | # Require the `devise-encryptable` gem when using anything other than bcrypt
217 | # config.encryptor = :sha512
218 |
219 | # ==> Scopes configuration
220 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
221 | # "users/sessions/new". It's turned off by default because it's slower if you
222 | # are using only default views.
223 | # config.scoped_views = false
224 |
225 | # Configure the default scope given to Warden. By default it's the first
226 | # devise role declared in your routes (usually :user).
227 | # config.default_scope = :user
228 |
229 | # Set this configuration to false if you want /users/sign_out to sign out
230 | # only the current scope. By default, Devise signs out all scopes.
231 | # config.sign_out_all_scopes = true
232 |
233 | # ==> Navigation configuration
234 | # Lists the formats that should be treated as navigational. Formats like
235 | # :html, should redirect to the sign in page when the user does not have
236 | # access, but formats like :xml or :json, should return 401.
237 | #
238 | # If you have any extra navigational formats, like :iphone or :mobile, you
239 | # should add them to the navigational formats lists.
240 | #
241 | # The "*/*" below is required to match Internet Explorer requests.
242 | # config.navigational_formats = ['*/*', :html]
243 |
244 | # The default HTTP method used to sign out a resource. Default is :delete.
245 | config.sign_out_via = :delete
246 |
247 | # ==> OmniAuth
248 | # Add a new OmniAuth provider. Check the wiki for more information on setting
249 | # up on your models and hooks.
250 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
251 |
252 | # ==> Warden configuration
253 | # If you want to use other strategies, that are not supported by Devise, or
254 | # change the failure app, you can configure them inside the config.warden block.
255 | #
256 | # config.warden do |manager|
257 | # manager.intercept_401 = false
258 | # manager.default_strategies(scope: :user).unshift :some_external_strategy
259 | # end
260 |
261 | # ==> Mountable engine configurations
262 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine
263 | # is mountable, there are some extra configurations to be taken into account.
264 | # The following options are available, assuming the engine is mounted as:
265 | #
266 | # mount MyEngine, at: '/my_engine'
267 | #
268 | # The router that invoked `devise_for`, in the example above, would be:
269 | # config.router_name = :my_engine
270 | #
271 | # When using OmniAuth, Devise cannot automatically set OmniAuth path,
272 | # so you need to do it manually. For the users scope, it would be:
273 | # config.omniauth_path_prefix = '/my_engine/users/auth'
274 | end
275 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password, :password_confirmation]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/config/initializers/new_framework_defaults.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file contains migration options to ease your Rails 5.0 upgrade.
4 | #
5 | # Read the Rails 5.0 release notes for more info on each option.
6 |
7 | # Enable per-form CSRF tokens. Previous versions had false.
8 | Rails.application.config.action_controller.per_form_csrf_tokens = true
9 |
10 | # Enable origin-checking CSRF mitigation. Previous versions had false.
11 | Rails.application.config.action_controller.forgery_protection_origin_check = true
12 |
13 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
14 | # Previous versions had false.
15 | ActiveSupport.to_time_preserves_timezone = true
16 |
17 | # Require `belongs_to` associations by default. Previous versions had false.
18 | Rails.application.config.active_record.belongs_to_required_by_default = true
19 |
20 | # Do not halt callback chains when a callback returns false. Previous versions had true.
21 | ActiveSupport.halt_callback_chains_on_return_false = false
22 |
23 | # Configure SSL options to enable HSTS with subdomains. Previous versions had false.
24 | Rails.application.config.ssl_options = { hsts: { subdomains: true } }
25 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_rails-signup-download_session'
4 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/locales/devise.en.yml:
--------------------------------------------------------------------------------
1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2 |
3 | en:
4 | devise:
5 | confirmations:
6 | confirmed: "Your email address has been successfully confirmed."
7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
9 | failure:
10 | already_authenticated: "You are already signed in."
11 | inactive: "Your account is not activated yet."
12 | invalid: "Invalid %{authentication_keys} or password."
13 | locked: "Your account is locked."
14 | last_attempt: "You have one more attempt before your account is locked."
15 | not_found_in_database: "Invalid %{authentication_keys} or password."
16 | timeout: "Your session expired. Please sign in again to continue."
17 | unauthenticated: "You need to sign in or sign up before continuing."
18 | unconfirmed: "You have to confirm your email address before continuing."
19 | mailer:
20 | confirmation_instructions:
21 | subject: "Confirmation instructions"
22 | reset_password_instructions:
23 | subject: "Reset password instructions"
24 | unlock_instructions:
25 | subject: "Unlock instructions"
26 | password_change:
27 | subject: "Password Changed"
28 | omniauth_callbacks:
29 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
30 | success: "Successfully authenticated from %{kind} account."
31 | passwords:
32 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
33 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
34 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
35 | updated: "Your password has been changed successfully. You are now signed in."
36 | updated_not_active: "Your password has been changed successfully."
37 | registrations:
38 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
39 | signed_up: "Welcome! You have signed up successfully."
40 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
41 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
42 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
43 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
44 | updated: "Your account has been updated successfully."
45 | sessions:
46 | signed_in: "Signed in successfully."
47 | signed_out: "Signed out successfully."
48 | already_signed_out: "Signed out successfully."
49 | unlocks:
50 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
51 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
52 | unlocked: "Your account has been unlocked successfully. Please sign in to continue."
53 | errors:
54 | messages:
55 | already_confirmed: "was already confirmed, please try signing in"
56 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
57 | expired: "has expired, please request a new one"
58 | not_found: "not found"
59 | not_locked: "was not locked"
60 | not_saved:
61 | one: "1 error prohibited this %{resource} from being saved:"
62 | other: "%{count} errors prohibited this %{resource} from being saved:"
63 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum, this matches the default thread size of Active Record.
6 | #
7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
8 | threads threads_count, threads_count
9 |
10 | # Specifies the `port` that Puma will listen on to receive requests, default is 3000.
11 | #
12 | port ENV.fetch("PORT") { 3000 }
13 |
14 | # Specifies the `environment` that Puma will run in.
15 | #
16 | environment ENV.fetch("RAILS_ENV") { "development" }
17 |
18 | # Specifies the number of `workers` to boot in clustered mode.
19 | # Workers are forked webserver processes. If using threads and workers together
20 | # the concurrency of the application would be max `threads` * `workers`.
21 | # Workers do not work on JRuby or Windows (both of which do not support
22 | # processes).
23 | #
24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25 |
26 | # Use the `preload_app!` method when specifying a `workers` number.
27 | # This directive tells Puma to first boot the application and load code
28 | # before forking the application. This takes advantage of Copy On Write
29 | # process behavior so workers use less memory. If you use this option
30 | # you need to make sure to reconnect any threads in the `on_worker_boot`
31 | # block.
32 | #
33 | # preload_app!
34 |
35 | # The code in the `on_worker_boot` will be called if you are using
36 | # clustered mode by specifying a number of `workers`. After each worker
37 | # process is booted this block will be run, if you are using `preload_app!`
38 | # option you will want to use this block to reconnect to any threads
39 | # or connections that may have been created at application boot, Ruby
40 | # cannot share connections between processes.
41 | #
42 | # on_worker_boot do
43 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44 | # end
45 |
46 | # Allow puma to be restarted by `rails restart` command.
47 | plugin :tmp_restart
48 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | root to: 'visitors#index'
3 | get 'products/:id', to: 'products#show', :as => :products
4 | devise_for :users
5 | resources :users
6 | end
7 |
--------------------------------------------------------------------------------
/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rails secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | development:
14 | admin_name: First User
15 | admin_email: user@example.com
16 | admin_password: changeme
17 | email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
18 | email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
19 | domain_name: example.com
20 | mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
21 | mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
22 | secret_key_base: 8293688da6debe75c394a16aae71d2d652d9867a6d6734ca5fb13c3a87fb6b47e50c29710de9683f2d7f1c15d78e39b0a588c8389c901b5110ef3b84fdb3e6b4
23 |
24 | test:
25 | domain_name: example.com
26 | secret_key_base: 0f9da9a13a991aaf1dcc8ad96c44acc704e572ec0cab0e613bd0c64e8adec7890335286a9475eb17a39915f3be86077b6fb98d95dcf6563b882050abf3746690
27 |
28 | # Do not keep production secrets in the repository,
29 | # instead read values from the environment.
30 | production:
31 | admin_name: <%= ENV["ADMIN_NAME"] %>
32 | admin_email: <%= ENV["ADMIN_EMAIL"] %>
33 | admin_password: <%= ENV["ADMIN_PASSWORD"] %>
34 | email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
35 | email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
36 | domain_name: <%= ENV["DOMAIN_NAME"] %>
37 | mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
38 | mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
39 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
40 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | %w(
2 | .ruby-version
3 | .rbenv-vars
4 | tmp/restart.txt
5 | tmp/caching-dev.txt
6 | ).each { |path| Spring.watch(path) }
7 |
--------------------------------------------------------------------------------
/db/migrate/20140708220529_devise_create_users.rb:
--------------------------------------------------------------------------------
1 | class DeviseCreateUsers < ActiveRecord::Migration
2 | def change
3 | create_table(:users) do |t|
4 | ## Database authenticatable
5 | t.string :email, null: false, default: ""
6 | t.string :encrypted_password, null: false, default: ""
7 |
8 | ## Recoverable
9 | t.string :reset_password_token
10 | t.datetime :reset_password_sent_at
11 |
12 | ## Rememberable
13 | t.datetime :remember_created_at
14 |
15 | ## Trackable
16 | t.integer :sign_in_count, default: 0, null: false
17 | t.datetime :current_sign_in_at
18 | t.datetime :last_sign_in_at
19 | t.string :current_sign_in_ip
20 | t.string :last_sign_in_ip
21 |
22 | ## Confirmable
23 | # t.string :confirmation_token
24 | # t.datetime :confirmed_at
25 | # t.datetime :confirmation_sent_at
26 | # t.string :unconfirmed_email # Only if using reconfirmable
27 |
28 | ## Lockable
29 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
30 | # t.string :unlock_token # Only if unlock strategy is :email or :both
31 | # t.datetime :locked_at
32 |
33 |
34 | t.timestamps
35 | end
36 |
37 | add_index :users, :email, unique: true
38 | add_index :users, :reset_password_token, unique: true
39 | # add_index :users, :confirmation_token, unique: true
40 | # add_index :users, :unlock_token, unique: true
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/db/migrate/20140708220531_add_name_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddNameToUsers < ActiveRecord::Migration
2 | def change
3 | add_column :users, :name, :string
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20140708220535_add_role_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddRoleToUsers < ActiveRecord::Migration
2 | def change
3 | add_column :users, :role, :integer
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # Note that this schema.rb definition is the authoritative source for your
6 | # database schema. If you need to create the application database on another
7 | # system, you should be using db:schema:load, not running all the migrations
8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 | # you'll amass, the slower it'll run and the greater likelihood for issues).
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema.define(version: 20150102122811) do
14 |
15 | create_table "users", force: :cascade do |t|
16 | t.string "email", default: "", null: false
17 | t.string "encrypted_password", default: "", null: false
18 | t.string "reset_password_token"
19 | t.datetime "reset_password_sent_at"
20 | t.datetime "remember_created_at"
21 | t.integer "sign_in_count", default: 0, null: false
22 | t.datetime "current_sign_in_at"
23 | t.datetime "last_sign_in_at"
24 | t.string "current_sign_in_ip"
25 | t.string "last_sign_in_ip"
26 | t.datetime "created_at"
27 | t.datetime "updated_at"
28 | t.string "name"
29 | t.integer "role"
30 | end
31 |
32 | add_index "users", ["email"], name: "index_users_on_email", unique: true
33 | add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
34 |
35 | end
36 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 | user = CreateAdminService.new.call
9 | puts 'CREATED ADMIN USER: ' << user.email
10 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/lib/tasks/.keep
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/public/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/public/favicon.ico
--------------------------------------------------------------------------------
/public/humans.txt:
--------------------------------------------------------------------------------
1 | /* the humans responsible & colophon */
2 | /* humanstxt.org */
3 |
4 |
5 | /* TEAM */
6 | :
7 | Site:
8 | Twitter:
9 | Location:
10 |
11 | /* THANKS */
12 | Daniel Kehoe (@rails_apps) for the RailsApps project
13 |
14 | /* SITE */
15 | Standards: HTML5, CSS3
16 | Components: jQuery
17 | Software: Ruby on Rails
18 |
19 | /* GENERATED BY */
20 | Rails Composer: http://railscomposer.com/
21 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/spec/controllers/products_controller_spec.rb:
--------------------------------------------------------------------------------
1 | describe ProductsController do
2 |
3 | describe 'GET #show' do
4 |
5 | it "returns a PDF file" do
6 | get :show, id: 'product', format: 'pdf'
7 | expect(response.headers['Content-Type']).to have_content 'application/pdf'
8 | end
9 |
10 | end
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/spec/factories/users.rb:
--------------------------------------------------------------------------------
1 | FactoryGirl.define do
2 | factory :user do
3 | name "Test User"
4 | email "test@example.com"
5 | password "please123"
6 |
7 | trait :admin do
8 | role 'admin'
9 | end
10 |
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/spec/features/users/product_acquisition_spec.rb:
--------------------------------------------------------------------------------
1 | include Warden::Test::Helpers
2 | Warden.test_mode!
3 |
4 | # Feature: Product acquisition
5 | # As a user
6 | # I want to download the product
7 | # So I can complete my acquisition
8 | feature 'Product acquisition' do
9 |
10 | after(:each) do
11 | Warden.test_reset!
12 | end
13 |
14 | # Scenario: Download the product
15 | # Given I am a user
16 | # When I click the 'Download' button
17 | # Then I should receive a PDF file
18 | scenario 'Download the product' do
19 | user = FactoryGirl.create(:user)
20 | login_as(user, scope: :user)
21 | visit root_path
22 | expect(page).to have_content 'Download a free book'
23 | click_link_or_button 'Download PDF'
24 | expect(page.response_headers['Content-Type']).to have_content 'application/pdf'
25 | end
26 |
27 | end
28 |
--------------------------------------------------------------------------------
/spec/features/users/sign_in_spec.rb:
--------------------------------------------------------------------------------
1 | # Feature: Sign in
2 | # As a user
3 | # I want to sign in
4 | # So I can visit protected areas of the site
5 | feature 'Sign in', :devise do
6 |
7 | # Scenario: User cannot sign in if not registered
8 | # Given I do not exist as a user
9 | # When I sign in with valid credentials
10 | # Then I see an invalid credentials message
11 | scenario 'user cannot sign in if not registered' do
12 | signin('test@example.com', 'please123')
13 | expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
14 | end
15 |
16 | # Scenario: User can sign in with valid credentials
17 | # Given I exist as a user
18 | # And I am not signed in
19 | # When I sign in with valid credentials
20 | # Then I see a success message
21 | scenario 'user can sign in with valid credentials' do
22 | user = FactoryGirl.create(:user)
23 | signin(user.email, user.password)
24 | expect(page).to have_content I18n.t 'devise.sessions.signed_in'
25 | end
26 |
27 | # Scenario: User cannot sign in with wrong email
28 | # Given I exist as a user
29 | # And I am not signed in
30 | # When I sign in with a wrong email
31 | # Then I see an invalid email message
32 | scenario 'user cannot sign in with wrong email' do
33 | user = FactoryGirl.create(:user)
34 | signin('invalid@email.com', user.password)
35 | expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
36 | end
37 |
38 | # Scenario: User cannot sign in with wrong password
39 | # Given I exist as a user
40 | # And I am not signed in
41 | # When I sign in with a wrong password
42 | # Then I see an invalid password message
43 | scenario 'user cannot sign in with wrong password' do
44 | user = FactoryGirl.create(:user)
45 | signin(user.email, 'invalidpass')
46 | expect(page).to have_content I18n.t 'devise.failure.invalid', authentication_keys: 'email'
47 | end
48 |
49 | end
50 |
--------------------------------------------------------------------------------
/spec/features/users/sign_out_spec.rb:
--------------------------------------------------------------------------------
1 | # Feature: Sign out
2 | # As a user
3 | # I want to sign out
4 | # So I can protect my account from unauthorized access
5 | feature 'Sign out', :devise do
6 |
7 | # Scenario: User signs out successfully
8 | # Given I am signed in
9 | # When I sign out
10 | # Then I see a signed out message
11 | scenario 'user signs out successfully' do
12 | user = FactoryGirl.create(:user)
13 | signin(user.email, user.password)
14 | expect(page).to have_content I18n.t 'devise.sessions.signed_in'
15 | click_link 'Sign out'
16 | expect(page).to have_content I18n.t 'devise.sessions.signed_out'
17 | end
18 |
19 | end
20 |
21 |
22 |
--------------------------------------------------------------------------------
/spec/features/users/user_delete_spec.rb:
--------------------------------------------------------------------------------
1 | include Warden::Test::Helpers
2 | Warden.test_mode!
3 |
4 | # Feature: User delete
5 | # As a user
6 | # I want to delete my user profile
7 | # So I can close my account
8 | feature 'User delete', :devise, :js do
9 |
10 | after(:each) do
11 | Warden.test_reset!
12 | end
13 |
14 | # Scenario: User can delete own account
15 | # Given I am signed in
16 | # When I delete my account
17 | # Then I should see an account deleted message
18 | scenario 'user can delete own account' do
19 | skip 'skip a slow test'
20 | user = FactoryGirl.create(:user)
21 | login_as(user, :scope => :user)
22 | visit edit_user_registration_path(user)
23 | click_button 'Cancel my account'
24 | page.driver.browser.switch_to.alert.accept
25 | expect(page).to have_content I18n.t 'devise.registrations.destroyed'
26 | end
27 |
28 | end
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/spec/features/users/user_edit_spec.rb:
--------------------------------------------------------------------------------
1 | include Warden::Test::Helpers
2 | Warden.test_mode!
3 |
4 | # Feature: User edit
5 | # As a user
6 | # I want to edit my user profile
7 | # So I can change my email address
8 | feature 'User edit', :devise do
9 |
10 | after(:each) do
11 | Warden.test_reset!
12 | end
13 |
14 | # Scenario: User changes email address
15 | # Given I am signed in
16 | # When I change my email address
17 | # Then I see an account updated message
18 | scenario 'user changes email address' do
19 | user = FactoryGirl.create(:user)
20 | login_as(user, :scope => :user)
21 | visit edit_user_registration_path(user)
22 | fill_in 'Email', :with => 'newemail@example.com'
23 | fill_in 'Current password', :with => user.password
24 | click_button 'Update'
25 | txts = [I18n.t( 'devise.registrations.updated'), I18n.t( 'devise.registrations.update_needs_confirmation')]
26 | expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
27 | end
28 |
29 | # Scenario: User cannot edit another user's profile
30 | # Given I am signed in
31 | # When I try to edit another user's profile
32 | # Then I see my own 'edit profile' page
33 | scenario "user cannot cannot edit another user's profile", :me do
34 | me = FactoryGirl.create(:user)
35 | other = FactoryGirl.create(:user, email: 'other@example.com')
36 | login_as(me, :scope => :user)
37 | visit edit_user_registration_path(other)
38 | expect(page).to have_content 'Edit User'
39 | expect(page).to have_field('Email', with: me.email)
40 | end
41 |
42 | end
43 |
--------------------------------------------------------------------------------
/spec/features/users/user_index_spec.rb:
--------------------------------------------------------------------------------
1 | include Warden::Test::Helpers
2 | Warden.test_mode!
3 |
4 | # Feature: User index page
5 | # As a user
6 | # I want to see a list of users
7 | # So I can see who has registered
8 | feature 'User index page', :devise do
9 |
10 | after(:each) do
11 | Warden.test_reset!
12 | end
13 |
14 | # Scenario: User listed on index page
15 | # Given I am signed in
16 | # When I visit the user index page
17 | # Then I see my own email address
18 | scenario 'user sees own email address' do
19 | user = FactoryGirl.create(:user, :admin)
20 | login_as(user, scope: :user)
21 | visit users_path
22 | expect(page).to have_content user.email
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/spec/features/users/user_show_spec.rb:
--------------------------------------------------------------------------------
1 | include Warden::Test::Helpers
2 | Warden.test_mode!
3 |
4 | # Feature: User profile page
5 | # As a user
6 | # I want to visit my user profile page
7 | # So I can see my personal account data
8 | feature 'User profile page', :devise do
9 |
10 | after(:each) do
11 | Warden.test_reset!
12 | end
13 |
14 | # Scenario: User sees own profile
15 | # Given I am signed in
16 | # When I visit the user profile page
17 | # Then I see my own email address
18 | scenario 'user sees own profile' do
19 | user = FactoryGirl.create(:user)
20 | login_as(user, :scope => :user)
21 | visit user_path(user)
22 | expect(page).to have_content 'User'
23 | expect(page).to have_content user.email
24 | end
25 |
26 | # Scenario: User cannot see another user's profile
27 | # Given I am signed in
28 | # When I visit another user's profile
29 | # Then I see an 'access denied' message
30 | scenario "user cannot see another user's profile" do
31 | me = FactoryGirl.create(:user)
32 | other = FactoryGirl.create(:user, email: 'other@example.com')
33 | login_as(me, :scope => :user)
34 | Capybara.current_session.driver.header 'Referer', root_path
35 | visit user_path(other)
36 | expect(page).to have_content 'Access denied.'
37 | end
38 |
39 | end
40 |
--------------------------------------------------------------------------------
/spec/features/visitors/about_page_spec.rb:
--------------------------------------------------------------------------------
1 | # Feature: 'About' page
2 | # As a visitor
3 | # I want to visit an 'about' page
4 | # So I can learn more about the website
5 | feature 'About page' do
6 |
7 | # Scenario: Visit the 'about' page
8 | # Given I am a visitor
9 | # When I visit the 'about' page
10 | # Then I see "About the Website"
11 | scenario 'Visit the about page' do
12 | visit 'pages/about'
13 | expect(page).to have_content 'About the Website'
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/spec/features/visitors/home_page_spec.rb:
--------------------------------------------------------------------------------
1 | # Feature: Home page
2 | # As a visitor
3 | # I want to visit a home page
4 | # So I can learn more about the website
5 | feature 'Home page' do
6 |
7 | # Scenario: Visit the home page
8 | # Given I am a visitor
9 | # When I visit the home page
10 | # Then I see "Welcome"
11 | scenario 'visit the home page' do
12 | visit root_path
13 | expect(page).to have_content 'Welcome'
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/spec/features/visitors/navigation_spec.rb:
--------------------------------------------------------------------------------
1 | # Feature: Navigation links
2 | # As a visitor
3 | # I want to see navigation links
4 | # So I can find home, sign in, or sign up
5 | feature 'Navigation links', :devise do
6 |
7 | # Scenario: View navigation links
8 | # Given I am a visitor
9 | # When I visit the home page
10 | # Then I see "home," "sign in," and "sign up"
11 | scenario 'view navigation links' do
12 | visit root_path
13 | expect(page).to have_content 'Home'
14 | expect(page).to have_content 'Sign in'
15 | expect(page).to have_content 'Sign up'
16 | end
17 |
18 | end
19 |
--------------------------------------------------------------------------------
/spec/features/visitors/sign_up_spec.rb:
--------------------------------------------------------------------------------
1 | # Feature: Sign up
2 | # As a visitor
3 | # I want to sign up
4 | # So I can visit protected areas of the site
5 | feature 'Sign Up', :devise do
6 |
7 | # Scenario: Visitor can sign up with valid email address and password
8 | # Given I am not signed in
9 | # When I sign up with a valid email address and password
10 | # Then I see a successful sign up message
11 | scenario 'visitor can sign up with valid email address and password' do
12 | sign_up_with('test@example.com', 'please123', 'please123')
13 | txts = [I18n.t( 'devise.registrations.signed_up'), I18n.t( 'devise.registrations.signed_up_but_unconfirmed')]
14 | expect(page).to have_content(/.*#{txts[0]}.*|.*#{txts[1]}.*/)
15 | end
16 |
17 | # Scenario: Visitor cannot sign up with invalid email address
18 | # Given I am not signed in
19 | # When I sign up with an invalid email address
20 | # Then I see an invalid email message
21 | scenario 'visitor cannot sign up with invalid email address' do
22 | sign_up_with('bogus', 'please123', 'please123')
23 | expect(page).to have_content 'Email is invalid'
24 | end
25 |
26 | # Scenario: Visitor cannot sign up without password
27 | # Given I am not signed in
28 | # When I sign up without a password
29 | # Then I see a missing password message
30 | scenario 'visitor cannot sign up without password' do
31 | sign_up_with('test@example.com', '', '')
32 | expect(page).to have_content "Password can't be blank"
33 | end
34 |
35 | # Scenario: Visitor cannot sign up with a short password
36 | # Given I am not signed in
37 | # When I sign up with a short password
38 | # Then I see a 'too short password' message
39 | scenario 'visitor cannot sign up with a short password' do
40 | sign_up_with('test@example.com', 'please', 'please')
41 | expect(page).to have_content "Password is too short"
42 | end
43 |
44 | # Scenario: Visitor cannot sign up without password confirmation
45 | # Given I am not signed in
46 | # When I sign up without a password confirmation
47 | # Then I see a missing password confirmation message
48 | scenario 'visitor cannot sign up without password confirmation' do
49 | sign_up_with('test@example.com', 'please123', '')
50 | expect(page).to have_content "Password confirmation doesn't match"
51 | end
52 |
53 | # Scenario: Visitor cannot sign up with mismatched password and confirmation
54 | # Given I am not signed in
55 | # When I sign up with a mismatched password confirmation
56 | # Then I should see a mismatched password message
57 | scenario 'visitor cannot sign up with mismatched password and confirmation' do
58 | sign_up_with('test@example.com', 'please123', 'mismatch')
59 | expect(page).to have_content "Password confirmation doesn't match"
60 | end
61 |
62 | end
63 |
--------------------------------------------------------------------------------
/spec/models/user_spec.rb:
--------------------------------------------------------------------------------
1 | describe User do
2 |
3 | before(:each) { @user = User.new(email: 'user@example.com') }
4 |
5 | subject { @user }
6 |
7 | it { should respond_to(:email) }
8 |
9 | it "#email returns a string" do
10 | expect(@user.email).to match 'user@example.com'
11 | end
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | ENV['RAILS_ENV'] ||= 'test'
3 | require File.expand_path('../../config/environment', __FILE__)
4 | # Prevent database truncation if the environment is production
5 | abort("The Rails environment is running in production mode!") if Rails.env.production?
6 | require 'spec_helper'
7 | require 'rspec/rails'
8 | # Add additional requires below this line. Rails is not loaded until this point!
9 |
10 | # Requires supporting ruby files with custom matchers and macros, etc, in
11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12 | # run as spec files by default. This means that files in spec/support that end
13 | # in _spec.rb will both be required and run as specs, causing the specs to be
14 | # run twice. It is recommended that you do not name files matching this glob to
15 | # end with _spec.rb. You can configure this pattern with the --pattern
16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17 | #
18 | # The following line is provided for convenience purposes. It has the downside
19 | # of increasing the boot-up time by auto-requiring all files in the support
20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
21 | # require only the support files necessary.
22 | #
23 | Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
24 |
25 | # Checks for pending migration and applies them before tests are run.
26 | # If you are not using ActiveRecord, you can remove this line.
27 | ActiveRecord::Migration.maintain_test_schema!
28 |
29 | RSpec.configure do |config|
30 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
31 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
32 |
33 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
34 | # examples within a transaction, remove the following line or assign false
35 | # instead of true.
36 | config.use_transactional_fixtures = false
37 |
38 | # RSpec Rails can automatically mix in different behaviours to your tests
39 | # based on their file location, for example enabling you to call `get` and
40 | # `post` in specs under `spec/controllers`.
41 | #
42 | # You can disable this behaviour by removing the line below, and instead
43 | # explicitly tag your specs with their type, e.g.:
44 | #
45 | # RSpec.describe UsersController, :type => :controller do
46 | # # ...
47 | # end
48 | #
49 | # The different available types are documented in the features, such as in
50 | # https://relishapp.com/rspec/rspec-rails/docs
51 | config.infer_spec_type_from_file_location!
52 |
53 | # Filter lines from Rails gems in backtraces.
54 | config.filter_rails_from_backtrace!
55 | # arbitrary gems may also be filtered via:
56 | # config.filter_gems_from_backtrace("gem name")
57 | end
58 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3 | # The generated `.rspec` file contains `--require spec_helper` which will cause
4 | # this file to always be loaded, without a need to explicitly require it in any
5 | # files.
6 | #
7 | # Given that it is always loaded, you are encouraged to keep this file as
8 | # light-weight as possible. Requiring heavyweight dependencies from this file
9 | # will add to the boot time of your test suite on EVERY test run, even for an
10 | # individual file that may not need all of that loaded. Instead, consider making
11 | # a separate helper file that requires the additional dependencies and performs
12 | # the additional setup, and require it from the spec files that actually need
13 | # it.
14 | #
15 | # The `.rspec` file also contains a few flags that are not defaults but that
16 | # users commonly want.
17 | #
18 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19 | RSpec.configure do |config|
20 | # rspec-expectations config goes here. You can use an alternate
21 | # assertion/expectation library such as wrong or the stdlib/minitest
22 | # assertions if you prefer.
23 | config.expect_with :rspec do |expectations|
24 | # This option will default to `true` in RSpec 4. It makes the `description`
25 | # and `failure_message` of custom matchers include text for helper methods
26 | # defined using `chain`, e.g.:
27 | # be_bigger_than(2).and_smaller_than(4).description
28 | # # => "be bigger than 2 and smaller than 4"
29 | # ...rather than:
30 | # # => "be bigger than 2"
31 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32 | end
33 |
34 | # rspec-mocks config goes here. You can use an alternate test double
35 | # library (such as bogus or mocha) by changing the `mock_with` option here.
36 | config.mock_with :rspec do |mocks|
37 | # Prevents you from mocking or stubbing a method that does not exist on
38 | # a real object. This is generally recommended, and will default to
39 | # `true` in RSpec 4.
40 | mocks.verify_partial_doubles = true
41 | end
42 |
43 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44 | # have no way to turn it off -- the option exists only for backwards
45 | # compatibility in RSpec 3). It causes shared context metadata to be
46 | # inherited by the metadata hash of host groups and examples, rather than
47 | # triggering implicit auto-inclusion in groups with matching metadata.
48 | config.shared_context_metadata_behavior = :apply_to_host_groups
49 |
50 | # The settings below are suggested to provide a good initial experience
51 | # with RSpec, but feel free to customize to your heart's content.
52 | =begin
53 | # This allows you to limit a spec run to individual examples or groups
54 | # you care about by tagging them with `:focus` metadata. When nothing
55 | # is tagged with `:focus`, all examples get run. RSpec also provides
56 | # aliases for `it`, `describe`, and `context` that include `:focus`
57 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58 | config.filter_run_when_matching :focus
59 |
60 | # Allows RSpec to persist some state between runs in order to support
61 | # the `--only-failures` and `--next-failure` CLI options. We recommend
62 | # you configure your source control system to ignore this file.
63 | config.example_status_persistence_file_path = "spec/examples.txt"
64 |
65 | # Limits the available syntax to the non-monkey patched syntax that is
66 | # recommended. For more details, see:
67 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70 | config.disable_monkey_patching!
71 |
72 | # Many RSpec users commonly either run the entire suite or an individual
73 | # file, and it's useful to allow more verbose output when running an
74 | # individual spec file.
75 | if config.files_to_run.one?
76 | # Use the documentation formatter for detailed output,
77 | # unless a formatter has already been configured
78 | # (e.g. via a command-line flag).
79 | config.default_formatter = 'doc'
80 | end
81 |
82 | # Print the 10 slowest examples and example groups at the
83 | # end of the spec run, to help surface which specs are running
84 | # particularly slow.
85 | config.profile_examples = 10
86 |
87 | # Run specs in random order to surface order dependencies. If you find an
88 | # order dependency and want to debug it, you can fix the order by providing
89 | # the seed, which is printed after each run.
90 | # --seed 1234
91 | config.order = :random
92 |
93 | # Seed global randomization in this process using the `--seed` CLI option.
94 | # Setting this allows you to use `--seed` to deterministically reproduce
95 | # test failures related to randomization by passing the same `--seed` value
96 | # as the one that triggered the failure.
97 | Kernel.srand config.seed
98 | =end
99 | end
100 |
--------------------------------------------------------------------------------
/spec/support/capybara.rb:
--------------------------------------------------------------------------------
1 | Capybara.asset_host = 'http://localhost:3000'
2 |
--------------------------------------------------------------------------------
/spec/support/database_cleaner.rb:
--------------------------------------------------------------------------------
1 | RSpec.configure do |config|
2 | config.before(:suite) do
3 | DatabaseCleaner.clean_with(:truncation)
4 | end
5 |
6 | config.before(:each) do
7 | DatabaseCleaner.strategy = :transaction
8 | end
9 |
10 | config.before(:each, :js => true) do
11 | DatabaseCleaner.strategy = :truncation
12 | end
13 |
14 | config.before(:each) do
15 | DatabaseCleaner.start
16 | end
17 |
18 | config.append_after(:each) do
19 | DatabaseCleaner.clean
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/spec/support/devise.rb:
--------------------------------------------------------------------------------
1 | RSpec.configure do |config|
2 | config.include Devise::TestHelpers, :type => :controller
3 | end
4 |
--------------------------------------------------------------------------------
/spec/support/factory_girl.rb:
--------------------------------------------------------------------------------
1 | RSpec.configure do |config|
2 | config.include FactoryGirl::Syntax::Methods
3 | end
4 |
--------------------------------------------------------------------------------
/spec/support/helpers.rb:
--------------------------------------------------------------------------------
1 | require 'support/helpers/session_helpers'
2 | RSpec.configure do |config|
3 | config.include Features::SessionHelpers, type: :feature
4 | end
5 |
--------------------------------------------------------------------------------
/spec/support/helpers/session_helpers.rb:
--------------------------------------------------------------------------------
1 | module Features
2 | module SessionHelpers
3 | def sign_up_with(email, password, confirmation)
4 | visit new_user_registration_path
5 | fill_in 'Email', with: email
6 | fill_in 'Password', with: password
7 | fill_in 'Password confirmation', :with => confirmation
8 | click_button 'Sign up'
9 | end
10 |
11 | def signin(email, password)
12 | visit new_user_session_path
13 | fill_in 'Email', with: email
14 | fill_in 'Password', with: password
15 | click_button 'Sign in'
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/vendor/assets/javascripts/.keep
--------------------------------------------------------------------------------
/vendor/assets/stylesheets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RailsApps/rails-signup-download/4a766a247d8e49b2ae5d2d48996ddf719e3e66c3/vendor/assets/stylesheets/.keep
--------------------------------------------------------------------------------