technicalpickles-shoulda 2.0.6 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.rdoc +61 -11
  2. data/Rakefile +7 -5
  3. data/lib/shoulda.rb +7 -15
  4. data/lib/shoulda/action_controller.rb +28 -0
  5. data/lib/shoulda/action_controller/helpers.rb +47 -0
  6. data/lib/shoulda/action_controller/macros.rb +277 -0
  7. data/lib/shoulda/action_controller/matchers.rb +37 -0
  8. data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  9. data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  10. data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  11. data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
  12. data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +81 -0
  13. data/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  14. data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
  15. data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  16. data/lib/shoulda/action_mailer.rb +1 -1
  17. data/lib/shoulda/action_mailer/assertions.rb +32 -33
  18. data/lib/shoulda/action_view.rb +10 -0
  19. data/lib/shoulda/action_view/macros.rb +56 -0
  20. data/lib/shoulda/active_record.rb +6 -2
  21. data/lib/shoulda/active_record/assertions.rb +62 -81
  22. data/lib/shoulda/active_record/helpers.rb +40 -0
  23. data/lib/shoulda/active_record/macros.rb +514 -640
  24. data/lib/shoulda/active_record/matchers.rb +42 -0
  25. data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  26. data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  27. data/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  28. data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  29. data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  30. data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  31. data/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  32. data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  33. data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  34. data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  35. data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  36. data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  37. data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  38. data/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  39. data/lib/shoulda/assertions.rb +50 -40
  40. data/lib/shoulda/autoload_macros.rb +46 -0
  41. data/lib/shoulda/context.rb +124 -126
  42. data/lib/shoulda/helpers.rb +5 -7
  43. data/lib/shoulda/macros.rb +63 -64
  44. data/lib/shoulda/private_helpers.rb +16 -18
  45. data/lib/shoulda/rails.rb +5 -11
  46. data/lib/shoulda/rspec.rb +11 -0
  47. data/lib/shoulda/tasks/list_tests.rake +6 -1
  48. data/lib/shoulda/test_unit.rb +19 -0
  49. data/rails/init.rb +7 -1
  50. data/test/README +2 -2
  51. data/test/fail_macros.rb +16 -16
  52. data/test/functional/posts_controller_test.rb +33 -24
  53. data/test/functional/users_controller_test.rb +0 -19
  54. data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +68 -0
  55. data/test/matchers/active_record/allow_value_matcher_test.rb +41 -0
  56. data/test/matchers/active_record/association_matcher_test.rb +258 -0
  57. data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +80 -0
  58. data/test/matchers/active_record/ensure_length_of_matcher_test.rb +158 -0
  59. data/test/matchers/active_record/have_db_column_matcher_test.rb +169 -0
  60. data/test/matchers/active_record/have_index_matcher_test.rb +74 -0
  61. data/test/matchers/active_record/have_named_scope_matcher_test.rb +65 -0
  62. data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +29 -0
  63. data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +44 -0
  64. data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +52 -0
  65. data/test/matchers/active_record/validate_presence_of_matcher_test.rb +86 -0
  66. data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +147 -0
  67. data/test/matchers/controller/assign_to_matcher_test.rb +35 -0
  68. data/test/matchers/controller/filter_param_matcher_test.rb +32 -0
  69. data/test/matchers/controller/render_with_layout_matcher_test.rb +33 -0
  70. data/test/matchers/controller/respond_with_content_type_matcher_test.rb +27 -0
  71. data/test/matchers/controller/respond_with_matcher_test.rb +106 -0
  72. data/test/matchers/controller/route_matcher_test.rb +58 -0
  73. data/test/matchers/controller/set_session_matcher_test.rb +27 -0
  74. data/test/matchers/controller/set_the_flash_matcher.rb +41 -0
  75. data/test/model_builder.rb +106 -0
  76. data/test/other/autoload_macro_test.rb +18 -0
  77. data/test/other/helpers_test.rb +58 -0
  78. data/test/other/private_helpers_test.rb +1 -1
  79. data/test/other/should_test.rb +16 -16
  80. data/test/rails_root/app/controllers/posts_controller.rb +6 -5
  81. data/test/rails_root/app/models/pets/dog.rb +10 -0
  82. data/test/rails_root/app/models/treat.rb +3 -0
  83. data/test/rails_root/app/models/user.rb +4 -3
  84. data/test/rails_root/app/views/layouts/posts.rhtml +2 -0
  85. data/test/rails_root/config/database.yml +1 -1
  86. data/test/rails_root/config/environment.rb +1 -1
  87. data/test/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
  88. data/test/rails_root/db/migrate/001_create_users.rb +3 -2
  89. data/test/rails_root/db/migrate/011_create_treats.rb +12 -0
  90. data/test/rails_root/test/shoulda_macros/custom_macro.rb +6 -0
  91. data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
  92. data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
  93. data/test/rspec_test.rb +207 -0
  94. data/test/test_helper.rb +3 -1
  95. data/test/unit/address_test.rb +1 -1
  96. data/test/unit/dog_test.rb +5 -2
  97. data/test/unit/post_test.rb +7 -3
  98. data/test/unit/product_test.rb +2 -2
  99. data/test/unit/tag_test.rb +2 -1
  100. data/test/unit/user_test.rb +27 -9
  101. metadata +82 -13
  102. data/lib/shoulda/controller.rb +0 -30
  103. data/lib/shoulda/controller/formats/html.rb +0 -201
  104. data/lib/shoulda/controller/formats/xml.rb +0 -170
  105. data/lib/shoulda/controller/helpers.rb +0 -64
  106. data/lib/shoulda/controller/macros.rb +0 -316
  107. data/lib/shoulda/controller/resource_options.rb +0 -236
  108. data/test/rails_root/app/models/dog.rb +0 -5
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
+
2
3
  # Load the environment
