socialcast_shoulda_ext 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +13 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.rdoc +126 -0
  5. data/Rakefile +12 -0
  6. data/lib/shoulda_ext.rb +7 -0
  7. data/lib/shoulda_ext/assertions.rb +14 -0
  8. data/lib/shoulda_ext/integrations/test_unit.rb +13 -0
  9. data/lib/shoulda_ext/matchers.rb +9 -0
  10. data/lib/shoulda_ext/matchers/record_count_change.rb +127 -0
  11. data/lib/shoulda_ext/matchers/respond_with_json.rb +99 -0
  12. data/lib/shoulda_ext/matchers/trigger_callback.rb +131 -0
  13. data/lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb +32 -0
  14. data/lib/shoulda_ext/version.rb +4 -0
  15. data/socialcast_shoulda_ext.gemspec +22 -0
  16. data/test/helper.rb +30 -0
  17. data/test/rails3_root/.gitignore +4 -0
  18. data/test/rails3_root/Rakefile +7 -0
  19. data/test/rails3_root/app/controllers/application_controller.rb +3 -0
  20. data/test/rails3_root/app/controllers/blogs_controller.rb +11 -0
  21. data/test/rails3_root/app/controllers/comments_controller.rb +2 -0
  22. data/test/rails3_root/app/helpers/application_helper.rb +2 -0
  23. data/test/rails3_root/app/helpers/blogs_helper.rb +2 -0
  24. data/test/rails3_root/app/helpers/comments_helper.rb +2 -0
  25. data/test/rails3_root/app/models/blog.rb +3 -0
  26. data/test/rails3_root/app/models/comment.rb +3 -0
  27. data/test/rails3_root/app/views/blogs/index.html.erb +6 -0
  28. data/test/rails3_root/app/views/layouts/application.html.erb +14 -0
  29. data/test/rails3_root/config.ru +4 -0
  30. data/test/rails3_root/config/application.rb +17 -0
  31. data/test/rails3_root/config/boot.rb +6 -0
  32. data/test/rails3_root/config/database.yml +22 -0
  33. data/test/rails3_root/config/environment.rb +5 -0
  34. data/test/rails3_root/config/environments/development.rb +26 -0
  35. data/test/rails3_root/config/environments/production.rb +49 -0
  36. data/test/rails3_root/config/environments/test.rb +35 -0
  37. data/test/rails3_root/config/initializers/backtrace_silencers.rb +7 -0
  38. data/test/rails3_root/config/initializers/inflections.rb +10 -0
  39. data/test/rails3_root/config/initializers/mime_types.rb +5 -0
  40. data/test/rails3_root/config/initializers/secret_token.rb +7 -0
  41. data/test/rails3_root/config/initializers/session_store.rb +8 -0
  42. data/test/rails3_root/config/locales/en.yml +5 -0
  43. data/test/rails3_root/config/routes.rb +4 -0
  44. data/test/rails3_root/db/migrate/20110411025326_create_blogs.rb +12 -0
  45. data/test/rails3_root/db/migrate/20110411025332_create_comments.rb +13 -0
  46. data/test/rails3_root/db/seeds.rb +7 -0
  47. data/test/rails3_root/lib/tasks/.gitkeep +0 -0
  48. data/test/rails3_root/public/404.html +26 -0
  49. data/test/rails3_root/public/422.html +26 -0
  50. data/test/rails3_root/public/500.html +26 -0
  51. data/test/rails3_root/public/favicon.ico +0 -0
  52. data/test/rails3_root/public/images/rails.png +0 -0
  53. data/test/rails3_root/public/index.html +239 -0
  54. data/test/rails3_root/public/javascripts/application.js +2 -0
  55. data/test/rails3_root/public/javascripts/controls.js +965 -0
  56. data/test/rails3_root/public/javascripts/dragdrop.js +974 -0
  57. data/test/rails3_root/public/javascripts/effects.js +1123 -0
  58. data/test/rails3_root/public/javascripts/prototype.js +6001 -0
  59. data/test/rails3_root/public/javascripts/rails.js +191 -0
  60. data/test/rails3_root/public/robots.txt +5 -0
  61. data/test/rails3_root/public/stylesheets/.gitkeep +0 -0
  62. data/test/rails3_root/script/rails +6 -0
  63. data/test/rails3_root/test/fixtures/blogs.yml +5 -0
  64. data/test/rails3_root/test/fixtures/comments.yml +0 -0
  65. data/test/rails3_root/test/functional/blogs_controller_test.rb +8 -0
  66. data/test/rails3_root/test/functional/comments_controller_test.rb +8 -0
  67. data/test/rails3_root/test/shoulda_ext.sqlite3 +0 -0
  68. data/test/rails3_root/test/test_helper.rb +13 -0
  69. data/test/rails3_root/test/unit/blog_test.rb +8 -0
  70. data/test/rails3_root/test/unit/comment_test.rb +8 -0
  71. data/test/rails3_root/test/unit/helpers/blogs_helper_test.rb +4 -0
  72. data/test/rails3_root/test/unit/helpers/comments_helper_test.rb +4 -0
  73. data/test/rails3_root/vendor/plugins/.gitkeep +0 -0
  74. data/test/test_assertions.rb +14 -0
  75. data/test/test_record_count_change_matcher.rb +150 -0
  76. data/test/test_respond_with_json.rb +42 -0
  77. data/test/test_trigger_callback_matcher.rb +38 -0
  78. metadata +362 -0
