yolk-biggs 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.textile +9 -0
- data/LICENSE +20 -0
- data/Rakefile +22 -0
- data/VERSION.yml +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/unit/activerecord_spec.rb +201 -0
- data/spec/unit/biggs_spec.rb +64 -0
- metadata +15 -9
data/CHANGES.textile
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
h3. biggs 0.1.4 - 2009-5-21
|
2
|
+
|
3
|
+
* Fixed Specs
|
4
|
+
|
5
|
+
h3. biggs 0.1.3 - 2009-3-6
|
6
|
+
|
7
|
+
* Correct japanese address format. [hiroshi]
|
8
|
+
* Fixed docs for current API. [hiroshi]
|
9
|
+
|
1
10
|
h3. biggs 0.1.2 - 2009-3-4
|
2
11
|
|
3
12
|
* Values can now be specified by an array of symbols.
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Yolk Sebastian Munz & Julia Soergel GbR
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
task :default => [:spec]
|
2
|
+
|
3
|
+
$gem_name = "biggs"
|
4
|
+
|
5
|
+
desc "Run specs"
|
6
|
+
task :spec do
|
7
|
+
sh "spec spec/* --format specdoc --color"
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |s|
|
13
|
+
s.name = $gem_name
|
14
|
+
s.summary = "biggs is a small ruby gem/rails plugin for formatting postal addresses from over 60 countries."
|
15
|
+
s.email = "sebastian@yo.lk"
|
16
|
+
s.homepage = "http://github.com/yolk/biggs"
|
17
|
+
s.description = s.summary
|
18
|
+
s.authors = ["Sebastian Munz"]
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
22
|
+
end
|
data/VERSION.yml
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
4
|
+
|
5
|
+
# A dummy class for mocking the activerecord connection class
|
6
|
+
class Connection;end
|
7
|
+
|
8
|
+
# StandardMethods for Address
|
9
|
+
module BiggsStandardMethods
|
10
|
+
Biggs::Formatter::FIELDS.each do |field|
|
11
|
+
define_method(field) do
|
12
|
+
field == :country ? "us" : field.to_s.upcase
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class FooBarEmpty < ActiveRecord::Base
|
18
|
+
include BiggsStandardMethods
|
19
|
+
end
|
20
|
+
|
21
|
+
class FooBar < ActiveRecord::Base
|
22
|
+
include BiggsStandardMethods
|
23
|
+
|
24
|
+
biggs :postal_address
|
25
|
+
end
|
26
|
+
|
27
|
+
class FooBarCustomFields < ActiveRecord::Base
|
28
|
+
include BiggsStandardMethods
|
29
|
+
|
30
|
+
biggs :postal_address, :country => :my_custom_country_method,
|
31
|
+
:city => :my_custom_city_method
|
32
|
+
|
33
|
+
def my_custom_country_method
|
34
|
+
"de"
|
35
|
+
end
|
36
|
+
|
37
|
+
def my_custom_city_method
|
38
|
+
"Hamburg"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class FooBarCustomBlankDECountry < ActiveRecord::Base
|
43
|
+
include BiggsStandardMethods
|
44
|
+
|
45
|
+
biggs :postal_address, :blank_country_on => "de"
|
46
|
+
|
47
|
+
def country
|
48
|
+
"DE"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class FooBarCustomMethod < ActiveRecord::Base
|
53
|
+
include BiggsStandardMethods
|
54
|
+
|
55
|
+
biggs :my_postal_address_method
|
56
|
+
end
|
57
|
+
|
58
|
+
class FooBarCustomProc < ActiveRecord::Base
|
59
|
+
include BiggsStandardMethods
|
60
|
+
|
61
|
+
biggs :postal_address,
|
62
|
+
:country => Proc.new {|it| it.method_accessed_from_proc + "XX"},
|
63
|
+
:state => Proc.new {|it| it.state.downcase }
|
64
|
+
|
65
|
+
def method_accessed_from_proc
|
66
|
+
"DE"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class FooBarCustomArray < ActiveRecord::Base
|
71
|
+
include BiggsStandardMethods
|
72
|
+
|
73
|
+
biggs :postal_address,
|
74
|
+
:street => [:address_1, :address_empty, :address_nil, :address_2]
|
75
|
+
|
76
|
+
def address_1
|
77
|
+
"Address line 1"
|
78
|
+
end
|
79
|
+
|
80
|
+
def address_2
|
81
|
+
"Address line 2"
|
82
|
+
end
|
83
|
+
|
84
|
+
def address_empty
|
85
|
+
""
|
86
|
+
end
|
87
|
+
|
88
|
+
def address_nil
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
describe "ActiveRecord Class" do
|
95
|
+
|
96
|
+
it "should include Biggs::ActiveRecordAdapter" do
|
97
|
+
FooBar.included_modules.should be_include(Biggs::ActiveRecordAdapter)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should set class value biggs_value_methods" do
|
101
|
+
FooBar.class_eval("biggs_value_methods").should be_is_a(Hash)
|
102
|
+
FooBar.class_eval("biggs_value_methods").size.should be_zero
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should set class value biggs_instance" do
|
106
|
+
FooBar.class_eval("biggs_instance").should be_is_a(Biggs::Formatter)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should respond to biggs" do
|
110
|
+
FooBar.should be_respond_to(:biggs)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "ActiveRecord Instance" do
|
115
|
+
|
116
|
+
describe "Empty" do
|
117
|
+
before(:each) do
|
118
|
+
connection = mock(Connection, :columns => [])
|
119
|
+
FooBarEmpty.stub!(:connection).and_return(connection)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not have postal_address method" do
|
123
|
+
FooBarEmpty.new.should_not be_respond_to(:postal_address)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "Standard" do
|
128
|
+
before(:each) do
|
129
|
+
connection = mock(Connection, :columns => [])
|
130
|
+
FooBar.stub!(:connection).and_return(connection)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have postal_address method" do
|
134
|
+
FooBar.new.should be_respond_to(:postal_address)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should return postal_address on postal_address" do
|
138
|
+
FooBar.new.postal_address.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "Customized Fields" do
|
143
|
+
before(:each) do
|
144
|
+
connection = mock(Connection, :columns => [])
|
145
|
+
FooBarCustomFields.stub!(:connection).and_return(connection)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should return address from custom fields on postal_address" do
|
149
|
+
FooBarCustomFields.new.postal_address.should eql("RECIPIENT\nSTREET\nZIP Hamburg\nGermany")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "Customized Blank DE Country" do
|
154
|
+
before(:each) do
|
155
|
+
connection = mock(Connection, :columns => [])
|
156
|
+
FooBarCustomBlankDECountry.stub!(:connection).and_return(connection)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should return address wo country on postal_address" do
|
160
|
+
FooBarCustomBlankDECountry.new.postal_address.should eql("RECIPIENT\nSTREET\nZIP CITY")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "Customized Method name" do
|
165
|
+
before(:each) do
|
166
|
+
connection = mock(Connection, :columns => [])
|
167
|
+
FooBarCustomMethod.stub!(:connection).and_return(connection)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should have my_postal_address_method" do
|
171
|
+
FooBarCustomMethod.new.should be_respond_to(:my_postal_address_method)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return formatted address on my_postal_address_method" do
|
175
|
+
FooBarCustomMethod.new.my_postal_address_method.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "Customized Proc as Param" do
|
180
|
+
before(:each) do
|
181
|
+
connection = mock(Connection, :columns => [])
|
182
|
+
FooBarCustomProc.stub!(:connection).and_return(connection)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should return formatted address for unknown-country DEXX" do
|
186
|
+
FooBarCustomProc.new.postal_address.should eql("RECIPIENT\nSTREET\nCITY state ZIP\ndexx")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "Customized array of symbols" do
|
191
|
+
before(:each) do
|
192
|
+
connection = mock(Connection, :columns => [])
|
193
|
+
FooBarCustomArray.stub!(:connection).and_return(connection)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should return formatted address with two lines for street" do
|
197
|
+
FooBarCustomArray.new.postal_address.should eql("RECIPIENT\nAddress line 1\nAddress line 2\nCITY STATE ZIP\nUnited States")
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
FAKE_ATTR_WITH_STATE = {:state => "STATE", :city => "CITY", :zip => 12345, :street => "STREET", :recipient => "MR. X"}
|
4
|
+
FAKE_ATTR_WO_STATE = {:city => "CITY", :zip => 12345, :street => "STREET", :recipient => "MR. X"}
|
5
|
+
|
6
|
+
describe Biggs::Formatter, "with defaults" do
|
7
|
+
|
8
|
+
before { @biggs = Biggs::Formatter.new }
|
9
|
+
|
10
|
+
it "should format to us format" do
|
11
|
+
@biggs.format('us', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345\nUnited States")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should format to de format" do
|
15
|
+
@biggs.format('de', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\n12345 CITY\nGermany")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should format to british format" do
|
19
|
+
@biggs.format('gb', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY\nSTATE\n12345\nUnited Kingdom")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should format to fr format" do
|
23
|
+
@biggs.format('fr', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nFrance")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should format to fr format if country_code unknown and there is no STATE given" do
|
27
|
+
@biggs.format('unknown', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nunknown")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should format to us format if country_code unknown and there is no STATE given" do
|
31
|
+
@biggs.format('unknown', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345\nunknown")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Biggs, "with options" do
|
37
|
+
|
38
|
+
describe "blank_country_on de" do
|
39
|
+
before { @biggs = Biggs::Formatter.new(:blank_country_on => 'de') }
|
40
|
+
|
41
|
+
it "should have blank country in 'de' address" do
|
42
|
+
@biggs.format('de', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have country in 'fr' address" do
|
46
|
+
@biggs.format('fr', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nFrance")
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "blank_country_on multiple (US,de)" do
|
52
|
+
before { @biggs = Biggs::Formatter.new(:blank_country_on => ['US', "de"]) }
|
53
|
+
|
54
|
+
it "should have blank country in 'us' address" do
|
55
|
+
@biggs.format('us', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have country in 'fr' address" do
|
59
|
+
@biggs.format('fr', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\n12345 CITY\nFrance")
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yolk-biggs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -19,21 +19,25 @@ executables: []
|
|
19
19
|
|
20
20
|
extensions: []
|
21
21
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.textile
|
24
25
|
files:
|
25
26
|
- CHANGES.textile
|
27
|
+
- LICENSE
|
26
28
|
- README.textile
|
29
|
+
- Rakefile
|
27
30
|
- VERSION.yml
|
28
|
-
- lib/biggs
|
31
|
+
- lib/biggs.rb
|
29
32
|
- lib/biggs/activerecord.rb
|
30
33
|
- lib/biggs/formatter.rb
|
31
|
-
-
|
34
|
+
- spec/spec_helper.rb
|
35
|
+
- spec/unit/activerecord_spec.rb
|
36
|
+
- spec/unit/biggs_spec.rb
|
32
37
|
has_rdoc: true
|
33
38
|
homepage: http://github.com/yolk/biggs
|
34
39
|
post_install_message:
|
35
40
|
rdoc_options:
|
36
|
-
- --inline-source
|
37
41
|
- --charset=UTF-8
|
38
42
|
require_paths:
|
39
43
|
- lib
|
@@ -56,5 +60,7 @@ rubygems_version: 1.2.0
|
|
56
60
|
signing_key:
|
57
61
|
specification_version: 2
|
58
62
|
summary: biggs is a small ruby gem/rails plugin for formatting postal addresses from over 60 countries.
|
59
|
-
test_files:
|
60
|
-
|
63
|
+
test_files:
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
- spec/unit/activerecord_spec.rb
|
66
|
+
- spec/unit/biggs_spec.rb
|