nifty-generators 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 0.2.2 (November 11th, 2008)
2
+
3
+ * fixing sessions_path reference in nifty_authentication
4
+
5
+ * adding more validations to user model in nifty_authentication
6
+
7
+ * cleaning up nifty_layout stylesheet
8
+
1
9
  0.2.1 (November 10th, 2008)
2
10
 
3
11
  * adding missing nifty_authentication files
data/Rakefile CHANGED
@@ -2,14 +2,13 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('nifty-generators', '0.2.1') do |p|
5
+ Echoe.new('nifty-generators', '0.2.2') do |p|
6
6
  p.project = "niftygenerators"
7
- p.summary = "A collection of useful generator scripts for Rails."
8
7
  p.description = "A collection of useful generator scripts for Rails."
9
8
  p.url = "http://github.com/ryanb/nifty-generators"
10
9
  p.author = 'Ryan Bates'
11
10
  p.email = "ryan (at) railscasts (dot) com"
12
- p.ignore_pattern = ["script/*", "*.gemspec"]
11
+ p.ignore_pattern = ["script/*"]
13
12
  p.development_dependencies = []
14
13
  end
15
14
 
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Nifty-generators-0.2.1
2
+ # Gem::Specification for Nifty-generators-0.2.2
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: nifty-generators
7
7
  version: !ruby/object:Gem::Version
8
- version: 0.2.1
8
+ version: 0.2.2
9
9
  platform: ruby
10
10
  authors:
11
11
  - Ryan Bates
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-11-10 00:00:00 -08:00
15
+ date: 2008-11-11 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies: []
18
18
 
@@ -9,6 +9,10 @@ describe <%= user_class_name %> do
9
9
  <%= user_class_name %>.new(attributes)
10
10
  end
11
11
 
12
+ before(:each) do
13
+ <%= user_class_name %>.delete_all
14
+ end
15
+
12
16
  it "should be valid" do
13
17
  new_<%= user_singular_name %>.should be_valid
14
18
  end
@@ -25,6 +29,24 @@ describe <%= user_class_name %> do
25
29
  new_<%= user_singular_name %>(:email => 'foo@bar@example.com').should have(1).error_on(:email)
26
30
  end
27
31
 
32
+ it "should validate uniqueness of email" do
33
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
34
+ new_<%= user_singular_name %>(:email => 'bar@example.com').should have(1).error_on(:email)
35
+ end
36
+
37
+ it "should validate uniqueness of username" do
38
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
39
+ new_<%= user_singular_name %>(:username => 'uniquename').should have(1).error_on(:username)
40
+ end
41
+
42
+ it "should not allow odd characters in username" do
43
+ new_<%= user_singular_name %>(:username => 'odd ^&(@)').should have(1).error_on(:username)
44
+ end
45
+
46
+ it "should validate password is longer than 3 characters" do
47
+ new_<%= user_singular_name %>(:password => 'bad').should have(1).error_on(:password)
48
+ end
49
+
28
50
  it "should require matching password confirmation" do
29
51
  new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have(1).error_on(:password)
30
52
  end
@@ -37,14 +59,12 @@ describe <%= user_class_name %> do
37
59
  end
38
60
 
39
61
  it "should authenticate by username" do
40
- <%= user_class_name %>.delete_all
41
62
  <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
42
63
  <%= user_singular_name %>.save!
43
64
  <%= user_class_name %>.authenticate('foobar', 'secret').should == <%= user_singular_name %>
44
65
  end
45
66
 
46
67
  it "should authenticate by email" do
47
- <%= user_class_name %>.delete_all
48
68
  <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
49
69
  <%= user_singular_name %>.save!
50
70
  <%= user_class_name %>.authenticate('foo@bar.com', 'secret').should == <%= user_singular_name %>
@@ -55,7 +75,6 @@ describe <%= user_class_name %> do
55
75
  end
56
76
 
57
77
  it "should not authenticate bad password" do
58
- <%= user_class_name %>.delete_all
59
78
  new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
60
79
  <%= user_class_name %>.authenticate('foobar', 'badpassword').should be_nil
61
80
  end
@@ -11,6 +11,10 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
11
11
  <%= user_singular_name %>
12
12
  end
13
13
 
14
+ def setup
15
+ <%= user_class_name %>.delete_all
16
+ end
17
+
14
18
  should "be valid" do
15
19
  assert new_<%= user_singular_name %>.valid?
16
20
  end
@@ -27,6 +31,24 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
27
31
  assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
28
32
  end
29
33
 
34
+ should "validate uniqueness of email" do
35
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
36
+ assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
37
+ end
38
+
39
+ should "validate uniqueness of username" do
40
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
41
+ assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
42
+ end
43
+
44
+ should "not allow odd characters in username" do
45
+ assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
46
+ end
47
+
48
+ should "validate password is longer than 3 characters" do
49
+ assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
50
+ end
51
+
30
52
  should "require matching password confirmation" do
31
53
  assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
32
54
  end
@@ -39,14 +61,12 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
39
61
  end
40
62
 
41
63
  should "authenticate by username" do
42
- <%= user_class_name %>.delete_all
43
64
  <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
44
65
  <%= user_singular_name %>.save!
45
66
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
46
67
  end
47
68
 
48
69
  should "authenticate by email" do
49
- <%= user_class_name %>.delete_all
50
70
  <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
51
71
  <%= user_singular_name %>.save!
52
72
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
@@ -57,7 +77,6 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
57
77
  end
58
78
 
59
79
  should "not authenticate bad password" do
60
- <%= user_class_name %>.delete_all
61
80
  new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
62
81
  assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
63
82
  end
@@ -11,6 +11,10 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
11
11
  <%= user_singular_name %>
