devise_paypal 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.markdown +125 -0
  5. data/Rakefile +2 -0
  6. data/app/controllers/devise/paypal_authable_controller.rb +24 -0
  7. data/app/controllers/devise/paypal_permissions_authable_controller.rb +25 -0
  8. data/config/locales/en.yml +7 -0
  9. data/devise_paypal.gemspec +23 -0
  10. data/features/paypal_authable.feature +30 -0
  11. data/features/paypal_permissions_authable.feature +40 -0
  12. data/features/step_definitions/extended_web_steps.rb +12 -0
  13. data/features/step_definitions/paypal_authable_steps.rb +11 -0
  14. data/features/step_definitions/paypal_authentication_steps.rb +25 -0
  15. data/features/step_definitions/paypal_permissions_authable_steps.rb +22 -0
  16. data/features/step_definitions/pickle_steps.rb +100 -0
  17. data/features/step_definitions/web_steps.rb +219 -0
  18. data/features/support/env.rb +58 -0
  19. data/features/support/fakeweb.rb +3 -0
  20. data/features/support/hooks.rb +10 -0
  21. data/features/support/paths.rb +46 -0
  22. data/features/support/paypal_response_helpers.rb +14 -0
  23. data/features/support/pickle.rb +24 -0
  24. data/lib/devise_paypal.rb +18 -0
  25. data/lib/devise_paypal/controllers/internal_helpers.rb +58 -0
  26. data/lib/devise_paypal/controllers/url_helpers.rb +16 -0
  27. data/lib/devise_paypal/models/paypal_authable.rb +22 -0
  28. data/lib/devise_paypal/models/paypal_permissions_authable.rb +22 -0
  29. data/lib/devise_paypal/rails.rb +21 -0
  30. data/lib/devise_paypal/rails/routes.rb +39 -0
  31. data/lib/devise_paypal/version.rb +3 -0
  32. data/lib/generators/devise_paypal/install_generator.rb +18 -0
  33. data/lib/generators/templates/README +20 -0
  34. data/test/rails_app/.gitignore +4 -0
  35. data/test/rails_app/Gemfile +21 -0
  36. data/test/rails_app/Gemfile.lock +169 -0
  37. data/test/rails_app/Rakefile +7 -0
  38. data/test/rails_app/app/controllers/application_controller.rb +3 -0
  39. data/test/rails_app/app/controllers/welcome_controller.rb +5 -0
  40. data/test/rails_app/app/models/user.rb +26 -0
  41. data/test/rails_app/app/views/layouts/application.html.erb +16 -0
  42. data/test/rails_app/app/views/welcome/index.html.erb +11 -0
  43. data/test/rails_app/config.ru +4 -0
  44. data/test/rails_app/config/application.rb +42 -0
  45. data/test/rails_app/config/boot.rb +13 -0
  46. data/test/rails_app/config/cucumber.yml +8 -0
  47. data/test/rails_app/config/database.yml +25 -0
  48. data/test/rails_app/config/environment.rb +5 -0
  49. data/test/rails_app/config/environments/development.rb +28 -0
  50. data/test/rails_app/config/environments/production.rb +49 -0
  51. data/test/rails_app/config/environments/test.rb +35 -0
  52. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/rails_app/config/initializers/devise.rb +168 -0
  54. data/test/rails_app/config/initializers/inflections.rb +10 -0
  55. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  56. data/test/rails_app/config/initializers/paypal.rb +7 -0
  57. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  58. data/test/rails_app/config/initializers/session_store.rb +8 -0
  59. data/test/rails_app/config/locales/devise.en.yml +43 -0
  60. data/test/rails_app/config/locales/en.yml +5 -0
  61. data/test/rails_app/config/routes.rb +5 -0
  62. data/test/rails_app/db/migrate/20101102105924_devise_create_users.rb +26 -0
  63. data/test/rails_app/db/schema.rb +34 -0
  64. data/test/rails_app/db/seeds.rb +7 -0
  65. data/test/rails_app/lib/tasks/.gitkeep +0 -0
  66. data/test/rails_app/lib/tasks/cucumber.rake +53 -0
  67. data/test/rails_app/public/404.html +26 -0
  68. data/test/rails_app/public/422.html +26 -0
  69. data/test/rails_app/public/500.html +26 -0
  70. data/test/rails_app/public/favicon.ico +0 -0
  71. data/test/rails_app/public/images/rails.png +0 -0
  72. data/test/rails_app/public/javascripts/application.js +2 -0
  73. data/test/rails_app/public/javascripts/controls.js +965 -0
  74. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  75. data/test/rails_app/public/javascripts/effects.js +1123 -0
  76. data/test/rails_app/public/javascripts/prototype.js +6001 -0
  77. data/test/rails_app/public/javascripts/rails.js +175 -0
  78. data/test/rails_app/public/robots.txt +5 -0
  79. data/test/rails_app/public/stylesheets/.gitkeep +0 -0
  80. data/test/rails_app/script/cucumber +10 -0
  81. data/test/rails_app/script/rails +6 -0
  82. metadata +159 -0
