remarkable_devise 1.0.0.alpha3 → 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 (28) hide show
  1. data/README.markdown +70 -7
  2. data/lib/remarkable/devise/matchers/base_matcher.rb +17 -0
  3. data/lib/remarkable/devise/matchers/be_a_confirmable_matcher.rb +7 -3
  4. data/lib/remarkable/devise/matchers/be_a_database_authenticatable_matcher.rb +11 -4
  5. data/lib/remarkable/devise/matchers/be_a_lockable_matcher.rb +34 -0
  6. data/lib/remarkable/devise/matchers/be_a_registerable_matcher.rb +19 -0
  7. data/lib/remarkable/devise/matchers/be_a_rememberable_matcher.rb +7 -3
  8. data/lib/remarkable/devise/matchers/be_a_timeoutable_matcher.rb +23 -0
  9. data/lib/remarkable/devise/matchers/be_a_token_authenticatable_matcher.rb +7 -3
  10. data/lib/remarkable/devise/matchers/be_a_validatable_matcher.rb +7 -3
  11. data/lib/remarkable/devise/matchers/be_an_authenticatable_matcher.rb +19 -0
  12. data/lib/remarkable/devise/version.rb +1 -1
  13. data/locale/en.yml +70 -0
  14. data/remarkable_devise.gemspec +1 -1
  15. data/spec/example_models.rb +10 -2
  16. data/spec/examples/user_spec.rb +24 -0
  17. data/spec/matchers/be_a_confirmable_spec.rb +32 -4
  18. data/spec/matchers/be_a_database_authenticatable_spec.rb +55 -5
  19. data/spec/matchers/be_a_lockable_spec.rb +274 -0
  20. data/spec/matchers/be_a_registerable_spec.rb +27 -0
  21. data/spec/matchers/be_a_rememberable_spec.rb +81 -1
  22. data/spec/matchers/be_a_timeoutable_spec.rb +59 -0
  23. data/spec/matchers/be_a_token_authenticatable_spec.rb +33 -1
  24. data/spec/matchers/be_a_validatable_spec.rb +58 -5
  25. data/spec/matchers_spec.rb +23 -5
  26. data/spec/shared_examples.rb +122 -0
  27. data/spec/spec_helper.rb +13 -4
  28. metadata +23 -12
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Remarkable::Devise::Matchers::BeARegisterableMatcher do
4
+ describe "validate inclusion of Devise::Models::Registerable module" do
5
+ it "should validate that a model has Devise::Models::Registerable included" do
6
+ subject.matches?(User).should be_true
7
+ end
8
+
9
+ it "should validate that a model hasn't Devise::Models::Registerable included" do
10
+ subject.matches?(FooUser).should be_false
11
+ end
12
+ end
13
+
14
+ describe "description" do
15
+ specify { subject.description.should eql("be a registerable") }
16
+ end
17
+
18
+ describe "failure message" do
19
+ context "when a model hasn't Devise::Models::Registerable module included" do
20
+ before do
21
+ subject.matches?(FooUser)
22
+ end
23
+
24
+ specify { subject.failure_message_for_should.should match("Foo user to have Devise :registerable model") }
25
+ end
26
+ end
27
+ end
@@ -17,6 +17,38 @@ describe Remarkable::Devise::Matchers::BeARememberableMatcher do
17
17
  end
18
18
  end
19
19
 
20
+ context "options validation" do
21
+ describe :remember_for do
22
+ it "should validate that a model has proper :remember_for option" do
23
+ subject.class.new(:remember_for => 2.weeks).matches?(User).should be_true
24
+ end
25
+
26
+ it "should validate that a model hasn't proper :remember_for option" do
27
+ subject.class.new(:remember_for => 1.month).matches?(User).should be_false
28
+ end
29
+ end
30
+
31
+ describe :extend_remember_period do
32
+ it "should validate that a model is configured with proper :remember_across_browsers option" do
33
+ subject.class.new(:extend_remember_period => true).matches?(User).should be_true
34
+ end
35
+
36
+ it "should validate that a model isn't configured with proper :remember_across_browsers option" do
37
+ subject.class.new(:extend_remember_period => false).matches?(User).should be_false
38
+ end
39
+ end
40
+
41
+ describe :cookie_domain do
42
+ it "should validate that a model is configured with proper :cookie_domain option" do
43
+ subject.class.new(:cookie_domain => 'foo').matches?(User).should be_true
44
+ end
45
+
46
+ it "should validate that a model isn't configured with proper :cookie_domain option" do
47
+ subject.class.new(:cookie_domain => 'bar').matches?(User).should be_false
48
+ end
49
+ end
50
+ end
51
+
20
52
  context "columns validation" do
