keymail 0.1.0.alpha → 0.1.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -9
  3. data/Rakefile +12 -11
  4. data/app/models/keymail/{auth.rb → authentication.rb} +4 -2
  5. data/app/models/keymail/token.rb +2 -1
  6. data/config/routes.rb +0 -1
  7. data/lib/keymail/version.rb +1 -1
  8. data/test/dummy/app/controllers/auth_controller.rb +32 -0
  9. data/test/dummy/app/views/auth/new.html.erb +8 -0
  10. data/test/dummy/app/views/auth/request_email.html.erb +7 -0
  11. data/test/dummy/app/views/auth/success.html.erb +3 -0
  12. data/test/dummy/config/initializers/setup_mail.rb +13 -0
  13. data/test/dummy/config/routes.rb +7 -1
  14. data/test/dummy/db/development.sqlite3 +0 -0
  15. data/test/dummy/db/test.sqlite3 +0 -0
  16. data/test/dummy/log/development.log +595 -0
  17. data/test/dummy/log/test.log +60222 -0
  18. data/test/dummy/test/controllers/auth_controller_test.rb +40 -0
  19. data/test/dummy/{app/assets/stylesheets/application.css → tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705} +0 -0
  20. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  21. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  23. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  24. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  25. data/test/dummy/tmp/pids/server.pid +1 -0
  26. data/test/integration/feature_test.rb +15 -7
  27. data/test/mailers/keymail/auth_mailer_test.rb +12 -5
  28. data/test/models/keymail/{auth_test.rb → authentication_test.rb} +12 -8
  29. data/test/test_helper.rb +21 -4
  30. metadata +33 -16
  31. data/test/dummy/app/assets/javascripts/application.js +0 -13
  32. data/test/dummy/app/helpers/application_helper.rb +0 -2
  33. data/test/integration/navigation_test.rb +0 -10
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ describe AuthController do
4
+
5
+ it 'renders the form' do
6
+ get :new
7
+ assert_template :new
8
+ end
9
+
10
+ it 'redirects to form if no email is posted' do
11
+ post :request_email
12
+ assert_redirected_to :root
13
+ end
14
+
15
+ it 'sends an email to the right address' do
16
+ test_email = 'test@email.com'
17
+ post :request_email, email: test_email
18
+ ActionMailer::Base.deliveries.wont_be :empty?
19
+ ActionMailer::Base.deliveries.last.to.must_equal [test_email]
20
+ assert_template :request_email
21
+ end
22
+
23
+ it 'redirects to success page with valid token' do
24
+ token = Factory :token
25
+ get :validate_link, url_key: token.url_key
26
+ assert_redirected_to :success
27
+ end
28
+
29
+ it 'redirects to error page with invalid token' do
30
+ get :validate_link, url_key: 'invalid_url_key'
31
+ assert_redirected_to :fail
32
+ end
33
+
34
+ it 'redirects to error page with expired token' do
35
+ token = Factory :token, expires_at: 10.minutes.ago
36
+ get :validate_link, url_key: 'invalid_url_key'
37
+ assert_redirected_to :fail
38
+ end
39
+
40
+ end
@@ -0,0 +1 @@
1
+ 95672
@@ -1,15 +1,23 @@
1
1
  require 'test_helper'
2
+ require 'pry'
2
3
 
3
- describe 'Keymail Integration' do
4
+ describe 'Feature Integration' do
5
+
6
+ before do
7
+ clear_emails
8
+
9
+ visit root_path
10
+ fill_in 'email', with: 'test@email.com'
11
+ click_on 'Send email'
12
+
13
+ open_email('test@email.com') # sets current_email
14
+ end
4
15
 
5
16
  it 'logs in a user when provided an email' do
6
- # visit log_in_path
7
- # enter email in field
8
- # click link in email
9
- # expect to be logged in
17
+ current_email.first(:link).click
18
+ page.must_have_content 'success'
10
19
  end
11
20
 
12
- it 'logs in a user with an optional passcode' do
21
+ # it 'logs in a user with an optional passcode'
13
22
 
14
- end
15
23
  end
@@ -1,22 +1,29 @@
1
1
  require 'test_helper'
2
2
 
3
- require 'minitest/mock'
4
-
5
3
  module Keymail
6
4
  describe AuthMailer do
7
5
 
6
+ before do
7
+ # Reset the list of sent email
8
+ ActionMailer::Base.deliveries.clear
9
+ AuthMailer.log_in(token).deliver
10
+ end
11
+
8
12
  let(:token) { Factory :token }
9
- let(:email) { AuthMailer.log_in(token).deliver }
13
+ let(:email) { ActionMailer::Base.deliveries.last }
10
14
  let(:body) { email.body.raw_source }
11
15
 
16
+ it 'sends the email' do
17
+ ActionMailer::Base.deliveries.wont_be :empty?
18
+ end
19
+
12
20
  it 'sends authentication email to the right address' do
