active_mocker 1.2 → 1.2.3
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/.gitignore +1 -0
- data/README.md +61 -25
- data/Rakefile +1 -1
- data/active_mocker.gemspec +3 -3
- data/lib/active_hash/init.rb +13 -22
- data/lib/active_mocker.rb +1 -0
- data/lib/active_mocker/active_record/unknown_class_method.rb +1 -1
- data/lib/active_mocker/active_record/unknown_module.rb +3 -3
- data/lib/active_mocker/collection_association.rb +19 -20
- data/lib/active_mocker/config.rb +7 -4
- data/lib/active_mocker/field.rb +4 -4
- data/lib/active_mocker/generate.rb +75 -18
- data/lib/active_mocker/logger.rb +10 -1
- data/lib/active_mocker/mock_class_methods.rb +12 -2
- data/lib/active_mocker/mock_instance_methods.rb +3 -2
- data/lib/active_mocker/mock_requires.rb +2 -1
- data/lib/active_mocker/mock_template.erb +25 -22
- data/lib/active_mocker/public_methods.rb +6 -2
- data/lib/active_mocker/version.rb +1 -1
- data/sample_app_rails_4/app/models/micropost.rb +0 -2
- data/sample_app_rails_4/bin/rspec +16 -0
- data/sample_app_rails_4/config/application.rb +0 -3
- data/sample_app_rails_4/config/database.yml +5 -6
- data/sample_app_rails_4/config/environments/development.rb +0 -2
- data/sample_app_rails_4/config/environments/test.rb +0 -1
- data/sample_app_rails_4/config/initializers/active_mocker.rb +7 -5
- data/sample_app_rails_4/db/migrate/20130311191400_create_users.rb +1 -1
- data/sample_app_rails_4/db/migrate/20130315015932_add_admin_to_users.rb +1 -1
- data/sample_app_rails_4/db/schema.rb +4 -3
- data/sample_app_rails_4/lib/tasks/{mocks.rake → active_mocker.rake} +5 -5
- data/sample_app_rails_4/lib/unit_logger.rb +22 -0
- data/sample_app_rails_4/spec/compare_mocker_and_record_spec.rb +110 -4
- data/sample_app_rails_4/spec/mocks/micropost_mock.rb +31 -27
- data/sample_app_rails_4/spec/mocks/relationship_mock.rb +29 -24
- data/sample_app_rails_4/spec/mocks/user_mock.rb +69 -58
- data/sample_app_rails_4/spec/spec_helper.rb +6 -7
- data/sample_app_rails_4/spec/user_mock_spec.rb +14 -7
- data/spec/lib/active_mocker/collection_association_spec.rb +17 -3
- data/spec/lib/active_mocker/generate_spec.rb +8 -6
- data/spec/lib/active_mocker/model_reader_spec.rb +5 -0
- data/spec/lib/active_mocker/schema_reader_spec.rb +1 -1
- data/spec/lib/readme_spec.rb +199 -205
- data/spec/unit_logger.rb +24 -0
- metadata +22 -32
- data/mocks/micropost_mock.rb +0 -108
- data/mocks/relationship_mock.rb +0 -109
- data/mocks/user_mock.rb +0 -199
- data/plan_mock.rb +0 -2323
- data/sample_app_rails_4/config/cucumber.yml +0 -8
- data/sample_app_rails_4/db/development.sqlite3 +0 -0
- data/sample_app_rails_4/db/test.sqlite3 +0 -0
- data/spec/lib/active_mocker/performance/base_spec.rb +0 -454
- data/spec/lib/active_mocker/performance/large_schema.rb +0 -3576
- data/spec/lib/active_mocker/performance/migration/20140327205359_migration.rb +0 -0
- data/spec/lib/active_mocker/performance/schema_reader_spec.rb +0 -96
- data/spec/lib/compare_mocker_and_record_spec.rb +0 -133
@@ -6,6 +6,13 @@ 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})
|
11
|
+
@associations = HashWithIndifferentAccess.new({:user=>nil})
|
12
|
+
super(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
9
16
|
def self.column_names
|
10
17
|
["id", "content", "user_id", "created_at", "updated_at"]
|
11
18
|
end
|
@@ -19,43 +26,48 @@ class MicropostMock < ::ActiveHash::Base
|
|
19
26
|
##################################
|
20
27
|
|
21
28
|
def id
|
22
|
-
|
23
|
-
|
29
|
+
@attributes['id']
|
30
|
+
end
|
24
31
|
|
25
32
|
def id=(val)
|
26
|
-
|
33
|
+
type = (types[:id] ||= Virtus::Attribute.build(Fixnum))
|
34
|
+
@attributes['id'] = type.coerce(val)
|
27
35
|
end
|
28
36
|
|
29
37
|
def content
|
30
|
-
|
31
|
-
|
38
|
+
@attributes['content']
|
39
|
+
end
|
32
40
|
|
33
41
|
def content=(val)
|
34
|
-
|
42
|
+
type = (types[:content] ||= Virtus::Attribute.build(String))
|
43
|
+
@attributes['content'] = type.coerce(val)
|
35
44
|
end
|
36
45
|
|
37
46
|
def user_id
|
38
|
-
|
39
|
-
|
47
|
+
@attributes['user_id']
|
48
|
+
end
|
40
49
|
|
41
50
|
def user_id=(val)
|
42
|
-
|
51
|
+
type = (types[:user_id] ||= Virtus::Attribute.build(Fixnum))
|
52
|
+
@attributes['user_id'] = type.coerce(val)
|
43
53
|
end
|
44
54
|
|
45
55
|
def created_at
|
46
|
-
|
47
|
-
|
56
|
+
@attributes['created_at']
|
57
|
+
end
|
48
58
|
|
49
59
|
def created_at=(val)
|
50
|
-
|
60
|
+
type = (types[:created_at] ||= Virtus::Attribute.build(DateTime))
|
61
|
+
@attributes['created_at'] = type.coerce(val)
|
51
62
|
end
|
52
63
|
|
53
64
|
def updated_at
|
54
|
-
|
55
|
-
|
65
|
+
@attributes['updated_at']
|
66
|
+
end
|
56
67
|
|
57
68
|
def updated_at=(val)
|
58
|
-
|
69
|
+
type = (types[:updated_at] ||= Virtus::Attribute.build(DateTime))
|
70
|
+
@attributes['updated_at'] = type.coerce(val)
|
59
71
|
end
|
60
72
|
|
61
73
|
##################################
|
@@ -74,22 +86,16 @@ class MicropostMock < ::ActiveHash::Base
|
|
74
86
|
associations['user'] = val
|
75
87
|
end
|
76
88
|
|
77
|
-
|
78
89
|
##################################
|
79
90
|
# Model Methods getter/setters #
|
80
91
|
##################################
|
81
92
|
|
82
93
|
def self.model_instance_methods
|
83
|
-
|
84
|
-
@model_instance_methods = {}
|
85
|
-
@model_instance_methods
|
94
|
+
@model_instance_methods ||= {}
|
86
95
|
end
|
87
96
|
|
88
97
|
def self.model_class_methods
|
89
|
-
|
90
|
-
@model_class_methods = {}
|
91
|
-
@model_class_methods[:from_users_followed_by] = :not_implemented
|
92
|
-
@model_class_methods
|
98
|
+
@model_class_methods ||= {"from_users_followed_by"=>:not_implemented}
|
93
99
|
end
|
94
100
|
|
95
101
|
def self.clear_mock
|
@@ -97,12 +103,10 @@ class MicropostMock < ::ActiveHash::Base
|
|
97
103
|
delete_all
|
98
104
|
end
|
99
105
|
|
100
|
-
|
101
106
|
def self.from_users_followed_by(user)
|
102
|
-
block = model_class_methods[
|
103
|
-
is_implemented(block,
|
107
|
+
block = model_class_methods['from_users_followed_by']
|
108
|
+
is_implemented(block, '::from_users_followed_by')
|
104
109
|
instance_exec(*[user], &block)
|
105
110
|
end
|
106
111
|
|
107
|
-
|
108
112
|
end
|
@@ -6,6 +6,13 @@ class RelationshipMock < ::ActiveHash::Base
|
|
6
6
|
include ActiveMocker::MockInstanceMethods
|
7
7
|
extend ActiveMocker::MockClassMethods
|
8
8
|
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@attributes = HashWithIndifferentAccess.new({"id"=>nil, "follower_id"=>nil, "followed_id"=>nil, "created_at"=>nil, "updated_at"=>nil})
|
11
|
+
@associations = HashWithIndifferentAccess.new({:follower=>nil, :followed=>nil})
|
12
|
+
super(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
9
16
|
def self.column_names
|
10
17
|
["id", "follower_id", "followed_id", "created_at", "updated_at"]
|
11
18
|
end
|
@@ -19,43 +26,48 @@ class RelationshipMock < ::ActiveHash::Base
|
|
19
26
|
##################################
|
20
27
|
|
21
28
|
def id
|
22
|
-
|
23
|
-
|
29
|
+
@attributes['id']
|
30
|
+
end
|
24
31
|
|
25
32
|
def id=(val)
|
26
|
-
|
33
|
+
type = (types[:id] ||= Virtus::Attribute.build(Fixnum))
|
34
|
+
@attributes['id'] = type.coerce(val)
|
27
35
|
end
|
28
36
|
|
29
37
|
def follower_id
|
30
|
-
|
31
|
-
|
38
|
+
@attributes['follower_id']
|
39
|
+
end
|
32
40
|
|
33
41
|
def follower_id=(val)
|
34
|
-
|
42
|
+
type = (types[:follower_id] ||= Virtus::Attribute.build(Fixnum))
|
43
|
+
@attributes['follower_id'] = type.coerce(val)
|
35
44
|
end
|
36
45
|
|
37
46
|
def followed_id
|
38
|
-
|
39
|
-
|
47
|
+
@attributes['followed_id']
|
48
|
+
end
|
40
49
|
|
41
50
|
def followed_id=(val)
|
42
|
-
|
51
|
+
type = (types[:followed_id] ||= Virtus::Attribute.build(Fixnum))
|
52
|
+
@attributes['followed_id'] = type.coerce(val)
|
43
53
|
end
|
44
54
|
|
45
55
|
def created_at
|
46
|
-
|
47
|
-
|
56
|
+
@attributes['created_at']
|
57
|
+
end
|
48
58
|
|
49
59
|
def created_at=(val)
|
50
|
-
|
60
|
+
type = (types[:created_at] ||= Virtus::Attribute.build(DateTime))
|
61
|
+
@attributes['created_at'] = type.coerce(val)
|
51
62
|
end
|
52
63
|
|
53
64
|
def updated_at
|
54
|
-
|
55
|
-
|
65
|
+
@attributes['updated_at']
|
66
|
+
end
|
56
67
|
|
57
68
|
def updated_at=(val)
|
58
|
-
|
69
|
+
type = (types[:updated_at] ||= Virtus::Attribute.build(DateTime))
|
70
|
+
@attributes['updated_at'] = type.coerce(val)
|
59
71
|
end
|
60
72
|
|
61
73
|
##################################
|
@@ -82,21 +94,16 @@ class RelationshipMock < ::ActiveHash::Base
|
|
82
94
|
associations['followed'] = val
|
83
95
|
end
|
84
96
|
|
85
|
-
|
86
97
|
##################################
|
87
98
|
# Model Methods getter/setters #
|
88
99
|
##################################
|
89
100
|
|
90
101
|
def self.model_instance_methods
|
91
|
-
|
92
|
-
@model_instance_methods = {}
|
93
|
-
@model_instance_methods
|
102
|
+
@model_instance_methods ||= {}
|
94
103
|
end
|
95
104
|
|
96
105
|
def self.model_class_methods
|
97
|
-
|
98
|
-
@model_class_methods = {}
|
99
|
-
@model_class_methods
|
106
|
+
@model_class_methods ||= {}
|
100
107
|
end
|
101
108
|
|
102
109
|
def self.clear_mock
|
@@ -104,6 +111,4 @@ class RelationshipMock < ::ActiveHash::Base
|
|
104
111
|
delete_all
|
105
112
|
end
|
106
113
|
|
107
|
-
|
108
|
-
|
109
114
|
end
|
@@ -6,12 +6,19 @@ class UserMock < ::ActiveHash::Base
|
|
6
6
|
include ActiveMocker::MockInstanceMethods
|
7
7
|
extend ActiveMocker::MockClassMethods
|
8
8
|
|
9
|
+
def initialize(attributes = {})
|
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
|
+
@associations = HashWithIndifferentAccess.new({:microposts=>nil, :relationships=>nil, :followed_users=>nil, :reverse_relationships=>nil, :followers=>nil})
|
12
|
+
super(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
9
16
|
def self.column_names
|
10
|
-
["id", "name", "email", "created_at", "updated_at", "password_digest", "remember_token", "admin"]
|
17
|
+
["id", "name", "email", "credits", "created_at", "updated_at", "password_digest", "remember_token", "admin"]
|
11
18
|
end
|
12
19
|
|
13
20
|
def self.attribute_names
|
14
|
-
@attribute_names = [:id, :name, :email, :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]
|
15
22
|
end
|
16
23
|
|
17
24
|
##################################
|
@@ -19,67 +26,84 @@ class UserMock < ::ActiveHash::Base
|
|
19
26
|
##################################
|
20
27
|
|
21
28
|
def id
|
22
|
-
|
23
|
-
|
29
|
+
@attributes['id']
|
30
|
+
end
|
24
31
|
|
25
32
|
def id=(val)
|
26
|
-
|
33
|
+
type = (types[:id] ||= Virtus::Attribute.build(Fixnum))
|
34
|
+
@attributes['id'] = type.coerce(val)
|
27
35
|
end
|
28
36
|
|
29
37
|
def name
|
30
|
-
|
31
|
-
|
38
|
+
@attributes['name']
|
39
|
+
end
|
32
40
|
|
33
41
|
def name=(val)
|
34
|
-
|
42
|
+
type = (types[:name] ||= Virtus::Attribute.build(String))
|
43
|
+
@attributes['name'] = type.coerce(val)
|
35
44
|
end
|
36
45
|
|
37
46
|
def email
|
38
|
-
|
39
|
-
|
47
|
+
@attributes['email']
|
48
|
+
end
|
40
49
|
|
41
50
|
def email=(val)
|
42
|
-
|
51
|
+
type = (types[:email] ||= Virtus::Attribute.build(String))
|
52
|
+
@attributes['email'] = type.coerce(val)
|
43
53
|
end
|
44
54
|
|
45
|
-
def
|
46
|
-
|
55
|
+
def credits
|
56
|
+
@attributes['credits']
|
57
|
+
end
|
58
|
+
|
59
|
+
def credits=(val)
|
60
|
+
type = (types[:credits] ||= Virtus::Attribute.build(BigDecimal))
|
61
|
+
@attributes['credits'] = type.coerce(val)
|
47
62
|
end
|
48
63
|
|
64
|
+
def created_at
|
65
|
+
@attributes['created_at']
|
66
|
+
end
|
67
|
+
|
49
68
|
def created_at=(val)
|
50
|
-
|
69
|
+
type = (types[:created_at] ||= Virtus::Attribute.build(DateTime))
|
70
|
+
@attributes['created_at'] = type.coerce(val)
|
51
71
|
end
|
52
72
|
|
53
73
|
def updated_at
|
54
|
-
|
55
|
-
|
74
|
+
@attributes['updated_at']
|
75
|
+
end
|
56
76
|
|
57
77
|
def updated_at=(val)
|
58
|
-
|
78
|
+
type = (types[:updated_at] ||= Virtus::Attribute.build(DateTime))
|
79
|
+
@attributes['updated_at'] = type.coerce(val)
|
59
80
|
end
|
60
81
|
|
61
82
|
def password_digest
|
62
|
-
|
63
|
-
|
83
|
+
@attributes['password_digest']
|
84
|
+
end
|
64
85
|
|
65
86
|
def password_digest=(val)
|
66
|
-
|
87
|
+
type = (types[:password_digest] ||= Virtus::Attribute.build(String))
|
88
|
+
@attributes['password_digest'] = type.coerce(val)
|
67
89
|
end
|
68
90
|
|
69
91
|
def remember_token
|
70
|
-
|
71
|
-
|
92
|
+
@attributes['remember_token']
|
93
|
+
end
|
72
94
|
|
73
95
|
def remember_token=(val)
|
74
|
-
|
96
|
+
type = (types[:remember_token] ||= Virtus::Attribute.build(Virtus::Attribute::Boolean))
|
97
|
+
@attributes['remember_token'] = type.coerce(val)
|
75
98
|
end
|
76
99
|
|
77
100
|
def admin
|
78
|
-
|
79
|
-
|
101
|
+
@attributes['admin']
|
102
|
+
end
|
80
103
|
|
81
104
|
def admin=(val)
|
82
|
-
|
105
|
+
type = (types[:admin] ||= Virtus::Attribute.build(Virtus::Attribute::Boolean))
|
106
|
+
@attributes['admin'] = type.coerce(val)
|
83
107
|
end
|
84
108
|
|
85
109
|
##################################
|
@@ -90,9 +114,8 @@ class UserMock < ::ActiveHash::Base
|
|
90
114
|
@association_names = [:microposts, :relationships, :followed_users, :reverse_relationships, :followers]
|
91
115
|
end
|
92
116
|
|
93
|
-
|
94
117
|
def microposts
|
95
|
-
associations['microposts']
|
118
|
+
associations['microposts'] ||= ActiveMocker::CollectionAssociation.new
|
96
119
|
end
|
97
120
|
|
98
121
|
def microposts=(val)
|
@@ -100,7 +123,7 @@ class UserMock < ::ActiveHash::Base
|
|
100
123
|
end
|
101
124
|
|
102
125
|
def relationships
|
103
|
-
associations['relationships']
|
126
|
+
associations['relationships'] ||= ActiveMocker::CollectionAssociation.new
|
104
127
|
end
|
105
128
|
|
106
129
|
def relationships=(val)
|
@@ -108,7 +131,7 @@ class UserMock < ::ActiveHash::Base
|
|
108
131
|
end
|
109
132
|
|
110
133
|
def followed_users
|
111
|
-
associations['followed_users']
|
134
|
+
associations['followed_users'] ||= ActiveMocker::CollectionAssociation.new
|
112
135
|
end
|
113
136
|
|
114
137
|
def followed_users=(val)
|
@@ -116,7 +139,7 @@ class UserMock < ::ActiveHash::Base
|
|
116
139
|
end
|
117
140
|
|
118
141
|
def reverse_relationships
|
119
|
-
associations['reverse_relationships']
|
142
|
+
associations['reverse_relationships'] ||= ActiveMocker::CollectionAssociation.new
|
120
143
|
end
|
121
144
|
|
122
145
|
def reverse_relationships=(val)
|
@@ -124,7 +147,7 @@ class UserMock < ::ActiveHash::Base
|
|
124
147
|
end
|
125
148
|
|
126
149
|
def followers
|
127
|
-
associations['followers']
|
150
|
+
associations['followers'] ||= ActiveMocker::CollectionAssociation.new
|
128
151
|
end
|
129
152
|
|
130
153
|
def followers=(val)
|
@@ -136,21 +159,11 @@ class UserMock < ::ActiveHash::Base
|
|
136
159
|
##################################
|
137
160
|
|
138
161
|
def self.model_instance_methods
|
139
|
-
|
140
|
-
@model_instance_methods = {}
|
141
|
-
@model_instance_methods[:feed] = :not_implemented
|
142
|
-
@model_instance_methods[:following?] = :not_implemented
|
143
|
-
@model_instance_methods[:follow!] = :not_implemented
|
144
|
-
@model_instance_methods[:unfollow!] = :not_implemented
|
145
|
-
@model_instance_methods
|
162
|
+
@model_instance_methods ||= {"feed"=>:not_implemented, "following?"=>:not_implemented, "follow!"=>:not_implemented, "unfollow!"=>:not_implemented}
|
146
163
|
end
|
147
164
|
|
148
165
|
def self.model_class_methods
|
149
|
-
|
150
|
-
@model_class_methods = {}
|
151
|
-
@model_class_methods[:new_remember_token] = :not_implemented
|
152
|
-
@model_class_methods[:digest] = :not_implemented
|
153
|
-
@model_class_methods
|
166
|
+
@model_class_methods ||= {"new_remember_token"=>:not_implemented, "digest"=>:not_implemented}
|
154
167
|
end
|
155
168
|
|
156
169
|
def self.clear_mock
|
@@ -159,41 +172,39 @@ class UserMock < ::ActiveHash::Base
|
|
159
172
|
end
|
160
173
|
|
161
174
|
def feed()
|
162
|
-
block = model_instance_methods[
|
163
|
-
self.class.is_implemented(block,
|
175
|
+
block = model_instance_methods['feed']
|
176
|
+
self.class.is_implemented(block, '#feed')
|
164
177
|
instance_exec(*[], &block)
|
165
178
|
end
|
166
179
|
|
167
180
|
def following?(other_user)
|
168
|
-
block = model_instance_methods[
|
169
|
-
self.class.is_implemented(block,
|
181
|
+
block = model_instance_methods['following?']
|
182
|
+
self.class.is_implemented(block, '#following?')
|
170
183
|
instance_exec(*[other_user], &block)
|
171
184
|
end
|
172
185
|
|
173
186
|
def follow!(other_user)
|
174
|
-
block = model_instance_methods[
|
175
|
-
self.class.is_implemented(block,
|
187
|
+
block = model_instance_methods['follow!']
|
188
|
+
self.class.is_implemented(block, '#follow!')
|
176
189
|
instance_exec(*[other_user], &block)
|
177
190
|
end
|
178
191
|
|
179
192
|
def unfollow!(other_user)
|
180
|
-
block = model_instance_methods[
|
181
|
-
self.class.is_implemented(block,
|
193
|
+
block = model_instance_methods['unfollow!']
|
194
|
+
self.class.is_implemented(block, '#unfollow!')
|
182
195
|
instance_exec(*[other_user], &block)
|
183
196
|
end
|
184
197
|
|
185
|
-
|
186
198
|
def self.new_remember_token()
|
187
|
-
block = model_class_methods[
|
188
|
-
is_implemented(block,
|
199
|
+
block = model_class_methods['new_remember_token']
|
200
|
+
is_implemented(block, '::new_remember_token')
|
189
201
|
instance_exec(*[], &block)
|
190
202
|
end
|
191
203
|
|
192
204
|
def self.digest(token)
|
193
|
-
block = model_class_methods[
|
194
|
-
is_implemented(block,
|
205
|
+
block = model_class_methods['digest']
|
206
|
+
is_implemented(block, '::digest')
|
195
207
|
instance_exec(*[token], &block)
|
196
208
|
end
|
197
209
|
|
198
|
-
|
199
210
|
end
|