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,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,19 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ # Use ISO 8601 format for JSON serialized times and dates.
15
+ ActiveSupport.use_standard_json_time_format = true
16
+
17
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
18
+ # if you're including raw json in an HTML page.
19
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying cookie session data integrity.
4
+ # If you change this key, all old sessions will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.session = {
8
+ :key => '_railsenv_session',
9
+ :secret => '5b6ce90fd6469cb00f7486f06c61280817a3fde17955abe87a4ae1f02547c6f65d54a1a04e843e0bf4f1694935aa95bddf2f57ce886ffb395a89a3af01d07b4a'
10
+ }
11
+
12
+ # Use the database for sessions instead of the cookie-based default,
13
+ # which shouldn't be used to store highly confidential information
14
+ # (create the session table with "rake db:sessions:create")
15
+ # ActionController::Base.session_store = :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,43 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+
4
+ # Sample of regular route:
5
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
+ # Keep in mind you can assign values other than :controller and :action
7
+
8
+ # Sample of named route:
9
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
+ # This route can be invoked with purchase_url(:id => product.id)
11
+
12
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
13
+ # map.resources :products
14
+
15
+ # Sample resource route with options:
16
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
+
18
+ # Sample resource route with sub-resources:
19
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
+
21
+ # Sample resource route with more complex sub-resources
22
+ # map.resources :products do |products|
23
+ # products.resources :comments
24
+ # products.resources :sales, :collection => { :recent => :get }
25
+ # end
26
+
27
+ # Sample resource route within a namespace:
28
+ # map.namespace :admin do |admin|
29
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
+ # admin.resources :products
31
+ # end
32
+
33
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
+ # map.root :controller => "welcome"
35
+
36
+ # See how all your routes lay out with "rake routes"
37
+
38
+ # Install the default routes as the lowest priority.
39
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
+ # consider removing the them or commenting them out if you're using named routes and resources.
41
+ map.connect ':controller/:action/:id'
42
+ map.connect ':controller/:action/:id.:format'
43
+ end
@@ -0,0 +1 @@
1
+ S
@@ -0,0 +1 @@
1
+ # Logfile created on Tue Mar 09 23:35:57 +1100 2010
@@ -0,0 +1 @@
1
+ # Logfile created on Tue Feb 23 14:37:00 +1100 2010
data/spec/rcov.opts ADDED
@@ -0,0 +1,3 @@
1
+ --exclude "spec/*,gems/*,tmp/,features/*"
2
+ --rails
3
+ --aggregate coverage.data
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ # class MockControllerUsersController < ActionController::Base
4
+ #
5
+ # end
6
+ #
7
+ describe "ControllerUserMail", :type => :helper do
8
+ # controller_name 'MockControllerUsers'
9
+
10
+ describe "host name" do
11
+ it "should set the host name to localhost:3000" do
12
+ RulesEngine::ControllerUserMail.host.should == "localhost:3000"
13
+ end
14
+
15
+ it "should set the host name to the host defined" do
16
+ RulesEngine::ControllerUserMail.host = "mock host"
17
+ RulesEngine::ControllerUserMail.host.should == "mock host"
18
+ end
19
+ end
20
+
21
+ describe "from" do
22
+ it "should set the from to Do Not Reply <do_not_reply@localhost:3000>" do
23
+ RulesEngine::ControllerUserMail.from.should == "Do Not Reply <do_not_reply@localhost:3000>"
24
+ end
25
+
26
+ it "should set the host name to the host defined" do
27
+ RulesEngine::ControllerUserMail.from = "mock from"
28
+ RulesEngine::ControllerUserMail.from.should == "mock from"
29
+ end
30
+ end
31
+
32
+ describe "prefix" do
33
+ it "should be blank by default" do
34
+ RulesEngine::ControllerUserMail.prefix.should be_blank
35
+ end
36
+
37
+ it "should set the host name to the host defined" do
38
+ RulesEngine::ControllerUserMail.prefix = "mock from"
39
+ RulesEngine::ControllerUserMail.prefix.should == "mock from"
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,337 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ class MockControllerUsersController < ActionController::Base
4
+
5
+ end
6
+
7
+ describe "ControllerUsers", :type => :controller do
8
+ controller_name 'MockControllerUsers'
9
+
10
+ before(:each) do
11
+ @current_user = mock_model(User)
12
+ @current_user.stub!(:remember_token).and_return('mock_token')
13
+ @current_user.stub!(:remember_token_expires_at).and_return(30.days.from_now)
14
+
15
+ User.stub!(:find_by_id).and_return(nil)
16
+ User.stub!(:authenticate_by_email).and_return(nil)
17
+ User.stub!(:authenticate_by_login).and_return(nil)
18
+ User.stub!(:authenticate_by_remember_token).and_return(nil)
19
+
20
+ controller.stub!(:cookies).and_return(:auth_token => 'mock_token')
21
+ controller.stub!(:session).and_return(:user_id => 'mock_session_id')
22
+ @credentials = ActionController::HttpAuthentication::Basic.encode_credentials("mock_name", "mock_password")
23
+ request.env['HTTP_AUTHORIZATION'] = @credentials
24
+
25
+ @format = mock("format")
26
+ @format.stub!(:js).and_yield(controller)
27
+ @format.stub!(:html).and_yield(controller)
28
+ controller.stub!(:respond_to).and_yield(@format)
29
+ @js = ""
30
+ controller.stub!(:render).with(:update).and_yield(@js)
31
+
32
+ controller.stub!(:user_login_path).and_return('/login')
33
+ controller.stub!(:root_path).and_return('/root')
34
+ end
35
+
36
+ describe "getting the current user" do
37
+ it "should try the session" do
38
+ User.should_receive(:find_by_id).with('mock_session_id').and_return(@current_user)
39
+ controller.current_user.should == @current_user
40
+ end
41
+
42
+ it "should try basic authentication by email" do
43
+ User.should_receive(:authenticate_by_email).with("mock_name", "mock_password").and_return(@current_user)
44
+ controller.current_user.should == @current_user
45
+ end
46
+
47
+ it "should try basic authentication by login" do
48
+ User.should_receive(:authenticate_by_login).with("mock_name", "mock_password").and_return(@current_user)
49
+ controller.current_user.should == @current_user
50
+ end
51
+
52
+
53
+ it "should get the cookie" do
54
+ User.stub!(:authenticate_by_remember_token).with('mock_token').and_return(@current_user)
55
+ controller.current_user.should == @current_user
56
+ end
57
+
58
+ it "should return nil if previous calls to the current user have failed" do
59
+ controller.current_user.should be_nil
60
+ controller.current_user.should be_nil
61
+ end
62
+
63
+ it "should return the current user if previous calls to current user have passed" do
64
+ User.stub!(:find_by_id).once.and_return(@current_user)
65
+ controller.current_user.should == @current_user
66
+ controller.current_user.should == @current_user
67
+ end
68
+ end
69
+
70
+ describe "checking the login" do
71
+ it "should tell us if the user is logged in" do
72
+ controller.should_receive(:current_user).and_return(@current_user)
73
+ controller.should be_logged_in
74
+ end
75
+
76
+ it "should tell us if the user is logged in" do
77
+ controller.should_receive(:current_user).and_return(nil)
78
+ controller.should_not be_logged_in
79
+ end
80
+ end
81
+
82
+ describe "checking for an administrator" do
83
+ before(:each) do
84
+ controller.stub!(:current_user).and_return(@current_user)
85
+ end
86
+
87
+ it "should tell us if the current user is an administrator" do
88
+ @current_user.should_receive(:access_level).and_return(User::ACCESS_LEVEL_ADMIN)
89
+ controller.should be_logged_in
90
+ controller.should be_logged_in_as_admin
91
+ end
92
+
93
+ it "should tell us if the current user is not an administrator" do
94
+ @current_user.should_receive(:access_level).and_return(101)
95
+ controller.should be_logged_in
96
+ controller.should_not be_logged_in_as_admin
97
+ end
98
+ end
99
+
100
+ describe "checking for a disabled account" do
101
+ before(:each) do
102
+ controller.stub!(:current_user).and_return(@current_user)
103
+ end
104
+
105
+ it "should tell us if the current user's account is disabled" do
106
+ @current_user.should_receive(:access_level).and_return(User::ACCESS_LEVEL_DISABLED)
107
+ controller.should be_logged_in
108
+ controller.should be_logged_in_disabled
109
+ end
110
+ end
111
+
112
+ describe "login required" do
113
+ before(:each) do
114
+ controller.stub!(:logged_in?).and_return(false)
115
+ controller.stub!(:redirect_to)
116
+ end
117
+
118
+ it "should pass if the user is logged in" do
119
+ controller.should_receive(:logged_in?).and_return(true)
120
+ controller.login_required
121
+ flash[:error].should be_blank
122
+ end
123
+
124
+ it "should set an error message if the user is not logged in" do
125
+ controller.should_receive(:access_denied)
126
+ controller.login_required
127
+ flash[:error].should_not be_blank
128
+ end
129
+
130
+ it "should redirect to login page if the user is not logged in" do
131
+ controller.should_receive(:redirect_to).with('/login')
132
+ controller.login_required
133
+ end
134
+
135
+ it "should set the js window location to the login page if the user is not logged in" do
136
+ @format.stub!(:html)
137
+ controller.should_receive(:render).with(:update).and_yield(@js)
138
+ controller.login_required
139
+ @js.should == "window.location.href = '/login';"
140
+ end
141
+ end
142
+
143
+ describe "admin access required" do
144
+ before(:each) do
145
+ controller.stub!(:logged_in?).and_return(true)
146
+ controller.stub!(:logged_in_as_admin?).and_return(false)
147
+ controller.stub!(:redirect_to)
148
+ controller.stub!(:current_user).and_return(@current_user)
149
+ end
150
+
151
+ it "should pass if the user is logged in and is an administrator" do
152
+ controller.stub!(:logged_in_as_admin?).and_return(true)
153
+ @current_user.stub!(:access_level).and_return(User::ACCESS_LEVEL_ADMIN)
154
+ controller.admin_access_required
155
+
156
+ flash[:error].should be_blank
157
+ end
158
+
159
+ it "should set an error message if the user is not logged in" do
160
+ controller.stub!(:logged_in?).and_return(false)
161
+ controller.admin_access_required
162
+ flash[:error].should_not be_blank
163
+ end
164
+
165
+ it "should redirect to the login page if the user is not logged in" do
166
+ controller.stub!(:logged_in?).and_return(false)
167
+ controller.should_receive(:redirect_to).with('/login')
168
+ controller.admin_access_required
169
+ end
170
+
171
+ it "should set the js window location to the login page if the user is not logged in" do
172
+ controller.stub!(:logged_in?).and_return(false)
173
+ @format.stub!(:html)
174
+ controller.should_receive(:render).with(:update).and_yield(@js)
175
+ controller.admin_access_required
176
+ @js.should == "window.location.href = '/login';"
177
+ end
178
+
179
+ it "should set an error message if the user is not an administrator" do
180
+ @current_user.stub!(:access_level).and_return(101)
181
+ controller.admin_access_required
182
+ flash[:error].should_not be_blank
183
+ end
184
+
185
+ it "should redirect to root path if the user is not an administrator" do
186
+ @current_user.stub!(:access_level).and_return(101)
187
+ controller.should_receive(:redirect_to).with('/root')
188
+ controller.admin_access_required
189
+ end
190
+
191
+ it "should set the js window location to the login page if the user is not an administrator" do
192
+ @current_user.stub!(:access_level).and_return(101)
193
+ @format.stub!(:html)
194
+ controller.should_receive(:render).with(:update).and_yield(@js)
195
+ controller.admin_access_required
196
+ @js.should == "window.location.href = '/root';"
197
+ end
198
+
199
+ end
200
+
201
+ describe "user access level" do
202
+ it "should return the admin access level" do
203
+ @current_user.stub!(:access_level).and_return(User::ACCESS_LEVEL_ADMIN)
204
+ controller.user_access_level(@current_user).should == "Administrator"
205
+ end
206
+
207
+ it "should return the account disabled access level" do
208
+ @current_user.stub!(:access_level).and_return(User::ACCESS_LEVEL_DISABLED)
209
+ controller.user_access_level(@current_user).should == "Account Disabled"
210
+ end
211
+ end
212
+
213
+ describe "user access levels" do
214
+ it "should return the access levels" do
215
+ controller.user_access_levels.should include ["Administrator", User::ACCESS_LEVEL_ADMIN]
216
+ controller.user_access_levels.should include ["Account Disabled", User::ACCESS_LEVEL_DISABLED]
217
+ end
218
+ end
219
+
220
+ describe "defining new access levels" do
221
+ before(:each) do
222
+ MockControllerUsersController.define_access_level(:reporter, 200)
223
+ end
224
+
225
+ describe "_access_level" do
226
+ it "should return the access level" do
227
+ ActionController::Base.reporter_access_level.should == 200
228
+ end
229
+ end
230
+
231
+ describe "logged_in_as_? method" do
232
+ before(:each) do
233
+ controller.stub!(:current_user).and_return(@current_user)
234
+ end
235
+
236
+ it "should pass if the current user has the access level" do
237
+ @current_user.stub!(:access_level).and_return(200)
238
+ controller.should be_logged_in
239
+ controller.should be_logged_in_as_reporter
240
+ end
241
+
242
+ it "should pass if the current user has an access level greater than that required" do
243
+ @current_user.stub!(:access_level).and_return(201)
244
+ controller.should be_logged_in
245
+ controller.should be_logged_in_as_reporter
246
+ end
247
+
248
+ it "should fail if the current user has an access level less than that required" do
249
+ @current_user.stub!(:access_level).and_return(199)
250
+ controller.should be_logged_in
251
+ controller.should_not be_logged_in_as_reporter
252
+ end
253
+ end
254
+
255
+ describe "_access_required method" do
256
+ before(:each) do
257
+ controller.stub!(:logged_in?).and_return(true)
258
+ controller.stub!(:redirect_to)
259
+ controller.stub!(:current_user).and_return(@current_user)
260
+ end
261
+
262
+ it "should pass if the user is logged in and has the access level" do
263
+ controller.stub!(:logged_in_as_admin?).and_return(true)
264
+ @current_user.stub!(:access_level).and_return(200)
265
+ controller.reporter_access_required
266
+
267
+ flash[:error].should be_blank
268
+ end
269
+
270
+ it "should pass if the user is logged in and has an access level greater than that required" do
271
+ controller.stub!(:logged_in_as_admin?).and_return(true)
272
+ @current_user.stub!(:access_level).and_return(201)
273
+ controller.reporter_access_required
274
+
275
+ flash[:error].should be_blank
276
+ end
277
+
278
+ it "should set an error message if the user is not logged in" do
279
+ controller.stub!(:logged_in?).and_return(false)
280
+ controller.admin_access_required
281
+ flash[:error].should_not be_blank
282
+ end
283
+
284
+ it "should redirect to the login page if the user is not logged in" do
285
+ controller.stub!(:logged_in?).and_return(false)
286
+ controller.should_receive(:access_denied)
287
+ controller.reporter_access_required
288
+ end
289
+
290
+ it "should set an error message if the user is does not have the access level required" do
291
+ controller.stub!(:logged_in_as_admin?).and_return(false)
292
+ @current_user.stub!(:access_level).and_return(199)
293
+ controller.should_receive(:user_access_denied)
294
+ controller.reporter_access_required
295
+ flash[:error].should_not be_blank
296
+ end
297
+
298
+ it "should redirect to root path if the user is does not have the access level required" do
299
+ controller.stub!(:logged_in_as_admin?).and_return(false)
300
+ @current_user.stub!(:access_level).and_return(199)
301
+ controller.should_receive(:user_access_denied)
302
+ controller.reporter_access_required
303
+ end
304
+ end
305
+
306
+ describe "user access level" do
307
+ it "should return the admin access level" do
308
+ @current_user.stub!(:access_level).and_return(200)
309
+ controller.user_access_level(@current_user).should == "Reporter"
310
+ end
311
+ end
312
+
313
+ describe "user access levels" do
314
+ it "should return the access levels" do
315
+ controller.user_access_levels.should include ["Reporter", 200]
316
+ end
317
+ end
318
+
319
+ describe "user time zone" do
320
+ it "Set the time zone to the user's timezone" do
321
+ controller.stub!(:current_user).and_return(@current_user)
322
+ @current_user.stub!(:time_zone).and_return('mock time zone')
323
+ Time.should_receive(:zone=).with('mock time zone')
324
+
325
+ controller.set_timezone
326
+ end
327
+
328
+ it "Set the time zone to the default timezone when not set" do
329
+ controller.stub!(:current_user).and_return(nil)
330
+ # @current_user.stub!(:time_zone).and_return('mock time zone')
331
+ Time.should_receive(:zone=).with('Eastern Time (US & Canada)')
332
+
333
+ controller.set_timezone
334
+ end
335
+ end
336
+ end
337
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,30 @@
1
+ # The minimal Rails project was created to run specs against using:
2
+ # rails -m http://github.com/robinsp/rails_templates/raw/master/minimal.rb railsenv
3
+
4
+
5
+ ENV["RAILS_ENV"] = "test"
6
+ require File.expand_path(File.dirname(__FILE__) + "/railsenv/config/environment")
7
+ require 'spec'
8
+ require 'spec/rails'
9
+ require 'spec/autorun'
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.use_transactional_fixtures = true
13
+ config.use_instantiated_fixtures = false
14
+ # config.mock_with :mocha
15
+ end
16
+
17
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/railsenv/log/debug.log")
18
+
19
+ # require File.expand_path(File.dirname(__FILE__) + "/../rails_generators/templates/app/models/user.rb")
20
+ class User < ActiveRecord::Base
21
+ ACCESS_LEVEL_ADMIN = 999 # administrator access
22
+ ACCESS_LEVEL_DISABLED = 0 # disabled access
23
+ def self.columns() @columns ||= []; end
24
+ # def self.column(name, sql_type = nil, default = nil, null = true)
25
+ # columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
26
+ # end
27
+
28
+ end
29
+
30
+ Dir["#{File.dirname(__FILE__)}/../lib/*.rb"].each {|f| require f}
data/tasks/rspec.rake ADDED
@@ -0,0 +1,18 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ desc "Run all specs in spec directory"
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_files = FileList['spec/**/*_spec.rb']
6
+ end
7
+
8
+ namespace :spec do
9
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
10
+ Spec::Rake::SpecTask.new(:rcov) do |t|
11
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/../spec/spec.opts\""]
12
+ t.spec_files = FileList['spec/**/*_spec.rb']
13
+ t.rcov = true
14
+ t.rcov_opts = lambda do
15
+ IO.readlines("#{File.dirname(__FILE__)}/../spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
16
+ end
17
+ end
18
+ end