iceauth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +4 -0
  2. data/.rvmrc +55 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +1 -0
  5. data/iceauth.gemspec +24 -0
  6. data/lib/generators/iceauth/.DS_Store +0 -0
  7. data/lib/generators/iceauth/USAGE +7 -0
  8. data/lib/generators/iceauth/iceauth_generator.rb +25 -0
  9. data/lib/generators/iceauth/templates/app/assets/images/rails.png +0 -0
  10. data/lib/generators/iceauth/templates/app/assets/stylesheets/application.css +9 -0
  11. data/lib/generators/iceauth/templates/app/assets/stylesheets/pages.css.scss +170 -0
  12. data/lib/generators/iceauth/templates/app/controllers/application_controller.rb +5 -0
  13. data/lib/generators/iceauth/templates/app/controllers/pages_controller.rb +22 -0
  14. data/lib/generators/iceauth/templates/app/controllers/sessions_controller.rb +24 -0
  15. data/lib/generators/iceauth/templates/app/controllers/users_controller.rb +52 -0
  16. data/lib/generators/iceauth/templates/app/helpers/.DS_Store +0 -0
  17. data/lib/generators/iceauth/templates/app/helpers/sessions_helper.rb +39 -0
  18. data/lib/generators/iceauth/templates/app/layouts/_footer.html.haml +7 -0
  19. data/lib/generators/iceauth/templates/app/layouts/_header.html.haml.tt +14 -0
  20. data/lib/generators/iceauth/templates/app/layouts/_javascripts.html.haml +2 -0
  21. data/lib/generators/iceauth/templates/app/layouts/_stylesheets.html.haml +4 -0
  22. data/lib/generators/iceauth/templates/app/layouts/application.html.haml.tt +16 -0
  23. data/lib/generators/iceauth/templates/app/models/.gitkeep +0 -0
  24. data/lib/generators/iceauth/templates/app/models/user.rb +53 -0
  25. data/lib/generators/iceauth/templates/app/views/layouts/_footer.html.haml +7 -0
  26. data/lib/generators/iceauth/templates/app/views/layouts/_header.html.haml.tt +14 -0
  27. data/lib/generators/iceauth/templates/app/views/layouts/_javascripts.html.haml +2 -0
  28. data/lib/generators/iceauth/templates/app/views/layouts/_stylesheets.html.haml +4 -0
  29. data/lib/generators/iceauth/templates/app/views/layouts/application.html.haml.tt +16 -0
  30. data/lib/generators/iceauth/templates/app/views/pages/about.html.haml.tt +3 -0
  31. data/lib/generators/iceauth/templates/app/views/pages/contact.html.haml.tt +3 -0
  32. data/lib/generators/iceauth/templates/app/views/pages/help.html.haml.tt +3 -0
  33. data/lib/generators/iceauth/templates/app/views/pages/home.html.haml.tt +7 -0
  34. data/lib/generators/iceauth/templates/app/views/sessions/new.html.haml +23 -0
  35. data/lib/generators/iceauth/templates/app/views/shared/_error_messages.html.haml +10 -0
  36. data/lib/generators/iceauth/templates/app/views/users/_fields.html.haml +27 -0
  37. data/lib/generators/iceauth/templates/app/views/users/edit.html.haml +7 -0
  38. data/lib/generators/iceauth/templates/app/views/users/new.html.haml +7 -0
  39. data/lib/generators/iceauth/templates/spec/controllers/pages_controller_spec.rb.tt +68 -0
  40. data/lib/generators/iceauth/templates/spec/controllers/sessions_controller_spec.rb +88 -0
  41. data/lib/generators/iceauth/templates/spec/controllers/users_controller_spec.rb +266 -0
  42. data/lib/generators/iceauth/templates/spec/factories.rb +16 -0
  43. data/lib/generators/iceauth/templates/spec/models/user_spec.rb +192 -0
  44. data/lib/generators/iceauth/templates/spec/spec_helper.rb +50 -0
  45. data/lib/generators/iceauth/templates/vendor/.DS_Store +0 -0
  46. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/.gitkeep +0 -0
  47. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/awesome-buttons.css +114 -0
  48. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/ie.css +36 -0
  49. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
  50. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
  51. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
  52. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
  53. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
  54. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
  55. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
  56. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
  57. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
  58. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
  59. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
  60. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
  61. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/lock.png +0 -0
  62. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  63. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
  64. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
  65. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
  66. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/screen.css +42 -0
  67. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
  68. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
  69. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/print.css +29 -0
  70. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/screen.css +265 -0
  71. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/forms.css +82 -0
  72. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/grid.css +280 -0
  73. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/grid.png +0 -0
  74. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/ie.css +79 -0
  75. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/print.css +92 -0
  76. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/reset.css +65 -0
  77. data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/typography.css +123 -0
  78. data/lib/iceauth/version.rb +3 -0
  79. data/lib/iceauth.rb +5 -0
  80. metadata +124 -0
