chilean_cities 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +674 -0
  4. data/README.md +133 -0
  5. data/Rakefile +43 -0
  6. data/lib/chilean_cities.rb +7 -0
  7. data/lib/chilean_cities/comuna.rb +27 -0
  8. data/lib/chilean_cities/comunas_list.rb +14 -0
  9. data/lib/chilean_cities/factory.rb +46 -0
  10. data/lib/chilean_cities/provincia.rb +23 -0
  11. data/lib/chilean_cities/provincia_part.rb +11 -0
  12. data/lib/chilean_cities/provincias_list.rb +14 -0
  13. data/lib/chilean_cities/region.rb +27 -0
  14. data/lib/chilean_cities/region_part.rb +6 -0
  15. data/lib/chilean_cities/version.rb +3 -0
  16. data/lib/schemas/place.rb +10 -0
  17. data/lib/schemas/thing.rb +6 -0
  18. data/spec/factories/comunas.rb +10 -0
  19. data/spec/factories/provincias.rb +9 -0
  20. data/spec/factories/regiones.rb +10 -0
  21. data/spec/lib/chilean_cities/comuna_spec.rb +67 -0
  22. data/spec/lib/chilean_cities/factory_spec.rb +46 -0
  23. data/spec/lib/chilean_cities/provincia_spec.rb +59 -0
  24. data/spec/lib/chilean_cities/region_spec.rb +66 -0
  25. data/spec/lib/chilean_cities_spec.rb +5 -0
  26. data/spec/spec_helper.rb +35 -0
  27. data/spec/support/factory_girl.rb +18 -0
  28. data/spec/support/schemas/README.md +13 -0
  29. data/spec/support/schemas/spec_for_administrative_area_interface.rb +6 -0
  30. data/spec/support/schemas/spec_for_city_interface.rb +6 -0
  31. data/spec/support/schemas/spec_for_place_interface.rb +14 -0
  32. data/spec/support/schemas/spec_for_state_interface.rb +6 -0
  33. data/spec/support/schemas/spec_for_thing_interface.rb +8 -0
  34. data/spec/support/spec_for_list_of_comunas_interface.rb +22 -0
  35. data/spec/support/spec_for_list_of_provincias_interface.rb +24 -0
  36. data/spec/support/spec_for_part_of_provincia_interface.rb +14 -0
  37. data/spec/support/spec_for_part_of_region_interface.rb +12 -0
  38. metadata +190 -0
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChileanCities::Factory do
4
+
5
+ let(:subject) { subject = ChileanCities::Factory.instance }
6
+
7
+ it 'class is a kind of Singleton', private: true do
8
+ expect(ChileanCities::Factory).to respond_to :instance
9
+ end
10
+
11
+ it 'responds to :generate!', public: true do
12
+ expect(subject).to respond_to :generate!
13
+ end
14
+
15
+ describe '#generate!', public: true do
16
+
17
+ it 'generates Comuna, Provincia and Region objects from the data' do
18
+ expect(subject.generate!).to eq({ comunas_count: 346, provincias_count: 54, regiones_count: 15 })
19
+ end
20
+
21
+ describe 'generates a collection of' do
22
+
23
+ it 'valid Regiones instances' do
24
+ subject.regiones.each do |region|
25
+ expect(region).to be_valid
26
+ end
27
+ subject.generate!
28
+ end
29
+
30
+ it 'valid Provincias instances' do
31
+ subject.provincias.each do |provincia|
32
+ expect(provincia).to be_valid
33
+ end
34
+ subject.generate!
35
+ end
36
+
37
+ it 'valid Comunas instances' do
38
+ subject.comunas.first.valid?
39
+ subject.comunas.each do |comuna|
40
+ expect(comuna).to be_valid
41
+ end
42
+ subject.generate!
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChileanCities::Provincia do
4
+
5
+ describe 'provides a Schema.org interface', public: true do
6
+ it_behaves_like 'an AdministrativeArea'
7
+ end
8
+
9
+ it_behaves_like 'a list of ChileanCities::Comuna'
10
+
11
+ it_behaves_like 'part of a ChileanCities::Region'
12
+
13
+ # validations
14
+
15
+ it 'has a valid factory', private: true do
16
+ expect(FactoryGirl.build(:provincia)).to be_valid
17
+ end
18
+
19
+ it 'requires a name', private: true do
20
+ expect(FactoryGirl.build(:provincia, name: nil)).not_to be_valid
21
+ end
22
+
23
+ describe '#comunas', data: true, private: true do
24
+
25
+ it 'returns a list of ChileanCities::Comuna' do
26
+ chile = ChileanCities::Factory.instance
27
+ chile.generate!
28
+
29
+ subject = chile.provincias.sample
30
+
31
+ expect(subject.comunas).not_to be_empty
32
+ expect(subject.comunas.sample).to be_instance_of ChileanCities::Comuna
33
+ end
34
+ end
35
+
36
+ describe '#region', data: true, private: true do
37
+
38
+ it 'returns a ChileanCities::Region' do
39
+ chile = ChileanCities::Factory.instance
40
+ chile.generate!
41
+
42
+ subject = chile.provincias.sample
43
+ expect(subject.region).not_to be_nil
44
+ expect(subject.region).to be_instance_of ChileanCities::Region
45
+ end
46
+ end
47
+
48
+ describe '#contained_in', data: true, private: true do
49
+
50
+ it 'returns a ChileanCities::Region' do
51
+ chile = ChileanCities::Factory.instance
52
+ chile.generate!
53
+
54
+ subject = chile.provincias.sample
55
+ expect(subject.contained_in).not_to be_nil
56
+ expect(subject.contained_in).to be_instance_of ChileanCities::Region
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChileanCities::Region do
4
+
5
+ describe 'provides a Schema.org interface', public: true do
6
+ it_behaves_like 'a State'
7
+ end
8
+
9
+ it 'responds to :iso_3166_2', public: true do
10
+ expect(subject).to respond_to :iso_3166_2
11
+ end
12
+
13
+ it_behaves_like 'a list of ChileanCities::Provincia'
14
+
15
+ # validations
16
+
17
+ it 'has a valid factory', private: true do
18
+ expect(FactoryGirl.build(:region)).to be_valid
19
+ end
20
+
21
+ it 'requires a name', private: true do
22
+ expect(FactoryGirl.build(:region, name: nil)).not_to be_valid
23
+ end
24
+
25
+ it 'requires an ISO 3166-2:CL code', private: true do
26
+ # see https://en.wikipedia.org/wiki/ISO_3166-2:CL
27
+ expect(FactoryGirl.build(:region, iso_3166_2: nil)).not_to be_valid
28
+ end
29
+
30
+ it 'requires iso_3166_2 to be a valid ISO 3166-2:CL code', private: true do
31
+ expect(FactoryGirl.build(:region, iso_3166_2: 'CP-AN')).not_to be_valid
32
+ expect(FactoryGirl.build(:region, iso_3166_2: 'CL-AND')).not_to be_valid
33
+ expect(FactoryGirl.build(:region, iso_3166_2: 'CL_AN')).not_to be_valid
34
+ expect(FactoryGirl.build(:region, iso_3166_2: 'CLAN')).not_to be_valid
35
+ expect(FactoryGirl.build(:region, iso_3166_2: 'CL-AN')).to be_valid
36
+ expect(FactoryGirl.build(:region, iso_3166_2: 'CL-A2')).not_to be_valid
37
+ expect(FactoryGirl.build(:region, iso_3166_2: 'ACL-AN')).not_to be_valid
38
+ expect(FactoryGirl.build(:region, iso_3166_2: 'AL-AN')).not_to be_valid
39
+ end
40
+
41
+ describe '#provincias', data: true, private: true do
42
+
43
+ it 'returns a list of ChileanCities::Provincia' do
44
+ chile = ChileanCities::Factory.instance
45
+ chile.generate!
46
+
47
+ subject = chile.regiones.sample
48
+
49
+ expect(subject.provincias).not_to be_empty
50
+ expect(subject.provincias.sample).to be_instance_of ChileanCities::Provincia
51
+ end
52
+ end
53
+
54
+ describe '#comunas', data: true, private: true do
55
+
56
+ it 'returns a list of ChileanCities::Comuna' do
57
+ chile = ChileanCities::Factory.instance
58
+ chile.generate!
59
+
60
+ subject = chile.regiones.sample
61
+
62
+ expect(subject.comunas).not_to be_empty
63
+ expect(subject.comunas.sample).to be_instance_of ChileanCities::Comuna
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChileanCities do
4
+
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'chilean_cities'
5
+
6
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f; puts f }
7
+
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ # make sure the deprecated RSpec 2 syntax is not used
11
+ config.raise_errors_for_deprecations!
12
+
13
+ # rspec-expectations config goes here. You can use an alternate
14
+ # assertion/expectation library such as wrong or the stdlib/minitest
15
+ # assertions if you prefer.
16
+ config.expect_with :rspec do |expectations|
17
+ # This option will default to `true` in RSpec 4. It makes the `description`
18
+ # and `failure_message` of custom matchers include text for helper methods
19
+ # defined using `chain`, e.g.:
20
+ # be_bigger_than(2).and_smaller_than(4).description
21
+ # # => "be bigger than 2 and smaller than 4"
22
+ # ...rather than:
23
+ # # => "be bigger than 2"
24
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
25
+ end
26
+
27
+ # rspec-mocks config goes here. You can use an alternate test double
28
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
29
+ config.mock_with :rspec do |mocks|
30
+ # Prevents you from mocking or stubbing a method that does not exist on
31
+ # a real object. This is generally recommended, and will default to
32
+ # `true` in RSpec 4.
33
+ mocks.verify_partial_doubles = true
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ require 'factory_girl'
2
+
3
+ RSpec.configure do |config|
4
+ config.include FactoryGirl::Syntax::Methods
5
+
6
+ Dir["#{File.dirname(__FILE__)}/../factories/**/*.rb"].each {|f| require f}
7
+
8
+ # check_factories_validity!
9
+ # see https://github.com/thoughtbot/factory_girl/blob/v4.5.0/GETTING_STARTED.md
10
+ #
11
+ # factories_to_lint = FactoryGirl.factories.reject do |factory|
12
+ # factory.name =~ /^invalid_/
13
+ # end
14
+ #
15
+ # config.before(:suite) do
16
+ # FactoryGirl.lint factories_to_lint
17
+ # end
18
+ end
@@ -0,0 +1,13 @@
1
+ Schema.org Specifications
2
+ =========================
3
+
4
+
5
+ These specifications allow to enforce the implementation of schemas (see [schema.org][schema]).
6
+
7
+ Schema properties are optional, for that reason, those specs are not meant to describe the full schemas. Instead, they describe the aspects of the schemas which we believe our own objects should be able to provide and allow to ensure those objects do provide them.
8
+
9
+ **Based on** the `1.93 sdo-stantz (2015-02-04)` [Schema.org][releases] release.
10
+
11
+
12
+ [schema]: http://schema.org
13
+ [releases]: http://schema.org/docs/releases.html
@@ -0,0 +1,6 @@
1
+ RSpec.shared_examples 'an AdministrativeArea' do
2
+
3
+ let(:administrative_area) { described_class.new() }
4
+
5
+ it_behaves_like 'a Place'
6
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.shared_examples 'a City' do
2
+
3
+ let(:place) { described_class.new() }
4
+
5
+ it_behaves_like 'an AdministrativeArea'
6
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.shared_examples 'a Place' do
2
+
3
+ let(:place) { described_class.new() }
4
+
5
+ it_behaves_like 'a Thing'
6
+
7
+ it 'responds to :contained_in', public: true do
8
+ expect(place).to respond_to :contained_in
9
+ end
10
+
11
+ it 'responds to :has_map', public: true do
12
+ expect(place).to respond_to :has_map
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.shared_examples 'a State' do
2
+
3
+ let(:place) { described_class.new() }
4
+
5
+ it_behaves_like 'an AdministrativeArea'
6
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.shared_examples 'a Thing' do
2
+
3
+ let(:thing) { described_class.new() }
4
+
5
+ it 'responds to :name', public: true do
6
+ expect(thing).to respond_to :name
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ RSpec.shared_examples 'a list of ChileanCities::Comuna' do
2
+
3
+ let(:comunas_list) { described_class.new() }
4
+
5
+ it 'responds to #comunas', public: true do
6
+ expect(comunas_list).to respond_to :comunas
7
+ end
8
+
9
+ it 'responds to #append_comuna', private: true do
10
+ expect(comunas_list).to respond_to :append_comuna
11
+ end
12
+
13
+ describe '#append_comuna', private: true do
14
+
15
+ it 'appends the comuna to the comunas list if not already present' do
16
+ comuna = FactoryGirl.build(:comuna)
17
+ expect{ comunas_list.append_comuna(comuna) }.to change{
18
+ comunas_list.comunas
19
+ }.from([]).to([comuna])
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ RSpec.shared_examples 'a list of ChileanCities::Provincia' do
2
+
3
+ let(:provincias_list) { described_class.new() }
4
+
5
+ it_behaves_like 'a list of ChileanCities::Comuna'
6
+
7
+ it 'responds to #provincias', public: true do
8
+ expect(provincias_list).to respond_to :provincias
9
+ end
10
+
11
+ it 'responds to #append_provincia', private: true do
12
+ expect(provincias_list).to respond_to :append_provincia
13
+ end
14
+
15
+ describe '#append_provincia', private: true do
16
+
17
+ it 'appends the provincia to the provincias list if not already present' do
18
+ provincia = FactoryGirl.build(:provincia)
19
+ expect{ provincias_list.append_provincia(provincia) }.to change{
20
+ provincias_list.provincias
21
+ }.from([]).to([provincia])
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.shared_examples 'part of a ChileanCities::Provincia' do
2
+
3
+ let(:part_of_provincia) { described_class.new() }
4
+
5
+ it_behaves_like 'part of a ChileanCities::Region'
6
+
7
+ it 'responds to #provincia', public: true do
8
+ expect(part_of_provincia).to respond_to :provincia
9
+ end
10
+
11
+ it 'responds to #provincia=', private: true do
12
+ expect(part_of_provincia).to respond_to :provincia=
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ RSpec.shared_examples 'part of a ChileanCities::Region' do
2
+
3
+ let(:part_of_region) { described_class.new() }
4
+
5
+ it 'responds to #region', public: true do
6
+ expect(part_of_region).to respond_to :region
7
+ end
8
+
9
+ it 'responds to #region=', private: true do
10
+ expect(part_of_region).to respond_to :region=
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chilean_cities
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Bulnes Guilpain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.11
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.11
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: multi_json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: inch
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.4.6
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.4.6
89
+ - !ruby/object:Gem::Dependency
90
+ name: factory_girl
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '4.5'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '4.5'
103
+ description: A ruby implementation of the Chilean 'comunas'.
104
+ email:
105
+ - gon.bulnes@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - lib/chilean_cities.rb
115
+ - lib/chilean_cities/comuna.rb
116
+ - lib/chilean_cities/comunas_list.rb
117
+ - lib/chilean_cities/factory.rb
118
+ - lib/chilean_cities/provincia.rb
119
+ - lib/chilean_cities/provincia_part.rb
120
+ - lib/chilean_cities/provincias_list.rb
121
+ - lib/chilean_cities/region.rb
122
+ - lib/chilean_cities/region_part.rb
123
+ - lib/chilean_cities/version.rb
124
+ - lib/schemas/place.rb
125
+ - lib/schemas/thing.rb
126
+ - spec/factories/comunas.rb
127
+ - spec/factories/provincias.rb
128
+ - spec/factories/regiones.rb
129
+ - spec/lib/chilean_cities/comuna_spec.rb
130
+ - spec/lib/chilean_cities/factory_spec.rb
131
+ - spec/lib/chilean_cities/provincia_spec.rb
132
+ - spec/lib/chilean_cities/region_spec.rb
133
+ - spec/lib/chilean_cities_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/support/factory_girl.rb
136
+ - spec/support/schemas/README.md
137
+ - spec/support/schemas/spec_for_administrative_area_interface.rb
138
+ - spec/support/schemas/spec_for_city_interface.rb
139
+ - spec/support/schemas/spec_for_place_interface.rb
140
+ - spec/support/schemas/spec_for_state_interface.rb
141
+ - spec/support/schemas/spec_for_thing_interface.rb
142
+ - spec/support/spec_for_list_of_comunas_interface.rb
143
+ - spec/support/spec_for_list_of_provincias_interface.rb
144
+ - spec/support/spec_for_part_of_provincia_interface.rb
145
+ - spec/support/spec_for_part_of_region_interface.rb
146
+ homepage: https://github.com/gonzalo-bulnes/chilean_cities
147
+ licenses:
148
+ - GPL-3.0
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubygems_version: 3.0.3
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Provides a Ruby representation of the Chilean 'comunas' as described by the
169
+ Subsecretaría de Desarrollo Regional y Administrativo.
170
+ test_files:
171
+ - spec/spec_helper.rb
172
+ - spec/support/spec_for_list_of_provincias_interface.rb
173
+ - spec/support/spec_for_part_of_provincia_interface.rb
174
+ - spec/support/schemas/spec_for_place_interface.rb
175
+ - spec/support/schemas/spec_for_thing_interface.rb
176
+ - spec/support/schemas/README.md
177
+ - spec/support/schemas/spec_for_city_interface.rb
178
+ - spec/support/schemas/spec_for_administrative_area_interface.rb
179
+ - spec/support/schemas/spec_for_state_interface.rb
180
+ - spec/support/spec_for_list_of_comunas_interface.rb
181
+ - spec/support/spec_for_part_of_region_interface.rb
182
+ - spec/support/factory_girl.rb
183
+ - spec/factories/regiones.rb
184
+ - spec/factories/comunas.rb
185
+ - spec/factories/provincias.rb
186
+ - spec/lib/chilean_cities/comuna_spec.rb
187
+ - spec/lib/chilean_cities/factory_spec.rb
188
+ - spec/lib/chilean_cities/provincia_spec.rb
189
+ - spec/lib/chilean_cities/region_spec.rb
190
+ - spec/lib/chilean_cities_spec.rb