Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added feature for ensuring that a user is signed in

             via a confirmation email by using email spec
  • Loading branch information...
commit f87fa45725ca3daa312f2da19c27a3c65120ee9b 1 parent c7c173d
@wycats authored
View
1  Gemfile
@@ -35,5 +35,6 @@ group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl'
+ gem 'email_spec'
end
View
158 Gemfile.lock
@@ -1,71 +1,73 @@
GIT
remote: git://github.com/rack/rack.git
- revision: 4d93f90b58b09329a227fac975228eeef76f2952
+ revision: 404f2f167f9f7d89d0662870ed13cde827703139
specs:
- rack (1.2.1)
+ rack (1.3.0)
GIT
remote: git://github.com/rails/arel.git
- revision: f72989de5b3b3cfb6e6e639b57c3a3bebb2de8f2
+ revision: 593002080cbcbb6e14acf3bc909aab819811f215
specs:
- arel (2.0.7.beta.20110228092631)
+ arel (2.1.1.20110518143805)
GIT
remote: git://github.com/rails/rails.git
- revision: 724a7866774c7847cc79b699ccf7da9fee72b154
+ revision: a1e78cfc36960569cf8cd380d9656ac6c14015ae
specs:
- actionmailer (3.1.0.beta)
- actionpack (= 3.1.0.beta)
- mail (~> 2.2.16)
- actionpack (3.1.0.beta)
- activemodel (= 3.1.0.beta)
- activesupport (= 3.1.0.beta)
+ actionmailer (3.1.0.rc1)
+ actionpack (= 3.1.0.rc1)
+ mail (~> 2.3.0)
+ actionpack (3.1.0.rc1)
+ activemodel (= 3.1.0.rc1)
+ activesupport (= 3.1.0.rc1)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- i18n (~> 0.5.0)
- rack (~> 1.2.1)
- rack-cache (~> 1.0.0)
- rack-mount (~> 0.7.1)
- rack-test (~> 0.5.7)
- tzinfo (~> 0.3.23)
- activemodel (3.1.0.beta)
- activesupport (= 3.1.0.beta)
+ i18n (~> 0.6)
+ rack (~> 1.3.0)
+ rack-cache (~> 1.0.1)
+ rack-mount (~> 0.8.1)
+ rack-test (~> 0.6.0)
+ sprockets (~> 2.0.0.beta.10)
+ tzinfo (~> 0.3.27)
+ activemodel (3.1.0.rc1)
+ activesupport (= 3.1.0.rc1)
bcrypt-ruby (~> 2.1.4)
builder (~> 3.0.0)
- i18n (~> 0.5.0)
- activerecord (3.1.0.beta)
- activemodel (= 3.1.0.beta)
- activesupport (= 3.1.0.beta)
- arel (~> 2.0.2)
- tzinfo (~> 0.3.23)
- activeresource (3.1.0.beta)
- activemodel (= 3.1.0.beta)
- activesupport (= 3.1.0.beta)
- activesupport (3.1.0.beta)
- multi_json (~> 1.0.0.rc3)
- rails (3.1.0.beta)
- actionmailer (= 3.1.0.beta)
- actionpack (= 3.1.0.beta)
- activerecord (= 3.1.0.beta)
- activeresource (= 3.1.0.beta)
- activesupport (= 3.1.0.beta)
+ i18n (~> 0.6)
+ activerecord (3.1.0.rc1)
+ activemodel (= 3.1.0.rc1)
+ activesupport (= 3.1.0.rc1)
+ arel (~> 2.1.1)
+ tzinfo (~> 0.3.27)
+ activeresource (3.1.0.rc1)
+ activemodel (= 3.1.0.rc1)
+ activesupport (= 3.1.0.rc1)
+ activesupport (3.1.0.rc1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ rails (3.1.0.rc1)
+ actionmailer (= 3.1.0.rc1)
+ actionpack (= 3.1.0.rc1)
+ activerecord (= 3.1.0.rc1)
+ activeresource (= 3.1.0.rc1)
+ activesupport (= 3.1.0.rc1)
bundler (~> 1.0)
- railties (= 3.1.0.beta)
- railties (3.1.0.beta)
- actionpack (= 3.1.0.beta)
- activesupport (= 3.1.0.beta)
+ railties (= 3.1.0.rc1)
+ railties (3.1.0.rc1)
+ actionpack (= 3.1.0.rc1)
+ activesupport (= 3.1.0.rc1)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
- thor (~> 0.14.4)
+ thor (~> 0.14.6)
GIT
remote: git://github.com/sstephenson/sprockets.git
- revision: 885a395317831982d0b375f7372287ef22d433c8
+ revision: f34395cdc4db915a8710a73fe676bb68075610e7
specs:
- sprockets (2.0.0)
- hike (>= 0.7.0)
- rack (>= 1.0.0)
- tilt (>= 1.1.0)
+ sprockets (2.0.0.beta.10)
+ hike (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
GEM
remote: http://rubygems.org/
@@ -82,16 +84,16 @@ GEM
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.3)
celerity (0.8.9)
- childprocess (0.1.8)
+ childprocess (0.1.9)
ffi (~> 1.0.6)
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.0.1)
- cucumber (0.10.2)
+ coffee-script-source (1.1.1)
+ cucumber (0.10.6)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
- gherkin (>= 2.3.5)
+ gherkin (~> 2.4.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
cucumber-rails (0.4.1)
@@ -106,52 +108,53 @@ GEM
warden (~> 1.0.3)
diff-lcs (1.1.2)
dynamic_form (1.1.4)
+ email_spec (1.1.1)
+ rspec (~> 2.0)
erubis (2.7.0)
- execjs (0.2.0)
+ execjs (1.1.0)
+ multi_json (~> 1.0)
factory_girl (1.3.3)
- ffi (1.0.7)
- rake (>= 0.8.7)
- gherkin (2.3.6)
+ ffi (1.0.9)
+ gherkin (2.4.0)
json (>= 1.4.6)
- hike (0.7.1)
- i18n (0.5.0)
+ hike (1.0.0)
+ i18n (0.6.0)
json (1.5.1)
json_pure (1.5.1)
- mail (2.2.17)
- activesupport (>= 2.3.6)
+ mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- multi_json (1.0.0.rc3)
+ multi_json (1.0.3)
nokogiri (1.4.4)
orm_adapter (0.0.5)
polyglot (0.3.1)
- rack-cache (1.0.1)
+ rack-cache (1.0.2)
rack (>= 0.4)
- rack-mount (0.7.2)
+ rack-mount (0.8.1)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
- rack-test (0.5.7)
+ rack-test (0.6.0)
rack (>= 1.0)
- rake (0.8.7)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
+ rake (0.9.2)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
- rspec-rails (2.5.0)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
- rspec (~> 2.5.0)
+ rspec (~> 2.6.0)
rubyzip (0.9.4)
- sass (3.1.0.alpha.256)
- selenium-webdriver (0.1.4)
+ sass (3.1.2)
+ selenium-webdriver (0.2.1)
childprocess (>= 0.1.7)
ffi (>= 1.0.7)
json_pure
@@ -159,13 +162,13 @@ GEM
sqlite3 (1.3.3)
term-ansicolor (1.0.5)
thor (0.14.6)
- tilt (1.2.2)
+ tilt (1.3.2)
treetop (1.4.9)
polyglot (>= 0.3.1)
- tzinfo (0.3.26)
+ tzinfo (0.3.27)
warden (1.0.4)
rack (>= 1.0)
- xpath (0.1.3)
+ xpath (0.1.4)
nokogiri (~> 1.3)
PLATFORMS
@@ -179,6 +182,7 @@ DEPENDENCIES
database_cleaner
devise
dynamic_form
+ email_spec
factory_girl
rack!
rails!
View
3  app/models/user.rb
@@ -2,7 +2,8 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable
+ :recoverable, :rememberable, :trackable,
+ :validatable, :confirmable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
View
6 app/views/layouts/application.html.erb
@@ -15,7 +15,11 @@
<% end %>
<h1><%= link_to "Ticketee", root_path %></h1>
<nav>
- <%= link_to "Sign up", new_user_registration_path %>
+ <% if user_signed_in? %>
+ Signed in as <%= current_user.email %>
+ <% else %>
+ <%= link_to "Sign up", new_user_registration_path %>
+ <% end %>
</nav>
<%= yield %>
</body>
View
7 db/migrate/20110607231443_add_confirmable_fields_to_users.rb
@@ -0,0 +1,7 @@
+class AddConfirmableFieldsToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :confirmation_token, :string
+ add_column :users, :confirmed_at, :datetime
+ add_column :users, :confirmation_sent_at, :datetime
+ end
+end
View
5 db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110607224324) do
+ActiveRecord::Schema.define(:version => 20110607231443) do
create_table "projects", :force => true do |t|
t.string "name"
@@ -41,6 +41,9 @@
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "confirmation_token"
+ t.datetime "confirmed_at"
+ t.datetime "confirmation_sent_at"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
View
14 features/signing_in.feature
@@ -0,0 +1,14 @@
+Feature: Signing in
+ In order to use the site
+ As a user
+ I want to be able to sign in
+
+ Scenario: Signing in via confirmation
+ Given there are the following users:
+ | email | password |
+ | user@ticketee.com | password |
+ And "user@ticketee.com" opens the email with subject "Confirmation instructions"
+ And they click the first link in the email
+ Then I should see "Your account was successfully confirmed"
+ And I should see "Signed in as user@ticketee.com"
+
View
194 features/step_definitions/email_steps.rb
@@ -0,0 +1,194 @@
+# Commonly used email steps
+#
+# To add your own steps make a custom_email_steps.rb
+# The provided methods are:
+#
+# last_email_address
+# reset_mailer
+# open_last_email
+# visit_in_email
+# unread_emails_for
+# mailbox_for
+# current_email
+# open_email
+# read_emails_for
+# find_email
+#
+# General form for email scenarios are:
+# - clear the email queue (done automatically by email_spec)
+# - execute steps that sends an email
+# - check the user received an/no/[0-9] emails
+# - open the email
+# - inspect the email contents
+# - interact with the email (e.g. click links)
+#
+# The Cucumber steps below are setup in this order.
+
+module EmailHelpers
+ def current_email_address
+ # Replace with your a way to find your current email. e.g @current_user.email
+ # last_email_address will return the last email address used by email spec to find an email.
+ # Note that last_email_address will be reset after each Scenario.
+ last_email_address || "example@example.com"
+ end
+end
+
+World(EmailHelpers)
+
+#
+# Reset the e-mail queue within a scenario.
+# This is done automatically before each scenario.
+#
+
+Given /^(?:a clear email queue|no emails have been sent)$/ do
+ reset_mailer
+end
+
+#
+# Check how many emails have been sent/received
+#
+
+Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
+ unread_emails_for(address).size.should == parse_email_count(amount)
+end
+
+Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
+ mailbox_for(address).size.should == parse_email_count(amount)
+end
+
+Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
+ unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
+end
+
+Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
+ open_email(address, :with_text => expected_body)
+end
+
+#
+# Accessing emails
+#
+
+# Opens the most recently received email
+When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
+ open_email(address)
+end
+
+When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
+ open_email(address, :with_subject => subject)
+end
+
+When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
+ open_email(address, :with_text => text)
+end
+
+#
+# Inspect the Email Contents
+#
+
+Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
+ current_email.should have_subject(text)
+end
+
+Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
+ current_email.should have_subject(Regexp.new(text))
+end
+
+Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
+ current_email.default_part_body.to_s.should include(text)
+end
+
+Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
+ current_email.default_part_body.to_s.should =~ Regexp.new(text)
+end
+
+Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
+ current_email.should be_delivered_from(text)
+end
+
+Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
+ current_email.should have_header(name, text)
+end
+
+Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
+ current_email.should have_header(name, Regexp.new(text))
+end
+
+Then /^I should see it is a multi\-part email$/ do
+ current_email.should be_multipart
+end
+
+Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text|
+ current_email.html_part.body.to_s.should include(text)
+end
+
+Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text|
+ current_email.text_part.body.to_s.should include(text)
+end
+
+#
+# Inspect the Email Attachments
+#
+
+Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
+ current_email_attachments.size.should == parse_email_count(amount)
+end
+
+Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
+ current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount)
+end
+
+Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
+ current_email_attachments[(index.to_i - 1)].filename.should == filename
+end
+
+Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
+ current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount)
+end
+
+Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
+ current_email_attachments[(index.to_i - 1)].content_type.should include(content_type)
+end
+
+Then /^all attachments should not be blank$/ do
+ current_email_attachments.each do |attachment|
+ attachment.read.size.should_not == 0
+ end
+end
+
+Then /^show me a list of email attachments$/ do
+ EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
+end
+
+#
+# Interact with Email Contents
+#
+
+When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
+ visit_in_email(link)
+end
+
+When /^(?:I|they) click the first link in the email$/ do
+ click_first_link_in_email
+end
+
+#
+# Debugging
+# These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command.
+# Patches accepted. ;)
+#
+
+Then /^save and open current email$/ do
+ EmailSpec::EmailViewer::save_and_open_email(current_email)
+end
+
+Then /^save and open all text emails$/ do
+ EmailSpec::EmailViewer::save_and_open_all_text_emails
+end
+
+Then /^save and open all html emails$/ do
+ EmailSpec::EmailViewer::save_and_open_all_html_emails
+end
+
+Then /^save and open all raw emails$/ do
+ EmailSpec::EmailViewer::save_and_open_all_raw_emails
+end
View
8 features/step_definitions/user_steps.rb
@@ -0,0 +1,8 @@
+ActiveSupport::SecureRandom = SecureRandom
+
+Given /^there are the following users:$/ do |table|
+ table.hashes.each do |attributes|
+ @user = User.create!(attributes)
+ end
+end
+
View
1  features/support/email.rb
@@ -0,0 +1 @@
+require 'email_spec/cucumber'
Please sign in to comment.
Something went wrong with that request. Please try again.