rules_engine_users 0.0.1

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 (85) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -0
  7. data/init.rb +1 -0
  8. data/lib/rules_engine/controller_user_mail.rb +29 -0
  9. data/lib/rules_engine/controller_users.rb +170 -0
  10. data/lib/rules_engine_users.rb +4 -0
  11. data/rails_generators/USAGE +97 -0
  12. data/rails_generators/manifests/rules_engine_users.rb +79 -0
  13. data/rails_generators/manifests/rules_engine_users.yml +32 -0
  14. data/rails_generators/rules_engine_users_generator.rb +21 -0
  15. data/rails_generators/templates/app/controllers/admin/users_controller.rb +64 -0
  16. data/rails_generators/templates/app/controllers/users_controller.rb +215 -0
  17. data/rails_generators/templates/app/models/user.rb +113 -0
  18. data/rails_generators/templates/app/models/user_mailer.rb +26 -0
  19. data/rails_generators/templates/app/models/user_observer.rb +19 -0
  20. data/rails_generators/templates/app/views/admin/users/_form.html.erb +6 -0
  21. data/rails_generators/templates/app/views/admin/users/edit.html.erb +18 -0
  22. data/rails_generators/templates/app/views/admin/users/index.html.erb +52 -0
  23. data/rails_generators/templates/app/views/admin/users/new.html.erb +17 -0
  24. data/rails_generators/templates/app/views/admin/users/show.html.erb +15 -0
  25. data/rails_generators/templates/app/views/user_mailer/forgot_password.html.erb +11 -0
  26. data/rails_generators/templates/app/views/user_mailer/welcome_message.html.erb +11 -0
  27. data/rails_generators/templates/app/views/users/change_form.html.erb +22 -0
  28. data/rails_generators/templates/app/views/users/details.html.erb +11 -0
  29. data/rails_generators/templates/app/views/users/login_form.html.erb +35 -0
  30. data/rails_generators/templates/app/views/users/pswd_change_form.html.erb +20 -0
  31. data/rails_generators/templates/app/views/users/pswd_forgot_form.html.erb +18 -0
  32. data/rails_generators/templates/app/views/users/pswd_reset_form.html.erb +22 -0
  33. data/rails_generators/templates/app/views/users/welcome_form.html.erb +21 -0
  34. data/rails_generators/templates/db/migrate/20100104014507_create_users.rb +41 -0
  35. data/rails_generators/templates/doc/README.rules_engine_users +122 -0
  36. data/rails_generators/templates/doc/README.rules_engine_users_paths +12 -0
  37. data/rails_generators/templates/features/admin/user/edit.feature +46 -0
  38. data/rails_generators/templates/features/admin/user/index.feature +78 -0
  39. data/rails_generators/templates/features/admin/user/new.feature +26 -0
  40. data/rails_generators/templates/features/admin/user/show.feature +22 -0
  41. data/rails_generators/templates/features/admin/user/step_definitions/edit_steps.rb +3 -0
  42. data/rails_generators/templates/features/admin/user/step_definitions/index_steps.rb +13 -0
  43. data/rails_generators/templates/features/admin/user/step_definitions/show_steps.rb +3 -0
  44. data/rails_generators/templates/features/support/blueprint_users.rb +14 -0
  45. data/rails_generators/templates/features/user/change.feature +37 -0
  46. data/rails_generators/templates/features/user/details.feature +15 -0
  47. data/rails_generators/templates/features/user/login.feature +65 -0
  48. data/rails_generators/templates/features/user/pswd_change.feature +46 -0
  49. data/rails_generators/templates/features/user/pswd_forgot.feature +32 -0
  50. data/rails_generators/templates/features/user/pswd_reset.feature +52 -0
  51. data/rails_generators/templates/features/user/step_definitions/login_steps.rb +46 -0
  52. data/rails_generators/templates/features/user/step_definitions/pswd_reset_steps.rb +15 -0
  53. data/rails_generators/templates/features/user/step_definitions/welcome_steps.rb +15 -0
  54. data/rails_generators/templates/features/user/welcome.feature +52 -0
  55. data/rails_generators/templates/spec/controllers/admin/users_controller_spec.rb +191 -0
  56. data/rails_generators/templates/spec/controllers/users_controller_spec.rb +579 -0
  57. data/rails_generators/templates/spec/models/user_mailer_spec.rb +39 -0
  58. data/rails_generators/templates/spec/models/user_observer_spec.rb +56 -0
  59. data/rails_generators/templates/spec/models/user_spec.rb +253 -0
  60. data/rails_generators/templates/spec/support/rules_engine_macros.rb +16 -0
  61. data/rules_engine_users.gemspec +141 -0
  62. data/spec/railsenv/app/controllers/application_controller.rb +10 -0
  63. data/spec/railsenv/config/boot.rb +110 -0
  64. data/spec/railsenv/config/database.yml +22 -0
  65. data/spec/railsenv/config/environment.rb +41 -0
  66. data/spec/railsenv/config/environments/development.rb +17 -0
  67. data/spec/railsenv/config/environments/production.rb +28 -0
  68. data/spec/railsenv/config/environments/test.rb +28 -0
  69. data/spec/railsenv/config/initializers/backtrace_silencers.rb +7 -0
  70. data/spec/railsenv/config/initializers/inflections.rb +10 -0
  71. data/spec/railsenv/config/initializers/mime_types.rb +5 -0
  72. data/spec/railsenv/config/initializers/new_rails_defaults.rb +19 -0
  73. data/spec/railsenv/config/initializers/session_store.rb +15 -0
  74. data/spec/railsenv/config/locales/en.yml +5 -0
  75. data/spec/railsenv/config/routes.rb +43 -0
  76. data/spec/railsenv/db/test.sqlite3 +1 -0
  77. data/spec/railsenv/log/debug.log +1 -0
  78. data/spec/railsenv/log/test.log +1 -0
  79. data/spec/rcov.opts +3 -0
  80. data/spec/rules_engine/controller_user_mail_spec.rb +43 -0
  81. data/spec/rules_engine/controller_users_spec.rb +337 -0
  82. data/spec/spec.opts +4 -0
  83. data/spec/spec_helper.rb +30 -0
  84. data/tasks/rspec.rake +18 -0
  85. metadata +180 -0
