sorcery 0.6.1 → 0.7.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 (185) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +52 -45
  3. data/README.rdoc +26 -54
  4. data/Rakefile +26 -0
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery/USAGE +22 -0
  7. data/lib/generators/sorcery/install_generator.rb +71 -0
  8. data/lib/{sorcery/initializers → generators/sorcery/templates}/initializer.rb +82 -61
  9. data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
  10. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +11 -0
  11. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +3 -3
  12. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
  14. data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
  15. data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
  16. data/lib/sorcery/controller/submodules/activity_logging.rb +23 -9
  17. data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -1
  18. data/lib/sorcery/controller/submodules/external/protocols/certs/ca-bundle.crt +5182 -0
  19. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +27 -8
  20. data/lib/sorcery/controller/submodules/external/providers/github.rb +80 -0
  21. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +5 -0
  22. data/lib/sorcery/controller/submodules/external.rb +10 -3
  23. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  24. data/lib/sorcery/controller/submodules/remember_me.rb +15 -5
  25. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  26. data/lib/sorcery/controller.rb +59 -38
  27. data/lib/sorcery/crypto_providers/aes256.rb +7 -3
  28. data/lib/sorcery/engine.rb +1 -0
  29. data/lib/sorcery/model/adapters/active_record.rb +2 -1
  30. data/lib/sorcery/model/adapters/mongo_mapper.rb +49 -0
  31. data/lib/sorcery/model/adapters/mongoid.rb +7 -2
  32. data/lib/sorcery/model/submodules/brute_force_protection.rb +13 -3
  33. data/lib/sorcery/model/submodules/remember_me.rb +9 -2
  34. data/lib/sorcery/model/submodules/reset_password.rb +11 -2
  35. data/lib/sorcery/model/submodules/user_activation.rb +13 -2
  36. data/lib/sorcery/model/temporary_token.rb +5 -0
  37. data/lib/sorcery/model.rb +34 -15
  38. data/lib/sorcery/test_helpers/internal/rails.rb +1 -1
  39. data/lib/sorcery/test_helpers/rails.rb +2 -2
  40. data/lib/sorcery.rb +6 -7
  41. data/sorcery.gemspec +86 -203
  42. data/spec/Gemfile.lock +23 -12
  43. data/spec/README.md +31 -0
  44. data/spec/rails3/Gemfile +3 -1
  45. data/spec/rails3/Gemfile.lock +45 -28
  46. data/spec/rails3/app/controllers/application_controller.rb +40 -22
  47. data/spec/rails3/app/views/application/index.html.erb +17 -0
  48. data/spec/rails3/spec/controller_activity_logging_spec.rb +23 -0
  49. data/spec/rails3/spec/controller_oauth2_spec.rb +59 -16
  50. data/spec/rails3/spec/controller_remember_me_spec.rb +37 -6
  51. data/spec/rails3/spec/controller_spec.rb +30 -0
  52. data/spec/rails3/spec/integration_spec.rb +23 -0
  53. data/spec/rails3/spec/spec_helper.rb +6 -5
  54. data/spec/rails3_mongo_mapper/.gitignore +4 -0
  55. data/spec/rails3_mongo_mapper/.rspec +1 -0
  56. data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +5 -5
  57. data/spec/rails3_mongo_mapper/Gemfile.lock +159 -0
  58. data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
  59. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
  60. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
  61. data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
  62. data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
  63. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
  64. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
  65. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
  66. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
  67. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
  68. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
  69. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
  70. data/spec/rails3_mongo_mapper/config/application.rb +51 -0
  71. data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
  72. data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
  73. data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
  74. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  75. data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
  76. data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
  77. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
  78. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
  79. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
  80. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
  81. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
  82. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
  83. data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
  84. data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
  85. data/spec/rails3_mongo_mapper/config.ru +4 -0
  86. data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
  87. data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
  88. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  89. data/spec/rails3_mongo_mapper/public/404.html +26 -0
  90. data/spec/rails3_mongo_mapper/public/422.html +26 -0
  91. data/spec/rails3_mongo_mapper/public/500.html +26 -0
  92. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  93. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  94. data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
  95. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
  96. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
  97. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
  98. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
  99. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
  100. data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
  101. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  102. data/spec/rails3_mongo_mapper/script/rails +6 -0
  103. data/spec/{sinatra → rails3_mongo_mapper}/spec/controller_spec.rb +51 -41
  104. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
  105. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
  106. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
  107. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
  108. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
  109. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
  110. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
  111. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
  112. data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
  113. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  114. data/spec/rails3_mongoid/Gemfile +1 -1
  115. data/spec/rails3_mongoid/Gemfile.lock +41 -34
  116. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +98 -0
  117. data/spec/rails3_mongoid/spec/controller_spec.rb +130 -0
  118. data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
  119. data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -0
  120. data/spec/shared_examples/user_shared_examples.rb +36 -8
  121. metadata +128 -234
  122. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
  123. data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
  124. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
  125. data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
  126. data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -13
  127. data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
  128. data/lib/sorcery/controller/adapters/sinatra.rb +0 -104
  129. data/lib/sorcery/sinatra.rb +0 -4
  130. data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
  131. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
  132. data/lib/sorcery/test_helpers/sinatra.rb +0 -88
  133. data/spec/rails3/Rakefile.unused +0 -7
  134. data/spec/rails3/public/index.html +0 -239
  135. data/spec/sinatra/Gemfile +0 -15
  136. data/spec/sinatra/Gemfile.lock +0 -117
  137. data/spec/sinatra/authentication.rb +0 -3
  138. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  139. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  140. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  141. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
  142. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  143. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  144. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  145. data/spec/sinatra/filters.rb +0 -27
  146. data/spec/sinatra/modular.rb +0 -157
  147. data/spec/sinatra/myapp.rb +0 -133
  148. data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
  149. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
  150. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
  151. data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -99
  152. data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
  153. data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
  154. data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
  155. data/spec/sinatra/spec/spec_helper.rb +0 -45
  156. data/spec/sinatra/user.rb +0 -6
  157. data/spec/sinatra/views/test_login.erb +0 -4
  158. data/spec/sinatra_modular/Gemfile.lock +0 -117
  159. data/spec/sinatra_modular/Rakefile +0 -11
  160. data/spec/sinatra_modular/authentication.rb +0 -3
  161. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  162. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  163. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  164. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
  165. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  166. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  167. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  168. data/spec/sinatra_modular/filters.rb +0 -27
  169. data/spec/sinatra_modular/modular.rb +0 -157
  170. data/spec/sinatra_modular/myapp.rb +0 -133
  171. data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
  172. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
  173. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
  174. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
  175. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -99
  176. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
  177. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
  178. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
  179. data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
  180. data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
  181. data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
  182. data/spec/sinatra_modular/user.rb +0 -6
  183. data/spec/sinatra_modular/views/test_login.erb +0 -4
  184. /data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
  185. /data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
