muck-users 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,12 +5,19 @@
5
5
  The muck users engine is part of the muck framework and relies upon the muck_engine as well as authlogic. Both gems should be installed automatically when you install the muck_users engine.
6
6
 
7
7
  sudo gem install muck_users
8
+
9
+ Use search logic for searching users. Add this to environment.rb:
10
+
11
+ config.gem "binarylogic-searchlogic",
12
+ :lib => 'searchlogic',
13
+ :source => 'http://gems.github.com',
14
+ :version => '~> 2.0.0'
15
+
8
16
 
9
17
  In addition, you will need to install the ssl_requirement plugin (http://github.com/rails/ssl_requirement/tree/master) into your Rails project:
10
18
 
11
19
  ruby script/plugin install ssl_requirement
12
20
 
13
-
14
21
  == General information
15
22
  This engine implements authlogic. Some of the code contained was taken from here:
16
23
  http://railsforum.com/viewtopic.php?id=14216 and here
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ begin
13
13
  gem.authors = ["Justin Ball"]
14
14
  gem.rubyforge_project = "muck-users"
15
15
  gem.add_dependency "authlogic"
16
+ gem.add_dependency "binarylogic-searchlogic"
16
17
  gem.add_dependency "bcrypt-ruby"
17
18
  gem.add_dependency "muck-engine"
18
19
  gem.files.include %w( tasks/*
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -1,6 +1,6 @@
1
1
  class Admin::Muck::UsersController < Admin::Muck::BaseController
2
2
  unloadable
3
-
3
+
4
4
  before_filter :get_user, :only => [:update, :destroy]
5
5
 
6
6
  def index
@@ -40,7 +40,7 @@ class Admin::Muck::UsersController < Admin::Muck::BaseController
40
40
  def search_results
41
41
  @users = User.do_search( params[:query] ).paginate(:page => @page, :per_page => @per_page )
42
42
  end
43
-
43
+
44
44
  def search
45
45
  search_results
46
46
  respond_to do |format|
@@ -22,6 +22,8 @@ module ActiveRecord
22
22
  domain_tld_regex = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'.freeze
23
23
  email_regex = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
24
24
 
25
+ before_save :lower_login
26
+
25
27
  class_eval <<-EOV
26
28
  validates_format_of :login, :with => /^[a-z0-9-]+$/i, :message => 'may only contain letters, numbers or a hyphen.'
27
29
  validates_format_of :email, :with => email_regex, :message => 'does not look like a valid email address.'
@@ -40,8 +42,8 @@ module ActiveRecord
40
42
 
41
43
  # class methods
42
44
  module SingletonMethods
43
- def do_search( query )
44
- User.find(:all, :conditions => [ "email LIKE ? OR first_name LIKE ? OR last_name LIKE ?", '%' + query + '%', '%' + query + '%', '%' + query + '%' ])
45
+ def do_search(query)
46
+ User.search(query)
45
47
  end
46
48
 
47
49
  def inactive_count
@@ -159,6 +161,11 @@ module ActiveRecord
159
161
  # def confirmed?
160
162
  # end
161
163
 
164
+ #lowercase all logins
165
+ def lower_login
166
+ self.login = self.login.nil? ? nil : self.login.downcase
167
+ end
168
+
162
169
  def activate!
163
170
  self.update_attribute(:activated_at, Time.now.utc)
164
171
  end
Binary file
data/muck-users.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{muck-users}
5
- s.version = "0.1.5"
5
+ s.version = "0.1.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Justin Ball"]
@@ -186,7 +186,9 @@ Gem::Specification.new do |s|
186
186
  "locales/zh-TW.yml",
187
187
  "locales/zh.yml",
188
188
  "locales/zh.yml",
189
+ "muck-users-0.1.4.gem",
189
190
  "muck-users.gemspec",
191
+ "pkg/muck-users-0.1.6.gem",
190
192
  "public/images/profile_default.jpg",
191
193
  "rails/init.rb",
192
194
  "rails/init.rb",
@@ -426,6 +428,7 @@ Gem::Specification.new do |s|
426
428
  "test/rails_root/test/unit/muck_user_mailer_test.rb",
427
429
  "test/rails_root/test/unit/permission_test.rb",
428
430
  "test/rails_root/test/unit/role_test.rb",
431
+ "test/rails_root/test/unit/user_test.rb",
429
432
  "test/rails_root/vendor/plugins/ssl_requirement/README",
430
433
  "test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb",
431
434
  "test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb",
@@ -477,6 +480,7 @@ Gem::Specification.new do |s|
477
480
  "test/rails_root/test/unit/muck_user_mailer_test.rb",
478
481
  "test/rails_root/test/unit/permission_test.rb",
479
482
  "test/rails_root/test/unit/role_test.rb",
483
+ "test/rails_root/test/unit/user_test.rb",
480
484
  "test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb",
481
485
  "test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb"
482
486
  ]
@@ -487,15 +491,18 @@ Gem::Specification.new do |s|
487
491
 
488
492
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
489
493
  s.add_runtime_dependency(%q<authlogic>, [">= 0"])
494
+ s.add_runtime_dependency(%q<binarylogic-searchlogic>, [">= 0"])
490
495
  s.add_runtime_dependency(%q<bcrypt-ruby>, [">= 0"])
491
496
  s.add_runtime_dependency(%q<muck-engine>, [">= 0"])
492
497
  else
493
498
  s.add_dependency(%q<authlogic>, [">= 0"])
499
+ s.add_dependency(%q<binarylogic-searchlogic>, [">= 0"])
494
500
  s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
495
501
  s.add_dependency(%q<muck-engine>, [">= 0"])
496
502
  end
497
503
  else
498
504
  s.add_dependency(%q<authlogic>, [">= 0"])
505
+ s.add_dependency(%q<binarylogic-searchlogic>, [">= 0"])
499
506
  s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
500
507
  s.add_dependency(%q<muck-engine>, [">= 0"])
501
508
  end
Binary file
data/rails/init.rb CHANGED
@@ -14,5 +14,19 @@ else
14
14
  end
15
15
  end
16
16
 
17
+ if config.respond_to?(:gems)
18
+ config.gem "binarylogic-searchlogic", :lib => 'searchlogic', :source => 'http://gems.github.com', :version => "~> 2.0.0"
19
+ else
20
+ begin
21
+ require 'binarylogic-searchlogic'
22
+ rescue LoadError
23
+ begin
24
+ gem 'binarylogic-searchlogic'
25
+ rescue Gem::LoadError
26
+ puts "Please install the binarylogic-searchlogic gem"
27
+ end
28
+ end
29
+ end
30
+
17
31
  require 'muck_users'
18
- require 'muck_users/initialize_routes'
32
+ require 'muck_users/initialize_routes'
@@ -138,14 +138,8 @@
138
138
  <span class="ruby-identifier">domain_head_regex</span> = <span class="ruby-value str">'(?:[A-Z0-9\-]+\.)+'</span>.<span class="ruby-identifier">freeze</span>
139
139
  <span class="ruby-identifier">domain_tld_regex</span> = <span class="ruby-value str">'(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'</span>.<span class="ruby-identifier">freeze</span>
140
140
  <span class="ruby-identifier">email_regex</span> = <span class="ruby-node">/\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i</span>
141
-
142
- <span class="ruby-identifier">has_attached_file</span> <span class="ruby-identifier">:photo</span>,
143
- <span class="ruby-identifier">:styles</span> =<span class="ruby-operator">&gt;</span> { <span class="ruby-identifier">:medium</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;300x300&gt;&quot;</span>,
144
- <span class="ruby-identifier">:thumb</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;100x100&gt;&quot;</span>,
145
- <span class="ruby-identifier">:icon</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;50x50&gt;&quot;</span> },
146
- <span class="ruby-identifier">:default_url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/images/profile_default.jpg&quot;</span>
147
-
148
- <span class="ruby-identifier">class_eval</span> <span class="ruby-value str">&quot;validates_format_of :login, :with =&gt; /^[a-z0-9-]+$/i, :message =&gt; 'may only contain letters, numbers or a hyphen.'\nvalidates_format_of :email, :with =&gt; email_regex, :message =&gt; 'does not look like a valid email address.'\n\n# prevents a user from submitting a crafted form that bypasses activation\nattr_protected :crypted_password, :password_salt, :persistence_token, :single_access_token, :perishable_token, :login_count,\n:failed_login_count, :last_request_at, :last_login_at, :current_login_at, :current_login_ip, :last_login_ip,\n:terms_of_service, :time_zone, :disabled_at, :activated_at, :created_at, :updated_at, :photo_file_name,\n:photo_content_type, :photo_file_size\n&quot;</span>
141
+
142
+ <span class="ruby-identifier">class_eval</span> <span class="ruby-value str">&quot;validates_format_of :login, :with =&gt; /^[a-z0-9-]+$/i, :message =&gt; 'may only contain letters, numbers or a hyphen.'\nvalidates_format_of :email, :with =&gt; email_regex, :message =&gt; 'does not look like a valid email address.'\n\n# prevents a user from submitting a crafted form that bypasses activation\nattr_protected :crypted_password, :password_salt, :persistence_token, :single_access_token, :perishable_token, :login_count,\n:failed_login_count, :last_request_at, :last_login_at, :current_login_at, :current_login_ip, :last_login_ip,\n:terms_of_service, :time_zone, :disabled_at, :activated_at, :created_at, :updated_at\n&quot;</span>
149
143
 
150
144
  <span class="ruby-identifier">include</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">MuckUser</span><span class="ruby-operator">::</span><span class="ruby-constant">InstanceMethods</span>
151
145
  <span class="ruby-identifier">extend</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">MuckUser</span><span class="ruby-operator">::</span><span class="ruby-constant">SingletonMethods</span>
@@ -143,7 +143,7 @@ def confirmed? end
143
143
  onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
144
144
  <div class="method-source-code" id="M000042-source">
145
145
  <pre>
146
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 170</span>
146
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 163</span>
147
147
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">activate!</span>
148
148
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">update_attribute</span>(<span class="ruby-identifier">:activated_at</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">utc</span>)
149
149
  <span class="ruby-keyword kw">end</span>
@@ -169,7 +169,7 @@ Authlogic automatically executes the following methods
169
169
  onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
170
170
  <div class="method-source-code" id="M000041-source">
171
171
  <pre>
172
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 160</span>
172
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 153</span>
173
173
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active?</span>
174
174
  <span class="ruby-operator">!</span><span class="ruby-identifier">activated_at</span>.<span class="ruby-identifier">blank?</span>
175
175
  <span class="ruby-keyword kw">end</span>
@@ -192,7 +192,7 @@ Authlogic automatically executes the following methods
192
192
  onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
193
193
  <div class="method-source-code" id="M000038-source">
194
194
  <pre>
195
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 142</span>
195
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 135</span>
196
196
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">admin?</span>
197
197
  <span class="ruby-identifier">has_role?</span>(<span class="ruby-value str">'administrator'</span>)
198
198
  <span class="ruby-keyword kw">end</span>
@@ -215,7 +215,7 @@ Authlogic automatically executes the following methods
215
215
  onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
216
216
  <div class="method-source-code" id="M000039-source">
217
217
  <pre>
218
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 146</span>
218
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 139</span>
219
219
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">can_edit?</span>(<span class="ruby-identifier">user</span>)
220
220
  <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">nil?</span>
221
221
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">admin?</span>
@@ -239,7 +239,7 @@ Authlogic automatically executes the following methods
239
239
  onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
240
240
  <div class="method-source-code" id="M000032-source">
241
241
  <pre>
242
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 104</span>
242
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 97</span>
243
243
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deliver_activation_confirmation!</span>
244
244
  <span class="ruby-identifier">reset_perishable_token!</span>
245
245
  <span class="ruby-constant">MuckUserMailer</span>.<span class="ruby-identifier">deliver_activation_confirmation</span>(<span class="ruby-keyword kw">self</span>)
@@ -263,7 +263,7 @@ Authlogic automatically executes the following methods
263
263
  onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
264
264
  <div class="method-source-code" id="M000033-source">
265
265
  <pre>
266
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 109</span>
266
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 102</span>
267
267
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deliver_activation_instructions!</span>
268
268
  <span class="ruby-identifier">reset_perishable_token!</span>
269
269
  <span class="ruby-constant">MuckUserMailer</span>.<span class="ruby-identifier">deliver_activation_instructions</span>(<span class="ruby-keyword kw">self</span>)
@@ -287,7 +287,7 @@ Authlogic automatically executes the following methods
287
287
  onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
288
288
  <div class="method-source-code" id="M000034-source">
289
289
  <pre>
290
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 114</span>
290
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 107</span>
291
291
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deliver_password_reset_instructions!</span>
292
292
  <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active?</span>
293
293
  <span class="ruby-identifier">reset_perishable_token!</span>
@@ -315,7 +315,7 @@ Authlogic automatically executes the following methods
315
315
  onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
316
316
  <div class="method-source-code" id="M000035-source">
317
317
  <pre>
318
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 123</span>
318
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 116</span>
319
319
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deliver_username_request!</span>
320
320
  <span class="ruby-constant">MuckUserMailer</span>.<span class="ruby-identifier">deliver_username_request</span>(<span class="ruby-keyword kw">self</span>)
321
321
  <span class="ruby-keyword kw">end</span>
@@ -338,7 +338,7 @@ Authlogic automatically executes the following methods
338
338
  onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
339
339
  <div class="method-source-code" id="M000031-source">
340
340
  <pre>
341
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 100</span>
341
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 93</span>
342
342
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deliver_welcome_email</span>
343
343
  <span class="ruby-constant">MuckUserMailer</span>.<span class="ruby-identifier">deliver_welcome_notification</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">GlobalConfig</span>.<span class="ruby-identifier">send_welcome</span>
344
344
  <span class="ruby-keyword kw">end</span>
@@ -361,7 +361,7 @@ Authlogic automatically executes the following methods
361
361
  onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
362
362
  <div class="method-source-code" id="M000045-source">
363
363
  <pre>
364
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 186</span>
364
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 179</span>
365
365
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">display_name</span>
366
366
  <span class="ruby-constant">CGI</span><span class="ruby-operator">::</span><span class="ruby-identifier">escapeHTML</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">login</span>)
367
367
  <span class="ruby-keyword kw">end</span>
@@ -384,7 +384,7 @@ Authlogic automatically executes the following methods
384
384
  onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
385
385
  <div class="method-source-code" id="M000044-source">
386
386
  <pre>
387
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 178</span>
387
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 171</span>
388
388
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">full_name</span>
389
389
  <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">first_name</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">last_name</span>.<span class="ruby-identifier">blank?</span>
390
390
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">display_name</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-value str">'Deleted user'</span>
@@ -411,7 +411,7 @@ Authlogic automatically executes the following methods
411
411
  onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
412
412
  <div class="method-source-code" id="M000037-source">
413
413
  <pre>
414
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 136</span>
414
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 129</span>
415
415
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_role?</span>(<span class="ruby-identifier">rolename</span>)
416
416
  <span class="ruby-ivar">@roles</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">roles</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">role</span><span class="ruby-operator">|</span> <span class="ruby-identifier">role</span>.<span class="ruby-identifier">rolename</span>}
417
417
  <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@roles</span>
@@ -440,7 +440,7 @@ save without block as usual.
440
440
  onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
441
441
  <div class="method-source-code" id="M000036-source">
442
442
  <pre>
443
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 130</span>
443
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 123</span>
444
444
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_password!</span>(<span class="ruby-identifier">user</span>)
445
445
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span> = <span class="ruby-identifier">user</span>[<span class="ruby-identifier">:password</span>]
446
446
  <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password_confirmation</span> = <span class="ruby-identifier">user</span>[<span class="ruby-identifier">:password_confirmation</span>]
@@ -465,7 +465,7 @@ save without block as usual.
465
465
  onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
466
466
  <div class="method-source-code" id="M000043-source">
467
467
  <pre>
468
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 174</span>
468
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 167</span>
469
469
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">short_name</span>
470
470
  <span class="ruby-constant">CGI</span><span class="ruby-operator">::</span><span class="ruby-identifier">escapeHTML</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">first_name</span>) <span class="ruby-operator">||</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">display_name</span>
471
471
  <span class="ruby-keyword kw">end</span>
@@ -488,7 +488,7 @@ save without block as usual.
488
488
  onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
489
489
  <div class="method-source-code" id="M000040-source">
490
490
  <pre>
491
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 151</span>
491
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 144</span>
492
492
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_xml</span>(<span class="ruby-identifier">options</span> = {})
493
493
  <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:except</span>] <span class="ruby-operator">||=</span> []
494
494
  <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:except</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">:email</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">:crypted_password</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">:salt</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">:remember_token</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">:remember_token_expires_at</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">:activation_code</span>
@@ -127,7 +127,7 @@ class methods
127
127
  onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
128
128
  <div class="method-source-code" id="M000026-source">
129
129
  <pre>
130
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 59</span>
130
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 52</span>
131
131
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">activate_all</span>
132
132
  <span class="ruby-constant">User</span>.<span class="ruby-identifier">update_all</span>(<span class="ruby-node">&quot;activated_at = '#{Time.now}'&quot;</span>, <span class="ruby-value str">'activated_at IS NULL'</span>)
133
133
  <span class="ruby-keyword kw">end</span>
@@ -150,7 +150,7 @@ class methods
150
150
  onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
151
151
  <div class="method-source-code" id="M000024-source">
152
152
  <pre>
153
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 51</span>
153
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 44</span>
154
154
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_search</span>( <span class="ruby-identifier">query</span> )
155
155
  <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [ <span class="ruby-value str">&quot;email LIKE ? OR first_name LIKE ? OR last_name LIKE ?&quot;</span>, <span class="ruby-value str">'%'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">query</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'%'</span>, <span class="ruby-value str">'%'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">query</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'%'</span>, <span class="ruby-value str">'%'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">query</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'%'</span> ])
156
156
  <span class="ruby-keyword kw">end</span>
@@ -176,7 +176,7 @@ checks to see if a given email is already in the database
176
176
  onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
177
177
  <div class="method-source-code" id="M000029-source">
178
178
  <pre>
179
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 87</span>
179
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 80</span>
180
180
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">email_exists?</span>(<span class="ruby-identifier">email</span>)
181
181
  <span class="ruby-keyword kw">if</span> <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_email</span>(<span class="ruby-identifier">email</span>).<span class="ruby-identifier">nil?</span>
182
182
  <span class="ruby-keyword kw">false</span>
@@ -214,7 +214,7 @@ Raises:
214
214
  onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
215
215
  <div class="method-source-code" id="M000027-source">
216
216
  <pre>
217
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 68</span>
217
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 61</span>
218
218
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_and_activate!</span>(<span class="ruby-identifier">activation_code</span>)
219
219
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">activation_code</span>.<span class="ruby-identifier">nil?</span>
220
220
  <span class="ruby-identifier">user</span> = <span class="ruby-identifier">find_by_activation_code</span>(<span class="ruby-identifier">activation_code</span>)
@@ -242,7 +242,7 @@ Raises:
242
242
  onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
243
243
  <div class="method-source-code" id="M000025-source">
244
244
  <pre>
245
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 55</span>
245
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 48</span>
246
246
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inactive_count</span>
247
247
  <span class="ruby-constant">User</span>.<span class="ruby-identifier">count</span> <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;activated_at is null&quot;</span>
248
248
  <span class="ruby-keyword kw">end</span>
@@ -268,7 +268,7 @@ checks to see if a given login is already in the database
268
268
  onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
269
269
  <div class="method-source-code" id="M000028-source">
270
270
  <pre>
271
- <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 78</span>
271
+ <span class="ruby-comment cmt"># File lib/active_record/acts/muck_user.rb, line 71</span>
272
272
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">login_exists?</span>(<span class="ruby-identifier">login</span>)
273
273
  <span class="ruby-keyword kw">if</span> <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_login</span>(<span class="ruby-identifier">login</span>).<span class="ruby-identifier">nil?</span>
274
274
  <span class="ruby-keyword kw">false</span>
data/rdoc/created.rid CHANGED
@@ -1 +1 @@
1
- Tue, 16 Jun 2009 23:12:42 -0600
1
+ Thu, 18 Jun 2009 11:28:24 -0600
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Jun 11 21:11:00 -0600 2009</td>
59
+ <td>Thu Jun 18 10:47:26 -0600 2009</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -3,4 +3,10 @@ class ApplicationController < ActionController::Base
3
3
  helper :all
4
4
  protect_from_forgery
5
5
 
6
+ # called by Admin::Muck::BaseController to check whether or not the
7
+ # user should have access to the admin UI
8
+ def admin_access?
9
+ admin?
10
+ end
11
+
6
12
  end
@@ -3,8 +3,7 @@ class User < ActiveRecord::Base
3
3
  c.crypto_provider = Authlogic::CryptoProviders::BCrypt
4
4
  end
5
5
  acts_as_muck_user
6
- has_activities
7
-
6
+
8
7
  def admin?
9
8
  false
10
9
  end
@@ -4,11 +4,9 @@ class Admin::Muck::UsersControllerTest < ActionController::TestCase
4
4
 
5
5
  tests Admin::Muck::UsersController
6
6
 
7
+ should_require_role(:admin, '/login', :index)
7
8
  should_require_login :index => :get, :inactive => :get, :inactive_emails => :get, :activate_all => :get, :search => :get, :login_url => '/login'
8
-
9
- #:enable => :get, :disable => :get, :update => :post
10
- #should_require_role(:admin, '/login', :index)
11
-
9
+
12
10
  context "logged in as admin" do
13
11
  setup do
14
12
  @admin = Factory(:user)
@@ -52,4 +50,4 @@ class Admin::Muck::UsersControllerTest < ActionController::TestCase
52
50
 
53
51
  end
54
52
 
55
- end
53
+ end
@@ -1,6 +1,6 @@
1
- ActiveSupport::TestCase.class_eval do
1
+ module MuckControllerMacros
2
2
 
3
- def self.should_require_login(*args)
3
+ def should_require_login(*args)
4
4
  args = Hash[*args]
5
5
  login_url = args.delete :login_url
6
6
  args.each do |action, verb|
@@ -11,7 +11,7 @@ ActiveSupport::TestCase.class_eval do
11
11
  end
12
12
  end
13
13
 
14
- def self.should_require_role(role, redirect_url, *actions)
14
+ def should_require_role(role, redirect_url, *actions)
15
15
  actions.each do |action|
16
16
  should "require role for '#{action}' action" do
17
17
  get(action)
@@ -22,7 +22,7 @@ ActiveSupport::TestCase.class_eval do
22
22
  end
23
23
 
24
24
  #from: http://blog.internautdesign.com/2008/9/11/more-on-custom-shoulda-macros-scoping-of-instance-variables
25
- def self.should_not_allow action, object, url= "/login", msg=nil
25
+ def should_not_allow action, object, url= "/login", msg=nil
26
26
  msg ||= "a #{object.class.to_s.downcase}"
27
27
  should "not be able to #{action} #{msg}" do
28
28
  object = eval(object, self.send(:binding), __FILE__, __LINE__)
@@ -31,7 +31,7 @@ ActiveSupport::TestCase.class_eval do
31
31
  end
32
32
  end
33
33
 
34
- def self.should_allow action, object, msg=nil
34
+ def should_allow action, object, msg=nil
35
35
  msg ||= "a #{object.class.to_s.downcase}"
36
36
  should "be able to #{action} #{msg}" do
37
37
  object = eval(object, self.send(:binding), __FILE__, __LINE__)
@@ -41,3 +41,5 @@ ActiveSupport::TestCase.class_eval do
41
41
  end
42
42
 
43
43
  end
44
+
45
+ ActionController::TestCase.extend(MuckControllerMacros)
@@ -1,4 +1,4 @@
1
- class ActiveSupport::TestCase
1
+ module ShouldaFormMacros
2
2
  def self.should_have_form(opts)
3
3
  model = self.name.gsub(/ControllerTest$/, '').singularize.downcase
4
4
  model = model[model.rindex('::')+2..model.size] if model.include?('::')
@@ -26,3 +26,7 @@ class ActiveSupport::TestCase
26
26
  end
27
27
  end
28
28
  end
29
+
30
+ class ActiveSupport::TestCase
31
+ extend ShouldaFormMacros
32
+ end
@@ -1,4 +1,4 @@
1
- ActiveSupport::TestCase.class_eval do
1
+ module ShouldaModelMacros
2
2
 
3
3
  def self.should_whitelist(*attributes)
4
4
  bad_scripts = [
@@ -31,4 +31,20 @@ ActiveSupport::TestCase.class_eval do
31
31
  end
32
32
  end
33
33
 
34
+ def should_accept_nested_attributes_for(*attr_names)
35
+ klass = self.name.gsub(/Test$/, '').constantize
36
+
37
+ context "#{klass}" do
38
+ attr_names.each do |association_name|
39
+ should "accept nested attrs for #{association_name}" do
40
+ assert klass.instance_methods.include?("#{association_name}_attributes="),
41
+ "#{klass} does not accept nested attributes for #{association_name}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ class ActiveSupport::TestCase
49
+ extend ShouldaModelMacros
34
50
  end
@@ -1,4 +1,4 @@
1
- class ActiveSupport::TestCase
1
+ module ShouldaPaginationMacros
2
2
  # Example:
3
3
  # context "a GET to index logged in as admin" do
4
4
  # setup do
@@ -46,3 +46,8 @@ class ActiveSupport::TestCase
46
46
  end
47
47
  end
48
48
  end
49
+
50
+
51
+ class ActiveSupport::TestCase
52
+ extend ShouldaPaginationMacros
53
+ end
@@ -1,4 +1,4 @@
1
- class ActiveSupport::TestCase
1
+ module ShouldaPluginMacros
2
2
 
3
3
  def self.should_act_as_taggable_on_steroids
4
4
  klass = self.name.gsub(/Test$/, '').constantize
@@ -27,4 +27,8 @@ class ActiveSupport::TestCase
27
27
  should_have_instance_methods :acts_as_list_class, :position_column, :scope_condition
28
28
  end
29
29
 
30
- end
30
+ end
31
+
32
+ ActiveSupport::TestCase.extend(ShouldaPluginMacros)
33
+ Test::Unit::TestCase.extend(ShouldaPluginMacros)
34
+ ActionController::TestCase.extend(ShouldaPluginMacros)
@@ -9,6 +9,7 @@ require 'authlogic/test_case'
9
9
  require 'redgreen' rescue LoadError
10
10
  require File.expand_path(File.dirname(__FILE__) + '/factories')
11
11
  require File.join(File.dirname(__FILE__), 'shoulda_macros', 'controller')
12
+ require File.join(File.dirname(__FILE__), 'shoulda_macros', 'models')
12
13
 
13
14
  class ActiveSupport::TestCase
14
15
  self.use_transactional_fixtures = true
@@ -0,0 +1,139 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+
5
+ context 'A user instance' do
6
+ should_have_many :permissions
7
+ should_have_many :roles
8
+
9
+ should_have_named_scope :by_newest
10
+ should_have_named_scope :active
11
+ should_have_named_scope :inactive
12
+ should_have_named_scope :recent
13
+
14
+ should_ensure_length_in_range :email, 6..100 #, :short_message => 'does not look like a valid email address.', :long_message => 'does not look like a valid email address.'
15
+ should_allow_values_for :email, 'a@x.com', 'de.veloper@example.com'
16
+ should_not_allow_values_for :email, 'example.com', '@example.com', 'developer@example', 'developer', :message => 'does not look like a valid email address.'
17
+
18
+ should_not_allow_values_for :login, 'test guy', 'test.guy', 'testguy!', 'test@guy.com', :message => 'may only contain letters, numbers or a hyphen.'
19
+ should_allow_values_for :login, 'testguy', 'test-guy'
20
+
21
+
22
+ should_protect_attributes :crypted_password, :password_salt, :persistence_token, :single_access_token, :perishable_token, :login_count,
23
+ :failed_login_count, :last_request_at, :last_login_at, :current_login_at, :current_login_ip, :last_login_ip,
24
+ :terms_of_service, :time_zone, :disabled_at, :activated_at, :created_at, :updated_at
25
+ end
26
+
27
+ context "search" do
28
+ setup do
29
+ @user = Factory(:user, :first_name => 'john', :last_name => 'smith', :email => 'john.smith@example.com')
30
+ end
31
+ should "find john" do
32
+ assert User.do_search(:first_name => 'john').include?(@user)
33
+ end
34
+ should "find smith" do
35
+ assert User.do_search(:first_name => 'john').include?(@user)
36
+ end
37
+ should "find john.smith@example.com" do
38
+ assert User.do_search(:email => 'john.smith@example.com').include?(@user)
39
+ end
40
+ end
41
+
42
+ context "a user" do
43
+ should "have full name" do
44
+ assert_difference 'User.count' do
45
+ user = Factory(:user, :first_name => 'quent', :last_name => 'smith')
46
+ assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
47
+ assert user.full_name == 'quent smith'
48
+ end
49
+ end
50
+
51
+ should "Create a new user and lowercase the login" do
52
+ assert_difference 'User.count' do
53
+ user = Factory(:user, :login => 'TESTGUY')
54
+ assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
55
+ assert user.login == 'testguy'
56
+ end
57
+ end
58
+
59
+ should "Not allow login with dot" do
60
+ user = Factory.build(:user, :login => 'test.guy')
61
+ assert !user.valid?
62
+ end
63
+
64
+ should "Not allow login with dots" do
65
+ user = Factory.build(:user, :login => 'test.guy.guy')
66
+ assert !user.valid?
67
+ end
68
+
69
+ should "Allow login with dash" do
70
+ user = Factory.build(:user, :login => 'test-guy')
71
+ assert user.valid?
72
+ end
73
+
74
+ should "Not allow login with '@'" do
75
+ user = Factory.build(:user, :login => 'testguy@example.com')
76
+ assert !user.valid?
77
+ end
78
+
79
+ should "Not allow login with '!'" do
80
+ user = Factory.build(:user, :login => 'testguy!')
81
+ assert !user.valid?
82
+ end
83
+
84
+ should "require login" do
85
+ assert_no_difference 'User.count' do
86
+ u = Factory.build(:user, :login => nil)
87
+ assert !u.valid?
88
+ assert u.errors.on(:login)
89
+ end
90
+ end
91
+
92
+ should "require password" do
93
+ assert_no_difference 'User.count' do
94
+ u = Factory.build(:user, :password => nil)
95
+ assert !u.valid?
96
+ assert u.errors.on(:password)
97
+ end
98
+ end
99
+
100
+ should "require password confirmation" do
101
+ assert_no_difference 'User.count' do
102
+ u = Factory.build(:user, :password_confirmation => nil)
103
+ assert !u.valid?
104
+ assert u.errors.on(:password_confirmation)
105
+ end
106
+ end
107
+
108
+ should "require require email" do
109
+ assert_no_difference 'User.count' do
110
+ u = Factory.build(:user, :email => nil)
111
+ assert !u.valid?
112
+ assert u.errors.on(:email)
113
+ end
114
+ end
115
+
116
+ end
117
+
118
+ context "inactive users" do
119
+ setup do
120
+ @user = Factory(:user, :activated_at => nil)
121
+ end
122
+ should "have at least one inactive user" do
123
+ assert User.inactive_count > 0
124
+ end
125
+ end
126
+
127
+ context "user exists" do
128
+ setup do
129
+ @user = Factory(:user, :login => 'atestguytoo', :email => 'atestguytoo@example.com')
130
+ end
131
+ should "find user with login" do
132
+ assert User.login_exists?('atestguytoo')
133
+ end
134
+ should "find user with email" do
135
+ assert User.email_exists?('atestguytoo@example.com')
136
+ end
137
+ end
138
+
139
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-users
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: binarylogic-searchlogic
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: bcrypt-ruby
27
37
  type: :runtime
@@ -140,7 +150,9 @@ files:
140
150
  - locales/zh-CN.yml
141
151
  - locales/zh-TW.yml
142
152
  - locales/zh.yml
153
+ - muck-users-0.1.4.gem
143
154
  - muck-users.gemspec
155
+ - pkg/muck-users-0.1.6.gem
144
156
  - public/images/profile_default.jpg
145
157
  - rails/init.rb
146
158
  - rdoc/classes/ActionController.html
@@ -378,6 +390,7 @@ files:
378
390
  - test/rails_root/test/unit/muck_user_mailer_test.rb
379
391
  - test/rails_root/test/unit/permission_test.rb
380
392
  - test/rails_root/test/unit/role_test.rb
393
+ - test/rails_root/test/unit/user_test.rb
381
394
  - test/rails_root/vendor/plugins/ssl_requirement/README
382
395
  - test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb
383
396
  - test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb
@@ -447,5 +460,6 @@ test_files:
447
460
  - test/rails_root/test/unit/muck_user_mailer_test.rb
448
461
  - test/rails_root/test/unit/permission_test.rb
449
462
  - test/rails_root/test/unit/role_test.rb
463
+ - test/rails_root/test/unit/user_test.rb
450
464
  - test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb
451
465
  - test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb