express_pigeon 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/express_pigeon.gemspec +1 -0
- data/lib/active_model/validations/date_format_validator.rb +20 -0
- data/lib/express_pigeon.rb +16 -21
- data/lib/express_pigeon/version.rb +1 -1
- data/spec/web_forms_spec.rb +66 -28
- metadata +20 -2
data/CHANGELOG
ADDED
data/express_pigeon.gemspec
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'chronic'
|
4
|
+
|
5
|
+
module ActiveModel
|
6
|
+
module Validations
|
7
|
+
class DateFormatValidator < ActiveModel::Validator
|
8
|
+
def validate(record)
|
9
|
+
|
10
|
+
return if [DateTime, Date, Time].include? record.date_of_birth.class
|
11
|
+
|
12
|
+
return if record.date_of_birth.blank?
|
13
|
+
|
14
|
+
unless Chronic.parse(record.date_of_birth)
|
15
|
+
record.errors[:base] << (options[:message] || "is not a valid date format")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/express_pigeon.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "express_pigeon/version"
|
2
|
-
require 'active_support'
|
3
|
-
require 'time'
|
4
2
|
require 'active_model'
|
5
|
-
require '
|
3
|
+
require 'curb-fu'
|
4
|
+
require 'active_model/validations/date_format_validator'
|
6
5
|
|
7
6
|
module ExpressPigeon
|
8
7
|
class WebForm
|
9
8
|
include ActiveModel::Validations
|
9
|
+
|
10
10
|
include ActiveModel::Dirty
|
11
11
|
|
12
12
|
define_attribute_methods [
|
@@ -38,31 +38,22 @@ module ExpressPigeon
|
|
38
38
|
# required and just check bounds.
|
39
39
|
validates :address1, :length => 0..255, :allow_blank => true
|
40
40
|
validates :address2, :length => 0..255, :allow_blank => true
|
41
|
-
validates :city,
|
42
|
-
validates :company,
|
43
|
-
validates :country,
|
41
|
+
validates :city, :length => 0..128, :allow_blank => true
|
42
|
+
validates :company, :length => 0..128, :allow_blank => true
|
43
|
+
validates :country, :length => 0..128, :allow_blank => true
|
44
44
|
|
45
45
|
# now sure why we can put 255 chars into date of birth but that's what it is.
|
46
46
|
# TODO validate and require date format, submit as MM/DD/YYYY
|
47
|
-
validates :date_of_birth, :length => 0..255, :allow_blank => true
|
47
|
+
validates :date_of_birth, :length => 0..255, :allow_blank => true, :date_format => true
|
48
48
|
|
49
49
|
# will email_form be a submittable field?
|
50
|
-
|
51
50
|
validates :first_name, :length => 0..50, :allow_blank => true
|
52
51
|
validates :last_name, :length => 0..50, :allow_blank => true
|
53
|
-
|
54
52
|
validates :phone, :length => 0..30, :allow_blank => true
|
55
|
-
|
56
|
-
# state is 48?
|
57
|
-
validates :state, :length => 0..48, :allow_blank => true
|
58
|
-
|
53
|
+
validates :state, :length => 0..48, :allow_blank => true # state is 48?
|
59
54
|
validates :title, :length => 0..30, :allow_blank => true
|
55
|
+
validates :zip, :length => 0..24, :allow_blank => true # zip is 24?
|
60
56
|
|
61
|
-
# zip is 24?
|
62
|
-
validates :zip, :length => 0..24, :allow_blank => true
|
63
|
-
|
64
|
-
|
65
|
-
# TODO validate date format MM/DD/YYYY
|
66
57
|
# TODO validate state
|
67
58
|
# TODO validate field sizes
|
68
59
|
|
@@ -116,7 +107,7 @@ module ExpressPigeon
|
|
116
107
|
:city => self.city,
|
117
108
|
:company => self.company,
|
118
109
|
:country => self.country,
|
119
|
-
:date_of_birth => self.date_of_birth,
|
110
|
+
:date_of_birth => format_date(self.date_of_birth),
|
120
111
|
:email => self.email,
|
121
112
|
:first_name => self.first_name,
|
122
113
|
:guid => self.guid,
|
@@ -127,11 +118,15 @@ module ExpressPigeon
|
|
127
118
|
:zip => self.zip,
|
128
119
|
}
|
129
120
|
|
130
|
-
require 'curb-fu'
|
131
|
-
|
132
121
|
response = CurbFu.post({:url => url}, params)
|
133
122
|
|
134
123
|
response
|
135
124
|
end
|
125
|
+
|
126
|
+
def format_date(date)
|
127
|
+
return "" if date.blank?
|
128
|
+
|
129
|
+
date.strftime("%m/%d/%Y")
|
130
|
+
end
|
136
131
|
end
|
137
132
|
end
|
data/spec/web_forms_spec.rb
CHANGED
@@ -8,15 +8,19 @@ describe ExpressPigeon::WebForm do
|
|
8
8
|
it { should validate_presence_of :email }
|
9
9
|
it { should validate_presence_of :guid }
|
10
10
|
|
11
|
+
|
11
12
|
describe "specific validations" do
|
12
13
|
# TODO add the matchers to activemodel-rspec
|
13
14
|
# that will make this section easier
|
14
15
|
let(:form) do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
wf = ExpressPigeon::WebForm.new
|
17
|
+
|
18
|
+
wf.guid = "51697971-48b4-45d3-ab80-3b23152999ed"
|
19
|
+
wf.email = "valid@just3ws.com"
|
20
|
+
|
21
|
+
wf.should be_valid
|
22
|
+
|
23
|
+
wf
|
20
24
|
end
|
21
25
|
|
22
26
|
it "checks email field" do
|
@@ -33,13 +37,45 @@ describe ExpressPigeon::WebForm do
|
|
33
37
|
form.should_not be_valid
|
34
38
|
end
|
35
39
|
|
40
|
+
it "only rejects non-date date of births" do
|
41
|
+
form.date_of_birth = "this is invalid"
|
42
|
+
|
43
|
+
form.should_not be_valid
|
44
|
+
end
|
45
|
+
|
46
|
+
it "accepts date of birth as MM/DD/YYYY" do
|
47
|
+
form.date_of_birth = "05/30/2008"
|
48
|
+
form.should be_valid
|
49
|
+
form.date_of_birth.should == "05/30/2008"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "accepts a date object as date of birth" do
|
53
|
+
form.date_of_birth = Chronic.parse("2011-2-22")
|
54
|
+
form.should be_valid
|
55
|
+
form
|
56
|
+
end
|
57
|
+
|
58
|
+
it "accepts DateTime for date of birth" do
|
59
|
+
form.date_of_birth = DateTime.now
|
60
|
+
form.should be_valid
|
61
|
+
end
|
62
|
+
|
63
|
+
it "accepts Time for date of birth" do
|
64
|
+
form.date_of_birth = Time.now
|
65
|
+
form.should be_valid
|
66
|
+
end
|
67
|
+
|
68
|
+
it "accepts Date for date of birth" do
|
69
|
+
form.date_of_birth = Date.today
|
70
|
+
form.should be_valid
|
71
|
+
end
|
72
|
+
|
36
73
|
|
37
74
|
{"address1" => 255,
|
38
75
|
"address2" => 255,
|
39
76
|
"city" => 128,
|
40
77
|
"company" => 128,
|
41
78
|
"country" => 128,
|
42
|
-
"date_of_birth" => 255,
|
43
79
|
"first_name" => 50,
|
44
80
|
"last_name" => 50,
|
45
81
|
"phone" => 30,
|
@@ -75,52 +111,54 @@ describe ExpressPigeon::WebForm do
|
|
75
111
|
|
76
112
|
it "resets changed after successfully saving" do
|
77
113
|
wf = ExpressPigeon::WebForm.new
|
114
|
+
|
78
115
|
wf.email = "doesnt@matter.com"
|
79
116
|
wf.guid = "doesn't matter"
|
117
|
+
|
80
118
|
wf.stub(:push_to_express_pigeon!).and_return(true)
|
119
|
+
|
81
120
|
wf.save
|
121
|
+
|
82
122
|
wf.should_not be_changed
|
83
123
|
end
|
84
124
|
|
85
125
|
it "remains changed when save fails" do
|
86
126
|
wf = ExpressPigeon::WebForm.new
|
127
|
+
|
87
128
|
wf.email = "doesnt@matter.com"
|
88
129
|
wf.guid = "doesn't matter"
|
89
130
|
wf.stub(:push_to_express_pigeon!).and_return(false)
|
131
|
+
|
90
132
|
wf.save
|
133
|
+
|
91
134
|
wf.should be_changed
|
92
135
|
end
|
93
136
|
end
|
94
137
|
|
95
138
|
it "pushes to expresspigeon.com", :live => true do
|
96
139
|
wf = ExpressPigeon::WebForm.new
|
97
|
-
wf.guid = "51697971-48b4-45d3-ab80-3b23152999ed"
|
98
|
-
|
99
|
-
wf.first_name = "Michael"
|
100
|
-
wf.last_name = "Hall"
|
101
|
-
|
102
|
-
wf.email = "mdh+rspec@just3ws.com"
|
103
|
-
|
104
|
-
wf.address1 = "1 Way Street"
|
105
|
-
wf.address1 = "Suite #0"
|
106
|
-
|
107
|
-
wf.city = "Springfield"
|
108
|
-
wf.state = "Illinois"
|
109
|
-
wf.zip = "60606"
|
110
|
-
wf.country = "United States"
|
111
140
|
|
141
|
+
wf.guid = "51697971-48b4-45d3-ab80-3b23152999ed"
|
142
|
+
wf.first_name = "Michael"
|
143
|
+
wf.last_name = "Hall"
|
144
|
+
wf.email = "mdh+rspec@just3ws.com"
|
145
|
+
wf.address1 = "1 Way Street"
|
146
|
+
wf.address1 = "Suite #0"
|
147
|
+
wf.city = "Springfield"
|
148
|
+
wf.state = "Illinois"
|
149
|
+
wf.zip = "60606"
|
150
|
+
wf.country = "United States"
|
112
151
|
wf.date_of_birth = "1/1/1900"
|
152
|
+
wf.phone = "888-555-1212"
|
153
|
+
wf.title = "Emperor of Mankind"
|
154
|
+
wf.company = "Imperium of Man"
|
113
155
|
|
114
|
-
wf.
|
115
|
-
|
116
|
-
wf.title = "Emperor of Mankind"
|
117
|
-
wf.company = "Imperium of Man"
|
118
|
-
|
156
|
+
wf.save
|
119
157
|
|
120
|
-
|
158
|
+
pending "Need to get the actual push to EP working first"
|
121
159
|
|
122
|
-
wf.save
|
123
|
-
pending "need to get the actual push to EP working first"
|
124
160
|
wf.should be_changed
|
125
161
|
end
|
162
|
+
|
163
|
+
|
126
164
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: express_pigeon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: chronic
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: Light-weight wrapper around ExpressPigeon.
|
47
63
|
email:
|
48
64
|
- mdh@just3ws.com
|
@@ -55,12 +71,14 @@ files:
|
|
55
71
|
- .rspec
|
56
72
|
- .rvmrc
|
57
73
|
- .travis.yml
|
74
|
+
- CHANGELOG
|
58
75
|
- Gemfile
|
59
76
|
- LICENSE
|
60
77
|
- README.md
|
61
78
|
- Rakefile
|
62
79
|
- bin/console
|
63
80
|
- express_pigeon.gemspec
|
81
|
+
- lib/active_model/validations/date_format_validator.rb
|
64
82
|
- lib/express_pigeon.rb
|
65
83
|
- lib/express_pigeon/version.rb
|
66
84
|
- script/lint
|