@@ -0,0 +1,175 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+ })();
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -1,9 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Sinatra::Application do
3
+ describe ApplicationController do
4
4
 
5
5
  # ----------------- PLUGIN CONFIGURATION -----------------------
6
- describe "plugin configuration" do
6
+ describe ApplicationController, "plugin configuration" do
7
7
  before(:all) do
8
8
  sorcery_reload!
9
9
  end
@@ -26,9 +26,9 @@ describe Sinatra::Application do
26
26
  end
27
27
 
28
28
  # ----------------- PLUGIN ACTIVATED -----------------------
29
- describe Sinatra::Application, "when activated with sorcery" do
30
-
29
+ describe ApplicationController, "when activated with sorcery" do
31
30
  before(:all) do
31
+ sorcery_reload!
32
32
  User.delete_all
33
33
  create_new_user
34
34
  end
@@ -36,85 +36,95 @@ describe Sinatra::Application do
36
36
  after(:each) do
37
37
  Sorcery::Controller::Config.reset!
38
38
  sorcery_controller_property_set(:user_class, User)
39
+ sorcery_model_property_set(:username_attribute_names, [:username, :email])
39
40
  end
40
41
 
41
- it "should respond to the instance method login" do
42
- get_sinatra_app(subject).should respond_to(:login)
43
- end
44
-
45
- it "should respond to the instance method logout" do
46
- get_sinatra_app(subject).should respond_to(:logout)
47
- end
48
-
49
- it "should respond to the instance method logged_in?" do
50
- get_sinatra_app(subject).should respond_to(:logged_in?)
51
- end
42
+ specify { should respond_to(:login) }
43
+
44
+ specify { should respond_to(:logout) }
45
+
46
+ specify { should respond_to(:logged_in?) }
52
47
 
53
- it "should respond to the instance method current_user" do
54
- get_sinatra_app(subject).should respond_to(:current_user)
55
- end
48
+ specify { should respond_to(:current_user) }
56
49
 
