shoulda 2.10.1 → 2.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTION_GUIDELINES.rdoc +4 -6
- data/README.rdoc +14 -12
- data/lib/shoulda.rb +1 -1
- data/lib/shoulda/action_controller.rb +0 -2
- data/lib/shoulda/action_controller/macros.rb +38 -75
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +4 -0
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +1 -1
- data/lib/shoulda/action_view/macros.rb +6 -1
- data/lib/shoulda/active_record/assertions.rb +4 -4
- data/lib/shoulda/active_record/helpers.rb +0 -13
- data/lib/shoulda/active_record/macros.rb +50 -127
- data/lib/shoulda/active_record/matchers.rb +2 -1
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +1 -1
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +5 -5
- data/lib/shoulda/active_record/matchers/association_matcher.rb +3 -3
- data/lib/shoulda/active_record/matchers/{have_index_matcher.rb → have_db_index_matcher.rb} +15 -8
- data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +3 -0
- data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +67 -0
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +1 -0
- data/lib/shoulda/assertions.rb +18 -6
- data/lib/shoulda/context.rb +99 -1
- data/lib/shoulda/macros.rb +83 -23
- data/lib/shoulda/private_helpers.rb +1 -8
- data/lib/shoulda/test_unit.rb +3 -0
- data/test/fail_macros.rb +6 -1
- data/test/functional/posts_controller_test.rb +17 -21
- data/test/functional/users_controller_test.rb +1 -1
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/allow_value_matcher_test.rb +24 -1
- data/test/matchers/active_record/association_matcher_test.rb +8 -3
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_db_column_matcher_test.rb +1 -1
- data/test/matchers/active_record/{have_index_matcher_test.rb → have_db_index_matcher_test.rb} +24 -7
- data/test/matchers/active_record/have_named_scope_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_format_of_matcher_test.rb +39 -0
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +1 -1
- data/test/matchers/controller/assign_to_matcher_test.rb +1 -1
- data/test/matchers/controller/filter_param_matcher_test.rb +1 -1
- data/test/matchers/controller/render_with_layout_matcher_test.rb +1 -1
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +12 -7
- data/test/matchers/controller/respond_with_matcher_test.rb +1 -1
- data/test/matchers/controller/route_matcher_test.rb +1 -1
- data/test/matchers/controller/set_session_matcher_test.rb +9 -2
- data/test/matchers/controller/set_the_flash_matcher.rb +1 -1
- data/test/model_builder.rb +1 -1
- data/test/other/autoload_macro_test.rb +1 -1
- data/test/other/context_test.rb +45 -1
- data/test/other/convert_to_should_syntax_test.rb +3 -3
- data/test/other/helpers_test.rb +102 -3
- data/test/other/private_helpers_test.rb +6 -8
- data/test/other/should_test.rb +8 -3
- data/test/rails_root/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/test/rails_root/app/controllers/posts_controller.rb +1 -0
- data/test/rails_root/app/models/pets/cat.rb +7 -0
- data/test/rails_root/app/models/profile.rb +2 -0
- data/test/rails_root/app/models/registration.rb +2 -0
- data/test/rails_root/app/models/user.rb +3 -0
- data/test/rails_root/config/boot.rb +6 -5
- data/test/rails_root/config/environment.rb +5 -1
- data/test/rails_root/db/migrate/20090506203502_create_profiles.rb +12 -0
- data/test/rails_root/db/migrate/20090506203536_create_registrations.rb +14 -0
- data/test/rails_root/db/migrate/20090513104502_create_cats.rb +12 -0
- data/test/rails_root/test/shoulda_macros/custom_macro.rb +1 -1
- data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +1 -1
- data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +1 -1
- data/test/rspec_test.rb +1 -1
- data/test/test_helper.rb +3 -10
- data/test/unit/address_test.rb +2 -2
- data/test/unit/cat_test.rb +7 -0
- data/test/unit/dog_test.rb +2 -3
- data/test/unit/flea_test.rb +1 -1
- data/test/unit/post_test.rb +2 -2
- data/test/unit/product_test.rb +2 -6
- data/test/unit/tag_test.rb +2 -2
- data/test/unit/tagging_test.rb +1 -1
- data/test/unit/user_test.rb +18 -8
- metadata +15 -9
- data/lib/shoulda/action_controller/helpers.rb +0 -47
- data/test/rails_root/log/sqlite3.log +0 -0
- data/test/rails_root/log/test.log +0 -0
data/test/rspec_test.rb
CHANGED
@@ -8,7 +8,7 @@ rescue LoadError => exception
|
|
8
8
|
puts "RSpec integration was not tested because RSpec is not available"
|
9
9
|
else
|
10
10
|
|
11
|
-
class RspecTest <
|
11
|
+
class RspecTest < ActiveSupport::TestCase
|
12
12
|
|
13
13
|
SHOULDA_ROOT =
|
14
14
|
File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
data/test/test_helper.rb
CHANGED
@@ -16,17 +16,10 @@ ActiveRecord::Migration.verbose = false
|
|
16
16
|
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
17
17
|
|
18
18
|
# Setup the fixtures path
|
19
|
-
|
20
|
-
|
21
|
-
class Test::Unit::TestCase #:nodoc:
|
22
|
-
def create_fixtures(*table_names)
|
23
|
-
if block_given?
|
24
|
-
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
25
|
-
else
|
26
|
-
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
27
|
-
end
|
28
|
-
end
|
19
|
+
ActiveSupport::TestCase.fixture_path =
|
20
|
+
File.join(File.dirname(__FILE__), "fixtures")
|
29
21
|
|
22
|
+
class ActiveSupport::TestCase #:nodoc:
|
30
23
|
self.use_transactional_fixtures = false
|
31
24
|
self.use_instantiated_fixtures = false
|
32
25
|
end
|
data/test/unit/address_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class AddressTest <
|
3
|
+
class AddressTest < ActiveSupport::TestCase
|
4
4
|
fixtures :all
|
5
5
|
|
6
6
|
should_belong_to :addressable
|
7
7
|
should_validate_uniqueness_of :title, :scoped_to => [:addressable_id, :addressable_type]
|
8
8
|
should_ensure_length_at_least :zip, 5
|
9
|
-
|
9
|
+
should_validate_numericality_of :zip
|
10
10
|
end
|
data/test/unit/dog_test.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class Pets::DogTest <
|
3
|
+
class Pets::DogTest < ActiveSupport::TestCase
|
4
4
|
should_belong_to :user
|
5
5
|
should_belong_to :address, :dependent => :destroy
|
6
6
|
should_have_many :treats
|
7
7
|
should_have_and_belong_to_many :fleas
|
8
|
-
|
9
|
-
should_validate_presence_of :owner_id
|
8
|
+
should_validate_presence_of :owner_id, :treats, :fleas
|
10
9
|
end
|
data/test/unit/flea_test.rb
CHANGED
data/test/unit/post_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class PostTest <
|
3
|
+
class PostTest < ActiveSupport::TestCase
|
4
4
|
fixtures :all
|
5
5
|
|
6
6
|
should_belong_to :user
|
@@ -8,7 +8,7 @@ class PostTest < Test::Unit::TestCase
|
|
8
8
|
should_have_many :tags, :through => :taggings
|
9
9
|
should_have_many :through_tags, :through => :taggings
|
10
10
|
|
11
|
-
|
11
|
+
should_validate_uniqueness_of :title
|
12
12
|
should_validate_presence_of :body, :message => /wtf/
|
13
13
|
should_validate_presence_of :title
|
14
14
|
should_validate_numericality_of :user_id
|
data/test/unit/product_test.rb
CHANGED
@@ -2,9 +2,7 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
2
2
|
|
3
3
|
class ProductTest < ActiveSupport::TestCase
|
4
4
|
context "An intangible product" do
|
5
|
-
|
6
|
-
@product = Product.new(:tangible => false)
|
7
|
-
end
|
5
|
+
subject { Product.new(:tangible => false) }
|
8
6
|
|
9
7
|
should_validate_presence_of :title
|
10
8
|
should_not_allow_values_for :size, "22"
|
@@ -13,9 +11,7 @@ class ProductTest < ActiveSupport::TestCase
|
|
13
11
|
end
|
14
12
|
|
15
13
|
context "A tangible product" do
|
16
|
-
|
17
|
-
@product = Product.new(:tangible => true)
|
18
|
-
end
|
14
|
+
subject { Product.new(:tangible => true) }
|
19
15
|
|
20
16
|
should_validate_presence_of :price
|
21
17
|
should_ensure_value_in_range :price, 1..9999
|
data/test/unit/tag_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class TagTest <
|
3
|
+
class TagTest < ActiveSupport::TestCase
|
4
4
|
should_have_many :taggings, :dependent => :destroy
|
5
5
|
should_have_many :posts
|
6
6
|
|
7
7
|
should_ensure_length_at_least :name, 2
|
8
8
|
|
9
|
-
|
9
|
+
should_not_allow_mass_assignment_of :secret
|
10
10
|
should_allow_mass_assignment_of :name
|
11
11
|
|
12
12
|
should_fail do
|
data/test/unit/tagging_test.rb
CHANGED
data/test/unit/user_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class UserTest <
|
3
|
+
class UserTest < ActiveSupport::TestCase
|
4
4
|
fixtures :all
|
5
5
|
|
6
6
|
should_have_many :posts
|
7
7
|
should_have_many :dogs
|
8
|
+
should_have_many :cats
|
8
9
|
|
9
10
|
should_have_many :friendships
|
10
11
|
should_have_many :friends
|
@@ -12,15 +13,15 @@ class UserTest < Test::Unit::TestCase
|
|
12
13
|
should_have_one :address
|
13
14
|
should_have_one :address, :dependent => :destroy
|
14
15
|
|
15
|
-
|
16
|
+
should_have_db_indices :email, :name
|
16
17
|
should_have_index :age
|
17
|
-
|
18
|
-
|
18
|
+
should_have_db_index [:email, :name], :unique => true
|
19
|
+
should_have_db_index :age, :unique => false
|
19
20
|
|
20
21
|
should_fail do
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
should_have_db_index :phone
|
23
|
+
should_have_db_index :email, :unique => false
|
24
|
+
should_have_db_index :age, :unique => true
|
24
25
|
end
|
25
26
|
|
26
27
|
should_have_named_scope :old, :conditions => "age > 50"
|
@@ -37,6 +38,9 @@ class UserTest < Test::Unit::TestCase
|
|
37
38
|
|
38
39
|
should_not_allow_values_for :email, "blah", "b lah"
|
39
40
|
should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
|
41
|
+
should_allow_values_for :age, 1, 10, 99
|
42
|
+
should_not_allow_values_for :age, "a", "-"
|
43
|
+
should_not_allow_values_for :ssn, "a", 1234567890
|
40
44
|
should_ensure_length_in_range :email, 1..100
|
41
45
|
should_ensure_value_in_range :age, 1..100, :low_message => /greater/,
|
42
46
|
:high_message => /less/
|
@@ -56,7 +60,6 @@ class UserTest < Test::Unit::TestCase
|
|
56
60
|
should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
|
57
61
|
:null => true, :scale => nil
|
58
62
|
should_validate_acceptance_of :eula
|
59
|
-
should_require_acceptance_of :eula
|
60
63
|
should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false
|
61
64
|
|
62
65
|
should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
|
@@ -67,4 +70,11 @@ class UserTest < Test::Unit::TestCase
|
|
67
70
|
should_fail do
|
68
71
|
should_not_allow_mass_assignment_of :name, :age
|
69
72
|
end
|
73
|
+
|
74
|
+
should_have_one :profile, :through => :registration
|
75
|
+
|
76
|
+
should_fail do
|
77
|
+
should_have_one :profile, :through => :interview
|
78
|
+
should_have_one :address, :through => :registration
|
79
|
+
end
|
70
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.10.
|
4
|
+
version: 2.10.2
|
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: 2009-
|
12
|
+
date: 2009-07-15 00:00:00 -04:00
|
13
13
|
default_executable: convert_to_should_syntax
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,7 +28,6 @@ files:
|
|
28
28
|
- Rakefile
|
29
29
|
- README.rdoc
|
30
30
|
- bin/convert_to_should_syntax
|
31
|
-
- lib/shoulda/action_controller/helpers.rb
|
32
31
|
- lib/shoulda/action_controller/macros.rb
|
33
32
|
- lib/shoulda/action_controller/matchers/assign_to_matcher.rb
|
34
33
|
- lib/shoulda/action_controller/matchers/filter_param_matcher.rb
|
@@ -53,10 +52,11 @@ files:
|
|
53
52
|
- lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb
|
54
53
|
- lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb
|
55
54
|
- lib/shoulda/active_record/matchers/have_db_column_matcher.rb
|
56
|
-
- lib/shoulda/active_record/matchers/
|
55
|
+
- lib/shoulda/active_record/matchers/have_db_index_matcher.rb
|
57
56
|
- lib/shoulda/active_record/matchers/have_named_scope_matcher.rb
|
58
57
|
- lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb
|
59
58
|
- lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
|
59
|
+
- lib/shoulda/active_record/matchers/validate_format_of_matcher.rb
|
60
60
|
- lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
|
61
61
|
- lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb
|
62
62
|
- lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb
|
@@ -94,10 +94,11 @@ files:
|
|
94
94
|
- test/matchers/active_record/ensure_inclusion_of_matcher_test.rb
|
95
95
|
- test/matchers/active_record/ensure_length_of_matcher_test.rb
|
96
96
|
- test/matchers/active_record/have_db_column_matcher_test.rb
|
97
|
-
- test/matchers/active_record/
|
97
|
+
- test/matchers/active_record/have_db_index_matcher_test.rb
|
98
98
|
- test/matchers/active_record/have_named_scope_matcher_test.rb
|
99
99
|
- test/matchers/active_record/have_readonly_attributes_matcher_test.rb
|
100
100
|
- test/matchers/active_record/validate_acceptance_of_matcher_test.rb
|
101
|
+
- test/matchers/active_record/validate_format_of_matcher_test.rb
|
101
102
|
- test/matchers/active_record/validate_numericality_of_matcher_test.rb
|
102
103
|
- test/matchers/active_record/validate_presence_of_matcher_test.rb
|
103
104
|
- test/matchers/active_record/validate_uniqueness_of_matcher_test.rb
|
@@ -116,7 +117,7 @@ files:
|
|
116
117
|
- test/other/helpers_test.rb
|
117
118
|
- test/other/private_helpers_test.rb
|
118
119
|
- test/other/should_test.rb
|
119
|
-
- test/rails_root/app/controllers/
|
120
|
+
- test/rails_root/app/controllers/application_controller.rb
|
120
121
|
- test/rails_root/app/controllers/posts_controller.rb
|
121
122
|
- test/rails_root/app/controllers/users_controller.rb
|
122
123
|
- test/rails_root/app/helpers/application_helper.rb
|
@@ -125,9 +126,12 @@ files:
|
|
125
126
|
- test/rails_root/app/models/address.rb
|
126
127
|
- test/rails_root/app/models/flea.rb
|
127
128
|
- test/rails_root/app/models/friendship.rb
|
129
|
+
- test/rails_root/app/models/pets/cat.rb
|
128
130
|
- test/rails_root/app/models/pets/dog.rb
|
129
131
|
- test/rails_root/app/models/post.rb
|
130
132
|
- test/rails_root/app/models/product.rb
|
133
|
+
- test/rails_root/app/models/profile.rb
|
134
|
+
- test/rails_root/app/models/registration.rb
|
131
135
|
- test/rails_root/app/models/tag.rb
|
132
136
|
- test/rails_root/app/models/tagging.rb
|
133
137
|
- test/rails_root/app/models/treat.rb
|
@@ -161,9 +165,10 @@ files:
|
|
161
165
|
- test/rails_root/db/migrate/009_create_products.rb
|
162
166
|
- test/rails_root/db/migrate/010_create_friendships.rb
|
163
167
|
- test/rails_root/db/migrate/011_create_treats.rb
|
168
|
+
- test/rails_root/db/migrate/20090506203502_create_profiles.rb
|
169
|
+
- test/rails_root/db/migrate/20090506203536_create_registrations.rb
|
170
|
+
- test/rails_root/db/migrate/20090513104502_create_cats.rb
|
164
171
|
- test/rails_root/db/schema.rb
|
165
|
-
- test/rails_root/log/sqlite3.log
|
166
|
-
- test/rails_root/log/test.log
|
167
172
|
- test/rails_root/public/404.html
|
168
173
|
- test/rails_root/public/422.html
|
169
174
|
- test/rails_root/public/500.html
|
@@ -176,6 +181,7 @@ files:
|
|
176
181
|
- test/rspec_test.rb
|
177
182
|
- test/test_helper.rb
|
178
183
|
- test/unit/address_test.rb
|
184
|
+
- test/unit/cat_test.rb
|
179
185
|
- test/unit/dog_test.rb
|
180
186
|
- test/unit/flea_test.rb
|
181
187
|
- test/unit/friendship_test.rb
|
@@ -212,7 +218,7 @@ requirements: []
|
|
212
218
|
rubyforge_project: shoulda
|
213
219
|
rubygems_version: 1.3.5
|
214
220
|
signing_key:
|
215
|
-
specification_version:
|
221
|
+
specification_version: 3
|
216
222
|
summary: Making tests easy on the fingers and eyes
|
217
223
|
test_files: []
|
218
224
|
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Shoulda # :nodoc:
|
2
|
-
module ActionController # :nodoc:
|
3
|
-
module Helpers # :nodoc:
|
4
|
-
private # :enddoc:
|
5
|
-
|
6
|
-
SPECIAL_INSTANCE_VARIABLES = %w{
|
7
|
-
_cookies
|
8
|
-
_flash
|
9
|
-
_headers
|
10
|
-
_params
|
11
|
-
_request
|
12
|
-
_response
|
13
|
-
_session
|
14
|
-
action_name
|
15
|
-
before_filter_chain_aborted
|
16
|
-
cookies
|
17
|
-
flash
|
18
|
-
headers
|
19
|
-
ignore_missing_templates
|
20
|
-
logger
|
21
|
-
params
|
22
|
-
request
|
23
|
-
request_origin
|
24
|
-
response
|
25
|
-
session
|
26
|
-
template
|
27
|
-
template_class
|
28
|
-
template_root
|
29
|
-
url
|
30
|
-
variables_added
|
31
|
-
}.map(&:to_s)
|
32
|
-
|
33
|
-
def instantiate_variables_from_assigns(*names, &blk)
|
34
|
-
old = {}
|
35
|
-
names = (@response.template.assigns.keys - SPECIAL_INSTANCE_VARIABLES) if names.empty?
|
36
|
-
names.each do |name|
|
37
|
-
old[name] = instance_variable_get("@#{name}")
|
38
|
-
instance_variable_set("@#{name}", assigns(name.to_sym))
|
39
|
-
end
|
40
|
-
blk.call
|
41
|
-
names.each do |name|
|
42
|
-
instance_variable_set("@#{name}", old[name])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
File without changes
|
File without changes
|