@@ -0,0 +1,219 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ require 'uri'
9
+ require 'cgi'
10
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
11
+
12
+ module WithinHelpers
13
+ def with_scope(locator)
14
+ locator ? within(locator) { yield } : yield
15
+ end
16
+ end
17
+ World(WithinHelpers)
18
+
19
+ Given /^(?:|I )am on (.+)$/ do |page_name|
20
+ visit path_to(page_name)
21
+ end
22
+
23
+ When /^(?:|I )go to (.+)$/ do |page_name|
24
+ visit path_to(page_name)
25
+ end
26
+
27
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
28
+ with_scope(selector) do
29
+ click_button(button)
30
+ end
31
+ end
32
+
33
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
34
+ with_scope(selector) do
35
+ click_link(link)
36
+ end
37
+ end
38
+
39
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
40
+ with_scope(selector) do
41
+ fill_in(field, :with => value)
42
+ end
43
+ end
44
+
45
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
46
+ with_scope(selector) do
47
+ fill_in(field, :with => value)
48
+ end
49
+ end
50
+
51
+ # Use this to fill in an entire form with data from a table. Example:
52
+ #
53
+ # When I fill in the following:
54
+ # | Account Number | 5002 |
55
+ # | Expiry date | 2009-11-01 |
56
+ # | Note | Nice guy |
57
+ # | Wants Email? | |
58
+ #
59
+ # TODO: Add support for checkbox, select og option
60
+ # based on naming conventions.
61
+ #
62
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
63
+ with_scope(selector) do
64
+ fields.rows_hash.each do |name, value|
65
+ When %{I fill in "#{name}" with "#{value}"}
66
+ end
67
+ end
68
+ end
69
+
70
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
71
+ with_scope(selector) do
72
+ select(value, :from => field)
73
+ end
74
+ end
75
+
76
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
77
+ with_scope(selector) do
78
+ check(field)
79
+ end
80
+ end
81
+
82
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
83
+ with_scope(selector) do
84
+ uncheck(field)
85
+ end
86
+ end
87
+
88
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
89
+ with_scope(selector) do
90
+ choose(field)
91
+ end
92
+ end
93
+
94
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
95
+ with_scope(selector) do
96
+ attach_file(field, path)
97
+ end
98
+ end
99
+
100
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
101
+ require 'json'
102
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
103
+ actual = JSON.pretty_generate(JSON.parse(response.body))
104
+ expected.should == actual
105
+ end
106
+
107
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
108
+ with_scope(selector) do
109
+ if page.respond_to? :should
110
+ page.should have_content(text)
111
+ else
112
+ assert page.has_content?(text)
113
+ end
114
+ end
115
+ end
116
+
117
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
118
+ regexp = Regexp.new(regexp)
119
+ with_scope(selector) do
120
+ if page.respond_to? :should
121
+ page.should have_xpath('//*', :text => regexp)
122
+ else
123
+ assert page.has_xpath?('//*', :text => regexp)
124
+ end
125
+ end
126
+ end
127
+
128
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
129
+ with_scope(selector) do
130
+ if page.respond_to? :should
131
+ page.should have_no_content(text)
132
+ else
133
+ assert page.has_no_content?(text)
134
+ end
135
+ end
136
+ end
137
+
138
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
139
+ regexp = Regexp.new(regexp)
140
+ with_scope(selector) do
141
+ if page.respond_to? :should
142
+ page.should have_no_xpath('//*', :text => regexp)
143
+ else
144
+ assert page.has_no_xpath?('//*', :text => regexp)
145
+ end
146
+ end
147
+ end
148
+
149
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
150
+ with_scope(selector) do
151
+ field = find_field(field)
152
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
153
+ if field_value.respond_to? :should
154
+ field_value.should =~ /#{value}/
155
+ else
156
+ assert_match(/#{value}/, field_value)
157
+ end
158
+ end
159
+ end
160
+
161
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
162
+ with_scope(selector) do
163
+ field = find_field(field)
164
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
165
+ if field_value.respond_to? :should_not
166
+ field_value.should_not =~ /#{value}/
167
+ else
168
+ assert_no_match(/#{value}/, field_value)
169
+ end
170
+ end
171
+ end
172
+
173
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
174
+ with_scope(selector) do
175
+ field_checked = find_field(label)['checked']
176
+ if field_checked.respond_to? :should
177
+ field_checked.should be_true
178
+ else
179
+ assert field_checked
180
+ end
181
+ end
182
+ end
183
+
184
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
185
+ with_scope(selector) do
186
+ field_checked = find_field(label)['checked']
187
+ if field_checked.respond_to? :should
188
+ field_checked.should be_false
189
+ else
190
+ assert !field_checked
191
+ end
192
+ end
193
+ end
194
+
195
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
196
+ current_path = URI.parse(current_url).path
197
+ if current_path.respond_to? :should
198
+ current_path.should == path_to(page_name)
199
+ else
200
+ assert_equal path_to(page_name), current_path
201
+ end
202
+ end
203
+
204
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
205
+ query = URI.parse(current_url).query
206
+ actual_params = query ? CGI.parse(query) : {}
207
+ expected_params = {}
208
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209
+
210
+ if actual_params.respond_to? :should
211
+ actual_params.should == expected_params
212
+ else
213
+ assert_equal expected_params, actual_params
214
+ end
215
+ end
216
+
217
+ Then /^show me the page$/ do
218
+ save_and_open_page
219
+ end
@@ -0,0 +1,58 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+ ENV["RAILS_ENV"] ||= "test"
8
+ require File.expand_path(File.dirname(__FILE__) + '/../../test/rails_app/config/environment')
9
+
10
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
11
+ require 'cucumber/rails/world'
12
+ require 'cucumber/rails/active_record'
13
+ require 'cucumber/web/tableish'
14
+
15
+ require 'capybara/rails'
16
+ require 'capybara/cucumber'
17
+ require 'capybara/session'
18
+ require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
19
+ # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
20
+ # order to ease the transition to Capybara we set the default here. If you'd
21
+ # prefer to use XPath just remove this line and adjust any selectors in your
22
+ # steps to use the XPath syntax.
23
+ Capybara.default_selector = :css
24
+
25
+ # If you set this to false, any error raised from within your app will bubble
26
+ # up to your step definition and out to cucumber unless you catch it somewhere
27
+ # on the way. You can make Rails rescue errors and render error pages on a
28
+ # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
29
+ #
30
+ # If you set this to true, Rails will rescue all errors and render error
31
+ # pages, more or less in the same way your application would behave in the
32
+ # default production environment. It's not recommended to do this for all
33
+ # of your scenarios, as this makes it hard to discover errors in your application.
34
+ ActionController::Base.allow_rescue = false
35
+
36
+ # If you set this to true, each scenario will run in a database transaction.
37
+ # You can still turn off transactions on a per-scenario basis, simply tagging
38
+ # a feature or scenario with the @no-txn tag. If you are using Capybara,
39
+ # tagging with @culerity or @javascript will also turn transactions off.
40
+ #
41
+ # If you set this to false, transactions will be off for all scenarios,
42
+ # regardless of whether you use @no-txn or not.
43
+ #
44
+ # Beware that turning transactions off will leave data in your database
45
+ # after each scenario, which can lead to hard-to-debug failures in
46
+ # subsequent scenarios. If you do this, we recommend you create a Before
47
+ # block that will explicitly put your database in a known state.
48
+ Cucumber::Rails::World.use_transactional_fixtures = true
49
+ # How to clean your database when transactions are turned off. See
50
+ # http://github.com/bmabey/database_cleaner for more info.
51
+ if defined?(ActiveRecord::Base)
52
+ begin
53
+ require 'database_cleaner'
54
+ DatabaseCleaner.strategy = :truncation
55
+ rescue LoadError => ignore_if_database_cleaner_not_present
56
+ end
57
+ end
58
+
@@ -0,0 +1,3 @@
1
+ require 'fakeweb'
2
+ FakeWeb.allow_net_connect = false
3
+
@@ -0,0 +1,10 @@
1
+ Before do
2
+ FakeWeb.clean_registry
3
+ end
4
+
5
+ Before("@paypal_authentication_request") do
6
+ @token = "HA-DJW3X5Y99KRR4"
7
+ body = "TOKEN=HA%2dDJW3X5Y99KRR4&TIMESTAMP=2010%2d10%2d07T10%3a06%3a31Z&CORRELATIONID=5c533a2b40c6a&ACK=Success&VERSION=2%2e3&BUILD=1545724"
8
+ FakeWeb.register_uri(:post, Paypal.nvp_uri, :body => body)
9
+ end
10
+
@@ -0,0 +1,46 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+
14
+ when /^the authenticate with paypal permissions page$/
15
+ new_user_paypal_permissions_authable_path
16
+
17
+ when /^the authenticate with paypal authable page$/
18
+ new_user_paypal_authable_path
19
+
20
+ when /^the paypal permissions callback page$/
21
+ user_paypal_permissions_authable_callback_path(:token => @token)
22
+
23
+ when /^the paypal authable callback page$/
24
+ user_paypal_authable_callback_path(:token => @token)
25
+
26
+ # Add more mappings here.
27
+ # Here is an example that pulls values out of the Regexp:
28
+ #
29
+ # when /^(.*)'s profile page$/i
30
+ # user_profile_path(User.find_by_login($1))
31
+
32
+ else
33
+ begin
34
+ page_name =~ /the (.*) page/
35
+ path_components = $1.split(/\s+/)
36
+ self.send(path_components.push('path').join('_').to_sym)
37
+ rescue Object => e
38
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
39
+ "Now, go and add a mapping in #{__FILE__}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ World(NavigationHelpers)
46
+
@@ -0,0 +1,14 @@
1
+ module PaypalResponseHelpers
2
+ def register_get_user_details_response
3
+ body_template = "PAYERID=RK7XZT4AUY79C&TIMESTAMP=2010%2d10%2d07T10%3a08%3a44Z&CORRELATIONID=83dfe25684ced&ACK=Success&VERSION=2%2e3&BUILD=1545724"
4
+ paypal_response = Rack::Utils.parse_nested_query(body_template)
5
+ paypal_response.merge!(@paypal_user_details)
6
+ response_body = Rack::Utils.build_nested_query(paypal_response)
7
+ FakeWeb.register_uri(
8
+ :post, Paypal.nvp_uri, :body => response_body
9
+ )
10
+ end
11
+ end
12
+
13
+ World(PaypalResponseHelpers)
14
+
@@ -0,0 +1,24 @@
1
+ # this file generated by script/generate pickle [paths] [email]
2
+ #
3
+ # Make sure that you are loading your factory of choice in your cucumber environment
4
+ #
5
+ # For machinist add: features/support/machinist.rb
6
+ #
7
+ # require 'machinist/active_record' # or your chosen adaptor
8
+ # require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
9
+ # Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
10
+ #
11
+ # For FactoryGirl add: features/support/factory_girl.rb
12
+ #
13
+ # require 'factory_girl'
14
+ # require File.dirname(__FILE__) + '/../../spec/factories' # or wherever your factories are
15
+ #
16
+ # You may also need to add gem dependencies on your factory of choice in <tt>config/environments/cucumber.rb</tt>
17
+
18
+ require 'pickle/world'
19
+ # Example of configuring pickle:
20
+ #
21
+ # Pickle.configure do |config|
22
+ # config.adapters = [:machinist]
23
+ # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
24
+ # end
@@ -0,0 +1,18 @@
1
+ require "devise"
2
+ require "paypal"
3
+
4
+ Devise.add_module :paypal_authable,
5
+ :controller => :paypal_authable,
6
+ :model => 'devise_paypal/models/paypal_authable',
7
+ :route => { :paypal_authable => [nil, :new] }
8
+
9
+ Devise.add_module :paypal_permissions_authable,
10
+ :controller => :paypal_permissions_authable,
11
+ :model => 'devise_paypal/models/paypal_permissions_authable',
12
+ :route => { :paypal_permissions_authable => [nil, :new] }
13
+
14
+ require 'devise_paypal/rails/routes'
15
+ require 'devise_paypal/rails'
16
+ require 'devise_paypal/controllers/url_helpers'
17
+ require 'devise_paypal/controllers/internal_helpers'
18
+
@@ -0,0 +1,58 @@
1
+ module DevisePaypal
2
+ module Controllers
3
+ module InternalHelpers
4
+ private
5
+ def handle_callback_action(resource_params)
6
+ self.resource = resource_class.find_for_paypal_auth(resource_params)
7
+
8
+ if resource.persisted? && resource.errors.empty?
9
+ set_flash_message :notice, :success
10
+ sign_in_and_redirect resource_name, resource, :event => :authentication
11
+ else
12
+ clean_up_passwords(resource)
13
+ render_for_paypal
14
+ end
15
+ end
16
+
17
+ # Handles Paypal flash messages by adding a cascade. The default messages
18
+ # are always in the controller namespace:
19
+ #
20
+ # en:
21
+ # devise:
22
+ # paypal_permissions_authable:
23
+ # success: 'Successfully authorized from Paypal account'
24
+ #
25
+ # paypal_authable:
26
+ # success: 'Successfully authorized from Paypal account.'
27
+ #
28
+ # But they can also be nested by Devise scope:
29
+ #
30
+ # en:
31
+ # devise:
32
+ # paypal_permissions_authable:
33
+ # admin:
34
+ # success: 'Hello admin! You're successfully authorized from Paypal'
35
+ # paypal_authable:
36
+ # admin:
37
+ # sucess: 'Hello admin! You're successfully authorized from Paypal'
38
+ #
39
+ # If you customize your controllers by inheriting
40
+ # Devise::PaypalPermissionsAuthable or Devise::PaypalAuthable
41
+ # don't forget to change your translation key from
42
+ # 'paypal_permissions_authable' => 'your paypal permissions controller' and
43
+ # 'paypal_authable' => 'your paypal authable controller'
44
+ #
45
+ def set_paypal_flash_message(key, type, options={})
46
+ set_flash_message(key, type, options)
47
+ end
48
+
49
+ # Choose which template to render when a not persisted resource is
50
+ # returned in the find_for_paypal_auth.
51
+ # By default, it renders registrations/new.
52
+ def render_for_paypal
53
+ render_with_scope :new, devise_mapping.controllers[:registrations]
54
+ end
55
+ end
56
+ end
57
+ end
58
+