active_mocker 1.0.1 → 1.1.0

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: 68e1a8af79ab2883a1bf658e91011099e30421c4
4
- data.tar.gz: 93bca089760bc5ab015eb032b733c3d66692d2a5
3
+ metadata.gz: 0a2d0fbaa263f4bf728b582647aa394985806039
4
+ data.tar.gz: 5a84ca50696981332659a1d8094d07fdf142ea5f
5
5
  SHA512:
6
- metadata.gz: f1fde90c5a2c72a6067f2bde4811cd3b66ecf769c567fa47542147ed547ab1dcd0c5ac0da79eb866d72f21af6373dde9500f2fd5a046da23e19a00ec7f18fd0c
7
- data.tar.gz: 86212e2a028c91646ac8ed9cb76d042e1b961b3227233f60685addbb34e847b49ee3bcb8c6e7dd610abab1440dacd04262e664f85bf35ae185cb051e103f9fbe
6
+ metadata.gz: 57a40c13c1b67286ddfb54f8dbdb3674862e5bc64918157c47a1d9b5db1202aafb0b89d477d9ecc384de61f9362eb55a68b53959bfeaa3d7e760c69af0a4ffb1
7
+ data.tar.gz: 98ff48e063e348392e7311a47ed5c0f023faae5c2edc1e6bc3d27f90abd847375131da70b9c85fa7c08430fea942ac06c36d91334689c66326febc5f56558f31
data/README.md CHANGED
@@ -57,6 +57,7 @@ Or install it yourself as:
57
57
  config.model_file_reader = model_file
58
58
  # Additional Options
59
59
  config.active_hash_as_base = false #default
60
+ config.active_hash_ext = false #default
60
61
  config.schema_attributes = true #default
61
62
  config.model_relationships = true #default
62
63
  config.model_methods = true #default
@@ -171,6 +172,36 @@ ActiveHash is a simple base class that allows you to use a ruby hash as a readon
171
172
  dustin.save
172
173
  => true
173
174
 
175
+ ### Additional ActiveHash extentions
176
+
177
+ ActiveMocker::Base.configure do |config|
178
+ config.active_hash_as_base = true
179
+ config.active_hash_ext = true
180
+ end
181
+
182
+
183
+ #update method
184
+
185
+ person = PersonMock.create(first_name: 'Justin')
186
+
187
+ person.update(first_name: 'Dustin')
188
+
189
+ person.first_name
190
+ => 'Dustin'
191
+
192
+
193
+ ::destroy_all
194
+
195
+ mock_class.create
196
+
197
+ mock_class.count
198
+ => 1
199
+
200
+ mock_class.destroy_all
201
+
202
+ mock_class.count
203
+ => 0
204
+
174
205
  ### Known Limitations
175
206
 
176
207
  ::mock model names and table names must follow the default ActiveRecord naming pattern.
@@ -0,0 +1,23 @@
1
+ require_relative 'destroy_all'
2
+ require_relative 'update'
3
+
4
+ module ActiveHash
5
+
6
+ module ARApi
7
+
8
+ include ARApi::Update
9
+
10
+ def self.included(base)
11
+ base.extend(ClassMethods)
12
+ end
13
+
14
+ module ClassMethods
15
+ include ARApi::DestroyAll
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+
23
+
@@ -0,0 +1,15 @@
1
+ module ActiveHash
2
+
3
+ module ARApi
4
+
5
+ module DestroyAll
6
+
7
+ def destroy_all
8
+ delete_all
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveHash
2
+
3
+ module ARApi
4
+
5
+ module Update
6
+
7
+ def update(options={})
8
+ options.each do |method, value|
9
+ send("#{method}=", value)
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -12,7 +12,8 @@ module ActiveMocker
12
12
  :model_dir,
13
13
  :schema_file,
14
14
  :model_file_reader,
15
- :schema_file_reader
15
+ :schema_file_reader,
16
+ :active_hash_ext
16
17
 
