pillowfort 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +10 -0
  3. data/app/controllers/pillowfort/concerns/controller_activation.rb +27 -0
  4. data/app/controllers/pillowfort/concerns/controller_authentication.rb +2 -9
  5. data/app/models/pillowfort/concerns/model_activation.rb +84 -0
  6. data/app/models/pillowfort/concerns/model_authentication.rb +10 -25
  7. data/app/models/pillowfort/concerns/model_password_reset.rb +62 -0
  8. data/lib/pillowfort/controller_methods.rb +12 -0
  9. data/lib/pillowfort/model_finder.rb +7 -0
  10. data/lib/pillowfort/token_generator.rb +19 -0
  11. data/lib/pillowfort/version.rb +1 -1
  12. data/spec/{dummy/spec/controllers → controllers}/accounts_controller_spec.rb +19 -1
  13. data/spec/dummy/app/controllers/accounts_controller.rb +2 -0
  14. data/spec/dummy/app/models/account.rb +2 -0
  15. data/spec/dummy/config/database.yml +5 -1
  16. data/spec/dummy/config/environments/development.rb +42 -0
  17. data/spec/dummy/db/development.sqlite3 +0 -0
  18. data/spec/dummy/db/migrate/20150210215727_add_password_reset_tokens.rb +8 -0
  19. data/spec/dummy/db/migrate/20150211185152_add_activation_token_to_account.rb +9 -0
  20. data/spec/dummy/db/migrate/20150413161345_add_auth_token_ttl_to_account.rb +7 -0
  21. data/spec/dummy/db/schema.rb +9 -3
  22. data/spec/dummy/db/test.sqlite3 +0 -0
  23. data/spec/dummy/log/test.log +15233 -1641
  24. data/spec/dummy/spec/spec_helper.rb +1 -10
  25. data/spec/factories/accounts.rb +19 -0
  26. data/spec/models/account_spec.rb +531 -0
  27. data/spec/{dummy/spec/rails_helper.rb → rails_helper.rb} +1 -1
  28. data/spec/spec_helper.rb +25 -0
  29. data/spec/{dummy/spec/support → support}/helpers/authentication_helper.rb +0 -0
  30. metadata +62 -17
  31. data/spec/dummy/log/development.log +0 -0
  32. data/spec/dummy/spec/factories/accounts.rb +0 -10
  33. data/spec/dummy/spec/models/account_spec.rb +0 -276
@@ -1,7 +1,7 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  ENV["RAILS_ENV"] ||= 'test'
3
3
  require 'spec_helper'
4
- require File.expand_path("../../config/environment", __FILE__)
4
+ require File.expand_path("../dummy/config/environment", __FILE__)
5
5
  require 'rspec/rails'
6
6
  require 'factory_girl_rails'
7
7
 
@@ -0,0 +1,25 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+
5
+ require 'rspec/rails'
6
+ require 'rspec/autorun'
7
+ require 'factory_girl_rails'
8
+ require 'rspec/its'
9
+
10
+ Rails.backtrace_cleaner.remove_silencers!
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ RSpec.configure do |config|
16
+ config.mock_with :rspec
17
+ config.use_transactional_fixtures = true
18
+ config.infer_base_class_for_anonymous_controllers = false
19
+ config.expect_with :rspec do |expectations|
20
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
21
+ end
22
+ config.mock_with :rspec do |mocks|
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pillowfort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Lowrimore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: factory_girl_rails
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Opinionated, session-less API authentication
84
112
  email:
85
113
  - tlowrimore@coroutine.com
@@ -89,15 +117,22 @@ extra_rdoc_files: []
89
117
  files:
90
118
  - MIT-LICENSE
91
119
  - Rakefile
120
+ - app/controllers/pillowfort/concerns/controller_activation.rb
92
121
  - app/controllers/pillowfort/concerns/controller_authentication.rb
122
+ - app/models/pillowfort/concerns/model_activation.rb
93
123
  - app/models/pillowfort/concerns/model_authentication.rb
124
+ - app/models/pillowfort/concerns/model_password_reset.rb
94
125
  - config/routes.rb
95
126
  - lib/pillowfort.rb
127
+ - lib/pillowfort/controller_methods.rb
96
128
  - lib/pillowfort/engine.rb
97
129
  - lib/pillowfort/model_context.rb
130
+ - lib/pillowfort/model_finder.rb
98
131
  - lib/pillowfort/pillow_fight.rb
132
+ - lib/pillowfort/token_generator.rb
99
133
  - lib/pillowfort/version.rb
100
134
  - lib/tasks/pillowfort_tasks.rake
135
+ - spec/controllers/accounts_controller_spec.rb
101
136
  - spec/dummy/README.rdoc
102
137
  - spec/dummy/Rakefile
