active_mocker 1.2.4 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,19 +6,19 @@ class MicropostMock < ::ActiveHash::Base
6
6
  include ActiveMocker::MockInstanceMethods
7
7
  extend ActiveMocker::MockClassMethods
8
8
 
9
- def initialize(attributes = {})
10
- @attributes = HashWithIndifferentAccess.new({"id"=>nil, "content"=>nil, "user_id"=>nil, "created_at"=>nil, "updated_at"=>nil})
9
+ def initialize(attributes={}, &block)
10
+ @attributes = HashWithIndifferentAccess.new({"id"=>nil, "content"=>nil, "user_id"=>nil, "up_votes"=>nil, "created_at"=>nil, "updated_at"=>nil})
11
11
  @associations = HashWithIndifferentAccess.new({:user=>nil})
12
- super(attributes)
12
+ super(attributes, &block)
13
13
  end
14
14
 
15
15
 
16
16
  def self.column_names
17
- ["id", "content", "user_id", "created_at", "updated_at"]
17
+ ["id", "content", "user_id", "up_votes", "created_at", "updated_at"]
18
18
  end
19
19
 
20
20
  def self.attribute_names
21
- @attribute_names = [:id, :content, :user_id, :created_at, :updated_at]
21
+ @attribute_names = ["id", "content", "user_id", "up_votes", "created_at", "updated_at"]
22
22
  end
23
23
 
24
24
  ##################################
@@ -26,7 +26,7 @@ class MicropostMock < ::ActiveHash::Base
26
26
  ##################################
27
27
 
28
28
  def id
29
- @attributes['id']
29
+ @attributes['id']
30
30
  end
31
31
 
32
32
  def id=(val)
@@ -35,7 +35,7 @@ class MicropostMock < ::ActiveHash::Base
35
35
  end
36
36
 
37
37
  def content
38
- @attributes['content']
38
+ @attributes['content']
39
39
  end
40
40
 
41
41
  def content=(val)
@@ -44,7 +44,7 @@ class MicropostMock < ::ActiveHash::Base
44
44
  end
45
45
 
46
46
  def user_id
47
- @attributes['user_id']
47
+ @attributes['user_id']
48
48
  end
49
49
 
50
50
  def user_id=(val)
@@ -52,8 +52,17 @@ class MicropostMock < ::ActiveHash::Base
52
52
  @attributes['user_id'] = type.coerce(val)
53
53
  end
54
54
 
55
+ def up_votes
56
+ @attributes['up_votes']
57
+ end
58
+
59
+ def up_votes=(val)
60
+ type = (types[:up_votes] ||= Virtus::Attribute.build(Fixnum))
61
+ @attributes['up_votes'] = type.coerce(val)
62
+ end
63
+
55
64
  def created_at
56
- @attributes['created_at']
65
+ @attributes['created_at']
57
66
  end
58
67
 
59
68
  def created_at=(val)
@@ -62,7 +71,7 @@ class MicropostMock < ::ActiveHash::Base
62
71
  end
63
72
 
64
73
  def updated_at
65
- @attributes['updated_at']
74
+ @attributes['updated_at']
66
75
  end
67
76
 
68
77
  def updated_at=(val)
@@ -6,10 +6,10 @@ class RelationshipMock < ::ActiveHash::Base
6
6
  include ActiveMocker::MockInstanceMethods
7
7
  extend ActiveMocker::MockClassMethods
8
8
 
9
- def initialize(attributes = {})
9
+ def initialize(attributes={}, &block)
10
10
  @attributes = HashWithIndifferentAccess.new({"id"=>nil, "follower_id"=>nil, "followed_id"=>nil, "created_at"=>nil, "updated_at"=>nil})
11
11
  @associations = HashWithIndifferentAccess.new({:follower=>nil, :followed=>nil})
12
- super(attributes)
12
+ super(attributes, &block)
13
13
  end
14
14
 
15
15
 
@@ -18,7 +18,7 @@ class RelationshipMock < ::ActiveHash::Base
18
18
  end
19
19
 
20
20
  def self.attribute_names
21
- @attribute_names = [:id, :follower_id, :followed_id, :created_at, :updated_at]
21
+ @attribute_names = ["id", "follower_id", "followed_id", "created_at", "updated_at"]
22
22
  end
23
23
 
24
24
  ##################################
@@ -26,7 +26,7 @@ class RelationshipMock < ::ActiveHash::Base
26
26
  ##################################
27
27
 
28
28
  def id
29
- @attributes['id']
29
+ @attributes['id']
30
30
  end
31
31
 
32
32
  def id=(val)
@@ -35,7 +35,7 @@ class RelationshipMock < ::ActiveHash::Base
35
35
  end
36
36
 
37
37
  def follower_id
38
- @attributes['follower_id']
38
+ @attributes['follower_id']
39
39
  end
40
40
 
41
41
  def follower_id=(val)
@@ -44,7 +44,7 @@ class RelationshipMock < ::ActiveHash::Base
44
44
  end
45
45
 
46
46
  def followed_id
47
- @attributes['followed_id']
47
+ @attributes['followed_id']
48
48
  end
49
49
 
50
50
  def followed_id=(val)
@@ -53,7 +53,7 @@ class RelationshipMock < ::ActiveHash::Base
53
53
  end
54
54
 
55
55
  def created_at
56
- @attributes['created_at']
56
+ @attributes['created_at']
57
57
  end
58
58
 
59
59
  def created_at=(val)
@@ -62,7 +62,7 @@ class RelationshipMock < ::ActiveHash::Base
62
62
  end
63
63
 
64
64
  def updated_at
65
- @attributes['updated_at']
65
+ @attributes['updated_at']
66
66
  end
67
67
 
68
68
  def updated_at=(val)
@@ -6,10 +6,10 @@ class UserMock < ::ActiveHash::Base
6
6
  include ActiveMocker::MockInstanceMethods
7
7
  extend ActiveMocker::MockClassMethods
8
8
 
9
- def initialize(attributes = {})
9
+ def initialize(attributes={}, &block)
10
10
  @attributes = HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "email"=>"", "credits"=>nil, "created_at"=>nil, "updated_at"=>nil, "password_digest"=>nil, "remember_token"=>true, "admin"=>false})
11
11
  @associations = HashWithIndifferentAccess.new({:microposts=>nil, :relationships=>nil, :followed_users=>nil, :reverse_relationships=>nil, :followers=>nil})
12
- super(attributes)
12
+ super(attributes, &block)
13
13
  end
14
14
 
15
15
 
@@ -18,7 +18,7 @@ class UserMock < ::ActiveHash::Base
18
18
  end
19
19
 
20
20
  def self.attribute_names
21
- @attribute_names = [:id, :name, :email, :credits, :created_at, :updated_at, :password_digest, :remember_token, :admin]
21
+ @attribute_names = ["id", "name", "email", "credits", "created_at", "updated_at", "password_digest", "remember_token", "admin"]
22
22
  end
23
23
 
24
24
  ##################################
@@ -26,7 +26,7 @@ class UserMock < ::ActiveHash::Base
26
26
  ##################################
27
27
 
28
28
  def id
29
- @attributes['id']
29
+ @attributes['id']
30
30
  end
31
31
 
32
32
  def id=(val)
@@ -35,7 +35,7 @@ class UserMock < ::ActiveHash::Base
35
35
  end
36
36
 
37
37
  def name
38
- @attributes['name']
38
+ @attributes['name']
39
39
  end
40
40
 
41
41
  def name=(val)
@@ -44,7 +44,7 @@ class UserMock < ::ActiveHash::Base
44
44
  end
45
45
 
46
46
  def email
47
- @attributes['email']
47
+ @attributes['email']
48
48
  end
49
49
 
50
50
  def email=(val)
@@ -53,7 +53,7 @@ class UserMock < ::ActiveHash::Base
53
53
  end
54
54
 
55
55
  def credits
56
- @attributes['credits']
56
+ @attributes['credits']
57
57
  end
58
58
 
59
59
  def credits=(val)
@@ -62,7 +62,7 @@ class UserMock < ::ActiveHash::Base
62
62
  end
63
63
 
64
64
  def created_at
65
- @attributes['created_at']
65
+ @attributes['created_at']
66
66
  end
67
67
 
68
68
  def created_at=(val)
@@ -71,7 +71,7 @@ class UserMock < ::ActiveHash::Base
71
71
  end
72
72
 
73
73
  def updated_at
74
- @attributes['updated_at']
74
+ @attributes['updated_at']
75
75
  end
76
76
 
77
77
  def updated_at=(val)
@@ -80,7 +80,7 @@ class UserMock < ::ActiveHash::Base
80
80
  end
81
81
 
82
82
  def password_digest
83
- @attributes['password_digest']
83
+ @attributes['password_digest']
84
84
  end
85
85
 
86
86
  def password_digest=(val)
@@ -89,7 +89,7 @@ class UserMock < ::ActiveHash::Base
89
89
  end
90
90
 
91
91
  def remember_token
92
- @attributes['remember_token']
92
+ @attributes['remember_token']
93
93
  end
94
94
 
95
95
  def remember_token=(val)
@@ -98,7 +98,7 @@ class UserMock < ::ActiveHash::Base
98
98
  end
99
99
 
100
100
  def admin
101
- @attributes['admin']
101
+ @attributes['admin']
102
102
  end
103
103
 
104
104
  def admin=(val)
@@ -115,43 +115,43 @@ class UserMock < ::ActiveHash::Base
115
115
  end
116
116
 
117
117
  def microposts
118
- associations['microposts'] ||= ActiveMocker::CollectionAssociation.new
118
+ associations['microposts'] ||= ActiveMocker::Collection::Association.new
119
119
  end
120
120
 
121
121
  def microposts=(val)
122
- associations['microposts'] = ActiveMocker::CollectionAssociation.new(val)
122
+ associations['microposts'] = ActiveMocker::Collection::Association.new(val)
123
123
  end
124
124
 
125
125
  def relationships
126
- associations['relationships'] ||= ActiveMocker::CollectionAssociation.new
126
+ associations['relationships'] ||= ActiveMocker::Collection::Association.new
127
127
  end
128
128
 
129
129
  def relationships=(val)
130
- associations['relationships'] = ActiveMocker::CollectionAssociation.new(val)
130
+ associations['relationships'] = ActiveMocker::Collection::Association.new(val)
131
131
  end
132
132
 
133
133
  def followed_users
134
- associations['followed_users'] ||= ActiveMocker::CollectionAssociation.new
134
+ associations['followed_users'] ||= ActiveMocker::Collection::Association.new
135
135
  end
136
136
 
137
137
  def followed_users=(val)
138
- associations['followed_users'] = ActiveMocker::CollectionAssociation.new(val)
138
+ associations['followed_users'] = ActiveMocker::Collection::Association.new(val)
139
139
  end
140
140
 
141
141
  def reverse_relationships
142
- associations['reverse_relationships'] ||= ActiveMocker::CollectionAssociation.new
142
+ associations['reverse_relationships'] ||= ActiveMocker::Collection::Association.new
143
143
  end
144
144
 
145
145
  def reverse_relationships=(val)
146
- associations['reverse_relationships'] = ActiveMocker::CollectionAssociation.new(val)
146
+ associations['reverse_relationships'] = ActiveMocker::Collection::Association.new(val)
147
147
  end
148
148
 
149
149
  def followers
150
- associations['followers'] ||= ActiveMocker::CollectionAssociation.new
150
+ associations['followers'] ||= ActiveMocker::Collection::Association.new
151
151
  end
152
152
 
153
153
  def followers=(val)
154
- associations['followers'] = ActiveMocker::CollectionAssociation.new(val)
154
+ associations['followers'] = ActiveMocker::Collection::Association.new(val)
155
155
  end
156
156
 
157
157
  ##################################
@@ -42,7 +42,6 @@ describe UserMock do
42
42
  end
43
43
 
44
44
  it 'add has_many relationship' do
45
- expect(UserMock.new.microposts.class).to eq ActiveMocker::CollectionAssociation
46
45
  expect(UserMock.new.microposts.count).to eq 0
47
46
  mock_inst = UserMock.new
48
47
  mock_inst.microposts << 1
@@ -1,21 +1,20 @@
1
1
  require 'rspec'
2
2
  $:.unshift File.expand_path('../../', __FILE__)
3
3
  require 'active_support/all'
4
- require 'active_mocker/collection_association'
4
+ require 'active_mocker/collection/base'
5
+ require 'active_mocker/collection/queries'
6
+ require 'active_mocker/collection/relation'
5
7
  require 'ostruct'
6
8
 
7
- describe ActiveMocker::CollectionAssociation do
9
+ describe ActiveMocker::Collection::Relation do
8
10
 
9
11
  subject{described_class.new}
10
12
 
11
13
  describe '#sum' do
12
14
 
13
-
14
15
  it 'sum values by attribute name' do
15
-
16
16
  subject << [OpenStruct.new(value: 1), OpenStruct.new(value: 1)]
17
17
  expect(subject.sum(:value)).to eq 2
18
-
19
18
  end
20
19
 
21
20
  end
@@ -1,51 +1,40 @@
1
1
  require 'rspec'
2
2
  $:.unshift File.expand_path('../../', __FILE__)
3
- require 'singleton'
4
- require 'logger'
5
- require 'forwardable'
6
- require 'active_mocker/logger'
7
- require 'string_reader'
8
- require 'active_mocker/public_methods'
9
- require 'file_reader'
10
- require 'active_mocker/collection_association'
11
- require 'active_mocker/table'
12
- require 'active_mocker/config'
13
- require 'active_mocker/reparameterize'
14
- require 'active_mocker/field'
15
- require 'active_mocker/active_record'
16
- require 'active_mocker/model_reader'
17
- require 'active_mocker/schema_reader'
18
- require 'active_mocker/active_record/schema'
19
- require 'active_support/all'
20
- require 'active_hash/ar_api'
21
- require 'active_mocker/generate'
22
- require 'erb'
23
- require 'virtus'
3
+ require 'active_mocker'
24
4
  require_relative '../../unit_logger'
25
5
 
26
6
  describe ActiveMocker::Generate do
27
7
 
8
+ let(:app_root){ File.expand_path('../../../../', __FILE__)}
9
+ let(:mock_dir){ File.join(app_root, 'sample_app_rails_4/spec/mocks')}
10
+
28
11
  before(:each) do
29
- app_root = File.expand_path('../../../../', __FILE__)
30
12
  ActiveMocker.config do |config|
31
- # Required Options
32
13
  config.schema_file = File.join(app_root, 'sample_app_rails_4/db/schema.rb')
33
14
  config.model_dir = File.join(app_root, 'sample_app_rails_4/app/models')
34
- config.mock_dir = File.join(app_root, 'sample_app_rails_4/spec/mocks')
35
- config.logger = UnitLogger
36
-
15
+ config.mock_dir = mock_dir
16
+ config.logger = UnitLogger
37
17
  end
38
18
 
19
+ FileUtils.rm_rf mock_dir
20
+
39
21
  end
40
22
 
41
- describe 'new' do
23
+ subject{described_class.new}
42
24
 
43
- it 'generates all mocks' do
25
+ describe 'new' do
44
26
 
45
- described_class.new
27
+ before(:each) do
28
+ subject
29
+ end
46
30
 
31
+ it 'generates all mocks files' do
32
+ expect(File.exist? File.join(mock_dir, 'user_mock.rb') ).to eq true
33
+ expect(File.exist? File.join(mock_dir, 'micropost_mock.rb') ).to eq true
34
+ expect(File.exist? File.join(mock_dir, 'relationship_mock.rb')).to eq true
47
35
  end
48
36
 
49
37
  end
50
38
 
51
- end
39
+ end
40
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -152,10 +152,10 @@ dependencies:
152
152
  version: '1.3'
153
153
  description: Creates mocks from Active Record models. Allows your test suite to run
154
154
  very fast by not loading Rails or hooking to a database. It parse the schema definition
155
- and the definded methods on a model then saves a ruby file that can be included
156
- with a test. Mocks are regenerated when the schema is modified so your mocks will
157
- not go stale. This prevents the case where your units tests pass but production
158
- code is failing.
155
+ and the defined methods on a model then saves a ruby file that can be included with
156
+ a test. Mocks are regenerated when the schema is modified so your mocks will not
157
+ go stale. This prevents the case where your units tests pass but production code
158
+ is failing.
159
159
  email:
160
160
  - dustin@zive.me
161
161
  executables: []
@@ -171,9 +171,7 @@ files:
171
171
  - Rakefile
172
172
  - active_mocker.gemspec
173
173
  - lib/active_hash/ar_api.rb
174
- - lib/active_hash/find_by.rb
175
174
  - lib/active_hash/init.rb
176
- - lib/active_hash/update.rb
177
175
  - lib/active_mocker.rb
178
176
  - lib/active_mocker/active_record.rb
179
177
  - lib/active_mocker/active_record/const_missing.rb
@@ -183,7 +181,10 @@ files:
183
181
  - lib/active_mocker/active_record/unknown_class_method.rb
184
182
  - lib/active_mocker/active_record/unknown_module.rb
185
183
  - lib/active_mocker/class_exists.rb
186
- - lib/active_mocker/collection_association.rb
184
+ - lib/active_mocker/collection/association.rb
185
+ - lib/active_mocker/collection/base.rb
186
+ - lib/active_mocker/collection/queries.rb
187
+ - lib/active_mocker/collection/relation.rb
187
188
  - lib/active_mocker/config.rb
188
189
  - lib/active_mocker/const_sets.rb
189
190
  - lib/active_mocker/field.rb
@@ -353,7 +354,7 @@ files:
353
354
  - sample_app_rails_4/spec/user_mock_spec.rb
354
355
  - sample_app_rails_4/vendor/assets/javascripts/.keep
355
356
  - sample_app_rails_4/vendor/assets/stylesheets/.keep
356
- - spec/lib/active_mocker/collection_association_spec.rb
357
+ - spec/lib/active_mocker/collection.rb
357
358
  - spec/lib/active_mocker/generate_spec.rb
358
359
  - spec/lib/active_mocker/model_reader_spec.rb
359
360
  - spec/lib/active_mocker/schema_reader_spec.rb
@@ -388,7 +389,7 @@ specification_version: 4
388
389
  summary: Creates mocks from Active Record models. Allows your test suite to run very
389
390
  fast by not loading Rails or hooking to a database.
390
391
  test_files:
391
- - spec/lib/active_mocker/collection_association_spec.rb
392
+ - spec/lib/active_mocker/collection.rb
392
393
  - spec/lib/active_mocker/generate_spec.rb
393
394
  - spec/lib/active_mocker/model_reader_spec.rb
394
395
  - spec/lib/active_mocker/schema_reader_spec.rb