quo_vadis 0.0.1 → 1.0.0

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 (72) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile.lock +114 -0
  3. data/README.md +79 -0
  4. data/Rakefile +11 -0
  5. data/app/controllers/controller_mixin.rb +20 -0
  6. data/app/controllers/quo_vadis/sessions_controller.rb +36 -0
  7. data/app/models/model_mixin.rb +44 -0
  8. data/config/initializers/quo_vadis.rb +50 -0
  9. data/config/locales/quo_vadis.en.yml +7 -0
  10. data/config/routes.rb +7 -0
  11. data/lib/generators/quo_vadis/install_generator.rb +28 -0
  12. data/lib/generators/quo_vadis/templates/migration.rb +11 -0
  13. data/lib/quo_vadis/engine.rb +15 -0
  14. data/lib/quo_vadis/version.rb +1 -1
  15. data/lib/quo_vadis.rb +63 -1
  16. data/quo_vadis.gemspec +8 -1
  17. data/test/dummy/.gitignore +1 -0
  18. data/test/dummy/app/controllers/application_controller.rb +3 -0
  19. data/test/dummy/app/controllers/articles_controller.rb +11 -0
  20. data/test/dummy/app/helpers/application_helper.rb +2 -0
  21. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  22. data/test/dummy/app/models/article.rb +2 -0
  23. data/test/dummy/app/models/user.rb +3 -0
  24. data/test/dummy/app/views/articles/index.html.erb +1 -0
  25. data/test/dummy/app/views/articles/new.html.erb +1 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +27 -0
  27. data/test/dummy/app/views/sessions/new.html.erb +15 -0
  28. data/test/dummy/config/application.rb +21 -0
  29. data/test/dummy/config/boot.rb +10 -0
  30. data/test/dummy/config/database.yml +22 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +26 -0
  33. data/test/dummy/config/environments/production.rb +49 -0
  34. data/test/dummy/config/environments/test.rb +35 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/inflections.rb +10 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/locales/en.yml +5 -0
  41. data/test/dummy/config/routes.rb +4 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/dummy/db/migrate/20110124125037_create_users.rb +13 -0
  44. data/test/dummy/db/migrate/20110124125216_add_authentication_to_users.rb +11 -0
  45. data/test/dummy/db/migrate/20110124131535_create_articles.rb +14 -0
  46. data/test/dummy/public/404.html +26 -0
  47. data/test/dummy/public/422.html +26 -0
  48. data/test/dummy/public/500.html +26 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/dummy/public/javascripts/application.js +2 -0
  51. data/test/dummy/public/javascripts/controls.js +965 -0
  52. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  53. data/test/dummy/public/javascripts/effects.js +1123 -0
  54. data/test/dummy/public/javascripts/prototype.js +6001 -0
  55. data/test/dummy/public/javascripts/rails.js +175 -0
  56. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  57. data/test/dummy/script/rails +6 -0
  58. data/test/dummy/tmp/capybara/capybara-20110124133149.html +27 -0
  59. data/test/dummy/tmp/capybara/capybara-20110124133340.html +27 -0
  60. data/test/dummy/tmp/capybara/capybara-20110124134001.html +27 -0
  61. data/test/dummy/tmp/capybara/capybara-20110124134214.html +27 -0
  62. data/test/dummy/tmp/capybara/capybara-20110124135435.html +39 -0
  63. data/test/integration/authenticate_test.rb +39 -0
  64. data/test/integration/config_test.rb +96 -0
  65. data/test/integration/helper_test.rb +18 -0
  66. data/test/integration/navigation_test.rb +7 -0
  67. data/test/integration/sign_in_test.rb +28 -0
  68. data/test/integration/sign_out_test.rb +20 -0
  69. data/test/quo_vadis_test.rb +7 -0
  70. data/test/support/integration_case.rb +5 -0
  71. data/test/test_helper.rb +46 -0
  72. metadata +202 -8
