forked from nicolasblanco/devise_rpx_connectable
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finally, adds some RSpec basic tests for the strategy.
- Loading branch information
slainer68
committed
Sep 20, 2010
1 parent
4ef0d68
commit 6a2c032
Showing
3 changed files
with
128 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
# encoding: utf-8 | ||
require 'rubygems' | ||
require 'rake' | ||
require 'rake/rdoctask' | ||
require "rake" | ||
require "rake/rdoctask" | ||
require "rspec" | ||
require "rspec/core/rake_task" | ||
require File.join(File.dirname(__FILE__), 'lib', 'devise_rpx_connectable', 'version') | ||
|
||
NAME = "devise_rpx_connectable" | ||
|
||
begin | ||
gem 'jeweler' | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |spec| | ||
spec.name = NAME | ||
spec.version = ::Devise::RpxConnectable::VERSION | ||
spec.summary = %{Devise << RPX} | ||
spec.description = spec.summary | ||
spec.homepage = "http://github.com/slainer68/#{spec.name}" | ||
spec.authors = ["Nicolas Blanco"] | ||
spec.email = "slainer68@gmail.com" | ||
|
||
spec.files = FileList['[A-Z]*', File.join(*%w[{lib,rails} ** *]).to_s] | ||
|
||
spec.add_dependency 'devise', '>= 1.1.2' | ||
spec.add_dependency 'rpx_now', '>= 0.6.23' | ||
Jeweler::Tasks.new do |gem| | ||
gem.name = "devise_rpx_connectable" | ||
gem.version = ::Devise::RpxConnectable::VERSION | ||
gem.summary = %Q{Authenticate your users with RPX in your Rails application using Devise.} | ||
gem.description = %Q{Authenticate your users with RPX in your Rails application using Devise.} | ||
gem.email = "slainer68@gmail.com" | ||
gem.homepage = "http://github.com/slainer68/devise_rpx_connectable" | ||
gem.authors = ["Nicolas Blanco"] | ||
|
||
gem.add_dependency 'devise', '>= 1.1.2' | ||
gem.add_dependency 'rpx_now', '>= 0.6.23' | ||
|
||
gem.add_development_dependency "rspec", ">= 2.0.0.beta.22" | ||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | ||
end | ||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler - or one of its dependencies - is not available. " << | ||
"Install it with: sudo gem install jeweler -s http://gemcutter.org" | ||
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" | ||
end | ||
|
||
Rspec::Core::RakeTask.new(:spec) do |spec| | ||
spec.pattern = "spec/**/*_spec.rb" | ||
end | ||
|
||
Rake::RDocTask.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "devise_rpx_connectable #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require "spec_helper" | ||
require "active_support/all" | ||
|
||
require File.join(File.dirname(__FILE__), '..', 'lib', 'devise_rpx_connectable', 'strategy') | ||
|
||
class User | ||
def self.rpx_extended_user_data; true; end | ||
def self.rpx_additional_user_data; true; end | ||
end | ||
|
||
class RPXNow | ||
@@api_key = "abcdefgh" | ||
cattr_accessor :api_key | ||
end | ||
|
||
RPX_USER_DATA = { "identifier" => "superpipo_user" } | ||
PARAMS = { :token => "rpx_token" } | ||
|
||
describe 'DeviseRpxConnectable' do | ||
before(:each) do | ||
@strategy = Devise::RpxConnectable::Strategies::RpxConnectable.new | ||
@mapping = mock(:mapping) | ||
@mapping.should_receive(:to).and_return(User) | ||
@strategy.should_receive(:mapping).and_return(@mapping) | ||
@strategy.should_receive(:params).and_return(PARAMS) | ||
|
||
@user = User.new | ||
end | ||
|
||
it "should fail if RPX returns no valid user" do | ||
RPXNow.should_receive(:user_data).and_return(nil) | ||
|
||
@strategy.should_receive(:"fail!").with(:rpx_invalid).and_return(true) | ||
|
||
lambda { @strategy.authenticate! }.should_not raise_error | ||
end | ||
|
||
describe 'when the RPX user is valid' do | ||
before(:each) do | ||
RPXNow.should_receive(:user_data).and_return(RPX_USER_DATA) | ||
end | ||
|
||
it "should authenticate if a user exists in database" do | ||
User.should_receive(:authenticate_with_rpx).with({ :identifier => RPX_USER_DATA["identifier"] }).and_return(@user) | ||
|
||
@user.should_receive(:on_before_rpx_success).with(RPX_USER_DATA).and_return(true) | ||
|
||
@strategy.should_receive(:"success!").with(@user).and_return(true) | ||
|
||
lambda { @strategy.authenticate! }.should_not raise_error | ||
end | ||
|
||
describe 'when no user exists in database' do | ||
before(:each) do | ||
User.should_receive(:authenticate_with_rpx).with({ :identifier => RPX_USER_DATA["identifier"] }).and_return(nil) | ||
end | ||
|
||
it "should fail unless rpx_auto_create_account" do | ||
User.should_receive(:"rpx_auto_create_account?").and_return(false) | ||
@strategy.should_receive(:"fail!").with(:rpx_invalid).and_return(true) | ||
|
||
lambda { @strategy.authenticate! }.should_not raise_error | ||
end | ||
|
||
it "should create a new user and success if rpx_auto_create_account" do | ||
User.should_receive(:"rpx_auto_create_account?").and_return(true) | ||
|
||
User.should_receive(:new).and_return(@user) | ||
@user.should_receive(:"store_rpx_credentials!").with(RPX_USER_DATA).and_return(true) | ||
@user.should_receive(:on_before_rpx_auto_create).with(RPX_USER_DATA).and_return(true) | ||
@user.should_receive(:save).with({ :validate => false }).and_return(true) | ||
@user.should_receive(:on_before_rpx_success).with(RPX_USER_DATA).and_return(true) | ||
|
||
@strategy.should_receive(:"success!").with(@user).and_return(true) | ||
|
||
lambda { @strategy.authenticate! }.should_not raise_error | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'ruby-debug' | ||
require 'rspec' | ||
|
||
module Devise | ||
class Strategies | ||
class Base | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.mock_with :rspec | ||
end | ||
|