Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Tests are running
Browse files Browse the repository at this point in the history
  • Loading branch information
nbibler committed Mar 4, 2010
1 parent ea6ef7a commit 2dc63c3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 47 deletions.
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ begin
gem.email = "nate@envylabs.com"
gem.homepage = "http://github.com/envylabs/blue_light_special"
gem.authors = ["Nathaniel Bibler"]

gem.add_dependency "facebooker", '=1.0.62'

gem.add_development_dependency "shoulda", ">= 0"
end
Jeweler::GemcutterTasks.new
Expand Down
6 changes: 3 additions & 3 deletions generators/blue_light_special/blue_light_special_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ def manifest
record do |m|
m.directory File.join("config", "initializers")
m.file "blue_light_special.rb", "config/initializers/blue_light_special.rb"

m.insert_into "app/controllers/application_controller.rb",
"include BlueLightSpecial::Authentication"

user_model = "app/models/user.rb"
if File.exists?(user_model)
m.insert_into user_model, "include BlueLightSpecial::User"
else
m.directory File.join("app", "models")
m.file "user.rb", user_model
end

m.insert_into "config/routes.rb",
"BlueLightSpecial::Routes.draw(map)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@ class SignOutTest < ActionController::IntegrationTest

context 'Signing out as a user' do

stubbing_any_authorize_net_customer_profile_request do

should 'see "Signed out"' do
sign_up(:email => 'bob@bob.bob')
sign_out
assert_match(/Signed out/, response.body)
end

should 'be signed out' do
sign_up(:email => 'bob@bob.bob')
sign_out
assert !controller.signed_in?
end

should 'be signed out when I return' do
sign_up(:email => 'bob@bob.bob')
sign_out
visit root_url
assert !controller.signed_in?
end

should 'see "Signed out"' do
sign_up(:email => 'bob@bob.bob')
sign_out
assert_match(/Signed out/, response.body)
end

should 'be signed out' do
sign_up(:email => 'bob@bob.bob')
sign_out
assert !controller.signed_in?
end

should 'be signed out when I return' do
sign_up(:email => 'bob@bob.bob')
sign_out
visit root_url
assert !controller.signed_in?
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,23 @@ class SignUpTest < ActionController::IntegrationTest

context 'with valid data' do

stubbing_any_authorize_net_customer_profile_request do

should 'sign in the user' do
sign_up(:email => 'bob@bob.bob', :password => 'password', :password_confirmation => 'password')
assert controller.signed_in?
end

should 'see "Thanks for signing up with Twongo!"' do
sign_up(:email => 'bob@bob.bob', :password => 'password', :password_confirmation => 'password')
assert_match /Thanks for signing up with Twongo!/, response.body
end

should 'send a welcome email' do
sign_up(:email => 'bob@bob.bob', :password => 'password', :password_confirmation => 'password')
user = User.find_by_email('bob@bob.bob')
Delayed::Job.work_off
sent = ActionMailer::Base.deliveries.last
assert_equal user.email, sent.recipients
assert_match /welcome/i, sent.subject
end

should 'sign in the user' do
sign_up(:email => 'bob@bob.bob', :password => 'password', :password_confirmation => 'password')
assert controller.signed_in?
end

should 'see "Thanks for signing up with Twongo!"' do
sign_up(:email => 'bob@bob.bob', :password => 'password', :password_confirmation => 'password')
assert_match /Thanks for signing up with Twongo!/, response.body
end

should 'send a welcome email' do
sign_up(:email => 'bob@bob.bob', :password => 'password', :password_confirmation => 'password')
user = User.find_by_email('bob@bob.bob')
Delayed::Job.work_off
sent = ActionMailer::Base.deliveries.last
assert_equal user.email, sent.recipients
assert_match /welcome/i, sent.subject
end

end
Expand Down
42 changes: 40 additions & 2 deletions lib/blue_light_special/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def self.included(controller) # :nodoc:

module ClassMethods
def self.extended(controller)
controller.helper_method :current_user, :signed_in?, :signed_out?
controller.helper_method :current_user, :signed_in?, :signed_out?, :facebook_session, :impersonating?
controller.hide_action :current_user, :current_user=,
:signed_in?, :signed_out?,
:sign_in, :sign_out,
:authenticate, :deny_access

controller.before_filter :find_facebook_session
end
end

Expand Down Expand Up @@ -89,6 +89,7 @@ def deny_access(flash_message = nil)
flash[:failure] = flash_message if flash_message
redirect_to(sign_in_url)
end


protected

Expand Down Expand Up @@ -125,6 +126,43 @@ def clear_return_to
def redirect_to_root
redirect_to('/')
end

def impersonating?
!session[:admin_user_id].blank?
end

##
# Sets up the facebook session if the logged-in user is from facebook
#--
# FIXME: Use i18n interface for flash.
#++
def find_facebook_session
set_facebook_session
if facebook_session
unless signed_in?
facebook_session.user.populate
sign_in(User.find_facebook_user(facebook_session.user))
end
elsif signed_in? && current_user.facebook_user? && !impersonating?
facebook_sign_out
end
rescue Facebooker::Session::SessionExpired
flash.now[:error] = "You have logged out of Facebook"
facebook_sign_out
rescue NoMethodError
flash[:error] = "Unable to connect to Facebook"
facebook_sign_out
redirect_to sign_in_path
end

##
# Sign the user out and clear the Facebook session info
#
def facebook_sign_out
clear_fb_cookies!
clear_facebook_session_information
sign_out
end
end

end
Expand Down

0 comments on commit 2dc63c3

Please sign in to comment.