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.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +8 -0
  5. data/Appraisals +82 -33
  6. data/Gemfile +18 -2
  7. data/Gemfile.lock +13 -1
  8. data/NEWS.md +27 -2
  9. data/README.md +83 -1329
  10. data/Rakefile +118 -1
  11. data/cucumber.yml +1 -0
  12. data/doc_config/gh-pages/index.html.erb +9 -0
  13. data/doc_config/yard/setup.rb +22 -0
  14. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
  15. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
  18. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
  19. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
  20. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
  21. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
  22. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +298 -0
  23. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
  24. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
  25. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
  26. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
  27. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
  28. data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
  29. data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
  30. data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
  31. data/doc_config/yard/templates/default/layout/html/setup.rb +40 -0
  32. data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
  33. data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
  34. data/docs.watchr +5 -0
  35. data/features/rails_integration.feature +32 -0
  36. data/features/step_definitions/rails_steps.rb +55 -9
  37. data/features/support/env.rb +1 -0
  38. data/gemfiles/3.0.gemfile +13 -1
  39. data/gemfiles/3.0.gemfile.lock +13 -1
  40. data/gemfiles/3.1.gemfile +17 -2
  41. data/gemfiles/3.1.gemfile.lock +31 -2
  42. data/gemfiles/3.1_1.9.2.gemfile +33 -0
  43. data/gemfiles/3.1_1.9.2.gemfile.lock +203 -0
  44. data/gemfiles/3.2.gemfile +18 -2
  45. data/gemfiles/3.2.gemfile.lock +32 -2
  46. data/gemfiles/3.2_1.9.2.gemfile +32 -0
  47. data/gemfiles/3.2_1.9.2.gemfile.lock +200 -0
  48. data/gemfiles/4.0.0.gemfile +20 -1
  49. data/gemfiles/4.0.0.gemfile.lock +46 -2
  50. data/gemfiles/4.0.1.gemfile +20 -1
  51. data/gemfiles/4.0.1.gemfile.lock +46 -2
  52. data/gemfiles/4.1.gemfile +21 -2
  53. data/gemfiles/4.1.gemfile.lock +47 -4
  54. data/lib/shoulda/matchers/action_controller.rb +0 -20
  55. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +119 -28
  56. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +22 -6
  57. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +43 -10
  58. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +40 -13
  59. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +63 -11
  60. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +34 -1
  61. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +84 -15
  62. data/lib/shoulda/matchers/action_controller/route_matcher.rb +84 -28
  63. data/lib/shoulda/matchers/action_controller/route_params.rb +4 -3
  64. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +76 -13
  65. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +147 -13
  66. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +148 -2
  67. data/lib/shoulda/matchers/active_model.rb +0 -25
  68. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +66 -9
  69. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +161 -19
  70. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -5
  71. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +92 -13
  72. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +218 -16
  73. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +198 -32
  74. data/lib/shoulda/matchers/active_model/errors.rb +5 -2
  75. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +1 -1
  76. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +29 -8
  77. data/lib/shoulda/matchers/active_model/helpers.rb +20 -8
  78. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  79. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +4 -6
  80. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
  81. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +3 -2
  82. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
  83. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +4 -3
  84. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +52 -14
  85. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +51 -13
  86. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +53 -7
  87. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +275 -19
  88. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +84 -14
  89. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +170 -41
  90. data/lib/shoulda/matchers/active_model/validation_matcher.rb +20 -15
  91. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -2
  92. data/lib/shoulda/matchers/active_record.rb +1 -12
  93. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +89 -15
  94. data/lib/shoulda/matchers/active_record/association_matcher.rb +726 -70
  95. data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  96. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +4 -3
  97. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -3
  98. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +4 -3
  99. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -1
  100. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +4 -3
  101. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +4 -5
  102. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +4 -3
  103. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +4 -3
  104. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +4 -3
  105. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +79 -15
  106. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +64 -15
  107. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +21 -7
  108. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +85 -10
  109. data/lib/shoulda/matchers/assertion_error.rb +7 -1
  110. data/lib/shoulda/matchers/doublespeak.rb +2 -1
  111. data/lib/shoulda/matchers/doublespeak/double.rb +3 -1
  112. data/lib/shoulda/matchers/doublespeak/double_collection.rb +2 -1
  113. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +1 -0
  114. data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
  115. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +2 -1
  116. data/lib/shoulda/matchers/doublespeak/structs.rb +2 -0
  117. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +2 -1
  118. data/lib/shoulda/matchers/doublespeak/world.rb +3 -4
  119. data/lib/shoulda/matchers/error.rb +1 -0
  120. data/lib/shoulda/matchers/independent/delegate_matcher.rb +108 -20
  121. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +4 -3
  122. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +3 -0
  123. data/lib/shoulda/matchers/rails_shim.rb +3 -2
  124. data/lib/shoulda/matchers/version.rb +2 -1
  125. data/lib/shoulda/matchers/warn.rb +1 -0
  126. data/script/SUPPORTED_VERSIONS +1 -0
  127. data/script/install_gems_in_all_appraisals +14 -0
  128. data/script/run_all_tests +14 -0
  129. data/shoulda-matchers.gemspec +0 -10
  130. data/spec/report_warnings.rb +7 -0
  131. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +1 -1
  132. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -0
  133. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -36
  134. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +2 -2
  135. data/spec/shoulda/matchers/doublespeak/double_spec.rb +1 -1
  136. data/spec/shoulda/matchers/doublespeak/world_spec.rb +11 -29
  137. data/spec/shoulda/matchers/doublespeak_spec.rb +3 -3
  138. data/spec/spec_helper.rb +17 -0
  139. data/spec/support/class_builder.rb +4 -0
  140. data/spec/support/test_application.rb +1 -1
  141. data/spec/warnings_spy.rb +64 -0
  142. data/spec/warnings_spy/filesystem.rb +45 -0
  143. data/spec/warnings_spy/partitioner.rb +29 -0
  144. data/spec/warnings_spy/reader.rb +64 -0
  145. data/spec/warnings_spy/reporter.rb +87 -0
  146. metadata +49 -134
