shoulda-matchers 2.6.1 → 2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +9 -0
- data/.yardopts +8 -0
- data/Appraisals +82 -33
- data/Gemfile +18 -2
- data/Gemfile.lock +13 -1
- data/NEWS.md +27 -2
- data/README.md +83 -1329
- data/Rakefile +118 -1
- data/cucumber.yml +1 -0
- data/doc_config/gh-pages/index.html.erb +9 -0
- data/doc_config/yard/setup.rb +22 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
- data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
- data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
- data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/app.js +298 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
- data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
- data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
- data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
- data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
- data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
- data/doc_config/yard/templates/default/layout/html/setup.rb +40 -0
- data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
- data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
- data/docs.watchr +5 -0
- data/features/rails_integration.feature +32 -0
- data/features/step_definitions/rails_steps.rb +55 -9
- data/features/support/env.rb +1 -0
- data/gemfiles/3.0.gemfile +13 -1
- data/gemfiles/3.0.gemfile.lock +13 -1
- data/gemfiles/3.1.gemfile +17 -2
- data/gemfiles/3.1.gemfile.lock +31 -2
- data/gemfiles/3.1_1.9.2.gemfile +33 -0
- data/gemfiles/3.1_1.9.2.gemfile.lock +203 -0
- data/gemfiles/3.2.gemfile +18 -2
- data/gemfiles/3.2.gemfile.lock +32 -2
- data/gemfiles/3.2_1.9.2.gemfile +32 -0
- data/gemfiles/3.2_1.9.2.gemfile.lock +200 -0
- data/gemfiles/4.0.0.gemfile +20 -1
- data/gemfiles/4.0.0.gemfile.lock +46 -2
- data/gemfiles/4.0.1.gemfile +20 -1
- data/gemfiles/4.0.1.gemfile.lock +46 -2
- data/gemfiles/4.1.gemfile +21 -2
- data/gemfiles/4.1.gemfile.lock +47 -4
- data/lib/shoulda/matchers/action_controller.rb +0 -20
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +119 -28
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +22 -6
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +43 -10
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +40 -13
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +63 -11
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +34 -1
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +84 -15
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +84 -28
- data/lib/shoulda/matchers/action_controller/route_params.rb +4 -3
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +76 -13
- data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +147 -13
- data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +148 -2
- data/lib/shoulda/matchers/active_model.rb +0 -25
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +66 -9
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +161 -19
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -5
- data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +92 -13
- data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +218 -16
- data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +198 -32
- data/lib/shoulda/matchers/active_model/errors.rb +5 -2
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +29 -8
- data/lib/shoulda/matchers/active_model/helpers.rb +20 -8
- data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +4 -6
- data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +52 -14
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +51 -13
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +53 -7
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +275 -19
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +84 -14
- data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +170 -41
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +20 -15
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -2
- data/lib/shoulda/matchers/active_record.rb +1 -12
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +89 -15
- data/lib/shoulda/matchers/active_record/association_matcher.rb +726 -70
- data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -1
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +4 -3
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +4 -5
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +79 -15
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +64 -15
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +21 -7
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +85 -10
- data/lib/shoulda/matchers/assertion_error.rb +7 -1
- data/lib/shoulda/matchers/doublespeak.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +3 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +1 -0
- data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/structs.rb +2 -0
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/world.rb +3 -4
- data/lib/shoulda/matchers/error.rb +1 -0
- data/lib/shoulda/matchers/independent/delegate_matcher.rb +108 -20
- data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +4 -3
- data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +3 -0
- data/lib/shoulda/matchers/rails_shim.rb +3 -2
- data/lib/shoulda/matchers/version.rb +2 -1
- data/lib/shoulda/matchers/warn.rb +1 -0
- data/script/SUPPORTED_VERSIONS +1 -0
- data/script/install_gems_in_all_appraisals +14 -0
- data/script/run_all_tests +14 -0
- data/shoulda-matchers.gemspec +0 -10
- data/spec/report_warnings.rb +7 -0
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -0
- data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -36
- data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +2 -2
- data/spec/shoulda/matchers/doublespeak/double_spec.rb +1 -1
- data/spec/shoulda/matchers/doublespeak/world_spec.rb +11 -29
- data/spec/shoulda/matchers/doublespeak_spec.rb +3 -3
- data/spec/spec_helper.rb +17 -0
- data/spec/support/class_builder.rb +4 -0
- data/spec/support/test_application.rb +1 -1
- data/spec/warnings_spy.rb +64 -0
- data/spec/warnings_spy/filesystem.rb +45 -0
- data/spec/warnings_spy/partitioner.rb +29 -0
- data/spec/warnings_spy/reader.rb +64 -0
- data/spec/warnings_spy/reporter.rb +87 -0
- metadata +49 -134
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class CounterCacheMatcher
|
6
7
|
attr_accessor :missing_option
|
7
8
|
|
@@ -26,7 +27,7 @@ module Shoulda # :nodoc:
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
protected
|
30
31
|
|
31
32
|
attr_accessor :subject, :counter_cache, :name
|
32
33
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class DependentMatcher
|
6
7
|
attr_accessor :missing_option
|
7
8
|
|
@@ -26,7 +27,7 @@ module Shoulda # :nodoc:
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
protected
|
30
31
|
|
31
32
|
attr_accessor :subject, :dependent, :name
|
32
33
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class InverseOfMatcher
|
6
7
|
attr_accessor :missing_option
|
7
8
|
|
@@ -26,7 +27,7 @@ module Shoulda # :nodoc:
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
protected
|
30
31
|
|
31
32
|
attr_accessor :subject, :inverse_of, :name
|
32
33
|
|
@@ -4,6 +4,7 @@ module Shoulda
|
|
4
4
|
module Matchers
|
5
5
|
module ActiveRecord
|
6
6
|
module AssociationMatchers
|
7
|
+
# @private
|
7
8
|
class ModelReflection < SimpleDelegator
|
8
9
|
def initialize(reflection)
|
9
10
|
super(reflection)
|
@@ -44,7 +45,7 @@ module Shoulda
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
|
-
|
48
|
+
protected
|
48
49
|
|
49
50
|
attr_reader :reflection, :subject
|
50
51
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class ModelReflector
|
6
7
|
delegate :associated_class, :through?, :join_table,
|
7
8
|
:association_relation, :polymorphic?, to: :reflection
|
@@ -46,7 +47,7 @@ module Shoulda # :nodoc:
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
+
protected
|
50
51
|
|
51
52
|
attr_reader :subject, :name
|
52
53
|
|
@@ -1,12 +1,11 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class OptionVerifier
|
6
7
|
delegate :reflection, to: :reflector
|
7
8
|
|
8
|
-
attr_reader :reflector
|
9
|
-
|
10
9
|
RELATION_OPTIONS = [:conditions, :order]
|
11
10
|
|
12
11
|
def initialize(reflector)
|
@@ -42,7 +41,7 @@ module Shoulda # :nodoc:
|
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
|
44
|
+
protected
|
46
45
|
|
47
46
|
attr_reader :reflector
|
48
47
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class OrderMatcher
|
6
7
|
attr_accessor :missing_option
|
7
8
|
|
@@ -26,7 +27,7 @@ module Shoulda # :nodoc:
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
protected
|
30
31
|
|
31
32
|
attr_accessor :subject, :order, :name
|
32
33
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class SourceMatcher
|
6
7
|
attr_accessor :missing_option
|
7
8
|
|
@@ -26,7 +27,7 @@ module Shoulda # :nodoc:
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
protected
|
30
31
|
|
31
32
|
attr_accessor :subject, :source, :name
|
32
33
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
3
|
+
module ActiveRecord
|
4
4
|
module AssociationMatchers
|
5
|
+
# @private
|
5
6
|
class ThroughMatcher
|
6
7
|
attr_accessor :missing_option
|
7
8
|
|
@@ -48,7 +49,7 @@ module Shoulda # :nodoc:
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
+
protected
|
52
53
|
|
53
54
|
attr_accessor :through, :name, :subject
|
54
55
|
|
@@ -1,25 +1,89 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
4
|
-
|
5
|
-
#
|
3
|
+
module ActiveRecord
|
4
|
+
# The `have_db_column` matcher tests that the table that backs your model
|
5
|
+
# has a specific column.
|
6
|
+
#
|
7
|
+
# class CreatePhones < ActiveRecord::Migration
|
8
|
+
# def change
|
9
|
+
# create_table :phones do |t|
|
10
|
+
# t.string :supported_ios_version
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # RSpec
|
16
|
+
# describe Phone do
|
17
|
+
# it { should have_db_column(:supported_ios_version) }
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # Test::Unit
|
21
|
+
# class PhoneTest < ActiveSupport::TestCase
|
22
|
+
# should have_db_column(:supported_ios_version)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# #### Qualifiers
|
26
|
+
#
|
27
|
+
# ##### of_type
|
28
|
+
#
|
29
|
+
# Use `of_type` to assert that a column is defined as a certain type.
|
30
|
+
#
|
31
|
+
# class CreatePhones < ActiveRecord::Migration
|
32
|
+
# def change
|
33
|
+
# create_table :phones do |t|
|
34
|
+
# t.decimal :camera_aperture
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# # RSpec
|
40
|
+
# describe Phone do
|
41
|
+
# it do
|
42
|
+
# should have_db_column(:camera_aperture).of_type(:decimal)
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # Test::Unit
|
47
|
+
# class PhoneTest < ActiveSupport::TestCase
|
48
|
+
# should have_db_column(:camera_aperture).of_type(:decimal)
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# ##### with_options
|
52
|
+
#
|
53
|
+
# Use `with_options` to assert that a column has been defined with
|
54
|
+
# certain options (`:precision`, `:limit`, `:default`, `:null`, `:scale`,
|
55
|
+
# or `:primary`).
|
56
|
+
#
|
57
|
+
# class CreatePhones < ActiveRecord::Migration
|
58
|
+
# def change
|
59
|
+
# create_table :phones do |t|
|
60
|
+
# t.decimal :camera_aperture, precision: 1, null: false
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# # RSpec
|
66
|
+
# describe Phone do
|
67
|
+
# it do
|
68
|
+
# should have_db_column(:camera_aperture).
|
69
|
+
# with_options(precision: 1, null: false)
|
70
|
+
# end
|
71
|
+
# end
|
6
72
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
73
|
+
# # Test::Unit
|
74
|
+
# class PhoneTest < ActiveSupport::TestCase
|
75
|
+
# should have_db_column(:camera_aperture).
|
76
|
+
# with_options(precision: 1, null: false)
|
77
|
+
# end
|
11
78
|
#
|
12
|
-
#
|
13
|
-
# it { should_not have_db_column(:admin).of_type(:boolean) }
|
14
|
-
# it { should have_db_column(:salary).
|
15
|
-
# of_type(:decimal).
|
16
|
-
# with_options(precision: 10, scale: 2) }
|
79
|
+
# @return [HaveDbColumnMatcher]
|
17
80
|
#
|
18
81
|
def have_db_column(column)
|
19
82
|
HaveDbColumnMatcher.new(column)
|
20
83
|
end
|
21
84
|
|
22
|
-
|
85
|
+
# @private
|
86
|
+
class HaveDbColumnMatcher
|
23
87
|
def initialize(column)
|
24
88
|
@column = column
|
25
89
|
@options = {}
|
@@ -189,7 +253,7 @@ module Shoulda # :nodoc:
|
|
189
253
|
end
|
190
254
|
|
191
255
|
def expectation
|
192
|
-
|
256
|
+
"#{model_class.name} to #{description}"
|
193
257
|
end
|
194
258
|
end
|
195
259
|
end
|
@@ -1,27 +1,76 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
3
|
+
module ActiveRecord
|
4
|
+
# The `have_db_index` matcher tests that the table that backs your model
|
5
|
+
# has a index on a specific column.
|
6
|
+
#
|
7
|
+
# class CreateBlogs < ActiveRecord::Migration
|
8
|
+
# def change
|
9
|
+
# create_table :blogs do |t|
|
10
|
+
# t.integer :user_id
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# add_index :blogs, :user_id
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # RSpec
|
18
|
+
# describe Blog do
|
19
|
+
# it { should have_db_index(:user_id) }
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # Test::Unit
|
23
|
+
# class BlogTest < ActiveSupport::TestCase
|
24
|
+
# should have_db_index(:user_id)
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# #### Qualifiers
|
28
|
+
#
|
29
|
+
# ##### unique
|
30
|
+
#
|
31
|
+
# Use `unique` to assert that the index is unique.
|
32
|
+
#
|
33
|
+
# class CreateBlogs < ActiveRecord::Migration
|
34
|
+
# def change
|
35
|
+
# create_table :blogs do |t|
|
36
|
+
# t.string :name
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# add_index :blogs, :name, unique: true
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # RSpec
|
44
|
+
# describe Blog do
|
45
|
+
# it { should have_db_index(:name).unique(true) }
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# # Test::Unit
|
49
|
+
# class BlogTest < ActiveSupport::TestCase
|
50
|
+
# should have_db_index(:name).unique(true)
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# Since it only ever makes since for `unique` to be `true`, you can also
|
54
|
+
# leave off the argument to save some keystrokes:
|
7
55
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# constraint.
|
56
|
+
# # RSpec
|
57
|
+
# describe Blog do
|
58
|
+
# it { should have_db_index(:name).unique }
|
59
|
+
# end
|
13
60
|
#
|
14
|
-
#
|
61
|
+
# # Test::Unit
|
62
|
+
# class BlogTest < ActiveSupport::TestCase
|
63
|
+
# should have_db_index(:name).unique
|
64
|
+
# end
|
15
65
|
#
|
16
|
-
#
|
17
|
-
# it { should have_db_index([:commentable_type, :commentable_id]) }
|
18
|
-
# it { should have_db_index(:ssn).unique(true) }
|
66
|
+
# @return [HaveDbIndexMatcher]
|
19
67
|
#
|
20
68
|
def have_db_index(columns)
|
21
69
|
HaveDbIndexMatcher.new(columns)
|
22
70
|
end
|
23
71
|
|
24
|
-
|
72
|
+
# @private
|
73
|
+
class HaveDbIndexMatcher
|
25
74
|
def initialize(columns)
|
26
75
|
@columns = normalize_columns_to_array(columns)
|
27
76
|
@options = {}
|
@@ -1,17 +1,31 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
3
|
+
module ActiveRecord
|
4
|
+
# The `have_readonly_attribute` matcher tests usage of the
|
5
|
+
# `attr_readonly` macro.
|
6
|
+
#
|
7
|
+
# class User < ActiveRecord::Base
|
8
|
+
# attr_readonly :password
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# # RSpec
|
12
|
+
# describe User do
|
13
|
+
# it { should have_readonly_attribute(:password) }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # Test::Unit
|
17
|
+
# class UserTest < ActiveSupport::TestCase
|
18
|
+
# should have_readonly_attribute(:password)
|
19
|
+
# end
|
7
20
|
#
|
8
|
-
#
|
21
|
+
# @return [HaveReadonlyAttributeMatcher]
|
9
22
|
#
|
10
23
|
def have_readonly_attribute(value)
|
11
24
|
HaveReadonlyAttributeMatcher.new(value)
|
12
25
|
end
|
13
26
|
|
14
|
-
|
27
|
+
# @private
|
28
|
+
class HaveReadonlyAttributeMatcher
|
15
29
|
def initialize(attribute)
|
16
30
|
@attribute = attribute.to_s
|
17
31
|
end
|
@@ -1,21 +1,96 @@
|
|
1
|
-
module Shoulda
|
1
|
+
module Shoulda
|
2
2
|
module Matchers
|
3
|
-
module ActiveRecord
|
4
|
-
#
|
3
|
+
module ActiveRecord
|
4
|
+
# The `serialize` matcher tests usage of the `serialize` macro.
|
5
5
|
#
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# class Product < ActiveRecord::Base
|
7
|
+
# serialize :customizations
|
8
|
+
# end
|
8
9
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# # RSpec
|
11
|
+
# describe Product do
|
12
|
+
# it { should serialize(:customizations) }
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # Test::Unit
|
16
|
+
# class ProductTest < ActiveSupport::TestCase
|
17
|
+
# should serialize(:customizations)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# #### Qualifiers
|
21
|
+
#
|
22
|
+
# ##### as
|
23
|
+
#
|
24
|
+
# Use `as` if you are using a custom serializer class.
|
25
|
+
#
|
26
|
+
# class ProductSpecsSerializer
|
27
|
+
# def load(string)
|
28
|
+
# # ...
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# def dump(options)
|
32
|
+
# # ...
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# class Product < ActiveRecord::Base
|
37
|
+
# serialize :specifications, ProductSpecsSerializer
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# # RSpec
|
41
|
+
# describe Product do
|
42
|
+
# it do
|
43
|
+
# should serialize(:specifications).
|
44
|
+
# as(ProductSpecsSerializer)
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# # Test::Unit
|
49
|
+
# class ProductTest < ActiveSupport::TestCase
|
50
|
+
# should serialize(:specifications).
|
51
|
+
# as(ProductSpecsSerializer)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# ##### as_instance_of
|
55
|
+
#
|
56
|
+
# Use `as_instance_of` if you are using a custom serializer object.
|
57
|
+
#
|
58
|
+
# class ProductOptionsSerializer
|
59
|
+
# def load(string)
|
60
|
+
# # ...
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# def dump(options)
|
64
|
+
# # ...
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# class Product < ActiveRecord::Base
|
69
|
+
# serialize :options, ProductOptionsSerializer.new
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# # RSpec
|
73
|
+
# describe Product do
|
74
|
+
# it do
|
75
|
+
# should serialize(:options).
|
76
|
+
# as_instance_of(ProductOptionsSerializer)
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# # Test::Unit
|
81
|
+
# class ProductTest < ActiveSupport::TestCase
|
82
|
+
# should serialize(:options).
|
83
|
+
# as_instance_of(ProductOptionsSerializer)
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# @return [SerializeMatcher]
|
13
87
|
#
|
14
88
|
def serialize(name)
|
15
89
|
SerializeMatcher.new(name)
|
16
90
|
end
|
17
91
|
|
18
|
-
|
92
|
+
# @private
|
93
|
+
class SerializeMatcher
|
19
94
|
def initialize(name)
|
20
95
|
@name = name.to_s
|
21
96
|
@options = {}
|