21
53
  before do
22
54
  subject.stubs(:included?).returns(true)
@@ -52,7 +84,47 @@ describe Remarkable::Devise::Matchers::BeARememberableMatcher do
52
84
  end
53
85
 
54
86
  describe "description" do
55
- specify { subject.description.should eql('be a rememberable') }
87
+ context "when matching without options" do
88
+ specify { subject.description.should eql('be a rememberable') }
89
+ end
90
+
91
+ context "when matching with :remember_for option" do
92
+ before do
93
+ @matcher = subject.class.new(:remember_for => 2.weeks)
94
+ @matcher.matches?(User)
95
+ end
96
+
97
+ specify { @matcher.description.should eql('be a rememberable with 14 days remember period') }
98
+ end
99
+
100
+ context "when matching with :extend_remember_period" do
101
+ context "positive" do
102
+ before do
103
+ @matcher = subject.class.new(:extend_remember_period => true)
104
+ @matcher.matches?(User)
105
+ end
106
+
107
+ specify { @matcher.description.should eql('be a rememberable with extendable remember period') }
108
+ end
109
+
110
+ context "negative" do
111
+ before do
112
+ @matcher = subject.class.new(:extend_remember_period => false)
113
+ @matcher.matches?(User)
114
+ end
115
+
116
+ specify { @matcher.description.should eql('be a rememberable without extandable remember period') }
117
+ end
118
+ end
119
+
120
+ context "when matching with :cookie_domain option" do
121
+ before do
122
+ @matcher = subject.class.new(:cookie_domain => 'foo')
123
+ @matcher.matches?(User)
124
+ end
125
+
126
+ specify { @matcher.description.should eql('be a rememberable with "foo" cookie domain') }
127
+ end
56
128
  end
57
129
 
58
130
  describe "expectation message" do
@@ -83,5 +155,13 @@ describe Remarkable::Devise::Matchers::BeARememberableMatcher do
83
155
  specify { subject.failure_message_for_should.should match('to have remember_created_at column') }
84
156
  end
85
157
 
158
+ context "when a model doesn't match given options" do
159
+ before do
160
+ @matcher = subject.class.new(:remember_for => 2.weeks, :cookie_domain => 'bar')
161
+ @matcher.matches?(User)
162
+ end
163
+
164
+ specify { @matcher.failure_message_for_should.should match('User to be rememberable with options (.+), got (.+)') }
165
+ end
86
166
  end
87
167
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers::BeATimeoutableMatcher do
4
+ describe "validate inclusion of Devise::Models::Timeoutable" do
5
+ it "should validate that model is include Devise::Models::Timeoutable module" do
6
+ subject.matches?(User).should be_true
7
+ end
8
+
9
+ it "should validate that model isn't include Devise::Models::Timeoutable module" do
10
+ subject.matches?(FooUser).should be_false
11
+ end
12
+ end
13
+
14
+ describe "options validation" do
15
+ describe :timeout_in do
16
+ it "should validate that model is timeoutable with proper :timeout_in option" do
17
+ subject.class.new(:timeout_in => 15.minutes).matches?(User).should be_true
18
+ end
19
+
20
+ it "should validate that model is timeoutable without proper :timeout_in option" do
21
+ subject.class.new(:timeout_in => 5.minutes).matches?(User).should be_false
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "description" do
27
+ context "when matching without options" do
28
+ specify { subject.description.should eql("be a timeoutable") }
29
+ end
30
+
31
+ context "when matching with :timeout_in option" do
32
+ before do
33
+ @matcher = subject.class.new(:timeout_in => 15.minutes)
34
+ @matcher.matches?(User)
35
+ end
36
+
37
+ specify { @matcher.description.should eql("be a timeoutable within 900 seconds") }
38
+ end
39
+ end
40
+
41
+ describe "expectation message" do
42
+ context "when model hasn't Devise::Models::Timeoutable module included" do
43
+ before do
44
+ subject.matches?(FooUser)
45
+ end
46
+
47
+ specify { subject.failure_message_for_should.should match("Foo user to include Devise :timeoutable model") }
48
+ end
49
+
50
+ context "when model doesn't match options" do
51
+ before do
52
+ @matcher = subject.class.new(:timeout_in => 5.minutes)
53
+ @matcher.matches?(User)
54
+ end
55
+
56
+ specify { @matcher.failure_message_for_should.should match("User to be a timeoutable with options (.+), got (.+)") }
57
+ end
58
+ end
59
+ end
@@ -17,6 +17,18 @@ describe Remarkable::Devise::Matchers::BeATokenAuthenticatableMatcher do
17
17
  end