@@ -0,0 +1,42 @@
1
+
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
+
4
+ class TestRespondWithJson < ActionController::TestCase
5
+ context "blogs controller" do
6
+ setup do
7
+ @controller = BlogsController.new
8
+ @request = ActionController::TestRequest.new
9
+ @response = ActionController::TestResponse.new
10
+ end
11
+
12
+ context ":index.json and block test" do
13
+ setup do
14
+ get :index, :format => 'json'
15
+ @expected_title = 'blog post 1'
16
+ end
17
+ should respond_with_json { |json| json.first['blog']['title'] == @expected_title}
18
+ end
19
+
20
+ context ":index.json and exact match" do
21
+ setup do
22
+ get :index, :format => 'json'
23
+ end
24
+ should respond_with_json.exactly(['blog' => {'id' => 1, 'title' => 'blog post 1', 'created_at' => '2011-04-11T07:16:33Z', 'updated_at' => '2011-04-11T07:16:33Z'}])
25
+ end
26
+
27
+ context ":index.json and exact block match" do
28
+ setup do
29
+ get :index, :format => 'json'
30
+ end
31
+ should respond_with_json.exactly{ |json| JSON.parse(Blog.all.to_json)}
32
+ end
33
+
34
+ context ":index and should_not response_with_json" do
35
+ setup do
36
+ get :index
37
+ end
38
+ should_not respond_with_json
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
+
4
+ class TestTriggerCallbackMatcher < Test::Unit::TestCase
5
+
6
+ context "doing nothing to a record" do
7
+ subject { Blog.new :title => 'blog title' }
8
+ should_not trigger_callbacks
9
+ end
10
+
11
+ context "creating a record" do
12
+ subject { Blog.create! :title => 'blog title' }
13
+ should trigger_callbacks.for :create
14
+ should_not trigger_callbacks.for :update, :destroy
15
+ end
16
+
17
+ context "updating a record" do
18
+ subject do
19
+ Blog.create!( :title => 'blog title').tap do |b|
20
+ b.reset_callback_flags!
21
+ b.update_attribute :title, 'new blog title'
22
+ end
23
+ end
24
+ should trigger_callbacks.for :update
25
+ should_not trigger_callbacks.for :create, :destroy
26
+ end
27
+
28
+ context "destroying a record" do
29
+ subject do
30
+ Blog.create!( :title => 'blog title').tap do |b|
31
+ b.reset_callback_flags!
32
+ b.destroy
33
+ end
34
+ end
35
+ should trigger_callbacks.for :destroy
36
+ should_not trigger_callbacks.for :create, :update
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,362 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socialcast_shoulda_ext
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Geoffrey Hichborn
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-06 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activerecord
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
33
+ version: 3.0.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 33
45
+ segments:
46
+ - 2
47
+ - 11
48
+ - 1
49
+ version: 2.11.1
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: |
53
+
54
+ = Socialcast Shoulda Extensions
55
+ Adds new matchers and functionality to the shoulda test library
56
+
57
+ = Installation
58
+
59
+ In your Gemfile:
60
+
61
+ group :test do
62
+ gem 'socialcast_shoulda_ext', :git => 'git@github.com:socialcast/socialcast-shoulda-ext.git', :require => 'shoulda_ext'
63
+ end
64
+
65
+ If you want to include the trigger_callbacks matcher, also add the following to your test helper:
66
+
67
+ ShouldaExt::Matchers::TriggerCallbackMatcher.attach_active_record_callback_hooks!
68
+
69
+ = Matchers
70
+
71
+ == RecordCountChangeMatcher
72
+ Test if the count for a model has changed, and by how much. Requires the context_with_matcher_before_hooks patch, which is included by default.
73
+
74
+ Provides the following matcher methods:
75
+
76
+ - create_record(klass_or_symbol)
77
+ Alias for change_record_count.for(klass_or_symbol).by(1)
78
+
79
+ - create_records(klass_or_symbol, amount)
80
+ Alias for change_record_count.for(klass_or_symbol).by(amount)
81
+
82
+ - destroy_record(klass_or_symbol)
83
+ Alias for change_record_count.for(klass_or_symbol).by(-1)
84
+
85
+ - destroy_records(klass_or_symbol, amount)
86
+ Alias for change_record_count.for(klass_or_symbol).by(-amount)
87
+
88
+ - change_record_count
89
+ Tests the difference in record count before and after the current setup/subject block
90
+ Can be used with the follow methods:
91
+ - for(klass_or_symbol)
92
+ Provides the class which the test is being performed on. Can be a constant or a symbol
93
+
94
+ - by(amount)
95
+ Provides an expected difference for the number of records for the specified class.
96
+ Excluding this number will allow the matcher to check for any difference
97
+
98
+ Examples:
99
+
100
+ context "creating a blog article" do
101
+
102
+ context "with good parameters" do
103
+ setup do
104
+ post :create, :blog => {:title => 'my blog post', :body => 'Ipsum lorem...'}
105
+ end
106
+ should create_record :blog
107
+ end
108
+
109
+ context "without a body" do
110
+ setup do
111
+ post :create, :blog => {:title => 'my blog post' }
112
+ end
113
+ should_not create_record Blog
114
+ end
115
+
116
+ end
117
+
118
+ == RespondWithJson
119
+ Check if the controller's response is json
120
+
121
+ Examples:
122
+
123
+ context ":index.json" do
124
+ setup do
125
+ get :index, :format => 'json'
126
+ end
127
+ # Just check to see that the response was json
128
+ should respond_with_json
129
+
130
+ # Evaluate the hash produced by the json yourself
131
+ should respond_with_json { |json| json.first['blog']['title'] == 'blog post 1'}
132
+
133
+ # Provide an exact match
134
+ should respond_with_json.exactly(['blog' => {'id' => 1, 'title' => 'blog post 1'}])
135
+
136
+ # Provide an exact match with a block
137
+ should response_with_json.exactly{ |json| JSON.parse(Blog.all.to_json)}
138
+ end
139
+
140
+ context ":index.html" do
141
+ setup do
142
+ get :index
143
+ end
144
+
145
+ # or the negation
146
+ should_not respond_with_json
147
+ end
148
+
149
+ == TriggerCallbackMatcher
150
+
151
+ Test if create, update, destroy, or save callbacks were triggered.
152
+
153
+ Requires running
154
+ ShouldaExt::Matchers::TriggerCallbackMatcher.attach_active_record_callback_hooks!
155
+ in your test suite in order to work properly.
156
+
157
+ Examples:
158
+
159
+ context "doing nothing to a record" do
160
+ subject { Blog.new :title => 'blog title' }
161
+ should_not trigger_callbacks
162
+ end
163
+
164
+ context "creating a record" do
165
+ subject { Blog.create! :title => 'blog title' }
166
+ should trigger_callbacks.for :create
167
+ should_not trigger_callbacks.for :update, :destroy
168
+ end
169
+
170
+ = Integrations
171
+
172
+ Currently only integrates with test/unit. RSpec support to come.
173
+
174
+ = Shoulda Extensions
175
+
176
+ == ContextWithMatcherBeforeHooks
177
+
178
+ Adds the ability to define a 'before' method on any method which will be run before each context's setup/subject block. Used by RecordCountChangeMatcher to record the number of records before the tested operation takes place.
179
+
180
+ email:
181
+ - geoff@socialcast.com
182
+ executables: []
183
+
184
+ extensions: []
185
+
186
+ extra_rdoc_files: []
187
+
188
+ files:
189
+ - .gitignore
190
+ - Gemfile
191
+ - Gemfile.lock
192
+ - MIT-LICENSE
193
+ - README.rdoc
194
+ - Rakefile
195
+ - lib/shoulda_ext.rb
196
+ - lib/shoulda_ext/assertions.rb
197
+ - lib/shoulda_ext/integrations/test_unit.rb
198
+ - lib/shoulda_ext/matchers.rb
199
+ - lib/shoulda_ext/matchers/record_count_change.rb
200
+ - lib/shoulda_ext/matchers/respond_with_json.rb
201
+ - lib/shoulda_ext/matchers/trigger_callback.rb
202
+ - lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb
203
+ - lib/shoulda_ext/version.rb
204
+ - socialcast_shoulda_ext.gemspec
205
+ - test/helper.rb
206
+ - test/rails3_root/.gitignore
207
+ - test/rails3_root/Rakefile
208
+ - test/rails3_root/app/controllers/application_controller.rb
209
+ - test/rails3_root/app/controllers/blogs_controller.rb
210
+ - test/rails3_root/app/controllers/comments_controller.rb
211
+ - test/rails3_root/app/helpers/application_helper.rb
212
+ - test/rails3_root/app/helpers/blogs_helper.rb
213
+ - test/rails3_root/app/helpers/comments_helper.rb
214
+ - test/rails3_root/app/models/blog.rb
215
+ - test/rails3_root/app/models/comment.rb
216
+ - test/rails3_root/app/views/blogs/index.html.erb
217
+ - test/rails3_root/app/views/layouts/application.html.erb
218
+ - test/rails3_root/config.ru
219
+ - test/rails3_root/config/application.rb
220
+ - test/rails3_root/config/boot.rb
221
+ - test/rails3_root/config/database.yml
222
+ - test/rails3_root/config/environment.rb
223
+ - test/rails3_root/config/environments/development.rb
224
+ - test/rails3_root/config/environments/production.rb
225
+ - test/rails3_root/config/environments/test.rb
226
+ - test/rails3_root/config/initializers/backtrace_silencers.rb
227
+ - test/rails3_root/config/initializers/inflections.rb
228
+ - test/rails3_root/config/initializers/mime_types.rb
229
+ - test/rails3_root/config/initializers/secret_token.rb
230
+ - test/rails3_root/config/initializers/session_store.rb
231
+ - test/rails3_root/config/locales/en.yml
232
+ - test/rails3_root/config/routes.rb
233
+ - test/rails3_root/db/migrate/20110411025326_create_blogs.rb
234
+ - test/rails3_root/db/migrate/20110411025332_create_comments.rb
235
+ - test/rails3_root/db/seeds.rb
236
+ - test/rails3_root/lib/tasks/.gitkeep
237
+ - test/rails3_root/public/404.html
238
+ - test/rails3_root/public/422.html
239
+ - test/rails3_root/public/500.html
240
+ - test/rails3_root/public/favicon.ico
241
+ - test/rails3_root/public/images/rails.png
242
+ - test/rails3_root/public/index.html
243
+ - test/rails3_root/public/javascripts/application.js
244
+ - test/rails3_root/public/javascripts/controls.js
245
+ - test/rails3_root/public/javascripts/dragdrop.js
246
+ - test/rails3_root/public/javascripts/effects.js
247
+ - test/rails3_root/public/javascripts/prototype.js
248
+ - test/rails3_root/public/javascripts/rails.js
249
+ - test/rails3_root/public/robots.txt
250
+ - test/rails3_root/public/stylesheets/.gitkeep
251
+ - test/rails3_root/script/rails
252
+ - test/rails3_root/test/fixtures/blogs.yml
253
+ - test/rails3_root/test/fixtures/comments.yml
254
+ - test/rails3_root/test/functional/blogs_controller_test.rb
255
+ - test/rails3_root/test/functional/comments_controller_test.rb
256
+ - test/rails3_root/test/shoulda_ext.sqlite3
257
+ - test/rails3_root/test/test_helper.rb
258
+ - test/rails3_root/test/unit/blog_test.rb
259
+ - test/rails3_root/test/unit/comment_test.rb
260
+ - test/rails3_root/test/unit/helpers/blogs_helper_test.rb
261
+ - test/rails3_root/test/unit/helpers/comments_helper_test.rb
262
+ - test/rails3_root/vendor/plugins/.gitkeep
263
+ - test/test_assertions.rb
264
+ - test/test_record_count_change_matcher.rb
265
+ - test/test_respond_with_json.rb
266
+ - test/test_trigger_callback_matcher.rb
267
+ homepage: http://github.com/socialcast/socialcast-shoulda-ext
268
+ licenses: []
269
+
270
+ post_install_message:
271
+ rdoc_options: []
272
+
273
+ require_paths:
274
+ - lib
275
+ required_ruby_version: !ruby/object:Gem::Requirement
276
+ none: false
277
+ requirements:
278
+ - - ">="
279
+ - !ruby/object:Gem::Version
280
+ hash: 3
281
+ segments:
282
+ - 0
283
+ version: "0"
284
+ required_rubygems_version: !ruby/object:Gem::Requirement
285
+ none: false
286
+ requirements:
287
+ - - ">="
288
+ - !ruby/object:Gem::Version
289
+ hash: 3
290
+ segments:
291
+ - 0
292
+ version: "0"
293
+ requirements: []
294
+
295
+ rubyforge_project:
296
+ rubygems_version: 1.8.10
297
+ signing_key:
298
+ specification_version: 3
299
+ summary: adds new shoulda matchers and assertions
300
+ test_files:
301
+ - test/helper.rb
302
+ - test/rails3_root/.gitignore
303
+ - test/rails3_root/Rakefile
304
+ - test/rails3_root/app/controllers/application_controller.rb
305
+ - test/rails3_root/app/controllers/blogs_controller.rb
306
+ - test/rails3_root/app/controllers/comments_controller.rb
307
+ - test/rails3_root/app/helpers/application_helper.rb
308
+ - test/rails3_root/app/helpers/blogs_helper.rb
309
+ - test/rails3_root/app/helpers/comments_helper.rb
310
+ - test/rails3_root/app/models/blog.rb
311
+ - test/rails3_root/app/models/comment.rb
312
+ - test/rails3_root/app/views/blogs/index.html.erb
313
+ - test/rails3_root/app/views/layouts/application.html.erb
314
+ - test/rails3_root/config.ru
315
+ - test/rails3_root/config/application.rb
316
+ - test/rails3_root/config/boot.rb
317
+ - test/rails3_root/config/database.yml
318
+ - test/rails3_root/config/environment.rb
319
+ - test/rails3_root/config/environments/development.rb
320
+ - test/rails3_root/config/environments/production.rb
321
+ - test/rails3_root/config/environments/test.rb
322
+ - test/rails3_root/config/initializers/backtrace_silencers.rb
323
+ - test/rails3_root/config/initializers/inflections.rb
324
+ - test/rails3_root/config/initializers/mime_types.rb
325
+ - test/rails3_root/config/initializers/secret_token.rb
326
+ - test/rails3_root/config/initializers/session_store.rb
327
+ - test/rails3_root/config/locales/en.yml
328
+ - test/rails3_root/config/routes.rb
329
+ - test/rails3_root/db/migrate/20110411025326_create_blogs.rb
330
+ - test/rails3_root/db/migrate/20110411025332_create_comments.rb
331
+ - test/rails3_root/db/seeds.rb
332
+ - test/rails3_root/lib/tasks/.gitkeep
333
+ - test/rails3_root/public/404.html
334
+ - test/rails3_root/public/422.html
335
+ - test/rails3_root/public/500.html
336
+ - test/rails3_root/public/favicon.ico
337
+ - test/rails3_root/public/images/rails.png
338
+ - test/rails3_root/public/index.html
339
+ - test/rails3_root/public/javascripts/application.js
340
+ - test/rails3_root/public/javascripts/controls.js
341
+ - test/rails3_root/public/javascripts/dragdrop.js
342
+ - test/rails3_root/public/javascripts/effects.js
343
+ - test/rails3_root/public/javascripts/prototype.js
344
+ - test/rails3_root/public/javascripts/rails.js
345
+ - test/rails3_root/public/robots.txt
346
+ - test/rails3_root/public/stylesheets/.gitkeep
347
+ - test/rails3_root/script/rails
348
+ - test/rails3_root/test/fixtures/blogs.yml
349
+ - test/rails3_root/test/fixtures/comments.yml
350
+ - test/rails3_root/test/functional/blogs_controller_test.rb
351
+ - test/rails3_root/test/functional/comments_controller_test.rb
352
+ - test/rails3_root/test/shoulda_ext.sqlite3
353
+ - test/rails3_root/test/test_helper.rb
354
+ - test/rails3_root/test/unit/blog_test.rb
355
+ - test/rails3_root/test/unit/comment_test.rb
356
+ - test/rails3_root/test/unit/helpers/blogs_helper_test.rb
357
+ - test/rails3_root/test/unit/helpers/comments_helper_test.rb
358
+ - test/rails3_root/vendor/plugins/.gitkeep
359
+ - test/test_assertions.rb
360
+ - test/test_record_count_change_matcher.rb
361
+ - test/test_respond_with_json.rb
362
+ - test/test_trigger_callback_matcher.rb