17
18
  attr_reader :model_name, :klass
18
19
 
@@ -163,6 +164,7 @@ module ActiveMocker
163
164
  def const_class
164
165
  remove_const(mock_class_name) if class_exists? mock_class_name
165
166
  klass = Object.const_set(mock_class_name ,Class.new(ActiveHash::Base)) if active_hash_as_base
167
+ klass.send(:include, ActiveHash::ARApi) if active_hash_ext
166
168
  klass = Object.const_set(mock_class_name ,Class.new()) unless active_hash_as_base
167
169
  klass.extend ModelClassMethods
168
170
  klass.send(:include, ModelInstanceMethods) # is a private method for ruby 2.0.0
@@ -11,7 +11,9 @@ module ActiveMocker
11
11
  :model_methods,
12
12
  :mass_assignment,
13
13
  :schema_file_reader,
14
- :model_file_reader
14
+ :model_file_reader,
15
+ :active_hash_ext
16
+
15
17
 
16
18
  def config
17
19
  @@first_load ||= reload_default
@@ -27,6 +29,7 @@ module ActiveMocker
27
29
  @model_relationships = true
28
30
  @model_methods = true
29
31
  @mass_assignment = true
32
+ @active_hash_ext = false
30
33
  @log_level = Logger::WARN
31
34
  end
32
35
 
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -13,6 +13,7 @@ require 'active_mocker/schema_reader'
13
13
  require 'active_mocker/active_record/schema'
14
14
  require 'active_mocker/base'
15
15
  require 'active_support/all'
16
+ require 'active_hash/ar_api'
16
17
 
17
18
  describe ActiveMocker::Base do
18
19
 
@@ -271,7 +272,7 @@ describe ActiveMocker::Base do
271
272
  eos
272
273
  }
273
274
 
274
- it 'uses active_hase::base as superclass' do
275
+ it 'uses active_hash::base as superclass' do
275
276
  expect(mock_class.superclass.name).to eq 'ActiveHash::Base'
276
277
  end
277
278
 
@@ -303,6 +304,55 @@ describe ActiveMocker::Base do
303
304
 
304
305
  end
305
306
 
307
+ describe 'option active_hash_ext' do
308
+
309
+ before(:each) do
310
+
311
+ ActiveMocker::Base.configure do |config|
312
+ config.active_hash_as_base = true
313
+ config.active_hash_ext = true
314
+ end
315
+
316
+ end
317
+
318
+ require 'active_hash'
319
+
320
+ let(:model_file){
321
+ StringReader.new <<-eos
322
+ class Person < ActiveRecord::Base
323
+ belongs_to :account
324
+
325
+ def bar
326
+ end
327
+
328
+ end
329
+ eos
330
+ }
331
+
332
+ it '#update' do
333
+
334
+ person = mock_class.create(first_name: 'Justin')
335
+
336
+ person.update(first_name: 'Dustin')
337
+
338
+ expect(person.first_name).to eq 'Dustin'
339
+
340
+ end
341
+
342
+ it '::destroy_all' do
343
+
344
+ mock_class.create
345
+
346
+ expect(mock_class.count).to eq 1
347
+
348
+ mock_class.destroy_all
349
+
350
+ expect(mock_class.count).to eq 0
351
+
352
+ end
353
+
354
+ end
355
+
306
356
  describe 'false' do
307
357
  let(:base_options){{active_hash_as_base: false}}
308
358
 
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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
@@ -110,6 +110,9 @@ files:
110
110
  - README.md
111
111
  - Rakefile
112
112
  - active_mocker.gemspec
113
+ - lib/active_hash/ar_api.rb
114
+ - lib/active_hash/destroy_all.rb
115
+ - lib/active_hash/update.rb
113
116
  - lib/active_mocker.rb
114
117
  - lib/active_mocker/active_record.rb
115
118
  - lib/active_mocker/active_record/relationships.rb