public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
- added should_require_acceptance_of 
[http://tammer.lighthouseapp.com/projects/5807-shoulda/tickets/6]


git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@290 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Mon Jan 21 07:06:05 -0800 2008
commit  4f4e52f6d4600a17900583695f3e843a2a5b4c36
tree    acb693fba2b61c0a4ebbd90b6dc055c96f4c8dbe
parent  e1af92ed2f73d869c35a7b4c61e938ee390cf335
...
455
456
457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
459
460
...
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
0
@@ -455,6 +455,32 @@ module ThoughtBot # :nodoc:
0
         end
0
       end
0
       
0
+ # Ensures that the model cannot be saved if one of the attributes listed is not accepted.
0
+ #
0
+ # Options:
0
+ # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
+ # Regexp or string. Default = <tt>/must be accepted/</tt>
0
+ #
0
+ # Example:
0
+ # should_require_acceptance_of :eula
0
+ #
0
+ def should_require_acceptance_of(*attributes)
0
+ message = get_options!(attributes, :message)
0
+ message ||= /must be accepted/
0
+ klass = model_class
0
+
0
+ attributes.each do |attribute|
0
+ should "require #{attribute} to be accepted" do
0
+ object = klass.new
0
+ object.send("#{attribute}=", false)
0
+
0
+ assert !object.valid?, "#{klass.name} does not require acceptance of #{attribute}."
0
+ assert object.errors.on(attribute), "#{klass.name} does not require acceptance of #{attribute}."
0
+ assert_contains(object.errors.on(attribute), message)
0
+ end
0
+ end
0
+ end
0
+
0
       private
0
       
0
       include ThoughtBot::Shoulda::Private
...
162
163
164
165
166
167
168
169
...
162
163
164
 
 
165
166
167
0
@@ -162,8 +162,6 @@ module ThoughtBot # :nodoc:
0
           msg += "Body: #{@response.body.first(100).chomp} ..."
0
 
0
           assert_match regex, content_type, msg
0
-
0
- # assert_equal "application/xml", @response.content_type, "Body: #{@response.body.first(100).chomp}..."
0
         end
0
         
0
       end
...
3
4
5
 
6
7
8
 
9
...
3
4
5
6
7
8
9
10
11
0
@@ -3,7 +3,9 @@ class User < ActiveRecord::Base
0
   has_many :dogs, :foreign_key => :owner_id
0
   
0
   attr_protected :password
0
+
0
   validates_format_of :email, :with => /\w*@\w*.com/
0
   validates_length_of :email, :in => 1..100
0
   validates_inclusion_of :age, :in => 1..100
0
+ validates_acceptance_of :eula
0
 end
...
5
6
7
8
 
9
10
11
...
17
18
19
 
20
...
5
6
7
 
8
9
10
11
...
17
18
19
20
21
0
@@ -5,7 +5,7 @@ class UserTest < Test::Unit::TestCase
0
 
0
   should_have_many :posts
0
   should_have_many :dogs
0
-
0
+
0
   should_not_allow_values_for :email, "blah", "b lah"
0
   should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
0
   should_ensure_length_in_range :email, 1..100
0
@@ -17,4 +17,5 @@ class UserTest < Test::Unit::TestCase
0
   should_have_db_column :id, :type => "integer", :primary => true
0
   should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
0
                                 :null => true, :primary => false, :scale => nil, :sql_type => 'varchar(255)'
0
+ should_require_acceptance_of :eula
0
 end

Comments

    No one has commented yet.