Permalink
Browse files

Added default translation for failure notice. And moved set_auth_flow…

… response into helper for reuse
  • Loading branch information...
1 parent 4d7dc47 commit 27162f8d5d5820e7718fc5b33f39f03daafda424 @dwilkie committed Nov 22, 2010
View
@@ -1,7 +1,9 @@
en:
devise:
- paypal_permissions_authable:
- success: "Successfully authorized from Paypal account."
paypal_authable:
success: "Successfully authorized from Paypal account."
+ failure: "Unable to authorize you from Paypal account."
+ paypal_permissions_authable:
+ success: "Successfully authorized from Paypal account."
+ failure: "Unable to authorize you from Paypal account."
@@ -10,7 +10,7 @@ Feature: Authenticate using Paypal Authable
Then I should be redirected to sign in with paypal
And I should be requested to grant access to my name and email address
- Scenario: I sign into paypal
+ Scenario: I sign into Paypal
Given I have a paypal account with email: "mara@example.com"
And I sign into paypal through paypal authable
@@ -20,11 +20,12 @@ Feature: Authenticate using Paypal Authable
And I should be on the home page
And I should see "Successfully authorized from Paypal account."
- Scenario: I do not sign into paypal
+ Scenario: I do not sign into Paypal
Given I have a paypal account with email: "mara@example.com"
But I do not sign into paypal
When I am redirected back to the application from paypal after an authentication request
Then a user should not exist with email: "mara@example.com"
+ And I should see "Unable to authorize you from Paypal account."
@@ -29,6 +29,7 @@ Feature: Authenticate using Paypal Permissions Authable
When I am redirected back to the application from paypal after a permissions request
Then a user should not exist with email: "mara@example.com"
+ And I should see "Unable to authorize you from Paypal account."
Scenario: I do not sign into paypal
Given I have a paypal account with email: "mara@example.com"
@@ -37,4 +38,5 @@ Feature: Authenticate using Paypal Permissions Authable
When I am redirected back to the application from paypal after a permissions request
Then a user should not exist with email: "mara@example.com"
+ And I should see "Unable to authorize you from Paypal account."
@@ -3,7 +3,9 @@
end
Given /^I do not sign into paypal$/ do
- # this step is intentionally blank
+ FakeWeb.register_uri(
+ :post, Paypal.nvp_uri, :body => get_user_details_response(nil)
+ )
end
Then /^I should be redirected to sign in with paypal$/ do
@@ -9,9 +9,8 @@
end
Given /^I do not grant the required permissions$/ do
- body = "TIMESTAMP=2010%2d10%2d08T11%3a35%3a41Z&CORRELATIONID=d41ee44136721&ACK=Failure&VERSION=2%2e3&BUILD=1545724&L_ERRORCODE0=11622&L_SHORTMESSAGE0=User%20Does%20Not%20Exist%2e&L_LONGMESSAGE0=User%20may%20not%20have%20logged%20in%20using%20this%20token%2e&L_SEVERITYCODE0=Error"
FakeWeb.register_uri(
- :post, Paypal.nvp_uri, :body => body
+ :post, Paypal.nvp_uri, :body => get_user_details_response(nil)
)
end
@@ -3,8 +3,10 @@
end
Before("@devise_paypal") do
- @token = "HA-DJW3X5Y99KRR4"
- body = "TOKEN=HA%2dDJW3X5Y99KRR4&TIMESTAMP=2010%2d10%2d07T10%3a06%3a31Z&CORRELATIONID=5c533a2b40c6a&ACK=Success&VERSION=2%2e3&BUILD=1545724"
- FakeWeb.register_uri(:post, Paypal.nvp_uri, :body => body)
+ paypal_response = setup_auth_flow_response
+ @token = paypal_response[:token]
+ FakeWeb.register_uri(
+ :post, Paypal.nvp_uri, :body => paypal_response[:body]
+ )
end
@@ -23,6 +23,9 @@ def path_to(page_name)
when /^the paypal authable callback page$/
user_paypal_authable_callback_path(:token => @token)
+ when /^the registration page$/
+ new_user_registration_path
+
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
@@ -4,11 +4,11 @@ module InternalHelpers
private
def handle_callback_action(resource_params)
self.resource = resource_class.find_for_paypal_auth(resource_params)
-
if resource.persisted? && resource.errors.empty?
set_paypal_flash_message :notice, :success, :resource => resource
sign_in_and_redirect resource_name, resource, :event => :authentication
else
+ set_paypal_flash_message :notice, :failure, :resource => resource
clean_up_passwords(resource)
render_for_paypal
end
@@ -19,22 +19,26 @@ def handle_callback_action(resource_params)
#
# en:
# devise:
- # paypal_permissions_authable:
- # success: 'Successfully authorized from Paypal account'
- #
# paypal_authable:
# success: 'Successfully authorized from Paypal account.'
+ # failure: 'Unable to authorize you from Paypal account.'
+ #
+ # paypal_permissions_authable:
+ # success: 'Successfully authorized from Paypal account'
+ # failure: 'Unable to authorize you from Paypal account'
#
# But they can also be nested by Devise scope:
#
# en:
# devise:
- # paypal_permissions_authable:
- # admin:
- # success: 'Hello admin! You're successfully authorized from Paypal'
# paypal_authable:
# admin:
- # sucess: 'Hello admin! You're successfully authorized from Paypal'
+ # sucess: 'Hello admin! You're successfully authorized from Paypal account.'
+ # failure: 'Sorry admin. Unalbe to authorize you from Paypal account.'
+ # paypal_permissions_authable:
+ # admin:
+ # success: 'Hello admin! You're successfully authorized from Paypal account.'
+ # failure: 'Sorry admin. Unable to authorize you from Paypal account.'
#
# If you customize your controllers by inheriting
# Devise::PaypalPermissionsAuthable or Devise::PaypalAuthable
@@ -1,15 +1,35 @@
module DevisePaypal
module IntegrationTestHelper
- def get_user_details_response(paypal_user_details)
- parsed_paypal_user_details = {}
- paypal_user_details.each do |key, value|
- parsed_paypal_user_details[key.classify.upcase] = value
+ def get_user_details_response(paypal_user_details, options = {})
+ if options[:unauthorized] || paypal_user_details.nil?
+ "TIMESTAMP=2010%2d10%2d08T11%3a35%3a41Z&CORRELATIONID=d41ee44136721&ACK=Failure&VERSION=2%2e3&BUILD=1545724&L_ERRORCODE0=11622&L_SHORTMESSAGE0=User%20Does%20Not%20Exist%2e&L_LONGMESSAGE0=User%20may%20not%20have%20logged%20in%20using%20this%20token%2e&L_SEVERITYCODE0=Error"
+ else
+ raise(
+ ArgumentError,
+ "You must specify a hash of paypal user details"
+ ) unless paypal_user_details || !paypal_user_details.is_a?(Hash)
+ body_template = "PAYERID=RK7XZT4AUY79C&TIMESTAMP=2010%2d10%2d07T10%3a08%3a44Z&CORRELATIONID=83dfe25684ced&ACK=Success&VERSION=2%2e3&BUILD=1545724"
+ parsed_paypal_user_details = {}
+ paypal_user_details.each do |key, value|
+ parsed_paypal_user_details[key.classify.upcase] = value
+ end
+ paypal_user_details = parsed_paypal_user_details
+ paypal_response = Rack::Utils.parse_nested_query(body_template)
+ paypal_response.merge!(paypal_user_details)
+ Rack::Utils.build_nested_query(paypal_response)
end
- paypal_user_details = parsed_paypal_user_details
- body_template = "PAYERID=RK7XZT4AUY79C&TIMESTAMP=2010%2d10%2d07T10%3a08%3a44Z&CORRELATIONID=83dfe25684ced&ACK=Success&VERSION=2%2e3&BUILD=1545724"
+ end
+
+ def setup_auth_flow_response(token = nil)
+ token ||= "HA-DJW3X5Y99KRR4"
+ body_template = "TIMESTAMP=2010%2d10%2d07T10%3a06%3a31Z&CORRELATIONID=5c533a2b40c6a&ACK=Success&VERSION=2%2e3&BUILD=1545724"
paypal_response = Rack::Utils.parse_nested_query(body_template)
- paypal_response.merge!(paypal_user_details)
- response_body = Rack::Utils.build_nested_query(paypal_response)
+ paypal_response.merge!("TOKEN" => token)
+ paypal_response = Rack::Utils.build_nested_query(paypal_response)
+ {
+ :token => token,
+ :body => paypal_response
+ }
end
def assert_equal_to_paypal_url(url, paypal_url)
View
@@ -8,14 +8,13 @@ gem 'rails', '3.0.1'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'devise', "1.2.rc"
-gem 'devise_paypal'
+gem 'devise_paypal', :path => "/home/dave/work/plugins/devise_paypal"
gem 'paypal-ipn'
group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'pickle'
gem 'fakeweb'
- gem 'ruby-debug19'
end
@@ -1,3 +1,9 @@
+PATH
+ remote: /home/dave/work/plugins/devise_paypal
+ specs:
+ devise_paypal (0.0.1)
+ paypal-ipn (> 0.0.1)
+
GEM
remote: http://rubygems.org/
specs:
@@ -28,7 +34,6 @@ GEM
activemodel (= 3.0.1)
activesupport (= 3.0.1)
activesupport (3.0.1)
- archive-tar-minitar (0.5.2)
arel (1.0.1)
activesupport (~> 3.0.0)
bcrypt-ruby (2.1.2)
@@ -42,7 +47,6 @@ GEM
selenium-webdriver (>= 0.0.3)
childprocess (0.0.7)
ffi (~> 0.6.3)
- columnize (0.3.1)
crack (0.1.8)
cucumber (0.8.5)
builder (~> 2.1.2)
@@ -56,8 +60,6 @@ GEM
devise (1.2.rc)
bcrypt-ruby (~> 2.1.2)
warden (~> 1.0.0)
- devise_paypal (0.0.1)
- paypal-ipn (> 0.0.1)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
@@ -70,8 +72,6 @@ GEM
crack (= 0.1.8)
i18n (0.4.2)
json_pure (1.4.6)
- linecache19 (0.5.11)
- ruby_core_source (>= 0.1.4)
mail (2.2.9)
activesupport (>= 2.3.6)
i18n (~> 0.4.1)
@@ -116,16 +116,6 @@ GEM
rspec-mocks (2.0.0.rc)
rspec-core (= 2.0.0.rc)
rspec-expectations (= 2.0.0.rc)
- ruby-debug-base19 (0.11.24)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby_core_source (>= 0.1.4)
- ruby-debug19 (0.11.6)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby-debug-base19 (>= 0.11.19)
- ruby_core_source (0.1.4)
- archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.4)
selenium-webdriver (0.0.29)
childprocess (>= 0.0.7)
@@ -150,10 +140,9 @@ DEPENDENCIES
capybara
cucumber-rails
devise (= 1.2.rc)
- devise_paypal
+ devise_paypal!
fakeweb
paypal-ipn
pickle
rails (= 3.0.1)
- ruby-debug19
sqlite3-ruby

0 comments on commit 27162f8

Please sign in to comment.