@@ -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
+ })();
File without changes
@@ -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'
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+
6
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/prototype.js?1295870562" type="text/javascript"></script>
7
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/effects.js?1295870562" type="text/javascript"></script>
8
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/dragdrop.js?1295870562" type="text/javascript"></script>
9
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/controls.js?1295870562" type="text/javascript"></script>
10
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/rails.js?1295870562" type="text/javascript"></script>
11
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/application.js?1295870562" type="text/javascript"></script>
12
+
13
+ </head>
14
+ <body>
15
+
16
+ <div id='topnav'>
17
+ You are signed in as Bob.
18
+ <a href="/sign-out">Sign out</a>
19
+ </div>
20
+
21
+ <div class='flash notice'>You have successfully signed in.</div>
22
+
23
+ <h1>Articles</h1>
24
+
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+
6
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/prototype.js?1295870562" type="text/javascript"></script>
7
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/effects.js?1295870562" type="text/javascript"></script>
8
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/dragdrop.js?1295870562" type="text/javascript"></script>
9
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/controls.js?1295870562" type="text/javascript"></script>
10
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/rails.js?1295870562" type="text/javascript"></script>
11
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/application.js?1295870562" type="text/javascript"></script>
12
+
13
+ </head>
14
+ <body>
15
+
16
+ <div id='topnav'>
17
+ You are signed in as Bob.
18
+ <a href="/sign-out">Sign out</a>
19
+ </div>
20
+
21
+ <div class='flash notice'>You have successfully signed in.</div>
22
+
23
+ <h1>Articles</h1>
24
+
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+
6
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/prototype.js?1295870562" type="text/javascript"></script>
7
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/effects.js?1295870562" type="text/javascript"></script>
8
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/dragdrop.js?1295870562" type="text/javascript"></script>
9
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/controls.js?1295870562" type="text/javascript"></script>
10
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/rails.js?1295870562" type="text/javascript"></script>
11
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/application.js?1295870562" type="text/javascript"></script>
12
+
13
+ </head>
14
+ <body>
15
+
16
+ <div id='topnav'>
17
+ You are signed in as Bob.
18
+ <a href="/sign-out">Sign out</a>
19
+ </div>
20
+
21
+ <div class='flash notice'>You have successfully signed in.</div>
22
+
23
+ <h1>Articles</h1>
24
+
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+
6
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/prototype.js?1295870562" type="text/javascript"></script>
7
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/effects.js?1295870562" type="text/javascript"></script>
8
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/dragdrop.js?1295870562" type="text/javascript"></script>
9
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/controls.js?1295870562" type="text/javascript"></script>
10
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/rails.js?1295870562" type="text/javascript"></script>
11
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/application.js?1295870562" type="text/javascript"></script>
12
+
13
+ </head>
14
+ <body>
15
+
16
+ <div id='topnav'>
17
+ You are signed in as Bob.
18
+ <a href="/sign-out">Sign out</a>
19
+ </div>
20
+
21
+ <div class='flash notice'>You have successfully signed in.</div>
22
+
23
+ <h1>Articles</h1>
24
+
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+
6
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/prototype.js?1295870562" type="text/javascript"></script>
7
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/effects.js?1295870562" type="text/javascript"></script>
8
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/dragdrop.js?1295870562" type="text/javascript"></script>
9
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/controls.js?1295870562" type="text/javascript"></script>
10
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/rails.js?1295870562" type="text/javascript"></script>
11
+ <script src="/Users/andy/code/src/quo_vadis/test/dummy/public/javascripts/application.js?1295870562" type="text/javascript"></script>
12
+
13
+ </head>
14
+ <body>
15
+
16
+ <div id='topnav'>
17
+ <a href="/sign-in">Sign in</a>
18
+ </div>
19
+
20
+ <div class='flash notice'>Please sign in first.</div>
21
+
22
+ <h1>Sign in</h1>
23
+
24
+ <form accept-charset="UTF-8" action="/sign-in" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
25
+ <p>
26
+ <label for="username">Username</label>
27
+ <input id="username" name="username" type="text" />
28
+ </p>
29
+ <p>
30
+ <label for="password">Password</label>
31
+ <input id="password" name="password" type="password" />
32
+ </p>
33
+ <p>
34
+ <input name="commit" type="submit" value="Sign in" />
35
+ </p>
36
+ </form>
37
+
38
+ </body>
39
+ </html>
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class AuthenticationTest < ActiveSupport::IntegrationCase
4
+
5
+ teardown do
6
+ Capybara.reset_sessions!
7
+ end
8
+
9
+ test 'action not requiring authentication' do
10
+ visit articles_path
11
+
12
+ assert_equal articles_path, current_path
13
+ within 'h1' do
14
+ assert page.has_content?('Articles')
15
+ end
16
+ end
17
+
18
+ test 'action requiring authentication' do
19
+ # try to see page
20
+ visit new_article_path
21
+
22
+ # test we need to authenticate
23
+ assert_equal sign_in_path, current_path
24
+ within '.flash.notice' do
25
+ assert page.has_content? 'Please sign in first.'
26
+ end
27
+
28
+ # sign in
29
+ user_factory 'Bob', 'bob', 'secret'
30
+ sign_in_as 'bob', 'secret'
31
+ visit new_article_path
32
+
33
+ # test we can now see page
34
+ assert_equal new_article_path, current_path
35
+ within 'h1' do
36
+ assert page.has_content?('New Article')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigTest < ActiveSupport::IntegrationCase
4
+
5
+ setup do
6
+ user_factory 'Bob', 'bob', 'secret'
7
+ end
8
+
9
+ teardown do
10
+ Capybara.reset_sessions!
11
+ reset_quo_vadis_configuration
12
+ end
13
+
14
+ test 'signed_in_url config' do
15
+ sign_in_as 'bob', 'secret'
16
+ assert_equal root_path, current_path
17
+ visit sign_out_path
18
+
19
+ QuoVadis.signed_in_url = :articles
20
+
21
+ sign_in_as 'bob', 'secret'
22
+ assert_equal articles_path, current_path
23
+ end
24
+
25
+ test 'signed_in_url proc config' do
26
+ QuoVadis.signed_in_url = Proc.new do |user|
27
+ user.name == 'Bob' ? :articles : :root
28
+ end
29
+ sign_in_as 'bob', 'secret'
30
+ assert_equal articles_path, current_path
31
+
32
+ QuoVadis.signed_in_url = Proc.new do |user|
33
+ user.name != 'Bob' ? :articles : :root
34
+ end
35
+ sign_in_as 'bob', 'secret'
36
+ assert_equal root_path, current_path
37
+ end
38
+
39
+ test 'override_original_url config' do
40
+ visit new_article_path
41
+ assert_equal sign_in_path, current_path
42
+ sign_in_as 'bob', 'secret'
43
+ assert_equal new_article_path, current_path
44
+ visit sign_out_path
45
+
46
+ QuoVadis.override_original_url = true
47
+
48
+ visit new_article_path
49
+ assert_equal sign_in_path, current_path
50
+ sign_in_as 'bob', 'secret'
51
+ assert_equal root_path, current_path
52
+ end
53
+
54
+ test 'signed_out_url config' do
55
+ visit sign_out_path
56
+ assert_equal root_path, current_path
57
+
58
+ QuoVadis.signed_out_url = :articles
59
+
60
+ visit sign_out_path
61
+ assert_equal articles_path, current_path
62
+ end
63
+
64
+ test 'signed_in_hook' do
65
+ QuoVadis.signed_in_hook = Proc.new do |user, request|
66
+ user.update_attributes :name => 'Robert'
67
+ end
68
+ sign_in_as 'bob', 'secret'
69
+ within '#topnav' do
70
+ assert page.has_content?('You are signed in as Robert.')
71
+ end
72
+ end
73
+
74
+ test 'failed_sign_in hook' do
75
+ QuoVadis.failed_sign_in_hook = Proc.new do |request|
76
+ request.flash[:muppet] = request.params[:username]
77
+ end
78
+ sign_in_as 'bob', 'wrong'
79
+ within '.flash.muppet' do
80
+ assert page.has_content?('bob')
81
+ end
82
+ end
83
+
84
+ test 'signed_out hook' do
85
+ QuoVadis.signed_out_hook = Proc.new do |user, request|
86
+ request.flash[:fyi] = user.name
87
+ end
88
+ sign_in_as 'bob', 'secret'
89
+ visit sign_out_path
90
+
91
+ within '.flash.fyi' do
92
+ assert page.has_content?('Bob')
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class HelperTest < ActiveSupport::IntegrationCase
4
+
5
+ teardown do
6
+ Capybara.reset_sessions!
7
+ end
8
+
9
+ test 'Current user helper' do
10
+ user_factory 'Bob', 'bob', 'secret'
11
+ sign_in_as 'bob', 'secret'
12
+
13
+ within '#topnav' do
14
+ assert page.has_content?('You are signed in as Bob.')
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActiveSupport::IntegrationCase
4
+ test 'Sanity test' do
5
+ assert_kind_of Dummy::Application, Rails.application
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class SignInTest < ActiveSupport::IntegrationCase
4
+
5
+ teardown do
6
+ Capybara.reset_sessions!
7
+ end
8
+
9
+ test 'failed sign in' do
10
+ sign_in_as 'bob', 'secret'
11
+
12
+ assert_equal sign_in_path, current_path
13
+ within '.flash.alert' do
14
+ assert page.has_content?('Sorry, we did not recognise you.')
15
+ end
16
+ end
17
+
18
+ test 'successful sign in' do
19
+ user_factory 'Bob', 'bob', 'secret'
20
+ sign_in_as 'bob', 'secret'
21
+
22
+ assert_equal root_path, current_path
23
+ within '.flash.notice' do
24
+ assert page.has_content?('You have successfully signed in.')
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class SignOutTest < ActiveSupport::IntegrationCase
4
+
5
+ teardown do
6
+ Capybara.reset_sessions!
7
+ end
8
+
9
+ test 'sign out' do
10
+ user_factory 'Bob', 'bob', 'secret'
11
+ sign_in_as 'bob', 'secret'
12
+ visit sign_out_path
13
+
14
+ assert_equal root_path, current_path
15
+ within '.flash.notice' do
16
+ assert page.has_content?('You have successfully signed out.')
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class QuoVadisTest < ActiveSupport::TestCase
4
+ test 'Sanity test' do
5
+ assert_kind_of Module, QuoVadis
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # Define a bare test case to use with Capybara
2
+ class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
3
+ include Capybara
4
+ include Rails.application.routes.url_helpers
5
+ end
@@ -0,0 +1,46 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ ActionMailer::Base.delivery_method = :test
8
+ ActionMailer::Base.perform_deliveries = true
9
+ ActionMailer::Base.default_url_options[:host] = "test.com"
10
+
11
+ Rails.backtrace_cleaner.remove_silencers!
12
+
13
+ # Configure capybara for integration testing
14
+ require "capybara/rails"
15
+ Capybara.default_driver = :rack_test
16
+ Capybara.default_selector = :css
17
+
18
+ # Run any available migration
19
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
20
+
21
+ # Load support files
22
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
23
+
24
+ #
25
+ # Common methods
26
+ #
27
+
28
+ def sign_in_as(username, password)
29
+ visit sign_in_path
30
+ fill_in 'username', :with => username
31
+ fill_in 'password', :with => password
32
+ click_button 'Sign in'
33
+ end
34
+
35
+ def user_factory(name, username, password)
36
+ User.create! :name => name, :username => username, :password => password
37
+ end
38
+
39
+ def reset_quo_vadis_configuration
40
+ QuoVadis.signed_in_url = :root
41
+ QuoVadis.override_original_url = false
42
+ QuoVadis.signed_out_url = :root
43
+ QuoVadis.signed_in_hook = nil
44
+ QuoVadis.failed_sign_in_hook = nil
45
+ QuoVadis.signed_out_hook = nil
46
+ end