12
12
  end
13
13
 
14
+ def setup
15
+ <%= user_class_name %>.delete_all
16
+ end
17
+
14
18
  def test_valid
15
19
  assert new_<%= user_singular_name %>.valid?
16
20
  end
@@ -27,6 +31,24 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
27
31
  assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
28
32
  end
29
33
 
34
+ def test_validate_uniqueness_of_email
35
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
36
+ assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
37
+ end
38
+
39
+ def test_validate_uniqueness_of_username
40
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
41
+ assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
42
+ end
43
+
44
+ def test_validate_odd_characters_in_username
45
+ assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
46
+ end
47
+
48
+ def test_validate_password_length
49
+ assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
50
+ end
51
+
30
52
  def test_require_matching_password_confirmation
31
53
  assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
32
54
  end
@@ -6,9 +6,12 @@ class <%= user_class_name %> < ActiveRecord::Base
6
6
  before_create :prepare_password
7
7
 
8
8
  validates_presence_of :username
9
+ validates_uniqueness_of :username, :email, :allow_blank => true
10
+ validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
9
11
  validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
10
12
  validates_presence_of :password, :on => :create
11
13
  validates_confirmation_of :password
14
+ validates_length_of :password, :minimum => 4, :allow_blank => true
12
15
 
13
16
  # login can be either username or email address
14
17
  def self.authenticate(login, pass)
@@ -2,7 +2,7 @@
2
2
 
3
3
  <p>Don't have an account? <%%= link_to "Sign up!", signup_path %></p>
4
4
 
5
- <%% form_tag sessions_path do %>
5
+ <%% form_tag <%= sessions_underscore_name %>_path do %>
6
6
  <p>
7
7
  <%%= label_tag :login, "Username or Email Address" %><br />
8
8
  <%%= text_field_tag :login, params[:login] %>
@@ -2,7 +2,7 @@
2
2
 
3
3
  %p== Don't have an account? #{link_to "Sign up!", signup_path}
4
4
 
5
- - form_tag sessions_path do
5
+ - form_tag <%= sessions_underscore_name %>_path do
6
6
  %p
7
7
  = label_tag :login, "Username or Email Address"
8
8
  %br
@@ -14,7 +14,7 @@ a {
14
14
 
15
15
  .clear {
16
16
  clear: both;
17
- height: 0px;
17
+ height: 0;
18
18
  overflow: hidden;
19
19
  }
20
20
 
@@ -42,8 +42,6 @@ a {
42
42
  border: solid 1px #C66;
43
43
  }
44
44
 
45
-
46
-
47
45
  .fieldWithErrors {
48
46
  display: inline;
49
47
  }
@@ -62,18 +60,21 @@ a {
62
60
  font-weight: bold;
63
61
  padding: 5px 5px 5px 15px;
64
62
  font-size: 12px;
65
- margin: 0px;
63
+ margin: 0;
66
64
  background-color: #c00;
67
65
  color: #fff;
68
66
  }
67
+
69
68
  #errorExplanation p {
70
69
  color: #333;
71
70
  margin-bottom: 0;
72
71
  padding: 8px;
73
72
  }
73
+
74
74
  #errorExplanation ul {
75
75
  margin: 2px 24px;
76
76
  }
77
+
77
78
  #errorExplanation ul li {
78
79
  font-size: 12px;
79
80
  list-style: disc;
@@ -6,9 +6,6 @@ body
6
6
  :family Verdana, Helvetica, Arial
7
7
  :size 14px
8
8
 
9
- ul li
10
- :list-style none
11
-
12
9
  a
13
10
  :color #0000FF
14
11
  img
@@ -16,7 +13,7 @@ a
16
13
 
17
14
  .clear
18
15
  :clear both
19
- :height 0px
16
+ :height 0
20
17
  :overflow hidden
21
18
 
22
19
  #container
@@ -40,19 +37,23 @@ a
40
37
  :background-color #FCC
41
38
  :border solid 1px #C66
42
39
 
40
+ .fieldWithErrors
41
+ :display inline
42
+
43
43
  #errorExplanation
44
44
  :width 400px
45
45
  :border 2px solid #CF0000
46
- :padding 0px
46
+ :padding 0
47
47
  :padding-bottom 12px
48
48
  :margin-bottom 20px
49
49
  :background-color #f0f0f0
50
50
  h2
51
51
  :text-align left
52
- :font-weight bold
53
52
  :padding 5px 5px 5px 15px
54
- :font-size 12px
55
- :margin 0px
53
+ :margin 0
54
+ :font
55
+ :weight bold
56
+ :size 12px
56
57
  :background-color #c00
57
58
  :color #fff
58
59
  p
@@ -1,3 +1,3 @@
1
1
  def index
2
- @<%= plural_name %> = <%= class_name %>.find(:all)
2
+ @<%= plural_name %> = <%= class_name %>.all
3
3
  end
@@ -96,9 +96,9 @@ module ActiveRecord
96
96
  attr_accessor :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
97
97
 
98
98
  def initialize(name, default, sql_type = nil)
99
- @name=name
100
- @default=default
101
- @type=@sql_type=sql_type
99
+ @name = name
100
+ @default = default
101
+ @type = @sql_type = sql_type
102
102
  end
103
103
 
104
104
  def human_name
@@ -100,7 +100,7 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
100
100
  should "generate controller with index action" do
101
101
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
102
102
  assert_match "def index", body
103
- assert_match "@line_items = LineItem.find(:all)", body
103
+ assert_match "@line_items = LineItem.all", body
104
104
  assert_no_match(/ def index/, body)
105
105
  end
106
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nifty-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-10 00:00:00 -08:00
12
+ date: 2008-11-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15