josevalim-auth_helpers 0.3.2 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -1
- data/README +1 -10
- data/lib/auth_helpers/spec/confirmable.rb +1 -1
- data/lib/auth_helpers/spec/recoverable.rb +1 -1
- data/lib/auth_helpers.rb +1 -1
- metadata +4 -6
- data/lib/auth_helpers/model/associatable.rb +0 -52
- data/lib/auth_helpers/spec/associatable.rb +0 -31
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
AuthHelpers
|
2
2
|
License: MIT
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.1
|
4
4
|
|
5
5
|
You can also read this README in pretty html at the GitHub project Wiki page:
|
6
6
|
|
@@ -51,19 +51,11 @@ Modules
|
|
51
51
|
a.require_password_confirmation = false
|
52
52
|
end
|
53
53
|
|
54
|
-
include AuthHelpers::Model::Associatable
|
55
54
|
include AuthHelpers::Model::Confirmable
|
56
55
|
include AuthHelpers::Model::Recoverable
|
57
56
|
include AuthHelpers::Model::Updatable
|
58
57
|
end
|
59
58
|
|
60
|
-
== Associatable
|
61
|
-
|
62
|
-
This module automatically creates a belongs_to association for the first *_id
|
63
|
-
in the table. This module exists because, whenever it's possible, I follow the
|
64
|
-
pattern of having an account model and then all accountable objects uses this
|
65
|
-
model (it autodetects polymorphic associations too).
|
66
|
-
|
67
59
|
== Confirmable
|
68
60
|
|
69
61
|
Adds the confirmation handling. It sends an e-mail to the user on account
|
@@ -99,7 +91,6 @@ All modules come with specs, that's why the library does not have tests per se.
|
|
99
91
|
So if you want to test the Account model declared above, just do:
|
100
92
|
|
101
93
|
describe Account do
|
102
|
-
include AuthHelpers::Spec::Associatable
|
103
94
|
include AuthHelpers::Spec::Confirmable
|
104
95
|
include AuthHelpers::Spec::Recoverable
|
105
96
|
include AuthHelpers::Spec::Updatable
|
@@ -54,7 +54,7 @@ module AuthHelpers
|
|
54
54
|
describe 'with an invalid perishable token' do
|
55
55
|
it "should set an error message" do
|
56
56
|
record = base.described_class.find_and_confirm(:perishable_token => "invalid token")
|
57
|
-
record.errors.on(:perishable_token).should == record.errors.generate_message(:perishable_token, :invalid_confirmation, :default => [:invalid])
|
57
|
+
record.errors.on(:perishable_token).should == record.errors.generate_message(:perishable_token, :invalid_confirmation, :default => [:"messages.invalid"])
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should return a new record with the perishable token set" do
|
@@ -32,7 +32,7 @@ module AuthHelpers
|
|
32
32
|
|
33
33
|
it "should not reset password if the given reset password code is invalid" do
|
34
34
|
record = base.described_class.find_and_reset_password(:perishable_token => 'invalid_token', :password => '654321', :password_confirmation => '654321')
|
35
|
-
record.errors.on(:perishable_token).should == record.errors.generate_message(:perishable_token, :invalid_reset_password, :default => [:invalid])
|
35
|
+
record.errors.on(:perishable_token).should == record.errors.generate_message(:perishable_token, :invalid_reset_password, :default => [:"messages.invalid"])
|
36
36
|
@recoverable.reload
|
37
37
|
@recoverable.valid_password?('654321').should be_false
|
38
38
|
end
|
data/lib/auth_helpers.rb
CHANGED
@@ -15,7 +15,7 @@ module AuthHelpers
|
|
15
15
|
def self.new_with_perishable_token_error(klass, message=:invalid, options={})
|
16
16
|
record = klass.new(options)
|
17
17
|
record.perishable_token = options[:perishable_token]
|
18
|
-
record.errors.add(:perishable_token, message, :default => [:invalid])
|
18
|
+
record.errors.add(:perishable_token, message, :default => [:"messages.invalid"])
|
19
19
|
record
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josevalim-auth_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
-
description: AuthHelpers is a collection of modules to improve your Authlogic
|
25
|
+
description: AuthHelpers is a collection of modules to improve your Authlogic resources.
|
26
26
|
email: jose.valim@gmail.com
|
27
27
|
executables: []
|
28
28
|
|
@@ -41,11 +41,9 @@ files:
|
|
41
41
|
- lib/auth_helpers/controller/confirmable.rb
|
42
42
|
- lib/auth_helpers/controller/helpers.rb
|
43
43
|
- lib/auth_helpers/controller/recoverable.rb
|
44
|
-
- lib/auth_helpers/model/associatable.rb
|
45
44
|
- lib/auth_helpers/model/confirmable.rb
|
46
45
|
- lib/auth_helpers/model/recoverable.rb
|
47
46
|
- lib/auth_helpers/model/updatable.rb
|
48
|
-
- lib/auth_helpers/spec/associatable.rb
|
49
47
|
- lib/auth_helpers/spec/confirmable.rb
|
50
48
|
- lib/auth_helpers/spec/notifier.rb
|
51
49
|
- lib/auth_helpers/spec/recoverable.rb
|
@@ -80,6 +78,6 @@ rubyforge_project:
|
|
80
78
|
rubygems_version: 1.2.0
|
81
79
|
signing_key:
|
82
80
|
specification_version: 2
|
83
|
-
summary: AuthHelpers is a collection of modules to improve your Authlogic
|
81
|
+
summary: AuthHelpers is a collection of modules to improve your Authlogic resources.
|
84
82
|
test_files: []
|
85
83
|
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module AuthHelpers
|
2
|
-
module Model
|
3
|
-
|
4
|
-
# Checks for a column that ends with _id in the included model. Then it adds
|
5
|
-
# a belongs_to association, accepts_nested_attributes_for and make the nested
|
6
|
-
# attributes accessible.
|
7
|
-
#
|
8
|
-
# Also includes a hook called remove_association_error, that removes the nested
|
9
|
-
# attribute errors from the parent object.
|
10
|
-
#
|
11
|
-
# Finally, if the *_id in the table has also *_type. It considers a polymorphic
|
12
|
-
# association.
|
13
|
-
#
|
14
|
-
# Whenever using this method with polymorphic association, don't forget to
|
15
|
-
# set the validation scope in AuthLogic.
|
16
|
-
#
|
17
|
-
# a.validations_scope = :accountable_type
|
18
|
-
#
|
19
|
-
module Associatable
|
20
|
-
def self.included(base)
|
21
|
-
column = base.columns.detect{|c| c.name =~ /_id$/ }
|
22
|
-
raise ScriptError, "Could not find a column that ends with id in #{base.name.tableize}" unless column
|
23
|
-
|
24
|
-
association = column.name.gsub(/_id$/, '').to_sym
|
25
|
-
polymorphic = !!base.columns.detect{ |c| c.name == "#{association}_type" }
|
26
|
-
|
27
|
-
base.class_eval do
|
28
|
-
belongs_to association, :validate => true, :dependent => :destroy,
|
29
|
-
:autosave => true, :polymorphic => polymorphic
|
30
|
-
|
31
|
-
accepts_nested_attributes_for association
|
32
|
-
attr_accessible :"#{association}_attributes"
|
33
|
-
|
34
|
-
after_validation :remove_association_error
|
35
|
-
end
|
36
|
-
|
37
|
-
base.class_eval <<-ASSOCIATION
|
38
|
-
# Remove association errors from the message
|
39
|
-
#
|
40
|
-
def remove_association_error
|
41
|
-
self.errors.each do |key, value|
|
42
|
-
next unless key.to_s =~ /^#{association}_/
|
43
|
-
self.errors.instance_variable_get('@errors').delete(key)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
protected :remove_association_error
|
47
|
-
ASSOCIATION
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module AuthHelpers
|
2
|
-
module Spec
|
3
|
-
|
4
|
-
module Associatable
|
5
|
-
def self.included(base)
|
6
|
-
klass = base.described_class
|
7
|
-
|
8
|
-
column = klass.columns.detect{|c| c.name =~ /_id$/ }
|
9
|
-
raise ScriptError, "Could not find a column that ends with id in #{base.name.tableize}" unless column
|
10
|
-
|
11
|
-
association = column.name.gsub(/_id$/, '').to_sym
|
12
|
-
polymorphic = !!klass.columns.detect{ |c| c.name == "#{association}_type" }
|
13
|
-
|
14
|
-
base.class_eval do
|
15
|
-
it "should validate associated #{association}" do
|
16
|
-
associatable = base.described_class.create(@valid_attributes.merge(:"#{association}_attributes" => {}))
|
17
|
-
associatable.should_not be_valid
|
18
|
-
|
19
|
-
unless associatable.send(association).errors.empty?
|
20
|
-
associatable.errors.should be_empty # this should be blank since errors is
|
21
|
-
# on the associated object.
|
22
|
-
|
23
|
-
associatable.send(association).errors.should_not be_empty
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|