3
- ENV['RAILS_ENV'] = 'sqlite3'
4
+ ENV['RAILS_ENV'] = 'test'
4
5
 
5
6
  rails_root = File.dirname(__FILE__) + '/rails_root'
6
7
 
@@ -31,3 +32,4 @@ class Test::Unit::TestCase #:nodoc:
31
32
  end
32
33
 
33
34
  require 'test/fail_macros'
35
+ require 'test/model_builder'
@@ -4,7 +4,7 @@ class AddressTest < Test::Unit::TestCase
4
4
  fixtures :all
5
5
 
6
6
  should_belong_to :addressable
7
- should_require_unique_attributes :title, :scoped_to => [:addressable_id, :addressable_type]
7
+ should_validate_uniqueness_of :title, :scoped_to => [:addressable_id, :addressable_type]
8
8
  should_ensure_length_at_least :zip, 5
9
9
  should_only_allow_numeric_values_for :zip
10
10
  end
@@ -1,7 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class DogTest < Test::Unit::TestCase
3
+ class Pets::DogTest < Test::Unit::TestCase
4
4
  should_belong_to :user
5
- should_belong_to :address
5
+ should_belong_to :address, :dependent => :destroy
6
+ should_have_many :treats
6
7
  should_have_and_belong_to_many :fleas
8
+ should_require_attributes :treats, :fleas
9
+ should_validate_presence_of :owner_id
7
10
  end
@@ -9,7 +9,11 @@ class PostTest < Test::Unit::TestCase
9
9
  should_have_many :through_tags, :through => :taggings
10
10
 
11
11
  should_require_unique_attributes :title
12
- should_require_attributes :body, :message => /wtf/
13
- should_require_attributes :title
14
- should_only_allow_numeric_values_for :user_id
12
+ should_validate_presence_of :body, :message => /wtf/
13
+ should_validate_presence_of :title
14
+ should_validate_numericality_of :user_id
15
+
16
+ should_fail do
17
+ should_validate_uniqueness_of :title, :case_sensitive => false
18
+ end
15
19
  end
@@ -6,7 +6,7 @@ class ProductTest < ActiveSupport::TestCase
6
6
  @product = Product.new(:tangible => false)
7
7
  end
8
8
 
9
- should_require_attributes :title
9
+ should_validate_presence_of :title
10
10
  should_not_allow_values_for :size, "22"
