Permalink
Browse files

add Document::Attributes#attribute_changed?

  • Loading branch information...
1 parent b5004ec commit d30d1c1eb34799b8bf4a0e5e8244d1e658466de6 @jamesgolick committed Jan 3, 2010
Showing with 16 additions and 0 deletions.
  1. +8 −0 lib/friendly/document/attributes.rb
  2. +8 −0 spec/unit/document/attributes_spec.rb
@@ -55,6 +55,14 @@ def attribute_was(attribute)
instance_variable_get(:"@#{attribute}_was")
end
+ # Has this attribute changed?
+ #
+ # @param [Symbol] attribute The name of the attribute.
+ #
+ def attribute_changed?(attribute)
+ changed.include?(attribute)
+ end
+
# Have any of the attributes that are being tracked changed since last reset?
#
def changed?
@@ -79,6 +79,10 @@
it "returns the value of the variable for #attribute_was" do
@object.attribute_was(:some_variable).should == "Some value"
end
+
+ it "returns true for attribute_changed?(:some_variable)" do
+ @object.should be_attribute_changed(:some_variable)
+ end
end
describe "#reset_changes" do
@@ -97,5 +101,9 @@
it "returns nil for attribute_was(:some_variable)" do
@object.attribute_was(:some_variable).should be_nil
end
+
+ it "returns false for attribute_changed?(:some_variable)" do
+ @object.should_not be_attribute_changed(:some_variable)
+ end
end
end

0 comments on commit d30d1c1

Please sign in to comment.