remarkable_devise 1.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .bundle
3
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rake"
4
+ gem "mocha"
5
+ gem "rspec", ">=2.1.0"
6
+ gem "rails", ">=3.0.1"
7
+ gem "activerecord", ">=3.0.1"
8
+ gem "remarkable_activerecord", ">=4.0.0.alpha4"
9
+ gem "devise", ">=1.1.3"
data/License.txt ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2010 Vasily Reys
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,32 @@
1
+ # Remarkable Devise
2
+
3
+ Remarkable Devise is a collection of RSpec matchers for [Devise](http://github.com/plataformatec/devise).
4
+
5
+ ## Install
6
+
7
+ Add to your Gemfile:
8
+
9
+ gem "remarkable_activerecord"
10
+ gem "remarkable_devise"
11
+
12
+ Add the require after the remarkable/active_record line in your spec_heplers.rb:
13
+
14
+ require 'remarkable/active_record'
15
+ require 'remarkable/devise'
16
+
17
+ ## Usage
18
+
19
+ # spec/models/user_spec.rb
20
+ describe User do
21
+ should_be_a_database_authenticatable
22
+ should_be_a_confirmable
23
+ should_be_a_recoverable
24
+ should_be_a_rememberable
25
+ should_be_a_trackable
26
+ end
27
+
28
+ ## See alse
29
+
30
+ * [http://github.com/remarkable/remarkable](http://github.com/remarkable/remarkable)
31
+ * [http://github.com/plataformatec/devise](http://github.com/plataformatec/devise)
32
+ * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require "rspec/core/rake_task"
3
+
4
+ desc 'Default: run RSpec examples'
5
+ task :default => :spec
6
+
7
+ desc "Run all examples"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_path = '/usr/bin/rspec'
10
+ end
@@ -0,0 +1,21 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Matchers
4
+ class Base < Remarkable::ActiveRecord::Base
5
+ protected
6
+
7
+ def has_column?(column_name)
8
+ subject_class.column_names.include?(column_name)
9
+ end
10
+
11
+ def method_missing(m, *args)
12
+ if m.to_s.match(/has_(.+)_column?/)
13
+ return has_column?($1)
14
+ end
15
+
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Matchers
4
+ class BeAConfirmableMatcher < Base
5
+ assertion :included?, :has_confirmation_token_column?, :has_confirmed_at_column?,
6
+ :has_confirmation_sent_at_column?
7
+
8
+ protected
9
+
10
+ def included?
11
+ subject_class.ancestors.include?(::Devise::Models::Confirmable)
12
+ end
13
+ end
14
+
15
+ def be_a_confirmable
16
+ BeAConfirmableMatcher.new
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Matchers
4
+ class BeADatabaseAuthenticatableMatcher < Base
5
+ assertion :included?, :has_email_column?, :has_encrypted_password_column?, :has_password_salt_column?
6
+
7
+ protected
8
+
9
+ def included?
10
+ subject_class.ancestors.include?(::Devise::Models::DatabaseAuthenticatable)
11
+ end
12
+ end
13
+
14
+ def be_a_database_authenticatable
15
+ BeADatabaseAuthenticatableMatcher.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Matchers
4
+ class BeARecoverableMatcher < Base
5
+ assertions :included?, :has_reset_password_token_column?
6
+
7
+ protected
8
+
9
+ def included?
10
+ subject_class.ancestors.include?(::Devise::Models::Recoverable)
11
+ end
12
+ end
13
+
14
+ def be_a_recoverable
15
+ BeARecoverableMatcher.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Matchers
4
+ class BeARememberableMatcher < Base
5
+ assertions :included?, :has_remember_token_column?, :has_remember_created_at_column?
6
+
7
+ protected
8
+
9
+ def included?
10
+ subject_class.include?(::Devise::Models::Rememberable)
11
+ end
12
+ end
13
+
14
+ def be_a_rememberable
15
+ BeARememberableMatcher.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Matchers
4
+ class BeATrackableMatcher < Base
5
+ assertions :included?, :has_sign_in_count_column?, :has_current_sign_in_at_column?,
6
+ :has_last_sign_in_at_column?, :has_current_sign_in_ip_column?, :has_last_sign_in_ip_column?
7
+
8
+ protected
9
+
10
+ def included?
11
+ subject_class.ancestors.include?(::Devise::Models::Trackable)
12
+ end
13
+ end
14
+
15
+ def be_a_trackable
16
+ BeATrackableMatcher.new
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Remarkable
2
+ module Devise
3
+ module Version
4
+ STRING = '1.0.0.alpha2'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ # Load rails and AR
2
+ require 'rails'
3
+ require 'active_record'
4
+
5
+ # Load remarkable
6
+ require 'remarkable/core'
7
+ require 'remarkable/active_record'
8
+
9
+ # Load devise
10
+ require 'devise'
11
+ require 'devise/orm/active_record'
12
+
13
+ dir = File.dirname(__FILE__)
14
+
15
+ # Add default locale
16
+ Dir["#{dir}/../../locale/*yml"].each {|f| Remarkable.add_locale(f) }
17
+
18
+ # Add matchers
19
+ require(File.join(dir, 'devise', 'matchers', 'base_matcher.rb'))
20
+
21
+ Dir[File.join(dir, 'devise', 'matchers', '*.rb')].each do |file|
22
+ require file
23
+ end
24
+
25
+ Remarkable.include_matchers!(Remarkable::Devise, RSpec::Core::ExampleGroup)
data/locale/en.yml ADDED
@@ -0,0 +1,41 @@
1
+ en:
2
+ remarkable:
3
+ devise:
4
+ be_a_database_authenticatable:
5
+ description: "be a database authenticatable"
6
+ expectations:
7
+ included: "%{subject_name} to include Devise :database_authenticatable model"
8
+ has_email_column: "%{subject_name} to have email column"
9
+ has_encrypted_password_column: "%{subject_name} to have encrypted_password column"
10
+ has_password_salt_column: "%{subject_name} to have password_salt column"
11
+
12
+ be_a_confirmable:
13
+ description: "be a confirmable"
14
+ expectations:
15
+ included: "%{subject_name} to include Devise :confirmable model"
16
+ has_confirmation_token_column: "%{subject_name} to have confirmation_token column"
17
+ has_confirmed_at_column: "%{subject_name} to have confirmed_at column"
18
+ has_confirmation_sent_at_column: "%{subject_name} to have confirmation_sent_at column"
19
+
20
+ be_a_recoverable:
21
+ description: "be a recoverable"
22
+ expectations:
23
+ included: "%{subject_name} to include Devise :recoverable model"
24
+ has_reset_password_token_column: "%{subject_name} to have reset_password_token column"
25
+
26
+ be_a_rememberable:
27
+ description: "be a rememberable"
28
+ expectations:
29
+ included: "%{subject_name} to include Devise :rememberable model"
30
+ has_remember_token_column: "%{subject_name} to have remember_token column"
31
+ has_remember_created_at_column: "%{subject_name} to have remember_created_at column"
32
+
33
+ be_a_trackable:
34
+ description: "be a trackable"
35
+ expectations:
36
+ included: "%{subject_name} to include Devise :trackable model"
37
+ has_sign_in_count_column: "%{subject_name} to have sign_in_count column"
38
+ has_current_sign_in_at_column: "%{subject_name} to have current_sign_in_at column"
39
+ has_last_sign_in_at_column: "%{subject_name} to have last_sign_in_at column"
40
+ has_current_sign_in_ip_column: "%{subject_name} to have current_sign_in_ip column"
41
+ has_last_sign_in_ip_column: "%{subject_name} to have last_sign_in_ip column"
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require "remarkable/devise/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "remarkable_devise"
6
+ s.version = Remarkable::Devise::Version::STRING
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Vasily Reys"]
9
+ s.email = "reys.vasily@gmail.com"
10
+ s.homepage = "http://github.com/vreys/remarkable_devise"
11
+ s.summary = "remarkable_devise_#{Remarkable::Devise::Version}"
12
+ s.description = "Devise remarkable rspec matchers"
13
+
14
+ s.rubygems_version = "1.3.7"
15
+ s.rubyforge_project = "remarkbl-devise"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.require_path = "lib"
20
+
21
+ s.add_runtime_dependency(%q<rspec>, [">=2.1.0"])
22
+ s.add_runtime_dependency(%q<rails>, [">=3.0.1"])
23
+ s.add_runtime_dependency(%q<activerecord>, [">=3.0.1"])
24
+ s.add_runtime_dependency(%q<remarkable_activerecord>, ["4.0.0.alpha4"])
25
+ s.add_runtime_dependency(%q<devise>, [">=1.1.3"])
26
+
27
+ s.add_development_dependency "mocha"
28
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+ devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable
3
+ end
4
+
5
+ class FooUser < ActiveRecord::Base
6
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers::BeAConfirmableMatcher do
4
+ before do
5
+ @valid_columns = ['confirmation_token', 'confirmed_at', 'confirmation_sent_at']
6
+
7
+ User.stubs(:column_names).returns(@valid_columns)
8
+ end
9
+
10
+ context "inclusion of Devise::Models::Confirmable" do
11
+ it "should validate that model has :confirmable Devise model included" do
12
+ subject.matches?(User).should be_true
13
+ end
14
+
15
+ it "should valodate that model has not :confirmable Devise model included" do
16
+ subject.matches?(FooUser).should be_false
17
+ end
18
+ end
19
+
20
+ context "columns validation" do
21
+ context "confirmation_token column" do
22
+ before do
23
+ subject.stubs(:has_confirmed_at_column?).returns(true)
24
+ subject.stubs(:has_confirmation_sent_at_column?).returns(true)
25
+ end
26
+
27
+ it "should validate that model has confirmation_token column" do
28
+ subject.matches?(User).should be_true
29
+ end
30
+
31
+ it "should validate that model has no confirmaion_token column" do
32
+ User.stubs(:column_names).returns(@valid_columns - ['confirmation_token'])
33
+
34
+ subject.matches?(User).should be_false
35
+ end
36
+ end
37
+
38
+ context "confirmed_at column" do
39
+ before do
40
+ subject.stubs(:has_confirmation_token_column?).returns(true)
41
+ subject.stubs(:has_confirmation_sent_at_column?).returns(true)
42
+ end
43
+
44
+ it "should validate that model has confirmed_at column" do
45
+ subject.matches?(User).should be_true
46
+ end
47
+
48
+ it "should validate that model has no confirmed_at column" do
49
+ User.stubs(:column_names).returns(@valid_columns - ['confirmed_at'])
50
+
51
+ subject.matches?(User).should be_false
52
+ end
53
+ end
54
+
55
+ context "confirmation_sent_at" do
56
+ before do
57
+ subject.stubs(:has_confirmation_token_column?).returns(true)
58
+ subject.stubs(:has_confirmed_at_column?).returns(true)
59
+ end
60
+
61
+ it "should validate that model has confirmation_sent_at column" do
62
+ subject.matches?(User).should be_true
63
+ end
64
+
65
+ it "should validate that model has no confirmation_sent_at column" do
66
+ User.stubs(:column_names).returns(@valid_columns - ['confirmation_sent_at'])
67
+
68
+ subject.matches?(User).should be_false
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "description" do
74
+ before do
75
+ @msg = subject.description
76
+ end
77
+
78
+ specify { @msg.should eql('be a confirmable') }
79
+ end
80
+
81
+ context "expectation message" do
82
+ context "when Devise::Models::Confirmable not included" do
83
+ before do
84
+ subject.matches?(FooUser)
85
+
86
+ @msg = subject.failure_message_for_should
87
+ end
88
+
89
+ specify { @msg.should match('to include Devise :confirmable model') }
90
+ end
91
+
92
+ context "when model has no confirmation_token column" do
93
+ before do
94
+ subject.stubs(:has_confirmation_token_column?).returns(false)
95
+ subject.matches?(User)
96
+
97
+ @msg = subject.failure_message_for_should
98
+ end
99
+
100
+ specify { @msg.should match('to have confirmation_token column') }
101
+ end
102
+
103
+ context "when model has no confirmed_at column" do
104
+ before do
105
+ subject.stubs(:has_confirmed_at_column?).returns(false)
106
+ subject.matches?(User)
107
+
108
+ @msg = subject.failure_message_for_should
109
+ end
110
+
111
+ specify { @msg.should match('to have confirmed_at column') }
112
+ end
113
+
114
+ context "when model has no confirmation_sent_at column" do
115
+ before do
116
+ subject.stubs(:has_confirmation_sent_at_column?).returns(false)
117
+ subject.matches?(User)
118
+
119
+ @msg = subject.failure_message_for_should
120
+ end
121
+
122
+ specify { @msg.should match('to have confirmation_sent_at column') }
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers::BeADatabaseAuthenticatableMatcher do
4
+ before do
5
+ @valid_columns = ['email', 'encrypted_password', 'password_salt']
6
+
7
+ User.stubs(:column_names).returns(@valid_columns)
8
+ end
9
+
10
+ context "inclusion of Devise::Models::DatabaseAuthenticatable" do
11
+ it "should validate that model has Devise :database_authenticatable model" do
12
+ subject.matches?(User).should be_true
13
+ end
14
+
15
+ it "should validate that model has no :database_authenticatable model" do
16
+ subject.matches?(FooUser).should be_false
17
+ end
18
+ end
19
+
20
+ context "columns validation" do
21
+ context "email column" do
22
+ before do
23
+ subject.stubs(:has_encrypted_password_column?).returns(true)
24
+ subject.stubs(:has_password_salt_column?).returns(true)
25
+ end
26
+
27
+ it "should validate that model has email column" do
28
+ subject.matches?(User).should be_true
29
+ end
30
+
31
+ it "should validate that model has no email column" do
32
+ User.stubs(:column_names).returns(@valid_columns - ['email'])
33
+
34
+ subject.matches?(User).should be_false
35
+ end
36
+ end
37
+
38
+ context "encrypted_password column" do
39
+ before do
40
+ subject.stubs(:has_email_column?).returns(true)
41
+ subject.stubs(:has_password_salt_column?).returns(true)
42
+ end
43
+
44
+ it "should validate that model has encrypted_password column" do
45
+ subject.matches?(User).should be_true
46
+ end
47
+
48
+ it "should validate that model has no encrypted_password column" do
49
+ User.stubs(:column_names).returns(@valid_columns - ['encrypted_password'])
50
+
51
+ subject.matches?(User).should be_false
52
+ end
53
+ end
54
+
55
+ context "password_salt column" do
56
+ before do
57
+ subject.stubs(:has_email_column?).returns(true)
58
+ subject.stubs(:has_encrypted_password_column?).returns(true)
59
+ end
60
+
61
+ it "should validate that model has password_salt column" do
62
+ subject.matches?(User).should be_true
63
+ end
64
+
65
+ it "should validate that model has no password_salt column" do
66
+ User.stubs(:column_names).returns(@valid_columns - ['password_salt'])
67
+
68
+ subject.matches?(User).should be_false
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "description" do
74
+ before do
75
+ @msg = subject.description
76
+ end
77
+
78
+ specify { @msg.should eql('be a database authenticatable') }
79
+ end
80
+
81
+ context "expectation message" do
82
+ context "when Devise::Models::DatabaseAuthenticatable not included" do
83
+ before do
84
+ subject.matches?(FooUser)
85
+
86
+ @msg = subject.failure_message_for_should
87
+ end
88
+
89
+ specify { @msg.should match('to include Devise :database_authenticatable model') }
90
+ end
91
+
92
+ context "when model has no email column" do
93
+ before do
94
+ subject.stubs(:has_email_column?).returns(false)
95
+ subject.matches?(User)
96
+
97
+ @msg = subject.failure_message_for_should
98
+ end
99
+
100
+ specify { @msg.should match('to have email column') }
101
+ end
102
+
103
+ context "when model has no encrypted_password column" do
104
+ before do
105
+ subject.stubs(:has_encrypted_password_column?).returns(false)
106
+ subject.matches?(User)
107
+
108
+ @msg = subject.failure_message_for_should
109
+ end
110
+
111
+ specify { @msg.should match('to have encrypted_password column') }
112
+ end
113
+
114
+ context "when model has no password_salt column" do
115
+ before do
116
+ subject.stubs(:has_password_salt_column?).returns(false)
117
+ subject.matches?(User)
118
+
119
+ @msg = subject.failure_message_for_should
120
+ end
121
+
122
+ specify { @msg.should match('to have password_salt column') }
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers::BeARecoverableMatcher do
4
+ before do
5
+ @valid_columns = ['reset_password_token']
6
+
7
+ User.stubs(:column_names).returns(@valid_columns)
8
+ end
9
+
10
+ context "inclusion of Devise::Models::Recoverable" do
11
+ it "should validate that model has Devise::Models::Recoverable included" do
12
+ subject.matches?(User).should be_true
13
+ end
14
+
15
+ it "should validate that model has no Devise::Models::Recoverable included" do
16
+ subject.matches?(FooUser).should be_false
17
+ end
18
+ end
19
+
20
+ context "columns validation" do
21
+ before do
22
+ subject.stubs(:included?).returns(true)
23
+ end
24
+
25
+ it "should validate that model has reset_password_token column" do
26
+ subject.matches?(User).should be_true
27
+ end
28
+
29
+ it "should validate that model has no reset_password_token column" do
30
+ User.stubs(:column_names).returns(@valid_columns - ['reset_password_token'])
31
+
32
+ subject.matches?(User).should be_false
33
+ end
34
+ end
35
+
36
+ describe "description" do
37
+ specify { subject.description.should eql('be a recoverable') }
38
+ end
39
+
40
+
41
+ describe "expectation message" do
42
+ context "when Devise::Models::Recoverable is not included" do
43
+ before do
44
+ subject.stubs(:included?).returns(false)
45
+ subject.matches?(User)
46
+ end
47
+
48
+ specify { subject.failure_message_for_should.should match('to include Devise :recoverable model') }
49
+ end
50
+
51
+ context "when has no reset_password_token column" do
52
+ before do
53
+ subject.stubs(:has_reset_password_token_column?).returns(false)
54
+ subject.matches?(User)
55
+ end
56
+ specify { subject.failure_message_for_should.should match('to have reset_password_token column') }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers::BeARememberableMatcher do
4
+ before do
5
+ @valid_columns = ['remember_token', 'remember_created_at']
6
+
7
+ User.stubs(:column_names).returns(@valid_columns)
8
+ end
9
+
10
+ context "validate inclusion of Devise::Models::Rememberable" do
11
+ it "should validate that model has Devise::Models::Rememberable module included" do
12
+ subject.matches?(User).should be_true
13
+ end
14
+
15
+ it "should validate that model has no Devise::Models::Rememberable module included" do
16
+ subject.matches?(FooUser).should be_false
17
+ end
18
+ end
19
+
20
+ context "columns validation" do
21
+ before do
22
+ subject.stubs(:included?).returns(true)
23
+ end
24
+
25
+ context "remember_token column" do
26
+ it "should validate that model has remember_token column" do
27
+ subject.matches?(User).should be_true
28
+ end
29
+
30
+ it "should validate that model has no remember_token column" do
31
+ User.stubs(:column_names).returns(@valid_columns - ['remember_token'])
32
+
33
+ subject.matches?(User).should be_false
34
+ end
35
+ end
36
+
37
+ context "remember_created_at" do
38
+ before do
39
+ subject.stubs(:has_remember_token_column?).returns(true)
40
+ end
41
+
42
+ it "should validate that model has remember_create_at column" do
43
+ subject.matches?(User).should be_true
44
+ end
45
+
46
+ it "should validate that model has no remember_create_at column" do
47
+ User.stubs(:column_names).returns(@valid_columns - ['remember_created_at'])
48
+
49
+ subject.matches?(User).should be_false
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "description" do
55
+ specify { subject.description.should eql('be a rememberable') }
56
+ end
57
+
58
+ describe "expectation message" do
59
+ context "when module Devise::Models::Remeberable is not included" do
60
+ before do
61
+ subject.stubs(:included?).returns(false)
62
+ subject.matches?(User)
63
+ end
64
+
65
+ specify { subject.failure_message_for_should.should match('to include Devise :rememberable model') }
66
+ end
67
+
68
+ context "when model has no remember_token column" do
69
+ before do
70
+ subject.stubs(:has_remember_token_column?).returns(false)
71
+ subject.matches?(User)
72
+ end
73
+
74
+ specify { subject.failure_message_for_should.should match('to have remember_token column') }
75
+ end
76
+
77
+ context "when model has no remember_created_at column" do
78
+ before do
79
+ subject.stubs(:has_remember_created_at_column?).returns(false)
80
+ subject.matches?(User)
81
+ end
82
+
83
+ specify { subject.failure_message_for_should.should match('to have remember_created_at column') }
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers::BeATrackableMatcher do
4
+ before do
5
+ @valid_columns = ['sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip']
6
+ User.stubs(:column_names).returns(@valid_columns)
7
+ end
8
+
9
+ context "requirement of Devise::Models::Trackable module inclusion" do
10
+ it "should validate that model has Devise::Models::Trackable included" do
11
+ subject.matches?(User).should be_true
12
+ end
13
+
14
+ it "should validate that model has no Devise::Models::Trackable included" do
15
+ subject.matches?(FooUser).should be_false
16
+ end
17
+
18
+ end
19
+
20
+ context "columns validation" do
21
+ before do
22
+ subject.stubs(:included?).returns(true)
23
+ end
24
+
25
+ describe "sign_in_count column" do
26
+ before do
27
+ subject.stubs(:has_current_sign_in_at_column?).returns(true)
28
+ subject.stubs(:has_last_sign_in_at_column?).returns(true)
29
+ subject.stubs(:has_current_sign_in_ip_column?).returns(true)
30
+ subject.stubs(:has_last_sign_in_ip_column?).returns(true)
31
+ end
32
+
33
+ it "should validate that model has sign_in_count column" do
34
+ subject.matches?(User).should be_true
35
+ end
36
+
37
+ it "should validate that model has no sign_in_count column" do
38
+ User.stubs(:column_names).returns(@valid_columns - ['sign_in_count'])
39
+
40
+ subject.matches?(User).should be_false
41
+ end
42
+ end
43
+
44
+ describe "current_sign_in_at column" do
45
+ before do
46
+ subject.stubs(:has_sign_in_count_column?).returns(true)
47
+ subject.stubs(:has_last_sign_in_at_column?).returns(true)
48
+ subject.stubs(:has_current_sign_in_ip_column?).returns(true)
49
+ subject.stubs(:has_last_sign_in_ip_column?).returns(true)
50
+ end
51
+
52
+ it "should validate that model has current_sign_in_at column" do
53
+ subject.matches?(User).should be_true
54
+ end
55
+
56
+ it "should validate that model has no current_sign_in_at column" do
57
+ User.stubs(:column_names).returns(@valid_columns - ['current_sign_in_at'])
58
+
59
+ subject.matches?(User).should be_false
60
+ end
61
+ end
62
+
63
+ describe "last_sign_in_at column" do
64
+ before do
65
+ subject.stubs(:has_sign_in_count_column?).returns(true)
66
+ subject.stubs(:has_current_sign_in_at_column?).returns(true)
67
+ subject.stubs(:has_current_sign_in_ip_column?).returns(true)
68
+ subject.stubs(:has_last_sign_in_ip_column?).returns(true)
69
+ end
70
+
71
+ it "should validate that model has last_sign_in_at column" do
72
+ subject.matches?(User).should be_true
73
+ end
74
+
75
+ it "should validate that model has no last_sign_in_at column" do
76
+ User.stubs(:column_names).returns(@valid_columns - ['last_sign_in_at'])
77
+
78
+ subject.matches?(User).should be_false
79
+ end
80
+ end
81
+
82
+ describe "current_sign_in_ip column" do
83
+ before do
84
+ subject.stubs(:has_sign_in_count_column?).returns(true)
85
+ subject.stubs(:has_current_sign_in_at_column?).returns(true)
86
+ subject.stubs(:has_last_sign_in_at_column?).returns(true)
87
+ subject.stubs(:has_last_sign_in_ip_column?).returns(true)
88
+ end
89
+
90
+ it "should validate that model has current_sign_in_ip column" do
91
+ subject.matches?(User).should be_true
92
+ end
93
+
94
+ it "should validate that model has no current_sign_in_ip column" do
95
+ User.stubs(:column_names).returns(@valid_columns - ['current_sign_in_ip'])
96
+
97
+ subject.matches?(User).should be_false
98
+ end
99
+ end
100
+
101
+ describe "last_sign_in_ip column" do
102
+ before do
103
+ subject.stubs(:has_sign_in_count_column?).returns(true)
104
+ subject.stubs(:has_current_sign_in_at_column?).returns(true)
105
+ subject.stubs(:has_last_sign_in_at_column?).returns(true)
106
+ subject.stubs(:has_current_sign_in_ip_column?).returns(true)
107
+ end
108
+
109
+ it "should validate that model has last_sign_in_ip column" do
110
+ subject.matches?(User).should be_true
111
+ end
112
+
113
+ it "should validate that model has no last_sign_in_ip column" do
114
+ User.stubs(:column_names).returns(@valid_columns - ['last_sign_in_ip'])
115
+
116
+ subject.matches?(User).should be_false
117
+ end
118
+
119
+ end
120
+ end
121
+
122
+ describe "description" do
123
+ specify { subject.description.should eql('be a trackable') }
124
+ end
125
+
126
+ describe "expectation message" do
127
+ context "when module Devise::Models::Trackable is not included" do
128
+ before do
129
+ subject.matches?(FooUser)
130
+ end
131
+
132
+ specify { subject.failure_message_for_should.should match('to include Devise :trackable model') }
133
+ end
134
+
135
+ context "when model has no sign_in_count column" do
136
+ before do
137
+ User.stubs(:column_names).returns(@valid_columns - ['sign_in_count'])
138
+
139
+ subject.matches?(User)
140
+ end
141
+
142
+ specify { subject.failure_message_for_should.should match('to have sign_in_count column') }
143
+ end
144
+
145
+ context "when model has no current_sign_in_at column" do
146
+ before do
147
+ User.stubs(:column_names).returns(@valid_columns - ['current_sign_in_at'])
148
+
149
+ subject.matches?(User)
150
+ end
151
+
152
+ specify { subject.failure_message_for_should.should match('to have current_sign_in_at column') }
153
+ end
154
+
155
+ context "when model has no last_sign_in_at column" do
156
+ before do
157
+ User.stubs(:column_names).returns(@valid_columns - ['last_sign_in_at'])
158
+
159
+ subject.matches?(User)
160
+ end
161
+
162
+ specify { subject.failure_message_for_should.should match('to have last_sign_in_at column') }
163
+ end
164
+
165
+ context "when model has no current_sign_in_ip column" do
166
+ before do
167
+ User.stubs(:column_names).returns(@valid_columns - ['current_sign_in_ip'])
168
+
169
+ subject.matches?(User)
170
+ end
171
+
172
+ specify { subject.failure_message_for_should.should match('to have current_sign_in_ip column') }
173
+ end
174
+
175
+ context "when model has no last_sign_in_ip column" do
176
+ before do
177
+ User.stubs(:column_names).returns(@valid_columns - ['last_sign_in_ip'])
178
+
179
+ subject.matches?(User)
180
+ end
181
+
182
+ specify { subject.failure_message_for_should.should match('to have last_sign_in_ip column')}
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Remarkable::Devise::Matchers do
4
+ describe "#be_a_database_authenticatable" do
5
+ it "should return Remarkable::Devise::Matchers::BeADatabaseAuthenticatableMatcher" do
6
+ be_a_database_authenticatable.should be_an_instance_of(Remarkable::Devise::Matchers::BeADatabaseAuthenticatableMatcher)
7
+ end
8
+ end
9
+
10
+ describe "#be_a_confirmable" do
11
+ it "should return Remarkable::Devise::Matchers::BeAConfirmableMatcher" do
12
+ be_a_confirmable.should be_an_instance_of(Remarkable::Devise::Matchers::BeAConfirmableMatcher)
13
+ end
14
+ end
15
+
16
+ describe "#be_a_recoverable" do
17
+ it "should return Remarkable::Devise::Matchers::BeARecoverableMatcher" do
18
+ be_a_recoverable.should be_an_instance_of(Remarkable::Devise::Matchers::BeARecoverableMatcher)
19
+ end
20
+ end
21
+
22
+ describe "#be_a_rememberable" do
23
+ it "should return Remarkable::Devise::Matchers::BeARememberableMatcher" do
24
+ be_a_rememberable.should be_an_instance_of(Remarkable::Devise::Matchers::BeARememberableMatcher)
25
+ end
26
+ end
27
+
28
+ describe "#be_a_trackable" do
29
+ it "should return Remarkable::Devise::Matchers::BeATrackableMatcher" do
30
+ be_a_trackable.should be_an_instance_of(Remarkable::Devise::Matchers::BeATrackableMatcher)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require 'mocha'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'remarkable', 'devise')
4
+
5
+ require 'example_models'
6
+
7
+ ActiveRecord::Base.establish_connection(
8
+ :adapter => 'sqlite3',
9
+ :database => ':memory:'
10
+ )
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :mocha
14
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remarkable_devise
3
+ version: !ruby/object:Gem::Version
4
+ hash: -1710980576
5
+ prerelease: true
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - alpha2
11
+ version: 1.0.0.alpha2
12
+ platform: ruby
13
+ authors:
14
+ - Vasily Reys
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-12-05 00:00:00 +06:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 11
31
+ segments:
32
+ - 2
33
+ - 1
34
+ - 0
35
+ version: 2.1.0
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rails
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 5
47
+ segments:
48
+ - 3
49
+ - 0
50
+ - 1
51
+ version: 3.0.1
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: activerecord
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 5
63
+ segments:
64
+ - 3
65
+ - 0
66
+ - 1
67
+ version: 3.0.1
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: remarkable_activerecord
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - "="
77
+ - !ruby/object:Gem::Version
78
+ hash: -1710980466
79
+ segments:
80
+ - 4
81
+ - 0
82
+ - 0
83
+ - alpha4
84
+ version: 4.0.0.alpha4
85
+ type: :runtime
86
+ version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: devise
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 21
96
+ segments:
97
+ - 1
98
+ - 1
99
+ - 3
100
+ version: 1.1.3
101
+ type: :runtime
102
+ version_requirements: *id005
103
+ - !ruby/object:Gem::Dependency
104
+ name: mocha
105
+ prerelease: false
106
+ requirement: &id006 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ type: :development
116
+ version_requirements: *id006
117
+ description: Devise remarkable rspec matchers
118
+ email: reys.vasily@gmail.com
119
+ executables: []
120
+
121
+ extensions: []
122
+
123
+ extra_rdoc_files: []
124
+
125
+ files:
126
+ - .gitignore
127
+ - .rspec
128
+ - Gemfile
129
+ - License.txt
130
+ - README.markdown
131
+ - Rakefile
132
+ - lib/remarkable/devise.rb
133
+ - lib/remarkable/devise/matchers/base_matcher.rb
134
+ - lib/remarkable/devise/matchers/be_a_confirmable_matcher.rb
135
+ - lib/remarkable/devise/matchers/be_a_database_authenticatable_matcher.rb
136
+ - lib/remarkable/devise/matchers/be_a_recoverable_matcher.rb
137
+ - lib/remarkable/devise/matchers/be_a_rememberable_matcher.rb
138
+ - lib/remarkable/devise/matchers/be_a_trackable_matcher.rb
139
+ - lib/remarkable/devise/version.rb
140
+ - locale/en.yml
141
+ - remarkable_devise.gemspec
142
+ - spec/example_models.rb
143
+ - spec/matchers/be_a_confirmable_spec.rb
144
+ - spec/matchers/be_a_database_authenticatable_spec.rb
145
+ - spec/matchers/be_a_recoverable_spec.rb
146
+ - spec/matchers/be_a_rememberable_spec.rb
147
+ - spec/matchers/be_a_trackable_spec.rb
148
+ - spec/matchers_spec.rb
149
+ - spec/spec_helper.rb
150
+ has_rdoc: true
151
+ homepage: http://github.com/vreys/remarkable_devise
152
+ licenses: []
153
+
154
+ post_install_message:
155
+ rdoc_options: []
156
+
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">"
172
+ - !ruby/object:Gem::Version
173
+ hash: 25
174
+ segments:
175
+ - 1
176
+ - 3
177
+ - 1
178
+ version: 1.3.1
179
+ requirements: []
180
+
181
+ rubyforge_project: remarkbl-devise
182
+ rubygems_version: 1.3.7
183
+ signing_key:
184
+ specification_version: 3
185
+ summary: remarkable_devise_Remarkable::Devise::Version
186
+ test_files:
187
+ - spec/example_models.rb
188
+ - spec/matchers/be_a_confirmable_spec.rb
189
+ - spec/matchers/be_a_database_authenticatable_spec.rb
190
+ - spec/matchers/be_a_recoverable_spec.rb
191
+ - spec/matchers/be_a_rememberable_spec.rb
192
+ - spec/matchers/be_a_trackable_spec.rb
193
+ - spec/matchers_spec.rb
194
+ - spec/spec_helper.rb