11
11
  should_allow_values_for :size, "22kb"
12
12
  should_ensure_value_in_range :price, 0..99
@@ -17,7 +17,7 @@ class ProductTest < ActiveSupport::TestCase
17
17
  @product = Product.new(:tangible => true)
18
18
  end
19
19
 
20
- should_require_attributes :price
20
+ should_validate_presence_of :price
21
21
  should_ensure_value_in_range :price, 1..9999
22
22
  should_ensure_value_in_range :weight, 1..100
23
23
  should_not_allow_values_for :size, "22", "10x15"
@@ -7,8 +7,9 @@ class TagTest < Test::Unit::TestCase
7
7
  should_ensure_length_at_least :name, 2
8
8
 
9
9
  should_protect_attributes :secret
10
+ should_allow_mass_assignment_of :name
10
11
 
11
12
  should_fail do
12
- should_protect_attributes :name
13
+ should_not_allow_mass_assignment_of :name
13
14
  end
14
15
  end
@@ -12,8 +12,16 @@ class UserTest < Test::Unit::TestCase
12
12
  should_have_one :address
13
13
  should_have_one :address, :dependent => :destroy
14
14
 
15
- should_have_indices :email, :name, [:email, :name]
15
+ should_have_indices :email, :name
16
16
  should_have_index :age
17
+ should_have_index [:email, :name], :unique => true
18
+ should_have_index :age, :unique => false
19
+
20
+ should_fail do
21
+ should_have_index :phone
22
+ should_have_index :email, :unique => false
23
+ should_have_index :age, :unique => true
24
+ end
17
25
 
18
26
  should_have_named_scope :old, :conditions => "age > 50"
19
27
  should_have_named_scope :eighteen, :conditions => { :age => 18 }
@@ -30,23 +38,33 @@ class UserTest < Test::Unit::TestCase
30
38
  should_not_allow_values_for :email, "blah", "b lah"
31
39
  should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
32
40
  should_ensure_length_in_range :email, 1..100
33
- should_ensure_value_in_range :age, 1..100
34
- should_protect_attributes :password
41
+ should_ensure_value_in_range :age, 1..100, :low_message => /greater/,
42
+ :high_message => /less/
43
+ should_fail do
44
+ should_ensure_value_in_range :age, 1..100, :low_message => /more/,
45
+ :high_message => /less/
46
+ end
47
+ should_fail do
48
+ should_ensure_value_in_range :age, 1..100, :low_message => /greater/,
49
+ :high_message => /fewer/
50
+ end
51
+ should_not_allow_mass_assignment_of :password
35
52
  should_have_class_methods :find, :destroy
36
53
  should_have_instance_methods :email, :age, :email=, :valid?
37
54
  should_have_db_columns :name, :email, :age
38
- should_have_db_column :id, :type => "integer", :primary => true
39
- should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
40
- :null => true, :primary => false, :scale => nil, :sql_type => 'varchar(255)'
55
+ should_have_db_column :id, :type => "integer"
56
+ should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
57
+ :null => true, :scale => nil
58
+ should_validate_acceptance_of :eula
41
59
  should_require_acceptance_of :eula
42
- should_require_unique_attributes :email, :scoped_to => :name
60
+ should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false
43
61
 
44
62
  should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
45
- should_only_allow_numeric_values_for :ssn
63
+ should_validate_numericality_of :ssn
46
64
 
47
65
  should_have_readonly_attributes :name
48
66
 
49
67
  should_fail do
50
- should_protect_attributes :name, :age
68
+ should_not_allow_mass_assignment_of :name, :age
51
69
  end
52
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technicalpickles-shoulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammer Saleh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-10 00:00:00 -08:00
12
+ date: 2009-03-04 00:00:00 -08:00
13
13
  default_executable: convert_to_should_syntax
14
14
  dependencies: []
15
15
 
@@ -29,32 +29,61 @@ files:
29
29
  - README.rdoc
30
30
  - bin/convert_to_should_syntax
31
31
  - lib/shoulda
