shoulda 2.11.3 → 3.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +9 -0
- data/Gemfile.lock +108 -0
- data/README.md +95 -0
- data/Rakefile +6 -50
- data/lib/shoulda/version.rb +1 -1
- metadata +50 -269
- data/README.rdoc +0 -154
- data/bin/convert_to_should_syntax +0 -42
- data/lib/shoulda.rb +0 -9
- data/lib/shoulda/action_controller.rb +0 -34
- data/lib/shoulda/action_controller/macros.rb +0 -221
- data/lib/shoulda/action_controller/matchers.rb +0 -39
- data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +0 -112
- data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +0 -74
- data/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb +0 -62
- data/lib/shoulda/action_controller/matchers/render_template_matcher.rb +0 -54
- data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +0 -99
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +0 -74
- data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +0 -85
- data/lib/shoulda/action_controller/matchers/route_matcher.rb +0 -93
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +0 -98
- data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +0 -100
- data/lib/shoulda/action_mailer.rb +0 -13
- data/lib/shoulda/action_mailer/assertions.rb +0 -42
- data/lib/shoulda/action_mailer/matchers.rb +0 -22
- data/lib/shoulda/action_mailer/matchers/have_sent_email.rb +0 -110
- data/lib/shoulda/active_record.rb +0 -16
- data/lib/shoulda/active_record/assertions.rb +0 -69
- data/lib/shoulda/active_record/helpers.rb +0 -32
- data/lib/shoulda/active_record/macros.rb +0 -457
- data/lib/shoulda/active_record/matchers.rb +0 -42
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +0 -83
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +0 -110
- data/lib/shoulda/active_record/matchers/association_matcher.rb +0 -226
- data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +0 -87
- data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +0 -141
- data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +0 -169
- data/lib/shoulda/active_record/matchers/have_db_index_matcher.rb +0 -112
- data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +0 -59
- data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +0 -41
- data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +0 -65
- data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +0 -39
- data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +0 -60
- data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +0 -148
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +0 -56
- data/lib/shoulda/assertions.rb +0 -79
- data/lib/shoulda/autoload_macros.rb +0 -46
- data/lib/shoulda/context.rb +0 -433
- data/lib/shoulda/helpers.rb +0 -8
- data/lib/shoulda/integrations/rspec.rb +0 -13
- data/lib/shoulda/integrations/rspec2.rb +0 -22
- data/lib/shoulda/integrations/test_unit.rb +0 -22
- data/lib/shoulda/macros.rb +0 -161
- data/lib/shoulda/private_helpers.rb +0 -13
- data/lib/shoulda/proc_extensions.rb +0 -14
- data/lib/shoulda/rails.rb +0 -8
- data/lib/shoulda/tasks.rb +0 -3
- data/lib/shoulda/tasks/list_tests.rake +0 -29
- data/lib/shoulda/tasks/yaml_to_shoulda.rake +0 -28
- data/rails/init.rb +0 -8
- data/test/README +0 -36
- data/test/fail_macros.rb +0 -55
- data/test/fixtures/addresses.yml +0 -3
- data/test/fixtures/friendships.yml +0 -0
- data/test/fixtures/posts.yml +0 -5
- data/test/fixtures/products.yml +0 -0
- data/test/fixtures/taggings.yml +0 -0
- data/test/fixtures/tags.yml +0 -9
- data/test/fixtures/users.yml +0 -6
- data/test/functional/posts_controller_test.rb +0 -121
- data/test/functional/users_controller_test.rb +0 -19
- data/test/matchers/action_mailer/have_sent_email_test.rb +0 -70
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +0 -74
- data/test/matchers/active_record/allow_value_matcher_test.rb +0 -64
- data/test/matchers/active_record/association_matcher_test.rb +0 -263
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +0 -81
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +0 -158
- data/test/matchers/active_record/have_db_column_matcher_test.rb +0 -169
- data/test/matchers/active_record/have_db_index_matcher_test.rb +0 -91
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +0 -29
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +0 -44
- data/test/matchers/active_record/validate_format_of_matcher_test.rb +0 -39
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +0 -52
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +0 -86
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +0 -147
- data/test/matchers/controller/assign_to_matcher_test.rb +0 -45
- data/test/matchers/controller/filter_param_matcher_test.rb +0 -40
- data/test/matchers/controller/redirect_to_matcher_test.rb +0 -37
- data/test/matchers/controller/render_template_matcher_test.rb +0 -37
- data/test/matchers/controller/render_with_layout_matcher_test.rb +0 -47
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +0 -32
- data/test/matchers/controller/respond_with_matcher_test.rb +0 -96
- data/test/matchers/controller/route_matcher_test.rb +0 -75
- data/test/matchers/controller/set_session_matcher_test.rb +0 -48
- data/test/matchers/controller/set_the_flash_matcher.rb +0 -95
- data/test/other/autoload_macro_test.rb +0 -18
- data/test/other/context_test.rb +0 -372
- data/test/other/convert_to_should_syntax_test.rb +0 -63
- data/test/other/helpers_test.rb +0 -317
- data/test/other/private_helpers_test.rb +0 -32
- data/test/other/should_test.rb +0 -271
- data/test/rails2_model_builder.rb +0 -130
- data/test/rails2_root/app/controllers/application_controller.rb +0 -22
- data/test/rails2_root/app/controllers/posts_controller.rb +0 -87
- data/test/rails2_root/app/controllers/users_controller.rb +0 -84
- data/test/rails2_root/app/helpers/application_helper.rb +0 -3
- data/test/rails2_root/app/helpers/posts_helper.rb +0 -2
- data/test/rails2_root/app/helpers/users_helper.rb +0 -2
- data/test/rails2_root/app/models/address.rb +0 -7
- data/test/rails2_root/app/models/flea.rb +0 -11
- data/test/rails2_root/app/models/friendship.rb +0 -4
- data/test/rails2_root/app/models/notifier.rb +0 -8
- data/test/rails2_root/app/models/pets/cat.rb +0 -7
- data/test/rails2_root/app/models/pets/dog.rb +0 -10
- data/test/rails2_root/app/models/post.rb +0 -12
- data/test/rails2_root/app/models/product.rb +0 -12
- data/test/rails2_root/app/models/profile.rb +0 -2
- data/test/rails2_root/app/models/registration.rb +0 -2
- data/test/rails2_root/app/models/tag.rb +0 -8
- data/test/rails2_root/app/models/tagging.rb +0 -4
- data/test/rails2_root/app/models/treat.rb +0 -3
- data/test/rails2_root/app/models/user.rb +0 -32
- data/test/rails2_root/app/views/layouts/posts.rhtml +0 -19
- data/test/rails2_root/app/views/layouts/users.rhtml +0 -17
- data/test/rails2_root/app/views/layouts/wide.html.erb +0 -1
- data/test/rails2_root/app/views/notifier/the_email.html.erb +0 -1
- data/test/rails2_root/app/views/posts/edit.rhtml +0 -27
- data/test/rails2_root/app/views/posts/index.rhtml +0 -25
- data/test/rails2_root/app/views/posts/new.rhtml +0 -26
- data/test/rails2_root/app/views/posts/show.rhtml +0 -18
- data/test/rails2_root/app/views/users/edit.rhtml +0 -22
- data/test/rails2_root/app/views/users/index.rhtml +0 -22
- data/test/rails2_root/app/views/users/new.rhtml +0 -21
- data/test/rails2_root/app/views/users/show.rhtml +0 -13
- data/test/rails2_root/config/boot.rb +0 -110
- data/test/rails2_root/config/database.yml +0 -4
- data/test/rails2_root/config/environment.rb +0 -17
- data/test/rails2_root/config/environments/test.rb +0 -23
- data/test/rails2_root/config/initializers/new_rails_defaults.rb +0 -15
- data/test/rails2_root/config/initializers/shoulda.rb +0 -8
- data/test/rails2_root/config/routes.rb +0 -6
- data/test/rails2_root/db/migrate/001_create_users.rb +0 -19
- data/test/rails2_root/db/migrate/002_create_posts.rb +0 -13
- data/test/rails2_root/db/migrate/003_create_taggings.rb +0 -12
- data/test/rails2_root/db/migrate/004_create_tags.rb +0 -11
- data/test/rails2_root/db/migrate/005_create_dogs.rb +0 -12
- data/test/rails2_root/db/migrate/006_create_addresses.rb +0 -14
- data/test/rails2_root/db/migrate/007_create_fleas.rb +0 -11
- data/test/rails2_root/db/migrate/008_create_dogs_fleas.rb +0 -12
- data/test/rails2_root/db/migrate/009_create_products.rb +0 -17
- data/test/rails2_root/db/migrate/010_create_friendships.rb +0 -14
- data/test/rails2_root/db/migrate/011_create_treats.rb +0 -12
- data/test/rails2_root/db/migrate/20090506203502_create_profiles.rb +0 -12
- data/test/rails2_root/db/migrate/20090506203536_create_registrations.rb +0 -14
- data/test/rails2_root/db/migrate/20090513104502_create_cats.rb +0 -12
- data/test/rails2_root/db/schema.rb +0 -0
- data/test/rails2_root/log/test.log +0 -50381
- data/test/rails2_root/public/404.html +0 -30
- data/test/rails2_root/public/422.html +0 -30
- data/test/rails2_root/public/500.html +0 -30
- data/test/rails2_root/script/console +0 -3
- data/test/rails2_root/script/generate +0 -3
- data/test/rails2_root/test/shoulda_macros/custom_macro.rb +0 -6
- data/test/rails2_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +0 -6
- data/test/rails2_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +0 -6
- data/test/rails2_test_helper.rb +0 -6
- data/test/rails3_model_builder.rb +0 -118
- data/test/rails3_root/Gemfile +0 -28
- data/test/rails3_root/README +0 -244
- data/test/rails3_root/Rakefile +0 -10
- data/test/rails3_root/app/controllers/application_controller.rb +0 -22
- data/test/rails3_root/app/controllers/posts_controller.rb +0 -87
- data/test/rails3_root/app/controllers/users_controller.rb +0 -82
- data/test/rails3_root/app/helpers/application_helper.rb +0 -2
- data/test/rails3_root/app/models/address.rb +0 -7
- data/test/rails3_root/app/models/flea.rb +0 -11
- data/test/rails3_root/app/models/friendship.rb +0 -4
- data/test/rails3_root/app/models/notifier.rb +0 -8
- data/test/rails3_root/app/models/pets/cat.rb +0 -7
- data/test/rails3_root/app/models/pets/dog.rb +0 -10
- data/test/rails3_root/app/models/post.rb +0 -12
- data/test/rails3_root/app/models/product.rb +0 -12
- data/test/rails3_root/app/models/profile.rb +0 -2
- data/test/rails3_root/app/models/registration.rb +0 -2
- data/test/rails3_root/app/models/tag.rb +0 -8
- data/test/rails3_root/app/models/tagging.rb +0 -4
- data/test/rails3_root/app/models/treat.rb +0 -3
- data/test/rails3_root/app/models/user.rb +0 -32
- data/test/rails3_root/app/views/layouts/application.html.erb +0 -14
- data/test/rails3_root/app/views/layouts/posts.rhtml +0 -19
- data/test/rails3_root/app/views/layouts/users.rhtml +0 -17
- data/test/rails3_root/app/views/layouts/wide.html.erb +0 -1
- data/test/rails3_root/app/views/notifier/the_email.html.erb +0 -1
- data/test/rails3_root/app/views/posts/edit.rhtml +0 -27
- data/test/rails3_root/app/views/posts/index.rhtml +0 -25
- data/test/rails3_root/app/views/posts/new.rhtml +0 -24
- data/test/rails3_root/app/views/posts/show.rhtml +0 -18
- data/test/rails3_root/app/views/users/edit.rhtml +0 -22
- data/test/rails3_root/app/views/users/index.rhtml +0 -22
- data/test/rails3_root/app/views/users/new.rhtml +0 -21
- data/test/rails3_root/app/views/users/show.rhtml +0 -13
- data/test/rails3_root/config.ru +0 -4
- data/test/rails3_root/config/application.rb +0 -46
- data/test/rails3_root/config/boot.rb +0 -6
- data/test/rails3_root/config/database.yml +0 -22
- data/test/rails3_root/config/environment.rb +0 -5
- data/test/rails3_root/config/environments/development.rb +0 -19
- data/test/rails3_root/config/environments/production.rb +0 -42
- data/test/rails3_root/config/environments/test.rb +0 -32
- data/test/rails3_root/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails3_root/config/initializers/inflections.rb +0 -10
- data/test/rails3_root/config/initializers/mime_types.rb +0 -5
- data/test/rails3_root/config/initializers/secret_token.rb +0 -7
- data/test/rails3_root/config/initializers/session_store.rb +0 -8
- data/test/rails3_root/config/locales/en.yml +0 -5
- data/test/rails3_root/config/routes.rb +0 -4
- data/test/rails3_root/db/migrate/001_create_users.rb +0 -19
- data/test/rails3_root/db/migrate/002_create_posts.rb +0 -13
- data/test/rails3_root/db/migrate/003_create_taggings.rb +0 -12
- data/test/rails3_root/db/migrate/004_create_tags.rb +0 -11
- data/test/rails3_root/db/migrate/005_create_dogs.rb +0 -12
- data/test/rails3_root/db/migrate/006_create_addresses.rb +0 -14
- data/test/rails3_root/db/migrate/007_create_fleas.rb +0 -11
- data/test/rails3_root/db/migrate/008_create_dogs_fleas.rb +0 -12
- data/test/rails3_root/db/migrate/009_create_products.rb +0 -17
- data/test/rails3_root/db/migrate/010_create_friendships.rb +0 -14
- data/test/rails3_root/db/migrate/011_create_treats.rb +0 -12
- data/test/rails3_root/db/migrate/20090506203502_create_profiles.rb +0 -12
- data/test/rails3_root/db/migrate/20090506203536_create_registrations.rb +0 -14
- data/test/rails3_root/db/migrate/20090513104502_create_cats.rb +0 -12
- data/test/rails3_root/db/seeds.rb +0 -7
- data/test/rails3_root/db/test.sqlite3 +0 -0
- data/test/rails3_root/log/test.log +0 -10834
- data/test/rails3_root/public/404.html +0 -26
- data/test/rails3_root/public/422.html +0 -26
- data/test/rails3_root/public/500.html +0 -26
- 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 +0 -279
- data/test/rails3_root/public/javascripts/application.js +0 -2
- data/test/rails3_root/public/javascripts/controls.js +0 -965
- data/test/rails3_root/public/javascripts/dragdrop.js +0 -974
- data/test/rails3_root/public/javascripts/effects.js +0 -1123
- data/test/rails3_root/public/javascripts/prototype.js +0 -4874
- data/test/rails3_root/public/javascripts/rails.js +0 -118
- data/test/rails3_root/public/robots.txt +0 -5
- data/test/rails3_root/script/rails +0 -9
- data/test/rails3_root/test/performance/browsing_test.rb +0 -9
- data/test/rails3_root/test/test_helper.rb +0 -13
- data/test/rails3_test_helper.rb +0 -6
- data/test/rspec_test.rb +0 -207
- data/test/test_helper.rb +0 -36
- data/test/unit/address_test.rb +0 -10
- data/test/unit/cat_test.rb +0 -7
- data/test/unit/dog_test.rb +0 -9
- data/test/unit/flea_test.rb +0 -14
- data/test/unit/friendship_test.rb +0 -6
- data/test/unit/post_test.rb +0 -15
- data/test/unit/product_test.rb +0 -23
- data/test/unit/tag_test.rb +0 -11
- data/test/unit/tagging_test.rb +0 -6
- data/test/unit/user_test.rb +0 -46
@@ -1,110 +0,0 @@
|
|
1
|
-
module Shoulda # :nodoc:
|
2
|
-
module ActionMailer # :nodoc:
|
3
|
-
module Matchers
|
4
|
-
|
5
|
-
# The right email is sent.
|
6
|
-
#
|
7
|
-
# it { should have_sent_email.with_subject(/is spam$/) }
|
8
|
-
# it { should have_sent_email.from('do-not-reply@example.com') }
|
9
|
-
# it { should have_sent_email.with_body(/is spam\./) }
|
10
|
-
# it { should have_sent_email.to('myself@me.com') }
|
11
|
-
# it { should have_sent_email.with_subject(/spam/).
|
12
|
-
# from('do-not-reply@example.com').
|
13
|
-
# with_body(/spam/).
|
14
|
-
# to('myself@me.com') }
|
15
|
-
def have_sent_email
|
16
|
-
HaveSentEmailMatcher.new
|
17
|
-
end
|
18
|
-
|
19
|
-
class HaveSentEmailMatcher # :nodoc:
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
end
|
23
|
-
|
24
|
-
def with_subject(email_subject)
|
25
|
-
@email_subject = email_subject
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def from(sender)
|
30
|
-
@sender = sender
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
def with_body(body)
|
35
|
-
@body = body
|
36
|
-
self
|
37
|
-
end
|
38
|
-
|
39
|
-
def to(recipient)
|
40
|
-
@recipient = recipient
|
41
|
-
self
|
42
|
-
end
|
43
|
-
|
44
|
-
def matches?(subject)
|
45
|
-
::ActionMailer::Base.deliveries.each do |mail|
|
46
|
-
@subject_failed = !regexp_or_string_match(mail.subject, @email_subject) if @email_subject
|
47
|
-
@body_failed = !regexp_or_string_match(mail.body, @body) if @body
|
48
|
-
@sender_failed = !regexp_or_string_match_in_array(mail.from, @sender) if @sender
|
49
|
-
@recipient_failed = !regexp_or_string_match_in_array(mail.to, @recipient) if @recipient
|
50
|
-
return true unless anything_failed?
|
51
|
-
end
|
52
|
-
|
53
|
-
false
|
54
|
-
end
|
55
|
-
|
56
|
-
def failure_message
|
57
|
-
"Expected #{expectation}"
|
58
|
-
end
|
59
|
-
|
60
|
-
def negative_failure_message
|
61
|
-
"Did not expect #{expectation}"
|
62
|
-
end
|
63
|
-
|
64
|
-
def description
|
65
|
-
"send an email"
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def expectation
|
71
|
-
expectation = "sent email"
|
72
|
-
expectation << " with subject #{@email_subject.inspect}" if @subject_failed
|
73
|
-
expectation << " with body #{@body.inspect}" if @body_failed
|
74
|
-
expectation << " from #{@sender.inspect}" if @sender_failed
|
75
|
-
expectation << " to #{@recipient.inspect}" if @recipient_failed
|
76
|
-
expectation << "\nDeliveries:\n#{inspect_deliveries}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def inspect_deliveries
|
80
|
-
::ActionMailer::Base.deliveries.map do |delivery|
|
81
|
-
"#{delivery.subject.inspect} to #{delivery.to.inspect}"
|
82
|
-
end.join("\n")
|
83
|
-
end
|
84
|
-
|
85
|
-
def anything_failed?
|
86
|
-
@subject_failed || @body_failed || @sender_failed || @recipient_failed
|
87
|
-
end
|
88
|
-
|
89
|
-
def regexp_or_string_match(a_string, a_regexp_or_string)
|
90
|
-
case a_regexp_or_string
|
91
|
-
when Regexp
|
92
|
-
a_string =~ a_regexp_or_string
|
93
|
-
when String
|
94
|
-
a_string == a_regexp_or_string
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def regexp_or_string_match_in_array(an_array, a_regexp_or_string)
|
99
|
-
case a_regexp_or_string
|
100
|
-
when Regexp
|
101
|
-
an_array.detect{|e| e =~ a_regexp_or_string}.any?
|
102
|
-
when String
|
103
|
-
an_array.include?(a_regexp_or_string)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'shoulda'
|
2
|
-
require 'shoulda/active_record/helpers'
|
3
|
-
require 'shoulda/active_record/matchers'
|
4
|
-
require 'shoulda/active_record/assertions'
|
5
|
-
require 'shoulda/active_record/macros'
|
6
|
-
|
7
|
-
module Test # :nodoc: all
|
8
|
-
module Unit
|
9
|
-
class TestCase
|
10
|
-
include Shoulda::ActiveRecord::Helpers
|
11
|
-
include Shoulda::ActiveRecord::Matchers
|
12
|
-
include Shoulda::ActiveRecord::Assertions
|
13
|
-
extend Shoulda::ActiveRecord::Macros
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Shoulda # :nodoc:
|
2
|
-
module ActiveRecord # :nodoc:
|
3
|
-
module Assertions
|
4
|
-
# Asserts that the given object can be saved
|
5
|
-
#
|
6
|
-
# assert_save User.new(params)
|
7
|
-
def assert_save(obj)
|
8
|
-
assert obj.save, "Errors: #{pretty_error_messages obj}"
|
9
|
-
obj.reload
|
10
|
-
end
|
11
|
-
|
12
|
-
# Asserts that the given object is valid
|
13
|
-
#
|
14
|
-
# assert_valid User.new(params)
|
15
|
-
def assert_valid(obj)
|
16
|
-
assert obj.valid?, "Errors: #{pretty_error_messages obj}"
|
17
|
-
end
|
18
|
-
|
19
|
-
# Asserts that an Active Record model validates with the passed
|
20
|
-
# <tt>value</tt> by making sure the <tt>error_message_to_avoid</tt> is not
|
21
|
-
# contained within the list of errors for that attribute.
|
22
|
-
#
|
23
|
-
# assert_good_value(User.new, :email, "user@example.com")
|
24
|
-
# assert_good_value(User.new, :ssn, "123456789", /length/)
|
25
|
-
#
|
26
|
-
# If a class is passed as the first argument, a new object will be
|
27
|
-
# instantiated before the assertion. If an instance variable exists with
|
28
|
-
# the same name as the class (underscored), that object will be used
|
29
|
-
# instead.
|
30
|
-
#
|
31
|
-
# assert_good_value(User, :email, "user@example.com")
|
32
|
-
#
|
33
|
-
# product = Product.new(:tangible => false)
|
34
|
-
# assert_good_value(product, :price, "0")
|
35
|
-
def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = nil)
|
36
|
-
object = get_instance_of(object_or_klass)
|
37
|
-
matcher = allow_value(value).
|
38
|
-
for(attribute).
|
39
|
-
with_message(error_message_to_avoid)
|
40
|
-
assert_accepts(matcher, object)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Asserts that an Active Record model invalidates the passed
|
44
|
-
# <tt>value</tt> by making sure the <tt>error_message_to_expect</tt> is
|
45
|
-
# contained within the list of errors for that attribute.
|
46
|
-
#
|
47
|
-
# assert_bad_value(User.new, :email, "invalid")
|
48
|
-
# assert_bad_value(User.new, :ssn, "123", /length/)
|
49
|
-
#
|
50
|
-
# If a class is passed as the first argument, a new object will be
|
51
|
-
# instantiated before the assertion. If an instance variable exists with
|
52
|
-
# the same name as the class (underscored), that object will be used
|
53
|
-
# instead.
|
54
|
-
#
|
55
|
-
# assert_bad_value(User, :email, "invalid")
|
56
|
-
#
|
57
|
-
# product = Product.new(:tangible => true)
|
58
|
-
# assert_bad_value(product, :price, "0")
|
59
|
-
def assert_bad_value(object_or_klass, attribute, value,
|
60
|
-
error_message_to_expect = nil)
|
61
|
-
object = get_instance_of(object_or_klass)
|
62
|
-
matcher = allow_value(value).
|
63
|
-
for(attribute).
|
64
|
-
with_message(error_message_to_expect)
|
65
|
-
assert_rejects(matcher, object)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Shoulda # :nodoc:
|
2
|
-
module ActiveRecord # :nodoc:
|
3
|
-
module Helpers
|
4
|
-
def pretty_error_messages(obj) # :nodoc:
|
5
|
-
obj.errors.map do |a, m|
|
6
|
-
msg = "#{a} #{m}"
|
7
|
-
msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Helper method that determines the default error message used by Active
|
12
|
-
# Record. Works for both existing Rails 2.1 and Rails 2.2 with the newly
|
13
|
-
# introduced I18n module used for localization.
|
14
|
-
#
|
15
|
-
# default_error_message(:blank)
|
16
|
-
# default_error_message(:too_short, :count => 5)
|
17
|
-
# default_error_message(:too_long, :count => 60)
|
18
|
-
def default_error_message(key, values = {})
|
19
|
-
if Object.const_defined?(:I18n) # Rails >= 2.2
|
20
|
-
result = I18n.translate("activerecord.errors.messages.#{key}", values)
|
21
|
-
if result =~ /^translation missing/
|
22
|
-
I18n.translate("errors.messages.#{key}", values)
|
23
|
-
else
|
24
|
-
result
|
25
|
-
end
|
26
|
-
else # Rails <= 2.1.x
|
27
|
-
::ActiveRecord::Errors.default_error_messages[key] % values[:count]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,457 +0,0 @@
|
|
1
|
-
module Shoulda # :nodoc:
|
2
|
-
module ActiveRecord # :nodoc:
|
3
|
-
# = Macro test helpers for your active record models
|
4
|
-
#
|
5
|
-
# These helpers will test most of the validations and associations for your ActiveRecord models.
|
6
|
-
#
|
7
|
-
# class UserTest < Test::Unit::TestCase
|
8
|
-
# should_validate_presence_of :name, :phone_number
|
9
|
-
# should_not_allow_values_for :phone_number, "abcd", "1234"
|
10
|
-
# should_allow_values_for :phone_number, "(123) 456-7890"
|
11
|
-
#
|
12
|
-
# should_not_allow_mass_assignment_of :password
|
13
|
-
#
|
14
|
-
# should_have_one :profile
|
15
|
-
# should_have_many :dogs
|
16
|
-
# should_have_many :messes, :through => :dogs
|
17
|
-
# should_belong_to :lover
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# For all of these helpers, the last parameter may be a hash of options.
|
21
|
-
#
|
22
|
-
module Macros
|
23
|
-
include Helpers
|
24
|
-
include Matchers
|
25
|
-
|
26
|
-
# Deprecated: use ActiveRecord::Matchers#validate_presence_of instead.
|
27
|
-
#
|
28
|
-
# Ensures that the model cannot be saved if one of the attributes listed is not present.
|
29
|
-
#
|
30
|
-
# Options:
|
31
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
32
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.blank')</tt>
|
33
|
-
#
|
34
|
-
# Example:
|
35
|
-
# should_validate_presence_of :name, :phone_number
|
36
|
-
#
|
37
|
-
def should_validate_presence_of(*attributes)
|
38
|
-
::ActiveSupport::Deprecation.warn("use: should validate_presence_of")
|
39
|
-
message = get_options!(attributes, :message)
|
40
|
-
|
41
|
-
attributes.each do |attribute|
|
42
|
-
should validate_presence_of(attribute).with_message(message)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Deprecated: use ActiveRecord::Matchers#validate_uniqueness_of instead.
|
47
|
-
#
|
48
|
-
# Ensures that the model cannot be saved if one of the attributes listed is not unique.
|
49
|
-
# Requires an existing record
|
50
|
-
#
|
51
|
-
# Options:
|
52
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
53
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.taken')</tt>
|
54
|
-
# * <tt>:scoped_to</tt> - field(s) to scope the uniqueness to.
|
55
|
-
# * <tt>:case_sensitive</tt> - whether or not uniqueness is defined by an
|
56
|
-
# exact match. Ignored by non-text attributes. Default = <tt>true</tt>
|
57
|
-
#
|
58
|
-
# Examples:
|
59
|
-
# should_validate_uniqueness_of :keyword, :username
|
60
|
-
# should_validate_uniqueness_of :name, :message => "O NOES! SOMEONE STOELED YER NAME!"
|
61
|
-
# should_validate_uniqueness_of :email, :scoped_to => :name
|
62
|
-
# should_validate_uniqueness_of :address, :scoped_to => [:first_name, :last_name]
|
63
|
-
# should_validate_uniqueness_of :email, :case_sensitive => false
|
64
|
-
#
|
65
|
-
def should_validate_uniqueness_of(*attributes)
|
66
|
-
::ActiveSupport::Deprecation.warn("use: should validate_uniqueness_of")
|
67
|
-
message, scope, case_sensitive = get_options!(attributes, :message, :scoped_to, :case_sensitive)
|
68
|
-
scope = [*scope].compact
|
69
|
-
case_sensitive = true if case_sensitive.nil?
|
70
|
-
|
71
|
-
attributes.each do |attribute|
|
72
|
-
matcher = validate_uniqueness_of(attribute).
|
73
|
-
with_message(message).scoped_to(scope)
|
74
|
-
matcher = matcher.case_insensitive unless case_sensitive
|
75
|
-
should matcher
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# Deprecated: use ActiveRecord::Matchers#allow_mass_assignment_of instead.
|
80
|
-
#
|
81
|
-
# Ensures that the attribute can be set on mass update.
|
82
|
-
#
|
83
|
-
# should_allow_mass_assignment_of :first_name, :last_name
|
84
|
-
#
|
85
|
-
def should_allow_mass_assignment_of(*attributes)
|
86
|
-
::ActiveSupport::Deprecation.warn("use: should allow_mass_assignment_of")
|
87
|
-
get_options!(attributes)
|
88
|
-
|
89
|
-
attributes.each do |attribute|
|
90
|
-
should allow_mass_assignment_of(attribute)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# Deprecated: use ActiveRecord::Matchers#allow_mass_assignment_of instead.
|
95
|
-
#
|
96
|
-
# Ensures that the attribute cannot be set on mass update.
|
97
|
-
#
|
98
|
-
# should_not_allow_mass_assignment_of :password, :admin_flag
|
99
|
-
#
|
100
|
-
def should_not_allow_mass_assignment_of(*attributes)
|
101
|
-
::ActiveSupport::Deprecation.warn("use: should_not allow_mass_assignment_of")
|
102
|
-
get_options!(attributes)
|
103
|
-
|
104
|
-
attributes.each do |attribute|
|
105
|
-
should_not allow_mass_assignment_of(attribute)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# Deprecated: use ActiveRecord::Matchers#have_readonly_attribute instead.
|
110
|
-
#
|
111
|
-
# Ensures that the attribute cannot be changed once the record has been created.
|
112
|
-
#
|
113
|
-
# should_have_readonly_attributes :password, :admin_flag
|
114
|
-
#
|
115
|
-
def should_have_readonly_attributes(*attributes)
|
116
|
-
::ActiveSupport::Deprecation.warn("use: should have_readonly_attribute")
|
117
|
-
get_options!(attributes)
|
118
|
-
|
119
|
-
attributes.each do |attribute|
|
120
|
-
should have_readonly_attribute(attribute)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Deprecated: use ActiveRecord::Matchers#allow_value instead.
|
125
|
-
#
|
126
|
-
# Ensures that the attribute cannot be set to the given values
|
127
|
-
#
|
128
|
-
# Options:
|
129
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
130
|
-
# Regexp or string. If omitted, the test will pass if there is ANY error in
|
131
|
-
# <tt>errors.on(:attribute)</tt>.
|
132
|
-
#
|
133
|
-
# Example:
|
134
|
-
# should_not_allow_values_for :isbn, "bad 1", "bad 2"
|
135
|
-
#
|
136
|
-
def should_not_allow_values_for(attribute, *bad_values)
|
137
|
-
::ActiveSupport::Deprecation.warn("use: should_not allow_value")
|
138
|
-
message = get_options!(bad_values, :message)
|
139
|
-
bad_values.each do |value|
|
140
|
-
should_not allow_value(value).for(attribute).with_message(message)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# Deprecated: use ActiveRecord::Matchers#allow_value instead.
|
145
|
-
#
|
146
|
-
# Ensures that the attribute can be set to the given values.
|
147
|
-
#
|
148
|
-
# Example:
|
149
|
-
# should_allow_values_for :isbn, "isbn 1 2345 6789 0", "ISBN 1-2345-6789-0"
|
150
|
-
#
|
151
|
-
def should_allow_values_for(attribute, *good_values)
|
152
|
-
::ActiveSupport::Deprecation.warn("use: should allow_value")
|
153
|
-
get_options!(good_values)
|
154
|
-
good_values.each do |value|
|
155
|
-
should allow_value(value).for(attribute)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# Deprecated: use ActiveRecord::Matchers#ensure_length_of instead.
|
160
|
-
#
|
161
|
-
# Ensures that the length of the attribute is in the given range
|
162
|
-
#
|
163
|
-
# Options:
|
164
|
-
# * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
165
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_short') % range.first</tt>
|
166
|
-
# * <tt>:long_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
167
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_long') % range.last</tt>
|
168
|
-
#
|
169
|
-
# Example:
|
170
|
-
# should_ensure_length_in_range :password, (6..20)
|
171
|
-
#
|
172
|
-
def should_ensure_length_in_range(attribute, range, opts = {})
|
173
|
-
::ActiveSupport::Deprecation.warn("use: should ensure_length_of.is_at_least.is_at_most")
|
174
|
-
short_message, long_message = get_options!([opts],
|
175
|
-
:short_message,
|
176
|
-
:long_message)
|
177
|
-
should ensure_length_of(attribute).
|
178
|
-
is_at_least(range.first).
|
179
|
-
with_short_message(short_message).
|
180
|
-
is_at_most(range.last).
|
181
|
-
with_long_message(long_message)
|
182
|
-
end
|
183
|
-
|
184
|
-
# Deprecated: use ActiveRecord::Matchers#ensure_length_of instead.
|
185
|
-
#
|
186
|
-
# Ensures that the length of the attribute is at least a certain length
|
187
|
-
#
|
188
|
-
# Options:
|
189
|
-
# * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
190
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_short') % min_length</tt>
|
191
|
-
#
|
192
|
-
# Example:
|
193
|
-
# should_ensure_length_at_least :name, 3
|
194
|
-
#
|
195
|
-
def should_ensure_length_at_least(attribute, min_length, opts = {})
|
196
|
-
::ActiveSupport::Deprecation.warn("use: should ensure_length_of.is_at_least")
|
197
|
-
short_message = get_options!([opts], :short_message)
|
198
|
-
|
199
|
-
should ensure_length_of(attribute).
|
200
|
-
is_at_least(min_length).
|
201
|
-
with_short_message(short_message)
|
202
|
-
end
|
203
|
-
|
204
|
-
# Deprecated: use ActiveRecord::Matchers#ensure_length_of instead.
|
205
|
-
#
|
206
|
-
# Ensures that the length of the attribute is exactly a certain length
|
207
|
-
#
|
208
|
-
# Options:
|
209
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
210
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.wrong_length') % length</tt>
|
211
|
-
#
|
212
|
-
# Example:
|
213
|
-
# should_ensure_length_is :ssn, 9
|
214
|
-
#
|
215
|
-
def should_ensure_length_is(attribute, length, opts = {})
|
216
|
-
::ActiveSupport::Deprecation.warn("use: should ensure_length_of.is_equal_to")
|
217
|
-
message = get_options!([opts], :message)
|
218
|
-
should ensure_length_of(attribute).
|
219
|
-
is_equal_to(length).
|
220
|
-
with_message(message)
|
221
|
-
end
|
222
|
-
|
223
|
-
# Deprecated: use ActiveRecord::Matchers#ensure_inclusion_of instead.
|
224
|
-
#
|
225
|
-
# Ensure that the attribute is in the range specified
|
226
|
-
#
|
227
|
-
# Options:
|
228
|
-
# * <tt>:low_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
229
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.inclusion')</tt>
|
230
|
-
# * <tt>:high_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
231
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.inclusion')</tt>
|
232
|
-
#
|
233
|
-
# Example:
|
234
|
-
# should_ensure_value_in_range :age, (0..100)
|
235
|
-
#
|
236
|
-
def should_ensure_value_in_range(attribute, range, opts = {})
|
237
|
-
::ActiveSupport::Deprecation.warn("use: should ensure_inclusion_of.in_range")
|
238
|
-
message, low_message, high_message = get_options!([opts],
|
239
|
-
:message,
|
240
|
-
:low_message,
|
241
|
-
:high_message)
|
242
|
-
should ensure_inclusion_of(attribute).
|
243
|
-
in_range(range).
|
244
|
-
with_message(message).
|
245
|
-
with_low_message(low_message).
|
246
|
-
with_high_message(high_message)
|
247
|
-
end
|
248
|
-
|
249
|
-
# Deprecated: use ActiveRecord::Matchers#validate_numericality_of instead.
|
250
|
-
#
|
251
|
-
# Ensure that the attribute is numeric
|
252
|
-
#
|
253
|
-
# Options:
|
254
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
255
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.not_a_number')</tt>
|
256
|
-
#
|
257
|
-
# Example:
|
258
|
-
# should_validate_numericality_of :age
|
259
|
-
#
|
260
|
-
def should_validate_numericality_of(*attributes)
|
261
|
-
::ActiveSupport::Deprecation.warn("use: should validate_numericality_of")
|
262
|
-
message = get_options!(attributes, :message)
|
263
|
-
attributes.each do |attribute|
|
264
|
-
should validate_numericality_of(attribute).
|
265
|
-
with_message(message)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
# Deprecated: use ActiveRecord::Matchers#have_many instead.
|
270
|
-
#
|
271
|
-
# Ensures that the has_many relationship exists. Will also test that the
|
272
|
-
# associated table has the required columns. Works with polymorphic
|
273
|
-
# associations.
|
274
|
-
#
|
275
|
-
# Options:
|
276
|
-
# * <tt>:through</tt> - association name for <tt>has_many :through</tt>
|
277
|
-
# * <tt>:dependent</tt> - tests that the association makes use of the dependent option.
|
278
|
-
#
|
279
|
-
# Example:
|
280
|
-
# should_have_many :friends
|
281
|
-
# should_have_many :enemies, :through => :friends
|
282
|
-
# should_have_many :enemies, :dependent => :destroy
|
283
|
-
#
|
284
|
-
def should_have_many(*associations)
|
285
|
-
::ActiveSupport::Deprecation.warn("use: should have_many")
|
286
|
-
through, dependent = get_options!(associations, :through, :dependent)
|
287
|
-
associations.each do |association|
|
288
|
-
should have_many(association).through(through).dependent(dependent)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
# Deprecated: use ActiveRecord::Matchers#have_one instead.
|
293
|
-
#
|
294
|
-
# Ensure that the has_one relationship exists. Will also test that the
|
295
|
-
# associated table has the required columns. Works with polymorphic
|
296
|
-
# associations.
|
297
|
-
#
|
298
|
-
# Options:
|
299
|
-
# * <tt>:dependent</tt> - tests that the association makes use of the dependent option.
|
300
|
-
#
|
301
|
-
# Example:
|
302
|
-
# should_have_one :god # unless hindu
|
303
|
-
#
|
304
|
-
def should_have_one(*associations)
|
305
|
-
::ActiveSupport::Deprecation.warn("use: should have_one")
|
306
|
-
dependent, through = get_options!(associations, :dependent, :through)
|
307
|
-
associations.each do |association|
|
308
|
-
should have_one(association).dependent(dependent).through(through)
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
# Deprecated: use ActiveRecord::Matchers#have_and_belong_to_many instead.
|
313
|
-
#
|
314
|
-
# Ensures that the has_and_belongs_to_many relationship exists, and that the join
|
315
|
-
# table is in place.
|
316
|
-
#
|
317
|
-
# should_have_and_belong_to_many :posts, :cars
|
318
|
-
#
|
319
|
-
def should_have_and_belong_to_many(*associations)
|
320
|
-
::ActiveSupport::Deprecation.warn("use: should have_and_belong_to_many")
|
321
|
-
get_options!(associations)
|
322
|
-
|
323
|
-
associations.each do |association|
|
324
|
-
should have_and_belong_to_many(association)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
# Deprecated: use ActiveRecord::Matchers#belong_to instead.
|
329
|
-
#
|
330
|
-
# Ensure that the belongs_to relationship exists.
|
331
|
-
#
|
332
|
-
# should_belong_to :parent
|
333
|
-
#
|
334
|
-
def should_belong_to(*associations)
|
335
|
-
::ActiveSupport::Deprecation.warn("use: should belong_to")
|
336
|
-
dependent = get_options!(associations, :dependent)
|
337
|
-
associations.each do |association|
|
338
|
-
should belong_to(association).dependent(dependent)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
# Deprecated.
|
343
|
-
#
|
344
|
-
# Ensure that the given class methods are defined on the model.
|
345
|
-
#
|
346
|
-
# should_have_class_methods :find, :destroy
|
347
|
-
#
|
348
|
-
def should_have_class_methods(*methods)
|
349
|
-
::ActiveSupport::Deprecation.warn
|
350
|
-
get_options!(methods)
|
351
|
-
klass = described_type
|
352
|
-
methods.each do |method|
|
353
|
-
should "respond to class method ##{method}" do
|
354
|
-
assert_respond_to klass, method, "#{klass.name} does not have class method #{method}"
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
# Deprecated.
|
360
|
-
#
|
361
|
-
# Ensure that the given instance methods are defined on the model.
|
362
|
-
#
|
363
|
-
# should_have_instance_methods :email, :name, :name=
|
364
|
-
#
|
365
|
-
def should_have_instance_methods(*methods)
|
366
|
-
::ActiveSupport::Deprecation.warn
|
367
|
-
get_options!(methods)
|
368
|
-
klass = described_type
|
369
|
-
methods.each do |method|
|
370
|
-
should "respond to instance method ##{method}" do
|
371
|
-
assert_respond_to klass.new, method, "#{klass.name} does not have instance method #{method}"
|
372
|
-
end
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
# Deprecated: use ActiveRecord::Matchers#have_db_column instead.
|
377
|
-
#
|
378
|
-
# Ensure that the given columns are defined on the models backing SQL table.
|
379
|
-
# Also aliased to should_have_db_column for readability.
|
380
|
-
# Takes the same options available in migrations:
|
381
|
-
# :type, :precision, :limit, :default, :null, and :scale
|
382
|
-
#
|
383
|
-
# Examples:
|
384
|
-
#
|
385
|
-
# should_have_db_columns :id, :email, :name, :created_at
|
386
|
-
#
|
387
|
-
# should_have_db_column :email, :type => "string", :limit => 255
|
388
|
-
# should_have_db_column :salary, :decimal, :precision => 15, :scale => 2
|
389
|
-
# should_have_db_column :admin, :default => false, :null => false
|
390
|
-
#
|
391
|
-
def should_have_db_columns(*columns)
|
392
|
-
::ActiveSupport::Deprecation.warn("use: should have_db_column")
|
393
|
-
column_type, precision, limit, default, null, scale, sql_type =
|
394
|
-
get_options!(columns, :type, :precision, :limit,
|
395
|
-
:default, :null, :scale, :sql_type)
|
396
|
-
columns.each do |name|
|
397
|
-
should have_db_column(name).
|
398
|
-
of_type(column_type).
|
399
|
-
with_options(:precision => precision, :limit => limit,
|
400
|
-
:default => default, :null => null,
|
401
|
-
:scale => scale, :sql_type => sql_type)
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
alias_method :should_have_db_column, :should_have_db_columns
|
406
|
-
|
407
|
-
# Deprecated: use ActiveRecord::Matchers#have_db_index instead.
|
408
|
-
#
|
409
|
-
# Ensures that there are DB indices on the given columns or tuples of columns.
|
410
|
-
# Also aliased to should_have_db_index for readability
|
411
|
-
#
|
412
|
-
# Options:
|
413
|
-
# * <tt>:unique</tt> - whether or not the index has a unique
|
414
|
-
# constraint. Use <tt>true</tt> to explicitly test for a unique
|
415
|
-
# constraint. Use <tt>false</tt> to explicitly test for a non-unique
|
416
|
-
# constraint. Use <tt>nil</tt> if you don't care whether the index is
|
417
|
-
# unique or not. Default = <tt>nil</tt>
|
418
|
-
#
|
419
|
-
# Examples:
|
420
|
-
#
|
421
|
-
# should_have_db_indices :email, :name, [:commentable_type, :commentable_id]
|
422
|
-
# should_have_db_index :age
|
423
|
-
# should_have_db_index :ssn, :unique => true
|
424
|
-
#
|
425
|
-
def should_have_db_indices(*columns)
|
426
|
-
::ActiveSupport::Deprecation.warn("use: should have_db_index")
|
427
|
-
unique = get_options!(columns, :unique)
|
428
|
-
|
429
|
-
columns.each do |column|
|
430
|
-
should have_db_index(column).unique(unique)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
alias_method :should_have_db_index, :should_have_db_indices
|
435
|
-
|
436
|
-
# Deprecated: use ActiveRecord::Matchers#validate_acceptance_of instead.
|
437
|
-
#
|
438
|
-
# Ensures that the model cannot be saved if one of the attributes listed is not accepted.
|
439
|
-
#
|
440
|
-
# Options:
|
441
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
442
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.accepted')</tt>
|
443
|
-
#
|
444
|
-
# Example:
|
445
|
-
# should_validate_acceptance_of :eula
|
446
|
-
#
|
447
|
-
def should_validate_acceptance_of(*attributes)
|
448
|
-
::ActiveSupport::Deprecation.warn("use: should validate_acceptance_of")
|
449
|
-
message = get_options!(attributes, :message)
|
450
|
-
|
451
|
-
attributes.each do |attribute|
|
452
|
-
should validate_acceptance_of(attribute).with_message(message)
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|
456
|
-
end
|
457
|
-
end
|