18
18
  end
19
19
 
20
+ describe "options validation" do
21
+ describe :token_authentication_key do
22
+ it "should validate that model is configured with proper :token_authentication_key option" do
23
+ subject.class.new(:token_authentication_key => :auth_token).matches?(User).should be_true
24
+ end
25
+
26
+ it "should validate that model isn't configured with proper :token_authentication_key option" do
27
+ subject.class.new(:token_authentication_key => :authen_foo_key).matches?(User).should be_false
28
+ end
29
+ end
30
+ end
31
+
20
32
  context "columns validation" do
21
33
  before do
22
34
  subject.stubs(:included?).returns(true)
@@ -36,7 +48,18 @@ describe Remarkable::Devise::Matchers::BeATokenAuthenticatableMatcher do
36
48
  end
37
49
 
38
50
  describe "description" do
39
- specify { subject.description.should eql('be a token authenticatable') }
51
+ context "when matching without options" do
52
+ specify { subject.description.should eql('be a token authenticatable') }
53
+ end
54
+
55
+ context "when matching with :token_authentication_key option" do
56
+ before do
57
+ @matcher = subject.class.new(:token_authentication_key => :auth_token)
58
+ @matcher.matches?(User)
59
+ end
60
+
61
+ specify { @matcher.description.should eql("be a token authenticatable with :auth_token as token authentication key") }
62
+ end
40
63
  end
41
64
 
42
65
  describe "expectation message" do
@@ -56,5 +79,14 @@ describe Remarkable::Devise::Matchers::BeATokenAuthenticatableMatcher do
56
79
 
57
80
  specify { subject.failure_message_for_should.should match("to have authentication_token column") }
58
81
  end
82
+
83
+ context "when options doesn't match" do
84
+ before do
85
+ @matcher = subject.class.new(:token_authentication_key => :auth_foo_key)
86
+ @matcher.matches?(User)
87
+ end
88
+
89
+ specify { @matcher.failure_message_for_should.should match("User to be a token authenticatable with options (.+), got (.+)") }
90
+ end
59
91
  end
60
92
  end
@@ -11,15 +11,68 @@ describe Remarkable::Devise::Matchers::BeAValidatableMatcher do
11
11
  end
12
12
  end
13
13
 
14
+ context "options matching" do
15
+ describe :password_length do
16
+ it "should validate that model is configured with proper :password_length option" do
17
+ subject.class.new(:password_length => 8..20).matches?(User).should be_true
18
+ end
19
+
20
+ it "should validate that model isn't configured with proper :password_length option" do
21
+ subject.class.new(:password_length => 4..10).matches?(User).should be_false
22
+ end
23
+ end
24
+
25
+ describe :email_regexp do
26
+ it "should validate that model is configured with proper :email_regexp option" do
27
+ subject.class.new(:email_regexp => /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i).matches?(User).should be_true
28
+ end
29
+
30
+ it "should validate that model isn't configured with proper :email_regexp option" do
31
+ subject.class.new(:email_regexp => /^(.+)@(.+)$/).matches?(User).should be_false
32
+ end
33
+ end
34
+ end
35
+
14
36
  context "description" do
15
- specify { subject.description.should eql('be a validatable') }
37
+ context "when matching without options" do
38
+ specify { subject.description.should eql('be a validatable') }
39
+ end
40
+
41
+ context "when matching with :password_length option" do
42
+ before do
43
+ @matcher = subject.class.new(:password_length => 8..20)
44
+ @matcher.matches?(User)
45
+ end
46
+
47
+ specify { @matcher.description.should eql("be a validatable with password length 8..20") }
48
+ end
49
+
50
+ context "when matching with :email_regexp option" do
51
+ before do
52
+ @matcher = subject.class.new(:email_regexp => /^(.+)@(.+)$/i)
53
+ @matcher.matches?(User)
54
+ end
55
+
56
+ specify { @matcher.description.should eql("be a validatable with email regexp /^(.+)@(.+)$/i") }
57
+ end
16
58
  end
