thoughtbot-shoulda 2.10.1 → 2.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CONTRIBUTION_GUIDELINES.rdoc +4 -6
  2. data/README.rdoc +14 -12
  3. data/lib/shoulda.rb +1 -1
  4. data/lib/shoulda/action_controller.rb +0 -2
  5. data/lib/shoulda/action_controller/macros.rb +38 -75
  6. data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +4 -0
  7. data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +1 -1
  8. data/lib/shoulda/action_view/macros.rb +6 -1
  9. data/lib/shoulda/active_record/assertions.rb +4 -4
  10. data/lib/shoulda/active_record/helpers.rb +0 -13
  11. data/lib/shoulda/active_record/macros.rb +50 -127
  12. data/lib/shoulda/active_record/matchers.rb +2 -1
  13. data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +1 -1
  14. data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +5 -5
  15. data/lib/shoulda/active_record/matchers/association_matcher.rb +3 -3
  16. data/lib/shoulda/active_record/matchers/{have_index_matcher.rb → have_db_index_matcher.rb} +15 -8
  17. data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +3 -0
  18. data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +67 -0
  19. data/lib/shoulda/active_record/matchers/validation_matcher.rb +1 -0
  20. data/lib/shoulda/assertions.rb +18 -6
  21. data/lib/shoulda/context.rb +99 -1
  22. data/lib/shoulda/macros.rb +83 -23
  23. data/lib/shoulda/private_helpers.rb +1 -8
  24. data/lib/shoulda/test_unit.rb +3 -0
  25. data/test/fail_macros.rb +6 -1
  26. data/test/functional/posts_controller_test.rb +17 -21
  27. data/test/functional/users_controller_test.rb +1 -1
  28. data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +1 -1
  29. data/test/matchers/active_record/allow_value_matcher_test.rb +24 -1
  30. data/test/matchers/active_record/association_matcher_test.rb +8 -3
  31. data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +1 -1
  32. data/test/matchers/active_record/ensure_length_of_matcher_test.rb +1 -1
  33. data/test/matchers/active_record/have_db_column_matcher_test.rb +1 -1
  34. data/test/matchers/active_record/{have_index_matcher_test.rb → have_db_index_matcher_test.rb} +24 -7
  35. data/test/matchers/active_record/have_named_scope_matcher_test.rb +1 -1
  36. data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +1 -1
  37. data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +1 -1
  38. data/test/matchers/active_record/validate_format_of_matcher_test.rb +39 -0
  39. data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +1 -1
  40. data/test/matchers/active_record/validate_presence_of_matcher_test.rb +1 -1
  41. data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +1 -1
  42. data/test/matchers/controller/assign_to_matcher_test.rb +1 -1
  43. data/test/matchers/controller/filter_param_matcher_test.rb +1 -1
  44. data/test/matchers/controller/render_with_layout_matcher_test.rb +1 -1
  45. data/test/matchers/controller/respond_with_content_type_matcher_test.rb +12 -7
  46. data/test/matchers/controller/respond_with_matcher_test.rb +1 -1
  47. data/test/matchers/controller/route_matcher_test.rb +1 -1
  48. data/test/matchers/controller/set_session_matcher_test.rb +9 -2
  49. data/test/matchers/controller/set_the_flash_matcher.rb +1 -1
  50. data/test/model_builder.rb +1 -1
  51. data/test/other/autoload_macro_test.rb +1 -1
  52. data/test/other/context_test.rb +45 -1
  53. data/test/other/convert_to_should_syntax_test.rb +3 -3
  54. data/test/other/helpers_test.rb +102 -3
  55. data/test/other/private_helpers_test.rb +6 -8
  56. data/test/other/should_test.rb +8 -3
  57. data/test/rails_root/app/controllers/{application.rb → application_controller.rb} +0 -0
  58. data/test/rails_root/app/controllers/posts_controller.rb +1 -0
  59. data/test/rails_root/app/models/pets/cat.rb +7 -0
  60. data/test/rails_root/app/models/profile.rb +2 -0
  61. data/test/rails_root/app/models/registration.rb +2 -0
  62. data/test/rails_root/app/models/user.rb +3 -0
  63. data/test/rails_root/config/boot.rb +6 -5
  64. data/test/rails_root/config/environment.rb +5 -1
  65. data/test/rails_root/db/migrate/20090506203502_create_profiles.rb +12 -0
  66. data/test/rails_root/db/migrate/20090506203536_create_registrations.rb +14 -0
  67. data/test/rails_root/db/migrate/20090513104502_create_cats.rb +12 -0
  68. data/test/rails_root/test/shoulda_macros/custom_macro.rb +1 -1
  69. data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +1 -1
  70. data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +1 -1
  71. data/test/rspec_test.rb +1 -1
  72. data/test/test_helper.rb +3 -10
  73. data/test/unit/address_test.rb +2 -2
  74. data/test/unit/cat_test.rb +7 -0
  75. data/test/unit/dog_test.rb +2 -3
  76. data/test/unit/flea_test.rb +1 -1
  77. data/test/unit/post_test.rb +2 -2
  78. data/test/unit/product_test.rb +2 -6
  79. data/test/unit/tag_test.rb +2 -2
  80. data/test/unit/tagging_test.rb +1 -1
  81. data/test/unit/user_test.rb +18 -8
  82. metadata +16 -10
  83. data/lib/shoulda/action_controller/helpers.rb +0 -47
