nimboids-shoulda 2.11.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTION_GUIDELINES.rdoc +10 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +154 -0
- data/Rakefile +74 -0
- data/bin/convert_to_should_syntax +42 -0
- data/lib/shoulda/action_controller/macros.rb +221 -0
- data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +114 -0
- data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +74 -0
- data/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb +62 -0
- data/lib/shoulda/action_controller/matchers/render_template_matcher.rb +54 -0
- data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +99 -0
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +74 -0
- data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +85 -0
- data/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +98 -0
- data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +100 -0
- data/lib/shoulda/action_controller/matchers.rb +39 -0
- data/lib/shoulda/action_controller.rb +34 -0
- data/lib/shoulda/action_mailer/assertions.rb +42 -0
- data/lib/shoulda/action_mailer/matchers/have_sent_email.rb +110 -0
- data/lib/shoulda/action_mailer/matchers.rb +22 -0
- data/lib/shoulda/action_mailer.rb +13 -0
- data/lib/shoulda/active_record/assertions.rb +69 -0
- data/lib/shoulda/active_record/helpers.rb +32 -0
- data/lib/shoulda/active_record/macros.rb +457 -0
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +110 -0
- data/lib/shoulda/active_record/matchers/association_matcher.rb +275 -0
- data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
- data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
- data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
- data/lib/shoulda/active_record/matchers/have_db_index_matcher.rb +112 -0
- data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
- data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
- data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +65 -0
- data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
- data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
- data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
- data/lib/shoulda/active_record/matchers.rb +42 -0
- data/lib/shoulda/active_record.rb +16 -0
- data/lib/shoulda/assertions.rb +79 -0
- data/lib/shoulda/autoload_macros.rb +46 -0
- data/lib/shoulda/context.rb +441 -0
- data/lib/shoulda/helpers.rb +8 -0
- data/lib/shoulda/integrations/rspec.rb +13 -0
- data/lib/shoulda/integrations/rspec2.rb +22 -0
- data/lib/shoulda/integrations/test_unit.rb +22 -0
- data/lib/shoulda/macros.rb +161 -0
- data/lib/shoulda/private_helpers.rb +13 -0
- data/lib/shoulda/proc_extensions.rb +14 -0
- data/lib/shoulda/rails.rb +8 -0
- data/lib/shoulda/tasks/list_tests.rake +29 -0
- data/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
- data/lib/shoulda/tasks.rb +3 -0
- data/lib/shoulda/version.rb +4 -0
- data/lib/shoulda.rb +9 -0
- data/rails/init.rb +8 -0
- data/test/README +36 -0
- data/test/fail_macros.rb +55 -0
- data/test/fixtures/addresses.yml +3 -0
- data/test/fixtures/friendships.yml +0 -0
- data/test/fixtures/posts.yml +5 -0
- data/test/fixtures/products.yml +0 -0
- data/test/fixtures/taggings.yml +0 -0
- data/test/fixtures/tags.yml +9 -0
- data/test/fixtures/users.yml +6 -0
- data/test/functional/posts_controller_test.rb +121 -0
- data/test/functional/users_controller_test.rb +19 -0
- data/test/matchers/action_mailer/have_sent_email_test.rb +76 -0
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +74 -0
- data/test/matchers/active_record/allow_value_matcher_test.rb +64 -0
- data/test/matchers/active_record/association_matcher_test.rb +462 -0
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +81 -0
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +158 -0
- data/test/matchers/active_record/have_db_column_matcher_test.rb +169 -0
- data/test/matchers/active_record/have_db_index_matcher_test.rb +91 -0
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +29 -0
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +44 -0
- data/test/matchers/active_record/validate_format_of_matcher_test.rb +39 -0
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +52 -0
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +86 -0
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +147 -0
- data/test/matchers/controller/assign_to_matcher_test.rb +55 -0
- data/test/matchers/controller/filter_param_matcher_test.rb +40 -0
- data/test/matchers/controller/redirect_to_matcher_test.rb +37 -0
- data/test/matchers/controller/render_template_matcher_test.rb +37 -0
- data/test/matchers/controller/render_with_layout_matcher_test.rb +47 -0
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +32 -0
- data/test/matchers/controller/respond_with_matcher_test.rb +96 -0
- data/test/matchers/controller/route_matcher_test.rb +75 -0
- data/test/matchers/controller/set_session_matcher_test.rb +48 -0
- data/test/matchers/controller/set_the_flash_matcher.rb +95 -0
- data/test/other/autoload_macro_test.rb +18 -0
- data/test/other/context_test.rb +372 -0
- data/test/other/convert_to_should_syntax_test.rb +63 -0
- data/test/other/helpers_test.rb +317 -0
- data/test/other/private_helpers_test.rb +32 -0
- data/test/other/should_test.rb +271 -0
- data/test/rails2_model_builder.rb +130 -0
- data/test/rails2_root/app/controllers/application_controller.rb +22 -0
- data/test/rails2_root/app/controllers/posts_controller.rb +87 -0
- data/test/rails2_root/app/controllers/users_controller.rb +84 -0
- data/test/rails2_root/app/helpers/application_helper.rb +3 -0
- data/test/rails2_root/app/helpers/posts_helper.rb +2 -0
- data/test/rails2_root/app/helpers/users_helper.rb +2 -0
- data/test/rails2_root/app/models/address.rb +7 -0
- data/test/rails2_root/app/models/flea.rb +11 -0
- data/test/rails2_root/app/models/friendship.rb +4 -0
- data/test/rails2_root/app/models/notifier.rb +8 -0
- data/test/rails2_root/app/models/pets/cat.rb +7 -0
- data/test/rails2_root/app/models/pets/dog.rb +10 -0
- data/test/rails2_root/app/models/post.rb +12 -0
- data/test/rails2_root/app/models/product.rb +12 -0
- data/test/rails2_root/app/models/profile.rb +2 -0
- data/test/rails2_root/app/models/registration.rb +2 -0
- data/test/rails2_root/app/models/tag.rb +8 -0
- data/test/rails2_root/app/models/tagging.rb +4 -0
- data/test/rails2_root/app/models/treat.rb +3 -0
- data/test/rails2_root/app/models/user.rb +32 -0
- data/test/rails2_root/app/views/layouts/posts.rhtml +19 -0
- data/test/rails2_root/app/views/layouts/users.rhtml +17 -0
- data/test/rails2_root/app/views/layouts/wide.html.erb +1 -0
- data/test/rails2_root/app/views/notifier/the_email.html.erb +1 -0
- data/test/rails2_root/app/views/posts/edit.rhtml +27 -0
- data/test/rails2_root/app/views/posts/index.rhtml +25 -0
- data/test/rails2_root/app/views/posts/new.rhtml +26 -0
- data/test/rails2_root/app/views/posts/show.rhtml +18 -0
- data/test/rails2_root/app/views/users/edit.rhtml +22 -0
- data/test/rails2_root/app/views/users/index.rhtml +22 -0
- data/test/rails2_root/app/views/users/new.rhtml +21 -0
- data/test/rails2_root/app/views/users/show.rhtml +13 -0
- data/test/rails2_root/config/boot.rb +110 -0
- data/test/rails2_root/config/database.yml +4 -0
- data/test/rails2_root/config/environment.rb +17 -0
- data/test/rails2_root/config/environments/test.rb +23 -0
- data/test/rails2_root/config/initializers/new_rails_defaults.rb +15 -0
- data/test/rails2_root/config/initializers/shoulda.rb +8 -0
- data/test/rails2_root/config/routes.rb +6 -0
- data/test/rails2_root/db/migrate/001_create_users.rb +19 -0
- data/test/rails2_root/db/migrate/002_create_posts.rb +13 -0
- data/test/rails2_root/db/migrate/003_create_taggings.rb +12 -0
- data/test/rails2_root/db/migrate/004_create_tags.rb +11 -0
- data/test/rails2_root/db/migrate/005_create_dogs.rb +12 -0
- data/test/rails2_root/db/migrate/006_create_addresses.rb +14 -0
- data/test/rails2_root/db/migrate/007_create_fleas.rb +11 -0
- data/test/rails2_root/db/migrate/008_create_dogs_fleas.rb +12 -0
- data/test/rails2_root/db/migrate/009_create_products.rb +17 -0
- data/test/rails2_root/db/migrate/010_create_friendships.rb +14 -0
- data/test/rails2_root/db/migrate/011_create_treats.rb +12 -0
- data/test/rails2_root/db/migrate/20090506203502_create_profiles.rb +12 -0
- data/test/rails2_root/db/migrate/20090506203536_create_registrations.rb +14 -0
- data/test/rails2_root/db/migrate/20090513104502_create_cats.rb +12 -0
- data/test/rails2_root/db/schema.rb +0 -0
- data/test/rails2_root/public/404.html +30 -0
- data/test/rails2_root/public/422.html +30 -0
- data/test/rails2_root/public/500.html +30 -0
- data/test/rails2_root/script/console +3 -0
- data/test/rails2_root/script/generate +3 -0
- data/test/rails2_root/test/shoulda_macros/custom_macro.rb +6 -0
- data/test/rails2_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
- data/test/rails2_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
- data/test/rails2_test_helper.rb +6 -0
- data/test/rails3_model_builder.rb +118 -0
- data/test/rails3_root/Gemfile +28 -0
- data/test/rails3_root/README +244 -0
- data/test/rails3_root/Rakefile +10 -0
- data/test/rails3_root/app/controllers/application_controller.rb +22 -0
- data/test/rails3_root/app/controllers/posts_controller.rb +87 -0
- data/test/rails3_root/app/controllers/users_controller.rb +82 -0
- data/test/rails3_root/app/helpers/application_helper.rb +2 -0
- data/test/rails3_root/app/models/address.rb +7 -0
- data/test/rails3_root/app/models/flea.rb +11 -0
- data/test/rails3_root/app/models/friendship.rb +4 -0
- data/test/rails3_root/app/models/notifier.rb +8 -0
- data/test/rails3_root/app/models/pets/cat.rb +7 -0
- data/test/rails3_root/app/models/pets/dog.rb +10 -0
- data/test/rails3_root/app/models/post.rb +12 -0
- data/test/rails3_root/app/models/product.rb +12 -0
- data/test/rails3_root/app/models/profile.rb +2 -0
- data/test/rails3_root/app/models/registration.rb +2 -0
- data/test/rails3_root/app/models/tag.rb +8 -0
- data/test/rails3_root/app/models/tagging.rb +4 -0
- data/test/rails3_root/app/models/treat.rb +3 -0
- data/test/rails3_root/app/models/user.rb +32 -0
- data/test/rails3_root/app/views/layouts/application.html.erb +14 -0
- data/test/rails3_root/app/views/layouts/posts.rhtml +19 -0
- data/test/rails3_root/app/views/layouts/users.rhtml +17 -0
- data/test/rails3_root/app/views/layouts/wide.html.erb +1 -0
- data/test/rails3_root/app/views/notifier/the_email.html.erb +1 -0
- data/test/rails3_root/app/views/posts/edit.rhtml +27 -0
- data/test/rails3_root/app/views/posts/index.rhtml +25 -0
- data/test/rails3_root/app/views/posts/new.rhtml +24 -0
- data/test/rails3_root/app/views/posts/show.rhtml +18 -0
- data/test/rails3_root/app/views/users/edit.rhtml +22 -0
- data/test/rails3_root/app/views/users/index.rhtml +22 -0
- data/test/rails3_root/app/views/users/new.rhtml +21 -0
- data/test/rails3_root/app/views/users/show.rhtml +13 -0
- data/test/rails3_root/config/application.rb +46 -0
- data/test/rails3_root/config/boot.rb +6 -0
- data/test/rails3_root/config/database.yml +22 -0
- data/test/rails3_root/config/environment.rb +5 -0
- data/test/rails3_root/config/environments/development.rb +19 -0
- data/test/rails3_root/config/environments/production.rb +42 -0
- data/test/rails3_root/config/environments/test.rb +32 -0
- data/test/rails3_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails3_root/config/initializers/inflections.rb +10 -0
- data/test/rails3_root/config/initializers/mime_types.rb +5 -0
- data/test/rails3_root/config/initializers/secret_token.rb +7 -0
- data/test/rails3_root/config/initializers/session_store.rb +8 -0
- data/test/rails3_root/config/locales/en.yml +5 -0
- data/test/rails3_root/config/routes.rb +4 -0
- data/test/rails3_root/config.ru +4 -0
- data/test/rails3_root/db/migrate/001_create_users.rb +19 -0
- data/test/rails3_root/db/migrate/002_create_posts.rb +13 -0
- data/test/rails3_root/db/migrate/003_create_taggings.rb +12 -0
- data/test/rails3_root/db/migrate/004_create_tags.rb +11 -0
- data/test/rails3_root/db/migrate/005_create_dogs.rb +12 -0
- data/test/rails3_root/db/migrate/006_create_addresses.rb +14 -0
- data/test/rails3_root/db/migrate/007_create_fleas.rb +11 -0
- data/test/rails3_root/db/migrate/008_create_dogs_fleas.rb +12 -0
- data/test/rails3_root/db/migrate/009_create_products.rb +17 -0
- data/test/rails3_root/db/migrate/010_create_friendships.rb +14 -0
- data/test/rails3_root/db/migrate/011_create_treats.rb +12 -0
- data/test/rails3_root/db/migrate/20090506203502_create_profiles.rb +12 -0
- data/test/rails3_root/db/migrate/20090506203536_create_registrations.rb +14 -0
- data/test/rails3_root/db/migrate/20090513104502_create_cats.rb +12 -0
- data/test/rails3_root/db/seeds.rb +7 -0
- data/test/rails3_root/public/404.html +26 -0
- data/test/rails3_root/public/422.html +26 -0
- data/test/rails3_root/public/500.html +26 -0
- data/test/rails3_root/public/favicon.ico +0 -0
- data/test/rails3_root/public/images/rails.png +0 -0
- data/test/rails3_root/public/index.html +279 -0
- data/test/rails3_root/public/javascripts/application.js +2 -0
- data/test/rails3_root/public/javascripts/controls.js +965 -0
- data/test/rails3_root/public/javascripts/dragdrop.js +974 -0
- data/test/rails3_root/public/javascripts/effects.js +1123 -0
- data/test/rails3_root/public/javascripts/prototype.js +4874 -0
- data/test/rails3_root/public/javascripts/rails.js +118 -0
- data/test/rails3_root/public/robots.txt +5 -0
- data/test/rails3_root/script/rails +9 -0
- data/test/rails3_root/test/performance/browsing_test.rb +9 -0
- data/test/rails3_root/test/test_helper.rb +13 -0
- data/test/rails3_test_helper.rb +6 -0
- data/test/rspec_test.rb +207 -0
- data/test/test_helper.rb +36 -0
- data/test/unit/address_test.rb +10 -0
- data/test/unit/cat_test.rb +7 -0
- data/test/unit/dog_test.rb +9 -0
- data/test/unit/flea_test.rb +14 -0
- data/test/unit/friendship_test.rb +6 -0
- data/test/unit/post_test.rb +15 -0
- data/test/unit/product_test.rb +23 -0
- data/test/unit/tag_test.rb +11 -0
- data/test/unit/tagging_test.rb +6 -0
- data/test/unit/user_test.rb +46 -0
- metadata +330 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
document.observe("dom:loaded", function() {
|
2
|
+
function handleRemote(element) {
|
3
|
+
var method, url, params;
|
4
|
+
|
5
|
+
if (element.tagName.toLowerCase() === 'form') {
|
6
|
+
method = element.readAttribute('method') || 'post';
|
7
|
+
url = element.readAttribute('action');
|
8
|
+
params = element.serialize(true);
|
9
|
+
} else {
|
10
|
+
method = element.readAttribute('data-method') || 'get';
|
11
|
+
url = element.readAttribute('href');
|
12
|
+
params = {};
|
13
|
+
}
|
14
|
+
|
15
|
+
var event = element.fire("ajax:before");
|
16
|
+
if (event.stopped) return false;
|
17
|
+
|
18
|
+
new Ajax.Request(url, {
|
19
|
+
method: method,
|
20
|
+
parameters: params,
|
21
|
+
asynchronous: true,
|
22
|
+
evalScripts: true,
|
23
|
+
|
24
|
+
onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
|
25
|
+
onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
|
26
|
+
onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
|
27
|
+
onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
|
28
|
+
onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
|
29
|
+
onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
|
30
|
+
});
|
31
|
+
|
32
|
+
element.fire("ajax:after");
|
33
|
+
}
|
34
|
+
|
35
|
+
function handleMethod(element) {
|
36
|
+
var method, url, token_name, token;
|
37
|
+
|
38
|
+
method = element.readAttribute('data-method');
|
39
|
+
url = element.readAttribute('href');
|
40
|
+
csrf_param = $$('meta[name=csrf-param]').first();
|
41
|
+
csrf_token = $$('meta[name=csrf-token]').first();
|
42
|
+
|
43
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
44
|
+
element.parentNode.appendChild(form);
|
45
|
+
|
46
|
+
if (method != 'post') {
|
47
|
+
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
48
|
+
form.appendChild(field);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (csrf_param) {
|
52
|
+
var param = csrf_param.readAttribute('content');
|
53
|
+
var token = csrf_token.readAttribute('content');
|
54
|
+
var field = new Element('input', { type: 'hidden', name: param, value: token });
|
55
|
+
form.appendChild(field);
|
56
|
+
}
|
57
|
+
|
58
|
+
form.submit();
|
59
|
+
}
|
60
|
+
|
61
|
+
$(document.body).observe("click", function(event) {
|
62
|
+
var message = event.findElement().readAttribute('data-confirm');
|
63
|
+
if (message && !confirm(message)) {
|
64
|
+
event.stop();
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
|
68
|
+
var element = event.findElement("a[data-remote]");
|
69
|
+
if (element) {
|
70
|
+
handleRemote(element);
|
71
|
+
event.stop();
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
|
75
|
+
var element = event.findElement("a[data-method]");
|
76
|
+
if (element) {
|
77
|
+
handleMethod(element);
|
78
|
+
event.stop();
|
79
|
+
return true;
|
80
|
+
}
|
81
|
+
});
|
82
|
+
|
83
|
+
// TODO: I don't think submit bubbles in IE
|
84
|
+
$(document.body).observe("submit", function(event) {
|
85
|
+
var element = event.findElement(),
|
86
|
+
message = element.readAttribute('data-confirm');
|
87
|
+
if (message && !confirm(message)) {
|
88
|
+
event.stop();
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
|
92
|
+
var inputs = element.select("input[type=submit][data-disable-with]");
|
93
|
+
inputs.each(function(input) {
|
94
|
+
input.disabled = true;
|
95
|
+
input.writeAttribute('data-original-value', input.value);
|
96
|
+
input.value = input.readAttribute('data-disable-with');
|
97
|
+
});
|
98
|
+
|
99
|
+
var element = event.findElement("form[data-remote]");
|
100
|
+
if (element) {
|
101
|
+
handleRemote(element);
|
102
|
+
event.stop();
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
$(document.body).observe("ajax:after", function(event) {
|
107
|
+
var element = event.findElement();
|
108
|
+
|
109
|
+
if (element.tagName.toLowerCase() === 'form') {
|
110
|
+
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
111
|
+
inputs.each(function(input) {
|
112
|
+
input.value = input.readAttribute('data-original-value');
|
113
|
+
input.writeAttribute('data-original-value', null);
|
114
|
+
input.disabled = false;
|
115
|
+
});
|
116
|
+
}
|
117
|
+
});
|
118
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENV_PATH = File.expand_path('../../config/environment', __FILE__)
|
5
|
+
BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
|
6
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
7
|
+
|
8
|
+
require BOOT_PATH
|
9
|
+
require 'rails/commands'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
+
# -- they do not yet inherit this setting
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
data/test/rspec_test.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
gem 'rspec'
|
5
|
+
gem 'rspec-rails'
|
6
|
+
rescue LoadError => exception
|
7
|
+
puts exception.message
|
8
|
+
puts "RSpec integration was not tested because RSpec is not available"
|
9
|
+
else
|
10
|
+
|
11
|
+
class RspecTest < ActiveSupport::TestCase
|
12
|
+
|
13
|
+
SHOULDA_ROOT =
|
14
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
15
|
+
|
16
|
+
def setup
|
17
|
+
build_gemspec
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
FileUtils.rm_rf(project_dir)
|
22
|
+
FileUtils.rm_rf("#{shoulda_root}/pkg")
|
23
|
+
end
|
24
|
+
|
25
|
+
should "integrate correctly when using config.gem in test.rb" do
|
26
|
+
create_project
|
27
|
+
insert(rspec_dependencies, "config/environments/test.rb")
|
28
|
+
vendor_gems('test')
|
29
|
+
configure_spec_rails
|
30
|
+
assert_configured
|
31
|
+
end
|
32
|
+
|
33
|
+
should "integrate correctly when using config.gem in environment.rb" do
|
34
|
+
create_project
|
35
|
+
insert(rspec_dependencies,
|
36
|
+
"config/environment.rb",
|
37
|
+
/Rails::Initializer\.run/)
|
38
|
+
vendor_gems('development')
|
39
|
+
configure_spec_rails
|
40
|
+
assert_configured
|
41
|
+
end
|
42
|
+
|
43
|
+
should "integrate correctly when using require in spec_helper" do
|
44
|
+
create_project
|
45
|
+
configure_spec_rails
|
46
|
+
insert(%{gem 'shoulda'; require 'shoulda'},
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
%{require 'spec/rails'})
|
49
|
+
assert_configured
|
50
|
+
end
|
51
|
+
|
52
|
+
should "integrate correctly when unpacked and required in spec_helper" do
|
53
|
+
create_project
|
54
|
+
configure_spec_rails
|
55
|
+
insert(%{require 'shoulda'},
|
56
|
+
"spec/spec_helper.rb",
|
57
|
+
%{require 'spec/rails'})
|
58
|
+
unpack_gems
|
59
|
+
assert_configured
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_project
|
63
|
+
command "rails #{project_dir}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def vendor_gems(env)
|
67
|
+
project_command "rake gems:unpack RAILS_ENV=#{env}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def unpack_gems
|
71
|
+
FileUtils.mkdir_p "#{project_dir}/vendor/gems"
|
72
|
+
FileUtils.cd "#{project_dir}/vendor/gems" do
|
73
|
+
%w(rspec rspec-rails shoulda).each do |gem|
|
74
|
+
command "gem unpack #{gem}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
insert('config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/*/lib"]',
|
79
|
+
"config/environment.rb",
|
80
|
+
/Rails::Initializer\.run/)
|
81
|
+
end
|
82
|
+
|
83
|
+
def command(command)
|
84
|
+
output = `GEM_PATH=#{shoulda_root}/pkg #{command} 2>&1`
|
85
|
+
unless $? == 0
|
86
|
+
flunk("Command failed with status #{$?}\n#{command}\n#{output}")
|
87
|
+
end
|
88
|
+
@command_output ||= ''
|
89
|
+
@command_output << output
|
90
|
+
output
|
91
|
+
end
|
92
|
+
|
93
|
+
def project_command(command)
|
94
|
+
result = nil
|
95
|
+
FileUtils.cd project_dir do
|
96
|
+
result = command(command)
|
97
|
+
end
|
98
|
+
result
|
99
|
+
end
|
100
|
+
|
101
|
+
def shoulda_command(command)
|
102
|
+
FileUtils.cd shoulda_root do
|
103
|
+
command(command)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def project_name
|
108
|
+
'example_rails_project'
|
109
|
+
end
|
110
|
+
|
111
|
+
def project_dir
|
112
|
+
File.expand_path(File.join(File.dirname(__FILE__), project_name))
|
113
|
+
end
|
114
|
+
|
115
|
+
def insert(content, path, after = nil)
|
116
|
+
path = File.join(project_dir, path)
|
117
|
+
contents = IO.read(path)
|
118
|
+
if after
|
119
|
+
contents.gsub!(/^(.*#{after}.*)$/, "\\1\n#{content}")
|
120
|
+
else
|
121
|
+
contents << "\n" << content
|
122
|
+
end
|
123
|
+
File.open(path, 'w') {|file| file.write(contents) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def rspec_dependencies
|
127
|
+
return <<-EOS
|
128
|
+
config.gem 'rspec', :lib => 'spec'
|
129
|
+
config.gem 'rspec-rails', :lib => false
|
130
|
+
config.gem 'shoulda', :lib => 'shoulda'
|
131
|
+
EOS
|
132
|
+
end
|
133
|
+
|
134
|
+
def configure_spec_rails
|
135
|
+
project_command "script/generate rspec"
|
136
|
+
end
|
137
|
+
|
138
|
+
def assert_configured
|
139
|
+
create_model
|
140
|
+
migrate
|
141
|
+
create_controller
|
142
|
+
assert_spec_passes
|
143
|
+
end
|
144
|
+
|
145
|
+
def create_model
|
146
|
+
project_command "script/generate rspec_model person name:string"
|
147
|
+
insert "validates_presence_of :name",
|
148
|
+
"app/models/person.rb",
|
149
|
+
/class Person/
|
150
|
+
insert "it { should validate_presence_of(:name) }",
|
151
|
+
"spec/models/person_spec.rb",
|
152
|
+
/describe Person do/
|
153
|
+
end
|
154
|
+
|
155
|
+
def create_controller
|
156
|
+
project_command "script/generate rspec_controller people"
|
157
|
+
insert "def index; render :text => 'Hello'; end",
|
158
|
+
"app/controllers/people_controller.rb",
|
159
|
+
/class PeopleController/
|
160
|
+
shoulda_controller_example = <<-EOS
|
161
|
+
describe PeopleController, "on GET index" do
|
162
|
+
integrate_views
|
163
|
+
subject { controller }
|
164
|
+
before(:each) { get :index }
|
165
|
+
it { should respond_with(:success) }
|
166
|
+
end
|
167
|
+
EOS
|
168
|
+
insert shoulda_controller_example,
|
169
|
+
"spec/controllers/people_controller_spec.rb"
|
170
|
+
end
|
171
|
+
|
172
|
+
def migrate
|
173
|
+
project_command "rake db:migrate"
|
174
|
+
end
|
175
|
+
|
176
|
+
def assert_spec_passes
|
177
|
+
result = project_command("rake spec SPEC_OPTS=-fs")
|
178
|
+
assert_match /should require name to be set/, result
|
179
|
+
assert_match /should respond with 200/, result
|
180
|
+
end
|
181
|
+
|
182
|
+
def shoulda_root
|
183
|
+
SHOULDA_ROOT
|
184
|
+
end
|
185
|
+
|
186
|
+
def build_gemspec
|
187
|
+
backup_gemspec do
|
188
|
+
shoulda_command "rake gemspec"
|
189
|
+
shoulda_command "rake gem"
|
190
|
+
shoulda_command "gem install --no-ri --no-rdoc -i pkg pkg/shoulda*.gem"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def backup_gemspec
|
195
|
+
actual = "#{shoulda_root}/shoulda.gemspec"
|
196
|
+
backup = "#{shoulda_root}/backup.gemspec"
|
197
|
+
FileUtils.mv(actual, backup)
|
198
|
+
begin
|
199
|
+
yield
|
200
|
+
ensure
|
201
|
+
FileUtils.mv(backup, actual)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] = 'test'
|
5
|
+
|
6
|
+
ENV['RAILS_VERSION'] ||= '2.3.8'
|
7
|
+
RAILS_GEM_VERSION = ENV['RAILS_VERSION']
|
8
|
+
|
9
|
+
if ENV['RAILS_VERSION'].to_s =~ /^2/
|
10
|
+
require 'test/rails2_test_helper'
|
11
|
+
else
|
12
|
+
require 'test/rails3_test_helper'
|
13
|
+
end
|
14
|
+
|
15
|
+
shoulda_path = File.join(File.dirname(__FILE__), '..', 'lib')
|
16
|
+
$LOAD_PATH << shoulda_path
|
17
|
+
require 'shoulda'
|
18
|
+
|
19
|
+
# Run the migrations
|
20
|
+
ActiveRecord::Migration.verbose = false
|
21
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
22
|
+
|
23
|
+
# Setup the fixtures path
|
24
|
+
ActiveSupport::TestCase.fixture_path =
|
25
|
+
File.join(File.dirname(__FILE__), "fixtures")
|
26
|
+
|
27
|
+
class ActiveSupport::TestCase #:nodoc:
|
28
|
+
self.use_transactional_fixtures = false
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
end
|
31
|
+
|
32
|
+
require 'test/fail_macros'
|
33
|
+
|
34
|
+
Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'rails2_root'),
|
35
|
+
File.join("vendor", "{plugins,gems}", "*")
|
36
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AddressTest < ActiveSupport::TestCase
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
should_belong_to :addressable
|
7
|
+
should_validate_uniqueness_of :title, :scoped_to => [:addressable_id, :addressable_type]
|
8
|
+
should_ensure_length_at_least :zip, 5
|
9
|
+
should_validate_numericality_of :zip
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Pets::DogTest < ActiveSupport::TestCase
|
4
|
+
should_belong_to :user
|
5
|
+
should_belong_to :address, :dependent => :destroy
|
6
|
+
should_have_many :treats
|
7
|
+
should_have_and_belong_to_many :fleas
|
8
|
+
should_validate_presence_of :owner_id, :treats, :fleas
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PostTest < ActiveSupport::TestCase
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
should_belong_to :user
|
7
|
+
should_belong_to :owner
|
8
|
+
should_have_many :tags, :through => :taggings
|
9
|
+
should_have_many :through_tags, :through => :taggings
|
10
|
+
|
11
|
+
should_validate_uniqueness_of :title
|
12
|
+
should_validate_presence_of :body, :message => /wtf/
|
13
|
+
should_validate_presence_of :title
|
14
|
+
should_validate_numericality_of :user_id
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ProductTest < ActiveSupport::TestCase
|
4
|
+
context "An intangible product" do
|
5
|
+
subject { Product.new(:tangible => false) }
|
6
|
+
|
7
|
+
should_validate_presence_of :title
|
8
|
+
should_not_allow_values_for :size, "22"
|
9
|
+
should_allow_values_for :size, "22kb"
|
10
|
+
should_ensure_value_in_range :price, 0..99
|
11
|
+
end
|
12
|
+
|
13
|
+
context "A tangible product" do
|
14
|
+
subject { Product.new(:tangible => true) }
|
15
|
+
|
16
|
+
should_validate_presence_of :price
|
17
|
+
should_ensure_value_in_range :price, 1..9999
|
18
|
+
should_ensure_value_in_range :weight, 1..100
|
19
|
+
should_not_allow_values_for :size, "22", "10x15"
|
20
|
+
should_allow_values_for :size, "12x12x1"
|
21
|
+
should_ensure_length_in_range :size, 5..20
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TagTest < ActiveSupport::TestCase
|
4
|
+
should_have_many :taggings, :dependent => :destroy
|
5
|
+
should_have_many :posts
|
6
|
+
|
7
|
+
should_ensure_length_at_least :name, 2
|
8
|
+
|
9
|
+
should_not_allow_mass_assignment_of :secret
|
10
|
+
should_allow_mass_assignment_of :name
|
11
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserTest < ActiveSupport::TestCase
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
should_have_many :posts
|
7
|
+
should_have_many :dogs
|
8
|
+
should_have_many :cats
|
9
|
+
|
10
|
+
should_have_many :friendships
|
11
|
+
should_have_many :friends
|
12
|
+
|
13
|
+
should_have_one :address
|
14
|
+
should_have_one :address, :dependent => :destroy
|
15
|
+
|
16
|
+
should_have_db_indices :email, :name
|
17
|
+
should_have_db_index :age
|
18
|
+
should_have_db_index [:email, :name], :unique => true
|
19
|
+
should_have_db_index :age, :unique => false
|
20
|
+
|
21
|
+
should_not_allow_values_for :email, "blah", "b lah"
|
22
|
+
should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
|
23
|
+
should_allow_values_for :age, 1, 10, 99
|
24
|
+
should_not_allow_values_for :age, "a", "-"
|
25
|
+
should_not_allow_values_for :ssn, "a", 1234567890
|
26
|
+
should_ensure_length_in_range :email, 1..100
|
27
|
+
should_ensure_value_in_range :age, 1..100, :low_message => /greater/,
|
28
|
+
:high_message => /less/
|
29
|
+
|
30
|
+
should_not_allow_mass_assignment_of :password
|
31
|
+
should_have_class_methods :find, :destroy
|
32
|
+
should_have_instance_methods :email, :age, :email=, :valid?
|
33
|
+
should_have_db_columns :name, :email, :age
|
34
|
+
should_have_db_column :id, :type => "integer"
|
35
|
+
should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
|
36
|
+
:null => true, :scale => nil
|
37
|
+
should_validate_acceptance_of :eula
|
38
|
+
should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false
|
39
|
+
|
40
|
+
should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
|
41
|
+
should_validate_numericality_of :ssn
|
42
|
+
|
43
|
+
should_have_readonly_attributes :name
|
44
|
+
|
45
|
+
should_have_one :profile, :through => :registration
|
46
|
+
end
|