soft_validate 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/soft_validate.rb CHANGED
@@ -17,15 +17,15 @@ module SoftValidate
17
17
  end
18
18
 
19
19
  def soft_valid?
20
- self.soft_attributes.all? { |a| !self.attributes[a.to_s].nil? }
20
+ self.soft_attributes.all? { |a| !self.attributes[a.to_s].blank? }
21
21
  end
22
22
 
23
23
  def soft_errors
24
- Hash[ self.soft_attributes.map { |a| [a, "shouldn't be blank"] if self.attributes[a.to_s].nil? } ]
24
+ Hash[ self.soft_attributes.map { |a| [a, "shouldn't be blank"] if self.attributes[a.to_s].blank? } ]
25
25
  end
26
26
 
27
27
  def progress_count
28
- self.soft_attributes.count { |a| !self.attributes[a.to_s].nil? }
28
+ self.soft_attributes.count { |a| !self.attributes[a.to_s].blank? }
29
29
  end
30
30
 
31
31
  def progress_percent
@@ -1,3 +1,3 @@
1
1
  module SoftValidate
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/debug.log CHANGED
@@ -39,3 +39,151 @@
39
39
   (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
40
40
   (0.1ms) SELECT version FROM "schema_migrations"
41
41
   (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
42
+  (1.8ms) select sqlite_version(*)
43
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
44
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
45
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
46
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
47
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
48
+  (0.0ms) PRAGMA index_list("schema_migrations")
49
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
50
+  (0.0ms) SELECT version FROM "schema_migrations"
51
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
52
+  (1.1ms) select sqlite_version(*)
53
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
54
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
55
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
56
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
57
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
58
+  (0.0ms) PRAGMA index_list("schema_migrations")
59
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
60
+  (0.0ms) SELECT version FROM "schema_migrations"
61
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
62
+  (1.1ms) select sqlite_version(*)
63
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
64
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
65
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
66
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
67
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
68
+  (0.0ms) PRAGMA index_list("schema_migrations")
69
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
70
+  (0.0ms) SELECT version FROM "schema_migrations"
71
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
72
+  (1.0ms) select sqlite_version(*)
73
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
74
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
75
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
76
+  (1.1ms) select sqlite_version(*)
77
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
78
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
79
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
80
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
81
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
82
+  (0.0ms) PRAGMA index_list("schema_migrations")
83
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
84
+  (0.0ms) SELECT version FROM "schema_migrations"
85
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
86
+  (1.0ms) select sqlite_version(*)
87
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
88
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
89
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
90
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
91
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
92
+  (0.0ms) PRAGMA index_list("schema_migrations")
93
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
94
+  (0.0ms) SELECT version FROM "schema_migrations"
95
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
96
+  (1.1ms) select sqlite_version(*)
97
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
98
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
99
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
100
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
101
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
102
+  (0.0ms) PRAGMA index_list("schema_migrations")
103
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
104
+  (0.0ms) SELECT version FROM "schema_migrations"
105
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
106
+  (1.4ms) select sqlite_version(*)
107
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
108
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
109
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
110
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
111
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
112
+  (0.0ms) PRAGMA index_list("schema_migrations")
113
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
114
+  (0.0ms) SELECT version FROM "schema_migrations"
115
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
116
+  (1.1ms) select sqlite_version(*)
117
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
118
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
119
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
120
+  (0.2ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
121
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
122
+  (0.0ms) PRAGMA index_list("schema_migrations")
123
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
124
+  (0.0ms) SELECT version FROM "schema_migrations"
125
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
126
+  (1.8ms) select sqlite_version(*)
127
+  (0.5ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
128
+  (0.2ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
129
+  (0.2ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
130
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
131
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
132
+  (0.0ms) PRAGMA index_list("schema_migrations")
133
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
134
+  (0.1ms) SELECT version FROM "schema_migrations"
135
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
136
+  (1.0ms) select sqlite_version(*)
137
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
138
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
139
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
140
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_addresses_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
141
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
142
+  (0.0ms) PRAGMA index_list("schema_migrations")
143
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
144
+  (0.0ms) SELECT version FROM "schema_migrations"
145
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
146
+  (1.1ms) select sqlite_version(*)
147
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
148
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
149
+  (0.1ms) CREATE TABLE "user_with_addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255))
150
+  (0.1ms) CREATE TABLE "addresses" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_with_address_id" integer, "street" varchar(255), "city" varchar(255), "state" varchar(255), "zip" varchar(255)) 
151
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
152
+  (0.0ms) PRAGMA index_list("schema_migrations")
153
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
154
+  (0.0ms) SELECT version FROM "schema_migrations"
155
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
156
+  (0.1ms) begin transaction
157
+  (0.0ms) commit transaction
158
+  (2.1ms) select sqlite_version(*)
159
+  (0.5ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
160
+  (0.2ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
161
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
162
+  (0.0ms) PRAGMA index_list("schema_migrations")
163
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
164
+  (0.1ms) SELECT version FROM "schema_migrations"
165
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
166
+  (1.3ms) select sqlite_version(*)
167
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
168
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
169
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
170
+  (0.0ms) PRAGMA index_list("schema_migrations")
171
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
172
+  (0.1ms) SELECT version FROM "schema_migrations"
173
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
174
+  (1.3ms) select sqlite_version(*)
175
+  (0.3ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
176
+  (0.1ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
177
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
178
+  (0.0ms) PRAGMA index_list("schema_migrations")
179
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
180
+  (0.1ms) SELECT version FROM "schema_migrations"
181
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
182
+  (2.7ms) select sqlite_version(*)
183
+  (0.4ms) CREATE TABLE "dumb_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255))
184
+  (0.2ms) CREATE TABLE "non_validated_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255)) 
185
+  (0.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
186
+  (0.0ms) PRAGMA index_list("schema_migrations")
187
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
188
+  (0.1ms) SELECT version FROM "schema_migrations"
189
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
@@ -34,6 +34,17 @@ class SoftValidateTest < TEST_CASE
34
34
  assert response[:last_name].eql?("shouldn't be blank")
35
35
  end
36
36
 
37
+ test 'an invalid user should return error messages for blank values, not just nils' do
38
+ user = DumbUser.new(:email => '', :first_name => '', :last_name => '')
39
+
40
+ response = user.soft_errors
41
+ assert !response.nil?
42
+ assert !response.empty?
43
+
44
+ assert response[:first_name].eql?("shouldn't be blank")
45
+ assert response[:last_name].eql?("shouldn't be blank")
46
+ end
47
+
37
48
  test 'a valid user should return an empty error message response' do
38
49
  user = DumbUser.new(:email => 'me@you.com', :first_name => 'joe', :last_name => 'schmoe')
39
50
  assert user.soft_errors.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soft_validate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-11 00:00:00.000000000 Z
13
+ date: 2012-05-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70180042847580 !ruby/object:Gem::Requirement
17
+ requirement: &70200595269100 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.2.3
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70180042847580
25
+ version_requirements: *70200595269100
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
- requirement: &70180042845940 !ruby/object:Gem::Requirement
28
+ requirement: &70200595268680 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70180042845940
36
+ version_requirements: *70200595268680
37
37
  description: Add softs_validate_presence_of :attr to your model and it will give you
38
38
  methods to figure out percent complete, missing fields, etc without preventing the
39
39
  record from being saved.
@@ -96,3 +96,4 @@ test_files:
96
96
  - test/schema.rb
97
97
  - test/soft_validate_test.rb
98
98
  - test/test_helper.rb
99
+ has_rdoc: