active_mocker 1.1.0 → 1.1.1

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: 0a2d0fbaa263f4bf728b582647aa394985806039
4
- data.tar.gz: 5a84ca50696981332659a1d8094d07fdf142ea5f
3
+ metadata.gz: bb88e9bbdae088750346daa4001db130c1aed7e3
4
+ data.tar.gz: 14d05364da6e8ba9e0b0f6566c159c2c7391c9e6
5
5
  SHA512:
6
- metadata.gz: 57a40c13c1b67286ddfb54f8dbdb3674862e5bc64918157c47a1d9b5db1202aafb0b89d477d9ecc384de61f9362eb55a68b53959bfeaa3d7e760c69af0a4ffb1
7
- data.tar.gz: 98ff48e063e348392e7311a47ed5c0f023faae5c2edc1e6bc3d27f90abd847375131da70b9c85fa7c08430fea942ac06c36d91334689c66326febc5f56558f31
6
+ metadata.gz: 4076f1de34b83f6b75bb52f63e95c06d3be4866dd6c8efc27f297d87954780455a0f5e761ee0bfc4ab1db4e6665c8bce15c5a407d1816b4a8b8492cb855fd44a
7
+ data.tar.gz: 58e11aeaf5570ef0e1a7ce37b7a71516424eb28f47923666ee6839de6da9aafc5a19555ed8c58a06110a7056c66c22ceb05c54562af0c3c0c38393c876f2e551
data/README.md CHANGED
@@ -44,6 +44,9 @@ Or install it yourself as:
44
44
  puts name
45
45
  end
46
46
 
47
+ def self.bar
48
+ end
49
+
47
50
  end
48
51
 
49
52
  require 'active_mocker'
@@ -52,12 +55,8 @@ Or install it yourself as:
52
55
  # Required Options
53
56
  config.schema_file = "#{APP_ROOT}/db/schema.rb"
54
57
  config.model_dir = "#{APP_ROOT}/app/models"
55
- # Dependency injection
56
- config.schema_file_reader = schema_file
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
61
60
  config.schema_attributes = true #default
62
61
  config.model_relationships = true #default
63
62
  config.model_methods = true #default
