Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Document::Attributes#attribute_changed?

  • Loading branch information...
commit d30d1c1eb34799b8bf4a0e5e8244d1e658466de6 1 parent b5004ec
@jamesgolick authored
View
8 lib/friendly/document/attributes.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?
View
8 spec/unit/document/attributes_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.