57
50
  it "login(username,password) should return the user when success and set the session with user.id" do
58
- get "/test_login", :username => 'gizmo', :password => 'secret'
51
+ get :test_login, :username => 'gizmo', :password => 'secret'
52
+ assigns[:user].should == @user
53
+ session[:user_id].should == @user.id
54
+ end
55
+
56
+ it "login(email,password) should return the user when success and set the session with user.id" do
57
+ get :test_login, :username => 'bla@bla.com', :password => 'secret'
59
58
  assigns[:user].should == @user
60
59
  session[:user_id].should == @user.id
61
60
  end
62
61
 
63
62
  it "login(username,password) should return nil and not set the session when failure" do
64
- get "/test_login", :username => 'gizmo', :password => 'opensesame!'
63
+ get :test_login, :username => 'gizmo', :password => 'opensesame!'
65
64
  assigns[:user].should be_nil
66
65
  session[:user_id].should be_nil
67
66
  end
68
67
 
69
68
  it "logout should clear the session" do
70
- get "/test_logout"
69
+ cookies[:remember_me_token] = nil
70
+ session[:user_id] = @user.id
71
+ get :test_logout
71
72
  session[:user_id].should be_nil
72
73
  end
73
74
 
74
75
  it "logged_in? should return true if logged in" do
75
- get "/test_login", :username => 'gizmo', :password => 'secret'
76
- assigns[:logged_in].should be_true
76
+ session[:user_id] = @user.id
77
+ subject.logged_in?.should be_true
77
78
  end
78
79
 
79
80
  it "logged_in? should return false if not logged in" do
80
- get "/test_login", :username => 'gizmo', :password => 'opensesame!'
81
- assigns[:logged_in].should be_false
81
+ session[:user_id] = nil
82
+ subject.logged_in?.should be_false
82
83
  end
83
84
 
84
85
  it "current_user should return the user instance if logged in" do
85
86
  create_new_user
86
- get "/test_current_user", :id => @user.id
87
- assigns[:current_user].should == @user
87
+ session[:user_id] = @user.id
88
+ subject.current_user.should == @user
88
89
  end
89
90
 
90
91
  it "current_user should return false if not logged in" do
91
- get "/test_logout"
92
- assigns[:current_user].should == false
92
+ session[:user_id] = nil
93
+ subject.current_user.should == false
93
94
  end
94
95
 
95
- it "should respond to 'require_login'" do
96
- get_sinatra_app(subject).should respond_to(:require_login)
97
- end
96
+ specify { should respond_to(:require_login) }
98
97
 
99
98
  it "should call the configured 'not_authenticated_action' when authenticate before_filter fails" do
99
+ session[:user_id] = nil
100
100
  sorcery_controller_property_set(:not_authenticated_action, :test_not_authenticated_action)
101
- get "/test_logout"
102
- last_response.body.should == "test_not_authenticated_action"
101
+ get :test_logout
102
+ response.body.should == "test_not_authenticated_action"
103
103
  end
104
104
 
105
105
  it "require_login before_filter should save the url that the user originally wanted" do
106
- sorcery_controller_property_set(:not_authenticated_action, :not_authenticated2)
107
- get "/some_action"
108
- assigns[:session][:return_to_url].should == "http://example.org/some_action"
109
- last_response.status.should == 302
110
- last_response.should redirect_to("http://example.org/")
106
+ get :some_action
107
+ session[:return_to_url].should == "http://test.host/application/some_action"
108
+ response.should redirect_to("http://test.host/")
111
109
  end
112
110
 
113
111
  it "on successful login the user should be redirected to the url he originally wanted" do
114
- post "/test_return_to", :username => 'gizmo', :password => 'secret', :return_to_url => "http://example.org/blabla"
115
- last_response.should redirect_to("http://example.org/blabla")
112
+ session[:return_to_url] = "http://test.host/some_action"
113
+ post :test_return_to, :username => 'gizmo', :password => 'secret'
114
+ response.should redirect_to("http://test.host/some_action")
115
+ flash[:notice].should == "haha!"
116
116
  end
117
117
 
118
+
119
+ # --- login_user(user) ---
120
+ specify { should respond_to(:auto_login) }
121
+
122
+ it "auto_login(user) should login a user instance" do
123
+ create_new_user
124
+ session[:user_id] = nil
125
+ subject.auto_login(@user)
126
+ subject.logged_in?.should be_true
127
+ end
118
128
  end