17
59
 
18
- context "expectation message" do
19
- before do
20
- subject.matches?(FooUser)
60
+ describe "expectation message" do
61
+ context "when Devise::Models::Validatable is not included" do
62
+ before do
63
+ subject.matches?(FooUser)
64
+ end
65
+
66
+ specify { subject.failure_message_for_should.should match('Foo user to include Devise :validatable model')}
21
67
  end
22
68
 
23
- specify { subject.failure_message_for_should.should match('to include Devise :validatable model')}
69
+ context "when options doesn't match" do
70
+ before do
71
+ @matcher = subject.class.new(:password_length => 4..18)
72
+ @matcher.matches?(User)
73
+ end
74
+
75
+ specify { @matcher.failure_message_for_should.should match('User to be a validatable with options (.+), got (.+)') }
76
+ end
24
77
  end
25
78
  end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  describe Remarkable::Devise::Matchers do
4
4
  describe "#be_a_database_authenticatable" do
5
5
  it "should return Remarkable::Devise::Matchers::BeADatabaseAuthenticatableMatcher" do
6
- be_a_database_authenticatable.should be_an_instance_of(Remarkable::Devise::Matchers::BeADatabaseAuthenticatableMatcher)
6
+ be_a_database_authenticatable(:stretches => 10).should be_an_instance_of(Remarkable::Devise::Matchers::BeADatabaseAuthenticatableMatcher)
7
7
  end
8
8
  end
9
9
 
10
10
  describe "#be_a_confirmable" do
11
11
  it "should return Remarkable::Devise::Matchers::BeAConfirmableMatcher" do
12
- be_a_confirmable.should be_an_instance_of(Remarkable::Devise::Matchers::BeAConfirmableMatcher)
12
+ be_a_confirmable(:confirm_within => 2.days).should be_an_instance_of(Remarkable::Devise::Matchers::BeAConfirmableMatcher)
13
13
  end
14
14
  end
15
15
 
@@ -21,7 +21,7 @@ describe Remarkable::Devise::Matchers do
21
21
 
22
22
  describe "#be_a_rememberable" do
23
23
  it "should return Remarkable::Devise::Matchers::BeARememberableMatcher" do
24
- be_a_rememberable.should be_an_instance_of(Remarkable::Devise::Matchers::BeARememberableMatcher)
24
+ be_a_rememberable(:remember_for => 2.weeks).should be_an_instance_of(Remarkable::Devise::Matchers::BeARememberableMatcher)
25
25
  end
26
26
  end
27
27
 
@@ -33,13 +33,31 @@ describe Remarkable::Devise::Matchers do
33
33
 
34
34
  describe "#be_a_validatable" do
35
35
  it "should return Remarkable::Devise::Matchers::BeAValidatableMatcher" do
36
- be_a_validatable.should be_an_instance_of(Remarkable::Devise::Matchers::BeAValidatableMatcher)
36
+ be_a_validatable(:password_length => 8..20).should be_an_instance_of(Remarkable::Devise::Matchers::BeAValidatableMatcher)
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#be_a_token_authenticatable" do
41
41
  it "should return Remarkable::Devise::Matchers::BeATokenAuthenticatableMatcher" do
42
- be_a_token_authenticatable.should be_an_instance_of(Remarkable::Devise::Matchers::BeATokenAuthenticatableMatcher)
42
+ be_a_token_authenticatable(:token_authentication_key => :auth_token).should be_an_instance_of(Remarkable::Devise::Matchers::BeATokenAuthenticatableMatcher)
43
+ end
44
+ end
45
+
46
+ describe "#be_a_timeoutable" do
47
+ it "should return Remarkable::Devise::Matchers::BeATimeoutableMatcher" do
48
+ be_a_timeoutable(:timeout_in => 5.minutes).should be_an_instance_of(Remarkable::Devise::Matchers::BeATimeoutableMatcher)
49
+ end
50
+ end
51
+
52
+ describe "#be_a_lockable" do
53
+ it "should return Remarkable::Devise::Matchers::BeALockableMatcher" do
54
+ be_a_lockable(:maximum_attempts => 10).should be_an_instance_of(Remarkable::Devise::Matchers::BeALockableMatcher)
55
+ end
56
+ end
57
+
58
+ describe "#be_a_registerable" do
59
+ it "should return Remarkable::Devise::Matchers::BeARegisterableMatcher" do
60
+ be_a_registerable.should be_an_instance_of(Remarkable::Devise::Matchers::BeARegisterableMatcher)
43
61
  end
