active_mocker 1.1.1 → 1.1.2
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.
- checksums.yaml +4 -4
- data/lib/active_mocker/base.rb +31 -3
- data/lib/active_mocker/version.rb +1 -1
- data/spec/lib/active_mocker/base_spec.rb +21 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe27b7374829d87d0aa1c346ecee3fb84e590f9
|
4
|
+
data.tar.gz: 5032e5a828552e52cd2f94b0ea9fcd85aaaeb43e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: debf17b98ec1e2204d28a18b80fadf6e753ce90592eee6203fe842e475c21cce8f6c80d96ce0be70c1d990ff7dc7955f5d469cbd1852ee903e3f127bdd2afaeb
|
7
|
+
data.tar.gz: ec9343f533db64c8206fbb8349a7d683d8baf426d8980582918ba9556d2e71e6ebfb231cf3838606e376fcf8467a4f4abe701f9b8910efb7557f1347014992d3
|
data/lib/active_mocker/base.rb
CHANGED
@@ -104,8 +104,18 @@ module ActiveMocker
|
|
104
104
|
def add_table_attributes
|
105
105
|
klass = create_klass
|
106
106
|
table_definition.column_names.each do |m|
|
107
|
-
|
108
|
-
klass.
|
107
|
+
|
108
|
+
klass.send(:schema_attributes_template)[m] = nil
|
109
|
+
|
110
|
+
klass.class_eval <<-eos, __FILE__, __LINE__+1 unless m =~ /^\d/
|
111
|
+
def #{m}
|
112
|
+
read_attribute(#{m.inspect})
|
113
|
+
end
|
114
|
+
|
115
|
+
def #{m}=(value)
|
116
|
+
write_attribute(#{m.inspect}, value)
|
117
|
+
end
|
118
|
+
eos
|
109
119
|
end
|
110
120
|
end
|
111
121
|
|
@@ -194,12 +204,23 @@ module ActiveMocker
|
|
194
204
|
model_instance_methods[method] = block
|
195
205
|
end
|
196
206
|
|
207
|
+
def read_attribute(attr)
|
208
|
+
schema_attributes[attr]
|
209
|
+
end
|
210
|
+
|
211
|
+
def write_attribute(attr, value)
|
212
|
+
schema_attributes[attr] = value
|
213
|
+
end
|
214
|
+
|
197
215
|
private
|
198
216
|
|
199
217
|
def model_instance_methods
|
200
218
|
@model_instance_methods ||= self.class.send(:model_methods_template).dup
|
201
219
|
end
|
202
220
|
|
221
|
+
def schema_attributes
|
222
|
+
@schema_attributes ||= self.class.send(:schema_attributes_template).dup
|
223
|
+
end
|
203
224
|
end
|
204
225
|
|
205
226
|
module ModelClassMethods
|
@@ -212,6 +233,10 @@ module ActiveMocker
|
|
212
233
|
model_class_methods[method] = block
|
213
234
|
end
|
214
235
|
|
236
|
+
def column_names
|
237
|
+
schema_attributes_template
|
238
|
+
end
|
239
|
+
|
215
240
|
private
|
216
241
|
|
217
242
|
def model_class_methods
|
@@ -222,8 +247,11 @@ module ActiveMocker
|
|
222
247
|
@model_methods_template ||= HashWithIndifferentAccess.new
|
223
248
|
end
|
224
249
|
|
225
|
-
|
250
|
+
def schema_attributes_template
|
251
|
+
@schema_attributes_template ||= HashWithIndifferentAccess.new
|
252
|
+
end
|
226
253
|
|
254
|
+
end
|
227
255
|
|
228
256
|
end
|
229
257
|
|
@@ -62,6 +62,7 @@ describe ActiveMocker::Base do
|
|
62
62
|
t.string "last_name", limit: 128
|
63
63
|
t.string "address", limit: 200
|
64
64
|
t.string "city", limit: 100
|
65
|
+
t.string "800_number", limit: 100
|
65
66
|
end
|
66
67
|
|
67
68
|
end
|
@@ -71,7 +72,25 @@ describe ActiveMocker::Base do
|
|
71
72
|
describe '::column_names' do
|
72
73
|
|
73
74
|
it 'returns an array of column names found from the schema.rb file' do
|
74
|
-
expect(mock_class.column_names).to eq(["account_id", "first_name", "last_name", "address", "city"])
|
75
|
+
expect(mock_class.column_names).to eq(["account_id", "first_name", "last_name", "address", "city", "800_number"])
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#read_attribute' do
|
81
|
+
|
82
|
+
it 'will access attributes' do
|
83
|
+
mock_class.new.read_attribute("800_number")
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#write_attribute' do
|
89
|
+
|
90
|
+
it 'will access attributes' do
|
91
|
+
person = mock_class.new
|
92
|
+
person.write_attribute("800_number", 100)
|
93
|
+
expect(person.read_attribute("800_number")).to eq 100
|
75
94
|
end
|
76
95
|
|
77
96
|
end
|
@@ -292,7 +311,7 @@ describe ActiveMocker::Base do
|
|
292
311
|
end
|
293
312
|
|
294
313
|
it '::column_names' do
|
295
|
-
expect(mock_class.column_names).to eq(["account_id", "first_name", "last_name", "address", "city"])
|
314
|
+
expect(mock_class.column_names).to eq(["account_id", "first_name", "last_name", "address", "city","800_number"])
|
296
315
|
end
|
297
316
|
|
298
317
|
it '#mock_of' do
|