From 39728be404ca43744cc29c8a253aa957d0de4dfc Mon Sep 17 00:00:00 2001 From: Kyle Partridge Date: Wed, 28 Dec 2011 16:10:26 -0800 Subject: [PATCH 1/8] created some basic tests for user --- spec/factories/users.rb | 2 ++ spec/models/user_spec.rb | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index d2dd4de..4763afd 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -2,5 +2,7 @@ FactoryGirl.define do factory :user do + email "test@example.com" + password "secret" end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 44032b4..9b3fcbc 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,20 @@ require 'spec_helper' describe User do - pending "add some examples to (or delete) #{__FILE__}" + + it "should require an email address" do + user = build(:user, email: nil) + user.should_not be_valid + end + + it "should only allow a valid email" do + user = build(:user, email: "bad/email") + user.should_not be_valid + end + + it "should require a password" do + user = build(:user, password: nil) + user.should_not be_valid + end + end From cc9fab946deba244a614d60fb3cb7cde0dd81f98 Mon Sep 17 00:00:00 2001 From: Kyle Partridge Date: Wed, 28 Dec 2011 16:50:16 -0800 Subject: [PATCH 2/8] made the user factory use a sequence --- spec/factories/users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 4763afd..c6817f5 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :user do - email "test@example.com" + sequence(:email) { |n| "test#{n}@example.com" } password "secret" end end From 1b5168f15d19569888be5e2dd3dc118da091ba93 Mon Sep 17 00:00:00 2001 From: Kyle Partridge Date: Wed, 28 Dec 2011 17:26:38 -0800 Subject: [PATCH 3/8] Added copybara for rspec and fixed guard settings --- Gemfile | 4 ++++ Gemfile.lock | 21 +++++++++++++++++++++ spec/spec_helper.rb | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f56b307..7bafe7b 100644 --- a/Gemfile +++ b/Gemfile @@ -42,8 +42,12 @@ group :test, :development do gem 'guard' gem 'guard-spork' + gem 'rb-readline' + gem 'guard-rspec' gem 'rspec-rails' + gem 'capybara' + gem 'growl', :require => false end diff --git a/Gemfile.lock b/Gemfile.lock index f01e681..b9940da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,6 +33,15 @@ GEM arel (2.2.1) bcrypt-ruby (3.0.1) builder (3.0.0) + capybara (1.1.2) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + selenium-webdriver (~> 2.0) + xpath (~> 0.1.4) + childprocess (0.2.4) + ffi (~> 1.0.6) coffee-rails (3.1.1) coffee-script (>= 2.2.0) railties (~> 3.1.0) @@ -75,6 +84,7 @@ GEM treetop (~> 1.4.8) mime-types (1.17.2) multi_json (1.0.4) + nokogiri (1.5.0) orm_adapter (0.0.5) polyglot (0.3.3) rack (1.3.5) @@ -102,6 +112,7 @@ GEM rdoc (~> 3.4) thor (~> 0.14.6) rake (0.9.2.2) + rb-readline (0.4.2) rdoc (3.12) json (~> 1.4) rspec (2.7.0) @@ -117,12 +128,18 @@ GEM activesupport (~> 3.0) railties (~> 3.0) rspec (~> 2.7.0) + rubyzip (0.9.5) sass (3.1.12) sass-rails (3.1.5) actionpack (~> 3.1.0) railties (~> 3.1.0) sass (~> 3.1.10) tilt (~> 1.3.2) + selenium-webdriver (2.15.0) + childprocess (>= 0.2.1) + ffi (~> 1.0.9) + multi_json (~> 1.0.4) + rubyzip spork (0.9.0.rc9) sprockets (2.0.3) hike (~> 1.2) @@ -142,11 +159,14 @@ GEM multi_json (>= 1.0.2) warden (1.1.0) rack (>= 1.0) + xpath (0.1.4) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES + capybara coffee-rails (~> 3.1.1) devise factory_girl_rails @@ -156,6 +176,7 @@ DEPENDENCIES guard-spork jquery-rails rails (= 3.1.3) + rb-readline rspec-rails sass-rails (~> 3.1.5) spork (>= 0.9.0.rc8) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0885bc..874be40 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ require 'rubygems' require 'spork' +require 'capybara/rspec' Spork.prefork do # This file is copied to spec/ when you run 'rails generate rspec:install' @@ -35,4 +36,4 @@ # Require Factory Girls config.include FactoryGirl::Syntax::Methods end -end \ No newline at end of file +end From a50dcc844a018b4c18023e62ca68ca71e028d886 Mon Sep 17 00:00:00 2001 From: Kyle Partridge Date: Thu, 29 Dec 2011 13:47:39 -0800 Subject: [PATCH 4/8] added tests for sign up --- spec/integration/signup_spec.rb | 62 +++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 5 ++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 spec/integration/signup_spec.rb diff --git a/spec/integration/signup_spec.rb b/spec/integration/signup_spec.rb new file mode 100644 index 0000000..309e832 --- /dev/null +++ b/spec/integration/signup_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +# simple sign up macro for a user +def sign_up(user) + within "#user_new" do + fill_in "user_email", with: user.email + fill_in "user_password", with: user.password + fill_in "user_password_confirmation", with: user.password_confirmation + + click_button 'Sign up' + end +end + +describe "the signup process", type: :request do + + context "with valid parameters" do + before :each do + @user = FactoryGirl.build(:user) + end + + it "signs me up" do + visit new_user_registration_path + + @user.password_confirmation = @user.password + sign_up(@user) + + page.should have_content(@user.email) + end + end + + context "with invalid parameters" do + before do + visit new_user_registration_path + end + + it "should require an email" do + user = build(:user, email: nil) + sign_up user + page.should have_content("Email can't be blank") + end + + it "should require a password" do + user = build(:user, password: nil) + sign_up user + page.should have_content("Password can't be blank") + end + + it "should confirm the password" do + user = build(:user) + sign_up user + page.should have_content("Password doesn't match confirmation") + end + + it "should not allow a user to sign up more than once" do + first = create(:user) + user = build(:user, email: first.email) + sign_up user + page.should have_content("Email has already been taken") + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 874be40..145853d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ require 'rubygems' require 'spork' -require 'capybara/rspec' Spork.prefork do # This file is copied to spec/ when you run 'rails generate rspec:install' @@ -8,6 +7,7 @@ require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' + require 'capybara/rspec' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. @@ -35,5 +35,8 @@ # Require Factory Girls config.include FactoryGirl::Syntax::Methods + + # include devise test helpers + config.include Devise::TestHelpers, :type => :controller end end From eba5cccaa60c3f5f561c799b3dab9f0e8242385a Mon Sep 17 00:00:00 2001 From: Kyle Partridge Date: Thu, 29 Dec 2011 14:21:11 -0800 Subject: [PATCH 5/8] testing for the root path on sign up --- spec/integration/signup_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/integration/signup_spec.rb b/spec/integration/signup_spec.rb index 309e832..ed54f11 100644 --- a/spec/integration/signup_spec.rb +++ b/spec/integration/signup_spec.rb @@ -25,6 +25,7 @@ def sign_up(user) sign_up(@user) page.should have_content(@user.email) + current_path.should eq(root_path) end end From 6760e2eca631da080372bcc876c0b19400c9aaf7 Mon Sep 17 00:00:00 2001 From: CJ Buchmann Date: Thu, 29 Dec 2011 14:26:26 -0800 Subject: [PATCH 6/8] Wrote some functional tests for senddit users --- Gemfile | 3 +++ Gemfile.lock | 21 +++++++++++++++++++++ app/views/application/_header.html.erb | 2 +- spec/integration/sign_in_spec.rb | 19 +++++++++++++++++++ spec/spec_helper.rb | 3 +++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 spec/integration/sign_in_spec.rb diff --git a/Gemfile b/Gemfile index f56b307..6db0795 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,9 @@ group :test, :development do gem 'guard-rspec' gem 'rspec-rails' + + gem 'capybara' gem 'growl', :require => false + gem 'ruby_gntp' end diff --git a/Gemfile.lock b/Gemfile.lock index f01e681..7ef35a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,6 +33,15 @@ GEM arel (2.2.1) bcrypt-ruby (3.0.1) builder (3.0.0) + capybara (1.1.2) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + selenium-webdriver (~> 2.0) + xpath (~> 0.1.4) + childprocess (0.2.4) + ffi (~> 1.0.6) coffee-rails (3.1.1) coffee-script (>= 2.2.0) railties (~> 3.1.0) @@ -75,6 +84,7 @@ GEM treetop (~> 1.4.8) mime-types (1.17.2) multi_json (1.0.4) + nokogiri (1.5.0) orm_adapter (0.0.5) polyglot (0.3.3) rack (1.3.5) @@ -117,12 +127,19 @@ GEM activesupport (~> 3.0) railties (~> 3.0) rspec (~> 2.7.0) + ruby_gntp (0.3.4) + rubyzip (0.9.5) sass (3.1.12) sass-rails (3.1.5) actionpack (~> 3.1.0) railties (~> 3.1.0) sass (~> 3.1.10) tilt (~> 1.3.2) + selenium-webdriver (2.15.0) + childprocess (>= 0.2.1) + ffi (~> 1.0.9) + multi_json (~> 1.0.4) + rubyzip spork (0.9.0.rc9) sprockets (2.0.3) hike (~> 1.2) @@ -142,11 +159,14 @@ GEM multi_json (>= 1.0.2) warden (1.1.0) rack (>= 1.0) + xpath (0.1.4) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES + capybara coffee-rails (~> 3.1.1) devise factory_girl_rails @@ -157,6 +177,7 @@ DEPENDENCIES jquery-rails rails (= 3.1.3) rspec-rails + ruby_gntp sass-rails (~> 3.1.5) spork (>= 0.9.0.rc8) sqlite3 diff --git a/app/views/application/_header.html.erb b/app/views/application/_header.html.erb index 53a603b..5db3e59 100644 --- a/app/views/application/_header.html.erb +++ b/app/views/application/_header.html.erb @@ -18,7 +18,7 @@ <%= form_tag user_session_path do %> <%= text_field_tag "user[email]", '', class: "input-small", placeholder: "Email" %> <%= password_field_tag "user[password]", '', class: "input-small", placeholder: "Password" %> - <%= button_tag "Sign in", class: "btn" %> + <%= button_tag "Sign in", class: "btn", id: "header_sign_in" %> <% end %> <% end %> diff --git a/spec/integration/sign_in_spec.rb b/spec/integration/sign_in_spec.rb new file mode 100644 index 0000000..9a0e156 --- /dev/null +++ b/spec/integration/sign_in_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe 'home page' do + it 'logs in with invalid credentials' do + visit '/' + + user = create(:user) + + fill_in('user[email]', :with => user.email) + fill_in('user[password]', :with => user.password) + click_button('header_sign_in') + + current_path.should == '/users/sign_in' + end + + it 'logs in using valid credentials' do + + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0885bc..9b1073f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,9 @@ require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' + + # Add this to load Capybara integration: + require 'capybara/rspec' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. From 27eb9076c43bacd2a84e66806a8891e77f4ac752 Mon Sep 17 00:00:00 2001 From: CJ Buchmann Date: Thu, 29 Dec 2011 15:08:50 -0800 Subject: [PATCH 7/8] Added user sign_in integration tests and also added Aptana Project ignore line. --- .gitignore | 1 + spec/integration/sign_in_spec.rb | 51 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8b7a449..8a557d3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ *.komodoproject .DS_Store +.project diff --git a/spec/integration/sign_in_spec.rb b/spec/integration/sign_in_spec.rb index 9a0e156..cf9e996 100644 --- a/spec/integration/sign_in_spec.rb +++ b/spec/integration/sign_in_spec.rb @@ -7,13 +7,62 @@ user = create(:user) fill_in('user[email]', :with => user.email) - fill_in('user[password]', :with => user.password) + fill_in('user[password]', :with => 'this_is_not_a_valid_password') click_button('header_sign_in') current_path.should == '/users/sign_in' end it 'logs in using valid credentials' do + visit '/' + + user = create(:user) + + fill_in('user[email]', :with => user.email) + fill_in('user[password]', :with => user.password) + click_button('header_sign_in') + + current_path.should == '/' + page.should have_content(user.email) + end + + it 'logs in with invalid credentails and then logs into /users/sign_in with invalid credentials' do + visit '/' + + user = create(:user) + + fill_in('user[email]', :with => user.email) + fill_in('user[password]', :with => 'this_is_not_a_valid_password') + click_button('header_sign_in') + + current_path.should == '/users/sign_in' + + within("form[@id='user_new']") do + fill_in('user[email]', :with => 'testing') + fill_in('user[password]', :with => 'testing') + click_button('Sign in') + end + + current_path.should == '/users/sign_in' + end + + it 'logs in with invalid credentails and then logs into /users/sign_in with valid credentials' do + visit '/' + + user = create(:user) + + fill_in('user[email]', :with => user.email) + fill_in('user[password]', :with => 'this_is_not_a_valid_password') + click_button('header_sign_in') + + current_path.should == '/users/sign_in' + + within("form[@id='user_new']") do + fill_in('user[email]', :with => user.email) + fill_in('user[password]', :with => user.password) + click_button('Sign in') + end + current_path.should == '/' end end \ No newline at end of file From 1d7330dd63a498ed693bf34b99c4ae2b24d384a2 Mon Sep 17 00:00:00 2001 From: CJ Buchmann Date: Thu, 29 Dec 2011 15:16:15 -0800 Subject: [PATCH 8/8] Added tests for signing out --- spec/integration/sign_in_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/integration/sign_in_spec.rb b/spec/integration/sign_in_spec.rb index cf9e996..b7bd6d9 100644 --- a/spec/integration/sign_in_spec.rb +++ b/spec/integration/sign_in_spec.rb @@ -13,7 +13,7 @@ current_path.should == '/users/sign_in' end - it 'logs in using valid credentials' do + it 'logs in and out using valid credentials' do visit '/' user = create(:user) @@ -24,6 +24,11 @@ current_path.should == '/' page.should have_content(user.email) + + click_link('Sign out') + + current_path.should == '/' + page.should have_no_content(user.email) end it 'logs in with invalid credentails and then logs into /users/sign_in with invalid credentials' do @@ -64,5 +69,10 @@ end current_path.should == '/' + + click_link('Sign out') + + current_path.should == '/' + page.should have_no_content(user.email) end end \ No newline at end of file