103
138
  - spec/dummy/app/assets/javascripts/accounts.js
@@ -121,6 +156,7 @@ files:
121
156
  - spec/dummy/config/boot.rb
122
157
  - spec/dummy/config/database.yml
123
158
  - spec/dummy/config/environment.rb
159
+ - spec/dummy/config/environments/development.rb
124
160
  - spec/dummy/config/environments/test.rb
125
161
  - spec/dummy/config/initializers/assets.rb
126
162
  - spec/dummy/config/initializers/backtrace_silencers.rb
@@ -133,21 +169,24 @@ files:
133
169
  - spec/dummy/config/locales/en.yml
134
170
  - spec/dummy/config/routes.rb
135
171
  - spec/dummy/config/secrets.yml
172
+ - spec/dummy/db/development.sqlite3
136
173
  - spec/dummy/db/migrate/20150127045508_create_accounts.rb
174
+ - spec/dummy/db/migrate/20150210215727_add_password_reset_tokens.rb
175
+ - spec/dummy/db/migrate/20150211185152_add_activation_token_to_account.rb
176
+ - spec/dummy/db/migrate/20150413161345_add_auth_token_ttl_to_account.rb
137
177
  - spec/dummy/db/schema.rb
138
178
  - spec/dummy/db/test.sqlite3
139
- - spec/dummy/log/development.log
140
179
  - spec/dummy/log/test.log
141
180
  - spec/dummy/public/404.html
142
181
  - spec/dummy/public/422.html
143
182
  - spec/dummy/public/500.html
144
183
  - spec/dummy/public/favicon.ico
145
- - spec/dummy/spec/controllers/accounts_controller_spec.rb
146
- - spec/dummy/spec/factories/accounts.rb
147
- - spec/dummy/spec/models/account_spec.rb
148
- - spec/dummy/spec/rails_helper.rb
149
184
  - spec/dummy/spec/spec_helper.rb
150
- - spec/dummy/spec/support/helpers/authentication_helper.rb
185
+ - spec/factories/accounts.rb
186
+ - spec/models/account_spec.rb
187
+ - spec/rails_helper.rb
188
+ - spec/spec_helper.rb
189
+ - spec/support/helpers/authentication_helper.rb
151
190
  homepage: https://github.com/coroutine/pillowfort
152
191
  licenses:
153
192
  - MIT
@@ -158,9 +197,9 @@ require_paths:
158
197
  - lib
159
198
  required_ruby_version: !ruby/object:Gem::Requirement
160
199
  requirements:
161
- - - ">="
200
+ - - "~>"
162
201
  - !ruby/object:Gem::Version
163
- version: '0'
202
+ version: 2.2.0
164
203
  required_rubygems_version: !ruby/object:Gem::Requirement
165
204
  requirements:
166
205
  - - ">="
@@ -168,11 +207,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
207
  version: '0'
169
208
  requirements: []
170
209
  rubyforge_project:
171
- rubygems_version: 2.4.5
210
+ rubygems_version: 2.4.6
172
211
  signing_key:
173
212
  specification_version: 4
174
213
  summary: Opinionated, session-less API authentication
175
214
  test_files:
215
+ - spec/controllers/accounts_controller_spec.rb
176
216
  - spec/dummy/app/assets/javascripts/accounts.js
177
217
  - spec/dummy/app/assets/javascripts/application.js
178
218
  - spec/dummy/app/assets/stylesheets/accounts.css
@@ -193,6 +233,7 @@ test_files:
193
233
  - spec/dummy/config/boot.rb
194
234
  - spec/dummy/config/database.yml
195
235
  - spec/dummy/config/environment.rb
236
+ - spec/dummy/config/environments/development.rb
196
237
  - spec/dummy/config/environments/test.rb
197
238
  - spec/dummy/config/initializers/assets.rb
198
239
  - spec/dummy/config/initializers/backtrace_silencers.rb
@@ -206,10 +247,13 @@ test_files:
206
247
  - spec/dummy/config/routes.rb
207
248
  - spec/dummy/config/secrets.yml
208
249
  - spec/dummy/config.ru
250
+ - spec/dummy/db/development.sqlite3
209
251
  - spec/dummy/db/migrate/20150127045508_create_accounts.rb
252
+ - spec/dummy/db/migrate/20150210215727_add_password_reset_tokens.rb
253
+ - spec/dummy/db/migrate/20150211185152_add_activation_token_to_account.rb
254
+ - spec/dummy/db/migrate/20150413161345_add_auth_token_ttl_to_account.rb
210
255
  - spec/dummy/db/schema.rb
211
256
  - spec/dummy/db/test.sqlite3
212
- - spec/dummy/log/development.log
213
257
  - spec/dummy/log/test.log