@@ -0,0 +1,12 @@
1
+ class CreateProfiles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :profiles do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :profiles
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateRegistrations < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :registrations do |t|
4
+ t.integer :user_id
5
+ t.integer :profile_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :registrations
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class CreateCats < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :cats do |t|
4
+ t.column :owner_id, :integer
5
+ t.column :address_id, :integer
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :cats
11
+ end
12
+ end
@@ -2,5 +2,5 @@ module CustomMacro
2
2
  def custom_macro
3
3
  end
4
4
  end
5
- Test::Unit::TestCase.extend(CustomMacro)
5
+ ActiveSupport::TestCase.extend(CustomMacro)
6
6
 
@@ -2,5 +2,5 @@ module GemMacro
2
2
  def gem_macro
3
3
  end
4
4
  end
5
- Test::Unit::TestCase.extend(GemMacro)
5
+ ActiveSupport::TestCase.extend(GemMacro)
6
6
 
@@ -2,5 +2,5 @@ module PluginMacro
2
2
  def plugin_macro
3
3
  end
4
4
  end
5
- Test::Unit::TestCase.extend(PluginMacro)
5
+ ActiveSupport::TestCase.extend(PluginMacro)
6
6
 
@@ -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 < Test::Unit::TestCase
11
+ class RspecTest < ActiveSupport::TestCase
12
12
 
13
13
  SHOULDA_ROOT =
14
14
  File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
@@ -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
- Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__), "fixtures")
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
@@ -1,10 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class AddressTest < Test::Unit::TestCase
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
- should_only_allow_numeric_values_for :zip
9
+ should_validate_numericality_of :zip
10
10
  end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class Pets::CatTest < ActiveSupport::TestCase
4
+ should_belong_to :owner
5
+ should_belong_to :address, :dependent => :destroy
6
+ should_validate_presence_of :owner_id
7
+ end
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class Pets::DogTest < Test::Unit::TestCase
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
- should_require_attributes :treats, :fleas
9
- should_validate_presence_of :owner_id
8
+ should_validate_presence_of :owner_id, :treats, :fleas
10
9
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class FleaTest < Test::Unit::TestCase
3
+ class FleaTest < ActiveSupport::TestCase
4
4
  should_have_and_belong_to_many :dogs
5
5
  end
6
6
 
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class PostTest < Test::Unit::TestCase
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
- should_require_unique_attributes :title
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
@@ -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
- setup do
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
- setup do
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
@@ -1,12 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class TagTest < Test::Unit::TestCase
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
- should_protect_attributes :secret
9
+ should_not_allow_mass_assignment_of :secret
10
10
  should_allow_mass_assignment_of :name
11
11
 
12
12
  should_fail do
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class TaggingTest < Test::Unit::TestCase
3
+ class TaggingTest < ActiveSupport::TestCase
4
4
  should_belong_to :post
5
5
  should_belong_to :tag
6
6
  end
@@ -1,10 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class UserTest < Test::Unit::TestCase
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
- should_have_indices :email, :name
16
+ should_have_db_indices :email, :name
16
17
  should_have_index :age
17
- should_have_index [:email, :name], :unique => true
18
- should_have_index :age, :unique => false
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
- should_have_index :phone
22
- should_have_index :email, :unique => false
23
- should_have_index :age, :unique => true
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: thoughtbot-shoulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.1
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-03-05 00:00:00 -08:00
12
+ date: 2009-07-15 00:00:00 -07:00
13
13
  default_executable: convert_to_should_syntax
14
14
  dependencies: []
15
15
 
@@ -30,7 +30,6 @@ files:
30
30
  - bin/convert_to_should_syntax
31
31
  - lib/shoulda
32
32
  - lib/shoulda/action_controller
33
- - lib/shoulda/action_controller/helpers.rb
34
33
  - lib/shoulda/action_controller/macros.rb
35
34
  - lib/shoulda/action_controller/matchers
36
35
  - lib/shoulda/action_controller/matchers/assign_to_matcher.rb
@@ -60,10 +59,11 @@ files:
60
59
  - lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb
61
60
  - lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb
62
61
  - lib/shoulda/active_record/matchers/have_db_column_matcher.rb
63
- - lib/shoulda/active_record/matchers/have_index_matcher.rb
62
+ - lib/shoulda/active_record/matchers/have_db_index_matcher.rb
64
63
  - lib/shoulda/active_record/matchers/have_named_scope_matcher.rb
65
64
  - lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb
66
65
  - lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
66
+ - lib/shoulda/active_record/matchers/validate_format_of_matcher.rb
67
67
  - lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
68
68
  - lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb
69
69
  - lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb
@@ -106,10 +106,11 @@ files:
106
106
  - test/matchers/active_record/ensure_inclusion_of_matcher_test.rb
107
107
  - test/matchers/active_record/ensure_length_of_matcher_test.rb
108
108
  - test/matchers/active_record/have_db_column_matcher_test.rb
109
- - test/matchers/active_record/have_index_matcher_test.rb
109
+ - test/matchers/active_record/have_db_index_matcher_test.rb
110
110
  - test/matchers/active_record/have_named_scope_matcher_test.rb
111
111
  - test/matchers/active_record/have_readonly_attributes_matcher_test.rb
112
112
  - test/matchers/active_record/validate_acceptance_of_matcher_test.rb
113
+ - test/matchers/active_record/validate_format_of_matcher_test.rb
113
114
  - test/matchers/active_record/validate_numericality_of_matcher_test.rb
114
115
  - test/matchers/active_record/validate_presence_of_matcher_test.rb
115
116
  - test/matchers/active_record/validate_uniqueness_of_matcher_test.rb
@@ -133,7 +134,7 @@ files:
133
134
  - test/rails_root
134
135
  - test/rails_root/app
135
136
  - test/rails_root/app/controllers
136
- - test/rails_root/app/controllers/application.rb
137
+ - test/rails_root/app/controllers/application_controller.rb
137
138
  - test/rails_root/app/controllers/posts_controller.rb
138
139
  - test/rails_root/app/controllers/users_controller.rb
139
140
  - test/rails_root/app/helpers
@@ -145,9 +146,12 @@ files:
145
146
  - test/rails_root/app/models/flea.rb
146
147
  - test/rails_root/app/models/friendship.rb
147
148
  - test/rails_root/app/models/pets
149
+ - test/rails_root/app/models/pets/cat.rb
148
150
  - test/rails_root/app/models/pets/dog.rb
149
151
  - test/rails_root/app/models/post.rb
150
152
  - test/rails_root/app/models/product.rb
153
+ - test/rails_root/app/models/profile.rb
154
+ - test/rails_root/app/models/registration.rb
151
155
  - test/rails_root/app/models/tag.rb
152
156
  - test/rails_root/app/models/tagging.rb
153
157
  - test/rails_root/app/models/treat.rb
@@ -190,10 +194,11 @@ files:
190
194
  - test/rails_root/db/migrate/009_create_products.rb
191
195
  - test/rails_root/db/migrate/010_create_friendships.rb
192
196
  - test/rails_root/db/migrate/011_create_treats.rb
197
+ - test/rails_root/db/migrate/20090506203502_create_profiles.rb
198
+ - test/rails_root/db/migrate/20090506203536_create_registrations.rb
199
+ - test/rails_root/db/migrate/20090513104502_create_cats.rb
193
200
  - test/rails_root/db/schema.rb
194
201
  - test/rails_root/log
195
- - test/rails_root/log/sqlite3.log
196
- - test/rails_root/log/test.log
197
202
  - test/rails_root/public
198
203
  - test/rails_root/public/404.html
199
204
  - test/rails_root/public/422.html
@@ -218,6 +223,7 @@ files:
218
223
  - test/test_helper.rb
219
224
  - test/unit
220
225
  - test/unit/address_test.rb
226
+ - test/unit/cat_test.rb
221
227
  - test/unit/dog_test.rb
222
228
  - test/unit/flea_test.rb
223
229
  - test/unit/friendship_test.rb
@@ -226,7 +232,7 @@ files:
226
232
  - test/unit/tag_test.rb
227
233
  - test/unit/tagging_test.rb
228
234
  - test/unit/user_test.rb
229
- has_rdoc: true
235
+ has_rdoc: false
230
236
  homepage: http://thoughtbot.com/projects/shoulda
231
237
  post_install_message:
232
238
  rdoc_options:
@@ -252,7 +258,7 @@ requirements: []
252
258
  rubyforge_project: shoulda
253
259
  rubygems_version: 1.2.0
254
260
  signing_key:
255
- specification_version: 2
261
+ specification_version: 3
256
262
  summary: Making tests easy on the fingers and eyes
257
263
  test_files: []
258
264
 
@@ -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