@@ -0,0 +1,52 @@
1
+ Feature: reset my password
2
+ As an unlogged in user
3
+ I want to reset my password
4
+
5
+ Background:
6
+ Given I am not logged in
7
+ Given there is a "user" with "email" set to "bill@smith.com"
8
+ Given the user reset token is set
9
+
10
+ Scenario: Visit user pswd reset
11
+ When I visit the user pswd reset page
12
+ Then I should see the view "users/pswd_reset_form"
13
+ Then the "Your Email" field should be required
14
+ Then I should see the "Login" link to the user login page
15
+ Then I should see the "Reset Password" button
16
+
17
+ Scenario: The reset token is blank
18
+ Given the reset token is blank
19
+ When I visit the user pswd reset page
20
+ Then I should see the view "users/pswd_forgot_form"
21
+
22
+ Scenario: The reset token is invalid
23
+ Given the reset token is invalid
24
+ When I visit the user pswd reset page
25
+ Then I should see the view "users/pswd_forgot_form"
26
+
27
+ Scenario: Enter an invalid email
28
+ Given I visit the user pswd reset page
29
+ Given I fill in "Your Email" with "wrong@wrong.com"
30
+ Given I fill in "New Password" with "newpassword"
31
+ Given I fill in "Confirm New Password" with "newpassword"
32
+ When I press "Reset Password"
33
+ Then I should see the view "users/pswd_reset_form"
34
+ Then the error message should be "Invalid Email"
35
+
36
+ Scenario: Enter a password does not match password confirmation
37
+ Given I visit the user pswd reset page
38
+ Given I fill in "Your Email" with "bill@smith.com"
39
+ Given I fill in "New Password" with "newpassword"
40
+ Given I fill in "Confirm New Password" with "wrong"
41
+ When I press "Reset Password"
42
+ Then I should see the view "users/pswd_reset_form"
43
+ Then the error message should be "Password Confirmation does not match"
44
+
45
+ Scenario: Enter a valid password
46
+ Given I visit the user pswd reset page
47
+ Given I fill in "Your Email" with "bill@smith.com"
48
+ Given I fill in "New Password" with "newpassword"
49
+ Given I fill in "Confirm New Password" with "newpassword"
50
+ When I press "Reset Password"
51
+ Then I should be logged in
52
+ Then the success message should be "Password Changed"
@@ -0,0 +1,46 @@
1
+ Then /^I should be logged in$/ do
2
+ response.session[:user_id].should_not be_nil
3
+ end
4
+
5
+ Then /^I should not be logged in$/ do
6
+ response.session[:user_id].should be_nil
7
+ end
8
+
9
+ Given /^I am not logged in$/ do
10
+ visit user_logout_path
11
+ end
12
+
13
+ Given /^I am logged in as a user$/ do
14
+ @login = User.make(:email => 'mock_login@mockemail.com', :password =>'mock_password', :access_level => User::ACCESS_LEVEL_DISABLED + 1)
15
+
16
+ visit user_login_path
17
+ fill_in "Email or Login Name", :with => 'mock_login@mockemail.com'
18
+ fill_in "Password", :with => 'mock_password'
19
+ click_button "Login"
20
+ end
21
+
22
+ Given /^I am logged in as an administrator$/ do
23
+ @login = User.make(:email => 'mock_login@mockemail.com', :password =>'mock_password', :access_level => User::ACCESS_LEVEL_ADMIN)
24
+
25
+ visit user_login_path
26
+ fill_in "Email or Login Name", :with => 'mock_login@mockemail.com'
27
+ fill_in "Password", :with => 'mock_password'
28
+ click_button "Login"
29
+ end
30
+
31
+
32
+ Given /^there is a user with email "([^\"]*)" and password "([^\"]*)"$/ do |email, password|
33
+ @login = User.make(:email => email, :password => password, :password_confirmation => password, :access_level => 100)
34
+ end
35
+
36
+ Given /^there is a disabled user with email "([^\"]*)" and password "([^\"]*)"$/ do |email, password|
37
+ @login = User.make(:email => email, :password => password, :password_confirmation => password, :access_level => User::ACCESS_LEVEL_DISABLED)
38
+ end
39
+
40
+ Then /^the remember me token should be set/ do
41
+ warning "Cannot test cookies in webrat" #response.cookies[:auth_token].should_not be_nil
42
+ end
43
+
44
+ Then /^the remember me token should not be set/ do
45
+ warning "Cannot test cookies in webrat" #response.cookies[:auth_token].should be_nil
46
+ end
@@ -0,0 +1,15 @@
1
+ When /^I visit the user pswd reset page$/ do
2
+ visit user_pswd_reset_path(:token => @reset_token)
3
+ end
4
+
5
+ Given /^the user reset token is set$/ do
6
+ @reset_token = User.set_reset_token(@user.email).reset_token
7
+ end
8
+
9
+ Given /^the reset token is blank$/ do
10
+ @reset_token = ""
11
+
12
+ end
13
+ Given /^the reset token is invalid$/ do
14
+ @reset_token = "invalid"
15
+ end
@@ -0,0 +1,15 @@
1
+ When /^I visit the user welcome page$/ do
2
+ visit user_welcome_path(:token => @welcome_token)
3
+ end
4
+
5
+ Given /^the user welcome token is set$/ do
6
+ @welcome_token = User.set_reset_token(@user.email).reset_token
7
+ end
8
+
9
+ Given /^the welcome token is blank$/ do
10
+ @welcome_token = ""
11
+
12
+ end
13
+ Given /^the welcome token is invalid$/ do
14
+ @welcome_token = "invalid"
15
+ end
@@ -0,0 +1,52 @@
1
+ Feature: welcome a new user and set the password
2
+ As an unlogged in user
3
+ I want to set my password for the first time
4
+
5
+ Background:
6
+ Given I am not logged in
7
+ Given there is a "user" with "email" set to "bill@smith.com"
8
+ Given the user welcome token is set
9
+
10
+ Scenario: Visit user welcome
11
+ When I visit the user welcome page
12
+ Then I should see the view "users/welcome_form"
13
+ Then the "Your Email" field should be required
14
+ Then I should see the "Login" link to the user login page
15
+ Then I should see the "Set Password" button
16
+
17
+ Scenario: The reset token is blank
18
+ Given the welcome token is blank
19
+ When I visit the user welcome page
20
+ Then I should see the view "users/pswd_forgot_form"
21
+
22
+ Scenario: The reset token is invalid
23
+ Given the welcome token is invalid
24
+ When I visit the user welcome page
25
+ Then I should see the view "users/pswd_forgot_form"
26
+
27
+ Scenario: Enter an invalid email
28
+ Given I visit the user welcome page
29
+ Given I fill in "Your Email" with "wrong@wrong.com"
30
+ Given I fill in "New Password" with "newpassword"
31
+ Given I fill in "Confirm New Password" with "newpassword"
32
+ When I press "Set Password"
33
+ Then I should see the view "users/welcome_form"
34
+ Then the error message should be "Invalid Email"
35
+
36
+ Scenario: Enter a password that does not match password confirmation
37
+ Given I visit the user welcome page
38
+ Given I fill in "Your Email" with "bill@smith.com"
39
+ Given I fill in "New Password" with "newpassword"
40
+ Given I fill in "Confirm New Password" with "wrong"
41
+ When I press "Set Password"
42
+ Then I should see the view "users/welcome_form"
43
+ Then the error message should be "Password Confirmation does not match"
44
+
45
+ Scenario: Enter a valid password
46
+ Given I visit the user welcome page
47
+ Given I fill in "Your Email" with "bill@smith.com"
48
+ Given I fill in "New Password" with "newpassword"
49
+ Given I fill in "Confirm New Password" with "newpassword"
50
+ When I press "Set Password"
51
+ Then I should be logged in
52
+ Then the success message should be "Password Created"
@@ -0,0 +1,191 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Admin::UsersController do
4
+ extend RulesEngineMacros
5
+ extend RulesEngineUsersMacros
6
+
7
+ before (:each) do
8
+ controller.stub!(:admin_access_required).and_return(true)
9
+ controller.instance_eval { flash.stub!(:sweep) }
10
+ end
11
+
12
+ describe "index" do
13
+ it_should_require_admin_access(:index)
14
+
15
+ it "should get the list of users" do
16
+ users = [1, 2]
17
+ User.should_receive(:paginate).and_return(users)
18
+ get :index
19
+ assigns[:users].should == users
20
+ end
21
+
22
+ describe "sorting the results" do
23
+ it "should sort by full_name by default" do
24
+ User.should_receive(:order_full_name).and_return(User)
25
+ get :index
26
+ end
27
+
28
+ it "should sort by full_name when query_type = full_name" do
29
+ User.should_receive(:order_full_name).and_return(User)
30
+ get :index, :query_type => "full_name"
31
+ end
32
+
33
+ it "should sort by login when query_type = login" do
34
+ User.should_receive(:order_login).and_return(User)
35
+ get :index, :query_type => "login"
36
+ end
37
+
38
+ it "should sort by email when query_type = email" do
39
+ User.should_receive(:order_email).and_return(User)
40
+ get :index, :query_type => "email"
41
+ end
42
+ end
43
+
44
+ describe "filtering the results" do
45
+ it "should sort by full_name when query_type = full_name and query set" do
46
+ User.should_receive(:by_ge_full_name).with('mock_query').and_return(User)
47
+ get :index, :query_type => "full_name", :query => "mock_query"
48
+ end
49
+
50
+ it "should sort by login when query_type = login and query set" do
51
+ User.should_receive(:by_ge_login).with('mock_query').and_return(User)
52
+ get :index, :query_type => "login", :query => "mock_query"
53
+ end
54
+
55
+ it "should sort by email when query_type = email and query set" do
56
+ User.should_receive(:by_ge_email).with('mock_query').and_return(User)
57
+ get :index, :query_type => "email", :query => "mock_query"
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "show" do
63
+ it_should_require_admin_access(:show)
64
+
65
+ it "should get the user record with the ID" do
66
+ User.should_receive(:find).with("123")
67
+ get :show, :id => 123
68
+ end
69
+ end
70
+
71
+ describe "new" do
72
+ it_should_require_admin_access(:new)
73
+
74
+ it "should provide a fresh user object" do
75
+ User.should_receive :new
76
+ get :new
77
+ end
78
+ end
79
+
80
+ describe "create" do
81
+ it_should_require_admin_access(:create)
82
+
83
+ before do
84
+ @user = mock_model(User, :save => false)
85
+ User.stub!(:new).and_return(@user)
86
+ end
87
+
88
+ describe "creation failed" do
89
+ it "should render the 'new' template" do
90
+ post :create, :user => { :key => "value" }
91
+ response.should render_template(:new)
92
+ end
93
+ end
94
+
95
+ describe "user created" do
96
+ before do
97
+ @user.stub!(:save).and_return(true)
98
+ end
99
+
100
+ it "should save the user" do
101
+ @user.should_receive :save
102
+ post :create, :user => { :key => "value" }
103
+ end
104
+
105
+ it "should display a flash success message" do
106
+ post :create, :user => { :key => "value" }
107
+ flash[:success].should_not be_blank
108
+ end
109
+
110
+ it "should redirect to the show user page" do
111
+ post :create, :user => { :key => "value" }
112
+ response.should redirect_to(admin_user_path(@user))
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "edit" do
118
+ it_should_require_admin_access(:edit)
119
+
120
+ it "should get the user with the specified ID" do
121
+ User.should_receive(:find).with "123"
122
+ put :edit, :id => 123
123
+ end
124
+ end
125
+
126
+ describe "update" do
127
+ it_should_require_admin_access(:update)
128
+
129
+ before do
130
+ @user = mock_model(User, :update_attributes => false)
131
+ User.stub!(:find).and_return(@user)
132
+ end
133
+
134
+ describe "update failed" do
135
+ it "should render the edit template on failure" do
136
+ put :update, :id => 1, :user => { :key => "value" }
137
+ response.should render_template(:edit)
138
+ end
139
+ end
140
+
141
+ describe "success" do
142
+ before do
143
+ @user.stub!(:update_attributes).and_return(true)
144
+ end
145
+
146
+ it "should save the user" do
147
+ @user.should_receive(:update_attributes).with("key" => "value")
148
+ put :update, :id => 1, :user => { :key => "value" }
149
+ end
150
+
151
+ it "should display a flash success message" do
152
+ put :update, :id => 1, :user => { :key => "value" }
153
+ flash[:success].should_not be_blank
154
+ end
155
+
156
+ it "should redirect to the profile of the user" do
157
+ put :update, :id => 1, :user => { :key => "value" }
158
+ response.should redirect_to(admin_user_path(@user))
159
+ end
160
+ end
161
+ end
162
+
163
+ describe "destroy" do
164
+ it_should_require_admin_access(:destroy)
165
+
166
+ before do
167
+ @user = mock_model(User, :destroy => true)
168
+ User.stub!(:find).and_return(@user)
169
+ end
170
+
171
+ it "should find the user with the given ID" do
172
+ User.should_receive(:find).with("123").and_return @user
173
+ delete :destroy, :id => 123
174
+ end
175
+
176
+ it "should destroy the found user" do
177
+ @user.should_receive :destroy
178
+ delete :destroy, :id => 123
179
+ end
180
+
181
+ it "should redirect to the users list after deletion" do
182
+ delete :destroy, :id => 123
183
+ response.should redirect_to(admin_users_path)
184
+ end
185
+
186
+ it "should show a flash sucess message" do
187
+ delete :destroy, :id => 123
188
+ flash[:success].should_not be_blank
189
+ end
190
+ end
191
+ end