active_mocker 1.4.2 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +35 -29
  4. data/lib/active_mocker.rb +3 -1
  5. data/lib/active_mocker/active_record.rb +27 -5
  6. data/lib/active_mocker/active_record/scope.rb +5 -5
  7. data/lib/active_mocker/active_record/unknown_module.rb +4 -4
  8. data/lib/active_mocker/generate.rb +36 -15
  9. data/lib/active_mocker/loaded_mocks.rb +60 -54
  10. data/lib/active_mocker/mock.rb +24 -0
  11. data/lib/active_mocker/mock/association.rb +6 -0
  12. data/lib/{active_mock → active_mocker/mock}/base.rb +43 -89
  13. data/lib/{active_mock → active_mocker/mock}/collection.rb +14 -7
  14. data/lib/{active_mock → active_mocker/mock}/do_nothing_active_record_methods.rb +7 -1
  15. data/lib/active_mocker/mock/exceptions.rb +25 -0
  16. data/lib/active_mocker/mock/has_and_belongs_to_many.rb +6 -0
  17. data/lib/active_mocker/mock/has_many.rb +60 -0
  18. data/lib/active_mocker/mock/hash_process.rb +19 -0
  19. data/lib/active_mocker/mock/mock_abilities.rb +98 -0
  20. data/lib/{active_mock → active_mocker/mock}/next_id.rb +7 -2
  21. data/lib/{active_mock → active_mocker/mock}/object_inspect.rb +3 -1
  22. data/lib/{active_mock → active_mocker/mock}/queries.rb +32 -29
  23. data/lib/active_mocker/mock/records.rb +62 -0
  24. data/lib/{active_mock → active_mocker/mock}/relation.rb +4 -3
  25. data/lib/active_mocker/mock/template_methods.rb +39 -0
  26. data/lib/active_mocker/mock_template.erb +45 -31
  27. data/lib/active_mocker/model_reader.rb +29 -0
  28. data/lib/active_mocker/model_schema.rb +23 -16
  29. data/lib/active_mocker/model_schema/generate.rb +19 -8
  30. data/lib/active_mocker/railtie.rb +17 -0
  31. data/lib/active_mocker/reparameterize.rb +2 -4
  32. data/lib/active_mocker/rspec_helper.rb +18 -0
  33. data/lib/active_mocker/task.rake +15 -0
  34. data/lib/active_mocker/version.rb +1 -1
  35. metadata +80 -206
  36. data/.gitignore +0 -19
  37. data/.hound.yml +0 -0
  38. data/.travis.yml +0 -5
  39. data/Gemfile +0 -4
  40. data/Rakefile +0 -26
  41. data/active_mocker.gemspec +0 -40
  42. data/lib/active_mock/association.rb +0 -7
  43. data/lib/active_mock/creators.rb +0 -25
  44. data/lib/active_mock/has_and_belongs_to_many.rb +0 -7
  45. data/lib/active_mock/has_many.rb +0 -54
  46. data/lib/active_mock/records.rb +0 -83
  47. data/lib/active_mocker/active_mock.rb +0 -26
  48. data/lib/active_mocker/active_record/const_missing.rb +0 -5
  49. data/lib/active_mocker/class_exists.rb +0 -12
  50. data/lib/active_mocker/const_sets.rb +0 -24
  51. data/lib/active_mocker/mock_task.rb +0 -12
  52. data/sample_app_rails_4/.idea/.generators +0 -8
  53. data/sample_app_rails_4/.idea/.name +0 -1
  54. data/sample_app_rails_4/.idea/.rakeTasks +0 -7
  55. data/sample_app_rails_4/.idea/dataSources.ids +0 -141
  56. data/sample_app_rails_4/.idea/dataSources.xml +0 -36
  57. data/sample_app_rails_4/.idea/dictionaries/zeisler.xml +0 -3
  58. data/sample_app_rails_4/.idea/encodings.xml +0 -5
  59. data/sample_app_rails_4/.idea/inspectionProfiles/Project_Default.xml +0 -20
  60. data/sample_app_rails_4/.idea/inspectionProfiles/profiles_settings.xml +0 -7
  61. data/sample_app_rails_4/.idea/misc.xml +0 -5
  62. data/sample_app_rails_4/.idea/modules.xml +0 -10
  63. data/sample_app_rails_4/.idea/runConfigurations/Development__sample_app_rails_4.xml +0 -28
  64. data/sample_app_rails_4/.idea/runConfigurations/Production__sample_app_rails_4.xml +0 -28
  65. data/sample_app_rails_4/.idea/runConfigurations/spec__sample_app_rails_4.xml +0 -26
  66. data/sample_app_rails_4/.idea/runConfigurations/test__sample_app_rails_4.xml +0 -28
  67. data/sample_app_rails_4/.idea/sample_app_rails_4.iml +0 -262
  68. data/sample_app_rails_4/.idea/scopes/scope_settings.xml +0 -5
  69. data/sample_app_rails_4/.idea/vcs.xml +0 -7
  70. data/sample_app_rails_4/.idea/workspace.xml +0 -619
  71. data/sample_app_rails_4/.rspec +0 -1
  72. data/sample_app_rails_4/.secret +0 -1
  73. data/sample_app_rails_4/Gemfile +0 -13
  74. data/sample_app_rails_4/Guardfile +0 -53
  75. data/sample_app_rails_4/LICENSE +0 -21
  76. data/sample_app_rails_4/README.md +0 -25
  77. data/sample_app_rails_4/README.nitrous.md +0 -20
  78. data/sample_app_rails_4/Rakefile +0 -6
  79. data/sample_app_rails_4/app/assets/images/rails.png +0 -0
  80. data/sample_app_rails_4/app/assets/javascripts/application.js +0 -17
  81. data/sample_app_rails_4/app/assets/javascripts/sessions.js.coffee +0 -3
  82. data/sample_app_rails_4/app/assets/javascripts/static_pages.js.coffee +0 -3
  83. data/sample_app_rails_4/app/assets/javascripts/users.js.coffee +0 -3
  84. data/sample_app_rails_4/app/assets/stylesheets/application.css +0 -13
  85. data/sample_app_rails_4/app/assets/stylesheets/custom.css.scss +0 -246
  86. data/sample_app_rails_4/app/assets/stylesheets/sessions.css.scss +0 -3
  87. data/sample_app_rails_4/app/assets/stylesheets/static_pages.css.scss +0 -3
  88. data/sample_app_rails_4/app/assets/stylesheets/users.css.scss +0 -3
  89. data/sample_app_rails_4/app/controllers/application_controller.rb +0 -6
  90. data/sample_app_rails_4/app/controllers/concerns/.keep +0 -0
  91. data/sample_app_rails_4/app/controllers/microposts_controller.rb +0 -31
  92. data/sample_app_rails_4/app/controllers/relationships_controller.rb +0 -21
  93. data/sample_app_rails_4/app/controllers/sessions_controller.rb +0 -21
  94. data/sample_app_rails_4/app/controllers/static_pages_controller.rb +0 -18
  95. data/sample_app_rails_4/app/controllers/users_controller.rb +0 -80
  96. data/sample_app_rails_4/app/helpers/application_helper.rb +0 -12
  97. data/sample_app_rails_4/app/helpers/sessions_helper.rb +0 -49
  98. data/sample_app_rails_4/app/helpers/static_pages_helper.rb +0 -2
  99. data/sample_app_rails_4/app/helpers/users_helper.rb +0 -10
  100. data/sample_app_rails_4/app/mailers/.keep +0 -0
  101. data/sample_app_rails_4/app/models/.keep +0 -0
  102. data/sample_app_rails_4/app/models/concerns/.keep +0 -0
  103. data/sample_app_rails_4/app/models/micropost.rb +0 -24
  104. data/sample_app_rails_4/app/models/relationship.rb +0 -6
  105. data/sample_app_rails_4/app/models/user.rb +0 -39
  106. data/sample_app_rails_4/app/views/layouts/_footer.html.erb +0 -13
  107. data/sample_app_rails_4/app/views/layouts/_header.html.erb +0 -31
  108. data/sample_app_rails_4/app/views/layouts/_shim.html.erb +0 -3
  109. data/sample_app_rails_4/app/views/layouts/application.html.erb +0 -22
  110. data/sample_app_rails_4/app/views/microposts/_micropost.html.erb +0 -11
  111. data/sample_app_rails_4/app/views/relationships/create.js.erb +0 -2
  112. data/sample_app_rails_4/app/views/relationships/destroy.js.erb +0 -2
  113. data/sample_app_rails_4/app/views/sessions/new.html.erb +0 -19
  114. data/sample_app_rails_4/app/views/shared/_error_messages.html.erb +0 -12
  115. data/sample_app_rails_4/app/views/shared/_feed.html.erb +0 -6
  116. data/sample_app_rails_4/app/views/shared/_feed_item.html.erb +0 -15
  117. data/sample_app_rails_4/app/views/shared/_micropost_form.html.erb +0 -7
  118. data/sample_app_rails_4/app/views/shared/_stats.html.erb +0 -15
  119. data/sample_app_rails_4/app/views/shared/_user_info.html.erb +0 -12
  120. data/sample_app_rails_4/app/views/static_pages/about.html.erb +0 -8
  121. data/sample_app_rails_4/app/views/static_pages/contact.html.erb +0 -6
  122. data/sample_app_rails_4/app/views/static_pages/help.html.erb +0 -8
  123. data/sample_app_rails_4/app/views/static_pages/home.html.erb +0 -34
  124. data/sample_app_rails_4/app/views/static_pages/show.html.erb +0 -0
  125. data/sample_app_rails_4/app/views/users/_follow.html.erb +0 -5
  126. data/sample_app_rails_4/app/views/users/_follow_form.html.erb +0 -9
  127. data/sample_app_rails_4/app/views/users/_unfollow.html.erb +0 -5
  128. data/sample_app_rails_4/app/views/users/_user.html.erb +0 -8
  129. data/sample_app_rails_4/app/views/users/edit.html.erb +0 -27
  130. data/sample_app_rails_4/app/views/users/index.html.erb +0 -10
  131. data/sample_app_rails_4/app/views/users/new.html.erb +0 -24
  132. data/sample_app_rails_4/app/views/users/show.html.erb +0 -24
  133. data/sample_app_rails_4/app/views/users/show_follow.html.erb +0 -30
  134. data/sample_app_rails_4/bin/bundle +0 -3
  135. data/sample_app_rails_4/bin/rails +0 -4
  136. data/sample_app_rails_4/bin/rake +0 -4
  137. data/sample_app_rails_4/bin/rspec +0 -16
  138. data/sample_app_rails_4/config.ru +0 -4
  139. data/sample_app_rails_4/config/application.rb +0 -28
  140. data/sample_app_rails_4/config/boot.rb +0 -4
  141. data/sample_app_rails_4/config/database.yml +0 -27
  142. data/sample_app_rails_4/config/environment.rb +0 -5
  143. data/sample_app_rails_4/config/environments/development.rb +0 -25
  144. data/sample_app_rails_4/config/environments/production.rb +0 -79
  145. data/sample_app_rails_4/config/environments/test.rb +0 -38
  146. data/sample_app_rails_4/config/initializers/active_mocker.rb +0 -12
  147. data/sample_app_rails_4/config/initializers/backtrace_silencers.rb +0 -7
  148. data/sample_app_rails_4/config/initializers/filter_parameter_logging.rb +0 -4
  149. data/sample_app_rails_4/config/initializers/inflections.rb +0 -16
  150. data/sample_app_rails_4/config/initializers/mime_types.rb +0 -5
  151. data/sample_app_rails_4/config/initializers/secret_token.rb +0 -22
  152. data/sample_app_rails_4/config/initializers/session_store.rb +0 -3
  153. data/sample_app_rails_4/config/initializers/wrap_parameters.rb +0 -14
  154. data/sample_app_rails_4/config/locales/en.yml +0 -23
  155. data/sample_app_rails_4/config/routes.rb +0 -17
  156. data/sample_app_rails_4/db/migrate/20130311191400_create_users.rb +0 -10
  157. data/sample_app_rails_4/db/migrate/20130311194153_add_index_to_users_email.rb +0 -5
  158. data/sample_app_rails_4/db/migrate/20130311201841_add_password_digest_to_users.rb +0 -5
  159. data/sample_app_rails_4/db/migrate/20130314184954_add_remember_token_to_users.rb +0 -6
  160. data/sample_app_rails_4/db/migrate/20130315015932_add_admin_to_users.rb +0 -5
  161. data/sample_app_rails_4/db/migrate/20130315175534_create_microposts.rb +0 -11
  162. data/sample_app_rails_4/db/migrate/20130315230445_create_relationships.rb +0 -13
  163. data/sample_app_rails_4/db/schema.rb +0 -51
  164. data/sample_app_rails_4/db/seeds.rb +0 -7
  165. data/sample_app_rails_4/features/signing_in.feature +0 -13
  166. data/sample_app_rails_4/features/step_definitions/authentication_steps.rb +0 -30
  167. data/sample_app_rails_4/features/support/env.rb +0 -59
  168. data/sample_app_rails_4/lib/assets/.keep +0 -0
  169. data/sample_app_rails_4/lib/tasks/.keep +0 -0
  170. data/sample_app_rails_4/lib/tasks/active_mocker.rake +0 -10
  171. data/sample_app_rails_4/lib/tasks/cucumber.rake +0 -65
  172. data/sample_app_rails_4/lib/tasks/sample_data.rake +0 -42
  173. data/sample_app_rails_4/lib/unit_logger.rb +0 -22
  174. data/sample_app_rails_4/public/404.html +0 -27
  175. data/sample_app_rails_4/public/422.html +0 -26
  176. data/sample_app_rails_4/public/500.html +0 -26
  177. data/sample_app_rails_4/public/assets/application-4962059d8f80f9bb096692bacc29c4e8.css +0 -5091
  178. data/sample_app_rails_4/public/assets/application-4962059d8f80f9bb096692bacc29c4e8.css.gz +0 -0
  179. data/sample_app_rails_4/public/assets/application-eeb856e3fe2c8f879c91d0e81d59cb40.js +0 -12952
  180. data/sample_app_rails_4/public/assets/application-eeb856e3fe2c8f879c91d0e81d59cb40.js.gz +0 -0
  181. data/sample_app_rails_4/public/assets/glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png +0 -0
  182. data/sample_app_rails_4/public/assets/glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png +0 -0
  183. data/sample_app_rails_4/public/assets/manifest-802de9eb1c853769101852422b620883.json +0 -1
  184. data/sample_app_rails_4/public/assets/rails-231a680f23887d9dd70710ea5efd3c62.png +0 -0
  185. data/sample_app_rails_4/public/favicon.ico +0 -0
  186. data/sample_app_rails_4/public/robots.txt +0 -5
  187. data/sample_app_rails_4/script/cucumber +0 -10
  188. data/sample_app_rails_4/spec/compare_mocker_and_record_spec.rb +0 -1038
  189. data/sample_app_rails_4/spec/factories.rb +0 -17
  190. data/sample_app_rails_4/spec/micropost_mock_spec.rb +0 -145
  191. data/sample_app_rails_4/spec/mocks/micropost_mock.rb +0 -153
  192. data/sample_app_rails_4/spec/mocks/relationship_mock.rb +0 -151
  193. data/sample_app_rails_4/spec/mocks/user_mock.rb +0 -215
  194. data/sample_app_rails_4/spec/reload_spec.rb +0 -45
  195. data/sample_app_rails_4/spec/spec_helper.rb +0 -46
  196. data/sample_app_rails_4/spec/user_mock_spec.rb +0 -197
  197. data/sample_app_rails_4/vendor/assets/javascripts/.keep +0 -0
  198. data/sample_app_rails_4/vendor/assets/stylesheets/.keep +0 -0
  199. data/spec/lib/acitve_mock/queriable_spec.rb +0 -207
  200. data/spec/lib/active_mocker/db_to_ruby_type_spec.rb +0 -124
  201. data/spec/lib/active_mocker/generate_spec.rb +0 -40
  202. data/spec/lib/active_mocker/loaded_mocks_spec.rb +0 -167
  203. data/spec/lib/active_mocker/logger_spec.rb +0 -32
  204. data/spec/lib/active_mocker/model_reader_spec.rb +0 -206
  205. data/spec/lib/active_mocker/model_schema/generate_spec.rb +0 -111
  206. data/spec/lib/active_mocker/model_schema_spec.rb +0 -145
  207. data/spec/lib/active_mocker/schema_reader_spec.rb +0 -109
  208. data/spec/lib/model.rb +0 -43
  209. data/spec/lib/person.rb +0 -9
  210. data/spec/lib/readme_spec.rb +0 -199
  211. data/spec/lib/reparameterize_spec.rb +0 -202
  212. data/spec/lib/schema.rb +0 -40
  213. data/spec/unit_logger.rb +0 -24
@@ -1 +0,0 @@
1
- {"files":{"rails-231a680f23887d9dd70710ea5efd3c62.png":{"logical_path":"rails.png","mtime":"2013-03-06T18:36:31-08:00","size":6646,"digest":"231a680f23887d9dd70710ea5efd3c62"},"application-eeb856e3fe2c8f879c91d0e81d59cb40.js":{"logical_path":"application.js","mtime":"2013-09-06T09:23:56-07:00","size":363970,"digest":"eeb856e3fe2c8f879c91d0e81d59cb40"},"application-4962059d8f80f9bb096692bacc29c4e8.css":{"logical_path":"application.css","mtime":"2013-09-06T13:20:19-07:00","size":134254,"digest":"4962059d8f80f9bb096692bacc29c4e8"},"glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png":{"logical_path":"glyphicons-halflings-white.png","mtime":"2013-06-24T16:40:09-07:00","size":8777,"digest":"62b67d9edee3db90d18833087f848d6e"},"glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png":{"logical_path":"glyphicons-halflings.png","mtime":"2013-06-24T16:40:09-07:00","size":12799,"digest":"c806376f05e4ccabe2c5315a8e95667c"}},"assets":{"rails.png":"rails-231a680f23887d9dd70710ea5efd3c62.png","application.js":"application-eeb856e3fe2c8f879c91d0e81d59cb40.js","application.css":"application-4962059d8f80f9bb096692bacc29c4e8.css","glyphicons-halflings-white.png":"glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png","glyphicons-halflings.png":"glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png"}}
File without changes
@@ -1,5 +0,0 @@
1
- # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
- #
3
- # To ban all spiders from the entire site uncomment the next two lines:
4
- # User-agent: *
5
- # Disallow: /
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
- if vendored_cucumber_bin
5
- load File.expand_path(vendored_cucumber_bin)
6
- else
7
- require 'rubygems' unless ENV['NO_RUBYGEMS']
8
- require 'cucumber'
9
- load Cucumber::BINARY
10
- end
@@ -1,1038 +0,0 @@
1
- $:.unshift File.expand_path('../', __FILE__)
2
- require 'spec_helper'
3
- load 'mocks/user_mock.rb'
4
- load 'mocks/micropost_mock.rb'
5
-
6
- describe 'Comparing ActiveMocker Api to ActiveRecord Api' do
7
-
8
- before(:each) do
9
- User.destroy_all
10
- UserMock.destroy_all
11
- MicropostMock.destroy_all
12
- Micropost.destroy_all
13
- end
14
-
15
- after(:each) do
16
- UserMock.destroy_all
17
- User.destroy_all
18
- MicropostMock.destroy_all
19
- Micropost.destroy_all
20
- end
21
-
22
-
23
- let(:attributes) { {name: 'Dustin Zeisler', email: 'dustin@example.com'} }
24
- let(:attributes_with_admin) { {name: 'Dustin Zeisler', email: 'dustin@example.com', admin: true} }
25
-
26
- describe '::superclass' do
27
-
28
- it 'mock has super of active hash' do
29
- expect(UserMock.superclass.name).to eq "ActiveMock::Base"
30
- end
31
-
32
- it 'ar has super of ar' do
33
- expect(User.superclass.name).to eq "ActiveRecord::Base"
34
- end
35
-
36
- end
37
-
38
- describe '::create' do
39
-
40
- let(:create_attributes){attributes}
41
-
42
- it 'mock will take all attributes that AR takes' do
43
- User.create(create_attributes)
44
- UserMock.create(create_attributes)
45
- end
46
-
47
- context 'new with block' do
48
-
49
- def create_with_block(klass)
50
- user = klass.new do |u|
51
- u.name = "David"
52
- u.admin = true
53
- end
54
-
55
- expect(user.name).to eq 'David'
56
- expect(user.admin).to eq true
57
-
58
- end
59
-
60
- it 'User' do
61
- create_with_block(User)
62
- end
63
-
64
- it 'UserMock' do
65
- create_with_block(UserMock)
66
- end
67
-
68
- end
69
-
70
- context 'create with block' do
71
-
72
- def create_with_block(klass)
73
- user = klass.create do |u|
74
- u.name = "David"
75
- u.admin = true
76
- end
77
-
78
- expect(user.name).to eq 'David'
79
- expect(user.admin).to eq true
80
-
81
- end
82
-
83
- it 'User' do
84
- create_with_block(User)
85
- end
86
-
87
- it 'UserMock' do
88
- create_with_block(UserMock)
89
- end
90
-
91
- end
92
-
93
- end
94
-
95
- describe '#attributes' do
96
-
97
- let(:user_ar){User.new(attributes)}
98
- let(:user_mock){
99
- UserMock.new(attributes)
100
- }
101
-
102
- it 'mock' do
103
- expect(user_mock.attributes).to eq({"id" => nil, "name" => "Dustin Zeisler", "email" => "dustin@example.com", "credits" => nil, "created_at" => nil, "updated_at" => nil, "password_digest" => nil, "remember_token" => true, "admin" => false})
104
- end
105
-
106
- it 'AR' do
107
- expect(user_ar.attributes).to eq({"id" => nil, "name" => "Dustin Zeisler", "email" => "dustin@example.com", "credits" => nil, "created_at" => nil, "updated_at" => nil, "password_digest" => nil, "remember_token" => true, "admin" => false})
108
- end
109
-
110
- end
111
-
112
- describe '::all' do
113
-
114
- def klass_all(klass)
115
- array = [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
116
- expect(klass.all).to eq array
117
- end
118
-
119
- it 'User' do
120
- klass_all(User)
121
- end
122
-
123
- it 'UserMock' do
124
- klass_all(UserMock)
125
- end
126
-
127
- end
128
-
129
- describe '::average' do
130
-
131
- def klass_method_average(klass)
132
- [klass.create!(credits: 12, email: '1'), klass.create!(credits: 2, email: '2'), klass.create!(credits: 8, email: '3'), klass.create!(credits: 4, email: '4')]
133
- expect(klass.average(:credits).to_s).to eq "6.5"
134
- end
135
-
136
- it 'User' do
137
- klass_method_average(User)
138
- end
139
-
140
- it 'UserMock' do
141
- klass_method_average(UserMock)
142
- end
143
-
144
- end
145
-
146
- describe '::minimum' do
147
-
148
- def klass_method_minimum(klass)
149
- [klass.create!(credits: 12, email: '1'), klass.create!(credits: 2, email: '2'), klass.create!(credits: 8, email: '3'), klass.create!(credits: 4, email: '4')]
150
- expect(klass.minimum(:credits).to_s).to eq "2.0"
151
- end
152
-
153
- it 'User' do
154
- klass_method_minimum(User)
155
- end
156
-
157
- it 'UserMock' do
158
- klass_method_minimum(UserMock)
159
- end
160
-
161
- end
162
-
163
- describe '::maximum' do
164
-
165
- def klass_method_maximum(klass)
166
- [klass.create!(credits: 12, email: '1'), klass.create!(credits: 2, email: '2'), klass.create!(credits: 8, email: '3'), klass.create!(credits: 4, email: '4')]
167
- expect(klass.maximum(:credits).to_s).to eq "12.0"
168
- end
169
-
170
- it 'User' do
171
- klass_method_maximum(User)
172
- end
173
-
174
- it 'UserMock' do
175
- klass_method_maximum(UserMock)
176
- end
177
-
178
- end
179
-
180
- describe 'associations' do
181
-
182
- let(:micropost){ Micropost.create(content: 'post')}
183
- let(:create_attributes){attributes.merge({microposts: [micropost]})}
184
-
185
- let(:user_ar){User.new(create_attributes)}
186
- let(:user_mock){UserMock.new(create_attributes)}
187
-
188
- it 'the Mock when adding an association will not set the _id attribute, do it manually' do
189
- expect(user_mock.attributes).to eq({"id" => nil, "name" => "Dustin Zeisler", "email" => "dustin@example.com", "credits" => nil, "created_at" => nil, "updated_at" => nil, "password_digest" => nil, "remember_token" => true, "admin" => false})
190
- expect(user_mock.microposts).to eq [micropost]
191
- end
192
-
193
- it 'Ar will not include associations in attributes' do
194
- expect(user_ar.attributes).to eq({"id" => nil, "name" => "Dustin Zeisler", "email" => "dustin@example.com", "credits" => nil, "created_at" => nil, "updated_at" => nil, "password_digest" => nil, "remember_token" => true, "admin" => false})
195
- expect(user_ar.microposts).to eq [micropost]
196
- end
197
-
198
- end
199
-
200
- describe 'column_names' do
201
-
202
- it 'they are the same' do
203
- expect(UserMock.column_names).to eq User.column_names
204
- end
205
-
206
- end
207
-
208
- describe 'attribute_names' do
209
-
210
- it 'they are the same' do
211
- expect(UserMock.attribute_names).to eq User.attribute_names
212
- end
213
-
214
- end
215
-
216
- describe '::find_by' do
217
-
218
- let!(:ar_record){User.create(attributes)}
219
- let!(:mock_record){UserMock.create(attributes)}
220
-
221
- it 'AR' do
222
- expect(ar_record).to eq User.find_by(attributes)
223
- end
224
-
225
- it 'Mock' do
226
- expect(UserMock.create(attributes_with_admin)).to eq UserMock.find_by(attributes_with_admin)
227
- end
228
-
229
- end
230
-
231
- describe '::where' do
232
-
233
- let!(:ar_record){User.create(attributes)}
234
- let!(:mock_record){UserMock.create(attributes)}
235
- let!(:mock_record_2){UserMock.create(attributes_with_admin)}
236
-
237
- it 'AR' do
238
- expect([ar_record]).to eq User.where(attributes)
239
- end
240
-
241
- it 'Mock' do
242
- expect(UserMock.where(attributes)).to eq [mock_record, mock_record_2]
243
- end
244
-
245
- it 'Mock will not take sql string needs to be mocked' do
246
- UserMock.create(attributes_with_admin)
247
- expect{UserMock.where("name = 'Dustin Zeisler'")}.to raise_error
248
- end
249
-
250
- context 'by association not only attribute'do
251
-
252
- def where_by_association(user_class, micropost_class)
253
- user = user_class.create!(email: '1')
254
- micropost = micropost_class.create(user: user)
255
- expect(micropost_class.where(user: user)).to eq [micropost]
256
- end
257
-
258
- it 'User' do
259
- where_by_association(User, Micropost)
260
- end
261
-
262
- it 'UserMock' do
263
- where_by_association(UserMock, MicropostMock)
264
- end
265
-
266
- end
267
-
268
- context 'passing array as value' do
269
-
270
- def array_as_value(user_class)
271
- users = [user_class.create!(email: '1', name: 'Alice'), user_class.create!(email: '2', name: 'Bob')]
272
- expect(user_class.where({name: ["Alice", "Bob"]})).to eq(users)
273
- end
274
-
275
- it 'User' do
276
- array_as_value(User)
277
- end
278
-
279
- it 'UserMock' do
280
- array_as_value(UserMock)
281
- end
282
-
283
- end
284
-
285
- context 'will return all if no options passed' do
286
-
287
- def where_no_options(klass, where_klass)
288
- records = [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
289
- expect(klass.where.class).to eq(where_klass)
290
- end
291
-
292
- it 'User' do
293
- where_no_options(User, ActiveRecord::QueryMethods::WhereChain)
294
- end
295
-
296
- it 'UserMock' do
297
- where_no_options(UserMock, ActiveMock::Queries::WhereNotChain)
298
- end
299
-
300
- end
301
-
302
- context 'multiple wheres' do
303
-
304
- def where_where(klass)
305
- records = [klass.create!(email: '1', name: 'fred', admin: true), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
306
- expect(klass.where(name: 'fred').where(admin: true)).to eq([records[0]])
307
- end
308
-
309
- it 'User' do
310
- where_where(User)
311
- end
312
-
313
- it 'UserMock' do
314
- where_where(UserMock)
315
- end
316
-
317
- end
318
-
319
- end
320
-
321
- describe '::where.not' do
322
-
323
- def where_not(klass)
324
- records = [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
325
- expect(klass.where.not(name: 'fred')).to eq([records[2]])
326
- end
327
-
328
- it 'User' do
329
- where_not(User)
330
- end
331
-
332
- it 'UserMock' do
333
- where_not(UserMock)
334
- end
335
-
336
- end
337
-
338
- describe '::update_all' do
339
-
340
- def klass_update_all(klass)
341
- [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
342
- klass.update_all(name: 'John')
343
- expect(klass.all.map{|a| a.name}).to eq(['John', 'John', 'John'])
344
- end
345
-
346
- it 'User' do
347
- klass_update_all(User)
348
- end
349
-
350
- it 'UserMock' do
351
- klass_update_all(UserMock)
352
- end
353
-
354
- end
355
-
356
- describe 'type coercion' do
357
-
358
- it 'will coerce string to integer' do
359
- expect(Micropost.new(user_id: '1').user_id).to eq 1
360
- expect(MicropostMock.new(user_id: '1').user_id).to eq 1
361
- end
362
-
363
- it 'will coerce string to bool' do
364
- expect(User.new(admin: 'true').admin).to eq true
365
- expect(UserMock.new(admin: 'true').admin).to eq true
366
- end
367
-
368
- it 'will coerce string to decimal' do
369
- expect(User.new(credits: '12345').credits).to eq 12345.0
370
- expect(UserMock.new(credits: '12345').credits).to eq 12345.0
371
- end
372
-
373
- it 'will coerce string to datetime' do
374
- expect(User.new(created_at: '1/1/1990').created_at).to eq 'Mon, 01 Jan 1990 00:00:00 UTC +00:00'
375
- expect(UserMock.new(created_at: '1/1/1990').created_at).to eq 'Mon, 01 Jan 1990 00:00:00 UTC +00:00'
376
- end
377
-
378
- it 'will coerce integer to string' do
379
- expect(User.create(name: 1).reload.name).to eq '1'
380
- expect(UserMock.new(name: 1).name).to eq '1'
381
- end
382
-
383
- end
384
-
385
- describe 'CollectionAssociation' do
386
-
387
- let(:support_array_methods) { [:<<, :take, :push, :clear, :first, :last, :concat, :replace, :distinct, :uniq, :count, :size, :length, :empty?, :any?, :include?] }
388
-
389
- context 'supported array methods' do
390
-
391
- def supported_array_methods(user_class, micropost, collection_klass)
392
- mp1 = micropost.create!(content: 'text')
393
- mp2 = micropost.create!(content: 'text')
394
- user = user_class.create(microposts: [mp1, mp2])
395
- expect(user.microposts.take(1).count).to eq(1)
396
- expect(user.microposts.class).to eq(collection_klass)
397
- expect(user.microposts.methods).to include *support_array_methods
398
- end
399
-
400
- it 'User' do
401
- supported_array_methods(User, Micropost, Micropost::ActiveRecord_Associations_CollectionProxy)
402
- end
403
-
404
- it 'UserMock' do
405
- supported_array_methods(UserMock, MicropostMock, ActiveMock::HasMany)
406
- end
407
-
408
- end
409
-
410
- describe '#find' do
411
-
412
- context 'single id passed' do
413
-
414
- def collection_find(user_class, micropost, collection_klass)
415
- microposts = [micropost.create, micropost.create]
416
- user = user_class.create!(email: '1', name: 'fred', microposts: microposts)
417
- expect(user.microposts.find(microposts.first.id)).to eq microposts.first
418
- end
419
-
420
- it 'User' do
421
- collection_find(User, Micropost, Micropost::ActiveRecord_Associations_CollectionProxy)
422
- end
423
-
424
- it 'UserMock' do
425
- collection_find(UserMock, MicropostMock, ActiveMock::Association)
426
- end
427
-
428
- end
429
-
430
- context 'multiple ids passed' do
431
-
432
- def collection_finds(user_class, micropost, collection_klass)
433
- microposts = [micropost.create(id: 1), micropost.create(id: 2)]
434
- user = user_class.create!(email: '1', name: 'fred', microposts: microposts)
435
- expect(user.microposts.find([microposts.first.id, microposts.last.id])).to include *microposts.first, microposts.last
436
- end
437
-
438
- it 'User' do
439
- collection_finds(User, Micropost, Micropost::ActiveRecord_Associations_CollectionProxy)
440
- end
441
-
442
- it 'UserMock' do
443
- collection_finds(UserMock, MicropostMock, ActiveMock::Association)
444
- end
445
-
446
- end
447
-
448
- end
449
-
450
- describe '#sum' do
451
-
452
- def collection_association_sum(user_class, micropost)
453
- mpm1 = micropost.create!(up_votes: 5)
454
- mpm2 = micropost.create!(up_votes: 5)
455
- user_mock = user_class.create!(microposts: [mpm1, mpm2])
456
- expect(user_mock.microposts.sum(:up_votes)).to eq 10
457
- end
458
-
459
- it 'User' do
460
- collection_association_sum(User, Micropost)
461
- end
462
-
463
- it 'UserMock' do
464
- collection_association_sum(UserMock, MicropostMock)
465
- end
466
-
467
- end
468
-
469
- context 'can delete unsaved object from collection' do
470
-
471
- def delete_object(klasses)
472
- mp1 = klasses.first.create!(content: 'text')
473
- mp2 = klasses.first.create!(content: 'text')
474
- user = klasses.last.new(microposts: [mp1, mp2])
475
- user.microposts.delete(mp1)
476
- expect(user.microposts).to eq [mp2]
477
- end
478
-
479
- it 'UserMock' do
480
- delete_object([MicropostMock, UserMock])
481
- end
482
-
483
- it 'User' do
484
- delete_object([Micropost, User])
485
- end
486
-
487
- end
488
-
489
- end
490
-
491
- describe 'Collections'do
492
-
493
- context 'delete_all' do
494
-
495
- context 'deletes all records from result' do
496
-
497
- def collections_delete_all(klass)
498
- [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
499
- klass.where(name: 'fred').delete_all
500
- expect(klass.count).to eq 1
501
- end
502
-
503
- it 'User' do
504
- collections_delete_all(User)
505
- end
506
-
507
- it 'UserMock' do
508
- collections_delete_all(UserMock)
509
- end
510
-
511
- end
512
-
513
- context 'deletes all records association' do
514
-
515
- def association_collections_delete_all(user_class, micropost)
516
- user = user_class.create!(email: '1', name: 'fred', microposts: [micropost.create, micropost.create])
517
- user.microposts.delete_all
518
- expect(user_class.count).to eq 1
519
- end
520
-
521
- it 'User' do
522
- association_collections_delete_all(User, Micropost)
523
- end
524
-
525
- it 'UserMock' do
526
- association_collections_delete_all(UserMock, MicropostMock)
527
- end
528
-
529
- end
530
-
531
- end
532
-
533
- context 'where' do
534
-
535
- context 'all.where' do
536
-
537
- def collections_all_where(klass)
538
- records = [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
539
- expect(klass.all.where(name: 'fred')).to eq([records[0], records[1]])
540
- end
541
-
542
- it 'User' do
543
- collections_all_where(User)
544
- end
545
-
546
- it 'UserMock' do
547
- collections_all_where(UserMock)
548
- end
549
-
550
- end
551
-
552
- end
553
-
554
- context 'order' do
555
-
556
- context 'where.order' do
557
-
558
- def collections_where_order(klass)
559
- records = [klass.create!(email: '2', name: 'fred'), klass.create!(email: '1', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
560
- expect(klass.where(name: 'fred').order(:email)).to eq([records[1], records[0]])
561
- end
562
-
563
- it 'User' do
564
- collections_where_order(User)
565
- end
566
-
567
- it 'UserMock' do
568
- collections_where_order(UserMock)
569
- end
570
-
571
- end
572
-
573
- context 'where.order.reverse_order' do
574
-
575
- def collections_where_order_reverse_order(klass)
576
- records = [klass.create!(email: '2', name: 'fred'), klass.create!(email: '1', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
577
- expect(klass.where(name: 'fred').order(:email).reverse_order).to eq([records[0], records[1]])
578
- end
579
-
580
- it 'User' do
581
- collections_where_order_reverse_order(User)
582
- end
583
-
584
- it 'UserMock' do
585
- collections_where_order_reverse_order(UserMock)
586
- end
587
-
588
- end
589
-
590
- end
591
-
592
- context 'update_all' do
593
-
594
- context 'where.update_all' do
595
-
596
- def collection_where_update_all(klass)
597
- [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
598
- klass.where(name: 'fred' ).update_all(name: 'John')
599
- expect(klass.all.map { |a| a.name }).to eq(['John', 'John', 'Sam'])
600
- end
601
-
602
- it 'User' do
603
- collection_where_update_all(User)
604
- end
605
-
606
- it 'UserMock' do
607
- collection_where_update_all(UserMock)
608
- end
609
-
610
- end
611
-
612
- context 'all.update_all' do
613
-
614
- def collection_all_update_all(klass)
615
- [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'fred'), klass.create!(email: '3', name: 'Sam')]
616
- klass.all.update_all(name: 'John')
617
- expect(klass.all.map { |a| a.name }).to eq(['John', 'John', 'John'])
618
- end
619
-
620
- it 'User' do
621
- collection_all_update_all(User)
622
- end
623
-
624
- it 'UserMock' do
625
- collection_all_update_all(UserMock)
626
- end
627
-
628
- end
629
-
630
- end
631
-
632
- end
633
-
634
- describe 'default values' do
635
-
636
- context 'default value of empty string' do
637
-
638
- it "User" do
639
- user = User.new
640
- expect(user.email).to eq ""
641
- end
642
-
643
- it "UserMock" do
644
- user = UserMock.new
645
- expect(user.email).to eq ""
646
- end
647
-
648
- end
649
-
650
- context 'default value of false' do
651
-
652
- it "User" do
653
- user = User.new
654
- expect(user.admin).to eq false
655
- expect(user.remember_token).to eq true
656
- end
657
-
658
- it "UserMock" do
659
- user = UserMock.new
660
- expect(user.admin).to eq false
661
- expect(user.remember_token).to eq true
662
- end
663
-
664
- end
665
-
666
- context 'values can be passed' do
667
-
668
- it "User" do
669
- user = User.new(admin: true, remember_token: false)
670
- expect(user.admin).to eq true
671
- expect(user.remember_token).to eq false
672
- end
673
-
674
- it "UserMock" do
675
- user = UserMock.new(admin: true, remember_token: false)
676
- expect(user.admin).to eq true
677
- expect(user.remember_token).to eq false
678
- end
679
-
680
- end
681
-
682
- end
683
-
684
- describe 'delete' do
685
-
686
- context 'delete a single record when only one exists' do
687
-
688
- it "User" do
689
- user = User.create
690
- user.delete
691
- expect(User.count).to eq 0
692
- end
693
-
694
- it "UserMock" do
695
- user = UserMock.create
696
- user.delete
697
- expect(UserMock.count).to eq 0
698
- end
699
-
700
- end
701
-
702
- context 'deletes the last record when more than one exists' do
703
-
704
- it "User" do
705
- User.create(email: '1')
706
- User.create(email: '2')
707
- user = User.create(email: '3')
708
- user.delete
709
- expect(User.count).to eq 2
710
- User.create(email: '3')
711
- expect(User.count).to eq 3
712
-
713
- end
714
-
715
- it "UserMock" do
716
- UserMock.create(email: '1')
717
- UserMock.create(email: '2')
718
- user = UserMock.create(email: '3')
719
- user.delete
720
- expect(UserMock.count).to eq 2
721
- UserMock.create(email: '3')
722
- expect(UserMock.count).to eq 3
723
-
724
- end
725
-
726
- end
727
-
728
- context 'deletes the middle record when more than one exists' do
729
-
730
- it "User" do
731
- User.create(email: '0')
732
- user2 =User.create(email: '1')
733
- user1 = User.create(email: '2')
734
- User.create(email: '3')
735
- user1.delete
736
- user2.delete
737
- expect(User.count).to eq 2
738
- User.create(email: '2')
739
- User.create(email: '4')
740
- expect(User.count).to eq 4
741
- end
742
-
743
- it "UserMock" do
744
- UserMock.create(email: '0')
745
- user2 =UserMock.create(email: '1')
746
- user1 = UserMock.create(email: '2')
747
- UserMock.create(email: '3')
748
- user1.delete
749
- user2.delete
750
- expect(UserMock.count).to eq 2
751
- UserMock.create(email: '2')
752
- UserMock.create(email: '4')
753
- expect(UserMock.count).to eq 4
754
- end
755
-
756
- end
757
-
758
- end
759
-
760
- describe '::destroy(id)' do
761
-
762
- context 'delete a single record when only one exists' do
763
-
764
- it "User" do
765
- user = User.create
766
- User.destroy(user.id)
767
- expect(User.count).to eq 0
768
- end
769
-
770
- it "UserMock" do
771
- user = UserMock.create
772
- UserMock.destroy(user.id)
773
- expect(UserMock.count).to eq 0
774
- end
775
-
776
- end
777
-
778
- end
779
-
780
- describe '::delete_all(conditions = nil)' do
781
-
782
- it "User" do
783
- user = User.create
784
- expect(User.delete_all(id: user.id)).to eq 1
785
- expect(User.count).to eq 0
786
- end
787
-
788
- it "UserMock" do
789
- user = UserMock.create
790
- expect(UserMock.delete_all(id: user.id)).to eq 1
791
- expect(UserMock.count).to eq 0
792
- end
793
-
794
- end
795
-
796
- describe '::limit' do
797
-
798
- def klass_limit(klass)
799
- records = [klass.create!(email: '1', name: 'fred'), klass.create!(email: '2', name: 'Dan'), klass.create!(email: '3', name: 'Sam')]
800
- expect(klass.limit(2)).to eq [records[0], records[1]]
801
- expect(klass.limit(2).where(name: 'fred')).to eq [records[0]]
802
- end
803
-
804
- it 'User' do
805
- klass_limit(User)
806
- end
807
-
808
- it 'UserMock' do
809
- klass_limit(UserMock)
810
- end
811
-
812
- end
813
-
814
- describe '::find_by!' do
815
-
816
- context 'will raise exception if not found' do
817
-
818
- def find_by_exception(user_class, error)
819
- expect{user_class.find_by!(name: 'Matz')}.to raise_error(error)
820
- end
821
-
822
- it 'User' do
823
- find_by_exception(User, ActiveRecord::RecordNotFound)
824
- end
825
-
826
- it 'UserMock' do
827
- find_by_exception(UserMock, ActiveMock::RecordNotFound)
828
- end
829
-
830
- end
831
-
832
- context 'will find one record by conditions' do
833
-
834
- def find_by_one_result(user_class)
835
- user = user_class.create!(email: '1', name: 'fred')
836
- expect(user_class.find_by!(name: 'fred') ).to eq user
837
- end
838
-
839
- it 'User' do
840
- find_by_one_result(User)
841
- end
842
-
843
- it 'UserMock' do
844
- find_by_one_result(UserMock)
845
- end
846
-
847
- end
848
-
849
- end
850
-
851
- describe '::transaction' do
852
-
853
- context 'will run code in block' do
854
-
855
- def transaction(user_class)
856
- user_class.transaction do
857
- user_class.create(email: '1')
858
- user_class.create(email: '2')
859
- end
860
-
861
- expect(user_class.count).to eq 2
862
- end
863
-
864
- it 'User' do
865
- transaction(User)
866
- end
867
-
868
- it 'UserMock' do
869
- transaction(UserMock)
870
- end
871
-
872
- end
873
-
874
- end
875
-
876
- describe 'belongs_to association' do
877
-
878
- describe 'when setting association by object it will set id if object is persisted' do
879
-
880
- def id_set_by_object(post_class, user_class)
881
- user = user_class.create
882
- post = post_class.create(user: user)
883
- expect(post.user_id).to eq user.id
884
- end
885
-
886
- it 'User' do
887
- id_set_by_object(Micropost, User)
888
- end
889
-
890
- it 'UserMock' do
891
- id_set_by_object(MicropostMock, UserMock)
892
- end
893
-
894
- end
895
-
896
- describe 'when setting association by object it will set the child association', pending:true do
897
-
898
- def set_by_object(post_class, user_class)
899
- user = user_class.create
900
- post = post_class.create(user: user)
901
- expect(user.microposts).to eq [post]
902
- end
903
-
904
- it 'User' do
905
- set_by_object(Micropost, User)
906
- end
907
-
908
- it 'UserMock' do
909
- set_by_object(MicropostMock, UserMock)
910
- end
911
-
912
- end
913
-
914
- describe 'when setting association by id it will set the object on the parent' do
915
-
916
- def object_set_by_id(post_class, user_class)
917
- user = user_class.create
918
- post = post_class.create(user_id: user.id)
919
- expect(post.user).to eq user
920
- end
921
-
922
- it 'User' do
923
- object_set_by_id(Micropost, User)
924
- end
925
-
926
- it 'UserMock' do
927
- object_set_by_id(MicropostMock, UserMock)
928
- end
929
-
930
- end
931
-
932
- describe 'when setting association by object it will not set id if object is not persisted' do
933
-
934
- def id_set_by_object(post_class, user_class)
935
- user = user_class.new
936
- post = post_class.new(user: user)
937
- expect(post.user_id).to eq nil
938
- end
939
-
940
- it 'User' do
941
- id_set_by_object(Micropost, User)
942
- end
943
-
944
- it 'UserMock' do
945
- id_set_by_object(MicropostMock, UserMock)
946
- end
947
-
948
- end
949
-
950
- describe 'can build' do
951
-
952
- def build_belong_to(post_class, user_class)
953
- post = post_class.new
954
- user = post.build_user
955
- expect(user.class).to eq user_class
956
- expect(post.user).to eq user
957
- end
958
-
959
- it 'User' do
960
- build_belong_to(Micropost, User)
961
- end
962
-
963
- it 'UserMock' do
964
- build_belong_to(MicropostMock, UserMock)
965
- end
966
-
967
- end
968
-
969
- end
970
-
971
- describe 'has_many association' do
972
-
973
- describe 'when passing in collection all item in collection will set its foreign key to the parent', pending: true do
974
-
975
- def id_set_to_children(user_class, post_class)
976
- posts = [post_class.create, post_class.create, post_class.create]
977
- user = user_class.create(microposts: posts)
978
- expect(user.microposts.map(&:user_id)).to eq posts.map(&:user_id)
979
- expect(posts.map(&:user_id)).to eq [user.id, user.id, user.id]
980
- end
981
-
982
- it 'User' do
983
- id_set_to_children(User, Micropost)
984
- end
985
-
986
- it 'UserMock' do
987
- id_set_to_children(UserMock, MicropostMock)
988
- end
989
-
990
- end
991
-
992
- end
993
-
994
- describe 'can build new object from collection' do
995
-
996
- def new_record_on_collection(user_class, post_class)
997
- user = user_class.create
998
- new_post = user.microposts.build
999
- expect(new_post.class).to eq(post_class)
1000
- expect(new_post.attributes).to eq({"id" => nil, "content" => nil, "user_id" => 1, "up_votes" => nil, "created_at" => nil, "updated_at" => nil})
1001
- expect(user.microposts.count).to eq 0
1002
- new_post.save
1003
- expect(user.microposts.count).to eq(1)
1004
- expect(user.microposts.first).to eq(new_post)
1005
- end
1006
-
1007
- it 'User' do
1008
- new_record_on_collection(User, Micropost)
1009
- end
1010
-
1011
- it 'UserMock' do
1012
- new_record_on_collection(UserMock, MicropostMock)
1013
- end
1014
-
1015
- end
1016
-
1017
- describe 'can create new object from collection' do
1018
-
1019
- def create_record_on_collection(user_class, post_class)
1020
- user = user_class.create
1021
- new_post = user.microposts.create
1022
- expect(new_post.class).to eq(post_class)
1023
- expect(new_post.user_id).to eq(1)
1024
- expect(user.microposts.count).to eq 1
1025
- expect(user.microposts.first).to eq(new_post)
1026
- end
1027
-
1028
- it 'User' do
1029
- create_record_on_collection(User, Micropost)
1030
- end
1031
-
1032
- it 'UserMock' do
1033
- create_record_on_collection(UserMock, MicropostMock)
1034
- end
1035
-
1036
- end
1037
-
1038
- end