mas-rad_core 0.0.94 → 0.0.95

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.
Binary file
@@ -1,13 +0,0 @@
1
- RSpec.describe DeleteFirmJob, '#perform' do
2
- let(:repository) { instance_double(FirmRepository) }
3
-
4
- before do
5
- allow(FirmRepository).to receive(:new).and_return(repository)
6
- end
7
-
8
- it 'delegates to the firm repository' do
9
- expect(repository).to receive(:delete).with(1)
10
-
11
- described_class.new.perform(1)
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- RSpec.describe IndexFirmJob, '#perform' do
2
- let(:firm) { Firm.new }
3
-
4
- it 'delegates to the firm indexer' do
5
- expect(FirmIndexer).to receive(:index_firm).with(firm)
6
- described_class.new.perform(firm)
7
- end
8
- end
@@ -1,224 +0,0 @@
1
- RSpec.shared_examples 'synchronously geocodable' do
2
- describe 'the interface the geocodable must implement' do
3
- subject { valid_new_geocodable }
4
-
5
- # needed for the ModelGeocoder
6
- it { is_expected.to respond_to(:full_street_address) }
7
-
8
- # used by #needs_to_be_geocoded?
9
- it { is_expected.to respond_to(:has_address_changes?) }
10
-
11
- # used by #geocode
12
- it { is_expected.to respond_to(:add_geocoding_failed_error) }
13
- end
14
-
15
- def modify_address(subject)
16
- subject.send("#{address_field_name}=", address_field_updated_value)
17
- end
18
-
19
- describe '#geocode' do
20
- context 'when the subject is not valid' do
21
- subject { invalid_geocodable }
22
-
23
- it 'does not call the geocoder' do
24
- expect(ModelGeocoder).not_to receive(:geocode)
25
- subject.geocode
26
- end
27
-
28
- it 'returns false' do
29
- expect(subject.geocode).to be(false)
30
- end
31
- end
32
-
33
- context 'when the subject is valid' do
34
- subject { valid_new_geocodable }
35
-
36
- context 'when the subject does not need to be geocoded' do
37
- before do
38
- subject.coordinates = [1.0, 1.0]
39
- subject.save!
40
- end
41
-
42
- it 'does not call the geocoder' do
43
- expect(ModelGeocoder).not_to receive(:geocode)
44
- subject.geocode
45
- end
46
-
47
- it 'returns true' do
48
- expect(subject.geocode).to be(true)
49
- end
50
- end
51
-
52
- context 'when the subject needs to be geocoded' do
53
- before do
54
- subject.coordinates = nil
55
- end
56
-
57
- context 'when geocoding succeeds' do
58
- before do
59
- allow(ModelGeocoder).to receive(:geocode).and_return([1.0, 1.0])
60
- end
61
-
62
- it 'returns true' do
63
- expect(subject.geocode).to be(true)
64
- end
65
-
66
- specify 'subject.errors.count is 0' do
67
- subject.geocode
68
- expect(subject.errors.count).to be(0)
69
- end
70
-
71
- context 'no persistence' do
72
- before do
73
- subject.save!
74
- expect(subject).not_to be_changed
75
- expect(subject.coordinates).to eq([nil, nil])
76
- subject.geocode
77
- end
78
-
79
- it 'sets the new coordinates on the in-memory instance' do
80
- expect(subject.coordinates).to eq([1.0, 1.0])
81
- end
82
-
83
- it 'does not persist the changed fields' do
84
- expect(subject).to be_changed
85
- expect(subject.reload.coordinates).to eq([nil, nil])
86
- end
87
- end
88
- end
89
-
90
- context 'when geocoding fails' do
91
- before do
92
- allow(ModelGeocoder).to receive(:geocode).and_return(nil)
93
- end
94
-
95
- it 'adds an error to subject.errors' do
96
- subject.geocode
97
- expect(subject.errors).to have_key(:geocoding)
98
- end
99
-
100
- it 'returns false' do
101
- expect(subject.geocode).to be(false)
102
- end
103
-
104
- context 'no persistence' do
105
- before do
106
- subject.coordinates = [1.0, 1.0]
107
- subject.save!
108
- modify_address(subject)
109
- subject.geocode
110
- end
111
-
112
- it 'blanks out the in-memory instance coordinates' do
113
- expect(subject.coordinates).to eq([nil, nil])
114
- end
115
-
116
- it 'does not persist the changed fields' do
117
- expect(subject).to be_changed
118
- expect(subject.reload.coordinates).to eq([1.0, 1.0])
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
125
-
126
- describe '#needs_to_be_geocoded?' do
127
- subject { saved_geocodable }
128
-
129
- context 'when the model has not been geocoded' do
130
- before do
131
- subject.coordinates = nil
132
- expect(subject).not_to be_geocoded
133
- end
134
-
135
- it 'returns true' do
136
- expect(subject.needs_to_be_geocoded?).to be(true)
137
- end
138
- end
139
-
140
- context 'when the model has been geocoded' do
141
- before do
142
- subject.update_coordinates!([1.0, 1.0])
143
- expect(subject).to be_geocoded
144
- end
145
-
146
- context 'when the model address fields have not changed' do
147
- before do
148
- expect(subject).not_to have_address_changes
149
- end
150
-
151
- it 'returns false' do
152
- expect(subject.needs_to_be_geocoded?).to be(false)
153
- end
154
- end
155
-
156
- context 'when the model address fields have changed' do
157
- before do
158
- modify_address(subject)
159
- expect(subject).to have_address_changes
160
- end
161
-
162
- it 'returns true' do
163
- expect(subject.needs_to_be_geocoded?).to be(true)
164
- end
165
- end
166
- end
167
- end
168
-
169
- describe '#save_with_geocoding' do
170
- before { allow(saved_geocodable).to receive(:geocode).and_return(result_of_geocoding) }
171
- subject { saved_geocodable.save_with_geocoding }
172
-
173
- context 'when geocoding fails' do
174
- let(:result_of_geocoding) { false }
175
-
176
- it { is_expected.to be(false) }
177
-
178
- it 'does not call save' do
179
- expect(saved_geocodable).not_to receive(:save)
180
- subject
181
- end
182
- end
183
-
184
- context 'when geocoding succeeds' do
185
- let(:result_of_geocoding) { true }
186
- let(:result_of_saving) { true }
187
- before { allow(saved_geocodable).to receive(:save).and_return(result_of_saving) }
188
-
189
- it 'calls save' do
190
- expect(saved_geocodable).to receive(:save)
191
- subject
192
- end
193
-
194
- context 'when saving fails' do
195
- let(:result_of_saving) { false }
196
- it { is_expected.to be(false) }
197
- end
198
-
199
- context 'when saving succeeds' do
200
- it { is_expected.to be(true) }
201
- end
202
- end
203
- end
204
-
205
- describe '#update_with_geocoding' do
206
- subject { saved_geocodable.update_with_geocoding(updated_address_params) }
207
-
208
- it 'updates the geocodable with new attributes' do
209
- allow(saved_geocodable).to receive(:save_with_geocoding)
210
- subject
211
- expect(saved_geocodable.changed_attributes).to include(updated_address_params.keys.first)
212
- end
213
-
214
- it 'calls #save_with_geocoding' do
215
- expect(saved_geocodable).to receive(:save_with_geocoding)
216
- subject
217
- end
218
-
219
- it 'returns the return value of #save_with_geocoding' do
220
- allow(saved_geocodable).to receive(:save_with_geocoding).and_return(:return_marker)
221
- expect(subject).to eq(:return_marker)
222
- end
223
- end
224
- end