@@ -98,7 +97,7 @@ Or install it yourself as:
98
97
  => NoMethodError: undefined method `first_name=' for #<PersonMock:0x007f860abf6b10>
99
98
 
100
99
 
101
- ### Mocking instance methods
100
+ ### Mocking instance and class methods
102
101
 
103
102
  person_mock.bar
104
103
  => ArgumentError: wrong number of arguments (0 for 1..2)
@@ -114,6 +113,10 @@ Or install it yourself as:
114
113
  mock_class.new.bar('foo', 'type')
115
114
  => "Now implemented with foo and type"
116
115
 
116
+ mock_class.mock_class_method(:baz) do
117
+ "Now implemented"
118
+ end
119
+
117
120
  ### When the model changes the mock fails
118
121
 
119
122
  #app/models/person.rb
@@ -127,8 +130,8 @@ Or install it yourself as:
127
130
 
128
131
  end
129
132
 
130
- mock_class.new.bar('foo', 'type')
131
- => ArgumentError: wrong number of arguments (2 for 1)
133
+ mock_class.new.bar('foo', 'type')
134
+ => ArgumentError: wrong number of arguments (2 for 1)
132
135
 
133
136
 
134
137
  app/models/person.rb
@@ -152,7 +155,6 @@ ActiveHash is a simple base class that allows you to use a ruby hash as a readon
152
155
  [zilkey/active_hash](https://github.com/zilkey/active_hash)
153
156
 
154
157
 
155
-
156
158
  ActiveMocker::Base.configure do |config|
157
159
  config.active_hash_as_base = true
158
160
  end
@@ -172,15 +174,10 @@ ActiveHash is a simple base class that allows you to use a ruby hash as a readon
172
174
  dustin.save
173
175
  => true
174
176
 
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
177
+ ### Additional ActiveHash extentions for matching ActiveRecord
181
178
 
182
179
 
183
- #update method
180
+ #### #update method
184
181
 
185
182
  person = PersonMock.create(first_name: 'Justin')
186
183
 
@@ -190,9 +187,9 @@ ActiveHash is a simple base class that allows you to use a ruby hash as a readon
190
187
  => 'Dustin'
191
188
 
192
189
 
193
- ::destroy_all
190
+ #### ::destroy_all
194
191
 
195
- mock_class.create
192
+ mock_class.create
196
193
 
197
194
  mock_class.count
198
195
  => 1
@@ -202,9 +199,18 @@ ActiveHash is a simple base class that allows you to use a ruby hash as a readon
202
199
  mock_class.count
203
200
  => 0
204
201
 
202
+
203
+ ::find_by
204
+
205
+ person = PersonMock.create(first_name: 'Dustin')
206
+
207
+ PersonMock.find_by(first_name: 'Dustin') == person
208
+ => true
209
+
210
+
205
211
  ### Known Limitations
206
212
 
207
- ::mock model names and table names must follow the default ActiveRecord naming pattern.
213
+ **::mock** model names and table names must follow the default ActiveRecord naming pattern.
208
214
 
209
215
  ## Contributing
210
216
 
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.required_ruby_version = '>= 2.0.0'
22
22
 
23
23
  spec.add_runtime_dependency "activesupport", "~>4.0"
24
+ spec.add_runtime_dependency "active_hash", "~>1.3"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.5"
26
27
  spec.add_development_dependency "rake", "~>10.1"
27
28
  spec.add_development_dependency "rspec", "~>2.14"
28
29
  spec.add_development_dependency "i18n", "~>0.6"
29
- spec.add_development_dependency "active_hash", "~>1.3"
30
30
 
31
31
  if ENV['DEBUG'] == '1'
32
32
  spec.add_development_dependency "debase", "~>0.0"
@@ -1,5 +1,6 @@
1
1
  require_relative 'destroy_all'
2
2
  require_relative 'update'
3
+ require_relative 'find_by'
3
4
 
4
5
  module ActiveHash
5
6
 
@@ -13,6 +14,7 @@ module ActiveHash
13
14
 
14
15
  module ClassMethods
15
16
  include ARApi::DestroyAll
17
+ include ARApi::FindBy
16
18
  end
17
19
 
18
20
  end
@@ -0,0 +1,15 @@
1
+ module ActiveHash
2
+
3
+ module ARApi
4
+
5
+ module FindBy
6
+
7
+ def find_by(options = {})
8
+ send("find_by_#{options.keys.first}", options.values.first)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+
15
+ end
data/lib/active_mocker.rb CHANGED
@@ -16,6 +16,7 @@ require 'active_mocker/base'
16
16
  require 'active_mocker/active_record'
17
17
  require 'active_mocker/model_reader'
18
18
  require 'active_mocker/reparameterize'
19
+ require 'active_hash/ar_api'
19
20
  module ActiveMocker
20
21
 
21
22
  end
@@ -12,8 +12,8 @@ module ActiveMocker
12
12
  :model_dir,
13
13
  :schema_file,
14
14
  :model_file_reader,
15
- :schema_file_reader,
16
- :active_hash_ext
15
+ :schema_file_reader
16
+
17
17
 
18
18
  attr_reader :model_name, :klass
19
19
 
@@ -164,7 +164,7 @@ module ActiveMocker
164
164
  def const_class
165
165
  remove_const(mock_class_name) if class_exists? mock_class_name
166
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
167
+ klass.send(:include, ActiveHash::ARApi) if active_hash_as_base
168
168
  klass = Object.const_set(mock_class_name ,Class.new()) unless active_hash_as_base
169
169
  klass.extend ModelClassMethods
170
170
  klass.send(:include, ModelInstanceMethods) # is a private method for ruby 2.0.0
@@ -11,9 +11,7 @@ module ActiveMocker
11
11
  :model_methods,
12
12
  :mass_assignment,
13
13
  :schema_file_reader,
14
- :model_file_reader,
15
- :active_hash_ext
16
-
14
+ :model_file_reader
17
15
 
18
16
  def config
19
17
  @@first_load ||= reload_default
@@ -29,7 +27,6 @@ module ActiveMocker
29
27
  @model_relationships = true
30
28
  @model_methods = true
31
29
  @mass_assignment = true
32
- @active_hash_ext = false
33
30
  @log_level = Logger::WARN
34
31
  end
35
32
 
@@ -42,6 +39,13 @@ module ActiveMocker
42
39
  Logger_.level = level
43
40
  end
44
41
 
42
+ def active_hash_as_base=(bool)
43
+ if bool
44
+ require 'active_hash'
45
+ end
46
+ @active_hash_as_base = bool
47
+ end
48
+
45
49
  end
46
50
 
47
51
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -17,10 +17,7 @@ require 'active_hash/ar_api'
17
17
 
18
18
  describe ActiveMocker::Base do
19
19
 
20
- let(:mock_class){described_class.mock('Person')}
21
-
22
20
  before(:each) do
23
-
24
21
  ActiveMocker::Base.configure do |config|
25
22
  # Required Options
26
23
  config.schema_file = 'file is being inject as string'
@@ -40,6 +37,10 @@ describe ActiveMocker::Base do
40
37
 
41
38
  end
42
39
 
40
+ let(:mock_class){
41
+ described_class.mock('Person')
42
+ }
43
+
43
44
  after(:each) do
44
45
  ActiveMocker::Base.reload_default
45
46
  end
@@ -310,7 +311,6 @@ describe ActiveMocker::Base do
310
311
 
311
312
  ActiveMocker::Base.configure do |config|
312
313
  config.active_hash_as_base = true
313
- config.active_hash_ext = true
314
314
  end
315
315
 
316
316
  end
@@ -351,6 +351,11 @@ describe ActiveMocker::Base do
351
351
 
352
352
  end
353
353
 
354
+ it '::find_by' do
355
+ person = mock_class.create(first_name: 'dustin')
356
+ expect(mock_class.find_by(first_name: 'dustin')).to eq person
357
+ end
358
+
354
359
  end
355
360
 
356
361
  describe 'false' 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.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_hash
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +94,6 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.6'
83
- - !ruby/object:Gem::Dependency
84
- name: active_hash
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.3'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.3'
97
97
  description: Create mocks from active record models without loading rails or running
98
98
  a database. The Mock's methods have the same arguments as the AR model and if they
99
99
  change you get a error in your test.
@@ -112,6 +112,7 @@ files:
112
112
  - active_mocker.gemspec
113
113
  - lib/active_hash/ar_api.rb
114
114
  - lib/active_hash/destroy_all.rb
115
+ - lib/active_hash/find_by.rb
115
116
  - lib/active_hash/update.rb
116
117
  - lib/active_mocker.rb
117
118
  - lib/active_mocker/active_record.rb