Skip to content

Commit

Permalink
added a few integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minhajuddin committed Jul 12, 2011
1 parent 299bcd6 commit 1ba1b5d
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 9 deletions.
1 change: 1 addition & 0 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ guard 'rspec', :version => 2, :cli => "--color --format nested --fail-fast --drb
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch('spec/factories.rb') { "spec" }

# Rails example
watch(%r{^spec/.+_spec\.rb$})
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class HomeController < ApplicationController
before_filter :authenticate_user!

def index
end
end
1 change: 1 addition & 0 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%h1 Home
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@

# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr


config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
end
15 changes: 8 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
#empty all collections#
[User].each &:destroy_all

#users#
admin = User.create! :email => 'admin@mailinator.com', :password => 'please', :password_confirmation => 'please'
admin.confirm!
user = User.create! :email => 'user@mailinator.com', :password => 'please', :password_confirmation => 'please'
user.confirm!
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe ProjectController do
describe ProjectsController do

describe "GET 'index'" do
it "should be successful" do
Expand Down
12 changes: 12 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Factory.define :admin, :class => :user do |user|
user.email 'admin@mailinator.com'
user.password 'please'
user.password_confirmation 'please'
#user.role 'admin'
end

Factory.define :user do |user|
user.email 'user@mailinator.com'
user.password 'please'
user.password_confirmation 'please'
end
23 changes: 23 additions & 0 deletions spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe "Authentication" do
describe "SignIn" do

it "should redirect to sign_in page when user is not logged in" do
visit root_path
page.should have_content("You need to sign in or sign up before continuing.")
end

it "should render home page when login is successful" do
@admin = Factory(:admin)
@admin.confirm!
visit new_user_session_path
fill_in "Email", with: @admin.email
fill_in "Password", with: 'please'
click_button "Sign in"

page.should have_content "Signed in successfully."
end

end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

Spork.each_run do
# This code will be run each time you run your specs.

Factory.factories.clear
load Rails.root.join 'spec/factories.rb'
end

# --- Instructions ---
Expand Down

0 comments on commit 1ba1b5d

Please sign in to comment.