32
+ - lib/shoulda/action_controller
33
+ - lib/shoulda/action_controller/helpers.rb
34
+ - lib/shoulda/action_controller/macros.rb
35
+ - lib/shoulda/action_controller/matchers
36
+ - lib/shoulda/action_controller/matchers/assign_to_matcher.rb
37
+ - lib/shoulda/action_controller/matchers/filter_param_matcher.rb
38
+ - lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
39
+ - lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb
40
+ - lib/shoulda/action_controller/matchers/respond_with_matcher.rb
41
+ - lib/shoulda/action_controller/matchers/route_matcher.rb
42
+ - lib/shoulda/action_controller/matchers/set_session_matcher.rb
43
+ - lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb
44
+ - lib/shoulda/action_controller/matchers.rb
45
+ - lib/shoulda/action_controller.rb
32
46
  - lib/shoulda/action_mailer
33
47
  - lib/shoulda/action_mailer/assertions.rb
34
48
  - lib/shoulda/action_mailer.rb
49
+ - lib/shoulda/action_view
50
+ - lib/shoulda/action_view/macros.rb
51
+ - lib/shoulda/action_view.rb
35
52
  - lib/shoulda/active_record
36
53
  - lib/shoulda/active_record/assertions.rb
54
+ - lib/shoulda/active_record/helpers.rb
37
55
  - lib/shoulda/active_record/macros.rb
56
+ - lib/shoulda/active_record/matchers
57
+ - lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb
58
+ - lib/shoulda/active_record/matchers/allow_value_matcher.rb
59
+ - lib/shoulda/active_record/matchers/association_matcher.rb
60
+ - lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb
61
+ - lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb
62
+ - lib/shoulda/active_record/matchers/have_db_column_matcher.rb
63
+ - lib/shoulda/active_record/matchers/have_index_matcher.rb
64
+ - lib/shoulda/active_record/matchers/have_named_scope_matcher.rb
65
+ - lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb
66
+ - lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
67
+ - lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
68
+ - lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb
69
+ - lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb
70
+ - lib/shoulda/active_record/matchers/validation_matcher.rb
71
+ - lib/shoulda/active_record/matchers.rb
38
72
  - lib/shoulda/active_record.rb
39
73
  - lib/shoulda/assertions.rb
74
+ - lib/shoulda/autoload_macros.rb
40
75
  - lib/shoulda/context.rb
41
- - lib/shoulda/controller
42
- - lib/shoulda/controller/formats
43
- - lib/shoulda/controller/formats/html.rb
44
- - lib/shoulda/controller/formats/xml.rb
45
- - lib/shoulda/controller/helpers.rb
46
- - lib/shoulda/controller/macros.rb
47
- - lib/shoulda/controller/resource_options.rb
48
- - lib/shoulda/controller.rb
49
76
  - lib/shoulda/helpers.rb
50
77
  - lib/shoulda/macros.rb
51
78
  - lib/shoulda/private_helpers.rb
52
79
  - lib/shoulda/proc_extensions.rb
53
80
  - lib/shoulda/rails.rb
81
+ - lib/shoulda/rspec.rb
54
82
  - lib/shoulda/tasks
55
83
  - lib/shoulda/tasks/list_tests.rake
56
84
  - lib/shoulda/tasks/yaml_to_shoulda.rake
57
85
  - lib/shoulda/tasks.rb
86
+ - lib/shoulda/test_unit.rb
58
87
  - lib/shoulda.rb
59
88
  - rails/init.rb
60
89
  - test/fail_macros.rb
@@ -69,7 +98,33 @@ files:
69
98
  - test/functional
70
99
  - test/functional/posts_controller_test.rb
71
100
  - test/functional/users_controller_test.rb