13
- sent_emails.wont_be :empty?
14
21
  email.to.must_equal [token.email]
15
22
  end
16
23
 
17
24
  it 'has the log in link' do
18
25
  # TODO: link_to
19
- body.must_have_content "http://localhost:3000/keymail/auth/#{token.url_key}"
26
+ body.must_have_content "http://localhost:3000/auth/#{token.url_key}"
20
27
  end
21
28
 
22
29
  it 'has the expiration date' do
@@ -1,32 +1,36 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Keymail
4
- describe Auth do
4
+ describe Authentication do
5
5
  context '.request' do
6
6
 
7
7
  it 'creates a new token' do
8
- -> { Auth.request('test@email.com') }.must_change 'Token.count', +1
8
+ -> { Authentication.request('test@email.com') }.must_change 'Token.count', +1
9
9
  end
10
10
 
11
11
  it 'sends an email' do
12
- -> { Auth.request('test@email.com') }.must_change 'sent_emails.count', +1
12
+ -> { Authentication.request('test@email.com') }.must_change 'ActionMailer::Base.deliveries.count', +1
13
+ end
14
+
15
+ it 'raises an error if email is nil' do
16
+ -> { Authentication.request(nil) }.must_raise StandardError
13
17
  end
14
18
  end
15
19
 
16
20
  context '.verify_url' do
17
21
  it 'destroys the token' do
18
22
  token = Factory :token
19
- Auth.verify_url_key(token.url_key)
23
+ Authentication.verify_url_key(token.url_key)
20
24
  Token.exists?(token).must_equal false
21
25
  end
22
26
 
23
27
  it 'does not delete anything if the token is invalid' do
24
- -> { Auth.verify_url_key('not_a_valid_key') }.wont_change 'Token.count'
28
+ -> { Authentication.verify_url_key('not_a_valid_key') }.wont_change 'Token.count'
25
29
  end
26
30
 
27
31
  context 'authenticated' do
28
32
  let(:token) { Factory :token }
29
- let(:response) { Auth.verify_url_key(token.url_key) }
33
+ let(:response) { Authentication.verify_url_key(token.url_key) }
30
34
 
31
35
  it 'is authenticated' do
32
36
  response.must_be :authenticated?
@@ -45,7 +49,7 @@ module Keymail
45
49
 
46
50
  context 'expired' do
47
51
  let(:token) { Factory :token, expires_at: 10.minutes.ago }
48
- let(:response) { Auth.verify_url_key(token.url_key) }
52
+ let(:response) { Authentication.verify_url_key(token.url_key) }
49
53
 
50
54
  it 'is not authenticated' do
51
55
  response.wont_be :authenticated?
@@ -61,7 +65,7 @@ module Keymail
61
65
  end
62
66
 
63
67
  context 'invalid' do
64
- let(:response) { Auth.verify_url_key('invalid_url_key') }
68
+ let(:response) { Authentication.verify_url_key('invalid_url_key') }
65
69
 
66
70
  it 'is not authenticated' do
67
71
  response.wont_be :authenticated?
@@ -53,10 +53,27 @@ class Proc
53
53
  infect_an_assertion :assert_no_difference, :wont_change
54
54
  end
55
55
 
56
- def sent_emails
57
- ActionMailer::Base.deliveries
56
+ # Make the controller methods (get, post etc...) work
57
+ class ControllerSpec < Minitest::Spec
58
+ include Rails.application.routes.url_helpers
59
+ include ActionController::TestCase::Behavior
60
+
61
+ before do
62
+ @routes = Rails.application.routes
63
+ end
58
64
  end
65
+ Minitest::Spec.register_spec_type(/Controller$/, ControllerSpec)
66
+
67
+ # Set up Capybara
68
+ require 'capybara/rails'
69
+ class AcceptanceSpec < MiniTest::Spec
70
+ include Rails.application.routes.url_helpers
71
+ include Capybara::DSL
72
+ include Capybara::Email::DSL
73
+
74
+ # before do
75
+ # @routes = Rails.application.routes
76
+ # end
59
77
 
60
- def last_email
61
- ActionMailer::Base.deliveries.last
62
78
  end
79
+ MiniTest::Spec.register_spec_type(/Integration$/, AcceptanceSpec)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keymail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alcesleo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-18 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -37,7 +37,7 @@ files:
37
37
  - Rakefile
38
38
  - app/controllers/keymail/application_controller.rb
39
39
  - app/mailers/keymail/auth_mailer.rb
40
- - app/models/keymail/auth.rb
40
+ - app/models/keymail/authentication.rb
41
41
  - app/models/keymail/token.rb
42
42
  - app/views/keymail/auth_mailer/log_in.text.erb
43
43
  - config/routes.rb
@@ -48,10 +48,11 @@ files:
48
48
  - lib/tasks/keymail_tasks.rake
49
49
  - test/dummy/README.rdoc
50
50
  - test/dummy/Rakefile
