shoulda 2.0.6 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/README.rdoc +35 -7
  2. data/Rakefile +5 -3
  3. data/lib/shoulda.rb +7 -15
  4. data/lib/shoulda/action_mailer.rb +1 -1
  5. data/lib/shoulda/action_mailer/assertions.rb +32 -33
  6. data/lib/shoulda/active_record.rb +6 -2
  7. data/lib/shoulda/active_record/assertions.rb +62 -81
  8. data/lib/shoulda/active_record/helpers.rb +40 -0
  9. data/lib/shoulda/active_record/macros.rb +518 -639
  10. data/lib/shoulda/active_record/matchers.rb +42 -0
  11. data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  12. data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  13. data/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  14. data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  15. data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  16. data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  17. data/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  18. data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  19. data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  20. data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  21. data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  22. data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  23. data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  24. data/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  25. data/lib/shoulda/assertions.rb +50 -40
  26. data/lib/shoulda/autoload_macros.rb +46 -0
  27. data/lib/shoulda/context.rb +124 -126
  28. data/lib/shoulda/controller.rb +8 -8
  29. data/lib/shoulda/controller/formats/html.rb +158 -160
  30. data/lib/shoulda/controller/formats/xml.rb +132 -134
  31. data/lib/shoulda/controller/helpers.rb +51 -53
  32. data/lib/shoulda/controller/macros.rb +278 -258
  33. data/lib/shoulda/controller/resource_options.rb +211 -214
  34. data/lib/shoulda/helpers.rb +5 -7
  35. data/lib/shoulda/macros.rb +63 -64
  36. data/lib/shoulda/private_helpers.rb +16 -18
  37. data/lib/shoulda/rails.rb +1 -8
  38. data/lib/shoulda/rspec.rb +5 -0
  39. data/lib/shoulda/tasks/list_tests.rake +6 -1
  40. data/lib/shoulda/test_unit.rb +19 -0
  41. data/rails/init.rb +1 -1
  42. data/test/README +2 -2
  43. data/test/fail_macros.rb +16 -16
  44. data/test/functional/posts_controller_test.rb +5 -2
  45. data/test/matchers/allow_mass_assignment_of_matcher_test.rb +68 -0
  46. data/test/matchers/allow_value_matcher_test.rb +41 -0
  47. data/test/matchers/association_matcher_test.rb +258 -0
  48. data/test/matchers/ensure_inclusion_of_matcher_test.rb +80 -0
  49. data/test/matchers/ensure_length_of_matcher_test.rb +158 -0
  50. data/test/matchers/have_db_column_matcher_test.rb +169 -0
  51. data/test/matchers/have_index_matcher_test.rb +74 -0
  52. data/test/matchers/have_named_scope_matcher_test.rb +65 -0
  53. data/test/matchers/have_readonly_attributes_matcher_test.rb +29 -0
  54. data/test/matchers/validate_acceptance_of_matcher_test.rb +44 -0
  55. data/test/matchers/validate_numericality_of_matcher_test.rb +52 -0
  56. data/test/matchers/validate_presence_of_matcher_test.rb +86 -0
  57. data/test/matchers/validate_uniqueness_of_matcher_test.rb +141 -0
  58. data/test/model_builder.rb +61 -0
  59. data/test/other/autoload_macro_test.rb +18 -0
  60. data/test/other/helpers_test.rb +58 -0
  61. data/test/other/private_helpers_test.rb +1 -1
  62. data/test/other/should_test.rb +16 -16
  63. data/test/rails_root/app/controllers/posts_controller.rb +6 -5
  64. data/test/rails_root/app/models/pets/dog.rb +10 -0
  65. data/test/rails_root/app/models/treat.rb +3 -0
  66. data/test/rails_root/app/models/user.rb +2 -2
  67. data/test/rails_root/app/views/layouts/posts.rhtml +2 -0
  68. data/test/rails_root/config/database.yml +1 -1
  69. data/test/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
  70. data/test/rails_root/db/migrate/001_create_users.rb +3 -2
  71. data/test/rails_root/db/migrate/011_create_treats.rb +12 -0
  72. data/test/rails_root/log/test.log +0 -0
  73. data/test/rails_root/test/shoulda_macros/custom_macro.rb +6 -0
  74. data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
  75. data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
  76. data/test/test_helper.rb +3 -1
  77. data/test/unit/address_test.rb +1 -1
  78. data/test/unit/dog_test.rb +5 -2
  79. data/test/unit/post_test.rb +7 -3
  80. data/test/unit/product_test.rb +2 -2
  81. data/test/unit/tag_test.rb +2 -1
  82. data/test/unit/user_test.rb +17 -8
  83. metadata +44 -4
  84. data/test/rails_root/app/models/dog.rb +0 -5
@@ -1,6 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
2
  has_many :posts
3
- has_many :dogs, :foreign_key => :owner_id
3
+ has_many :dogs, :foreign_key => :owner_id, :class_name => "Pets::Dog"
4
4
 
5
5
  has_many :friendships
6
6
  has_many :friends, :through => :friendships
@@ -22,7 +22,7 @@ class User < ActiveRecord::Base
22
22
  validates_length_of :email, :in => 1..100
23
23
  validates_inclusion_of :age, :in => 1..100
24
24
  validates_acceptance_of :eula
25
- validates_uniqueness_of :email, :scope => :name
25
+ validates_uniqueness_of :email, :scope => :name, :case_sensitive => false
26
26
  validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length"
27
27
  validates_numericality_of :ssn
28
28
  end
@@ -4,6 +4,8 @@
4
4
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
5
  <head>
6
6
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <meta name="description" content="Posts, posts and more posts" />
8
+ <meta name='keywords' content='posts' />
7
9
  <title>Posts: <%= controller.action_name %></title>
8
10
  <%= stylesheet_link_tag 'scaffold' %>
9
11
  </head>
@@ -1,4 +1,4 @@
1
- sqlite3:
1
+ test:
2
2
  :adapter: sqlite3
3
3
  # :dbfile: db/sqlite3.db
4
4
  :dbfile: ":memory:"
@@ -5,11 +5,12 @@ class CreateUsers < ActiveRecord::Migration
5
5
  t.column :email, :string
6
6
  t.column :age, :integer
7
7
  t.column :ssn, :string
8
+ t.column :phone, :string
8
9
  end
9
- add_index :users, :email
10
+ add_index :users, :email, :unique => true
10
11
  add_index :users, :name
11
12
  add_index :users, :age
12
- add_index :users, [:email, :name]
13
+ add_index :users, [:email, :name], :unique => true
13
14
  end
14
15
 
15
16
  def self.down
@@ -0,0 +1,12 @@
1
+ class CreateTreats < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :treats do |t|
4
+ t.integer :dog_id
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :treats
11
+ end
12
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ module CustomMacro
2
+ def custom_macro
3
+ end
4
+ end
5
+ Test::Unit::TestCase.extend(CustomMacro)
6
+
@@ -0,0 +1,6 @@
1
+ module GemMacro
2
+ def gem_macro
3
+ end
4
+ end
5
+ Test::Unit::TestCase.extend(GemMacro)
6
+
@@ -0,0 +1,6 @@
1
+ module PluginMacro
2
+ def plugin_macro
3
+ end
4
+ end
5
+ Test::Unit::TestCase.extend(PluginMacro)
6
+
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 }
@@ -31,22 +39,23 @@ class UserTest < Test::Unit::TestCase
31
39
  should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
32
40
  should_ensure_length_in_range :email, 1..100
33
41
  should_ensure_value_in_range :age, 1..100
34
- should_protect_attributes :password
42
+ should_not_allow_mass_assignment_of :password
35
43
  should_have_class_methods :find, :destroy
36
44
  should_have_instance_methods :email, :age, :email=, :valid?
37
45
  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)'
46
+ should_have_db_column :id, :type => "integer"
47
+ should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
48
+ :null => true, :scale => nil
49
+ should_validate_acceptance_of :eula
41
50
  should_require_acceptance_of :eula
42
- should_require_unique_attributes :email, :scoped_to => :name
51
+ should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false
43
52
 
44
53
  should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
45
- should_only_allow_numeric_values_for :ssn
54
+ should_validate_numericality_of :ssn
46
55
 
47
56
  should_have_readonly_attributes :name
48
57
 
49
58
  should_fail do
50
- should_protect_attributes :name, :age
59
+ should_not_allow_mass_assignment_of :name, :age
51
60
  end
52
61
  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.0.6
4
+ version: 2.9.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 -05:00
12
+ date: 2009-02-03 00:00:00 -05:00
13
13
  default_executable: convert_to_should_syntax
14
14
  dependencies: []
15
15
 
@@ -31,9 +31,26 @@ files:
31
31
  - lib/shoulda/action_mailer/assertions.rb
32
32
  - lib/shoulda/action_mailer.rb
33
33
  - lib/shoulda/active_record/assertions.rb
34
+ - lib/shoulda/active_record/helpers.rb
34
35
  - lib/shoulda/active_record/macros.rb
36
+ - lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb
37
+ - lib/shoulda/active_record/matchers/allow_value_matcher.rb
38
+ - lib/shoulda/active_record/matchers/association_matcher.rb
39
+ - lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb
40
+ - lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb
41
+ - lib/shoulda/active_record/matchers/have_db_column_matcher.rb
42
+ - lib/shoulda/active_record/matchers/have_index_matcher.rb
43
+ - lib/shoulda/active_record/matchers/have_named_scope_matcher.rb
44
+ - lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb
45
+ - lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb
46
+ - lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
47
+ - lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb
48
+ - lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb
49
+ - lib/shoulda/active_record/matchers/validation_matcher.rb
50
+ - lib/shoulda/active_record/matchers.rb
35
51
  - lib/shoulda/active_record.rb
36
52
  - lib/shoulda/assertions.rb
53
+ - lib/shoulda/autoload_macros.rb
37
54
  - lib/shoulda/context.rb
38
55
  - lib/shoulda/controller/formats/html.rb
39
56
  - lib/shoulda/controller/formats/xml.rb
@@ -46,9 +63,11 @@ files:
46
63
  - lib/shoulda/private_helpers.rb
47
64
  - lib/shoulda/proc_extensions.rb
48
65
  - lib/shoulda/rails.rb
66
+ - lib/shoulda/rspec.rb
49
67
  - lib/shoulda/tasks/list_tests.rake
50
68
  - lib/shoulda/tasks/yaml_to_shoulda.rake
51
69
  - lib/shoulda/tasks.rb
70
+ - lib/shoulda/test_unit.rb
52
71
  - lib/shoulda.rb
53
72
  - rails/init.rb
54
73
  - test/fail_macros.rb
@@ -61,6 +80,21 @@ files:
61
80
  - test/fixtures/users.yml
62
81
  - test/functional/posts_controller_test.rb
63
82
  - test/functional/users_controller_test.rb
83
+ - test/matchers/allow_mass_assignment_of_matcher_test.rb
84
+ - test/matchers/allow_value_matcher_test.rb
85
+ - test/matchers/association_matcher_test.rb
86
+ - test/matchers/ensure_inclusion_of_matcher_test.rb
87
+ - test/matchers/ensure_length_of_matcher_test.rb
88
+ - test/matchers/have_db_column_matcher_test.rb
89
+ - test/matchers/have_index_matcher_test.rb
90
+ - test/matchers/have_named_scope_matcher_test.rb
91
+ - test/matchers/have_readonly_attributes_matcher_test.rb
92
+ - test/matchers/validate_acceptance_of_matcher_test.rb
93
+ - test/matchers/validate_numericality_of_matcher_test.rb
94
+ - test/matchers/validate_presence_of_matcher_test.rb
95
+ - test/matchers/validate_uniqueness_of_matcher_test.rb
96
+ - test/model_builder.rb
97
+ - test/other/autoload_macro_test.rb
64
98
  - test/other/context_test.rb
65
99
  - test/other/convert_to_should_syntax_test.rb
66
100
  - test/other/helpers_test.rb
@@ -73,13 +107,14 @@ files:
73
107
  - test/rails_root/app/helpers/posts_helper.rb
74
108
  - test/rails_root/app/helpers/users_helper.rb
75
109
  - test/rails_root/app/models/address.rb
76
- - test/rails_root/app/models/dog.rb
77
110
  - test/rails_root/app/models/flea.rb
78
111
  - test/rails_root/app/models/friendship.rb
112
+ - test/rails_root/app/models/pets/dog.rb
79
113
  - test/rails_root/app/models/post.rb
80
114
  - test/rails_root/app/models/product.rb
81
115
  - test/rails_root/app/models/tag.rb
82
116
  - test/rails_root/app/models/tagging.rb
117
+ - test/rails_root/app/models/treat.rb
83
118
  - test/rails_root/app/models/user.rb
84
119
  - test/rails_root/app/views/layouts/posts.rhtml
85
120
  - test/rails_root/app/views/layouts/users.rhtml
@@ -95,7 +130,7 @@ files:
95
130
  - test/rails_root/config/boot.rb
96
131
  - test/rails_root/config/database.yml
97
132
  - test/rails_root/config/environment.rb
98
- - test/rails_root/config/environments/sqlite3.rb
133
+ - test/rails_root/config/environments/test.rb
99
134
  - test/rails_root/config/initializers/new_rails_defaults.rb
100
135
  - test/rails_root/config/initializers/shoulda.rb
101
136
  - test/rails_root/config/routes.rb
@@ -109,13 +144,18 @@ files:
109
144
  - test/rails_root/db/migrate/008_create_dogs_fleas.rb
110
145
  - test/rails_root/db/migrate/009_create_products.rb
111
146
  - test/rails_root/db/migrate/010_create_friendships.rb
147
+ - test/rails_root/db/migrate/011_create_treats.rb
112
148
  - test/rails_root/db/schema.rb
113
149
  - test/rails_root/log/sqlite3.log
150
+ - test/rails_root/log/test.log
114
151
  - test/rails_root/public/404.html
115
152
  - test/rails_root/public/422.html
116
153
  - test/rails_root/public/500.html
117
154
  - test/rails_root/script/console
118
155
  - test/rails_root/script/generate
156
+ - test/rails_root/test/shoulda_macros/custom_macro.rb
157
+ - test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb
158
+ - test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb
119
159
  - test/README
120
160
  - test/test_helper.rb
121
161
  - test/unit/address_test.rb
@@ -1,5 +0,0 @@
1
- class Dog < ActiveRecord::Base
2
- belongs_to :user, :foreign_key => :owner_id
3
- belongs_to :address
4
- has_and_belongs_to_many :fleas, :join_table => :fleas
5
- end