119
129
 
120
130
  end
@@ -0,0 +1,27 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ # Requires supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ # == Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+ config.mock_with :rspec
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+ end
@@ -0,0 +1,55 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', '..', 'lib' )
2
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path("../../config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+ require 'timecop'
7
+
8
+ # require 'simplecov'
9
+ # SimpleCov.root File.join(File.dirname(__FILE__), "..", "..", "rails3" )
10
+ # SimpleCov.start do
11
+ # add_filter "/config/"
12
+ #
13
+ # add_group 'Controllers', 'app/controllers'
14
+ # add_group 'Models', 'app/models'
15
+ # add_group 'Helpers', 'app/helpers'
16
+ # add_group 'Libraries', 'lib'
17
+ # add_group 'Plugins', 'vendor/plugins'
18
+ # add_group 'Migrations', 'db/migrate'
19
+ # end
20
+
21
+ # Requires supporting ruby files with custom matchers and macros, etc,
22
+ # in spec/support/ and its subdirectories.
23
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
24
+
25
+
26
+
27
+ RSpec.configure do |config|
28
+ config.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /controller(.)*_spec.rb$/ }
29
+ # == Mock Framework
30
+ #
31
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
32
+ #
33
+ # config.mock_with :mocha
34
+ # config.mock_with :flexmock
35
+ # config.mock_with :rr
36
+ config.mock_with :rspec
37
+ end
38
+
39
+ #----------------------------------------------------------------
40
+ # needed when running individual specs
41
+ require File.join(File.dirname(__FILE__), '..','app','models','user')
42
+ require File.join(File.dirname(__FILE__), '..','app','models','authentication')
43
+
44
+ class TestUser
45
+ include MongoMapper::Document
46
+ authenticates_with_sorcery!
47
+ end
48
+
49
+ class TestMailer < ActionMailer::Base
50
+
51
+ end
52
+
53
+ include ::Sorcery::TestHelpers::Internal
54
+ include ::Sorcery::TestHelpers::Internal::Rails
55
+
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../app/mailers/sorcery_mailer')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_activation_shared_examples')
4
+
5
+ describe "User with activation submodule" do
6
+
7
+ it_behaves_like "rails_3_activation_model"
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_activity_logging_shared_examples')
3
+
4
+ describe "User with activity logging submodule" do
5
+
6
+ it_behaves_like "rails_3_activity_logging_model"
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_brute_force_protection_shared_examples')
3
+
4
+ describe "User with brute_force_protection submodule" do
5
+
6
+ it_behaves_like "rails_3_brute_force_protection_model"
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_oauth_shared_examples')
3
+
4
+ describe "User with oauth submodule" do
5
+
6
+ it_behaves_like "rails_3_oauth_model"
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_remember_me_shared_examples')
3
+
4
+ describe "User with remember_me submodule" do
5
+
6
+ it_behaves_like "rails_3_remember_me_model"
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_reset_password_shared_examples')
3
+
4
+ describe "User with reset_password submodule" do
5
+
6
+ it_behaves_like "rails_3_reset_password_model"
7
+
8
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../app/mailers/sorcery_mailer')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_shared_examples')
4
+
5
+ describe "User with no submodules (core)" do
6
+ before(:all) do
7
+ sorcery_reload!
8
+ end
9
+
10
+ describe User, "when app has plugin loaded" do
11
+ it "User should respond_to .authenticates_with_sorcery!" do
12
+ User.should respond_to(:authenticates_with_sorcery!)
13
+ end
14
+ end
15
+
16
+ # ----------------- PLUGIN CONFIGURATION -----------------------
17
+
18
+ it_should_behave_like "rails_3_core_model"
19
+
20
+ describe User, "external users" do
21
+
22
+ it_should_behave_like "external_user"
23
+
24
+ end
25
+
26
+ describe User, "when inherited" do
27
+ it "should inherit mongo_mapper keys" do
28
+ User.class_eval do
29
+ key :blabla
30
+ end
31
+ class SubUser < User
32
+ end
33
+
34
+ SubUser.keys.should include("blabla")
35
+ end
36
+ end
37
+ end
File without changes
@@ -1,7 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.0.3'
4
- gem "sorcery", '>= 0.1.0', :path => '../../../'
4
+ gem "sorcery", '>= 0.1.0', :path => '../../'
5
5
  gem "mongoid", "~> 2.0"
6
6
  gem "bson_ext", "~> 1.3"
7
7