51
- - test/dummy/app/assets/javascripts/application.js
52
- - test/dummy/app/assets/stylesheets/application.css
53
51
  - test/dummy/app/controllers/application_controller.rb
54
- - test/dummy/app/helpers/application_helper.rb
52
+ - test/dummy/app/controllers/auth_controller.rb
53
+ - test/dummy/app/views/auth/new.html.erb
54
+ - test/dummy/app/views/auth/request_email.html.erb
55
+ - test/dummy/app/views/auth/success.html.erb
55
56
  - test/dummy/app/views/layouts/application.html.erb
56
57
  - test/dummy/bin/bundle
57
58
  - test/dummy/bin/rails
@@ -70,6 +71,7 @@ files:
70
71
  - test/dummy/config/initializers/mime_types.rb
71
72
  - test/dummy/config/initializers/secret_token.rb
72
73
  - test/dummy/config/initializers/session_store.rb
74
+ - test/dummy/config/initializers/setup_mail.rb
73
75
  - test/dummy/config/initializers/wrap_parameters.rb
74
76
  - test/dummy/config/locales/en.yml
75
77
  - test/dummy/config/routes.rb
@@ -82,12 +84,19 @@ files:
82
84
  - test/dummy/public/422.html
83
85
  - test/dummy/public/500.html
84
86
  - test/dummy/public/favicon.ico
87
+ - test/dummy/test/controllers/auth_controller_test.rb
88
+ - test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
89
+ - test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
90
+ - test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
91
+ - test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
92
+ - test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
93
+ - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
94
+ - test/dummy/tmp/pids/server.pid
85
95
  - test/factories.rb
86
96
  - test/integration/feature_test.rb
87
- - test/integration/navigation_test.rb
88
97
  - test/keymail_test.rb
89
98
  - test/mailers/keymail/auth_mailer_test.rb
90
- - test/models/keymail/auth_test.rb
99
+ - test/models/keymail/authentication_test.rb
91
100
  - test/models/keymail/token_test.rb
92
101
  - test/test_helper.rb
93
102
  homepage: https://github.com/alcesleo/keymail
@@ -104,9 +113,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
113
  version: '0'
105
114
  required_rubygems_version: !ruby/object:Gem::Requirement
106
115
  requirements:
107
- - - ">"
116
+ - - ">="
108
117
  - !ruby/object:Gem::Version
109
- version: 1.3.1
118
+ version: '0'
110
119
  requirements: []
111
120
  rubyforge_project:
112
121
  rubygems_version: 2.2.2
@@ -116,10 +125,11 @@ summary: Forget passwords, authenticate via email!
116
125
  test_files:
117
126
  - test/dummy/README.rdoc
118
127
  - test/dummy/Rakefile
119
- - test/dummy/app/assets/javascripts/application.js
120
- - test/dummy/app/assets/stylesheets/application.css
121
128
  - test/dummy/app/controllers/application_controller.rb
122
- - test/dummy/app/helpers/application_helper.rb
129
+ - test/dummy/app/controllers/auth_controller.rb
130
+ - test/dummy/app/views/auth/new.html.erb
131
+ - test/dummy/app/views/auth/request_email.html.erb
132
+ - test/dummy/app/views/auth/success.html.erb
123
133
  - test/dummy/app/views/layouts/application.html.erb
124
134
  - test/dummy/bin/bundle
125
135
  - test/dummy/bin/rails
@@ -137,6 +147,7 @@ test_files:
137
147
  - test/dummy/config/initializers/mime_types.rb
138
148
  - test/dummy/config/initializers/secret_token.rb
139
149
  - test/dummy/config/initializers/session_store.rb
150
+ - test/dummy/config/initializers/setup_mail.rb
140
151
  - test/dummy/config/initializers/wrap_parameters.rb
141
152
  - test/dummy/config/locales/en.yml
142
153
  - test/dummy/config/routes.rb
@@ -150,12 +161,18 @@ test_files:
150
161
  - test/dummy/public/422.html
151
162
  - test/dummy/public/500.html
152
163
  - test/dummy/public/favicon.ico
164
+ - test/dummy/test/controllers/auth_controller_test.rb
165
+ - test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
166
+ - test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
167
+ - test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
168
+ - test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
169
+ - test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
170
+ - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
171
+ - test/dummy/tmp/pids/server.pid
153
172
  - test/factories.rb
154
173
  - test/integration/feature_test.rb
155
- - test/integration/navigation_test.rb
156
174
  - test/keymail_test.rb
157
175
  - test/mailers/keymail/auth_mailer_test.rb
158
- - test/models/keymail/auth_test.rb
176
+ - test/models/keymail/authentication_test.rb
159
177
  - test/models/keymail/token_test.rb
160
178
  - test/test_helper.rb
161
- has_rdoc:
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,10 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NavigationTest < ActionDispatch::IntegrationTest
4
- fixtures :all
5
-
6
- # test "the truth" do
7
- # assert true
8
- # end
9
- end
10
-