Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

finally started adding specs to oauth

  • Loading branch information...
commit 07f3564f1b945e4fce290ebfb15946c72094cf86 1 parent 7a7ad6f
@NoamB authored
View
7 Gemfile
@@ -2,11 +2,12 @@ source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
-
+gem "rails", ">= 3.0.0"
+gem 'json', ">= 1.5.1"
+gem 'oauth', ">= 0.4.4"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "rails", ">= 3.0.0"
gem "rspec", "~> 2.3.0"
gem 'rspec-rails'
gem 'ruby-debug19'
@@ -15,6 +16,4 @@ group :development do
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
- gem 'json', ">= 1.5.1"
- gem 'oauth', ">= 0.4.4"
end
View
4 Gemfile.lock
@@ -41,6 +41,7 @@ GEM
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
+ json (1.5.1)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
mail (2.2.13)
@@ -49,6 +50,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
+ oauth (0.4.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
@@ -108,6 +110,8 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
+ json (>= 1.5.1)
+ oauth (>= 0.4.4)
rails (>= 3.0.0)
rspec (~> 2.3.0)
rspec-rails
View
3  Rakefile
@@ -1,4 +1,5 @@
# require 'bundler'
+# -- Commented because it's slow
# begin
# Bundler.setup(:default, :development)
# rescue Bundler::BundlerError => e
@@ -6,6 +7,8 @@
# $stderr.puts "Run `bundle install` to install missing gems"
# exit e.status_code
# end
+# --
+
require 'rake'
require 'jeweler'
View
6 lib/sorcery/test_helpers.rb
@@ -58,6 +58,12 @@ def sorcery_controller_property_set(property, value)
config.send(:"#{property}=", value)
end
end
+
+ def sorcery_controller_oauth_property_set(provider, property, value)
+ ApplicationController.activate_sorcery! do |config|
+ config.send(provider).send(:"#{property}=", value)
+ end
+ end
private
View
1  spec/Gemfile
@@ -3,6 +3,7 @@ source 'http://rubygems.org'
gem "rails", '3.0.3'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem "sorcery", '0.1.4', :path => '../../../'
+gem 'oauth', ">= 0.4.4"
group :development do
gem 'rspec'
View
2  spec/Gemfile.lock
@@ -50,6 +50,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
+ oauth (0.4.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
@@ -101,6 +102,7 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby
+ oauth (>= 0.4.4)
rails (= 3.0.3)
rspec
ruby-debug19
View
3  spec/rails3/app_root/Gemfile
@@ -4,7 +4,8 @@ gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem "sorcery", '0.1.4', :path => '../../../'
gem 'bcrypt-ruby', '~> 2.1.4', :require => 'bcrypt'
-
+gem 'oauth', ">= 0.4.4"
+
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
View
2  spec/rails3/app_root/Gemfile.lock
@@ -51,6 +51,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
+ oauth (0.4.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
@@ -109,6 +110,7 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby (~> 2.1.4)
+ oauth (>= 0.4.4)
rails (= 3.0.3)
rspec
rspec-rails
View
6 spec/rails3/app_root/app/controllers/application_controller.rb
@@ -1,3 +1,5 @@
+require 'oauth'
+
class ApplicationController < ActionController::Base
protect_from_forgery
@@ -64,6 +66,10 @@ def test_http_basic_auth
render :text => "HTTP Basic Auth"
end
+ def auth_at_provider_test
+ auth_at_provider(:twitter)
+ end
+
protected
View
12 spec/rails3/app_root/config/routes.rb
@@ -1,15 +1,5 @@
AppRoot::Application.routes.draw do
root :to => "application#index"
- match '/test_login', :to => "application#test_login"
- match '/test_return_to', :to => "application#test_return_to"
- match '/test_logout', :to => "application#test_logout"
- match '/some_action', :to => "application#some_action"
- match '/test_logout_with_remember', :to => "application#test_logout_with_remember"
- match '/test_login_with_remember', :to => 'application#test_login_with_remember'
- match '/test_login_with_remember_in_login', :to => 'application#test_login_with_remember_in_login'
- match '/test_login_from_cookie', :to => 'application#test_login_from_cookie'
- match '/test_should_be_logged_in', :to => 'application#test_should_be_logged_in'
- match '/test_http_basic_auth', :to => 'application#test_http_basic_auth'
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -65,5 +55,5 @@
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ match ':controller(/:action(/:id(.:format)))'
end
View
34 spec/rails3/app_root/spec/controller_oauth_spec.rb
@@ -0,0 +1,34 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe ApplicationController do
+
+ # ----------------- OAuth -----------------------
+ describe ApplicationController, "with OAuth features" do
+ before(:all) do
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
+ sorcery_reload!([:oauth])
+ sorcery_controller_property_set(:oauth_providers, [:twitter])
+ sorcery_controller_oauth_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
+ sorcery_controller_oauth_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
+ sorcery_controller_oauth_property_set(:twitter, :callback_url, "http://blabla.com")
+ end
+
+ before(:each) do
+ create_new_user
+ end
+
+ after(:all) do
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
+ end
+
+ after(:each) do
+ User.delete_all
+ end
+
+ it "auth_at_provider redirects correctly" do
+ get :auth_at_provider_test
+ response.should be_a_redirect
+ response.should redirect_to("https://api.twitter.com/oauth/authorize?oauth_callback=http%3A%2F%2Fblabla.com&oauth_token=#{session[:request_token].token}")
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.