shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
@@ -1,111 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher, type: :model do
4
- it 'accepts an existing database column' do
5
- expect(model(nickname: :string)).to have_db_column(:nickname)
6
- end
7
-
8
- it 'rejects a nonexistent database column' do
9
- expect(define_model(:employee).new).not_to have_db_column(:nickname)
10
- end
11
-
12
- context '#of_type' do
13
- it 'accepts a column of correct type' do
14
- expect(model(nickname: :string)).
15
- to have_db_column(:nickname).of_type(:string)
16
- end
17
-
18
- it 'rejects a nonexistent database column' do
19
- expect(define_model(:superhero).new).
20
- not_to have_db_column(:nickname).of_type(:string)
21
- end
22
-
23
- it 'rejects a column of wrong type' do
24
- expect(model(nickname: :integer)).
25
- not_to have_db_column(:nickname).of_type(:string)
26
- end
27
- end
28
-
29
- context 'with precision option' do
30
- it 'accepts a column of correct precision' do
31
- expect(with_table(:salary, :decimal, precision: 5)).
32
- to have_db_column(:salary).with_options(precision: 5)
33
- end
34
-
35
- it 'rejects a column of wrong precision' do
36
- expect(with_table(:salary, :decimal, precision: 6)).
37
- not_to have_db_column(:salary).with_options(precision: 5)
38
- end
39
- end
40
-
41
- context 'with limit option' do
42
- it 'accepts a column of correct limit' do
43
- expect(with_table(:email, :string, limit: 255)).
44
- to have_db_column(:email).with_options(limit: 255)
45
- end
46
-
47
- it 'rejects a column of wrong limit' do
48
- expect(with_table(:email, :string, limit: 100)).
49
- not_to have_db_column(:email).with_options(limit: 255)
50
- end
51
- end
52
-
53
- context 'with default option' do
54
- it 'accepts a column with correct default' do
55
- expect(with_table(:admin, :boolean, default: false)).
56
- to have_db_column(:admin).with_options(default: false)
57
- end
58
-
59
- it 'rejects a column with wrong default' do
60
- expect(with_table(:admin, :boolean, default: true)).
61
- not_to have_db_column(:admin).with_options(default: false)
62
- end
63
- end
64
-
65
- context 'with null option' do
66
- it 'accepts a column of correct null' do
67
- expect(with_table(:admin, :boolean, null: false)).
68
- to have_db_column(:admin).with_options(null: false)
69
- end
70
-
71
- it 'rejects a column of wrong null' do
72
- expect(with_table(:admin, :boolean, null: true)).
73
- not_to have_db_column(:admin).with_options(null: false)
74
- end
75
- end
76
-
77
- context 'with scale option' do
78
- it 'accepts a column of correct scale' do
79
- expect(with_table(:salary, :decimal, precision: 10, scale: 2)).
80
- to have_db_column(:salary).with_options(scale: 2)
81
- end
82
-
83
- it 'rejects a column of wrong scale' do
84
- expect(with_table(:salary, :decimal, precision: 10, scale: 4)).
85
- not_to have_db_column(:salary).with_options(scale: 2)
86
- end
87
- end
88
-
89
- context 'with primary option' do
90
- it 'accepts a column that is primary' do
91
- expect(with_table(:custom_id, :integer, primary: true)).
92
- to have_db_column(:id).with_options(primary: true)
93
- end
94
-
95
- it 'rejects a column that is not primary' do
96
- expect(with_table(:whatever, :integer, primary: false)).
97
- not_to have_db_column(:whatever).with_options(primary: true)
98
- end
99
- end
100
-
101
- def model(options = {})
102
- define_model(:employee, options).new
103
- end
104
-
105
- def with_table(column_name, column_type, options)
106
- create_table 'employees' do |table|
107
- table.__send__(column_type, column_name, options)
108
- end
109
- define_model_class('Employee').new
110
- end
111
- end
@@ -1,85 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher, type: :model do
4
- context 'have_db_index' do
5
- it 'accepts an existing index' do
6
- expect(with_index_on(:age)).to have_db_index(:age)
7
- end
8
-
9
- it 'rejects a nonexistent index' do
10
- expect(define_model(:employee).new).not_to have_db_index(:age)
11
- end
12
- end
13
-
14
- context 'have_db_index with unique option' do
15
- it 'accepts an index of correct unique' do
16
- expect(with_index_on(:ssn, unique: true)).
17
- to have_db_index(:ssn).unique(true)
18
- end
19
-
20
- it 'rejects an index of wrong unique' do
21
- expect(with_index_on(:ssn, unique: false)).
22
- not_to have_db_index(:ssn).unique(true)
23
- end
24
- end
25
-
26
- context 'have_db_index on multiple columns' do
27
- it 'accepts an existing index' do
28
- db_connection = create_table 'geocodings' do |table|
29
- table.integer :geocodable_id
30
- table.string :geocodable_type
31
- end
32
- db_connection.add_index :geocodings, [:geocodable_type, :geocodable_id]
33
- expect(define_model_class('Geocoding').new).
34
- to have_db_index([:geocodable_type, :geocodable_id])
35
- end
36
-
37
- it 'rejects a nonexistent index' do
38
- create_table 'geocodings' do |table|
39
- table.integer :geocodable_id
40
- table.string :geocodable_type
41
- end
42
- expect(define_model_class('Geocoding').new).
43
- not_to have_db_index([:geocodable_type, :geocodable_id])
44
- end
45
- end
46
-
47
- it 'join columns with and when describing multiple columns' do
48
- expect(have_db_index([:user_id, :post_id]).description).to match(/on columns user_id and post_id/)
49
- end
50
-
51
- it 'describes a unique index as unique' do
52
- expect(have_db_index(:user_id).unique(true).description).to match(/a unique index/)
53
- end
54
-
55
- it 'describes a unique index as unique when no argument is given' do
56
- expect(have_db_index(:user_id).unique.description).to match(/a unique index/)
57
- end
58
-
59
- it 'describes a non-unique index as non-unique' do
60
- expect(have_db_index(:user_id).unique(false).description).to match(/a non-unique index/)
61
- end
62
-
63
- it "does not display an index's uniqueness when it's not important" do
64
- expect(have_db_index(:user_id).description).not_to match(/unique/)
65
- end
66
-
67
- it 'allows an IndexDefinition to have a truthy value for unique' do
68
- index_definition = double(
69
- 'ActiveRecord::ConnectionAdapters::IndexDefinition',
70
- unique: 7,
71
- name: :age
72
- )
73
- matcher = have_db_index(:age).unique(true)
74
- allow(matcher).to receive(:matched_index).and_return(index_definition)
75
-
76
- expect(with_index_on(:age)).to matcher
77
- end
78
-
79
- def with_index_on(column_name, index_options = {})
80
- create_table 'employees' do |table|
81
- table.integer column_name
82
- end.add_index(:employees, column_name, index_options)
83
- define_model_class('Employee').new
84
- end
85
- end
@@ -1,41 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher, type: :model do
4
- context 'a read-only attribute' do
5
- it 'accepts' do
6
- expect(with_readonly_attr).to have_readonly_attribute(:attr)
7
- end
8
- end
9
-
10
- context 'an attribute that is not part of the read-only set' do
11
- it 'rejects being read-only' do
12
- model = define_model :example, attr: :string, other: :string do
13
- attr_readonly :attr
14
- end.new
15
-
16
- expect(model).not_to have_readonly_attribute(:other)
17
- end
18
- end
19
-
20
- context 'an attribute on a class with no readonly attributes' do
21
- it 'rejects being read-only' do
22
- expect(define_model(:example, attr: :string).new).
23
- not_to have_readonly_attribute(:attr)
24
- end
25
-
26
- it 'assigns a failure message' do
27
- model = define_model(:example, attr: :string).new
28
- matcher = have_readonly_attribute(:attr)
29
-
30
- matcher.matches?(model)
31
-
32
- expect(matcher.failure_message).not_to be_nil
33
- end
34
- end
35
-
36
- def with_readonly_attr
37
- define_model :example, attr: :string do
38
- attr_readonly :attr
39
- end.new
40
- end
41
- end
@@ -1,169 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- # rubocop:disable Metrics/BlockLength
4
- describe Shoulda::Matchers::ActiveRecord::HaveSecureTokenMatcher,
5
- type: :model do
6
-
7
- if active_record_supports_has_secure_token?
8
- describe '#description' do
9
- it 'returns the message including the name of the default column' do
10
- matcher = have_secure_token
11
- expect(matcher.description).
12
- to eq('have :token as a secure token')
13
- end
14
-
15
- it 'returns the message including the name of a provided column' do
16
- matcher = have_secure_token(:special_token)
17
- expect(matcher.description).
18
- to eq('have :special_token as a secure token')
19
- end
20
- end
21
-
22
- it 'matches when the subject configures has_secure_token with the db' do
23
- create_table(:users) do |t|
24
- t.string :token
25
- t.index :token, unique: true
26
- end
27
-
28
- valid_model = define_model_class(:User) { has_secure_token }
29
-
30
- expect(valid_model.new).to have_secure_token
31
- end
32
-
33
- it 'matches when the subject configures has_secure_token with the db for ' \
34
- 'a custom attribute' do
35
- create_table(:users) do |t|
36
- t.string :auth_token
37
- t.index :auth_token, unique: true
38
- end
39
-
40
- valid_model = define_model_class(:User) { has_secure_token(:auth_token) }
41
- expect(valid_model.new).to have_secure_token(:auth_token)
42
- end
43
-
44
- it 'does not match when missing an token index' do
45
- create_table(:users) do |t|
46
- t.string :token
47
- end
48
-
49
- invalid_model = define_model_class(:User) { has_secure_token }
50
- expected_message =
51
- 'Expected User to have :token as a secure token but the following ' \
52
- 'errors were found: missing unique index for users.token'
53
-
54
- aggregate_failures do
55
- expect(invalid_model.new).not_to have_secure_token
56
- expect { expect(invalid_model.new).to have_secure_token }.
57
- to fail_with_message(expected_message)
58
- end
59
- end
60
-
61
- it 'does not match when missing a token column' do
62
- create_table(:users)
63
- invalid_model = define_model_class(:User) { has_secure_token }
64
-
65
- expected_message =
66
- 'Expected User to have :token as a secure token but the following ' \
67
- 'errors were found: missing expected class and instance methods, ' \
68
- 'missing correct column token:string, missing unique index for ' \
69
- 'users.token'
70
-
71
- aggregate_failures do
72
- expect(invalid_model.new).not_to have_secure_token
73
- expect { expect(invalid_model.new).to have_secure_token }.
74
- to fail_with_message(expected_message)
75
- end
76
- end
77
-
78
- it 'does not match when when lacking has_secure_token' do
79
- create_table(:users) do |t|
80
- t.string :token
81
- t.index :token
82
- end
83
-
84
- invalid_model = define_model_class(:User)
85
-
86
- expected_message =
87
- 'Expected User to have :token as a secure token but the following ' \
88
- 'errors were found: missing expected class and instance methods, ' \
89
- 'missing unique index for users.token'
90
-
91
- aggregate_failures do
92
- expect(invalid_model.new).not_to have_secure_token
93
- expect { expect(invalid_model.new).to have_secure_token }.
94
- to fail_with_message(expected_message)
95
- end
96
- end
97
-
98
- it 'does not match when missing an index for a custom attribute' do
99
- create_table(:users) do |t|
100
- t.string :auth_token
101
- end
102
-
103
- invalid_model = define_model_class(:User) do
104
- has_secure_token(:auth_token)
105
- end
106
-
107
- expected_message =
108
- 'Expected User to have :auth_token as a secure token but the ' \
109
- 'following errors were found: missing unique index for ' \
110
- 'users.auth_token'
111
-
112
- aggregate_failures do
113
- expect(invalid_model.new).not_to have_secure_token(:auth_token)
114
- expect { expect(invalid_model.new).to have_secure_token(:auth_token) }.
115
- to fail_with_message(expected_message)
116
- end
117
- end
118
-
119
- it 'does not match when missing a column for a custom attribute' do
120
- create_table(:users)
121
- invalid_model = define_model_class(:User) do
122
- has_secure_token(:auth_token)
123
- end
124
-
125
- expected_message =
126
- 'Expected User to have :auth_token as a secure token but the ' \
127
- 'following errors were found: missing expected class and instance ' \
128
- 'methods, missing correct column auth_token:string, missing unique ' \
129
- 'index for users.auth_token'
130
-
131
- aggregate_failures do
132
- expect(invalid_model.new).not_to have_secure_token(:auth_token)
133
- expect { expect(invalid_model.new).to have_secure_token(:auth_token) }.
134
- to fail_with_message(expected_message)
135
- end
136
- end
137
-
138
- it 'does not match when when lacking has_secure_token for the attribute' do
139
- create_table(:users) do |t|
140
- t.string :auth_token
141
- t.index :auth_token, unique: true
142
- end
143
-
144
- invalid_model = define_model_class(:User)
145
- expected_message =
146
- 'Expected User to have :auth_token as a secure token but the ' \
147
- 'following errors were found: missing expected class and instance ' \
148
- 'methods'
149
-
150
- aggregate_failures do
151
- expect(invalid_model.new).not_to have_secure_token(:auth_token)
152
- expect { expect(invalid_model.new).to have_secure_token(:auth_token) }.
153
- to fail_with_message(expected_message)
154
- end
155
- end
156
-
157
- it 'fails with the appropriate message when negated' do
158
- create_table(:users) do |t|
159
- t.string :token
160
- t.index :token, unique: true
161
- end
162
-
163
- valid_model = define_model_class(:User) { has_secure_token }
164
-
165
- expect { expect(valid_model.new).not_to have_secure_token }.
166
- to fail_with_message('Did not expect User to have secure token :token')
167
- end
168
- end
169
- end
@@ -1,86 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::SerializeMatcher, type: :model do
4
- it 'accepts when the attribute is serialized' do
5
- expect(with_serialized_attr).to serialize(:attr)
6
- end
7
-
8
- context 'when attribute is not serialized' do
9
- it 'rejects' do
10
- expect(unserialized_model).not_to serialize(:attr)
11
- end
12
-
13
- it 'assigns a helpful failure message' do
14
- matcher = serialize(:attr)
15
-
16
- matcher.matches?(unserialized_model)
17
-
18
- expect(matcher.failure_message).to match(/to serialize the attribute called :attr/)
19
- end
20
-
21
- it 'assigns a helpful failure message when using #as' do
22
- matcher = serialize(:attr).as(Hash)
23
-
24
- matcher.matches?(unserialized_model)
25
-
26
- expect(matcher.failure_message).to match(/with a type of Hash/)
27
- end
28
-
29
- it 'assigns a helpful failure message when using #as_instance_of' do
30
- matcher = serialize(:attr).as_instance_of(Hash)
31
-
32
- matcher.matches?(unserialized_model)
33
-
34
- expect(matcher.failure_message).to match(/with an instance of Hash/)
35
- end
36
-
37
- def unserialized_model
38
- @model ||= define_model(:example, attr: :string).new
39
- end
40
- end
41
-
42
- context 'an attribute that will end up being serialized as YAML' do
43
- it 'accepts when the types match' do
44
- expect(with_serialized_attr(Hash)).to serialize(:attr).as(Hash)
45
- end
46
-
47
- it 'rejects when the types do not match' do
48
- expect(with_serialized_attr(Hash)).not_to serialize(:attr).as(String)
49
- end
50
-
51
- it 'rejects when using as_instance_of' do
52
- expect(with_serialized_attr(Hash)).not_to serialize(:attr).as_instance_of(Hash)
53
- end
54
- end
55
-
56
- context 'a serializer that is an instance of a class' do
57
- it 'accepts when using #as_instance_of' do
58
- define_serializer(:ExampleSerializer)
59
- expect(with_serialized_attr(ExampleSerializer.new)).
60
- to serialize(:attr).as_instance_of(ExampleSerializer)
61
- end
62
-
63
- it 'rejects when using #as' do
64
- define_serializer(:ExampleSerializer)
65
- expect(with_serialized_attr(ExampleSerializer.new)).
66
- not_to serialize(:attr).as(ExampleSerializer)
67
- end
68
- end
69
-
70
- def with_serialized_attr(type = nil)
71
- define_model(:example, attr: :string) do
72
- if type
73
- serialize :attr, type
74
- else
75
- serialize :attr
76
- end
77
- end.new
78
- end
79
-
80
- def define_serializer(name)
81
- define_class(name) do
82
- def load(*); end
83
- def dump(*); end
84
- end
85
- end
86
- end