smart_field_constraints 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  == master
2
2
 
3
+ == 0.1.1 / 2009-03-15
4
+
5
+ * Fix limits for integer columns being interpreted incorrectly [Michael Grosser]
6
+
3
7
  == 0.1.0 / 2008-12-14
4
8
 
5
9
  * Remove the PluginAWeek namespace
@@ -8,8 +12,8 @@
8
12
  == 0.0.2 / 2008-06-22
9
13
 
10
14
  * Remove log files from gems
11
- * Don't check length validation constraints if models were loaded prior to the plugin being loaded [grosser]
12
- * Refactor FormHelper extension to allow for others to easily extend the plugin for things like textarea lengths [grosser]
15
+ * Don't check length validation constraints if models were loaded prior to the plugin being loaded [Michael Grosser]
16
+ * Refactor FormHelper extension to allow for others to easily extend the plugin for things like textarea lengths [Michael Grosser]
13
17
  * Add support for tracking validates_size_of validations
14
18
 
15
19
  == 0.0.1 / 2008-05-05
data/README.rdoc CHANGED
@@ -59,7 +59,7 @@ HTML:
59
59
  Since the +maxlength+ attribute is not W3C-compliant for textareas, it is not
60
60
  included in the types of fields that will be automatically assigned length
61
61
  constraints. However, you can easily add this yourself by extending the plugin
62
- yourself.
62
+ yourself. For an example of this see smart_field_constraints_textarea[http://github.com/grosser/smart_field_constraints_textarea].
63
63
 
64
64
  == Caveats
65
65
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'smart_field_constraints'
8
- s.version = '0.1.0'
8
+ s.version = '0.1.1'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Intelligently applies a maxlength attribute for text fields based on column constraints and validations'
11
11
 
@@ -42,8 +42,15 @@ module SmartFieldConstraints
42
42
 
43
43
  # Finds the maximum length according to column limits
44
44
  def column_limit
45
- if column = object.class.columns_hash[method_name]
46
- column.limit
45
+ column = object.class.columns_hash[method_name]
46
+
47
+ if column && limit = column.limit
48
+ if column.text?
49
+ limit
50
+ elsif column.number?
51
+ # Length is bound by the upper limit of the number + 1 (for negatives)
52
+ Math.log10(2 ** (limit * 8 - 1)).ceil + 1
53
+ end
47
54
  end
48
55
  end
49
56
  end
@@ -1,6 +1,7 @@
1
1
  class CreateUsers < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :users do |t|
3
+ create_table :users, :id => false do |t|
4
+ t.integer :id, :limit => 4, :null => false # For limit for testing purposes
4
5
  t.string :login, :limit => 12
5
6
  t.string :password, :limit => 16
6
7
  t.text :biography
@@ -57,7 +57,7 @@ class FormHelperWithValidationConstraintsTest < ActionView::TestCase
57
57
  end
58
58
  end
59
59
 
60
- class FormHelperWithColumnConstraintsTest < ActionView::TestCase
60
+ class FormHelperWithStringColumnConstraintsTest < ActionView::TestCase
61
61
  tests ActionView::Helpers::FormHelper
62
62
 
63
63
  def setup
@@ -85,6 +85,18 @@ class FormHelperWithColumnConstraintsTest < ActionView::TestCase
85
85
  end
86
86
  end
87
87
 
88
+ class FormHelperWithNumberColumnConstraintsTest < ActionView::TestCase
89
+ tests ActionView::Helpers::FormHelper
90
+
91
+ def setup
92
+ @user = User.new
93
+ end
94
+
95
+ def test_should_add_maxlength
96
+ assert_equal '<input id="user_id" maxlength="11" name="user[id]" size="30" type="text" />', text_field(:user, :id)
97
+ end
98
+ end
99
+
88
100
  class FormHelperForModelNotTrackedTest < ActionView::TestCase
89
101
  tests ActionView::Helpers::FormHelper
90
102
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_field_constraints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-14 00:00:00 -05:00
12
+ date: 2009-03-15 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15