active_mocker 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb88e9bbdae088750346daa4001db130c1aed7e3
4
- data.tar.gz: 14d05364da6e8ba9e0b0f6566c159c2c7391c9e6
3
+ metadata.gz: bfe27b7374829d87d0aa1c346ecee3fb84e590f9
4
+ data.tar.gz: 5032e5a828552e52cd2f94b0ea9fcd85aaaeb43e
5
5
  SHA512:
6
- metadata.gz: 4076f1de34b83f6b75bb52f63e95c06d3be4866dd6c8efc27f297d87954780455a0f5e761ee0bfc4ab1db4e6665c8bce15c5a407d1816b4a8b8492cb855fd44a
7
- data.tar.gz: 58e11aeaf5570ef0e1a7ce37b7a71516424eb28f47923666ee6839de6da9aafc5a19555ed8c58a06110a7056c66c22ceb05c54562af0c3c0c38393c876f2e551
6
+ metadata.gz: debf17b98ec1e2204d28a18b80fadf6e753ce90592eee6203fe842e475c21cce8f6c80d96ce0be70c1d990ff7dc7955f5d469cbd1852ee903e3f127bdd2afaeb
7
+ data.tar.gz: ec9343f533db64c8206fbb8349a7d683d8baf426d8980582918ba9556d2e71e6ebfb231cf3838606e376fcf8467a4f4abe701f9b8910efb7557f1347014992d3
@@ -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
- klass.instance_variable_set("@#{m}", nil)
108
- klass.class_eval { attr_accessor m }
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
- end
250
+ def schema_attributes_template
251
+ @schema_attributes_template ||= HashWithIndifferentAccess.new
252
+ end
226
253
 
254
+ end
227
255
 
228
256
  end
229
257
 
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler