0
@@ -101,14 +101,10 @@ module ThoughtBot # :nodoc:
0
attributes.each do |attribute|
0
attribute = attribute.to_sym
0
- should "not allow #{attribute} to be changed by update" do
0
- assert object = klass.find(:first), "Can't find first #{klass}"
0
- value = object[attribute]
0
- # TODO: 1 may not be a valid value for the attribute (due to validations)
0
- assert object.update_attributes({ attribute => 1 }),
0
- "Cannot update #{klass} with { :#{attribute} => 1 }, #{object.errors.full_messages.to_sentence}"
0
- assert object.valid?, "#{klass} isn't valid after changing #{attribute}"
0
- assert_equal value, object[attribute], "Was able to change #{klass}##{attribute}"
0
+ should "protect #{attribute} from mass updates" do
0
+ protected = klass.protected_attributes
0
+ assert protected.include?(attribute.to_s),
0
+ "#{klass} is protecting #{protected.to_a.to_sentence}, but not #{attribute}."
0
@@ -285,7 +281,9 @@ module ThoughtBot # :nodoc:
0
- # Ensures that the has_many relationship exists.
0
+ # Ensures that the has_many relationship exists. Will also test that the
0
+ # associated table has the required columns. Works with polymorphic
0
# * <tt>:through</tt> - association name for <tt>has_many :through</tt>
0
@@ -327,23 +325,11 @@ module ThoughtBot # :nodoc:
0
- # Ensures that the has_and_belongs_to_many relationship exists.
0
- # should_have_and_belong_to_many :posts, :cars
0
- def should_have_and_belong_to_many(*associations)
0
- get_options!(associations)
0
- associations.each do |association|
0
- should "should have and belong to many #{association}" do
0
- assert klass.reflect_on_association(association), "#{klass.name} does not have any relationship to #{association}"
0
- assert_equal :has_and_belongs_to_many, klass.reflect_on_association(association).macro
0
- # Ensure that the has_one relationship exists.
0
+ # Ensure that the has_one relationship exists. Will also test that the
0
+ # associated table has the required columns. Works with polymorphic
0
# should_have_one :god # unless hindu
0
def should_have_one(*associations)
0
@@ -373,6 +359,21 @@ module ThoughtBot # :nodoc:
0
+ # Ensures that the has_and_belongs_to_many relationship exists.
0
+ # should_have_and_belong_to_many :posts, :cars
0
+ def should_have_and_belong_to_many(*associations)
0
+ get_options!(associations)
0
+ associations.each do |association|
0
+ should "should have and belong to many #{association}" do
0
+ assert klass.reflect_on_association(association), "#{klass.name} does not have any relationship to #{association}"
0
+ assert_equal :has_and_belongs_to_many, klass.reflect_on_association(association).macro
0
# Ensure that the belongs_to relationship exists.
0
# should_belong_to :parent
Comments
No one has commented yet.