@@ -0,0 +1,9 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module ActiveRecord
4
+ # @private
5
+ module AssociationMatchers
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
30
+ protected
30
31
 
31
32
  attr_accessor :subject, :counter_cache, :name
32
33
 
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
30
+ protected
30
31
 
31
32
  attr_accessor :subject, :dependent, :name
32
33
 
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
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
- private
48
+ protected
48
49
 
49
50
  attr_reader :reflection, :subject
50
51
 
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
50
+ protected
50
51
 
51
52
  attr_reader :subject, :name
52
53
 
@@ -1,12 +1,11 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
44
+ protected
46
45
 
47
46
  attr_reader :reflector
48
47
 
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
30
+ protected
30
31
 
31
32
  attr_accessor :subject, :order, :name
32
33
 
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
30
+ protected
30
31
 
31
32
  attr_accessor :subject, :source, :name
32
33
 
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
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
- private
52
+ protected
52
53
 
53
54
  attr_accessor :through, :name, :subject
54
55
 
@@ -1,25 +1,89 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
4
-
5
- # Ensures the database column exists.
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
- # Options:
8
- # * <tt>of_type</tt> - db column type (:integer, :string, etc.)
9
- # * <tt>with_options</tt> - same options available in migrations
10
- # (:default, :null, :limit, :precision, :scale)
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
- # Examples:
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
- class HaveDbColumnMatcher # :nodoc:
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
- expected = "#{model_class.name} to #{description}"
256
+ "#{model_class.name} to #{description}"
193
257
  end
194
258
  end
195
259
  end
@@ -1,27 +1,76 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
4
-
5
- # Ensures that there are DB indices on the given columns or tuples of
6
- # columns.
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
- # Options:
9
- # * <tt>unique</tt> - whether or not the index has a unique
10
- # constraint. Use <tt>true</tt> to explicitly test for a unique
11
- # constraint. Use <tt>false</tt> to explicitly test for a non-unique
12
- # constraint.
56
+ # # RSpec
57
+ # describe Blog do
58
+ # it { should have_db_index(:name).unique }
59
+ # end
13
60
  #
14
- # Examples:
61
+ # # Test::Unit
62
+ # class BlogTest < ActiveSupport::TestCase
63
+ # should have_db_index(:name).unique
64
+ # end
15
65
  #
16
- # it { should have_db_index(:age) }
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
- class HaveDbIndexMatcher # :nodoc:
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 # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
4
-
5
- # Ensures that the attribute cannot be changed once the record has been
6
- # created.
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
- # it { should have_readonly_attribute(:password) }
21
+ # @return [HaveReadonlyAttributeMatcher]
9
22
  #
10
23
  def have_readonly_attribute(value)
11
24
  HaveReadonlyAttributeMatcher.new(value)
12
25
  end
13
26
 
14
- class HaveReadonlyAttributeMatcher # :nodoc:
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 # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveRecord # :nodoc:
4
- # Ensure that the field becomes serialized.
3
+ module ActiveRecord
4
+ # The `serialize` matcher tests usage of the `serialize` macro.
5
5
  #
6
- # Options:
7
- # * <tt>:as</tt> - tests that the serialized attribute makes use of the class_name option.
6
+ # class Product < ActiveRecord::Base
7
+ # serialize :customizations
8
+ # end
8
9
  #
9
- # Example:
10
- # it { should serialize(:details) }
11
- # it { should serialize(:details).as(Hash) }
12
- # it { should serialize(:details).as_instance_of(ExampleSerializer) }
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
- class SerializeMatcher # :nodoc:
92
+ # @private
93
+ class SerializeMatcher
19
94
  def initialize(name)
20
95
  @name = name.to_s
21
96
  @options = {}