101
+ - test/matchers
102
+ - test/matchers/active_record
103
+ - test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
104
+ - test/matchers/active_record/allow_value_matcher_test.rb
105
+ - test/matchers/active_record/association_matcher_test.rb
106
+ - test/matchers/active_record/ensure_inclusion_of_matcher_test.rb
107
+ - test/matchers/active_record/ensure_length_of_matcher_test.rb
108
+ - test/matchers/active_record/have_db_column_matcher_test.rb
109
+ - test/matchers/active_record/have_index_matcher_test.rb
110
+ - test/matchers/active_record/have_named_scope_matcher_test.rb
111
+ - test/matchers/active_record/have_readonly_attributes_matcher_test.rb
112
+ - test/matchers/active_record/validate_acceptance_of_matcher_test.rb
113
+ - test/matchers/active_record/validate_numericality_of_matcher_test.rb
114
+ - test/matchers/active_record/validate_presence_of_matcher_test.rb
115
+ - test/matchers/active_record/validate_uniqueness_of_matcher_test.rb
116
+ - test/matchers/controller
117
+ - test/matchers/controller/assign_to_matcher_test.rb
118
+ - test/matchers/controller/filter_param_matcher_test.rb
119
+ - test/matchers/controller/render_with_layout_matcher_test.rb
120
+ - test/matchers/controller/respond_with_content_type_matcher_test.rb
121
+ - test/matchers/controller/respond_with_matcher_test.rb
122
+ - test/matchers/controller/route_matcher_test.rb
123
+ - test/matchers/controller/set_session_matcher_test.rb
124
+ - test/matchers/controller/set_the_flash_matcher.rb
125
+ - test/model_builder.rb
72
126
  - test/other
127
+ - test/other/autoload_macro_test.rb
73
128
  - test/other/context_test.rb
74
129
  - test/other/convert_to_should_syntax_test.rb
75
130
  - test/other/helpers_test.rb
@@ -87,13 +142,15 @@ files:
87
142
  - test/rails_root/app/helpers/users_helper.rb
88
143
  - test/rails_root/app/models
89
144
  - test/rails_root/app/models/address.rb
90
- - test/rails_root/app/models/dog.rb
91
145
  - test/rails_root/app/models/flea.rb
92
146
  - test/rails_root/app/models/friendship.rb
147
+ - test/rails_root/app/models/pets
148
+ - test/rails_root/app/models/pets/dog.rb
93
149
  - test/rails_root/app/models/post.rb
94
150
  - test/rails_root/app/models/product.rb
95
151
  - test/rails_root/app/models/tag.rb
96
152
  - test/rails_root/app/models/tagging.rb
153
+ - test/rails_root/app/models/treat.rb
97
154
  - test/rails_root/app/models/user.rb
98
155
  - test/rails_root/app/views
99
156
  - test/rails_root/app/views/layouts
@@ -115,7 +172,7 @@ files:
115
172
  - test/rails_root/config/database.yml
116
173
  - test/rails_root/config/environment.rb
117
174
  - test/rails_root/config/environments
118
- - test/rails_root/config/environments/sqlite3.rb
175
+ - test/rails_root/config/environments/test.rb
119
176
  - test/rails_root/config/initializers
120
177
  - test/rails_root/config/initializers/new_rails_defaults.rb
121
178
  - test/rails_root/config/initializers/shoulda.rb
@@ -132,9 +189,11 @@ files:
132
189
  - test/rails_root/db/migrate/008_create_dogs_fleas.rb
133
190
  - test/rails_root/db/migrate/009_create_products.rb
134
191
  - test/rails_root/db/migrate/010_create_friendships.rb
192
+ - test/rails_root/db/migrate/011_create_treats.rb
135
193
  - test/rails_root/db/schema.rb
136
194
  - test/rails_root/log
137
195
  - test/rails_root/log/sqlite3.log
196
+ - test/rails_root/log/test.log
138
197
  - test/rails_root/public
139
198
  - test/rails_root/public/404.html
140
199
  - test/rails_root/public/422.html
@@ -142,9 +201,20 @@ files:
142
201
  - test/rails_root/script
143
202
  - test/rails_root/script/console
144
203
  - test/rails_root/script/generate
204
+ - test/rails_root/test
205
+ - test/rails_root/test/shoulda_macros
206
+ - test/rails_root/test/shoulda_macros/custom_macro.rb
145
207
  - test/rails_root/vendor
208
+ - test/rails_root/vendor/gems
209
+ - test/rails_root/vendor/gems/gem_with_macro-0.0.1
210
+ - test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros
211
+ - test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb
146
212
  - test/rails_root/vendor/plugins