44
62
  end
45
63
  end
@@ -0,0 +1,122 @@
1
+ shared_examples_for "lockable matcher for unlock_strategy with unlock_token column needed" do
2
+ context "when a model has :unlock_token column" do
3
+ it "should match" do
4
+ subject.matches?(User).should be_true
5
+ end
6
+ end
7
+
8
+ context "when a model has no :unlock_token column" do
9
+ before do
10
+ User.stubs(:column_names).returns(@valid_columns - ['unlock_token'])
11
+ end
12
+
13
+ it "should not match" do
14
+ subject.matches?(User).should be_false
15
+ end
16
+ end
17
+ end
18
+
19
+ shared_examples_for "lockable matcher for unlock_strategy without unlock_token column needed" do
20
+ context "when a model has :unlock_token column" do
21
+ it "should match" do
22
+ subject.matches?(User).should be_true
23
+ end
24
+ end
25
+
26
+ context "when a model has no :unlock_token column" do
27
+ before do
28
+ User.stubs(:column_names).returns(@valid_columns - ['unlock_token'])
29
+ end
30
+
31
+ it "should match" do
32
+ subject.matches?(User).should be_true
33
+ end
34
+ end
35
+ end
36
+
37
+ shared_examples_for "any Devise authentication model" do
38
+ describe "validation of Devise::Models::Authenticatable module inclusion" do
39
+ context "when a model has module included" do
40
+ it "should match" do
41
+ subject.matches?(User).should be_true
42
+ end
43
+ end
44
+
45
+ context "when a model hasn't module included" do
46
+ it "should not match" do
47
+ subject.matches?(FooUser).should be_false
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "options validation" do
53
+ describe :authentication_keys do
54
+ context "when a model has expected :authentication_keys value" do
55
+ it "should match" do
56
+ subject.class.new(:authentication_keys => [:email, :login]).matches?(User).should be_true
57
+ end
58
+ end
59
+
60
+ context "when a model hasn't expected :authentication_keys value" do
61
+ it "should not match" do
62
+ subject.class.new(:authentication_keys => [:login]).matches?(User).should be_false
63
+ end
64
+ end
65
+ end
66
+
67
+ describe :params_authenticatable do
68
+ context "when a model has expected :params_authenticatable value" do
69
+ it "should match" do
70
+ subject.class.new(:params_authenticatable => false).matches?(User).should be_true
71
+ end
72
+ end
73
+
74
+ context "when a model hasn't expected :params_authenticatable value" do
75
+ it "should not match" do
76
+ subject.class.new(:params_authenticatable => true).matches?(User).should be_false
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "description" do
83
+ context "when matching with :authentication_keys option" do
84
+ before do
85
+ @matcher = subject.class.new(:authentication_keys => [:email, :login])
86
+ @matcher.matches?(User)
87
+ end
88
+
89
+ specify { @matcher.description.should match(/with \[\:email, \:login\] as authentication keys/) }
90
+ end
91
+
92
+ context "when matching with :params_authenticatable option" do
93
+ context "positive" do
94
+ before do
95
+ @matcher = subject.class.new(:params_authenticatable => true)
96
+ @matcher.matches?(User)
97
+ end
98
+
99
+ specify { @matcher.description.should match(/with params authenticatable/) }
100
+ end
101
+
102
+ context "negative" do
103
+ before do
104
+ @matcher = subject.class.new(:params_authenticatable => false)
105
+ @matcher.matches?(User)
106
+ end
107
+
108
+ specify { @matcher.description.should match(/without params authenticatable/) }
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "failure message" do
114
+ context "when Devise::Models::Authenticatable module isn't included" do
115
+ before do
116
+ subject.matches?(FooUser)
117
+ end
118
+
119
+ specify { subject.failure_message_for_should.should match("Foo user to have Devise :authenticatable model") }
120
+ end
121
+ end
122
+ end