pinpoint 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pinpoint.rb +44 -1
- data/lib/pinpoint/address.rb +70 -0
- data/lib/pinpoint/{addressable.rb → validations.rb} +7 -21
- data/lib/pinpoint/version.rb +1 -1
- data/spec/address_spec.rb +234 -0
- data/spec/pinpoint_spec.rb +85 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/focused.rb +7 -0
- data/spec/support/pending.rb +4 -0
- data/spec/validations_spec.rb +148 -0
- metadata +148 -7
data/lib/pinpoint.rb
CHANGED
@@ -1,5 +1,48 @@
|
|
1
1
|
require 'pinpoint/version'
|
2
|
-
require 'pinpoint/
|
2
|
+
require 'pinpoint/validations'
|
3
|
+
require 'pinpoint/address'
|
3
4
|
|
4
5
|
module Pinpoint
|
6
|
+
module ClassMethods
|
7
|
+
include Validations
|
8
|
+
|
9
|
+
def pinpoint(name, options = {})
|
10
|
+
if options[:validate]
|
11
|
+
install_validations(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
define_method name do
|
15
|
+
# TODO: Memoize
|
16
|
+
|
17
|
+
Pinpoint::Address.new(
|
18
|
+
:name => respond_to?(:"#{name}_name") ? send(:"#{name}_name") : '',
|
19
|
+
:street => respond_to?(:"#{name}_street_and_premises") ? send(:"#{name}_street_and_premises") : '',
|
20
|
+
:city => respond_to?(:"#{name}_city") ? send(:"#{name}_city") : '',
|
21
|
+
:state => respond_to?(:"#{name}_state_or_province") ? send(:"#{name}_state_or_province") : '',
|
22
|
+
:county => respond_to?(:"#{name}_district_or_county") ? send(:"#{name}_district_or_county") : '',
|
23
|
+
:postal_code => respond_to?(:"#{name}_postal_code") ? send(:"#{name}_postal_code") : '',
|
24
|
+
:country => respond_to?(:"#{name}_country") ? send(:"#{name}_country") : '',
|
25
|
+
:latitude => respond_to?(:"#{name}_latitude") ? send(:"#{name}_latitude") : '',
|
26
|
+
:longitude => respond_to?(:"#{name}_longitude") ? send(:"#{name}_longitude") : ''
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method "#{name}=" do |address|
|
31
|
+
send(:"#{name}_name=", address.name)
|
32
|
+
send(:"#{name}_street_and_premises=", address.street)
|
33
|
+
send(:"#{name}_city=", address.city)
|
34
|
+
send(:"#{name}_state_or_province=", address.state)
|
35
|
+
send(:"#{name}_postal_code=", address.zip_code)
|
36
|
+
send(:"#{name}_country=", address.country)
|
37
|
+
end
|
38
|
+
|
39
|
+
define_method "#{name}_incomplete?" do
|
40
|
+
send(:"#{name}").incomplete?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.included(base)
|
46
|
+
base.extend ClassMethods
|
47
|
+
end
|
5
48
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Pinpoint
|
2
|
+
class Address
|
3
|
+
attr_accessor :name,
|
4
|
+
:street,
|
5
|
+
:city,
|
6
|
+
:state,
|
7
|
+
:county,
|
8
|
+
:zip_code,
|
9
|
+
:country,
|
10
|
+
:latitude,
|
11
|
+
:longitude
|
12
|
+
|
13
|
+
# State Aliases
|
14
|
+
alias :region :state
|
15
|
+
alias :region= :state=
|
16
|
+
alias :province :state
|
17
|
+
alias :province= :state=
|
18
|
+
|
19
|
+
# Zip Code Aliases
|
20
|
+
alias :postal_code :zip_code
|
21
|
+
alias :postal_code= :zip_code=
|
22
|
+
alias :postalcode :zip_code
|
23
|
+
alias :postalcode= :zip_code=
|
24
|
+
alias :zip :zip_code
|
25
|
+
alias :zip= :zip_code=
|
26
|
+
|
27
|
+
# County Aliases
|
28
|
+
alias :district :county
|
29
|
+
alias :district= :county=
|
30
|
+
|
31
|
+
def initialize(options = {})
|
32
|
+
options.each do |key, value|
|
33
|
+
send("#{key}=", value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def complete?
|
38
|
+
present?(street) &&
|
39
|
+
present?(city) &&
|
40
|
+
present?(state) &&
|
41
|
+
present?(zip_code)
|
42
|
+
end
|
43
|
+
|
44
|
+
def incomplete?
|
45
|
+
!complete? && !empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
def empty?
|
49
|
+
blank?(street) &&
|
50
|
+
blank?(city) &&
|
51
|
+
blank?(state) &&
|
52
|
+
blank?(zip_code)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def present?(value)
|
57
|
+
!blank?(value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def blank?(value)
|
61
|
+
return true if value.nil?
|
62
|
+
|
63
|
+
if value.respond_to?(:match)
|
64
|
+
value.match(/\A\s*\z/)
|
65
|
+
else
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'pinpoint/us_states'
|
2
2
|
require 'pinpoint/formats'
|
3
3
|
|
4
|
-
module
|
5
|
-
module
|
6
|
-
def
|
4
|
+
module Pinpoint
|
5
|
+
module Validations
|
6
|
+
def install_validations(name)
|
7
7
|
instance_eval <<-VALIDATIONIZATION
|
8
|
+
validates :#{name}_name,
|
9
|
+
:length => {
|
10
|
+
:maximum => 140 }
|
11
|
+
|
8
12
|
validates :#{name}_street_and_premises,
|
9
13
|
:presence => {
|
10
14
|
:if => :#{name}_incomplete? },
|
@@ -31,24 +35,6 @@ module Addressable
|
|
31
35
|
:with => Pinpoint::FORMATS[:zip_code],
|
32
36
|
:allow_blank => true }
|
33
37
|
VALIDATIONIZATION
|
34
|
-
|
35
|
-
define_method :"#{name}_address?" do
|
36
|
-
send(:"#{name}_street_and_premises?") &&
|
37
|
-
send(:"#{name}_city?") &&
|
38
|
-
send(:"#{name}_state_or_province?") &&
|
39
|
-
send(:"#{name}_postal_code?")
|
40
|
-
end
|
41
|
-
|
42
|
-
define_method :"#{name}_incomplete?" do
|
43
|
-
send(:"#{name}_street_and_premises?") ||
|
44
|
-
send(:"#{name}_city?") ||
|
45
|
-
send(:"#{name}_state_or_province?") ||
|
46
|
-
send(:"#{name}_postal_code?")
|
47
|
-
end
|
48
38
|
end
|
49
39
|
end
|
50
|
-
|
51
|
-
def self.included(base)
|
52
|
-
base.extend ClassMethods
|
53
|
-
end
|
54
40
|
end
|
data/lib/pinpoint/version.rb
CHANGED
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Pinpoint::Address' do
|
4
|
+
let(:address) { Pinpoint::Address.new }
|
5
|
+
|
6
|
+
it { address.respond_to?(:region).should be_true }
|
7
|
+
it { address.respond_to?(:region=).should be_true }
|
8
|
+
it { address.respond_to?(:province).should be_true }
|
9
|
+
it { address.respond_to?(:province=).should be_true }
|
10
|
+
it { address.respond_to?(:postal_code).should be_true }
|
11
|
+
it { address.respond_to?(:postal_code=).should be_true }
|
12
|
+
it { address.respond_to?(:postalcode).should be_true }
|
13
|
+
it { address.respond_to?(:postalcode=).should be_true }
|
14
|
+
it { address.respond_to?(:zip).should be_true }
|
15
|
+
it { address.respond_to?(:zip=).should be_true }
|
16
|
+
it { address.respond_to?(:district).should be_true }
|
17
|
+
it { address.respond_to?(:district=).should be_true }
|
18
|
+
|
19
|
+
describe '#new' do
|
20
|
+
context 'when it is passed a set of initial values as a Hash' do
|
21
|
+
let(:address) do
|
22
|
+
Pinpoint::Address.new(
|
23
|
+
name: 'The Frist Center for the Visual Arts',
|
24
|
+
street: '919 Broadway',
|
25
|
+
city: 'Nashville',
|
26
|
+
state: 'Tennessee',
|
27
|
+
county: 'Davidson',
|
28
|
+
zip_code: '37203',
|
29
|
+
country: 'United States',
|
30
|
+
latitude: '36.15885623029150',
|
31
|
+
longitude: '-86.78226636970851'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sets its values properly' do
|
36
|
+
address.name.should eql 'The Frist Center for the Visual Arts'
|
37
|
+
address.street.should eql '919 Broadway'
|
38
|
+
address.city.should eql 'Nashville'
|
39
|
+
address.state.should eql 'Tennessee'
|
40
|
+
address.county.should eql 'Davidson'
|
41
|
+
address.zip_code.should eql '37203'
|
42
|
+
address.country.should eql 'United States'
|
43
|
+
address.latitude.should eql '36.15885623029150'
|
44
|
+
address.longitude.should eql '-86.78226636970851'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#complete?' do
|
50
|
+
context 'when any of the main parts of the address are blank' do
|
51
|
+
let(:address) do
|
52
|
+
Pinpoint::Address.new(
|
53
|
+
street: '',
|
54
|
+
city: 'Nashville',
|
55
|
+
state: 'Tennessee',
|
56
|
+
zip_code: '37203'
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'is false' do
|
61
|
+
address.should_not be_complete
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when any of the main parts of the address are missing' do
|
66
|
+
let(:address) do
|
67
|
+
Pinpoint::Address.new(
|
68
|
+
street: nil,
|
69
|
+
city: 'Nashville',
|
70
|
+
state: 'Tennessee',
|
71
|
+
zip_code: '37203'
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'is false' do
|
76
|
+
address.should_not be_complete
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when all of the main parts of the address are present' do
|
81
|
+
let(:address) do
|
82
|
+
Pinpoint::Address.new(
|
83
|
+
street: '919 Broadway',
|
84
|
+
city: 'Nashville',
|
85
|
+
state: 'Tennessee',
|
86
|
+
zip_code: '37203'
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'is true' do
|
91
|
+
address.should be_complete
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when all of the main parts of the address are missing' do
|
96
|
+
let(:address) do
|
97
|
+
Pinpoint::Address.new(
|
98
|
+
street: nil,
|
99
|
+
city: nil,
|
100
|
+
state: nil,
|
101
|
+
zip_code: nil
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'is false' do
|
106
|
+
address.should_not be_complete
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#incomplete?' do
|
112
|
+
context 'when any of the main parts of the address are blank' do
|
113
|
+
let(:address) do
|
114
|
+
Pinpoint::Address.new(
|
115
|
+
street: '',
|
116
|
+
city: 'Nashville',
|
117
|
+
state: 'Tennessee',
|
118
|
+
zip_code: '37203'
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'is true' do
|
123
|
+
address.should be_incomplete
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when any of the main parts of the address are missing' do
|
128
|
+
let(:address) do
|
129
|
+
Pinpoint::Address.new(
|
130
|
+
street: nil,
|
131
|
+
city: 'Nashville',
|
132
|
+
state: 'Tennessee',
|
133
|
+
zip_code: '37203'
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'is true' do
|
138
|
+
address.should be_incomplete
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when all of the main parts of the address are present' do
|
143
|
+
let(:address) do
|
144
|
+
Pinpoint::Address.new(
|
145
|
+
street: '919 Broadway',
|
146
|
+
city: 'Nashville',
|
147
|
+
state: 'Tennessee',
|
148
|
+
zip_code: '37203'
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'is false' do
|
153
|
+
address.should_not be_incomplete
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when all of the main parts of the address are missing' do
|
158
|
+
let(:address) do
|
159
|
+
Pinpoint::Address.new(
|
160
|
+
street: nil,
|
161
|
+
city: nil,
|
162
|
+
state: nil,
|
163
|
+
zip_code: nil
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'is false' do
|
168
|
+
address.should_not be_incomplete
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#empty?' do
|
174
|
+
context 'when any of the main parts of the address are blank' do
|
175
|
+
let(:address) do
|
176
|
+
Pinpoint::Address.new(
|
177
|
+
street: '',
|
178
|
+
city: 'Nashville',
|
179
|
+
state: 'Tennessee',
|
180
|
+
zip_code: '37203'
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'is false' do
|
185
|
+
address.should_not be_empty
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when any of the main parts of the address are missing' do
|
190
|
+
let(:address) do
|
191
|
+
Pinpoint::Address.new(
|
192
|
+
street: nil,
|
193
|
+
city: 'Nashville',
|
194
|
+
state: 'Tennessee',
|
195
|
+
zip_code: '37203'
|
196
|
+
)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'is false' do
|
200
|
+
address.should_not be_empty
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'when all of the main parts of the address are present' do
|
205
|
+
let(:address) do
|
206
|
+
Pinpoint::Address.new(
|
207
|
+
street: '919 Broadway',
|
208
|
+
city: 'Nashville',
|
209
|
+
state: 'Tennessee',
|
210
|
+
zip_code: '37203'
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'is false' do
|
215
|
+
address.should_not be_empty
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'when all of the main parts of the address are missing' do
|
220
|
+
let(:address) do
|
221
|
+
Pinpoint::Address.new(
|
222
|
+
street: nil,
|
223
|
+
city: nil,
|
224
|
+
state: nil,
|
225
|
+
zip_code: nil
|
226
|
+
)
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'is true' do
|
230
|
+
address.should be_empty
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Pinpointable
|
4
|
+
include Pinpoint
|
5
|
+
|
6
|
+
attr_accessor :address_name,
|
7
|
+
:address_street_and_premises,
|
8
|
+
:address_city,
|
9
|
+
:address_state_or_province,
|
10
|
+
:address_postal_code,
|
11
|
+
:address_country
|
12
|
+
|
13
|
+
pinpoint :address
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'Pinpoint' do
|
17
|
+
let(:pinpointable) { Pinpointable.new }
|
18
|
+
|
19
|
+
describe '.pinpoint' do
|
20
|
+
it 'creates a method to access the address' do
|
21
|
+
pinpointable.respond_to?(:address).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'creates a method to set the address' do
|
25
|
+
pinpointable.respond_to?(:address=).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#address' do
|
30
|
+
it 'is a Pinpoint::Address' do
|
31
|
+
pinpointable.address.should be_a Pinpoint::Address
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when the object has address information set' do
|
35
|
+
before do
|
36
|
+
pinpointable.address_name = 'The TARDIS'
|
37
|
+
pinpointable.address_street_and_premises = '413 Citadel Drive'
|
38
|
+
pinpointable.address_city = 'Panopticon'
|
39
|
+
pinpointable.address_state_or_province = 'Eye of Harmony'
|
40
|
+
pinpointable.address_postal_code = '12345'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has the correct address components' do
|
44
|
+
pinpointable.address.name.should eql 'The TARDIS'
|
45
|
+
pinpointable.address.street.should eql '413 Citadel Drive'
|
46
|
+
pinpointable.address.city.should eql 'Panopticon'
|
47
|
+
pinpointable.address.state.should eql 'Eye of Harmony'
|
48
|
+
pinpointable.address.county.should eql ''
|
49
|
+
pinpointable.address.zip_code.should eql '12345'
|
50
|
+
pinpointable.address.latitude.should eql ''
|
51
|
+
pinpointable.address.longitude.should eql ''
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#address=' do
|
57
|
+
context 'when the object has address information set' do
|
58
|
+
before do
|
59
|
+
pinpointable.address_name = 'The TARDIS'
|
60
|
+
pinpointable.address_street_and_premises = '413 Citadel Drive'
|
61
|
+
pinpointable.address_city = 'Panopticon'
|
62
|
+
pinpointable.address_state_or_province = 'Eye of Harmony'
|
63
|
+
pinpointable.address_postal_code = '12345'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'overrides the current address information with that stored in the Pinpoint::Address' do
|
67
|
+
pinpointable.address = Pinpoint::Address.new(
|
68
|
+
name: 'Buckingham Palace',
|
69
|
+
street: '',
|
70
|
+
city: 'City of Westminster',
|
71
|
+
state: 'London',
|
72
|
+
zip_code: 'SW1A',
|
73
|
+
country: 'United Kingdom'
|
74
|
+
)
|
75
|
+
|
76
|
+
pinpointable.address_name.should eql 'Buckingham Palace'
|
77
|
+
pinpointable.address_street_and_premises.should eql ''
|
78
|
+
pinpointable.address_city.should eql 'City of Westminster'
|
79
|
+
pinpointable.address_state_or_province.should eql 'London'
|
80
|
+
pinpointable.address_postal_code.should eql 'SW1A'
|
81
|
+
pinpointable.address_country.should eql 'United Kingdom'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
# Configure RSpec to run focused specs, and also respect the alias 'fit' for focused specs
|
3
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
4
|
+
config.filter_run :focused => true
|
5
|
+
config.alias_example_to :fit, :focused => true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ValidatablePinpointable
|
4
|
+
include ActiveModel::Validations
|
5
|
+
include Pinpoint
|
6
|
+
|
7
|
+
attr_accessor :address_name,
|
8
|
+
:address_street_and_premises,
|
9
|
+
:address_city,
|
10
|
+
:address_state_or_province,
|
11
|
+
:address_postal_code,
|
12
|
+
:address_country
|
13
|
+
|
14
|
+
pinpoint :address, :validate => true
|
15
|
+
end
|
16
|
+
|
17
|
+
class UnvalidatablePinpointable
|
18
|
+
include ActiveModel::Validations
|
19
|
+
include Pinpoint
|
20
|
+
|
21
|
+
attr_accessor :address_name,
|
22
|
+
:address_street_and_premises,
|
23
|
+
:address_city,
|
24
|
+
:address_state_or_province,
|
25
|
+
:address_postal_code,
|
26
|
+
:address_country
|
27
|
+
|
28
|
+
pinpoint :address
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'Pinpoint::Validations' do
|
32
|
+
context 'when the pinpoint object has validations enabled' do
|
33
|
+
subject { ValidatablePinpointable.new }
|
34
|
+
|
35
|
+
describe '#address_name' do
|
36
|
+
it { should have_valid(:address_name).when nil, ('*' * 140) }
|
37
|
+
it { should_not have_valid(:address_name).when ('*' * 141) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#address_state_or_province' do
|
41
|
+
it { should have_valid(:address_street_and_premises).when nil, ('*' * 255) }
|
42
|
+
it { should_not have_valid(:address_street_and_premises).when ('*' * 256) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#address_city' do
|
46
|
+
it { should have_valid(:address_city).when nil, ('*' * 60) }
|
47
|
+
it { should_not have_valid(:address_city).when ('*' * 61) }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#address_street_and_premises' do
|
51
|
+
it { should have_valid(:address_state_or_province).when nil, '', 'NY', 'MO' }
|
52
|
+
it { should_not have_valid(:address_state_or_province).when 'WP', 'NI', 'PO' }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#address_postal_code' do
|
56
|
+
it { should have_valid(:address_postal_code).when nil, '', 12345, 12345-1234 }
|
57
|
+
it { should_not have_valid(:address_postal_code).when 'asdf', '123456' }
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when the street address is set" do
|
61
|
+
before { subject.address_street_and_premises = "foo" }
|
62
|
+
|
63
|
+
it('the city should not be valid when blank') { should_not have_valid(:address_city).when nil, '' }
|
64
|
+
it('the state should not be valid when blank') { should_not have_valid(:address_state_or_province).when nil, '' }
|
65
|
+
it('the zip code should not be valid when blank') { should_not have_valid(:address_postal_code).when nil, '' }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the city is set" do
|
69
|
+
before { subject.address_city = "foo" }
|
70
|
+
|
71
|
+
it('the street should not be valid when blank') { should_not have_valid(:address_street_and_premises).when nil, '' }
|
72
|
+
it('the state should not be valid when blank') { should_not have_valid(:address_state_or_province).when nil, '' }
|
73
|
+
it('the zip code should not be valid when blank') { should_not have_valid(:address_postal_code).when nil, '' }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when the state is set" do
|
77
|
+
before { subject.address_state_or_province= "FO" }
|
78
|
+
|
79
|
+
it('the street should not be valid when blank') { should_not have_valid(:address_street_and_premises).when nil, '' }
|
80
|
+
it('the city should not be valid when blank') { should_not have_valid(:address_city).when nil, '' }
|
81
|
+
it('the zip code should not be valid when blank') { should_not have_valid(:address_postal_code).when nil, '' }
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when the zip is set" do
|
85
|
+
before { subject.address_postal_code = "12345" }
|
86
|
+
|
87
|
+
it('the street should not be valid when blank') { should_not have_valid(:address_street_and_premises).when nil, '' }
|
88
|
+
it('the city should not be valid when blank') { should_not have_valid(:address_city).when nil, '' }
|
89
|
+
it('the state should not be valid when blank') { should_not have_valid(:address_state_or_province).when nil, '' }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when the pinpoint object has validations enabled' do
|
94
|
+
subject { UnvalidatablePinpointable.new }
|
95
|
+
|
96
|
+
describe '#address_name' do
|
97
|
+
it { should have_valid(:address_name).when ('*' * 141) }
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#address_state_or_province' do
|
101
|
+
it { should have_valid(:address_street_and_premises).when ('*' * 256) }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#address_city' do
|
105
|
+
it { should have_valid(:address_city).when ('*' * 61) }
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#address_street_and_premises' do
|
109
|
+
it { should have_valid(:address_state_or_province).when 'WP', 'NI', 'PO' }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#address_postal_code' do
|
113
|
+
it { should have_valid(:address_postal_code).when 'asdf', '123456' }
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when the street address is set" do
|
117
|
+
before { subject.address_street_and_premises = "foo" }
|
118
|
+
|
119
|
+
it('the city should not be valid when blank') { should have_valid(:address_city).when nil, '' }
|
120
|
+
it('the state should not be valid when blank') { should have_valid(:address_state_or_province).when nil, '' }
|
121
|
+
it('the zip code should not be valid when blank') { should have_valid(:address_postal_code).when nil, '' }
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when the city is set" do
|
125
|
+
before { subject.address_city = "foo" }
|
126
|
+
|
127
|
+
it('the street should not be valid when blank') { should have_valid(:address_street_and_premises).when nil, '' }
|
128
|
+
it('the state should not be valid when blank') { should have_valid(:address_state_or_province).when nil, '' }
|
129
|
+
it('the zip code should not be valid when blank') { should have_valid(:address_postal_code).when nil, '' }
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when the state is set" do
|
133
|
+
before { subject.address_state_or_province= "FO" }
|
134
|
+
|
135
|
+
it('the street should not be valid when blank') { should have_valid(:address_street_and_premises).when nil, '' }
|
136
|
+
it('the city should not be valid when blank') { should have_valid(:address_city).when nil, '' }
|
137
|
+
it('the zip code should not be valid when blank') { should have_valid(:address_postal_code).when nil, '' }
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when the zip is set" do
|
141
|
+
before { subject.address_postal_code = "12345" }
|
142
|
+
|
143
|
+
it('the street should not be valid when blank') { should have_valid(:address_street_and_premises).when nil, '' }
|
144
|
+
it('the city should not be valid when blank') { should have_valid(:address_city).when nil, '' }
|
145
|
+
it('the state should not be valid when blank') { should have_valid(:address_state_or_province).when nil, '' }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,10 +10,138 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
13
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.11'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '2.11'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: fuubar
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.4.0
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: guard-rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.0.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.0.0
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rb-fsevent
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 0.9.1
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.9.1
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: awesome_print
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.1.0
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: valid_attribute
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.3.1
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.3.1
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: activemodel
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ~>
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 3.1.8
|
135
|
+
type: :development
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ~>
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 3.1.8
|
143
|
+
description: Handling common address logic. (currently only for US addresses but international
|
144
|
+
is planned.)
|
17
145
|
email: support@chirrpy.com
|
18
146
|
executables: []
|
19
147
|
extensions: []
|
@@ -21,14 +149,21 @@ extra_rdoc_files:
|
|
21
149
|
- README.md
|
22
150
|
- LICENSE
|
23
151
|
files:
|
24
|
-
- lib/pinpoint/
|
152
|
+
- lib/pinpoint/address.rb
|
25
153
|
- lib/pinpoint/formats.rb
|
26
154
|
- lib/pinpoint/us_states.rb
|
155
|
+
- lib/pinpoint/validations.rb
|
27
156
|
- lib/pinpoint/version.rb
|
28
157
|
- lib/pinpoint.rb
|
29
158
|
- Rakefile
|
30
159
|
- README.md
|
31
160
|
- LICENSE
|
161
|
+
- spec/address_spec.rb
|
162
|
+
- spec/pinpoint_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
- spec/support/focused.rb
|
165
|
+
- spec/support/pending.rb
|
166
|
+
- spec/validations_spec.rb
|
32
167
|
homepage: https://github.com/chirrpy/pinpoint
|
33
168
|
licenses: []
|
34
169
|
post_install_message:
|
@@ -54,4 +189,10 @@ rubygems_version: 1.8.24
|
|
54
189
|
signing_key:
|
55
190
|
specification_version: 3
|
56
191
|
summary: (Un)conventional Address Composition for Ruby (and Rails)
|
57
|
-
test_files:
|
192
|
+
test_files:
|
193
|
+
- spec/address_spec.rb
|
194
|
+
- spec/pinpoint_spec.rb
|
195
|
+
- spec/spec_helper.rb
|
196
|
+
- spec/support/focused.rb
|
197
|
+
- spec/support/pending.rb
|
198
|
+
- spec/validations_spec.rb
|