214
258
  - spec/dummy/public/404.html
215
259
  - spec/dummy/public/422.html
@@ -217,9 +261,10 @@ test_files:
217
261
  - spec/dummy/public/favicon.ico
218
262
  - spec/dummy/Rakefile
219
263
  - spec/dummy/README.rdoc
220
- - spec/dummy/spec/controllers/accounts_controller_spec.rb
221
- - spec/dummy/spec/factories/accounts.rb
222
- - spec/dummy/spec/models/account_spec.rb
223
- - spec/dummy/spec/rails_helper.rb
224
264
  - spec/dummy/spec/spec_helper.rb
225
- - spec/dummy/spec/support/helpers/authentication_helper.rb
265
+ - spec/factories/accounts.rb
266
+ - spec/models/account_spec.rb
267
+ - spec/rails_helper.rb
268
+ - spec/spec_helper.rb
269
+ - spec/support/helpers/authentication_helper.rb
270
+ has_rdoc:
File without changes
@@ -1,10 +0,0 @@
1
- FactoryGirl.define do
2
- sequence :email do |n|
3
- "foo.bar.#{n}@baz.org"
4
- end
5
-
6
- factory :account do
7
- email
8
- password { "SuperSafe123" }
9
- end
10
- end
@@ -1,276 +0,0 @@
1
- require 'rails_helper'
2
-
3
- # ------------------------------------------------------------------------------
4
- # Shared Examples
5
- # ------------------------------------------------------------------------------
6
-
7
- RSpec.shared_examples 'an auth token resetter' do
8
- describe 'its affect on the auth_token' do
9
- subject { account.auth_token }
10
-
11
- describe 'before the call' do
12
- it { should eq(auth_token) }
13
- end
14
-
15
- describe 'after the call' do
16
- before { call_the_method }
17
- it { should_not eq(auth_token) }
18
- end
19
- end
20
-
21
- describe 'its affect on the auth_token_expires_at' do
22
- subject { account.auth_token_expires_at }
23
-
24
- describe 'before the call' do
25
- it { should eq(auth_token_expires_at) }
26
- end
27
-
28
- describe 'after the call' do
29
- before { call_the_method }
30
- it { should be > auth_token_expires_at }
31
- end
32
- end
33
- end
34
-
35
- # ------------------------------------------------------------------------------
36
- # The Spec!
37
- # ------------------------------------------------------------------------------
38
-
39
- RSpec.describe Account, :type => :model do
40
-
41
- describe 'its validations' do
42
- before { account.save }
43
- subject { account.errors.messages }
44
-
45
- describe 'email validations' do
46
- let(:account) { FactoryGirl.build(:account, email: email) }
47
-
48
- context 'presence_of' do
49
- let(:email) { nil }
50
-
51
- it { should include(email: ["can't be blank"]) }
52
- end
53
-
54
- context 'uniqueness' do
55
- let(:email) { 'foobar@baz.com' }
56
- let(:dup_account) { FactoryGirl.build(:account, email: email) }
57
- before { dup_account.save }
58
- subject { dup_account.errors.messages}
59
-
60
- it { should include(email: ["has already been taken"]) }
61
- end
62
- end
63
-
64
- describe 'password validations' do
65
- let(:account) { FactoryGirl.build(:account, password: password) }
66
-
67
- context 'presence_of' do
68
- let(:password) { nil }
69
-
70
- it { should include(password: [/can't be blank/, /is too short/]) }
71
- end
72
-
73
- context 'length of' do
74
- context "when it's too short" do
75
- let(:password) { "x"*3 }
76
-
77
- it { should include(password: [/is too short/])}
78
- end
79
-
80
- context "when it's too long" do
81
- let(:password) { "x"*80 }
82
-
83
- it { should include(password: [/is too long/])}
84
- end
85
- end
86
- end
87
- end
88
-
89
- describe 'the instance methods' do
90
- let(:account) {
91
- FactoryGirl.create :account,
92
- auth_token: auth_token,
93
- auth_token_expires_at: auth_token_expires_at
94
- }
95
-
96
- let(:auth_token) { 'abc123def456' }
97
- let(:auth_token_expires_at) { 1.day.from_now }
98
-
99
- describe '#ensure_auth_token' do
100
- subject { account.auth_token }
101
- before { account.ensure_auth_token }
102
-
103
- context 'when the token is nil' do
104
- let(:auth_token) { nil }
105
- it { should_not be_nil }
106
- end
107
-
108
- context 'when the token is not nil' do
109
- let(:auth_token) { 'deadbeef' }
110
- it { should eq('deadbeef') }
111
- end
112
- end
113
-
114
- describe '#reset_auth_token' do
115
- let(:call_the_method) { account.reset_auth_token }
116
- it_behaves_like 'an auth token resetter'
117
-
118
- describe 'its persistence' do
119
- subject { account }
120
- after { call_the_method }
121
- it { should_not receive(:save) }
122
- end
123
- end
124
-
125
- describe '#reset_auth_token!' do
126
- let(:call_the_method) { account.reset_auth_token! }
127
- it_behaves_like 'an auth token resetter'
128
-
129
- describe 'its persistence' do
130
- subject { account }
131
- after { call_the_method }
132
- it { should receive(:save) }
133
- end
134
- end
135
-
136
- describe '#token_expired?' do
137
- subject { account.token_expired? }
138
-
139
- context 'when the token expiration is in the future' do
140
- let(:auth_token_expires_at) { 1.minute.from_now }
141
- it { should be_falsey }
142
- end
143
-
144
- context 'when the token expiration is in the past' do
145
- let(:auth_token_expires_at) { 1.minute.ago }
146
- it { should be_truthy }
147
- end
148
- end
149
-
150
- describe '#password=' do
151
- let!(:current_password) { account.password.to_s }
152
- subject { account.password.to_s }
153
-
154
- describe 'before the call' do
155
- it { should == (current_password) }
156
- end
157
-
158
- describe 'after the call' do
159
- before { account.password = 'fudge_knuckles_45' }
160
- it { should_not eq(current_password) }
161
- end
162
- end
163
- end
164
-
165
- describe 'the class methods' do
166
- let(:email) { 'foobar@baz.com' }
167
- let(:token) { 'deadbeef' }
168
- let(:password) { 'admin4lolz' }
169
- let(:auth_token_expires_at) { 1.day.from_now }
170
-
171
- let!(:account) {
172
- FactoryGirl.create :account,
173
- email: email,
174
- auth_token: token,
175
- password: password,
176
- auth_token_expires_at: auth_token_expires_at
177
- }
178
-
179
- describe '.authenticate_securely' do
180
- let(:email_param) { email }
181
- let(:token_param) { token }
182
- let(:block) { ->(resource) {} }
183
-
184
- subject { Account.authenticate_securely(email_param, token_param, &block) }
185
-
186
- context 'when email is nil' do
187
- let(:email_param) { nil }
188
- it { should be_falsey }
189
- end
190
-
191
- context 'when token is nil' do
192
- let(:token_param) { nil }
193
- it { should be_falsey }
194
- end
195
-
196
- context 'when email and token are provided' do
197
-
198
- context 'email case-sensitivity' do
199
- describe 'when an uppercased email address is provided' do
200
- let(:email_param) { email.upcase }
201
-
202
- it 'should yield the matched account' do
203
- expect { |b| Account.authenticate_securely(email_param, token_param, &b) }.to yield_with_args(account)
204
- end
205
- end
206
-
207
- describe 'when a downcased email address is provided' do
208
- let(:email_param) { email.downcase }
209
-
210
- it 'should yield the matched account' do
211
- expect { |b| Account.authenticate_securely(email_param, token_param, &b) }.to yield_with_args(account)
212
- end
213
- end
214
- end
215
-
216
- context 'when the resource is located' do
217
-
218
- context 'when the auth_token is expired' do
219
- let(:auth_token_expires_at) { 1.week.ago }
220
-
221
- it 'should reset the account auth_token' do
222
- allow(Account).to receive(:find_by_email_case_insensitive) { account }
223
- expect(account).to receive(:reset_auth_token!)
224
- subject
225
- end
226
-
227
- it { should be_falsey }
228
- end
229
-
230
- context 'when the auth_token is current' do
231
-
232
- context 'when the auth_token matches' do
233
- it 'should yield the matched account' do
234
- expect { |b| Account.authenticate_securely(email_param, token_param, &b) }.to yield_with_args(account)
235
- end
236
- end
237
-
238
- context 'when the auth_token does not match' do
239
- it { should be_falsey }
240
- end
241
- end
242
- end
243
-
244
- context 'when the resource is not located' do
245
- it { should be_falsey }
246
- end
247
-
248
- end
249
- end
250
-
251
- describe '.find_and_authenticate' do
252
- let(:email_param) { email }
253
- let(:password_param) { password }
254
-
255
- subject { Account.find_and_authenticate(email_param, password_param) }
256
-
257
-
258
- context 'when the resource is located' do
259
-
260
- context 'when the password matches' do
261
- it { should eq(account) }
262
- end
263
-
264
- context 'when the password does not match' do
265
- let(:password_param) { "#{password}_bad" }
266
- it { should be_falsey }
267
- end
268
- end
269
-
270
- context 'when the resource is not located' do
271
- let(:email_param) { "#{email}_evil" }
272
- it { should be_falsey }
273
- end
274
- end
275
- end
276
- end