You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
h1. Rails Application with Devise and RSpec and Cucumber
1
+
h1. Rails Application for Devise with RSpec and Cucumber
2
2
3
3
Rails 3.2 example application shows how to use "Devise":http://github.com/plataformatec/devise with "RSpec":http://rspec.info/ and "Cucumber":http://cukes.info/.
4
4
5
-
Devise gives you ready-made authentication and user management. RSpec is a popular alternative to the Test::Unit testing framework. Cucumber is often used with RSpec for Behaviour Driven Development.
5
+
* "Devise":http://github.com/plataformatec/devise gives you ready-made authentication and user management.
6
+
* "RSpec":http://rspec.info/ is a popular alternative to the Test::Unit testing framework.
7
+
* "Cucumber":http://cukes.info/ is used for Behaviour Driven Development.
6
8
7
9
Best of all, there's a "detailed tutorial":http://railsapps.github.com/tutorial-rails-devise-rspec-cucumber.html to show how it's built.
8
10
@@ -26,13 +28,13 @@ If you simply wish to modify the application for your own project, you can downl
26
28
27
29
h2. What Is Implemented -- and What Is Not
28
30
29
-
This is a demonstration application that allows you to visit a home page and see a list of users. With the default user's email and password (supplied below), you can log in and view details for each user. You can customize this app as you need.
31
+
This is a demonstration application that allows you to visit a home page and see a list of users. With the default user's email and password (supplied below), you can log in and view details for each user. Devise provides user management so a visitor can register with an email address and password and create an account. Devise provides authentication so access to the site can be limited to users who are registered and logged in.
30
32
31
33
h4. Similar Examples and Tutorials
32
34
33
-
If you'd like to use the Mongoid ORM with the MongoDB datastore instead of ActiveRecord and a SQLite database, see the "rails3-mongoid-devise":https://github.com/RailsApps/rails3-mongoid-devise example app and tutorial. Mongoid makes development quicker without schemas or migrations. The "rails3-mongoid-devise":https://github.com/RailsApps/rails3-mongoid-devise example app and tutorial shows how to set up Devise and Mongoid with RSpec and Cucumber.
35
+
This example application uses ActiveRecord and a SQLite database. You can use the Mongoid ORM with the MongoDB datastore instead, for faster development without schemas or migrations. The "rails3-mongoid-devise":https://github.com/RailsApps/rails3-mongoid-devise example app and tutorial shows how to set up Devise and Mongoid with RSpec and Cucumber.
34
36
35
-
See an expanded list of more "Rails examples, tutorials, and starter apps":http://railsapps.github.com/rails-examples-tutorials.html.
37
+
See an expanded list of similar "Rails examples, tutorials, and starter apps":http://railsapps.github.com/rails-examples-tutorials.html.
36
38
37
39
h2. Dependencies
38
40
@@ -47,7 +49,15 @@ h2. Getting the Application
47
49
48
50
You have several options for getting the code.
49
51
50
-
h4. Downloading the Code
52
+
h4. Fork, Clone, or Generate?
53
+
54
+
_Fork:_ If you'd like to add features (or bug fixes) to improve the example application, you can fork the GitHub repo and "make pull requests":http://help.github.com/send-pull-requests/. Your code contributions are welcome!
55
+
56
+
_Clone:_ If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo. You'll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below).
57
+
58
+
_Generate:_ If you want to use the project as a starter app for your customized application, use the application template to generate a new version of the example app. You'll be able to give it your project name when you generate the app.
59
+
60
+
h4. Clone the Repository
51
61
52
62
If you simply wish to examine the example code, you can download the code ("clone the repository") with the command
53
63
@@ -64,39 +74,43 @@ You can use an application template to generate a new version of the example app
64
74
To build the "rails3-devise-rspec-cucumber" example application, run the command:
65
75
66
76
<pre>
67
-
rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-devise-rspec-cucumber-template.rb -T
77
+
$ rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-devise-rspec-cucumber-template.rb -T
68
78
</pre>
69
79
70
80
Use the @-T@ flag to skip Test::Unit files.
71
81
82
+
The @$@ character indicates a shell prompt; don't include it when you run the command.
83
+
72
84
This creates a new Rails app (with the name @myapp@) on your computer.
73
85
74
-
The application generator template will ask you for your preferences:
75
-
76
-
* Would you like to use Haml instead of ERB?
77
-
* Would you like to use RSpec instead of TestUnit?
78
-
* Would you like to use factory_girl for test fixtures with RSpec?
79
-
* Would you like to use Cucumber for your BDD?
80
-
* Would you like to use Guard to automate your workflow?
81
-
* Would you like to use Devise for authentication?
82
-
* Would you like to install HTML5 Boilerplate?
83
-
* Normalize CSS and use Skeleton boilerplate?
84
-
* Normalize CSS for consistent styling across browsers?
85
-
* Completely reset all CSS to eliminate styling?
86
-
* Would you like to set a robots.txt file to ban spiders?
87
-
* Would you like to use ‘rails-footnotes’ during development?
86
+
The application generator templates will ask you for various preferences:
87
+
88
+
* Would you like to use "Haml":http://en.wikipedia.org/wiki/Haml instead of ERB?
89
+
* Would you like to use "RSpec":http://rspec.info/ instead of TestUnit?
90
+
* Would you like to use "factory_girl":https://github.com/thoughtbot/factory_girl for test fixtures with RSpec?
91
+
* Would you like to use "machinist":https://github.com/notahat/machinist for test fixtures with RSpec?
92
+
* Would you like to use "Cucumber":http://cukes.info/ for your BDD?
93
+
* Would you like to use "Guard":http://intridea.com/posts/hire-a-guard-for-your-project to automate your workflow?
94
+
* Would you like the app to use a Gmail account to send email?
95
+
* Would you like to use "Devise":http://github.com/plataformatec/devise for authentication?
96
+
## No
97
+
## Devise with default modules
98
+
## Devise with Confirmable module
99
+
## Devise with Confirmable and Invitable modules
88
100
* Which front-end framework would you like for HTML5 and CSS3?
* Would you like to use "rails-footnotes":https://github.com/josevalim/rails-footnotes during development?
107
+
* Would you like to set a robots.txt file to ban spiders?
94
108
95
109
h4. Use "Recipes" to Customize an Application Template
96
110
97
-
The "tutorial":http://railsapps.github.com/tutorial-rails-devise-rspec-cucumber.html shows how a customized application template can be assembled from "recipes." The application template was created using the "Rails Apps Composer":https://github.com/RailsApps/rails_apps_composer gem which provides a convenient way to assemble a reusable application template by selecting various "recipes" for popular Rails development packages.
111
+
The application template was created using the "rails_apps_composer":https://github.com/RailsApps/rails_apps_composer gem which provides a convenient way to assemble a reusable application template by selecting various "recipes" for popular Rails development packages. Use "rails_apps_composer":https://github.com/RailsApps/rails_apps_composer if you want to customize the application template for your own starter apps.
98
112
99
-
h4. Please Remember: Edit the README
113
+
h4. Edit the README
100
114
101
115
If you're open sourcing the app on GitHub, please edit the README file to add a description of the app and your contact info. Changing the README is important if you're using a clone of the example app. I've been mistaken (and contacted) as the author of apps that are copied from my example.
102
116
@@ -114,6 +128,8 @@ The application uses the following gems:
114
128
* "capybara":http://rubygems.org/gems/capybara
115
129
* "devise":http://rubygems.org/gems/devise
116
130
131
+
See "Example Gemfiles for Rails 3.2":http://railsapps.github.com/rails-3-2-example-gemfile.html.
132
+
117
133
h4. Install the Required Gems
118
134
119
135
Install the required gems on your computer:
@@ -126,26 +142,60 @@ You can check which gems are installed on your computer with:
126
142
127
143
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.
128
144
129
-
h4. Set Up Configuration for Devise
145
+
h2. Configure Email
130
146
131
-
This app uses "Devise":http://github.com/plataformatec/devise for user management and authentication.
147
+
You must configure the app for your email account if you want your application to send email messages, for example, if you've generated the application with the option to install the Devise @:confirmable@ module.
132
148
133
-
You can modify the configuration file for Devise if you want to use something other than the defaults:
149
+
h4. Use a Gmail account
134
150
135
-
*config/initializers/devise.rb*
151
+
If you've generated the application with the option to use a Gmail account to send email, you'll need to modify the files *config/environments/development.rb* and *config/environments/production.rb* to include your Gmail username and password.
152
+
153
+
<pre>
154
+
config.action_mailer.smtp_settings = {
155
+
address: "smtp.gmail.com",
156
+
port: 587,
157
+
domain: "example.com",
158
+
authentication: "plain",
159
+
enable_starttls_auto: true,
160
+
user_name: ENV["GMAIL_USERNAME"],
161
+
password: ENV["GMAIL_PASSWORD"]
162
+
}
163
+
</pre>
164
+
165
+
You can replace @ENV["GMAIL_USERNAME"]@ and @ENV["GMAIL_PASSWORD"]@ with your Gmail username and password. However, committing the file to a public GitHub repository will expose your secret password.
166
+
167
+
If you're familiar with setting "Unix environment variables":http://en.wikipedia.org/wiki/Environment_variable, it's advisable to leave @config.action_mailer.smtp_settings@ unchanged and set your environment variables in the file that is read when starting an interactive shell (the *~/.bashrc* file for the bash shell). This will keep the password out of your repository.
168
+
169
+
Are you using a bash shell? Use @echo $SHELL@ to find out. For a bash shell, edit the *~/.bashrc* file and add:
170
+
171
+
<pre>
172
+
export GMAIL_USERNAME="myname@gmail.com"
173
+
export GMAIL_PASSWORD="secret*"
174
+
</pre>
175
+
176
+
Open a new shell or restart your terminal application to continue.
136
177
137
-
h4. Configure Email for Devise
178
+
h4. Configure ActionMailer
138
179
139
-
Configure email by modifying
180
+
The example application is set to deliver email in both development and production. It will raise deliervy errors in development but not production.
181
+
182
+
In development, @config.action_mailer.default_url_options@ is set for a host at @localhost:3000@ which will enable links in Devise confirmation email messages to work properly. You'll need to change the @config.action_mailer.default_url_options@ host option from @example.com@ to your own domain for the production environment.
183
+
184
+
You can change these values as needed in the *config/environments/development.rb* and *config/environments/production.rb* files.
185
+
186
+
h4. Configure Devise for Email
187
+
188
+
Complete your email configuration by modifying
140
189
141
190
*config/initializers/devise.rb*
142
191
143
-
and setting the return email address for emails sent from the application.
192
+
and setting the @config.mailer_sender@ option for the return email address for messages that Devise sends from the application.
193
+
194
+
h2. Configure Devise
144
195
145
-
You may need to set values for your mailhost in
196
+
You can modify the configuration file for Devise if you want to use something other than the defaults:
Use the defaults or change the values for name, email, and password as you wish.
163
213
164
-
h4. Seed the Database
214
+
If you've generated the application with the option to install the Devise @:confirmable@ module, there will be an extra attribute @confirmed_at => Time.now@ for creation of a user.
215
+
216
+
h4. Set the Database
217
+
218
+
Prepare the database and add the default user to the database by running the commands:
219
+
220
+
<pre>
221
+
$ bundle exec rake db:migrate
222
+
$ bundle exec rake db:seed
223
+
</pre>
165
224
166
-
Add the default user to the database by running the command:
225
+
Set the database for running tests:
167
226
168
-
@$ rake db:migrate@
169
-
@$ rake db:seed@
227
+
<pre>
228
+
$ bundle exec rake db:test:prepare
229
+
</pre>
170
230
171
-
h4. Test the App
231
+
h2. Test the App
172
232
173
233
You can check that your app runs properly by entering the command
174
234
@@ -185,7 +245,7 @@ You should delete or change the pre-configured logins before you deploy your app
185
245
186
246
h2. Deploy to Heroku
187
247
188
-
For your convenience, here are instructions for "deploying your app to Heroku":http://railsapps.github.com/rails-heroku-tutorial.html. Heroku provides low cost, easily configured Rails application hosting.
248
+
For your convenience, here is a "Tutorial for Rails on Heroku":http://railsapps.github.com/rails-heroku-tutorial.html. Heroku provides low cost, easily configured Rails application hosting.
189
249
190
250
h2. Customizing
191
251
@@ -195,15 +255,15 @@ This application provides no useful functionality apart from demonstrating Devis
195
255
196
256
h2. Testing
197
257
198
-
The application contains RSpec unit tests and Cucumber scenarios and steps. The tests are minimal and can be improved.
199
-
200
-
Please send the author a message, create an issue, or submit a pull request if you can contribute improved RSpec or Cucumber files.
258
+
The example application contains a suite of RSpec unit tests and Cucumber scenarios and step definitions.
201
259
202
260
After installing the application, run @rake -T@ to check that rake tasks for RSpec and Cucumber are available.
203
261
204
262
Run @rake spec@ to run all RSpec tests.
205
263
206
-
Run @rake cucumber@ (or more simply, @cucumber@) to run all Cucumber scenarios and steps.
264
+
Run @rake cucumber@ (or more simply, @cucumber@) to run all Cucumber scenarios.
265
+
266
+
Please send the author a message, create an issue, or submit a pull request if you can contribute improved RSpec or Cucumber files.
207
267
208
268
h2. Documentation and Support
209
269
@@ -236,10 +296,6 @@ Daniel Kehoe ("http://danielkehoe.com/":http://danielkehoe.com/) implemented the
236
296
Is the app useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps
237
297
and tweet some praise. I'd love to know you were helped out by what I've put together.
0 commit comments