213
+ - test/rails_root/vendor/plugins/plugin_with_macro
214
+ - test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros
215
+ - test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb
147
216
  - test/README
217
+ - test/rspec_test.rb
148
218
  - test/test_helper.rb
149
219
  - test/unit
150
220
  - test/unit/address_test.rb
@@ -161,7 +231,6 @@ homepage: http://thoughtbot.com/projects/shoulda
161
231
  post_install_message:
162
232
  rdoc_options:
163
233
  - --line-numbers
164
- - --inline-source
165
234
  - --main
166
235
  - README.rdoc
167
236
  require_paths:
@@ -1,30 +0,0 @@
1
- require 'shoulda'
2
- require 'shoulda/controller/helpers'
3
- require 'shoulda/controller/resource_options'
4
- require 'shoulda/controller/macros'
5
-
6
- module Test # :nodoc: all
7
- module Unit
8
- class TestCase
9
- extend ThoughtBot::Shoulda::Controller::Macros
10
- include ThoughtBot::Shoulda::Controller::Helpers
11
- ThoughtBot::Shoulda::Controller::VALID_FORMATS.each do |format|
12
- include "ThoughtBot::Shoulda::Controller::#{format.to_s.upcase}".constantize
13
- end
14
- end
15
- end
16
- end
17
-
18
- require 'shoulda/active_record/assertions'
19
- require 'shoulda/action_mailer/assertions'
20
-
21
- module ActionController #:nodoc: all
22
- module Integration
23
- class Session
24
- include ThoughtBot::Shoulda::Assertions
25
- include ThoughtBot::Shoulda::Helpers
26
- include ThoughtBot::Shoulda::ActiveRecord::Assertions
27
- include ThoughtBot::Shoulda::ActionMailer::Assertions
28
- end
29
- end
30
- end
@@ -1,201 +0,0 @@
1
- module ThoughtBot # :nodoc:
2
- module Shoulda # :nodoc:
3
- module Controller # :nodoc:
4
- module HTML # :nodoc: all
5
- def self.included(other)
6
- other.class_eval do
7
- extend ThoughtBot::Shoulda::Controller::HTML::ClassMethods
8
- end
9
- end
10
-
11
- module ClassMethods
12
- def controller_name_from_class
13
- self.name.gsub(/Test/, '')
14
- end
15
-
16
- def make_show_html_tests(res)
17
- context "on GET to #{controller_name_from_class}#show" do
18
- setup do
19
- record = get_existing_record(res)
20
- parent_params = make_parent_params(res, record)
21
- get :show, parent_params.merge({ res.identifier => record.to_param })
22
- end
23
-
24
- if res.denied.actions.include?(:show)
25
- should_not_assign_to res.object
26
- should_redirect_to res.denied.redirect
27
- should_set_the_flash_to res.denied.flash
28
- else
29
- should_assign_to res.object
30
- should_respond_with :success
31
- should_render_template :show
32
- should_not_set_the_flash
33
- end
34
- end
35
- end
36
-
37
- def make_edit_html_tests(res)
38
- context "on GET to #{controller_name_from_class}#edit" do
39
- setup do
40
- @record = get_existing_record(res)
41
- parent_params = make_parent_params(res, @record)
42
- get :edit, parent_params.merge({ res.identifier => @record.to_param })
43
- end
44
-
45
- if res.denied.actions.include?(:edit)
46
- should_not_assign_to res.object
47
- should_redirect_to res.denied.redirect
48
- should_set_the_flash_to res.denied.flash
49
- else
50
- should_assign_to res.object
51
- should_respond_with :success
52
- should_render_template :edit
53
- should_not_set_the_flash
54
- should_render_a_form
55
- should "set @#{res.object} to requested instance" do
56
- assert_equal @record, assigns(res.object)
57
- end
58
- end
59
- end
60
- end
61
-
62
- def make_index_html_tests(res)
63
- context "on GET to #{controller_name_from_class}#index" do
64
- setup do
65
- record = get_existing_record(res) rescue nil
66
- parent_params = make_parent_params(res, record)
67
- get(:index, parent_params)
68
- end
69
-
70
- if res.denied.actions.include?(:index)
71
- should_not_assign_to res.object.to_s.pluralize
72
- should_redirect_to res.denied.redirect
73
- should_set_the_flash_to res.denied.flash
74
- else
75
- should_respond_with :success
76
- should_assign_to res.object.to_s.pluralize
77
- should_render_template :index
78
- should_not_set_the_flash
79
- end
80
- end
81
- end
82
-
83
- def make_new_html_tests(res)
84
- context "on GET to #{controller_name_from_class}#new" do
85
- setup do
86
- record = get_existing_record(res) rescue nil
87
- parent_params = make_parent_params(res, record)
88
- get(:new, parent_params)
89
- end
90
-
91
- if res.denied.actions.include?(:new)
92
- should_not_assign_to res.object
93
- should_redirect_to res.denied.redirect
94
- should_set_the_flash_to res.denied.flash
95
- else
96
- should_respond_with :success
97
- should_assign_to res.object
98
- should_not_set_the_flash
99
- should_render_template :new
100
- should_render_a_form
101
- end
102
- end
103
- end
104
-
105
- def make_destroy_html_tests(res)
106
- context "on DELETE to #{controller_name_from_class}#destroy" do
107
- setup do
108
- @record = get_existing_record(res)
109
- parent_params = make_parent_params(res, @record)
110
- delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
111
- end
112
-
113
- if res.denied.actions.include?(:destroy)
114
- should_redirect_to res.denied.redirect
115
- should_set_the_flash_to res.denied.flash
116
-
117
- should "not destroy record" do
118
- assert_nothing_raised { assert @record.reload }
119
- end
120
- else
121
- should_set_the_flash_to res.destroy.flash
122
- if res.destroy.redirect.is_a? Symbol
123
- should_respond_with res.destroy.redirect
124
- else
125
- should_redirect_to res.destroy.redirect
126
- end
127
-
128
- should "destroy record" do
129
- assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
130
- @record.reload
131
- end
132
- end
133
- end
134
- end
135
- end
136
-
137
- def make_create_html_tests(res)
138
- context "on POST to #{controller_name_from_class}#create with #{res.create.params.inspect}" do
139
- setup do
140
- record = get_existing_record(res) rescue nil
141
- parent_params = make_parent_params(res, record)
142
- @count = res.klass.count
143
- post :create, parent_params.merge(res.object => res.create.params)
144
- end
145
-
146
- if res.denied.actions.include?(:create)
147
- should_redirect_to res.denied.redirect
148
- should_set_the_flash_to res.denied.flash
149
- should_not_assign_to res.object
150
-
151
- should "not create new record" do
152
- assert_equal @count, res.klass.count
153
- end
154
- else
155
- should_assign_to res.object
156
- should_set_the_flash_to res.create.flash
157
- if res.create.redirect.is_a? Symbol
158
- should_respond_with res.create.redirect
159
- else
160
- should_redirect_to res.create.redirect
161
- end
162
-
163
- should "not have errors on @#{res.object}" do
164
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
165
- end
166
- end
167
- end
168
- end
169
-
170
- def make_update_html_tests(res)
171
- context "on PUT to #{controller_name_from_class}#update with #{res.create.params.inspect}" do
172
- setup do
173
- @record = get_existing_record(res)
174
- parent_params = make_parent_params(res, @record)
175
- put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
176
- end
177
-
178
- if res.denied.actions.include?(:update)
179
- should_not_assign_to res.object
180
- should_redirect_to res.denied.redirect
181
- should_set_the_flash_to res.denied.flash
182
- else
183
- should_assign_to res.object
184
- should_set_the_flash_to(res.update.flash)
185
- if res.update.redirect.is_a? Symbol
186
- should_respond_with res.update.redirect
187
- else
188
- should_redirect_to res.update.redirect
189
- end
190
-
191
- should "not have errors on @#{res.object}" do
192
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
193
- end
194
- end
195
- end
196
- end
197
- end
198
- end
199
- end
200
- end
201
- end