active_mocker 1.4.2 → 1.5
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/CHANGELOG.md +20 -0
- data/README.md +35 -29
- data/lib/active_mocker.rb +3 -1
- data/lib/active_mocker/active_record.rb +27 -5
- data/lib/active_mocker/active_record/scope.rb +5 -5
- data/lib/active_mocker/active_record/unknown_module.rb +4 -4
- data/lib/active_mocker/generate.rb +36 -15
- data/lib/active_mocker/loaded_mocks.rb +60 -54
- data/lib/active_mocker/mock.rb +24 -0
- data/lib/active_mocker/mock/association.rb +6 -0
- data/lib/{active_mock → active_mocker/mock}/base.rb +43 -89
- data/lib/{active_mock → active_mocker/mock}/collection.rb +14 -7
- data/lib/{active_mock → active_mocker/mock}/do_nothing_active_record_methods.rb +7 -1
- data/lib/active_mocker/mock/exceptions.rb +25 -0
- data/lib/active_mocker/mock/has_and_belongs_to_many.rb +6 -0
- data/lib/active_mocker/mock/has_many.rb +60 -0
- data/lib/active_mocker/mock/hash_process.rb +19 -0
- data/lib/active_mocker/mock/mock_abilities.rb +98 -0
- data/lib/{active_mock → active_mocker/mock}/next_id.rb +7 -2
- data/lib/{active_mock → active_mocker/mock}/object_inspect.rb +3 -1
- data/lib/{active_mock → active_mocker/mock}/queries.rb +32 -29
- data/lib/active_mocker/mock/records.rb +62 -0
- data/lib/{active_mock → active_mocker/mock}/relation.rb +4 -3
- data/lib/active_mocker/mock/template_methods.rb +39 -0
- data/lib/active_mocker/mock_template.erb +45 -31
- data/lib/active_mocker/model_reader.rb +29 -0
- data/lib/active_mocker/model_schema.rb +23 -16
- data/lib/active_mocker/model_schema/generate.rb +19 -8
- data/lib/active_mocker/railtie.rb +17 -0
- data/lib/active_mocker/reparameterize.rb +2 -4
- data/lib/active_mocker/rspec_helper.rb +18 -0
- data/lib/active_mocker/task.rake +15 -0
- data/lib/active_mocker/version.rb +1 -1
- metadata +80 -206
- data/.gitignore +0 -19
- data/.hound.yml +0 -0
- data/.travis.yml +0 -5
- data/Gemfile +0 -4
- data/Rakefile +0 -26
- data/active_mocker.gemspec +0 -40
- data/lib/active_mock/association.rb +0 -7
- data/lib/active_mock/creators.rb +0 -25
- data/lib/active_mock/has_and_belongs_to_many.rb +0 -7
- data/lib/active_mock/has_many.rb +0 -54
- data/lib/active_mock/records.rb +0 -83
- data/lib/active_mocker/active_mock.rb +0 -26
- data/lib/active_mocker/active_record/const_missing.rb +0 -5
- data/lib/active_mocker/class_exists.rb +0 -12
- data/lib/active_mocker/const_sets.rb +0 -24
- data/lib/active_mocker/mock_task.rb +0 -12
- data/sample_app_rails_4/.idea/.generators +0 -8
- data/sample_app_rails_4/.idea/.name +0 -1
- data/sample_app_rails_4/.idea/.rakeTasks +0 -7
- data/sample_app_rails_4/.idea/dataSources.ids +0 -141
- data/sample_app_rails_4/.idea/dataSources.xml +0 -36
- data/sample_app_rails_4/.idea/dictionaries/zeisler.xml +0 -3
- data/sample_app_rails_4/.idea/encodings.xml +0 -5
- data/sample_app_rails_4/.idea/inspectionProfiles/Project_Default.xml +0 -20
- data/sample_app_rails_4/.idea/inspectionProfiles/profiles_settings.xml +0 -7
- data/sample_app_rails_4/.idea/misc.xml +0 -5
- data/sample_app_rails_4/.idea/modules.xml +0 -10
- data/sample_app_rails_4/.idea/runConfigurations/Development__sample_app_rails_4.xml +0 -28
- data/sample_app_rails_4/.idea/runConfigurations/Production__sample_app_rails_4.xml +0 -28
- data/sample_app_rails_4/.idea/runConfigurations/spec__sample_app_rails_4.xml +0 -26
- data/sample_app_rails_4/.idea/runConfigurations/test__sample_app_rails_4.xml +0 -28
- data/sample_app_rails_4/.idea/sample_app_rails_4.iml +0 -262
- data/sample_app_rails_4/.idea/scopes/scope_settings.xml +0 -5
- data/sample_app_rails_4/.idea/vcs.xml +0 -7
- data/sample_app_rails_4/.idea/workspace.xml +0 -619
- data/sample_app_rails_4/.rspec +0 -1
- data/sample_app_rails_4/.secret +0 -1
- data/sample_app_rails_4/Gemfile +0 -13
- data/sample_app_rails_4/Guardfile +0 -53
- data/sample_app_rails_4/LICENSE +0 -21
- data/sample_app_rails_4/README.md +0 -25
- data/sample_app_rails_4/README.nitrous.md +0 -20
- data/sample_app_rails_4/Rakefile +0 -6
- data/sample_app_rails_4/app/assets/images/rails.png +0 -0
- data/sample_app_rails_4/app/assets/javascripts/application.js +0 -17
- data/sample_app_rails_4/app/assets/javascripts/sessions.js.coffee +0 -3
- data/sample_app_rails_4/app/assets/javascripts/static_pages.js.coffee +0 -3
- data/sample_app_rails_4/app/assets/javascripts/users.js.coffee +0 -3
- data/sample_app_rails_4/app/assets/stylesheets/application.css +0 -13
- data/sample_app_rails_4/app/assets/stylesheets/custom.css.scss +0 -246
- data/sample_app_rails_4/app/assets/stylesheets/sessions.css.scss +0 -3
- data/sample_app_rails_4/app/assets/stylesheets/static_pages.css.scss +0 -3
- data/sample_app_rails_4/app/assets/stylesheets/users.css.scss +0 -3
- data/sample_app_rails_4/app/controllers/application_controller.rb +0 -6
- data/sample_app_rails_4/app/controllers/concerns/.keep +0 -0
- data/sample_app_rails_4/app/controllers/microposts_controller.rb +0 -31
- data/sample_app_rails_4/app/controllers/relationships_controller.rb +0 -21
- data/sample_app_rails_4/app/controllers/sessions_controller.rb +0 -21
- data/sample_app_rails_4/app/controllers/static_pages_controller.rb +0 -18
- data/sample_app_rails_4/app/controllers/users_controller.rb +0 -80
- data/sample_app_rails_4/app/helpers/application_helper.rb +0 -12
- data/sample_app_rails_4/app/helpers/sessions_helper.rb +0 -49
- data/sample_app_rails_4/app/helpers/static_pages_helper.rb +0 -2
- data/sample_app_rails_4/app/helpers/users_helper.rb +0 -10
- data/sample_app_rails_4/app/mailers/.keep +0 -0
- data/sample_app_rails_4/app/models/.keep +0 -0
- data/sample_app_rails_4/app/models/concerns/.keep +0 -0
- data/sample_app_rails_4/app/models/micropost.rb +0 -24
- data/sample_app_rails_4/app/models/relationship.rb +0 -6
- data/sample_app_rails_4/app/models/user.rb +0 -39
- data/sample_app_rails_4/app/views/layouts/_footer.html.erb +0 -13
- data/sample_app_rails_4/app/views/layouts/_header.html.erb +0 -31
- data/sample_app_rails_4/app/views/layouts/_shim.html.erb +0 -3
- data/sample_app_rails_4/app/views/layouts/application.html.erb +0 -22
- data/sample_app_rails_4/app/views/microposts/_micropost.html.erb +0 -11
- data/sample_app_rails_4/app/views/relationships/create.js.erb +0 -2
- data/sample_app_rails_4/app/views/relationships/destroy.js.erb +0 -2
- data/sample_app_rails_4/app/views/sessions/new.html.erb +0 -19
- data/sample_app_rails_4/app/views/shared/_error_messages.html.erb +0 -12
- data/sample_app_rails_4/app/views/shared/_feed.html.erb +0 -6
- data/sample_app_rails_4/app/views/shared/_feed_item.html.erb +0 -15
- data/sample_app_rails_4/app/views/shared/_micropost_form.html.erb +0 -7
- data/sample_app_rails_4/app/views/shared/_stats.html.erb +0 -15
- data/sample_app_rails_4/app/views/shared/_user_info.html.erb +0 -12
- data/sample_app_rails_4/app/views/static_pages/about.html.erb +0 -8
- data/sample_app_rails_4/app/views/static_pages/contact.html.erb +0 -6
- data/sample_app_rails_4/app/views/static_pages/help.html.erb +0 -8
- data/sample_app_rails_4/app/views/static_pages/home.html.erb +0 -34
- data/sample_app_rails_4/app/views/static_pages/show.html.erb +0 -0
- data/sample_app_rails_4/app/views/users/_follow.html.erb +0 -5
- data/sample_app_rails_4/app/views/users/_follow_form.html.erb +0 -9
- data/sample_app_rails_4/app/views/users/_unfollow.html.erb +0 -5
- data/sample_app_rails_4/app/views/users/_user.html.erb +0 -8
- data/sample_app_rails_4/app/views/users/edit.html.erb +0 -27
- data/sample_app_rails_4/app/views/users/index.html.erb +0 -10
- data/sample_app_rails_4/app/views/users/new.html.erb +0 -24
- data/sample_app_rails_4/app/views/users/show.html.erb +0 -24
- data/sample_app_rails_4/app/views/users/show_follow.html.erb +0 -30
- data/sample_app_rails_4/bin/bundle +0 -3
- data/sample_app_rails_4/bin/rails +0 -4
- data/sample_app_rails_4/bin/rake +0 -4
- data/sample_app_rails_4/bin/rspec +0 -16
- data/sample_app_rails_4/config.ru +0 -4
- data/sample_app_rails_4/config/application.rb +0 -28
- data/sample_app_rails_4/config/boot.rb +0 -4
- data/sample_app_rails_4/config/database.yml +0 -27
- data/sample_app_rails_4/config/environment.rb +0 -5
- data/sample_app_rails_4/config/environments/development.rb +0 -25
- data/sample_app_rails_4/config/environments/production.rb +0 -79
- data/sample_app_rails_4/config/environments/test.rb +0 -38
- data/sample_app_rails_4/config/initializers/active_mocker.rb +0 -12
- data/sample_app_rails_4/config/initializers/backtrace_silencers.rb +0 -7
- data/sample_app_rails_4/config/initializers/filter_parameter_logging.rb +0 -4
- data/sample_app_rails_4/config/initializers/inflections.rb +0 -16
- data/sample_app_rails_4/config/initializers/mime_types.rb +0 -5
- data/sample_app_rails_4/config/initializers/secret_token.rb +0 -22
- data/sample_app_rails_4/config/initializers/session_store.rb +0 -3
- data/sample_app_rails_4/config/initializers/wrap_parameters.rb +0 -14
- data/sample_app_rails_4/config/locales/en.yml +0 -23
- data/sample_app_rails_4/config/routes.rb +0 -17
- data/sample_app_rails_4/db/migrate/20130311191400_create_users.rb +0 -10
- data/sample_app_rails_4/db/migrate/20130311194153_add_index_to_users_email.rb +0 -5
- data/sample_app_rails_4/db/migrate/20130311201841_add_password_digest_to_users.rb +0 -5
- data/sample_app_rails_4/db/migrate/20130314184954_add_remember_token_to_users.rb +0 -6
- data/sample_app_rails_4/db/migrate/20130315015932_add_admin_to_users.rb +0 -5
- data/sample_app_rails_4/db/migrate/20130315175534_create_microposts.rb +0 -11
- data/sample_app_rails_4/db/migrate/20130315230445_create_relationships.rb +0 -13
- data/sample_app_rails_4/db/schema.rb +0 -51
- data/sample_app_rails_4/db/seeds.rb +0 -7
- data/sample_app_rails_4/features/signing_in.feature +0 -13
- data/sample_app_rails_4/features/step_definitions/authentication_steps.rb +0 -30
- data/sample_app_rails_4/features/support/env.rb +0 -59
- data/sample_app_rails_4/lib/assets/.keep +0 -0
- data/sample_app_rails_4/lib/tasks/.keep +0 -0
- data/sample_app_rails_4/lib/tasks/active_mocker.rake +0 -10
- data/sample_app_rails_4/lib/tasks/cucumber.rake +0 -65
- data/sample_app_rails_4/lib/tasks/sample_data.rake +0 -42
- data/sample_app_rails_4/lib/unit_logger.rb +0 -22
- data/sample_app_rails_4/public/404.html +0 -27
- data/sample_app_rails_4/public/422.html +0 -26
- data/sample_app_rails_4/public/500.html +0 -26
- data/sample_app_rails_4/public/assets/application-4962059d8f80f9bb096692bacc29c4e8.css +0 -5091
- data/sample_app_rails_4/public/assets/application-4962059d8f80f9bb096692bacc29c4e8.css.gz +0 -0
- data/sample_app_rails_4/public/assets/application-eeb856e3fe2c8f879c91d0e81d59cb40.js +0 -12952
- data/sample_app_rails_4/public/assets/application-eeb856e3fe2c8f879c91d0e81d59cb40.js.gz +0 -0
- data/sample_app_rails_4/public/assets/glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png +0 -0
- data/sample_app_rails_4/public/assets/glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png +0 -0
- data/sample_app_rails_4/public/assets/manifest-802de9eb1c853769101852422b620883.json +0 -1
- data/sample_app_rails_4/public/assets/rails-231a680f23887d9dd70710ea5efd3c62.png +0 -0
- data/sample_app_rails_4/public/favicon.ico +0 -0
- data/sample_app_rails_4/public/robots.txt +0 -5
- data/sample_app_rails_4/script/cucumber +0 -10
- data/sample_app_rails_4/spec/compare_mocker_and_record_spec.rb +0 -1038
- data/sample_app_rails_4/spec/factories.rb +0 -17
- data/sample_app_rails_4/spec/micropost_mock_spec.rb +0 -145
- data/sample_app_rails_4/spec/mocks/micropost_mock.rb +0 -153
- data/sample_app_rails_4/spec/mocks/relationship_mock.rb +0 -151
- data/sample_app_rails_4/spec/mocks/user_mock.rb +0 -215
- data/sample_app_rails_4/spec/reload_spec.rb +0 -45
- data/sample_app_rails_4/spec/spec_helper.rb +0 -46
- data/sample_app_rails_4/spec/user_mock_spec.rb +0 -197
- data/sample_app_rails_4/vendor/assets/javascripts/.keep +0 -0
- data/sample_app_rails_4/vendor/assets/stylesheets/.keep +0 -0
- data/spec/lib/acitve_mock/queriable_spec.rb +0 -207
- data/spec/lib/active_mocker/db_to_ruby_type_spec.rb +0 -124
- data/spec/lib/active_mocker/generate_spec.rb +0 -40
- data/spec/lib/active_mocker/loaded_mocks_spec.rb +0 -167
- data/spec/lib/active_mocker/logger_spec.rb +0 -32
- data/spec/lib/active_mocker/model_reader_spec.rb +0 -206
- data/spec/lib/active_mocker/model_schema/generate_spec.rb +0 -111
- data/spec/lib/active_mocker/model_schema_spec.rb +0 -145
- data/spec/lib/active_mocker/schema_reader_spec.rb +0 -109
- data/spec/lib/model.rb +0 -43
- data/spec/lib/person.rb +0 -9
- data/spec/lib/readme_spec.rb +0 -199
- data/spec/lib/reparameterize_spec.rb +0 -202
- data/spec/lib/schema.rb +0 -40
- data/spec/unit_logger.rb +0 -24
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
require 'active_mocker/active_mock'
|
|
2
|
-
Object.send(:remove_const, "UserMock") if Object.const_defined?("UserMock")
|
|
3
|
-
|
|
4
|
-
class UserMock < ActiveMock::Base
|
|
5
|
-
|
|
6
|
-
class << self
|
|
7
|
-
|
|
8
|
-
def attributes
|
|
9
|
-
@attributes ||= HashWithIndifferentAccess.new({"id"=>nil, "name"=>nil, "email"=>"", "credits"=>nil, "created_at"=>nil, "updated_at"=>nil, "password_digest"=>nil, "remember_token"=>true, "admin"=>false})
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def types
|
|
13
|
-
@types ||= { id: build_type(Fixnum), name: build_type(String), email: build_type(String), credits: build_type(BigDecimal), created_at: build_type(DateTime), updated_at: build_type(DateTime), password_digest: build_type(String), remember_token: build_type(Axiom::Types::Boolean), admin: build_type(Axiom::Types::Boolean) }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def associations
|
|
17
|
-
@associations ||= {:microposts=>nil, :relationships=>nil, :followed_users=>nil, :reverse_relationships=>nil, :followers=>nil}
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def model_instance_methods
|
|
21
|
-
@model_instance_methods ||= {"feed"=>:not_implemented, "following?"=>:not_implemented, "follow!"=>:not_implemented, "unfollow!"=>:not_implemented}
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def model_class_methods
|
|
25
|
-
@model_class_methods ||= {"new_remember_token"=>:not_implemented, "digest"=>:not_implemented}
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def mocked_class
|
|
29
|
-
'User'
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def column_names
|
|
33
|
-
attribute_names
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def attribute_names
|
|
37
|
-
@attribute_names ||= ["id", "name", "email", "credits", "created_at", "updated_at", "password_digest", "remember_token", "admin"]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def primary_key
|
|
41
|
-
"id"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
##################################
|
|
47
|
-
# Attributes getter/setters #
|
|
48
|
-
##################################
|
|
49
|
-
|
|
50
|
-
def id
|
|
51
|
-
read_attribute(:id)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def id=(val)
|
|
55
|
-
write_attribute(:id, val)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def name
|
|
59
|
-
read_attribute(:name)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def name=(val)
|
|
63
|
-
write_attribute(:name, val)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def email
|
|
67
|
-
read_attribute(:email)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def email=(val)
|
|
71
|
-
write_attribute(:email, val)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def credits
|
|
75
|
-
read_attribute(:credits)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def credits=(val)
|
|
79
|
-
write_attribute(:credits, val)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def created_at
|
|
83
|
-
read_attribute(:created_at)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def created_at=(val)
|
|
87
|
-
write_attribute(:created_at, val)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def updated_at
|
|
91
|
-
read_attribute(:updated_at)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def updated_at=(val)
|
|
95
|
-
write_attribute(:updated_at, val)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def password_digest
|
|
99
|
-
read_attribute(:password_digest)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def password_digest=(val)
|
|
103
|
-
write_attribute(:password_digest, val)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def remember_token
|
|
107
|
-
read_attribute(:remember_token)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def remember_token=(val)
|
|
111
|
-
write_attribute(:remember_token, val)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def admin
|
|
115
|
-
read_attribute(:admin)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def admin=(val)
|
|
119
|
-
write_attribute(:admin, val)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
##################################
|
|
123
|
-
# Associations #
|
|
124
|
-
##################################
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
# has_many
|
|
128
|
-
def microposts
|
|
129
|
-
@associations[:microposts] ||= ActiveMock::HasMany.new([],'user_id', @attributes['id'], classes('Micropost'))
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def microposts=(val)
|
|
133
|
-
@associations[:microposts] ||= ActiveMock::HasMany.new(val,'user_id', @attributes['id'], classes('Micropost'))
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def relationships
|
|
137
|
-
@associations[:relationships] ||= ActiveMock::HasMany.new([],'follower_id', @attributes['id'], classes('Relationship'))
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def relationships=(val)
|
|
141
|
-
@associations[:relationships] ||= ActiveMock::HasMany.new(val,'follower_id', @attributes['id'], classes('Relationship'))
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def followed_users
|
|
145
|
-
@associations[:followed_users] ||= ActiveMock::HasMany.new([],'user_id', @attributes['id'], classes('FollowedUser'))
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def followed_users=(val)
|
|
149
|
-
@associations[:followed_users] ||= ActiveMock::HasMany.new(val,'user_id', @attributes['id'], classes('FollowedUser'))
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def reverse_relationships
|
|
153
|
-
@associations[:reverse_relationships] ||= ActiveMock::HasMany.new([],'followed_id', @attributes['id'], classes('Relationship'))
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def reverse_relationships=(val)
|
|
157
|
-
@associations[:reverse_relationships] ||= ActiveMock::HasMany.new(val,'followed_id', @attributes['id'], classes('Relationship'))
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def followers
|
|
161
|
-
@associations[:followers] ||= ActiveMock::HasMany.new([],'user_id', @attributes['id'], classes('Follower'))
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def followers=(val)
|
|
165
|
-
@associations[:followers] ||= ActiveMock::HasMany.new(val,'user_id', @attributes['id'], classes('Follower'))
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
##################################
|
|
169
|
-
# Model Methods getter/setters #
|
|
170
|
-
##################################
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def feed()
|
|
174
|
-
block = model_instance_methods['feed']
|
|
175
|
-
self.class.is_implemented(block, '#feed')
|
|
176
|
-
block.call(*[])
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def following?(other_user)
|
|
180
|
-
block = model_instance_methods['following?']
|
|
181
|
-
self.class.is_implemented(block, '#following?')
|
|
182
|
-
block.call(*[other_user])
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def follow!(other_user)
|
|
186
|
-
block = model_instance_methods['follow!']
|
|
187
|
-
self.class.is_implemented(block, '#follow!')
|
|
188
|
-
block.call(*[other_user])
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def unfollow!(other_user)
|
|
192
|
-
block = model_instance_methods['unfollow!']
|
|
193
|
-
self.class.is_implemented(block, '#unfollow!')
|
|
194
|
-
block.call(*[other_user])
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def self.new_remember_token()
|
|
198
|
-
block = model_class_methods['new_remember_token']
|
|
199
|
-
is_implemented(block, '::new_remember_token')
|
|
200
|
-
block.call(*[])
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
def self.digest(token)
|
|
204
|
-
block = model_class_methods['digest']
|
|
205
|
-
is_implemented(block, '::digest')
|
|
206
|
-
block.call(*[token])
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
private
|
|
210
|
-
|
|
211
|
-
def self.reload
|
|
212
|
-
load __FILE__
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
require 'rspec'
|
|
2
|
-
|
|
3
|
-
RSpec.configure do |config|
|
|
4
|
-
config.after(:all) do
|
|
5
|
-
ActiveMocker::LoadedMocks.clear_all
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
config.before(:all) do
|
|
9
|
-
ActiveMocker::LoadedMocks.clear_all
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
$:.unshift File.expand_path('../../', __FILE__)
|
|
14
|
-
APP_ROOT = File.expand_path('../../', __FILE__) unless defined? APP_ROOT
|
|
15
|
-
require 'config/initializers/active_mocker.rb'
|
|
16
|
-
load 'mocks/user_mock.rb'
|
|
17
|
-
|
|
18
|
-
describe 'Should change state of mock'do
|
|
19
|
-
|
|
20
|
-
before(:each) do
|
|
21
|
-
UserMock.create
|
|
22
|
-
|
|
23
|
-
UserMock.mock_class_method(:digest) do |token|
|
|
24
|
-
token
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'should change record count and digest should be implemented' do
|
|
29
|
-
expect(UserMock.count).to eq 1
|
|
30
|
-
expect(UserMock.digest('token')).to eq 'token'
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe 'should have fresh mock' do
|
|
36
|
-
|
|
37
|
-
it 'should have record count of zero' do
|
|
38
|
-
expect(UserMock.count).to eq 0
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'should raise error when calling digest' do
|
|
42
|
-
expect{UserMock.digest(nil)}.to raise_error(RuntimeError, '::digest is not Implemented for Class: UserMock')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
ENV["RAILS_ENV"] ||= 'test'
|
|
2
|
-
|
|
3
|
-
require File.expand_path("../../config/environment", __FILE__)
|
|
4
|
-
require 'rspec/rails'
|
|
5
|
-
require 'rspec/autorun'
|
|
6
|
-
|
|
7
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
8
|
-
# in spec/support/ and its subdirectories.
|
|
9
|
-
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
|
10
|
-
|
|
11
|
-
# Checks for pending migrations before tests are run.
|
|
12
|
-
# If you are not using ActiveRecord, you can remove this line.
|
|
13
|
-
ActiveRecord::Migration.maintain_test_schema!
|
|
14
|
-
|
|
15
|
-
RSpec.configure do |config|
|
|
16
|
-
# ## Mock Framework
|
|
17
|
-
#
|
|
18
|
-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
19
|
-
#
|
|
20
|
-
# config.mock_with :mocha
|
|
21
|
-
# config.mock_with :flexmock
|
|
22
|
-
# config.mock_with :rr
|
|
23
|
-
|
|
24
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
|
25
|
-
|
|
26
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
27
|
-
# examples within a transaction, remove the following line or assign false
|
|
28
|
-
# instead of true.
|
|
29
|
-
config.use_transactional_fixtures = true
|
|
30
|
-
|
|
31
|
-
# If true, the base class of anonymous controllers will be inferred
|
|
32
|
-
# automatically. This will be the default behavior in future versions of
|
|
33
|
-
# rspec-rails.
|
|
34
|
-
config.infer_base_class_for_anonymous_controllers = false
|
|
35
|
-
|
|
36
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
37
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
38
|
-
# the seed, which is printed after each run.
|
|
39
|
-
# --seed 1234
|
|
40
|
-
config.order = "random"
|
|
41
|
-
# Include the Capybara DSL so that specs in spec/requests still work.
|
|
42
|
-
# Disable the old-style object.should syntax.
|
|
43
|
-
config.expect_with :rspec do |c|
|
|
44
|
-
c.syntax = :expect
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
require 'rspec'
|
|
2
|
-
$:.unshift File.expand_path('../../', __FILE__)
|
|
3
|
-
require 'active_support'
|
|
4
|
-
require 'spec/mocks/user_mock.rb'
|
|
5
|
-
APP_ROOT = File.expand_path('../../', __FILE__) unless defined? APP_ROOT
|
|
6
|
-
require 'config/initializers/active_mocker.rb'
|
|
7
|
-
require 'forwardable'
|
|
8
|
-
|
|
9
|
-
describe 'UserMock' do
|
|
10
|
-
|
|
11
|
-
before(:each){
|
|
12
|
-
ActiveMocker::Generate.new
|
|
13
|
-
UserMock.clear_mock
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe '::mocked_class' do
|
|
17
|
-
|
|
18
|
-
it 'returns the name of the class being mocked' do
|
|
19
|
-
expect(UserMock.mocked_class).to eq 'User'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe 'ActiveMocker::LoadedMocks' do
|
|
25
|
-
|
|
26
|
-
it 'will be added when sub classed' do
|
|
27
|
-
expect(ActiveMocker::LoadedMocks.all.keys.include?('UserMock')).to eq true
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
describe '::column_names' do
|
|
34
|
-
|
|
35
|
-
it 'returns an array of column names found from the schema.rb file' do
|
|
36
|
-
expect(UserMock.column_names).to eq(["id", "name", "email", "credits", "created_at", "updated_at", "password_digest", "remember_token", "admin"])
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe 'mass_assignment' do
|
|
42
|
-
|
|
43
|
-
it "can pass any or all attributes from schema in initializer" do
|
|
44
|
-
result = UserMock.new(name: "Sam", email: 'Walton')
|
|
45
|
-
expect(result.name).to eq 'Sam'
|
|
46
|
-
expect(result.email).to eq 'Walton'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'will raise error if not an attribute or association' do
|
|
50
|
-
expect{UserMock.new(baz: "Hello")}.to raise_error(ActiveMock::RejectedParams, '{:baz=>"Hello"} for UserMock')
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
describe 'relationships' do
|
|
56
|
-
|
|
57
|
-
it 'add instance methods from model relationships' do
|
|
58
|
-
result = UserMock.new(followers: [1])
|
|
59
|
-
expect(result.followers).to eq [1]
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'add has_many relationship' do
|
|
63
|
-
expect(UserMock.new.microposts.count).to eq 0
|
|
64
|
-
mock_inst = UserMock.new
|
|
65
|
-
mock_inst.microposts << 1
|
|
66
|
-
expect(mock_inst.microposts.count).to eq 1
|
|
67
|
-
mock_inst.microposts << 1
|
|
68
|
-
expect(mock_inst.microposts.count).to eq 2
|
|
69
|
-
expect(mock_inst.microposts.to_a).to eq [1, 1]
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe 'instance methods' do
|
|
75
|
-
|
|
76
|
-
it 'will raise exception for unimplemented methods' do
|
|
77
|
-
expect(UserMock.new.method(:following?).parameters).to eq [[:req, :other_user]]
|
|
78
|
-
expect{UserMock.new.following?}.to raise_error ArgumentError
|
|
79
|
-
expect{UserMock.new.following?('foo')}.to raise_error(RuntimeError, '#following? is not Implemented for Class: UserMock')
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it 'can be implemented dynamically' do
|
|
83
|
-
|
|
84
|
-
UserMock.mock_instance_method(:follow!) do |other_user|
|
|
85
|
-
"Now implemented with #{other_user}"
|
|
86
|
-
end
|
|
87
|
-
result = UserMock.new
|
|
88
|
-
result = result.follow!('foo')
|
|
89
|
-
expect(result).to eq "Now implemented with foo"
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it 'can not reference another method within the mock' do
|
|
94
|
-
|
|
95
|
-
UserMock.mock_instance_method(:following?) do |person|
|
|
96
|
-
true
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
UserMock.mock_instance_method(:follow!) do |person|
|
|
100
|
-
following?(person)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
expect{UserMock.new.follow!("name") }.to raise_error
|
|
104
|
-
expect(UserMock.new.following?(1)).to eq true
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe 'class methods' do
|
|
110
|
-
|
|
111
|
-
it 'will raise exception for unimplemented methods' do
|
|
112
|
-
expect{UserMock.new_remember_token}.to raise_error('::new_remember_token is not Implemented for Class: UserMock')
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it 'can be implemented as follows' do
|
|
116
|
-
|
|
117
|
-
UserMock.mock_class_method(:new_remember_token) do
|
|
118
|
-
"Now implemented"
|
|
119
|
-
end
|
|
120
|
-
expect{UserMock.new_remember_token}.to_not raise_error
|
|
121
|
-
expect(UserMock.new_remember_token).to eq("Now implemented")
|
|
122
|
-
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
context 'active_mock' do
|
|
128
|
-
|
|
129
|
-
it 'uses active_mock::base as superclass' do
|
|
130
|
-
expect(UserMock.superclass.name).to eq 'ActiveMock::Base'
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it 'can save to class and then find instance by attribute' do
|
|
134
|
-
record = UserMock.create(name: "Sam")
|
|
135
|
-
expect(UserMock.find_by(name:"Sam")).to eq record
|
|
136
|
-
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it '#update' do
|
|
140
|
-
|
|
141
|
-
person = UserMock.create(name: 'Justin')
|
|
142
|
-
expect(UserMock.first.name).to eq 'Justin'
|
|
143
|
-
person.update(name: 'Dustin')
|
|
144
|
-
expect(UserMock.first.name).to eq 'Dustin'
|
|
145
|
-
|
|
146
|
-
expect(person.name).to eq 'Dustin'
|
|
147
|
-
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it '::destroy_all' do
|
|
151
|
-
|
|
152
|
-
UserMock.create
|
|
153
|
-
|
|
154
|
-
expect(UserMock.count).to eq 1
|
|
155
|
-
|
|
156
|
-
UserMock.destroy_all
|
|
157
|
-
|
|
158
|
-
expect(UserMock.count).to eq 0
|
|
159
|
-
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it '::find_by' do
|
|
163
|
-
person = UserMock.create(name: 'dustin')
|
|
164
|
-
expect(UserMock.find_by(name: 'dustin')).to eq person
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it '::find_or_create_by' do
|
|
168
|
-
person = UserMock.find_or_create_by(name: 'dustin')
|
|
169
|
-
expect(UserMock.find_by(name: 'dustin')).to eq person
|
|
170
|
-
person = UserMock.find_or_create_by(name: 'dustin')
|
|
171
|
-
expect(UserMock.count).to eq 1
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
it '::find_or_create_by with update' do
|
|
175
|
-
UserMock.create(name: 'dustin')
|
|
176
|
-
person = UserMock.find_or_create_by(name: 'dustin')
|
|
177
|
-
person.update(email: 'Zeisler')
|
|
178
|
-
expect(UserMock.first.attributes).to eq person.attributes
|
|
179
|
-
expect(UserMock.count).to eq 1
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it '::find_or_initialize_by' do
|
|
183
|
-
person = UserMock.find_or_initialize_by(name: 'dustin')
|
|
184
|
-
expect(person.persisted?).to eq false
|
|
185
|
-
UserMock.create(name: 'dustin')
|
|
186
|
-
person = UserMock.find_or_initialize_by(name: 'dustin')
|
|
187
|
-
expect(person.persisted?).to eq true
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
after(:each) do
|
|
192
|
-
UserMock.delete_all
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
end
|