@@ -0,0 +1,10 @@
1
+ - if object.errors.any?
2
+ #error_explanation
3
+ %h2
4
+ = pluralize(object.errors.count, "error")
5
+ prohibited this #{object.class} from being saved:
6
+ - # FIXME: Fix the display of the class name
7
+ %p There were problems with the following fields:
8
+ %ul
9
+ - object.errors.full_messages.each do |msg|
10
+ %li= msg
@@ -0,0 +1,27 @@
1
+ = render 'shared/error_messages', :object => f.object
2
+ - unless @user.new_record?
3
+ .field
4
+ = f.label :current_password, "Current Password"
5
+ %br
6
+ = f.password_field :current_password
7
+ .field
8
+ = f.label :name
9
+ %br
10
+ = f.text_field :name
11
+ .field
12
+ = f.label :username
13
+ %br
14
+ = f.text_field :username
15
+ .field
16
+ = f.label :email
17
+ %br
18
+ = f.text_field :email
19
+ .field
20
+ = f.label :password, "#{@user.new_record? ? '' : 'New ' }Password"
21
+ %br
22
+ = f.password_field :password
23
+ .field
24
+ = f.label :password_confirmation, "Password Confirmation"
25
+ %br
26
+ = f.password_field :password_confirmation
27
+ %br
@@ -0,0 +1,7 @@
1
+ %section.main.round
2
+ %h1 Profile Settings
3
+
4
+ = form_for(@user) do |f|
5
+ = render 'fields', :f => f
6
+ .actions
7
+ = f.submit "Update", :class => 'awesome'
@@ -0,0 +1,7 @@
1
+ %section.round
2
+ %h1 Sign Up
3
+
4
+ = form_for(@user) do |f|
5
+ = render 'users/fields', :f => f
6
+ .actions
7
+ = f.submit "Sign Up", :class => 'awesome'
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController do
4
+ render_views
5
+
6
+ before(:each) do
7
+ @base_title = "<%= name.camelcase %>"
8
+ end
9
+
10
+ describe "#home", "(GET)" do
11
+
12
+ before(:each) do
13
+ get :home
14
+ end
15
+
16
+ it "is successful" do
17
+ response.should be_success
18
+ end
19
+
20
+ it "has the correct title" do
21
+ page.has_content?("#{@base_title} | Home")
22
+ end
23
+
24
+ end
25
+
26
+ describe "#contact", "(GET)" do
27
+ before(:each) do
28
+ get :contact
29
+ end
30
+
31
+ it "is successful" do
32
+ response.should be_success
33
+ end
34
+
35
+ it "has the correct title" do
36
+ page.has_content?("#{@base_title} | Contact")
37
+ end
38
+ end
39
+
40
+ describe "#about", "(GET)" do
41
+ before(:each) do
42
+ get :about
43
+ end
44
+
45
+ it "is successful" do
46
+ response.should be_success
47
+ end
48
+
49
+ it "has the correct title" do
50
+ page.has_content?("#{@base_title} | About")
51
+ end
52
+ end
53
+
54
+ describe "#help", "(GET)" do
55
+ before(:each) do
56
+ get :help
57
+ end
58
+
59
+ it "is successful" do
60
+ response.should be_success
61
+ end
62
+
63
+ it "has the correct title" do
64
+ page.has_content?("#{@base_title} | Help")
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe SessionsController do
4
+ render_views
5
+
6
+ describe "#new", "(GET)" do
7
+
8
+ it "is successful" do
9
+ get :new
10
+ response.should be_success
11
+ end
12
+
13
+ it "has the right title" do
14
+ get :new
15
+ page.has_content?("Sign In")
16
+ end
17
+
18
+ end
19
+
20
+ describe "#create", "(POST)" do
21
+
22
+ context "given invalid login or password" do
23
+
24
+ before(:each) do
25
+ @attr = { :login => "email@example.com", :password => "invalid" }
26
+ end
27
+
28
+ it "re-renders the new page" do
29
+ post :create, :session => @attr
30
+ response.should render_template('new')
31
+ end
32
+
33
+ it "has the correct title" do
34
+ post :create, :session => @attr
35
+ page.has_content?("Sign in")
36
+ end
37
+
38
+ it "has a flash.now error message" do
39
+ post :create, :session => @attr
40
+ flash.now[:error].should =~ /invalid/i
41
+ end
42
+
43
+ end
44
+
45
+ context "given valid login and password" do
46
+
47
+ before(:each) do
48
+ @user = Factory(:user)
49
+ @attr = { :login => @user.username, :password => @user.password }
50
+ end
51
+
52
+ it "signs the user in" do
53
+ post :create, :session => @attr
54
+ controller.current_user.should == @user
55
+ controller.should be_signed_in
56
+ end
57
+
58
+ it "redirects to the root page" do
59
+ post :create, :session => @attr
60
+ response.should redirect_to(root_path)
61
+ end
62
+
63
+ end
64
+
65
+ describe "with twitter omniauth"
66
+
67
+ describe "with facebook omniauth"
68
+
69
+ end
70
+
71
+ describe "#destroy", "(DELETE)" do
72
+
73
+ before(:each) do
74
+ test_sign_in(Factory(:user))
75
+ delete :destroy
76
+ end
77
+
78
+ it "signs a user out" do
79
+ controller.should_not be_signed_in
80
+ end
81
+
82
+ it "redirects to root path" do
83
+ response.should redirect_to(root_path)
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,266 @@
1
+ require 'spec_helper'
2
+
3
+ describe UsersController do
4
+ render_views
5
+
6
+ describe "#new", '(GET)' do
7
+
8
+ context "when not logged in" do
9
+
10
+ before(:each) do
11
+ get :new
12
+ end
13
+
14
+ it "is successful" do
15
+ response.should be_success
16
+ end
17
+
18
+ it "has the correct title" do
19
+ page.has_content?("Sign Up")
20
+ end
21
+
22
+ it "has a name field" do
23
+ page.has_selector?("input[name='user[name]'][type='text']")
24
+ end
25
+
26
+ it "has a username field" do
27
+ page.has_selector?("input[name='user[username]'][type='text']")
28
+ end
29
+
30
+ it "has an email field" do
31
+ page.has_selector?("input[name='user[email]'][type='text']")
32
+ end
33
+
34
+ it "has a password field" do
35
+ page.has_selector?("input[name='user[password]'][type='password']")
36
+ end
37
+
38
+ it "has a password confirmation field" do
39
+ page.has_selector?("input[name='user[password_confirmation]'][type='password']")
40
+ end
41
+
42
+ end
43
+
44
+ context "when logged in" do
45
+
46
+ before(:each) do
47
+ test_sign_in(Factory(:user))
48
+ get :new
49
+ end
50
+
51
+ it "redirects to the root path" do
52
+ response.should redirect_to(root_path)
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ describe '#create', '(POST)' do
60
+
61
+ context "when not logged in" do
62
+
63
+ context "given invalid parameters" do
64
+
65
+ before(:each) do
66
+ @attr = { :name => "", :username => "", :email => "", :password => "",
67
+ :password_confirmation => "" }
68
+ end
69
+
70
+ it "does not create a user" do
71
+ lambda do
72
+ post :create, :user => @attr
73
+ end.should_not change(User, :count)
74
+ end
75
+
76
+ it "renders the 'new' page" do
77
+ post :create, :user => @attr
78
+ response.should render_template('new')
79
+ end
80
+
81
+ it "has the correct title" do
82
+ post :create, :user => @attr
83
+ page.has_content?("Sign Up")
84
+ end
85
+
86
+ end
87
+
88
+ context "given valid parameters" do
89
+
90
+ before(:each) do
91
+ @attr = { :name => "Mark Dillon", :username => "markdillon", :email => "mdillon@gmail.com",
92
+ :password => "foobar", :password_confirmation => "foobar" }
93
+ end
94
+
95
+ it "creates a user" do
96
+ lambda do
97
+ post :create, :user => @attr
98
+ end.should change(User, :count).by(1)
99
+ end
100
+
101
+ it "redirects to the root path" do
102
+ post :create, :user => @attr
103
+ response.should redirect_to(root_path)
104
+ end
105
+
106
+ it "has a welcome message" do
107
+ post :create, :user => @attr
108
+ flash[:success].should =~ /Signed Up/i
109
+ end
110
+
111
+ it "signs the user in" do
112
+ post :create, :user => @attr
113
+ controller.should be_signed_in
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+
120
+ context "when logged in" do
121
+
122
+ before(:each) do
123
+ test_sign_in(Factory(:user))
124
+ end
125
+
126
+ it "redirects to the root path" do
127
+ post :create, :user => @attr
128
+ response.should redirect_to(root_path)
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ describe '#edit', '(GET)' do
136
+
137
+ context 'when not logged in' do
138
+
139
+ before(:each) do
140
+ @user = Factory(:user)
141
+ get :edit, :id => @user.username
142
+ end
143
+
144
+ it "is not successful" do
145
+ response.should_not be_success
146
+ end
147
+
148
+ it 'redirects to the signin page' do
149
+ response.should redirect_to(signin_path)
150
+ end
151
+
152
+ end
153
+
154
+ context 'when logged in' do
155
+
156
+ before(:each) do
157
+ @user = Factory(:user)
158
+ test_sign_in(@user)
159
+ end
160
+
161
+ context 'given a user other than current user' do
162
+
163
+ it 'redirects to rooth path' do
164
+ wrong_user = Factory(:user, :username => Factory.next(:username), :email => Factory.next(:email))
165
+ get :edit, :id => wrong_user.id
166
+ response.should redirect_to(root_path)
167
+ end
168
+
169
+ end
170
+
171
+ context 'given the current user' do
172
+
173
+ before(:each) do
174
+ get :edit, :id => @user.id
175
+ end
176
+
177
+ it "is successful" do
178
+ response.should be_success
179
+ end
180
+
181
+ it "has the correct title" do
182
+ page.has_content?("Profile Settings")
183
+ end
184
+
185
+ end
186
+ end
187
+
188
+ end
189
+
190
+ describe '#update', 'PUT' do
191
+
192
+ context 'when not logged in' do
193
+
194
+ before(:each) do
195
+ @user = Factory(:user)
196
+ put :update, :id => @user.id, :user => {}
197
+ end
198
+
199
+ it 'is not successful' do
200
+ response.should_not be_success
201
+ end
202
+
203
+ it "redirects to the signin path" do
204
+ response.should redirect_to(signin_path)
205
+ end
206
+
207
+ end
208
+
209
+ context "when logged in" do
210
+
211
+ before(:each) do
212
+ @user = Factory(:user)
213
+ test_sign_in(@user)
214
+ end
215
+
216
+ context "given a user other than current user" do
217
+ it 'redirects to rooth path' do
218
+ wrong_user = Factory(:user, :username => Factory.next(:username), :email => Factory.next(:email))
219
+ put :update, :id => wrong_user.id, :user => {}
220
+ response.should redirect_to(root_path)
221
+ end
222
+ end
223
+
224
+ context "given invalid parameters" do
225
+ before(:each) do
226
+ @attr = { :email => "", :name => "", :password => "",
227
+ :password_confirmation => "" }
228
+ put :update, :id => @user.id, :user => @attr
229
+ end
230
+
231
+ it "renders the 'edit' page" do
232
+ response.should render_template('edit')
233
+ end
234
+
235
+ it "should have the right title" do
236
+ page.has_content?("Profile Settings")
237
+ end
238
+ end
239
+
240
+ context 'given valid parameters' do
241
+ before(:each) do
242
+ @attr = { :current_password => @user.password, :name => "New Name", :email => "user@example.org",
243
+ :password => "barbaz", :password_confirmation => "barbaz" }
244
+ put :update, :id => @user.id, :user => @attr
245
+ end
246
+
247
+ it "changes the user's attributes" do
248
+ @user.reload
249
+ @user.name.should == @attr[:name]
250
+ @user.email.should == @attr[:email]
251
+ end
252
+
253
+ it "redirects to the user edit page" do
254
+ response.should redirect_to(edit_user_path(@user))
255
+ end
256
+
257
+ it "displays a message that the user was updated" do
258
+ flash[:success].should =~ /updated/i
259
+ end
260
+ end
261
+
262
+ end
263
+
264
+ end
265
+
266
+ end
@@ -0,0 +1,16 @@
1
+ # By using the symbol ':user', we get Factory Girl to simulate the User model.
2
+ Factory.define :user do |user|
3
+ user.name "Leah Dillon"
4
+ user.username "leahdillon"
5
+ user.email "leahdillon@gmail.com"
6
+ user.password "foobar"
7
+ user.password_confirmation "foobar"
8
+ end
9
+
10
+ Factory.sequence :username do |n|
11
+ "username#{n}"
12
+ end
13
+
14
+ Factory.sequence :email do |n|
15
+ "user#{n}@example.com"
16
+ end
@@ -0,0 +1,192 @@
1
+ require 'spec_helper'
2
+
3
+ describe User do
4
+
5
+ before(:each) do
6
+ @attr = {
7
+ :name => "Mark Dillon",
8
+ :username => "markdillon",
9
+ :email => "mdillon@gmail.com",
10
+ :password => "foobar",
11
+ :password_confirmation => "foobar"
12
+ }
13
+ end
14
+
15
+ describe ".create" do
16
+
17
+ before(:each) do
18
+ @count = User.count
19
+ @user = User.create!(@attr)
20
+ end
21
+
22
+ context "given valid attributes" do
23
+ it "creates a new instance" do
24
+ User.count.should == @count + 1
25
+ end
26
+
27
+ it "sets the created_at timestamp" do
28
+ @user.created_at.should be
29
+ end
30
+
31
+ it "sets the updated_at timestamp" do
32
+ @user.updated_at.should be
33
+ end
34
+
35
+ it "sets the password digest" do
36
+ @user.password_digest.should_not be_blank
37
+ end
38
+
39
+ it "is not an admin by default" do
40
+ @user.should_not be_admin
41
+ end
42
+
43
+ it "is convertible to an admin" do
44
+ @user.should_not be_admin
45
+ @user.toggle_admin!
46
+ @user.should be_admin
47
+ end
48
+ end
49
+
50
+ context "given invalid attributes" do
51
+ it "does not create a user" do
52
+ @count = User.count
53
+ expect { User.create!({}) }.to raise_error(Mongoid::Errors::Validations)
54
+ User.count.should == @count
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ describe "#valid?" do
61
+
62
+ it "requires a username" do
63
+ User.new(@attr.merge(:username => "")).should_not be_valid
64
+ end
65
+
66
+ it "requires an email address" do
67
+ User.new(@attr.merge(:email => "")).should_not be_valid
68
+ end
69
+
70
+ it "requires a name" do
71
+ User.new(@attr.merge(:name => "")).should_not be_valid
72
+ end
73
+
74
+ it "rejects usernames with spaces in them" do
75
+ User.new(@attr.merge(:username => "mark dillon")).should_not be_valid
76
+ end
77
+
78
+ it "rejects usernames that are too long" do
79
+ long_username = "a" * 21
80
+ User.new(@attr.merge(:username => long_username)).should_not be_valid
81
+ end
82
+
83
+ it "accepts valid email addresses" do
84
+ %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp].each do |address|
85
+ User.new(@attr.merge(:email => address)).should be_valid
86
+ end
87
+ end
88
+
89
+ it "rejects invalid email addresses" do
90
+ %w[user@foo,com user_at_foo.org example.user@foo.].each do |address|
91
+ User.new(@attr.merge(:email => address)).should_not be_valid
92
+ end
93
+ end
94
+
95
+ it "rejects duplicate email addresses" do
96
+ User.create!(@attr)
97
+ User.new(@attr).should_not be_valid
98
+ end
99
+
100
+ it "rejects email addresses identical up to case" do
101
+ upcased_email = @attr[:email].upcase
102
+ User.create!(@attr.merge(:email => upcased_email))
103
+ User.new(@attr).should_not be_valid
104
+ end
105
+
106
+ it "rejects names that are too long" do
107
+ long_name = "a" * 31
108
+ User.new(@attr.merge(:name => long_name)).should_not be_valid
109
+ end
110
+
111
+ it "requires a password" do
112
+ User.new(@attr.merge(:password => "", :password_confirmation => "")).should_not be_valid
113
+ end
114
+
115
+ it "requires a matching password confirmation" do
116
+ User.new(@attr.merge(:password_confirmation => "invalid")).should_not be_valid
117
+ end
118
+
119
+ it "rejects short passwords" do
120
+ short = "a" * 5
121
+ hash = @attr.merge(:password => short, :password_confirmation => short)
122
+ User.new(hash).should_not be_valid
123
+ end
124
+
125
+ it "rejects long passwords" do
126
+ long = "a" * 41
127
+ hash = @attr.merge(:password => long, :password_confirmation => long)
128
+ User.new(hash).should_not be_valid
129
+ end
130
+
131
+ end
132
+
133
+ describe "#delete" do
134
+
135
+ before(:each) do
136
+ @user = User.create!(@attr)
137
+ end
138
+
139
+ it "deletes the user" do
140
+ @count = User.count
141
+ @user.delete
142
+ User.count.should == @count - 1
143
+ end
144
+
145
+ it "sets deleted_at for the user" do
146
+ @user.deleted_at.should_not be
147
+ @user.delete
148
+ @user.deleted_at.should be
149
+ end
150
+
151
+ it "makes user irretrievable by normal means" do
152
+ id = @user.id
153
+ User.find(id).should be
154
+ @user.delete
155
+ expect { User.find(id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
156
+ end
157
+
158
+ it "allows user to be retrieved specifying deleted_at exists" do
159
+ id = @user.id
160
+ @user.delete
161
+ User.where(:_id => id).first.should_not be
162
+ User.where(:deleted_at.exists => true, :_id => id).first.should be
163
+ end
164
+
165
+ it "allows user to be restored" do
166
+ id = @user.id
167
+ @user.delete
168
+ expect { User.find(id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
169
+ @user.restore
170
+ User.find(id).should be
171
+ end
172
+
173
+ end
174
+
175
+ describe "#restore" do
176
+
177
+ before(:each) do
178
+ @user = User.create!(@attr)
179
+ end
180
+
181
+ it "restores a deleted user" do
182
+ id = @user.id
183
+ @user.delete
184
+ expect { User.find(id) }.to raise_error(Mongoid::Errors::DocumentNotFound)
185
+ @user.restore
186
+ User.find(id).should be
187
+ end
188
+
189
+ end
190
+
191
+
192
+ end